idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
23,100
protected function _loadFile ( $ path , $ dot_syntax_explode = true ) { if ( ! is_file ( $ path ) ) return [ ] ; if ( $ dot_syntax_explode ) return $ this -> arrayExplode ( include ( $ path ) ) ; return include ( $ path ) ; }
Loads a config file and extracts dot syntax keys .
23,101
protected function _varExport ( $ array , $ section ) { if ( empty ( $ array ) ) return '' ; $ returner = "\n\t/* $section */\n" ; foreach ( $ array as $ k => $ v ) { $ key = str_replace ( "'" , "\'" , $ k ) ; $ value = str_replace ( "'" , "\'" , $ v ) ; $ returner .= str_pad ( "\t'$key'" , 40 , ' ' ) ; $ returner .= '=> ' ; $ returner .= "'$value',\n" ; } return $ returner ; }
Like var_export from php but creates a code styled array . Called by checkLanguageFiles to create the i18n files .
23,102
protected function getReflectionParameterName ( \ ReflectionParameter $ parameter ) { if ( $ class = $ parameter -> getClass ( ) ) { return $ class -> getName ( ) . ' \$' . $ parameter -> getName ( ) ; } return $ parameter -> getName ( ) ; }
Helper method to get the type of a reflection paramter
23,103
protected function getReflectionFunctionName ( \ ReflectionFunctionAbstract $ reflection ) { if ( $ reflection instanceof \ ReflectionMethod ) { return $ reflection -> getDeclaringClass ( ) -> getName ( ) . '::' . $ reflection -> getName ( ) ; } return $ reflection -> getName ( ) ; }
Helper method to retrieve the name of a ReflectionFunctionAbstract
23,104
public function release ( ) { if ( ! $ this -> handler ) { throw new \ LogicException ( 'Lock is not acquired' ) ; } if ( ! @ ftruncate ( $ this -> handler , 0 ) ) { $ this -> throwLastErrorException ( ) ; } if ( ! flock ( $ this -> handler , LOCK_UN ) ) { throw new \ RuntimeException ( sprintf ( 'Unable to release lock on %s' , $ this -> file ) ) ; } $ this -> closeFile ( ) ; }
Release the lock
23,105
public function getAttributeDbValue ( AttributeMetadata $ attrMeta , $ value ) { if ( 'date' === $ attrMeta -> dataType && $ value instanceof \ DateTime ) { return new \ MongoDate ( $ value -> getTimestamp ( ) , $ value -> format ( 'u' ) ) ; } if ( 'array' === $ attrMeta -> dataType && empty ( $ value ) ) { return ; } if ( 'object' === $ attrMeta -> dataType ) { $ array = ( array ) $ value ; return empty ( $ array ) ? null : $ value ; } return $ value ; }
Prepares and formats an attribute value for proper insertion into the database .
23,106
public function getEmbedManyDbValue ( EmbeddedPropMetadata $ embeddedPropMeta , $ embeds = null ) { if ( null === $ embeds ) { return ; } if ( ! is_array ( $ embeds ) && ! $ embeds instanceof \ Traversable ) { throw new \ InvalidArgumentException ( 'Unable to traverse the embed collection' ) ; } $ created = [ ] ; foreach ( $ embeds as $ embed ) { $ created [ ] = $ this -> createEmbed ( $ embeddedPropMeta , $ embed ) ; } return empty ( $ created ) ? null : $ created ; }
Prepares and formats a has - many embed for proper insertion into the database .
23,107
public function getEmbedOneDbValue ( EmbeddedPropMetadata $ embeddedPropMeta , Embed $ embed = null ) { if ( null === $ embed ) { return ; } return $ this -> createEmbed ( $ embeddedPropMeta , $ embed ) ; }
Prepares and formats a has - one embed for proper insertion into the database .
23,108
public function getHasOneDbValue ( RelationshipMetadata $ relMeta , Model $ model = null ) { if ( null === $ model || true === $ relMeta -> isInverse ) { return ; } return $ this -> createReference ( $ relMeta , $ model ) ; }
Prepares and formats a has - one relationship model for proper insertion into the database .
23,109
public function getHasManyDbValue ( RelationshipMetadata $ relMeta , array $ models = null ) { if ( null === $ models || true === $ relMeta -> isInverse ) { return null ; } $ references = [ ] ; foreach ( $ models as $ model ) { $ references [ ] = $ this -> createReference ( $ relMeta , $ model ) ; } return empty ( $ references ) ? null : $ references ; }
Prepares and formats a has - many relationship model set for proper insertion into the database .
23,110
private function createEmbed ( EmbeddedPropMetadata $ embeddedPropMeta , Embed $ embed ) { $ embedMeta = $ embeddedPropMeta -> embedMeta ; $ obj = [ ] ; foreach ( $ embedMeta -> getAttributes ( ) as $ key => $ attrMeta ) { $ value = $ this -> getAttributeDbValue ( $ attrMeta , $ embed -> get ( $ key ) ) ; if ( null === $ value ) { continue ; } $ obj [ $ key ] = $ value ; } foreach ( $ embedMeta -> getEmbeds ( ) as $ key => $ propMeta ) { $ value = ( true === $ propMeta -> isOne ( ) ) ? $ this -> getEmbedOneDbValue ( $ propMeta , $ embed -> get ( $ key ) ) : $ this -> getEmbedManyDbValue ( $ propMeta , $ embed -> get ( $ key ) ) ; if ( null === $ value ) { continue ; } $ obj [ $ key ] = $ value ; } return $ obj ; }
Creates an embed for storage of an embed model in the database
23,111
private function createReference ( RelationshipMetadata $ relMeta , Model $ model ) { $ reference = [ ] ; $ identifier = $ this -> getIdentifierDbValue ( $ model -> getId ( ) ) ; if ( true === $ relMeta -> isPolymorphic ( ) ) { $ reference [ Persister :: IDENTIFIER_KEY ] = $ identifier ; $ reference [ Persister :: POLYMORPHIC_KEY ] = $ model -> getType ( ) ; return $ reference ; } return $ identifier ; }
Creates a reference for storage of a related model in the database
23,112
private function formatQueryElement ( $ key , $ value , EntityMetadata $ metadata , Store $ store ) { if ( null !== $ result = $ this -> formatQueryElementRoot ( $ key , $ value , $ metadata ) ) { return $ result ; } if ( null !== $ result = $ this -> formatQueryElementAttr ( $ key , $ value , $ metadata , $ store ) ) { return $ result ; } if ( null !== $ result = $ this -> formatQueryElementRel ( $ key , $ value , $ metadata , $ store ) ) { return $ result ; } if ( null !== $ result = $ this -> formatQueryElementDotted ( $ key , $ value , $ metadata , $ store ) ) { return $ result ; } return [ $ key , $ value ] ; }
Formats a query element and ensures the correct key and value are set . Returns a tuple of the formatted key and value .
23,113
private function formatQueryElementAttr ( $ key , $ value , EntityMetadata $ metadata , Store $ store ) { if ( null === $ attrMeta = $ metadata -> getAttribute ( $ key ) ) { return ; } $ converter = $ this -> getQueryAttrConverter ( $ store , $ attrMeta ) ; if ( is_array ( $ value ) ) { if ( true === $ this -> hasOperators ( $ value ) ) { return [ $ key , $ this -> formatQueryExpression ( $ value , $ converter ) ] ; } if ( in_array ( $ attrMeta -> dataType , [ 'array' , 'object' ] ) ) { return [ $ key , $ value ] ; } return [ $ key , $ this -> formatQueryExpression ( [ '$in' => $ value ] , $ converter ) ] ; } return [ $ key , $ converter ( $ value ) ] ; }
Formats an attribute query element . Returns a tuple of the formatted key and value or null if the key is not an attribute field .
23,114
private function formatQueryElementDotted ( $ key , $ value , EntityMetadata $ metadata , Store $ store ) { if ( false === stripos ( $ key , '.' ) ) { return ; } $ parts = explode ( '.' , $ key ) ; $ root = array_shift ( $ parts ) ; if ( false === $ metadata -> hasRelationship ( $ root ) ) { return [ $ key , $ value ] ; } $ hasIndex = is_numeric ( $ parts [ 0 ] ) ; if ( true === $ hasIndex ) { $ subKey = isset ( $ parts [ 1 ] ) ? $ parts [ 1 ] : 'id' ; } else { $ subKey = $ parts [ 0 ] ; } if ( $ this -> isIdentifierField ( $ subKey ) ) { list ( $ key , $ value ) = $ this -> formatQueryElementRel ( $ root , $ value , $ metadata , $ store ) ; $ key = ( true === $ hasIndex ) ? sprintf ( '%s.%s' , $ key , $ parts [ 0 ] ) : $ key ; return [ $ key , $ value ] ; } if ( $ this -> isTypeField ( $ subKey ) ) { list ( $ key , $ value ) = $ this -> formatQueryElementRoot ( $ subKey , $ value , $ metadata ) ; $ key = ( true === $ hasIndex ) ? sprintf ( '%s.%s.%s' , $ root , $ parts [ 0 ] , $ key ) : sprintf ( '%s.%s' , $ root , $ key ) ; return [ $ key , $ value ] ; } return [ $ key , $ value ] ; }
Formats a dot - notated field . Returns a tuple of the formatted key and value or null if the key is not a dot - notated field or cannot be handled .
23,115
private function formatQueryElementRel ( $ key , $ value , EntityMetadata $ metadata , Store $ store ) { if ( null === $ relMeta = $ metadata -> getRelationship ( $ key ) ) { return ; } $ converter = $ this -> getQueryRelConverter ( $ store , $ relMeta ) ; if ( true === $ relMeta -> isPolymorphic ( ) ) { $ key = sprintf ( '%s.%s' , $ key , Persister :: IDENTIFIER_KEY ) ; } if ( is_array ( $ value ) ) { $ value = ( true === $ this -> hasOperators ( $ value ) ) ? $ value : [ '$in' => $ value ] ; return [ $ key , $ this -> formatQueryExpression ( $ value , $ converter ) ] ; } return [ $ key , $ converter ( $ value ) ] ; }
Formats a relationship query element . Returns a tuple of the formatted key and value or null if the key is not a relationship field .
23,116
private function formatQueryExpression ( array $ expression , Closure $ converter ) { foreach ( $ expression as $ key => $ value ) { if ( '$regex' === $ key && ! $ value instanceof \ MongoRegex ) { $ expression [ $ key ] = new \ MongoRegex ( $ value ) ; continue ; } if ( true === $ this -> isOpType ( 'ignore' , $ key ) ) { continue ; } if ( true === $ this -> isOpType ( 'single' , $ key ) ) { $ expression [ $ key ] = $ converter ( $ value ) ; continue ; } if ( true === $ this -> isOpType ( 'multiple' , $ key ) ) { $ value = ( array ) $ value ; foreach ( $ value as $ subKey => $ subValue ) { $ expression [ $ key ] [ $ subKey ] = $ converter ( $ subValue ) ; } continue ; } if ( true === $ this -> isOpType ( 'recursive' , $ key ) ) { $ value = ( array ) $ value ; $ expression [ $ key ] = $ this -> formatQueryExpression ( $ value , $ converter ) ; continue ; } $ expression [ $ key ] = $ converter ( $ value ) ; } return $ expression ; }
Formats a query expression .
23,117
private function getQueryAttrConverter ( Store $ store , AttributeMetadata $ attrMeta ) { return function ( $ value ) use ( $ store , $ attrMeta ) { if ( in_array ( $ attrMeta -> dataType , [ 'object' , 'array' ] ) ) { return $ value ; } $ value = $ store -> convertAttributeValue ( $ attrMeta -> dataType , $ value ) ; return $ this -> getAttributeDbValue ( $ attrMeta , $ value ) ; } ; }
Gets the converter for handling attribute values in queries .
23,118
private function getQueryRelConverter ( Store $ store , RelationshipMetadata $ relMeta ) { $ related = $ store -> getMetadataForType ( $ relMeta -> getEntityType ( ) ) ; return $ this -> getQueryRootConverter ( $ related , Persister :: IDENTIFIER_KEY ) ; }
Gets the converter for handling relationship values in queries .
23,119
private function hasOperators ( $ value ) { if ( ! is_array ( $ value ) && ! is_object ( $ value ) ) { return false ; } if ( is_object ( $ value ) ) { $ value = get_object_vars ( $ value ) ; } foreach ( $ value as $ key => $ subValue ) { if ( true === $ this -> isOperator ( $ key ) ) { return true ; } } return false ; }
Determines whether a query value has additional query operators .
23,120
private function isOpType ( $ type , $ key ) { if ( ! isset ( $ this -> ops [ $ type ] ) ) { return false ; } return in_array ( $ key , $ this -> ops [ $ type ] ) ; }
Determines if a key is of a certain operator handling type .
23,121
private function validateAlnum ( ) : bool { $ charClass = '[:alnum:]' ; if ( $ this -> options [ 'allow-spaces' ] === true ) { $ charClass .= '[:space:]' ; } if ( $ this -> options [ 'allow-whitespaces' ] === true ) { $ charClass .= '[:blank:]' ; } $ modifier = '' ; if ( $ this -> options [ 'utf-8' ] === true ) { $ modifier = 'u' ; } $ isValid = \ preg_match ( '/^[' . $ charClass . ']+$/' . $ modifier , $ this -> value ) ? true : false ; if ( ! $ isValid ) { $ this -> setError ( self :: VALIDATOR_ERROR_ALNUM_NOT_VALID ) ; if ( $ this -> options [ 'allow-whitespaces' ] === true && $ this -> options [ 'allow-spaces' ] === true ) { $ this -> setError ( self :: VALIDATOR_ERROR_ALNUM_SPACES_WHITESPACES_NOT_VALID ) ; } elseif ( $ this -> options [ 'allow-whitespaces' ] === true ) { $ this -> setError ( self :: VALIDATOR_ERROR_ALNUM_WHITESPACES_NOT_VALID ) ; } elseif ( $ this -> options [ 'allow-spaces' ] === true ) { $ this -> setError ( self :: VALIDATOR_ERROR_ALNUM_SPACES_NOT_VALID ) ; } } return $ isValid ; }
Checks whether string is valid alnum string
23,122
public function start ( ) { if ( $ this -> started ) { return ; } $ this -> started = true ; $ this -> getConfigLoader ( ) -> setEnvironment ( $ this -> getEnvironment ( ) ) ; $ this -> config = $ this -> getConfigLoader ( ) -> load ( ) ; $ this -> container -> set ( [ Config :: class , IConfig :: class ] , $ this -> config ) ; $ this -> config -> set ( 'env' , $ this -> getEnvironment ( ) ) ; $ this -> config -> set ( 'debug' , $ this -> getDebug ( ) ) ; $ this -> eventer -> dispatch ( new ConfigLoadedEvent ( $ this -> config ) ) ; $ this -> kernel -> initialize ( ) ; $ this -> eventer -> dispatch ( new KernelInitializedEvent ( $ this -> kernel ) ) ; $ this -> kernel -> boot ( ) ; $ this -> eventer -> dispatch ( new KernelBootedEvent ( $ this -> kernel ) ) ; $ this -> eventer -> dispatch ( new AppStartedEvent ( $ this ) ) ; }
Start App .
23,123
public function shutdown ( ) { if ( ! $ this -> started ) { return ; } $ this -> started = false ; $ this -> kernel -> shutdown ( ) ; $ this -> eventer -> dispatch ( new KernelShutdownEvent ( $ this -> kernel ) ) ; $ this -> eventer -> dispatch ( new AppShutdownEvent ( $ this ) ) ; }
Shutdown App .
23,124
private function renderParameterInformation ( OutputInterface $ output ) { $ table = new Table ( $ output ) ; $ table -> setHeaders ( array ( 'Parameter Name' , 'Parameter Value' ) ) ; $ parameters = $ this -> container -> getParameterBag ( ) -> all ( ) ; ksort ( $ parameters ) ; foreach ( $ parameters as $ name => $ value ) { $ table -> addRow ( array ( $ name , $ value ) ) ; } $ table -> render ( ) ; }
Renders a table that includes all parameters that a developer can use in a build file
23,125
private function renderServiceInformation ( OutputInterface $ output ) { $ table = new Table ( $ output ) ; $ table -> setHeaders ( array ( 'Service ID' , 'Class' ) ) ; $ serviceIds = $ this -> container -> getServiceIds ( ) ; sort ( $ serviceIds ) ; foreach ( $ serviceIds as $ id ) { $ service = $ this -> container -> get ( $ id ) ; $ table -> addRow ( array ( $ id , get_class ( $ service ) ) ) ; } $ table -> render ( ) ; }
Renders a table that has all the services in the container
23,126
public function addSortedSet ( $ key , $ member , $ value ) { $ this -> driver -> zAdd ( $ key , $ value , $ member ) ; }
add data to sorted set .
23,127
public function getSortedRankAsc ( $ key , $ member ) { $ score = $ this -> getScore ( $ key , $ member ) ; if ( $ score === false || $ score === null ) return null ; return $ this -> driver -> zCount ( $ key , '-inf' , -- $ score ) ; }
get sorted set rank by asc
23,128
public function getSortedSets ( $ key , $ start = 0 , $ limit = 20 , $ with_scores = true ) { return $ this -> getSortedSetsAsc ( $ key , $ start , $ limit , $ with_scores ) ; }
get sets with score .
23,129
public function getSortedSetsAsc ( $ key , $ start = 0 , $ limit = 20 , $ with_scores = true ) { return $ this -> driver -> zRangeByScore ( $ key , 0 , '+inf' , [ 'limit' => [ $ start , $ limit ] , 'withscores' => $ with_scores ] ) ; }
get sets with score order by score asc .
23,130
public function getSortedSetsDesc ( $ key , $ start = 0 , $ limit = 20 , $ with_scores = true ) { return $ this -> driver -> zRevRangeByScore ( $ key , '+inf' , 0 , [ 'limit' => [ $ start , $ limit ] , 'withscores' => $ with_scores ] ) ; }
get sets with score order by score desc .
23,131
public function set ( string $ name , $ value ) : Recipe { $ this -> variables -> $ name = $ value ; return $ this ; }
Set a variable to later be passed to Twig .
23,132
public function process ( ) : void { if ( isset ( $ this -> output ) ) { $ this -> output -> call ( $ this ) ; } elseif ( ! $ this -> delegated ) { self :: $ inout -> error ( "Recipe is missing a call to `output` and did not delegate anything, not very useful probably...\n" ) ; } }
Process this recipe .
23,133
public function delegate ( string $ recipe , ... $ args ) : Recipe { ( new Bootstrap ( $ recipe ) ) -> run ( ... $ args ) ; $ this -> delegated = true ; return $ this ; }
Delegate to a sub - recipe .
23,134
public function init ( ) { parent :: init ( ) ; $ this -> on ( FrontendController :: EVENT_BEFORE_ACTION , function ( ) { $ this -> layout = isset ( Yii :: $ app -> params [ 'admin.layout' ] ) ? Yii :: $ app -> params [ 'admin.layout' ] : '@app/views/layouts/main' ; AdminBundle :: register ( $ this -> view ) ; return true ; } ) ; }
Overrides default init adding some additional stuff
23,135
public function generate ( IMetaModel $ metaModel ) : \ Generator { foreach ( $ metaModel -> getAttributes ( ) as $ attribute ) { if ( ! $ attribute instanceof ITranslated ) { continue ; } if ( $ this -> handlerFactories -> has ( $ class = \ get_class ( $ attribute ) ) ) { yield $ attribute -> getColName ( ) => $ this -> handlerFactories -> get ( $ class ) -> create ( $ attribute ) ; } } }
Generate the attribute handlers .
23,136
public function ignore ( $ ignore ) { if ( ! is_array ( $ ignore ) ) { $ ignore = [ $ ignore ] ; } $ this -> ignore = array_unique ( array_merge ( $ this -> ignore , $ ignore ) ) ; return $ this ; }
Add a path or file to ignore .
23,137
public static function findPropertiesNames ( string $ classFqcn , array $ excludedNames = [ ] , array $ excludedVisibility = [ ] ) { $ defaultVisibility = [ 'public' => true , 'protected' => true , 'private' => true , 'static' => true ] ; $ excludedVisibility = array_merge ( $ defaultVisibility , self :: setGivenExcludedVisivilitiesToKeysWithValueFalse ( $ excludedVisibility ) ) ; $ reflectionClass = self :: getReflectionClass ( $ classFqcn ) ; $ reflectionPropertiesArray = $ reflectionClass -> getProperties ( ) ; return self :: filterProperties ( $ excludedNames , $ excludedVisibility , $ reflectionPropertiesArray ) ; }
Returns an array with all properties names of the mixed
23,138
public static function getReflectionProperty ( ReflectionClass $ class , string $ propertyName ) : ReflectionProperty { try { return $ class -> getProperty ( $ propertyName ) ; } catch ( ReflectionException $ e ) { $ parentClass = $ class -> getParentClass ( ) ; if ( $ parentClass === false ) { throw $ e ; } return self :: getReflectionProperty ( $ parentClass , $ propertyName ) ; } }
Gets the property from the current class when not available will look on parent classes before failing
23,139
public function setFirstWeekday ( $ firstWeekday = 0 ) { $ this -> firstWeekday = is_string ( $ firstWeekday ) ? self :: firstWeekday ( $ firstWeekday ) : $ firstWeekday ; $ this -> buildWeekdays = true ; return $ this ; }
Sets the first day of the week in a calendar page view .
23,140
public function map ( callable $ callback ) { $ that = clone $ this ; foreach ( $ that -> getIterator ( ) as $ index => $ item ) { $ that -> offsetSet ( $ index , $ callback ( $ item ) ) ; } return $ that ; }
Apply callback to each element of array
23,141
public function group ( callable $ callback ) { $ array = array ( ) ; foreach ( $ this -> getIterator ( ) as $ index => $ item ) { $ group = $ callback ( $ item ) ; $ array [ $ group ] [ ] = $ item ; } return new static ( $ array ) ; }
Group elements of array
23,142
public function getPermission ( $ permission ) { if ( $ permission instanceof PermissionInterface ) { $ permission = $ permission -> key ; } return $ this -> permissions ( ) -> key ( $ permission ) -> first ( ) ; }
Get the actual permission
23,143
public function give ( PermissionInterface $ permission , $ level = 'allow' ) { $ current = $ this -> getPermission ( $ permission -> key ) ; if ( isset ( $ current ) ) { if ( $ current -> level === $ level ) { return true ; } $ this -> remove ( $ permission ) ; } $ this -> cache ( $ permission -> key , null ) ; $ this -> permissions ( ) -> attach ( $ permission , compact ( 'level' ) ) ; return ! is_null ( $ this -> getPermission ( $ permission ) ) ; }
Give role a permission
23,144
public function remove ( PermissionInterface $ permission ) { $ this -> cache ( $ permission -> key , null ) ; if ( ! is_null ( $ this -> getPermission ( $ permission ) ) ) { $ this -> permissions ( ) -> detach ( $ permission ) ; } return true ; }
Remove a permission from this role
23,145
public function deleteDependents ( Event $ event , $ ids , $ count ) { $ pfk = $ this -> getPrimaryForeignKey ( ) ; $ this -> getJunctionRepository ( ) -> deleteMany ( function ( Query $ query ) use ( $ pfk , $ ids ) { $ query -> where ( $ pfk , $ ids ) ; } ) ; }
Delete records found in the junction table but do not delete records in the foreign table .
23,146
public function getJunctionRepository ( ) { if ( $ repo = $ this -> _junction ) { return $ repo ; } $ this -> setJunctionRepository ( new Repository ( $ this -> getJunction ( ) ) ) ; return $ this -> _junction ; }
Return the junction repository instance .
23,147
public function setJunction ( $ table ) { if ( ! is_array ( $ table ) ) { $ table = [ 'table' => $ table ] ; } $ this -> setConfig ( 'junction' , $ table ) ; return $ this ; }
Set the junction table name .
23,148
private static function parseHeaders ( UrlInterface $ url ) : HeaderCollectionInterface { $ result = new HeaderCollection ( ) ; $ result -> set ( 'Host' , $ url -> getHostAndPort ( ) ) ; return $ result ; }
Parses a url into a header collection .
23,149
private static function parseQueryParameters ( ? string $ queryString ) : ParameterCollectionInterface { $ parameters = new ParameterCollection ( ) ; if ( $ queryString === null ) { return $ parameters ; } parse_str ( $ queryString , $ parametersArray ) ; foreach ( $ parametersArray as $ parameterName => $ parameterValue ) { $ parameters -> set ( $ parameterName , is_array ( $ parameterValue ) ? $ parameterValue [ 0 ] : $ parameterValue ) ; } return $ parameters ; }
Parses a query string into a parameter collection .
23,150
public static function load ( string $ token , array $ config ) : Token { $ fields = [ 'id' , 'h' , 'e' ] ; $ params = [ ] ; parse_str ( self :: base64url_decode ( $ token ) , $ params ) ; foreach ( $ fields as $ f ) { if ( ! array_key_exists ( $ f , $ params ) ) { throw new \ UnexpectedValueException ( '"' . $ f . '" should exists in token attributes.' ) ; } } $ id = Identificator :: load ( $ params [ 'id' ] , $ config [ 'idFields' ] ) ; $ token = new Token ( $ id , $ config ) ; $ token -> setHash ( $ params [ 'h' ] ) ; $ token -> setExpiration ( $ params [ 'e' ] ) ; return $ token ; }
Create new token from string representation
23,151
public function generateHash ( ) : string { $ h = sprintf ( '%s%s%s' , ( string ) $ this -> getIdentificator ( ) , $ this -> getExpiration ( ) , $ this -> getSecret ( ) ) ; $ h = md5 ( $ h , true ) ; $ h = self :: base64url_encode ( $ h ) ; return $ h ; }
Generate new hash for identificator
23,152
public function validate ( ) { if ( time ( ) > $ this -> getExpiration ( ) ) { throw new exceptions \ TokenExpiredException ( 'Token is expired.' ) ; } if ( $ this -> getHash ( ) != $ this -> generateHash ( ) ) { throw new exceptions \ InvalidHashException ( 'Invalid token hash.' ) ; } }
Validate token usually used only when token is loaded from string representation .
23,153
public function setParameters ( array $ params ) { foreach ( $ params as $ name => $ value ) { $ this -> getParameterContainer ( ) -> add ( $ name , $ value ) ; } return $ this ; }
Set multiple parameters
23,154
public function getParameters ( $ asString = false ) { if ( $ asString ) { $ str = ( string ) $ this -> getParameterContainer ( ) ; return $ str ; } return $ this -> getParameterContainer ( ) -> all ( ) ; }
Get all parameters
23,155
public function removeParameter ( $ name ) { if ( $ this -> hasParameter ( $ name ) ) { $ this -> getParameterContainer ( ) -> remove ( $ name ) ; } return $ this ; }
Remove a parameter
23,156
private function addMimeInfo ( ) : void { $ finfoMimeType = new \ finfo ( FILEINFO_MIME_TYPE ) ; $ finfoMimeEncoding = new \ finfo ( FILEINFO_MIME_ENCODING ) ; foreach ( $ this -> variables as $ file => $ data ) { foreach ( $ data as $ varName => $ varVal ) { if ( \ is_array ( $ varVal ) ) { $ this -> variables [ $ file ] [ $ varName ] [ 'encoding' ] = '' ; if ( isset ( $ this -> variables [ $ file ] [ $ varName ] [ 'error' ] ) && $ this -> variables [ $ file ] [ $ varName ] [ 'error' ] === 0 ) { $ finfoFile = $ this -> variables [ $ file ] [ $ varName ] [ 'tmp_name' ] ; $ this -> variables [ $ file ] [ $ varName ] [ 'type' ] = $ finfoMimeType -> file ( $ finfoFile ) ; $ this -> variables [ $ file ] [ $ varName ] [ 'encoding' ] = $ finfoMimeEncoding -> file ( $ finfoFile ) ; } } if ( ! \ is_array ( $ varVal ) ) { $ this -> variables [ $ file ] [ 'encoding' ] = '' ; if ( isset ( $ this -> variables [ $ file ] [ 'error' ] ) && $ this -> variables [ $ file ] [ 'error' ] === 0 ) { $ finfoFile = $ this -> variables [ $ file ] [ 'tmp_name' ] ; $ this -> variables [ $ file ] [ 'type' ] = $ finfoMimeType -> file ( $ finfoFile ) ; $ this -> variables [ $ file ] [ 'encoding' ] = $ finfoMimeEncoding -> file ( $ finfoFile ) ; } } } } }
Adds MIME information to files
23,157
public function get ( string $ variableName = null , int $ type = Variables :: TYPE_ARRAY ) { if ( $ variableName === null ) { throw new BadMethodCallException ( 'Variable name must be specified' ) ; } if ( isset ( $ this -> variables [ 'MFVARS' ] [ $ variableName ] ) ) { return $ this -> variables [ 'MFVARS' ] [ $ variableName ] ; } if ( isset ( $ this -> variables [ $ variableName ] ) ) { return $ this -> variables [ $ variableName ] ; } return [ ] ; }
Returns FILES variable s value . If variable doesn t exist method returns default value for specified type .
23,158
private function publish ( $ register ) { $ this -> publishConfig ( $ register ) ; $ this -> publishPublicFolder ( $ register ) ; $ this -> publishAssets ( $ register ) ; $ this -> publishCommands ( $ register ) ; $ this -> publishMigrations ( $ register ) ; $ this -> publishLanguages ( $ register ) ; $ this -> publishViews ( $ register ) ; $ this -> publishRoutes ( $ register ) ; $ this -> publishControllers ( $ register ) ; $ this -> publishMiddleware ( $ register ) ; $ this -> publishDrivers ( $ register ) ; $ this -> publishServices ( $ register ) ; $ this -> publishBootstraps ( $ register ) ; $ this -> enablePackage ( $ register ) ; }
Register and unregister the plugin
23,159
private function getNamespace ( $ composerJson ) { if ( ! file_exists ( $ composerJson ) ) { throw new InvalidArgumentException ( '"' . $ composerJson . '" not found.' ) ; } $ composer = json_decode ( file_get_contents ( $ composerJson ) , true ) ; $ autoload = isset ( $ composer [ 'autoload' ] [ 'psr-4' ] ) ? array_flip ( $ composer [ 'autoload' ] [ 'psr-4' ] ) : [ ] ; if ( ! isset ( $ autoload [ 'src/' ] ) ) { throw new InvalidArgumentException ( 'psr-4 autoload directive for folder "src/" is missing in ' . $ composerJson . '.' ) ; } return $ autoload [ 'src/' ] ; }
Read the namespace from composer . json
23,160
private function publishConfig ( $ register ) { $ src = $ this -> path . '/config.php' ; if ( ! file_exists ( $ src ) ) { return ; } $ dest = config_path ( $ this -> plugin . '.php' ) ; if ( file_exists ( $ dest ) ) { return ; } if ( $ register ) { copy ( $ src , $ dest ) ; } }
Copy the config if not already done
23,161
private function publishPublicFolder ( $ register ) { $ publicPath = $ this -> path . '/public' ; if ( ! file_exists ( $ publicPath ) ) { return ; } $ files = [ ] ; list_files ( $ files , $ publicPath ) ; $ publicPathLength = strlen ( $ publicPath ) + 1 ; foreach ( $ files as $ file ) { $ destDir = public_path ( substr ( dirname ( $ file ) , $ publicPathLength ) ) ; if ( ! file_exists ( $ destDir ) ) { if ( ! make_dir ( $ destDir , 0755 ) ) { throw new RuntimeException ( 'Unable to create directory ' . $ destDir ) ; } } $ dest = $ destDir . DIRECTORY_SEPARATOR . basename ( $ file ) ; if ( $ register ) { copy ( $ file , $ dest ) ; } else { if ( file_exists ( $ dest ) ) { unlink ( $ dest ) ; } } } }
Copy the public folder
23,162
private function publishAssets ( $ register ) { $ build = $ this -> path . '/assets/build.php' ; if ( ! file_exists ( $ build ) ) { return ; } if ( ! $ register ) { DI :: getInstance ( ) -> get ( 'asset-manager' ) -> remove ( null , $ this -> plugin ) ; } $ manifest = $ this -> getManifest ( 'assets' ) ; $ list = file_exists ( $ manifest ) ? include $ manifest : [ ] ; if ( $ register ) { $ basePath = base_path ( ) ; $ basePathLength = strlen ( $ basePath ) ; $ assets = include $ build ; foreach ( $ assets as $ asset => $ sources ) { foreach ( $ sources as $ i => $ source ) { if ( substr ( $ source , 0 , $ basePathLength ) == $ basePath ) { $ assets [ $ asset ] [ $ i ] = substr ( $ source , $ basePathLength + 1 ) ; } } } $ list [ $ this -> plugin ] = $ assets ; } else { unset ( $ list [ $ this -> plugin ] ) ; } $ this -> saveArray ( $ manifest , $ list ) ; if ( $ register ) { DI :: getInstance ( ) -> get ( 'asset-manager' ) -> publish ( null , true , $ this -> plugin ) ; } }
Update manifest assets . php and run the Asset Manager to publish the assets .
23,163
private function publishCommands ( $ register ) { $ commandPath = $ this -> path . '/src/Commands' ; if ( ! file_exists ( $ commandPath ) ) { return ; } $ classes = [ ] ; list_classes ( $ classes , $ commandPath , $ this -> namespace . 'Commands' ) ; $ manifest = $ this -> getManifest ( 'commands' ) ; $ list = file_exists ( $ manifest ) ? include $ manifest : [ ] ; foreach ( $ classes as $ class ) { $ command = new $ class ; $ name = $ command -> name ( ) ; if ( $ register ) { $ description = trim ( $ command -> description ( ) ? : '' ) ; $ list [ $ name ] = compact ( 'class' , 'name' , 'description' ) ; } else { unset ( $ list [ $ name ] ) ; } } ksort ( $ list ) ; $ this -> saveArray ( $ manifest , $ list ) ; }
Update manifest commands . php
23,164
private function publishMigrations ( $ register ) { $ migrationPath = $ this -> path . '/migrations' ; if ( ! file_exists ( $ migrationPath ) ) { return ; } $ files = [ ] ; list_files ( $ files , $ migrationPath , [ 'php' ] ) ; $ manifest = $ this -> getManifest ( 'migrations' ) ; $ list = file_exists ( $ manifest ) ? include $ manifest : [ ] ; $ basePathLength = strlen ( base_path ( ) ) + 1 ; foreach ( $ files as $ file ) { $ name = basename ( $ file , '.php' ) ; if ( $ register ) { $ list [ $ name ] = substr ( $ file , $ basePathLength ) ; } else { unset ( $ list [ $ name ] ) ; } } $ this -> saveArray ( $ manifest , $ list ) ; }
Update manifest migrations . php
23,165
private function publishLanguages ( $ register ) { $ langPath = $ this -> path . '/lang' ; if ( ! file_exists ( $ langPath ) ) { return ; } $ files = [ ] ; list_files ( $ files , $ langPath , [ 'php' ] , false ) ; $ manifest = $ this -> getManifest ( 'languages' ) ; $ list = file_exists ( $ manifest ) ? include $ manifest : [ ] ; $ basePathLength = strlen ( base_path ( ) ) + 1 ; foreach ( $ files as $ file ) { $ locale = basename ( $ file , '.php' ) ; if ( $ register ) { if ( ! isset ( $ list [ $ locale ] ) ) { $ list [ $ locale ] = [ ] ; } $ list [ $ locale ] [ $ this -> plugin ] = substr ( $ file , $ basePathLength ) ; } else { if ( isset ( $ list [ $ locale ] ) ) { unset ( $ list [ $ locale ] [ $ this -> plugin ] ) ; if ( empty ( $ list [ $ locale ] ) ) { unset ( $ list [ $ locale ] ) ; } } } } $ this -> saveArray ( $ manifest , $ list ) ; }
Update the language files .
23,166
private function publishViews ( $ register ) { $ visitPath = $ this -> path . '/views' ; if ( ! file_exists ( $ visitPath ) ) { return ; } $ files = [ ] ; list_files ( $ files , $ visitPath , [ 'php' ] ) ; $ manifest = $ this -> getManifest ( 'views' ) ; $ list = file_exists ( $ manifest ) ? include $ manifest : [ ] ; $ visitPathLength = strlen ( $ visitPath ) + 1 ; $ basePathLength = strlen ( base_path ( ) ) + 1 ; foreach ( $ files as $ file ) { if ( substr ( $ file , - 10 ) == '.blade.php' ) { $ name = $ this -> plugin . '.' . str_replace ( DIRECTORY_SEPARATOR , '.' , substr ( $ file , $ visitPathLength , - 10 ) ) ; if ( $ register ) { $ list [ $ name ] = substr ( $ file , $ basePathLength ) ; } else { unset ( $ list [ $ name ] ) ; } } } $ this -> saveArray ( $ manifest , $ list ) ; }
Update manifest views . php
23,167
private function publishClasses ( $ register , $ subfolder ) { $ path = $ this -> path . '/src/' . $ subfolder ; if ( ! file_exists ( $ path ) ) { return ; } $ classes = [ ] ; $ ns = $ this -> namespace . $ subfolder ; list_classes ( $ classes , $ path , $ ns ) ; $ manifest = $ this -> getManifest ( lcfirst ( $ subfolder ) ) ; $ list = file_exists ( $ manifest ) ? include $ manifest : [ ] ; $ len = strlen ( $ ns ) ; foreach ( $ classes as $ class ) { if ( strpos ( $ class , '\\Contracts\\' ) !== false ) { continue ; } $ name = substr ( $ class , $ len + 1 ) ; if ( $ register ) { if ( ! isset ( $ list [ $ name ] ) ) { $ list [ $ name ] = [ ] ; } if ( ( $ i = array_search ( $ class , $ list [ $ name ] ) ) === false ) { $ list [ $ name ] [ ] = $ class ; } } else { if ( isset ( $ list [ $ name ] ) && ( $ i = array_search ( $ class , $ list [ $ name ] ) ) !== false ) { unset ( $ list [ $ name ] [ $ i ] ) ; if ( empty ( $ list [ $ name ] ) ) { unset ( $ list [ $ name ] ) ; } else { $ list [ $ name ] = array_values ( $ list [ $ name ] ) ; } } } } $ this -> saveArray ( $ manifest , $ list ) ; }
Update manifest classes . php
23,168
private function publishDrivers ( $ register ) { $ path = $ this -> path . '/src/Drivers' ; if ( ! file_exists ( $ path ) ) { return ; } $ classes = [ ] ; $ ns = $ this -> namespace . 'Drivers' ; list_classes ( $ classes , $ path , $ ns ) ; $ manifest = $ this -> getManifest ( 'drivers' ) ; $ list = file_exists ( $ manifest ) ? include $ manifest : [ ] ; $ len = strlen ( $ ns ) ; foreach ( $ classes as $ class ) { if ( strpos ( $ class , '\\Contracts\\' ) !== false ) { continue ; } $ name = substr ( $ class , $ len + 1 ) ; if ( ( $ pos = strpos ( $ name , '\\' ) ) !== false ) { $ group = substr ( $ name , 0 , $ pos ) ; $ name = substr ( $ name , $ pos + 1 ) ; } else { $ group = '' ; } if ( $ register ) { if ( ! isset ( $ list [ $ group ] ) ) { $ list [ $ group ] = [ ] ; } if ( ! isset ( $ list [ $ group ] [ $ name ] ) ) { $ list [ $ group ] [ $ name ] = [ ] ; } if ( ( $ i = array_search ( $ class , $ list [ $ group ] [ $ name ] ) ) === false ) { $ list [ $ group ] [ $ name ] [ ] = $ class ; } } else { if ( isset ( $ list [ $ group ] [ $ name ] ) && ( $ i = array_search ( $ class , $ list [ $ group ] [ $ name ] ) ) !== false ) { unset ( $ list [ $ group ] [ $ name ] [ $ i ] ) ; if ( empty ( $ list [ $ group ] [ $ name ] ) ) { unset ( $ list [ $ group ] [ $ name ] ) ; } else { $ list [ $ group ] [ $ name ] = array_values ( $ list [ $ group ] [ $ name ] ) ; } if ( empty ( $ list [ $ group ] ) ) { unset ( $ list [ $ group ] ) ; } } } } $ this -> saveArray ( $ manifest , $ list ) ; }
Update manifest drivers . php
23,169
private function publishRoutes ( $ register ) { if ( $ register && ( isset ( $ this -> options [ 'no-routes' ] ) && $ this -> options [ 'no-routes' ] == true ) ) { return ; } if ( ! file_exists ( $ this -> path . '/boot/routes.php' ) ) { return ; } $ packages = $ this -> listPackages ( $ register ) ; $ dest = '' ; foreach ( $ packages as $ package => $ path ) { $ file = base_path ( $ path . '/boot/routes.php' ) ; if ( ! file_exists ( $ file ) ) { continue ; } $ src = trim ( file_get_contents ( $ file ) ) ; if ( substr ( $ src , 0 , 5 ) == '<?php' ) { $ src = trim ( substr ( $ src , 5 ) ) ; } if ( substr ( $ src , - 2 ) == '?>' ) { $ src = trim ( substr ( $ src , 0 , - 2 ) ) ; } $ src = trim ( preg_replace ( '/\\$router\\s*=\\s*\\\\?Core\\\\Application::router\\(\\);/' , '' , $ src ) ) ; $ src = trim ( preg_replace ( '/use Core\\\\Services\\\\Contracts\\\\Router;/' , '' , $ src ) ) ; if ( $ dest == '' ) { $ dest = PHP_EOL . 'use Core\Services\Contracts\Router;' . PHP_EOL . PHP_EOL . '$router = \Core\Application::router();' . PHP_EOL ; } $ dest .= PHP_EOL . '///////////////////////////////////////////////////////////////////////////////' . PHP_EOL . '// ' . $ package . PHP_EOL . PHP_EOL . $ src . PHP_EOL ; } $ this -> saveContent ( $ this -> getManifest ( 'routes' ) , '<?php' . PHP_EOL . $ dest ) ; }
Update manifest routes . php
23,170
private function publishServices ( $ register ) { if ( ! file_exists ( $ this -> path . '/boot/services.php' ) ) { return ; } $ packages = $ this -> listPackages ( $ register ) ; $ dest = '' ; foreach ( $ packages as $ package => $ path ) { $ file = base_path ( $ path . '/boot/services.php' ) ; if ( ! file_exists ( $ file ) ) { continue ; } $ src = trim ( file_get_contents ( $ file ) ) ; if ( substr ( $ src , 0 , 5 ) == '<?php' ) { $ src = trim ( substr ( $ src , 5 ) ) ; } if ( substr ( $ src , - 2 ) == '?>' ) { $ src = trim ( substr ( $ src , 0 , - 2 ) ) ; } $ src = trim ( preg_replace ( '/\$di\s*=\s*\\\\Core\\\\Services\\\\DI::getInstance\(\);/' , '' , $ src ) ) ; if ( $ dest == '' ) { $ dest = PHP_EOL . '$di = \Core\Services\DI::getInstance();' . PHP_EOL ; } $ dest .= PHP_EOL . '///////////////////////////////////////////////////////////////////////////////' . PHP_EOL . '// ' . $ package . PHP_EOL . PHP_EOL . $ src . PHP_EOL ; } $ this -> saveContent ( $ this -> getManifest ( 'services' ) , '<?php' . PHP_EOL . $ dest ) ; }
Update manifest services . php
23,171
private function publishBootstraps ( $ register ) { $ classes = [ ] ; if ( file_exists ( $ this -> path . '/src/Bootstraps' ) ) { list_classes ( $ classes , $ this -> path . '/src/Bootstraps' , $ this -> namespace . 'Bootstraps' ) ; } if ( empty ( $ classes ) ) { return ; } $ packages = $ this -> listPackages ( $ register ) ; $ dest = '' ; foreach ( $ packages as $ package => $ relativePath ) { $ path = base_path ( $ relativePath ) ; $ classes = [ ] ; if ( file_exists ( $ path . '/src/Bootstraps' ) ) { $ namespace = $ this -> getNamespace ( $ path . '/composer.json' ) ; list_classes ( $ classes , $ path . '/src/Bootstraps' , $ namespace . 'Bootstraps' ) ; } if ( empty ( $ classes ) ) { continue ; } $ dest .= PHP_EOL . '///////////////////////////////////////////////////////////////////////////////' . PHP_EOL . '// ' . $ package . PHP_EOL . PHP_EOL ; foreach ( $ classes as $ class ) { $ dest .= '(new ' . $ class . ')->boot();' . PHP_EOL ; } } $ this -> saveContent ( $ this -> getManifest ( 'bootstrap' ) , '<?php' . PHP_EOL . $ dest ) ; }
Update manifest bootstraps . php .
23,172
private function saveArray ( $ file , $ array ) { if ( file_put_contents ( $ file , '<?php return ' . var_export ( $ array , true ) . ';' . PHP_EOL , LOCK_EX ) === false ) { throw new RuntimeException ( 'Plugin Manager is not able to save ' . $ file . '.' ) ; } }
Save array as an include file .
23,173
public function registerOptionPage ( $ pluginName = null ) { add_action ( 'admin_init' , array ( & $ this , 'adminInit' ) ) ; if ( $ this -> multiSite ) { add_action ( 'network_admin_menu' , array ( & $ this , 'networkAdminMenu' ) ) ; add_action ( 'update_wpmu_options' , array ( & $ this , 'adminUpdateOptions' ) ) ; } else { add_action ( 'admin_menu' , array ( & $ this , 'adminMenu' ) ) ; } if ( $ pluginName ) { add_filter ( "plugin_action_links_" . $ pluginName , array ( & $ this , 'settingsLink' ) ) ; } }
Register WP hooks to render admin page . Should be called inside of WP_Loaded hook but can be called either after or before adding the settings .
23,174
public function addSetting ( $ name , $ label , $ renderer = null , $ args = null , $ default = null ) { if ( ! $ renderer ) $ renderer = array ( $ this , 'createSettingsTextbox' ) ; $ this -> settings [ ] = array ( 'name' => $ name , 'label' => $ label , 'renderer' => $ renderer , 'args' => $ args , 'default' => $ default ) ; }
Register a new setting
23,175
public function adminUpdateOptions ( ) { if ( isset ( $ _GET [ 'settings' ] ) && $ _GET [ 'settings' ] == $ this -> settingsName ) { $ cleanPost = $ _POST ; if ( function_exists ( 'wp_magic_quotes' ) ) { $ cleanPost = array_map ( 'stripslashes_deep' , $ cleanPost ) ; } $ options = $ cleanPost [ $ this -> settingsName ] ; $ options = $ this -> onSanitizeOptions ( $ options ) ; update_site_option ( $ this -> settingsName , $ options ) ; wp_redirect ( network_admin_url ( 'settings.php?updated=true&page=' . $ this -> settingsName ) ) ; exit ( ) ; } }
Used for network settings page
23,176
public function getOption ( $ optionName = null ) { if ( $ this -> multiSite ) { $ options = get_site_option ( $ this -> settingsName ) ; } else { $ options = get_option ( $ this -> settingsName ) ; } if ( ! $ optionName ) return $ options ; if ( is_array ( $ options ) && isset ( $ options [ $ optionName ] ) ) return $ options [ $ optionName ] ; foreach ( $ this -> settings as $ setting ) { if ( $ setting [ 'name' ] == $ optionName ) { if ( ! empty ( $ setting [ 'default' ] ) ) return $ setting [ 'default' ] ; break ; } } return null ; }
Retrieve option value . If the option is not set and a default was provided when adding the setting it will be returned instead .
23,177
static function saveIncludedFiles ( $ filename , $ fromFile ) { if ( file_exists ( $ filename ) ) { $ all_included_files = json_decode ( file_get_contents ( $ filename ) , JSON_OBJECT_AS_ARRAY ) ; } else { $ all_included_files = array ( ) ; } foreach ( get_included_files ( ) as $ includedFile ) { if ( ! isset ( $ all_included_files [ $ includedFile ] ) ) { $ all_included_files [ $ includedFile ] = array ( ) ; } if ( ! in_array ( $ fromFile , $ all_included_files [ $ includedFile ] ) ) { array_push ( $ all_included_files [ $ includedFile ] , $ fromFile ) ; } } file_put_contents ( $ filename , json_encode ( $ all_included_files ) ) ; }
Used to inspect shit
23,178
public function setIdentity ( $ identity = null ) { if ( null === $ identity ) { $ this -> setResult ( ) ; } $ this -> setParam ( 'identity' , $ identity ) ; return $ this ; }
Sets the identity .
23,179
public function boot ( ) { $ this -> getContainer ( ) -> addProvider ( ArraySerializerProvider :: class ) -> addProvider ( JsonSerializerProvider :: class ) -> addProvider ( CompressorProvider :: class ) -> addProvider ( ArrayCacheDriver :: class ) ; }
register new providers or something
23,180
public static function search ( $ query , $ callback = null ) { if ( config ( 'livecms.deepsearch' , false ) ) { return static :: LaravelSearch ( $ query , $ callback ) ; } $ instance = new static ; if ( $ instance instanceof PostableModel ) { $ mandatoryField = 'title' ; $ selectFields = [ 'id' , 'title' , 'slug' , 'published_at' , 'status' , 'author_id' ] ; return $ instance -> select ( $ selectFields ) -> where ( $ mandatoryField , 'like' , '%' . $ query . '%' ) ; } else { $ mandatoryField = strtolower ( ( new \ ReflectionClass ( $ instance ) ) -> getShortName ( ) ) ; if ( in_array ( $ mandatoryField , $ instance -> getFillable ( ) ) ) { return $ instance -> where ( $ mandatoryField , 'like' , '%' . $ query . '%' ) ; } } return $ instance -> where ( $ instance -> getKeyName ( ) , null ) ; }
Override Laravel Scout s search .
23,181
public function update ( $ token , $ _params = array ( ) ) { return $ this -> transform ( $ this -> master -> put ( 'resources/' . $ token , $ _params ) , true ) ; }
Update a single resource
23,182
public static function getMethodFromAction ( string $ action ) : string { $ method = str_replace ( [ '.' , '-' , '_' ] , ' ' , $ action ) ; $ method = ucwords ( $ method ) ; $ method = str_replace ( ' ' , '' , $ method ) ; $ method = lcfirst ( $ method ) ; $ method .= 'Action' ; return $ method ; }
Transform an action token into a method name
23,183
public function plugin ( string $ name , array $ options = [ ] ) : PluginInterface { return $ this -> getPluginManager ( ) -> get ( $ name , $ options ) ; }
Get plugin instance
23,184
public function locateRootDirectory ( ) { $ vendorDirectoryName = 'vendor' ; $ fileDirectory = __DIR__ ; $ searchDirectories = [ __DIR__ . '/..' , __DIR__ . '/../..' , __DIR__ . '/../../..' , __DIR__ . '/../../../..' , __DIR__ . '/../../../../..' ] ; $ fileSystem = $ this -> createNew ( FileSystem :: class ) ; foreach ( $ searchDirectories as $ searchDirectory ) { if ( $ fileSystem -> fileExists ( $ searchDirectory . '/' . $ vendorDirectoryName ) ) { return $ fileSystem -> getRealPath ( $ searchDirectory ) ; } } throw new FileSystemException ( 'No application root directory found' ) ; }
Attempts to find the root directory
23,185
public function getRootDirectory ( ) { if ( isset ( $ this -> rootDirectory ) == false ) { $ this -> rootDirectory = $ this -> locateRootDirectory ( ) ; } return $ this -> rootDirectory ; }
Get the root directory
23,186
protected function get ( $ objectName , $ datas = null ) { if ( isset ( $ this -> bag [ $ objectName ] ) ) { return $ this -> bag [ $ objectName ] ; } if ( $ this -> cacheDriver ) { if ( ( $ cached = $ this -> cacheDriver -> fetch ( $ objectName . $ this -> cacheSalt ) ) !== false ) { $ this -> bag [ $ objectName ] = $ cached ; } else { $ this -> load ( $ objectName , $ datas ) ; $ this -> cacheDriver -> save ( $ objectName . $ this -> getCacheSalt ( ) , $ this -> bag [ $ objectName ] ) ; } } else { $ this -> load ( $ objectName , $ datas ) ; } return $ this -> bag [ $ objectName ] ; }
Call this method to get the object
23,187
private function load ( $ objectName , $ datas ) { if ( ! $ this -> initialized ) { $ this -> initialize ( ) ; $ this -> initialized = true ; } $ this -> bag [ $ objectName ] = $ this -> doLoad ( isset ( $ datas ) ? $ datas : $ objectName ) ; }
Initialise factory construct new object instance and store it in bag
23,188
public function appNameSpace ( ) { $ app_dir = $ this -> appDir ( ) ; $ root_dir = $ this -> rootDir ( ) ; $ ns_path = substr ( $ app_dir , strlen ( $ root_dir ) + 1 ) ; return str_replace ( DS , '\\' , $ ns_path ) ; }
app namespace accessor .
23,189
public function absolutize ( ) { $ new = [ ] ; $ path = $ this -> path ; if ( $ path [ 0 ] !== '/' ) $ path = $ this -> cwd . DS . $ this -> path ; $ paths = explode ( DS , $ path ) ; foreach ( $ paths as $ p ) { switch ( $ p ) { case '.' : break ; case '..' : array_pop ( $ new ) ; if ( ! $ new ) $ new [ ] = '' ; break ; default : $ new [ ] = $ p ; break ; } } $ this -> path = join ( DS , $ new ) ; }
relational path to absolute path .
23,190
public static function create ( $ namespace = null , $ name = null ) { if ( null === $ namespace ) { return self :: createNamespacelessUuid ( ) ; } return self :: createNamespacedUuid ( $ namespace , $ name ) ; }
Returns an Uuid identifier .
23,191
private static function generate ( $ uuidKey , array $ arguments ) { $ classAndMethod = \ explode ( '::' , self :: $ uuidMap [ $ uuidKey ] ) ; return \ call_user_func_array ( $ classAndMethod , $ arguments ) ; }
Call a Uuid generator and returns an Uuid identifier .
23,192
protected function getEvent ( ) { if ( null === $ this -> event ) { $ this -> event = $ event = new EntityEvent ; $ event -> setTarget ( $ this ) ; } return $ this -> event ; }
Get the pre initialized event object
23,193
public function setEventManager ( EventManagerInterface $ eventManager ) { if ( $ this -> eventManager === $ eventManager || $ eventManager === null ) { return ; } if ( $ this -> eventManager !== null ) { $ this -> detach ( $ this -> eventManager ) ; } $ this -> eventManager = $ eventManager ; $ this -> eventManager -> addIdentifiers ( [ 'EntityService' , 'PolderKnowledge\EntityService\Service\EntityService' , $ this -> getEntityServiceName ( ) , trim ( $ this -> getEntityServiceName ( ) , '\\' ) , ] ) ; $ this -> attach ( $ this -> eventManager ) ; }
Set the EventManager used by this service instance to handle its events . It will take care of disabling the old EventManager and will subscribe the internal listeners to the new EventManager
23,194
public function delete ( $ entity ) { if ( ! $ this -> isRepositoryDeletable ( ) ) { throw $ this -> createNotDeletableException ( ) ; } return $ this -> trigger ( __FUNCTION__ , [ 'entity' => $ entity , ] ) ; }
Deletes the given object from the repository
23,195
public function deleteBy ( $ criteria ) { if ( ! $ this -> isRepositoryDeletable ( ) ) { throw $ this -> createNotDeletableException ( ) ; } return $ this -> trigger ( __FUNCTION__ , [ 'criteria' => $ criteria , ] ) ; }
Deletes all objects matching the criteria from the repository
23,196
public function countBy ( $ criteria ) { if ( ! $ this -> isRepositoryReadable ( ) ) { throw $ this -> createNotReadableException ( ) ; } return $ this -> trigger ( __FUNCTION__ , [ 'criteria' => $ criteria , ] ) ; }
Count the objects matching the criteria respecting the order limit and offset .
23,197
public function findBy ( $ criteria ) { if ( ! $ this -> isRepositoryReadable ( ) ) { throw $ this -> createNotReadableException ( ) ; } return $ this -> trigger ( __FUNCTION__ , [ 'criteria' => $ criteria , ] ) ; }
Find one or more objects in the repository matching the criteria respecting the order limit and offset
23,198
public function findOneBy ( $ criteria ) { if ( ! $ this -> isRepositoryReadable ( ) ) { throw $ this -> createNotReadableException ( ) ; } return $ this -> trigger ( __FUNCTION__ , [ 'criteria' => $ criteria , ] ) ; }
Find one object in the repository matching the criteria
23,199
public function persist ( $ entity ) { if ( ! $ this -> isRepositoryWritable ( ) ) { throw $ this -> createNotWritableException ( ) ; } return $ this -> trigger ( __FUNCTION__ , [ 'entity' => $ entity , ] ) ; }
Persist the given entity