idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
46,400
protected function getHandler ( ) : HandlerStack { $ stack = HandlerStack :: create ( ) ; $ stack -> push ( Middleware :: mapResponse ( function ( ResponseInterface $ response ) { $ handler = $ this -> getResponseHandler ( ) ; return new $ handler ( $ response ) ; } ) , 'bitcoind_response' ) ; return $ stack ; }
Gets Guzzle handler stack .
46,401
protected function makeJson ( string $ method , $ params = [ ] ) : array { return [ 'json' => [ 'method' => $ this -> config [ 'preserve_case' ] ? $ method : strtolower ( $ method ) , 'params' => ( array ) $ params , 'id' => $ this -> rpcId ++ , ] , ] ; }
Construct json request .
46,402
public function get ( ? string $ key = null ) { $ key = $ this -> constructKey ( $ key ) ; if ( is_null ( $ key ) ) { $ array = $ this -> toArray ( ) ; return $ this -> count ( ) == 1 ? end ( $ array ) : $ array ; } return $ this -> parseKey ( $ key , function ( $ part , $ result ) { if ( isset ( $ result [ $ part ] ) ...
Gets data by using key with dotted notation .
46,403
public function exists ( ? string $ key = null ) : bool { $ key = $ this -> constructKey ( $ key ) ; return $ this -> parseKey ( $ key , function ( $ part , $ result ) { return array_key_exists ( $ part , $ result ) ; } ) ; }
Checks if key exists .
46,404
public function has ( ? string $ key = null ) : bool { $ key = $ this -> constructKey ( $ key ) ; return $ this -> parseKey ( $ key , function ( $ part , $ result ) { return isset ( $ result [ $ part ] ) ; } ) ; }
Checks if key exists and not null .
46,405
public function first ( ? string $ key = null ) { $ value = $ this -> get ( $ key ) ; if ( is_array ( $ value ) ) { return reset ( $ value ) ; } return $ value ; }
Gets first element .
46,406
public function last ( ? string $ key = null ) { $ value = $ this -> get ( $ key ) ; if ( is_array ( $ value ) ) { return end ( $ value ) ; } return $ value ; }
Gets last element .
46,407
public function contains ( $ needle , ? string $ key = null ) : bool { $ value = $ this -> get ( $ key ) ; if ( ! is_array ( $ value ) ) { throw new InvalidArgumentException ( 'method contains() should be called on array' ) ; } return in_array ( $ needle , $ value ) ; }
Checks if response contains value .
46,408
public function keys ( ? string $ key = null ) : array { $ value = $ this -> get ( $ key ) ; if ( ! is_array ( $ value ) ) { throw new InvalidArgumentException ( 'method keys() should be called on array' ) ; } return array_keys ( $ value ) ; }
Gets response keys .
46,409
public function values ( ? string $ key = null ) : array { $ value = $ this -> get ( $ key ) ; if ( ! is_array ( $ value ) ) { throw new InvalidArgumentException ( 'method values() should be called on array' ) ; } return array_values ( $ value ) ; }
Gets response values .
46,410
public function random ( int $ number = 1 , ? string $ key = null ) { $ value = $ this -> get ( $ key ) ; if ( is_array ( $ value ) ) { $ keys = array_keys ( $ value ) ; $ keysLength = count ( $ keys ) ; shuffle ( $ keys ) ; if ( $ number > $ keysLength ) { $ number = $ keysLength ; } for ( $ result = [ ] , $ count = 0...
Gets random value .
46,411
public function count ( ? string $ key = null ) : int { if ( is_null ( $ this -> constructKey ( $ key ) ) ) { return count ( $ this -> toArray ( ) ) ; } $ value = $ this -> get ( $ key ) ; if ( ! is_array ( $ value ) ) { throw new InvalidArgumentException ( 'method count() should be called on array' ) ; } return count ...
Counts response items .
46,412
public function flatten ( ? string $ key = null ) : array { $ array = new \ RecursiveIteratorIterator ( new \ RecursiveArrayIterator ( ( array ) $ this -> get ( $ key ) ) ) ; $ tmp = [ ] ; foreach ( $ array as $ value ) { $ tmp [ ] = $ value ; } return $ tmp ; }
Flattens multi - dimensional array .
46,413
protected function constructKey ( ? string $ key = null ) : ? string { if ( ! is_null ( $ key ) && ! is_null ( $ this -> current ) ) { return $ this -> current . '.' . $ key ; } if ( is_null ( $ key ) && ! is_null ( $ this -> current ) ) { return $ this -> current ; } return $ key ; }
Constructs full key .
46,414
protected function parseKey ( $ key , callable $ callback , ? array $ result = null ) { $ parts = is_array ( $ key ) ? $ key : explode ( '.' , trim ( $ key , '.' ) ) ; $ result = $ result ? : $ this -> toArray ( ) ; while ( ! is_null ( $ part = array_shift ( $ parts ) ) ) { if ( $ part == '*' ) { array_walk ( $ result ...
Parses dotted notation .
46,415
protected function validate ( ) { $ realPath = $ this -> realPath ( ) ; if ( ! $ realPath ) { throw new \ InvalidArgumentException ( "Path can not be empty" ) ; } if ( ! file_exists ( $ realPath ) ) { throw new PathNotFoundException ( "Path does not exist: [{$realPath}]" ) ; } if ( ! $ this -> composer ( 'type' ) ) { t...
Validate addon parameters
46,416
protected function make ( ) { $ entry = AddonModel :: query ( ) -> create ( [ 'name' => $ this -> name ( ) , 'vendor' => $ this -> vendor ( ) , 'slug' => $ this -> slug , 'path' => $ this -> relativePath ( ) , 'type' => $ this -> type ( ) , 'namespace' => $ this -> namespace ( ) , 'enabled' => true , ] ) ; $ this -> ad...
Make addon entry
46,417
protected function migrate ( ) { $ this -> console -> call ( 'migrate' , [ '--scope' => $ this -> addon -> slug ( ) , '--force' => true ] , $ this -> command ? $ this -> command -> getOutput ( ) : null ) ; }
Migrate addon migrations
46,418
protected function installSubAddons ( ) { if ( $ subAddons = $ this -> addon -> installs ( ) ) { foreach ( $ subAddons as $ slug => $ path ) { app ( self :: class ) -> setSlug ( $ slug ) -> setPath ( $ this -> path . '/' . $ path ) -> install ( ) ; } } }
Install sub addons
46,419
protected function composer ( $ key = null ) { if ( ! $ this -> composerJson ) { $ composerFile = $ this -> realPath ( ) . '/composer.json' ; if ( ! file_exists ( $ composerFile ) ) { return null ; } $ this -> composerJson = json_decode ( file_get_contents ( $ composerFile ) , true ) ; } return $ key ? array_get ( $ th...
Load composer config from addon path
46,420
public function current ( ) { $ port = Current :: port ( ) ; if ( ! $ port || ! $ prefix = $ port -> prefix ( ) ) { return $ this -> to ( $ this -> request -> getPathInfo ( ) ) ; } return $ this -> to ( $ this -> getPathInfo ( ) ) ; }
Get the current URL for the request .
46,421
public function hibernate ( ) : string { $ url = sprintf ( 'sv/wake/%s' , uuid ( ) ) ; cache ( ) -> forever ( $ url , serialize ( $ this ) ) ; return $ url ; }
Hibernate and return wakeup url
46,422
public function register ( array $ routes ) : self { foreach ( $ routes as $ uri => $ action ) { $ this -> registerRoute ( $ uri , $ action ) ; } return $ this ; }
Register multiple routes
46,423
public function registerRoute ( $ uri , $ action ) { if ( $ this -> globally ) { $ ports = Hub :: ports ( ) -> merge ( new Port ) ; } else { $ ports = collect ( [ $ this -> port ] ) ; } $ ports -> map ( function ( $ port ) use ( $ action , $ uri ) { $ this -> routes -> push ( Action :: make ( $ uri , $ action ) -> port...
Register a route
46,424
public function register ( $ port ) { if ( is_string ( $ port ) ) { $ port = resolve ( $ port ) ; } $ this -> ports -> push ( $ port ) ; return $ port ; }
Register the port resolve if class name is provided and return the resolved instance .
46,425
public function get ( $ slug ) { return $ this -> ports -> first ( function ( Port $ port ) use ( $ slug ) { return $ port -> slug ( ) === $ slug ; } ) ; }
Get port by slug
46,426
protected function matchAction ( $ action , $ actions ) : bool { return in_array ( $ action , $ actions ) || $ this -> matchWild ( $ actions , $ action ) ; }
Determine if an action is valid for a given list of actions
46,427
public function getAssignedActions ( ) { $ assigned = $ this -> roles -> map ( function ( Role $ role ) { return $ role -> actions ; } ) -> flatten ( 1 ) -> merge ( $ this -> actions ( ) -> get ( ) ) ; return $ assigned ; }
Get all assigned actions
46,428
protected function getForbiddenActions ( ) { $ forbidden = $ this -> getAssignedActions ( ) -> filter ( function ( Action $ action ) { return $ action -> pivot -> provision === 'fail' ; } ) -> pluck ( 'slug' ) -> all ( ) ; return $ forbidden ; }
Get only assigned actions that are forbidden
46,429
protected function getAllowedActions ( ) { $ allowed = $ this -> getAssignedActions ( ) -> filter ( function ( Action $ action ) { return $ action -> pivot -> provision === 'pass' ; } ) -> pluck ( 'slug' ) -> all ( ) ; return $ allowed ; }
Get only assigned actions that are allowed
46,430
public function user ( ) { if ( ! $ this -> user ) { $ this -> user = app ( Users :: class ) -> find ( auth ( ) -> guard ( ) -> id ( ) ) ; } return $ this -> user ; }
Return the current logged in user
46,431
public function url ( string $ path = null ) : string { return $ path ? sv_url ( $ path ) : sv_url ( ) -> current ( ) ; }
Return the current url of the active port
46,432
public function boot ( ) { $ entries = AddonModel :: query ( ) -> where ( 'enabled' , true ) -> get ( ) ; foreach ( $ entries as $ entry ) { if ( $ addon = $ entry -> resolveAddon ( ) ) { $ addon -> boot ( ) ; } } PlatformBootedEvent :: dispatch ( ) ; }
Boot enabled addons
46,433
public static function get ( $ key , $ default = null ) { static $ variables ; if ( $ variables === null ) { $ variables = ( new DotenvFactory ( [ new EnvConstAdapter , new PutenvAdapter , new ServerConstAdapter ] ) ) -> createImmutable ( ) ; } return Option :: fromValue ( $ variables -> get ( $ key ) ) -> map ( functi...
Gets the value of an environment variable .
46,434
public function buildAttrFromArray ( array $ array ) { $ attributes = [ ] ; foreach ( $ array as $ attribute => $ data ) { if ( is_array ( $ data ) ) { $ data = implode ( ' ' , $ data ) ; } $ attributes [ ] = $ attribute . '="' . htmlspecialchars ( $ data ) . '"' ; } return $ attributes ? ' ' . implode ( ' ' , $ attrib...
Builds HTML tag attributes from an array of attributes data
46,435
public function getTable ( $ tableName ) { if ( is_array ( $ tableName ) ) { list ( $ tableName , $ entitySuffix ) = $ tableName ; } else { $ entitySuffix = null ; } if ( $ entitySuffix !== null ) { $ tableName .= '_' . $ entitySuffix ; } if ( ! isset ( $ this -> _tables [ $ tableName ] ) ) { $ this -> _tables [ $ tabl...
Get real table name for db table validated by db adapter
46,436
protected function getResource ( ) { if ( empty ( $ this -> _resourceName ) && empty ( $ this -> _resource ) ) { throw new LocalizedException ( new Phrase ( 'The resource isn\'t set.' ) ) ; } return $ this -> _resource ? : ObjectManager :: getInstance ( ) -> get ( $ this -> _resourceName ) ; }
Get resource instance
46,437
public function getResource ( $ application = null ) { if ( $ application === null ) { $ application = $ this -> getWebhook ( ) -> getApplication ( ) ; } $ url = new URL ( $ application , $ this -> getResourceUrl ( ) ) ; $ request = new Request ( $ application , $ url , Request :: METHOD_GET ) ; $ request -> send ( ) ;...
Fetches the resource and if possible loads it into it s respective model class
46,438
public function loadByGUID ( $ model , $ guid ) { $ class = $ this -> validateModelClass ( $ model ) ; $ uri = sprintf ( '%s/%s' , $ class :: getResourceURI ( ) , $ guid ) ; $ api = $ class :: getAPIStem ( ) ; $ url = new URL ( $ this , $ uri , $ api ) ; $ request = new Request ( $ this , $ url , Request :: METHOD_GET ...
As you should never have a GUID for a non - existent object will throw a NotFoundExceptioon
46,439
public function loadByGUIDs ( $ model , $ guids ) { $ class = $ this -> validateModelClass ( $ model ) ; $ uri = sprintf ( '%s' , $ class :: getResourceURI ( ) ) ; $ api = $ class :: getAPIStem ( ) ; $ url = new URL ( $ this , $ uri , $ api ) ; $ request = new Request ( $ this , $ url , Request :: METHOD_GET ) ; $ requ...
Filter by comma separated string of guid s
46,440
private function savePropertiesDirectly ( Remote \ Model $ object ) { foreach ( $ object :: getProperties ( ) as $ property_name => $ meta ) { if ( $ meta [ Remote \ Model :: KEY_SAVE_DIRECTLY ] && $ object -> isDirty ( $ property_name ) ) { $ property_objects = $ object -> $ property_name ; $ property_type = get_class...
Function to save properties directly which do not update via a POST .
46,441
private function getOAuthParams ( ) { if ( ! isset ( $ this -> oauth_params ) ) { $ this -> oauth_params = [ 'oauth_consumer_key' => $ this -> getConsumerKey ( ) , 'oauth_signature_method' => $ this -> getSignatureMethod ( ) , 'oauth_timestamp' => $ this -> getTimestamp ( ) , 'oauth_nonce' => $ this -> getNonce ( ) , '...
Gets the skeleton Oauth parameter array . The only one missing is the actual oauth_signature which should get populated from this data and then merged into it .
46,442
private function getSignature ( Request $ request ) { switch ( $ this -> getSignatureMethod ( ) ) { case self :: SIGNATURE_RSA_SHA1 : $ signature = RSASHA1 :: generateSignature ( $ this -> config , $ this -> getSBS ( $ request ) , $ this -> getSigningSecret ( ) ) ; break ; case self :: SIGNATURE_HMAC_SHA1 : $ signature...
Call the appropriate signature method s signing function . Not all mechanisms use all of the parameters but for consistency pass the same constructor to each one .
46,443
private function getSigningSecret ( ) { $ secret = $ this -> getConsumerSecret ( ) . '&' ; if ( null !== $ token_secret = $ this -> getTokenSecret ( ) ) { $ secret .= $ token_secret ; } return $ secret ; }
This is the signing secret passed to HMAC and PLAINTEXT signing mechanisms .
46,444
private function getNonce ( $ length = 20 ) { $ parts = explode ( '.' , number_format ( microtime ( true ) , 22 , '.' , '' ) ) ; if ( ! isset ( $ parts [ 1 ] ) ) { $ parts [ 1 ] = 0 ; } $ nonce = base_convert ( $ parts [ 1 ] , 10 , 36 ) ; for ( $ i = 0 ; $ i < $ length - strlen ( $ nonce ) ; $ i ++ ) { $ nonce .= base_...
Generic nonce generating function for the request . It s important that it s long enough as the spec says the server will reject any request that reuses one .
46,445
protected function appendUrlQuery ( $ url , $ query ) { $ glue = $ this -> urlHasQuery ( $ url ) ? '&' : '?' ; return $ url . $ glue . http_build_query ( $ query ) ; }
Prepend URL with query string .
46,446
public function isDirty ( $ property = null ) { if ( $ property === null ) { return count ( $ this -> _dirty ) > 0 ; } else { return isset ( $ this -> _dirty [ $ property ] ) ; } }
If there have been any properties changed since load
46,447
public function setClean ( $ property = null ) { if ( $ property === null ) { $ this -> _dirty = [ ] ; } else { unset ( $ this -> _dirty [ $ property ] ) ; } return $ this ; }
Manually set a property as clean
46,448
public function toStringArray ( $ dirty_only = false ) { $ out = [ ] ; foreach ( static :: getProperties ( ) as $ property => $ meta ) { if ( ! isset ( $ this -> _data [ $ property ] ) ) { continue ; } if ( $ dirty_only && ! isset ( $ this -> _dirty [ $ property ] ) ) { continue ; } $ type = $ meta [ self :: KEY_TYPE ]...
Convert the object into an array and any non - primitives to string .
46,449
public static function castToString ( $ type , $ value ) { if ( $ value === '' ) { return '' ; } switch ( $ type ) { case self :: PROPERTY_TYPE_BOOLEAN : return $ value ? 'true' : 'false' ; case self :: PROPERTY_TYPE_DATE : return $ value -> format ( 'Y-m-d' ) ; case self :: PROPERTY_TYPE_TIMESTAMP : return $ value -> ...
Convert properties to strings based on the types parsed .
46,450
public static function castFromString ( $ type , $ value , $ php_type ) { $ timezone = null ; switch ( $ type ) { case self :: PROPERTY_TYPE_INT : return ( int ) $ value ; case self :: PROPERTY_TYPE_FLOAT : return ( float ) $ value ; case self :: PROPERTY_TYPE_BOOLEAN : return in_array ( strtolower ( $ value ) , [ 'tru...
Cast the values to PHP types .
46,451
public static function getSupportedMethods ( ) { return [ Remote \ Request :: METHOD_POST , Remote \ Request :: METHOD_PUT , Remote \ Request :: METHOD_GET , ] ; }
Get the supported methods
46,452
public static function getProperties ( ) { return [ 'AttachmentID' => [ false , self :: PROPERTY_TYPE_STRING , null , false , false ] , 'FileName' => [ true , self :: PROPERTY_TYPE_STRING , null , false , false ] , 'Url' => [ false , self :: PROPERTY_TYPE_STRING , null , false , false ] , 'MimeType' => [ false , self :...
Get a list of properties
46,453
public static function createFromLocalFile ( $ file_name , $ mime_type = null ) { if ( $ mime_type === null ) { $ finfo = new \ finfo ( FILEINFO_MIME_TYPE ) ; $ info = $ finfo -> file ( $ file_name ) ; if ( $ info !== false ) { $ mime_type = $ info ; } } $ content_length = filesize ( $ file_name ) ; $ path_info = pathi...
Do this with a file handle please
46,454
public function removeAt ( $ index ) { if ( isset ( $ this [ $ index ] ) ) { foreach ( $ this -> _associated_objects as $ parent_property => $ object ) { $ object -> setDirty ( $ parent_property ) ; } unset ( $ this [ $ index ] ) ; } }
Remove an item at a specific index
46,455
public function remove ( Model $ object ) { foreach ( $ this as $ index => $ item ) { if ( $ item === $ object ) { $ this -> removeAt ( $ index ) ; } } }
Remove a specific object from the collection
46,456
public function removeAll ( ) { foreach ( $ this -> _associated_objects as $ parent_property => $ object ) { $ object -> setDirty ( $ parent_property ) ; } $ this -> exchangeArray ( [ ] ) ; }
Remove all of the values int he collection
46,457
protected function buildPDFRequest ( ) { return ( new Request ( $ this -> getApplication ( ) , $ this -> buildPDFURL ( ) , Request :: METHOD_GET ) ) -> setHeader ( Request :: HEADER_ACCEPT , Request :: CONTENT_TYPE_PDF ) ; }
Build a request for the resources PDF .
46,458
public static function flattenAssocArray ( array $ array , $ format , $ glue = null , $ escape = false ) { $ pairs = [ ] ; foreach ( $ array as $ key => $ val ) { if ( $ escape ) { $ key = self :: escape ( $ key ) ; $ val = self :: escape ( $ val ) ; } $ pairs [ ] = sprintf ( $ format , $ key , $ val ) ; } if ( $ glue ...
Generic function to flatten an associative array into an arbitrarily delimited string .
46,459
public function prepareValue ( Context $ context ) { $ name = $ this -> getName ( ) ; $ value = $ this -> parent -> prepareValue ( $ context ) -> getValue ( ) ; if ( is_object ( $ value ) && ! $ value instanceof \ Closure ) { if ( method_exists ( $ value , $ name ) ) { return $ this -> asValue ( call_user_func ( array ...
Prepare a Value for this VariableProperty given the current Context .
46,460
public function setContains ( Value $ value ) { if ( is_array ( $ value -> getValue ( ) ) ) { foreach ( $ this -> value as $ val ) { if ( $ val instanceof Set && $ val == $ value -> getSet ( ) ) { return true ; } } return false ; } return in_array ( $ value -> getValue ( ) , $ this -> value ) ; }
Set Contains comparison .
46,461
public function union ( Value $ set ) { $ union = $ this -> value ; foreach ( func_get_args ( ) as $ arg ) { $ convertedArg = $ arg -> getSet ( ) -> getValue ( ) ; $ union = array_merge ( $ union , array_diff ( $ convertedArg , $ union ) ) ; } return new self ( $ union ) ; }
Set union operator .
46,462
public function intersect ( Value $ set ) { $ intersect = $ this -> value ; foreach ( func_get_args ( ) as $ arg ) { $ convertedArg = $ arg -> getSet ( ) -> getValue ( ) ; $ intersect = array_values ( array_intersect ( $ intersect , $ convertedArg ) ) ; } return new self ( $ intersect ) ; }
Set intersection operator .
46,463
public function complement ( Value $ set ) { $ complement = $ this -> value ; foreach ( func_get_args ( ) as $ arg ) { $ convertedArg = $ arg -> getSet ( ) -> getValue ( ) ; $ complement = array_values ( array_diff ( $ complement , $ convertedArg ) ) ; } return new self ( $ complement ) ; }
Set complement operator .
46,464
public function symmetricDifference ( Value $ set ) { $ returnValue = new Set ( array ( ) ) ; return $ returnValue -> union ( $ this -> complement ( $ set ) , $ set -> getSet ( ) -> complement ( $ this ) ) ; }
Set symmetric difference operator .
46,465
public function min ( ) { if ( ! $ this -> isValidNumericSet ( ) ) { throw new \ RuntimeException ( 'min: all values must be numeric' ) ; } if ( empty ( $ this -> value ) ) { return null ; } return min ( $ this -> value ) ; }
Numeric minimum value in this Set .
46,466
public function max ( ) { if ( ! $ this -> isValidNumericSet ( ) ) { throw new \ RuntimeException ( 'max: all values must be numeric' ) ; } if ( empty ( $ this -> value ) ) { return null ; } return max ( $ this -> value ) ; }
Numeric maximum value in this Set .
46,467
public function containsSubset ( Set $ set ) { if ( count ( $ set -> getValue ( ) ) > count ( $ this -> getValue ( ) ) ) { return false ; } return array_intersect ( $ set -> getValue ( ) , $ this -> getValue ( ) ) == $ set -> getValue ( ) ; }
Contains Subset comparison .
46,468
public function offsetGet ( $ name ) { if ( ! isset ( $ this -> variables [ $ name ] ) ) { $ this -> variables [ $ name ] = new RuleBuilder \ Variable ( $ this , $ name ) ; } return $ this -> variables [ $ name ] ; }
Retrieve a Variable by name .
46,469
public function findOperator ( $ name ) { $ operator = ucfirst ( $ name ) ; foreach ( array_keys ( $ this -> operatorNamespaces ) as $ namespace ) { $ class = $ namespace . '\\' . $ operator ; if ( class_exists ( $ class ) ) { return $ class ; } } throw new \ LogicException ( sprintf ( 'Unknown operator: "%s"' , $ name...
Find an operator in the registered operator namespaces .
46,470
public function executeRules ( Context $ context ) { foreach ( $ this -> rules as $ rule ) { $ rule -> execute ( $ context ) ; } }
Execute all Rules in the RuleSet .
46,471
public function offsetGet ( $ name ) { if ( ! $ this -> offsetExists ( $ name ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Fact "%s" is not defined.' , $ name ) ) ; } $ value = $ this -> values [ $ name ] ; if ( isset ( $ this -> frozen [ $ name ] ) || ! is_object ( $ value ) || $ this -> protected -> contai...
Get the value of a fact .
46,472
public function offsetSet ( $ name , $ value ) { if ( isset ( $ this -> frozen [ $ name ] ) ) { throw new \ RuntimeException ( sprintf ( 'Cannot override frozen fact "%s".' , $ name ) ) ; } $ this -> keys [ $ name ] = true ; $ this -> values [ $ name ] = $ value ; }
Set a fact name and value .
46,473
public function offsetUnset ( $ name ) { if ( $ this -> offsetExists ( $ name ) ) { $ value = $ this -> values [ $ name ] ; if ( is_object ( $ value ) ) { $ this -> shared -> detach ( $ value ) ; $ this -> protected -> detach ( $ value ) ; } unset ( $ this -> keys [ $ name ] , $ this -> values [ $ name ] , $ this -> fr...
Unset a fact
46,474
public function raw ( $ name ) { if ( ! $ this -> offsetExists ( $ name ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Fact "%s" is not defined.' , $ name ) ) ; } if ( isset ( $ this -> frozen [ $ name ] ) ) { return $ this -> raw [ $ name ] ; } return $ this -> values [ $ name ] ; }
Get a fact or the closure defining a fact .
46,475
public function getProperty ( $ name , $ value = null ) { if ( ! isset ( $ this -> properties [ $ name ] ) ) { $ this -> properties [ $ name ] = new VariableProperty ( $ this , $ name , $ value ) ; } return $ this -> properties [ $ name ] ; }
Get a VariableProperty for accessing methods indexes and properties of the current variable .
46,476
private function applySetOperator ( $ name , array $ args ) { $ reflection = new \ ReflectionClass ( '\\Ruler\\Operator\\' . $ name ) ; array_unshift ( $ args , $ this ) ; return $ this -> wrap ( $ reflection -> newInstanceArgs ( $ args ) ) ; }
Private helper to apply a set operator .
46,477
public function prepareValue ( Context $ context ) { if ( isset ( $ this -> name ) && isset ( $ context [ $ this -> name ] ) ) { $ value = $ context [ $ this -> name ] ; } elseif ( $ this -> value instanceof VariableOperand ) { $ value = $ this -> value -> prepareValue ( $ context ) ; } else { $ value = $ this -> value...
Prepare a Value for this Variable given the current Context .
46,478
public function execute ( Context $ context ) { if ( $ this -> evaluate ( $ context ) && isset ( $ this -> action ) ) { if ( ! is_callable ( $ this -> action ) ) { throw new \ LogicException ( 'Rule actions must be callable.' ) ; } call_user_func ( $ this -> action ) ; } }
Execute the Rule with the given Context .
46,479
public function startsWith ( Value $ value , $ insensitive = false ) { $ value = $ value -> getValue ( ) ; $ valueLength = strlen ( $ value ) ; if ( ! empty ( $ this -> value ) && ! empty ( $ value ) && strlen ( $ this -> value ) >= $ valueLength ) { return substr_compare ( $ this -> value , $ value , 0 , $ valueLength...
String StartsWith comparison .
46,480
public function updateAuthServiceProviderClass ( ) { $ modelName = $ this -> modelNames [ 'model_name' ] ; $ fullModelName = $ this -> modelNames [ 'full_model_name' ] ; $ authSPPath = $ this -> makeAuthServiceProvilderFile ( app_path ( 'Providers' ) , 'AuthServiceProvider.php' ) ; $ authSPContent = $ this -> files -> ...
Update AuthServiceProviderClass based on created model policy object
46,481
protected function makeAuthServiceProvilderFile ( $ routeDirPath , $ filename ) { $ routeDirPath = $ this -> makeDirectory ( $ routeDirPath ) ; if ( ! $ this -> files -> exists ( $ routeDirPath . '/' . $ filename ) ) { $ this -> generateFile ( $ routeDirPath . '/' . $ filename , $ this -> files -> get ( __DIR__ . '/../...
Create AuthServiceProvider class if not exists
46,482
public function getModelName ( $ modelName = null ) { $ modelName = is_null ( $ modelName ) ? $ this -> argument ( 'name' ) : $ modelName ; $ model_name = ucfirst ( class_basename ( $ modelName ) ) ; $ plural_model_name = str_plural ( $ model_name ) ; $ modelPath = $ this -> getModelPath ( $ modelName ) ; $ modelNamesp...
Generate class properties for model names in different usage .
46,483
protected function getModelPath ( $ modelName ) { $ inputName = explode ( '/' , ucfirst ( $ modelName ) ) ; array_pop ( $ inputName ) ; return implode ( '/' , $ inputName ) ; }
Get model path on storage
46,484
protected function getModelNamespace ( $ modelPath ) { $ appNamespace = trim ( $ this -> getAppNamespace ( ) , '\\' ) ; $ modelNamespace = str_replace ( '/' , '\\' , $ appNamespace . '/' . ucfirst ( $ modelPath ) ) ; $ modelNamespace = trim ( $ modelNamespace , '\\' ) ; return $ modelNamespace == 'App\\' ? 'App' : $ mo...
Get model namespace
46,485
protected function makeRouteFile ( $ routeDirPath , $ filename ) { if ( ! $ this -> files -> isDirectory ( $ routeDirPath ) ) { $ this -> files -> makeDirectory ( $ routeDirPath , 0777 , true , true ) ; } if ( ! $ this -> files -> exists ( $ routeDirPath . '/' . $ filename ) ) { $ this -> generateFile ( $ routeDirPath ...
Create php route file if not exists
46,486
public function generate ( string $ type = 'full' ) { $ modelName = $ this -> modelNames [ 'model_name' ] ; $ pluralModelName = $ this -> modelNames [ 'plural_model_name' ] ; $ requestPath = $ this -> makeDirectory ( app_path ( 'Http/Requests/' . $ pluralModelName ) ) ; $ this -> generateFile ( $ requestPath . '/Create...
Generate class file content .
46,487
public function getContent ( string $ stubName ) { $ stub = $ this -> getStubFileContent ( $ stubName ) ; $ requestFileContent = $ this -> replaceStubString ( $ stub ) ; $ appNamespace = $ this -> getAppNamespace ( ) ; $ requestFileContent = str_replace ( "App\Http\Requests" , "{$appNamespace}Http\Requests" , $ request...
Get class file content .
46,488
public function get ( $ ipAddress ) { if ( \ func_num_args ( ) !== 1 ) { throw new \ InvalidArgumentException ( 'Method takes exactly one argument.' ) ; } if ( ! \ is_resource ( $ this -> fileHandle ) ) { throw new \ BadMethodCallException ( 'Attempt to read from a closed MaxMind DB.' ) ; } if ( ! filter_var ( $ ipAddr...
Looks up the address in the MaxMind DB .
46,489
public function curl ( $ url ) { $ ch = curl_init ( $ url ) ; curl_setopt ( $ ch , CURLOPT_USERAGENT , 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0' ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ ch , CURLOPT_HEADER , 0 ) ; curl_setopt ( $ ch , CURLOPT_SSL_VERIFYPEE...
what identifies each request? user agent cookies ...
46,490
public function getPlayerHtml ( $ video_html ) { $ player_url = $ this -> getPlayerUrl ( $ video_html ) ; $ cache_path = sprintf ( '%s/%s' , $ this -> storage_dir , md5 ( $ player_url ) ) ; if ( file_exists ( $ cache_path ) ) { $ contents = file_get_contents ( $ cache_path ) ; } $ contents = $ this -> curl ( $ player_u...
Do not redownload player . js everytime - cache it
46,491
public function getSigDecodeInstructions ( $ player_html , $ func_name ) { if ( preg_match ( '/' . $ func_name . '=function\([a-z]+\){(.*?)}/' , $ player_html , $ matches ) ) { $ js_code = $ matches [ 1 ] ; if ( preg_match_all ( '/([a-z0-9]{2})\.([a-z0-9]{2})\([^,]+,(\d+)\)/i' , $ js_code , $ matches ) != false ) { $ o...
convert JS code for signature decipher to PHP code
46,492
public function parseStreamMap ( $ video_html , $ video_id ) { $ stream_map = array ( ) ; $ result = array ( ) ; if ( preg_match ( '@url_encoded_fmt_stream_map["\']:\s*["\']([^"\'\s]*)@' , $ video_html , $ matches ) ) { $ stream_map = $ matches [ 1 ] ; } else { $ gvi = $ this -> curl ( "https://www.youtube.com/get_vide...
some of the data may need signature decoding
46,493
public function wait ( ) : void { while ( ! $ this -> stream -> eof ( ) ) { $ frame = $ this -> readFrame ( ) ; if ( null !== $ frame ) { if ( ! \ is_array ( $ frame ) ) { $ frame = [ $ frame ] ; } foreach ( $ this -> onNewFrameCallables as $ newFrameCallable ) { \ call_user_func_array ( $ newFrameCallable , $ frame ) ...
Wait for stream to finish and call callables if defined .
46,494
public function listen ( ) : Promise { return call ( function ( ) { while ( null !== ( $ chunk = yield $ this -> stream -> read ( ) ) ) { foreach ( $ this -> onNewFrameCallables as $ newFrameCallable ) { $ newFrameCallable ( $ this -> transformChunk ( $ chunk ) ) ; } } } ) ; }
Consume stream chunks .
46,495
private function transformChunk ( string $ chunk ) { if ( null === $ this -> chunkTransformer ) { return $ chunk ; } return \ call_user_func ( $ this -> chunkTransformer , $ chunk ) ; }
Transform stream chunks if required .
46,496
protected function readFrame ( ) : void { $ header = $ this -> forceRead ( 8 ) ; if ( \ strlen ( $ header ) < 8 ) { return ; } $ decoded = \ unpack ( 'C1type/C3/N1size' , $ header ) ; $ output = $ this -> forceRead ( $ decoded [ 'size' ] ) ; $ callbackList = [ ] ; if ( 0 === $ decoded [ 'type' ] ) { $ callbackList = $ ...
Read a frame in the stream .
46,497
public function toTar ( ) { $ process = new Process ( '/usr/bin/env tar c .' , $ this -> directory ) ; $ process -> run ( ) ; if ( ! $ process -> isSuccessful ( ) ) { throw new ProcessFailedException ( $ process ) ; } return $ process -> getOutput ( ) ; }
Return the context as a tar archive .
46,498
public function toStream ( ) { if ( ! \ is_resource ( $ this -> process ) ) { $ this -> process = \ proc_open ( '/usr/bin/env tar c .' , [ [ 'pipe' , 'r' ] , [ 'pipe' , 'w' ] , [ 'pipe' , 'w' ] ] , $ pipes , $ this -> directory ) ; $ this -> stream = $ pipes [ 1 ] ; } return $ this -> stream ; }
Return a stream for this context .
46,499
public function write ( $ data ) : void { $ rand = \ random_int ( 0 , 28 ) ; $ frame = [ 'fin' => 1 , 'rsv1' => 0 , 'rsv2' => 0 , 'rsv3' => 0 , 'opcode' => 1 , 'mask' => 1 , 'len' => \ strlen ( $ data ) , 'mask_key' => \ substr ( \ md5 ( \ uniqid ( ) ) , $ rand , 4 ) , 'data' => $ data , ] ; if ( 1 === $ frame [ 'mask'...
Send input to the container .