idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
22,300
public static function gc ( $ name ) { $ files = glob ( self :: $ folder . "/{$name}_*.log" ) ; foreach ( $ files as $ filename ) { $ date = str_replace ( self :: $ folder . "/{$name}_" , "" , $ filename ) ; $ date = str_replace ( ".log" , "" , $ date ) ; if ( time ( ) - strtotime ( $ date ) > self :: $ rotate * 3600 * 24 ) { unlink ( $ filename ) ; } } }
gc the roate files
22,301
public function log ( ) { global $ wp_query ; if ( ! $ wp_query -> is_search ( ) || max ( 1 , get_query_var ( 'paged' ) ) > 1 ) { return ; } global $ wpdb ; $ query = get_search_query ( ) ; $ hits = $ wp_query -> found_posts ; $ siteId = null ; $ loggedIn = is_user_logged_in ( ) ; if ( isset ( $ _COOKIE [ 'search_log' ] ) && is_array ( unserialize ( stripslashes ( $ _COOKIE [ 'search_log' ] ) ) ) && in_array ( $ query , unserialize ( stripslashes ( $ _COOKIE [ 'search_log' ] ) ) ) ) { return ; } if ( is_multisite ( ) && function_exists ( 'get_current_blog_id' ) ) { $ siteId = get_current_blog_id ( ) ; } $ insertedId = $ wpdb -> insert ( \ SearchStatistics \ App :: $ dbTable , array ( 'query' => $ query , 'results' => $ hits , 'site_id' => $ siteId , 'logged_in' => $ loggedIn ) , array ( '%s' , '%d' , '%d' , '%d' ) ) ; $ cookie = array ( ) ; if ( isset ( $ _COOKIE [ 'search_log' ] ) && is_array ( $ _COOKIE [ 'search_log' ] ) ) { $ cookie = $ _COOKIE [ 'search_log' ] ; } $ cookie [ ] = $ query ; setcookie ( 'search_log' , serialize ( $ cookie ) , time ( ) + ( 86400 * 1 ) , "/" ) ; }
Log search query to the database
22,302
public function setEmitter ( $ entityClass , EmitterInterface $ emitter ) { $ this -> emitters -> set ( $ entityClass , $ emitter ) ; return $ this ; }
Sets the emitter for provided class name
22,303
public function getRepositoryFor ( $ entityClass ) { if ( ! is_subclass_of ( $ entityClass , EntityInterface :: class ) ) { throw new InvalidArgumentException ( 'Cannot create ORM repository for a class that does not ' . 'implement EntityInterface.' ) ; } return $ this -> repositories -> containsKey ( $ entityClass ) ? $ this -> repositories -> get ( $ entityClass ) : $ this -> createRepository ( $ entityClass ) ; }
Gets repository for provided entity class name
22,304
public function getMapperFor ( $ entity ) { return $ this -> mappers -> containsKey ( $ entity ) ? $ this -> mappers -> get ( $ entity ) : $ this -> createMapper ( $ entity ) ; }
Retrieves the mapper for provided entity
22,305
public function getEmitterFor ( $ entity ) { $ emitter = $ this -> emitters -> containsKey ( $ entity ) ? $ this -> emitters -> get ( $ entity ) : $ this -> createEmitter ( $ entity ) ; return $ emitter ; }
Gets the event emitter for provided entity
22,306
public function setAdapter ( $ alias , AdapterInterface $ adapter ) { $ this -> adapters -> set ( $ alias , $ adapter ) ; return $ this ; }
Sets an adapter mapped with alias name
22,307
private function createRepository ( $ entityClass ) { $ repository = new EntityRepository ( ) ; $ repository -> setAdapter ( $ this -> adapters -> get ( $ this -> getAdapterAlias ( $ entityClass ) ) ) -> setEntityMapper ( $ this -> getMapperFor ( $ entityClass ) ) -> setEntityDescriptor ( EntityDescriptorRegistry :: getInstance ( ) -> getDescriptorFor ( $ entityClass ) ) ; $ this -> repositories -> set ( $ entityClass , $ repository ) ; return $ repository ; }
Creates a repository for provided entity class name
22,308
private function createMapper ( $ entity ) { $ mapper = new EntityMapper ( ) ; $ mapper -> setAdapter ( $ this -> adapters -> get ( $ this -> getAdapterAlias ( $ entity ) ) ) -> setEntityClassName ( $ entity ) ; $ this -> mappers -> set ( $ entity , $ mapper ) ; return $ mapper ; }
Creates entity map for provided entity
22,309
private function createEmitter ( $ entity ) { $ emitter = new Emitter ( ) ; $ this -> emitters -> set ( $ entity , $ emitter ) ; return $ emitter ; }
Creates an emitter for provided entity class name
22,310
private function getAdapterAlias ( $ entity ) { $ descriptor = EntityDescriptorRegistry :: getInstance ( ) -> getDescriptorFor ( $ entity ) ; return $ descriptor -> getAdapterAlias ( ) ? $ descriptor -> getAdapterAlias ( ) : 'default' ; }
Gets the adapter alias for current working entity
22,311
public static function parseSelector ( $ text ) { $ text = preg_replace ( '/(\>|\+|~)\s+/is' , '$1' , $ text ) ; $ selector = null ; foreach ( preg_split ( '/\s+/' , $ text , - 1 , PREG_SPLIT_NO_EMPTY ) as $ part ) { if ( ! preg_match ( '/^([\>\+~]?)([^ >\+~]+)$/is' , $ part , $ matches ) ) throw new \ Exception ( "Invalid selector part '$part'" ) ; $ selector = $ selector ? $ selector -> add ( $ matches [ 1 ] ? $ matches [ 1 ] : false ) : Selector :: create ( ) ; $ offset = 0 ; $ subtext = $ matches [ 2 ] ; while ( $ offset < strlen ( $ subtext ) ) { if ( ! preg_match ( '/^([\.:#]?)((:?[a-z0-9\-]|\*)+)/is' , substr ( $ subtext , $ offset ) , $ matches ) ) throw new \ Exception ( "Invalid property at '" . substr ( $ text , $ offset , 20 ) . "'" ) ; switch ( $ matches [ 1 ] ) { case '' : $ selector -> setTagName ( $ matches [ 2 ] ) ; break ; case '#' : $ selector -> setIdentification ( $ matches [ 2 ] ) ; break ; case '.' : $ selector -> addClass ( $ matches [ 2 ] ) ; break ; case ':' : $ selector -> addPseudo ( $ matches [ 2 ] ) ; break ; default : throw new \ Exception ( "Knonwn type '" . $ matches [ 1 ] . "'" ) ; } $ offset += strlen ( $ matches [ 0 ] ) ; } } return $ selector -> get ( ) ; }
Parses a selector
22,312
protected function evaluateResult ( $ field , $ result , $ message ) { $ this -> messages = [ ] ; if ( $ result ) { return true ; } else { if ( is_array ( $ field [ 'name' ] ) ) { foreach ( $ field [ 'name' ] as $ name ) { $ this -> messages [ $ name ] [ ] = $ field [ 'options' ] [ 'message' ] ?? $ message ; } } else { $ this -> messages [ $ field [ 'name' ] ] [ ] = $ field [ 'options' ] [ 'message' ] ?? $ message ; } return false ; } }
Utility function that evaluates the result of a validation test and prepares validation messages . Receives a boolean from the validation function and a message to be displayed when the value is false . It also receives the options array so it could override the standard message that the validation code generates .
22,313
protected function getFieldValue ( $ field , $ data ) { $ value = null ; if ( isset ( $ data [ $ field [ 'name' ] ] ) ) { $ value = $ data [ $ field [ 'name' ] ] ; } return $ value ; }
Extracts the value of the field description from the data passed .
22,314
public function setPort ( $ port ) { if ( ! is_int ( $ port ) || $ port < 0 || $ port > 65535 ) { throw new InvalidArgumentException ( sprintf ( '%s only accepts a port between 0 and 65535 inclusive' , __FUNCTION__ ) ) ; } $ this -> port = $ port ; return $ this ; }
Set the port to connect to .
22,315
public function setSSL ( $ isEnabled ) { if ( ! is_bool ( $ isEnabled ) ) { throw new InvalidArgumentException ( sprintf ( '%s only accepts a boolean' , __FUNCTION__ ) ) ; } $ this -> ssl = ( bool ) $ isEnabled ; return $ this ; }
Set if SSL should be used for the connection .
22,316
public function setTLS ( $ isEnabled ) { if ( ! is_bool ( $ isEnabled ) ) { throw new InvalidArgumentException ( sprintf ( '%s only accepts a boolean' , __FUNCTION__ ) ) ; } $ this -> tls = ( bool ) $ isEnabled ; return $ this ; }
Set if TLS should be used for the connection .
22,317
private function checkPermissions ( $ style ) { $ warnings = [ ] ; foreach ( $ this -> procedure -> getCommands ( ) as $ command ) { if ( ! $ command -> hasPublicMethod ( 'recommendsRoot' ) ) continue ; if ( $ command -> recommendsRoot ( ) && ! ShellUser :: getInstance ( ) -> isRoot ( ) ) { $ name = $ command -> getName ( ) ; $ user = ShellUser :: getInstance ( ) -> getName ( ) ; $ warnings [ ] = "Command $name recommends running as root, currently $user." ; } } if ( ! empty ( $ warnings ) ) { $ style -> warning ( $ warnings ) ; if ( $ style -> confirm ( "Would you like to abort current procedure ({$this->procedure->getName()})?" ) ) { $ this -> abort ( "Procedure aborted by user" ) ; } } }
Warn user if procedure should be ran as root and is being ran by some other user
22,318
protected function _normalizeIterable ( $ iterable ) { if ( is_array ( $ iterable ) || $ iterable instanceof Traversable || $ iterable instanceof stdClass ) { return $ iterable ; } throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Invalid iterable' ) , null , null , $ iterable ) ; }
Normalizes an iterable .
22,319
public function addParameter ( string $ name , $ value ) { if ( ! is_scalar ( $ value ) ) { throw new InvalidParameterTypeException ( __CLASS__ , __METHOD__ , 1 , 'scalar' , gettype ( $ value ) ) ; } $ this -> parameters -> set ( $ name , $ value ) ; return $ this ; }
Adds a parameter
22,320
public static function Tdbtcb ( $ tdb1 , $ tdb2 , & $ tcb1 , & $ tcb2 ) { $ t77td = DJM0 + DJM77 ; $ t77tf = TTMTAI / DAYSEC ; $ tdb0 = TDB0 / DAYSEC ; $ elbb = ELB / ( 1.0 - ELB ) ; $ d ; $ f ; if ( $ tdb1 > $ tdb2 ) { $ d = $ t77td - $ tdb1 ; $ f = $ tdb2 - $ tdb0 ; $ tcb1 = $ tdb1 ; $ tcb2 = $ f - ( $ d - ( $ f - $ t77tf ) ) * $ elbb ; } else { $ d = t77td - $ tdb2 ; $ f = $ tdb1 - $ tdb0 ; $ tcb1 = $ f + ( $ d - ( $ f - $ t77tf ) ) * $ elbb ; $ tcb2 = $ tdb2 ; } return 0 ; }
- - - - - - - - - - i a u T d b t c b - - - - - - - - - -
22,321
public static function Dtf2d ( $ scale , $ iy , $ im , $ id , $ ihr , $ imn , $ sec , & $ d1 , & $ d2 ) { $ js ; $ iy2 ; $ im2 ; $ id2 ; $ dj ; $ w ; $ day ; $ seclim ; $ dat0 ; $ dat12 ; $ dat24 ; $ dleap ; $ time ; $ js = IAU :: Cal2jd ( $ iy , $ im , $ id , $ dj , $ w ) ; if ( $ js ) return $ js ; $ dj += $ w ; $ day = DAYSEC ; $ seclim = 60.0 ; if ( ! strcmp ( $ scale , "UTC" ) ) { $ js = IAU :: Dat ( $ iy , $ im , $ id , 0.0 , $ dat0 ) ; if ( $ js < 0 ) return $ js ; $ js = IAU :: Dat ( $ iy , $ im , $ id , 0.5 , $ dat12 ) ; if ( $ js < 0 ) return $ js ; $ js = IAU :: Jd2cal ( $ dj , 1.5 , $ iy2 , $ im2 , $ id2 , $ w ) ; if ( $ js ) return js ; $ js = IAU :: Dat ( $ iy2 , $ im2 , $ id2 , 0.0 , $ dat24 ) ; if ( $ js < 0 ) return $ js ; $ dleap = $ dat24 - ( 2.0 * $ dat12 - $ dat0 ) ; $ day += $ dleap ; if ( $ ihr == 23 && $ imn == 59 ) $ seclim += $ dleap ; } if ( $ ihr >= 0 && $ ihr <= 23 ) { if ( $ imn >= 0 && $ imn <= 59 ) { if ( $ sec >= 0 ) { if ( $ sec >= $ seclim ) { $ js += 2 ; } } else { $ js = - 6 ; } } else { $ js = - 5 ; } } else { $ js = - 4 ; } if ( $ js < 0 ) return $ js ; $ time = ( 60.0 * ( ( double ) ( 60 * $ ihr + $ imn ) ) + $ sec ) / $ day ; $ d1 = $ dj ; $ d2 = $ time ; return $ js ; }
- - - - - - - - - i a u D t f 2 d - - - - - - - - -
22,322
public function setJsonRedirection ( FilterResponseEvent $ event ) { if ( ! $ event -> isMasterRequest ( ) ) { return ; } $ request = $ event -> getRequest ( ) ; if ( $ event -> getResponse ( ) instanceof RedirectResponse && $ request -> isXmlHttpRequest ( ) ) { $ uri = rtrim ( explode ( '?' , $ request -> getUri ( ) ) [ 0 ] , '/' ) ; $ target = rtrim ( explode ( '?' , $ targetUrl = $ event -> getResponse ( ) -> getTargetUrl ( ) ) [ 0 ] , '/' ) ; if ( $ uri === $ target ) { return ; } $ flashes = $ event -> getRequest ( ) -> getSession ( ) -> getFlashBag ( ) ; $ headers = array ( 'x-location' => $ targetUrl , 'x-flashes' => $ flashes ? json_encode ( $ flashes -> all ( ) ) : null ) ; $ event -> setResponse ( new Response ( null , 204 , $ headers ) ) ; } }
Set 204 status and return location redirect for ajax redirect .
22,323
public function hasRole ( $ name ) { foreach ( $ this -> roles as $ role ) { if ( $ role -> name == $ name ) return true ; } return false ; }
Does the user have a particular role?
22,324
public function createSwooleTable ( ) { $ configTable = new SwooleTable ( 2048 ) ; $ configTable -> column ( 'value' , SwooleTable :: TYPE_STRING , 1024 ) ; $ configTable -> create ( ) ; $ this -> table = $ configTable ; }
create swoole table
22,325
public function createImage ( UploadedFile $ uploadedImage ) { $ image = $ this -> imageManager -> create ( ) ; $ filename = $ this -> getUniqueFilename ( $ uploadedImage ) ; $ image -> setFilename ( $ filename ) ; $ image -> setMimeType ( $ uploadedImage -> getClientMimeType ( ) ) ; $ image -> setOrderNr ( 1 ) ; $ image -> setOriginalPath ( $ this -> filesystem -> getRelativeFilePath ( $ filename ) ) ; $ image -> setPath ( $ image -> getOriginalPath ( ) ) ; $ image -> setSize ( $ uploadedImage -> getClientSize ( ) ) ; $ image -> setTemporary ( true ) ; $ this -> imageManager -> add ( $ image ) ; $ fileDir = $ this -> filesystem -> getActualFileDir ( $ filename ) ; $ uploadedImage -> move ( $ fileDir , $ image -> getFilename ( ) ) ; return $ image ; }
Create image .
22,326
public function commit ( ) { try { $ toUpdate = array_merge ( $ this -> getFieldsToUpdate ( ) , $ this -> getFieldsToDelete ( ) ) ; if ( ! empty ( $ toUpdate ) ) { $ idField = $ this -> _item -> getIdField ( ) ; $ query = " UPDATE `" . $ this -> getDbPrefix ( ) . $ this -> _item -> getDbContainer ( ) . "` SET " . $ this -> _getPreparedFields ( $ toUpdate ) . " WHERE `$idField` = ?" ; if ( ! array_key_exists ( $ idField , $ toUpdate ) ) { $ toUpdate [ $ idField ] = $ this -> _item -> getId ( ) -> getOrig ( ) ; } $ prepared = Agl :: app ( ) -> getDb ( ) -> getConnection ( ) -> prepare ( $ query ) ; if ( ! $ prepared -> execute ( array_values ( $ toUpdate ) ) ) { $ error = $ prepared -> errorInfo ( ) ; throw new Exception ( "The update query failed (table '" . $ this -> getDbPrefix ( ) . $ this -> _item -> getDbContainer ( ) . "') with message '" . $ error [ 2 ] . "'" ) ; } if ( Agl :: app ( ) -> isDebugMode ( ) ) { Agl :: app ( ) -> getDb ( ) -> incrementCounter ( ) ; } return $ prepared -> rowCount ( ) ; } } catch ( Exception $ e ) { throw new Exception ( $ e ) ; } return true ; }
Commit the update to MySQL and check the query result .
22,327
protected function build ( ) { if ( $ this -> beforeExecute ) { call_user_func ( $ this -> beforeExecute , $ this ) ; } if ( $ this -> bodyEntity !== null ) { if ( $ this -> pendingRequest instanceof EntityEnclosingRequestInterface ) { $ this -> pendingRequest -> setBody ( $ this -> serializer -> serialize ( $ this -> bodyEntity , $ this -> requestFormat ) , $ this -> requestContentType ) ; } else { throw new \ LogicException ( 'Request must implement EntityEnclosingRequestInterface when command has body' ) ; } } if ( $ this -> accessToken !== null ) { $ this -> pendingRequest -> getParams ( ) -> set ( 'oauth_commerce.token' , $ this -> accessToken ) ; } $ this -> request = $ this -> pendingRequest ; }
Create the request object that will carry out the command
22,328
public function setResult ( $ result = self :: RESULT_SUCCESS , $ message = null , array $ data = [ ] , array $ additional = [ ] ) { $ this -> headers -> set ( 'X-Phlexible-Response' , 'result' ) ; $ values = [ 'success' => $ result , 'msg' => $ message , 'data' => $ data , ] ; if ( is_array ( $ additional ) && count ( $ additional ) ) { foreach ( $ additional as $ key => $ value ) { $ values += $ additional ; } } $ this -> setData ( $ values ) ; }
Generate a standard result .
22,329
public function refresh ( ) { $ behaviors = $ this -> owner -> behaviors ( ) ; $ settings = $ behaviors [ $ this -> getName ( ) ] ; foreach ( $ settings as $ attribute => $ value ) { if ( in_array ( $ attribute , array ( 'class' ) ) ) { continue ; } $ this -> $ attribute = $ value ; } return $ this ; }
refreshes its attributes from owner behavior method data
22,330
public function mockObject ( $ objectClassName , ... $ configurations ) { foreach ( $ configurations as & $ configuration ) { $ this -> prepareMockConfig ( $ configuration ) ; } $ config = call_user_func_array ( 'array_replace_recursive' , $ configurations ) ; $ willReturn = $ this -> pullOutArrayValue ( $ config , 'willReturn' , [ ] ) ; $ will = $ this -> pullOutArrayValue ( $ config , 'will' ) ; $ mockType = $ this -> pullOutArrayValue ( $ config , 'mockType' , self :: MOCK_TYPE_DEFAULT ) ; if ( empty ( $ config [ 'methods' ] ) ) { if ( $ mockType == self :: MOCK_TYPE_DEFAULT ) { $ config [ 'methods' ] = null ; } } $ mockBuilder = $ this -> testCase -> getMockBuilder ( $ objectClassName ) ; foreach ( $ config as $ property => $ value ) { $ method = "set$property" ; if ( method_exists ( $ mockBuilder , $ method ) ) { $ mockBuilder -> $ method ( $ value ) ; } } if ( $ this -> getArrayValue ( $ config , 'disableOriginalConstructor' , true ) ) { $ mockBuilder -> disableOriginalConstructor ( ) ; } $ mockMethod = $ this -> getMockMethod ( $ mockType ) ; $ mock = $ mockBuilder -> $ mockMethod ( ) ; foreach ( $ willReturn as $ method => $ value ) { $ mock -> method ( $ method ) -> willReturn ( $ value ) ; } foreach ( $ will as $ method => $ value ) { $ mock -> method ( $ method ) -> will ( $ value ) ; } return $ mock ; }
General method for mocking objects
22,331
protected function prepareMockConfig ( array & $ config = [ ] ) { if ( ! isset ( $ config [ 'willReturn' ] ) ) { $ config [ 'willReturn' ] = [ ] ; } if ( ! empty ( $ config [ 'methods' ] ) && is_array ( $ config [ 'methods' ] ) ) { $ methodNames = [ ] ; foreach ( $ config [ 'methods' ] as $ key => $ value ) { $ methodNames [ ] = is_numeric ( $ key ) ? $ value : $ key ; if ( ! is_numeric ( $ key ) ) { $ config [ 'willReturn' ] [ $ key ] = $ value ; } } $ config [ 'methods' ] = $ methodNames ; } if ( ! isset ( $ config [ 'will' ] ) ) { $ config [ 'will' ] = [ ] ; } if ( isset ( $ config [ 'constructor' ] , $ config [ 'disableOriginalConstructor' ] ) ) { unset ( $ config [ 'constructor' ] ) ; } if ( isset ( $ config [ 'constructor' ] ) ) { $ config [ 'disableOriginalConstructor' ] = ! $ config [ 'constructor' ] ; unset ( $ config [ 'constructor' ] ) ; } }
Index keys of the item setMethods using its values
22,332
protected function getMockMethod ( $ mockType ) { if ( ! isset ( $ this -> mockTypesToMethodsMap [ $ mockType ] ) ) { throw new InvalidMockTypeException ( ) ; } return $ this -> mockTypesToMethodsMap [ $ mockType ] ; }
Returns a name of method for getting an instance of mock .
22,333
private function pullOutArrayValue ( array & $ array , string $ key , $ defaultValue = null ) { if ( ! array_key_exists ( $ key , $ array ) ) { return $ defaultValue ; } $ value = $ array [ $ key ] ; unset ( $ array [ $ key ] ) ; return $ value ; }
Returns an array item value and removes it from the array .
22,334
public function getAllCategoryTreesAsArray ( ) { $ rootIds = $ this -> getAllRootIds ( ) ; $ trees = array ( ) ; foreach ( $ rootIds as $ rootId ) { $ trees [ $ rootId ] = $ this -> getCategoryTreeAsArray ( $ rootId ) ; } return $ trees ; }
Returns an array of all category trees
22,335
public function deleteCategory ( $ id ) { $ this -> validateId ( $ id ) ; $ category = $ this -> getMapper ( ) -> find ( $ id ) ; if ( null === $ category ) { throw new \ InvalidArgumentException ( 'No category found for id "' . $ id . '"' ) ; } $ node = $ this -> getNestedSetManager ( ) -> wrapNode ( $ category ) ; $ node -> delete ( ) ; return $ this ; }
Deletes a category node
22,336
public function addDefinition ( Definition $ definition ) { if ( $ this -> hasDefinition ( $ definition ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Definition "%s" allready exists.' , $ definition -> getName ( ) ) ) ; } $ this -> definitions [ $ definition -> getName ( ) ] = $ definition ; return $ this ; }
Adds a definition .
22,337
public function getDefinitionByName ( $ name ) { if ( ! array_key_exists ( $ name , $ this -> definitions ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Can\'t find "%s" Definition.' , $ name ) ) ; } return $ this -> definitions [ $ name ] ; }
Returns a definition by name .
22,338
public function getAvatar ( $ user , $ options = [ ] ) { if ( ! isset ( $ options [ 'size' ] ) ) { $ options [ 'size' ] = 100 ; } if ( ! isset ( $ options [ 'secure' ] ) ) { $ options [ 'secure' ] = true ; } try { if ( method_exists ( 'getEmail' , $ user ) ) { $ email = $ user -> getEmail ( ) ; } elseif ( isset ( $ user -> email ) ) { $ email = $ user -> email ; } elseif ( isset ( $ user [ 'email' ] ) ) { $ email = $ user [ 'email' ] ; } $ hash = $ this -> getHash ( $ email ) ; if ( $ options [ 'secure' ] ) { $ avatar_url = $ this -> https_url . $ hash . '?s=' . $ options [ 'size' ] ; } else { $ avatar_url = $ this -> http_url . $ hash . '?s=' . $ options [ 'size' ] ; } return $ avatar_url ; } catch ( Exception $ e ) { return false ; } }
Retrieves a users gravatar using their email address
22,339
private function getHash ( $ email ) { try { $ gravatar_hash = md5 ( strtolower ( trim ( $ email ) ) ) ; return $ gravatar_hash ; } catch ( Exception $ e ) { return false ; } }
Get the gravatar hash from an email address .
22,340
public static function forThe ( string $ class ) : DeserializesObjects { return new ObjectDeserializer ( Instantiator :: forThe ( $ class ) , empty ( listOfParentsForThe ( $ class ) ) ? ObjectHydrator :: default ( ) : ReflectiveHydrator :: default ( ) ) ; }
Makes a new deserializer for the class .
22,341
public function prepareCallback ( $ callback ) { $ result = $ callback ; if ( is_string ( $ callback ) && ( $ callbackInfo = $ this -> parseHandlerStr ( $ callback ) ) && class_exists ( $ callbackInfo [ 'class' ] ) && method_exists ( ( $ controller = new $ callbackInfo [ 'class' ] ) , $ callbackInfo [ 'method' ] ) ) { $ result = [ $ controller , $ callbackInfo [ 'method' ] ] ; } elseif ( ! is_callable ( $ callback ) ) { throw new \ pwf \ exception \ HttpNotFoundException ( ) ; } return $ result ; }
Prepare handler for invokation
22,342
public function edit ( $ id , $ data ) { $ record = $ this -> read ( null , $ id ) ; if ( ! $ record ) { throw new OutOfBoundsException ( 'view.fail' ) ; } if ( empty ( $ data ) ) { return ; } $ data [ $ this -> alias ] = array_merge ( array_diff_key ( $ data [ $ this -> alias ] , $ record [ $ this -> alias ] ) , array_diff ( $ data [ $ this -> alias ] , $ record [ $ this -> alias ] ) ) ; $ validate = $ this -> validate ; foreach ( array_keys ( $ this -> validate ) as $ field ) { if ( ! isset ( $ data [ $ this -> alias ] [ $ field ] ) ) { unset ( $ this -> validate [ $ field ] ) ; } } $ this -> id = $ id ; $ this -> data = $ data ; $ result = $ this -> save ( null , false ) ; $ this -> validate = $ validate ; $ this -> data = Hash :: merge ( $ record , $ result ) ; if ( ! $ result ) { return false ; } $ this -> triggerEvent ( 'Model.' . $ this -> name . '.afterEdit' , $ this ) ; return $ data ; }
Common edit operation .
22,343
public static function getForeignModelDisplayField ( $ model , $ foreignModel , $ path = false ) { $ _this = ClassRegistry :: init ( $ model ) ; $ displayField = $ _this -> displayField ; if ( is_bool ( $ foreignModel ) ) { $ path = $ foreignModel ; list ( , $ name ) = pluginSplit ( $ model ) ; } else { list ( , $ name ) = pluginSplit ( $ foreignModel ) ; foreach ( array_keys ( $ _this -> belongsToForeignModels ) as $ model ) { if ( $ name == $ model ) { $ displayField = $ _this -> { $ model } -> displayField ; break ; } } } if ( true === $ path || ( false !== $ path && empty ( $ path ) ) ) { $ displayField = "$name.$displayField" ; } else if ( false !== $ path ) { $ displayField = "$path.$name.$displayField" ; } return $ displayField ; }
Gets the foreign model s display field . Useful in views .
22,344
public function triggerEvent ( $ event , $ subject = null , $ data = null ) { return $ this -> getEventManager ( ) -> trigger ( $ event , $ subject , $ data ) ; }
Trigger an event using the Model instead of the CommonEventManager .
22,345
protected function _containForeignModels ( $ query , $ assoc = null ) { if ( ( isset ( $ query [ 'contain' ] ) && empty ( $ query [ 'contain' ] ) ) || ( isset ( $ this -> contain ) && empty ( $ this -> contain ) ) ) { return $ query ; } if ( ! isset ( $ query [ 'contain' ] ) ) { $ query [ 'contain' ] = array ( ) ; } else if ( ! is_array ( $ query [ 'contain' ] ) ) { $ query [ 'contain' ] = ( array ) $ query [ 'contain' ] ; } foreach ( array_keys ( $ this -> belongsToForeignModels ) as $ model ) { if ( ! empty ( $ assoc ) ) { $ model = "$assoc.$model" ; } if ( ! in_array ( $ model , $ query [ 'contain' ] ) && ! isset ( $ query [ 'contain' ] [ $ model ] ) ) { $ query [ 'contain' ] [ ] = $ model ; } } return $ query ; }
Adds the foreign models to the query s contain .
22,346
protected function _filterForeignModels ( $ result , $ keep ) { foreach ( $ this -> belongsToForeignModels as $ name => $ assoc ) { if ( $ keep === $ assoc [ 'className' ] ) { continue ; } if ( isset ( $ result [ $ name ] ) ) { unset ( $ result [ $ name ] ) ; } } return $ result ; }
Loops through associated belongsTo foreign models to keep only the associated one .
22,347
public function invalidateAll ( ) { if ( true === $ this -> filesystem -> exists ( $ this -> httpCacheDir ) ) { $ this -> filesystem -> remove ( $ this -> httpCacheDir ) ; } }
Invalidate all http cache .
22,348
public function shouldTransform ( $ action , $ data ) : bool { if ( $ this -> matchData ( $ data ) && $ this -> matchCustom ( $ action , $ data ) ) { return true ; } return false ; }
Checks whether this filter should transform the specified action data .
22,349
public function register ( Container $ pimple ) { $ pimple [ 'console' ] = function ( $ pimple ) { $ console = new ContainerAwareApplication ( $ pimple [ 'console.name' ] , $ pimple [ 'console.version' ] ) ; $ console -> setDispatcher ( $ pimple [ 'eventDispatcher' ] ) ; $ console -> setContainer ( $ pimple ) ; return $ console ; } ; }
Registers console services on the given container .
22,350
public function getRole ( ) { if ( null === $ this -> role ) { $ auth = $ this -> getAuthenticationService ( ) ; if ( $ auth -> hasIdentity ( ) ) { $ this -> role = $ auth -> getIdentity ( ) ; } else { $ this -> role = new Acl \ Role \ GenericRole ( self :: ROLE_GUEST_ID ) ; } } return $ this -> role ; }
Get inner acl - role
22,351
public function setRole ( Acl \ Role \ RoleInterface $ role = null ) { $ this -> role = $ role ; return $ this ; }
Set inner acl - role
22,352
public function checkResource ( $ resource , $ parent = null ) { if ( null === $ resource ) { return null ; } if ( $ resource instanceof Acl \ Resource \ ResourceInterface ) { $ resource = $ resource -> getResourceId ( ) ; } $ acl = $ this -> getAcl ( ) ; if ( ! $ acl -> hasResource ( $ resource ) ) { if ( null === $ parent ) { $ parent = $ this -> getParentId ( $ resource ) ; } elseif ( $ parent instanceof Acl \ Resource \ ResourceInterface ) { $ parent = $ parent -> getResourceId ( ) ; } $ parent = $ this -> checkResource ( $ parent ) ; $ acl -> addResource ( $ resource , $ parent ) ; } return $ resource ; }
Check existence of a resource
22,353
public function checkRole ( $ role , $ parent = null ) { if ( null === $ role ) { return null ; } if ( $ role instanceof Acl \ Role \ RoleInterface ) { $ role = $ role -> getRoleId ( ) ; } $ acl = $ this -> getAcl ( ) ; if ( ! $ acl -> hasRole ( $ role ) ) { if ( null === $ parent ) { $ parent = $ this -> getParentId ( $ role ) ; } elseif ( $ parent instanceof Acl \ Role \ RoleInterface ) { $ parent = $ parent -> getRoleId ( ) ; } $ parent = $ this -> checkRole ( $ parent ) ; $ acl -> addRole ( $ role , ( array ) $ parent ) ; $ matches = array ( ) ; $ structures = array ( ) ; if ( preg_match ( '/^(\d+)$/' , $ role , $ matches ) ) { $ structures = $ this -> getMapper ( ) -> findAllByGroupId ( $ matches [ 1 ] ) ; } else if ( preg_match ( '/^(\d+)\.(\d+)$/' , $ role , $ matches ) ) { $ structures = $ this -> getMapper ( ) -> findAllByUserId ( $ matches [ 2 ] ) ; $ resource = 'user.group.' . $ matches [ 1 ] . '.identity.' . $ matches [ 2 ] ; $ this -> checkResource ( $ resource ) ; $ acl -> allow ( $ role , $ resource ) ; } foreach ( $ structures as $ structure ) { $ this -> checkResource ( $ structure -> resource ) ; $ acl -> allow ( $ role , $ structure -> resource , $ structure -> privilege ) ; } } return $ role ; }
Check existence of a role
22,354
public static function expand ( $ template , $ variables , array $ options = array ( ) ) { if ( is_object ( $ variables ) ) { $ variables = get_object_vars ( $ variables ) ; } elseif ( ! is_array ( $ variables ) ) { throw new UriTemplateException ( '$variables must be an array or object' ) ; } $ result = $ template ; $ errors = array ( ) ; $ expressions = self :: getExpressions ( $ template , $ options ) ; $ i = count ( $ expressions ) ; while ( $ i -- > 0 ) { try { $ expression = $ expressions [ $ i ] ; if ( ! $ expression [ 'valid' ] ) { throw new UriTemplateException ( 'Malformed expression: "%s" at offset %d' , array ( $ expression [ 'complete' ] , $ expression [ 'offset' ] ) ) ; } $ sub = UriTemplate :: expandExpression ( $ expression [ 'expression' ] , $ variables , isset ( $ options [ 'keySort' ] ) ? ( bool ) $ options [ 'keySort' ] : false ) ; $ result = substr_replace ( $ result , $ sub , $ expression [ 'offset' ] , strlen ( $ expression [ 'complete' ] ) ) ; } catch ( UriTemplateException $ e ) { $ errors [ ] = $ e -> getMessage ( ) ; continue ; } } if ( $ errors ) { throw new UriTemplateException ( 'Invalid URI Template string: "%s"' , array ( $ template ) , $ errors ) ; } return $ result ; }
Expand template as a URI Template using variables .
22,355
public static function getErrors ( $ template , array $ options = array ( ) ) { $ errors = array ( ) ; foreach ( self :: getExpressions ( $ template , $ options ) as $ expression ) { if ( ! $ expression [ 'valid' ] ) { $ errors [ ] = 'Malformed expression: "' . $ expression [ 'complete' ] . '" at offset ' . $ expression [ 'offset' ] ; continue ; } try { $ expression = self :: parseExpression ( $ expression [ 'expression' ] ) ; foreach ( $ expression [ 'varspecs' ] as $ varspec ) { try { $ varspec = self :: parseVarspec ( $ varspec ) ; } catch ( UriTemplateException $ e ) { $ errors [ ] = $ e -> getMessage ( ) ; } } } catch ( UriTemplateException $ e ) { $ errors [ ] = $ e -> getMessage ( ) ; } } return $ errors ; }
Get a list of errors in a URI Template .
22,356
public static function getVariables ( $ template , array $ options = array ( ) ) { $ varnames = array ( ) ; foreach ( self :: getExpressions ( $ template , $ options ) as $ expression ) { if ( $ expression [ 'valid' ] ) { try { $ expression = self :: parseExpression ( $ expression [ 'expression' ] ) ; foreach ( $ expression [ 'varspecs' ] as $ varspec ) { try { $ varspec = self :: parseVarspec ( $ varspec ) ; $ varnames [ ] = $ varspec [ 'varname' ] ; } catch ( UriTemplateException $ e ) { continue ; } } } catch ( UriTemplateException $ e ) { continue ; } } } return array_unique ( $ varnames ) ; }
Get a list of variables used in a URI Template .
22,357
public static function delete ( $ id , $ additionalAttributes , $ table , $ idAttribute = 'id' , $ limit = 1 ) { $ limit = null ; $ queryValues = [ $ id ] ; $ additional = [ ] ; foreach ( $ additionalAttributes as $ key => $ value ) { $ additional [ ] = sprintf ( 'AND "%s"."%s" = ?' , $ table , $ key ) ; $ queryValues [ ] = $ value ; } $ tableName = '' ; if ( is_array ( $ table ) && isset ( $ table [ 'schema' ] ) && isset ( $ table [ 'table' ] ) ) { $ tableName = '"' . $ table [ 'schema' ] . '"' . '."' . $ table [ 'table' ] . '"' ; } else { $ tableName = '"' . $ table . '"' ; } $ query = sprintf ( 'DELETE FROM %s WHERE "%s" = ? %s %s' , $ tableName , $ idAttribute , implode ( "\n" , $ additional ) , ( $ limit === null ? '' : 'LIMIT ' . $ limit ) ) ; return Database :: execute ( $ query , $ queryValues ) ; }
Delete database records
22,358
public function boot ( ) { if ( $ this -> booted ) return ; $ this -> container = $ container = new Container ( ) ; $ this -> registerServices ( $ container ) ; $ this -> registerRoutes ( $ container ) ; $ this -> registerEventListeners ( $ container ) ; $ this -> booted = true ; }
Make this public for testing
22,359
public function first ( ) { if ( ! empty ( $ this -> data ) ) { if ( Collection :: count ( $ this -> data ) > 0 ) { return $ this -> data [ 0 ] ; } else { return ; } } else { return ; } }
Get first row of data selected by where clause .
22,360
public function appendChildFromHtmlString ( $ html ) { $ dom = new \ DOMDocument ; $ dom -> loadHTML ( $ html ) ; $ element = simplexml_import_dom ( $ dom ) ; $ element = current ( $ element -> xPath ( '//body/*' ) ) ; $ this -> appendChildNode ( $ element ) ; }
Append a childelement from a well formed html string .
22,361
public function appendChildFromXmlString ( $ xml ) { $ dom = new \ DOMDocument ; $ dom -> loadXML ( $ xml ) ; $ element = simplexml_import_dom ( $ dom ) ; $ this -> appendChildNode ( $ element ) ; }
Append a childelement from a well formed xml string .
22,362
public function appendChildNode ( \ SimpleXMLElement $ element ) { $ target = dom_import_simplexml ( $ this ) ; $ insert = $ target -> ownerDocument -> importNode ( dom_import_simplexml ( $ element ) , true ) ; $ target -> appendChild ( $ insert ) ; }
Append a SimpleXMLElement to the current SimpleXMLElement .
22,363
public static function generate ( ) { self :: dispatchEvent ( self :: EVENT_GET_MENU ) ; $ return = '' ; uksort ( self :: $ menu , 'strnatcmp' ) ; ; foreach ( self :: $ menu as $ item ) { if ( $ item -> resources && ! self :: userHasResource ( $ item -> resources ) ) { continue ; } if ( $ children = $ item -> getChildren ( ) ) { $ subItems = '' ; uksort ( $ children , 'strnatcmp' ) ; ; foreach ( $ children as $ child ) { if ( $ child -> resources && ! self :: userHasResource ( $ child -> resources ) ) { continue ; } $ subItems .= '<li><a href="' . $ child -> getLink ( ) . '">' . $ child -> getLabel ( ) . '</a></li>' ; } $ return .= '<li class="treeview"> <a href="#"> <i class="fa ' . $ item -> getIcon ( ) . '"></i> <span>' . $ item -> getLabel ( ) . '</span> <i class="fa fa-angle-left pull-right"></i> </a> <ul class="treeview-menu"> ' . $ subItems . ' </ul> </li>' ; } else { $ return .= '<li> <a href="' . $ item -> getLink ( ) . '"> <i class="fa ' . $ item -> getIcon ( ) . ' fa-fw"></i> <span>' . $ item -> getLabel ( ) . '</span> </a> </li>' ; } } return $ return ; }
Generate menu it s only used in this bundle!
22,364
public function addChild ( Menu $ child ) { $ this -> children [ $ child -> getOrder ( ) . '--' . $ child -> getLabel ( ) ] = $ child ; return $ this ; }
Add child to menu
22,365
public function getPostalCode ( ) : ? string { if ( ! $ this -> hasPostalCode ( ) ) { $ this -> setPostalCode ( $ this -> getDefaultPostalCode ( ) ) ; } return $ this -> postalCode ; }
Get postal code
22,366
public function daySuffix ( $ day ) { $ locale = \ Locale :: getDefault ( ) ; switch ( $ day ) { case 1 : $ nf = new \ NumberFormatter ( $ locale , \ NumberFormatter :: ORDINAL ) ; $ day = $ nf -> format ( $ day ) ; } return $ day ; }
Adds day suffix .
22,367
public function uploadAction ( Request $ request ) { $ folderId = $ request -> get ( 'folder_id' , null ) ; try { $ volumeManager = $ this -> get ( 'phlexible_media_manager.volume_manager' ) ; $ volume = $ volumeManager -> getByFolderId ( $ folderId ) ; $ folder = $ volume -> findFolder ( $ folderId ) ; if ( empty ( $ folder ) ) { return new ResultResponse ( false , 'Target folder not found.' , [ 'params' => $ request -> request -> all ( ) , 'files' => $ request -> files -> all ( ) , ] ) ; } if ( ! $ request -> files -> count ( ) ) { return new ResultResponse ( false , 'No files received.' , [ 'params' => $ request -> request -> all ( ) , 'files' => $ request -> files -> all ( ) , ] ) ; } $ uploadHandler = $ this -> get ( 'phlexible_media_manager.upload.handler' ) ; $ cnt = 0 ; foreach ( $ request -> files -> all ( ) as $ uploadedFile ) { $ file = $ uploadHandler -> handle ( $ uploadedFile , $ folderId , $ this -> getUser ( ) -> getId ( ) ) ; if ( $ file ) { ++ $ cnt ; $ body = 'Filename: ' . $ uploadedFile -> getClientOriginalName ( ) . PHP_EOL . 'Folder: ' . $ folder -> getName ( ) . PHP_EOL . 'Filesize: ' . $ file -> getSize ( ) . PHP_EOL . 'Filetype: ' . $ file -> getMimeType ( ) . PHP_EOL ; $ message = MediaManagerMessage :: create ( 'File "' . $ file -> getName ( ) . '" uploaded.' , $ body ) ; $ this -> get ( 'phlexible_message.message_poster' ) -> post ( $ message ) ; } } return new ResultResponse ( true , $ cnt . ' file(s) uploaded.' , [ 'params' => $ request -> request -> all ( ) , 'files' => $ request -> files -> all ( ) , ] ) ; } catch ( \ Exception $ e ) { return new ResultResponse ( false , $ e -> getMessage ( ) , [ 'params' => $ request -> request -> all ( ) , 'files' => $ request -> files -> all ( ) , 'trace' => $ e -> getTraceAsString ( ) , 'traceArray' => $ e -> getTrace ( ) , ] ) ; } }
Upload File .
22,368
public function findRoute ( \ Psr \ Http \ Message \ ServerRequestInterface & $ p_request ) { if ( $ this -> routes instanceof \ FreeFW \ Router \ RouteCollection ) { $ params = $ p_request -> getServerParams ( ) ; $ currentDir = '/' ; $ requestUrl = '' ; if ( array_key_exists ( '_request' , $ _GET ) ) { $ requestUrl = '/' . ltrim ( $ _GET [ '_request' ] , '/' ) ; } if ( ( $ pos = strpos ( $ requestUrl , '?' ) ) !== false ) { if ( array_key_exists ( '_url' , $ _GET ) ) { $ requestUrl = $ _GET [ '_url' ] ; } else { $ requestUrl = substr ( $ requestUrl , 0 , $ pos ) ; } } $ currentDir = rtrim ( $ this -> base_path , '/' ) ; $ this -> logger -> debug ( 'router.findRoute.request : ' . $ requestUrl ) ; foreach ( $ this -> routes -> getRoutes ( ) as $ idx => $ oneRoute ) { $ this -> logger -> debug ( 'router.findRoute.test : ' . $ oneRoute -> getUrl ( ) ) ; if ( strtoupper ( $ p_request -> getMethod ( ) ) == strtoupper ( $ oneRoute -> getMethod ( ) ) ) { if ( $ currentDir != '/' ) { $ requestUrl = str_replace ( $ currentDir , '' , $ requestUrl ) ; } $ params = array ( ) ; if ( $ oneRoute -> getUrl ( ) == $ requestUrl ) { } else { if ( ! preg_match ( "#^" . $ oneRoute -> getRegex ( ) . "$#" , $ requestUrl , $ matches ) ) { continue ; } $ matchedText = array_shift ( $ matches ) ; if ( preg_match_all ( "/:([\w-\._@%]+)/" , $ oneRoute -> getUrl ( ) , $ argument_keys ) ) { $ argument_keys = $ argument_keys [ 1 ] ; if ( count ( $ argument_keys ) != count ( $ matches ) ) { continue ; } foreach ( $ argument_keys as $ key => $ name ) { if ( isset ( $ matches [ $ key ] ) && $ matches [ $ key ] !== null && $ matches [ $ key ] != '' && $ matches [ $ key ] != '/' ) { $ params [ $ name ] = ltrim ( $ matches [ $ key ] , '/' ) ; } else { $ params [ $ name ] = '' ; } } } foreach ( $ params as $ name => $ value ) { $ p_request = $ p_request -> withAttribute ( $ name , $ value ) ; } } $ this -> logger -> debug ( 'router.findRoute.match : ' . $ oneRoute -> getUrl ( ) ) ; return $ oneRoute ; } } } return false ; }
Find called route
22,369
public static function copyToString ( StreamInterface $ stream , $ maxLen = - 1 ) { $ buffer = '' ; if ( $ maxLen === - 1 ) { while ( ! $ stream -> eof ( ) ) { $ buf = $ stream -> read ( 1048576 ) ; if ( $ buf == null ) { break ; } $ buffer .= $ buf ; } return $ buffer ; } $ len = 0 ; while ( ! $ stream -> eof ( ) && $ len < $ maxLen ) { $ buf = $ stream -> read ( $ maxLen - $ len ) ; if ( $ buf == null ) { break ; } $ buffer .= $ buf ; $ len = strlen ( $ buffer ) ; } return $ buffer ; }
Copy the contents of a stream into a string until the given number of bytes have been read .
22,370
public function method ( $ class , $ method , $ args = array ( ) , $ ttl = null ) { is_string ( $ class ) or $ class = get_class ( $ class ) ; $ identifier = array ( 'class' => $ class , 'method' => $ method , 'args' => $ args ) ; $ result = $ this -> driver -> get_method ( $ identifier ) ; if ( $ result [ 'status' ] ) { return unserialize ( $ result [ 'data' ] ) ; } if ( is_string ( $ class ) ) { $ object = new $ class ; } $ data = call_user_func_array ( array ( $ object , $ method ) , $ args ) ; $ data_string = serialize ( $ data ) ; $ this -> driver -> set_method ( $ identifier , $ data_string , $ ttl ) ; if ( $ this -> strict ) { $ result = $ this -> driver -> get_method ( $ identifier ) ; return unserialize ( $ result [ 'data' ] ) ; } return $ data ; }
Call a method cache the result and return the data
22,371
public function loadClassMetadata ( LoadClassMetadataEventArgs $ eventArgs ) { $ metadata = $ eventArgs -> getClassMetadata ( ) ; $ class = $ metadata -> getReflectionClass ( ) ; if ( $ class === null ) { $ class = new \ ReflectionClass ( $ metadata -> getName ( ) ) ; } if ( $ this -> className && $ class -> getName ( ) == "Hexmedia\\UserBundle\\Entity\\User" ) { $ reader = new AnnotationReader ( ) ; $ discriminatorMap = [ ] ; $ discriminatorMapAnnotation = $ reader -> getClassAnnotation ( $ class , 'Doctrine\ORM\Mapping\DiscriminatorMap' ) ; if ( $ discriminatorMapAnnotation ) { $ discriminatorMap = $ discriminatorMapAnnotation -> value ; } $ discriminatorMap [ 'users' ] = $ this -> className ; $ discriminatorMap [ 'users_base' ] = "Hexmedia\\UserBundle\\Entity\\User" ; $ metadata -> setDiscriminatorColumn ( [ "name" => "type" , "length" => 255 ] ) ; $ metadata -> setInheritanceType ( ClassMetadataInfo :: INHERITANCE_TYPE_SINGLE_TABLE ) ; $ metadata -> setDiscriminatorMap ( $ discriminatorMap ) ; } }
Sets the discriminator map according to the config
22,372
protected function getMigrationStub ( ) { $ stub = file_get_contents ( __DIR__ . '/../Mmanos/Metable/Stubs/MetasMigration.stub.php' ) ; $ stub = str_replace ( '{{table}}' , $ this -> tableName ( ) , $ stub ) ; $ stub = str_replace ( '{{class}}' , 'Create' . Str :: studly ( $ this -> tableName ( ) ) . 'Table' , $ stub ) ; return $ stub ; }
Get the contents of the migration stub .
22,373
protected function createBaseModel ( ) { $ name_parts = explode ( '_' , $ this -> tableName ( ) ) ; $ path = $ this -> laravel [ 'path' ] . '/models' ; for ( $ i = 0 ; $ i < ( count ( $ name_parts ) - 1 ) ; $ i ++ ) { $ path .= '/' . Str :: studly ( Str :: singular ( $ name_parts [ $ i ] ) ) ; } if ( count ( $ name_parts ) > 1 && ! File :: exists ( $ path ) ) { File :: makeDirectory ( $ path , 0755 , true ) ; } $ path .= '/' . Str :: studly ( Str :: singular ( end ( $ name_parts ) ) ) . '.php' ; return $ path ; }
Create a base model file .
22,374
protected function getModelStub ( ) { $ stub = file_get_contents ( __DIR__ . '/../Mmanos/Metable/Stubs/MetaModel.stub.php' ) ; $ name_parts = explode ( '_' , $ this -> tableName ( ) ) ; $ namespace = '' ; for ( $ i = 0 ; $ i < ( count ( $ name_parts ) - 1 ) ; $ i ++ ) { $ namespace .= '\\' . Str :: studly ( Str :: singular ( $ name_parts [ $ i ] ) ) ; } $ namespace = trim ( $ namespace , '\\' ) ; $ class = Str :: studly ( Str :: singular ( end ( $ name_parts ) ) ) ; $ stub = str_replace ( '{{namespace}}' , empty ( $ namespace ) ? '' : " namespace {$namespace};" , $ stub ) ; $ stub = str_replace ( '{{class}}' , $ class , $ stub ) ; $ stub = str_replace ( '{{table}}' , $ this -> tableName ( ) , $ stub ) ; return $ stub ; }
Get the contents of the model stub .
22,375
public function addHandler ( $ level , callable $ handler , $ channel = '*' , $ priority = 0 ) { if ( ! isset ( LogLevel :: $ levels [ $ level ] ) ) { throw new InvalidArgumentException ( Message :: get ( Message :: LOG_LEVEL_INVALID , $ level ) , Message :: LOG_LEVEL_INVALID ) ; } return $ this -> addCallable ( 'handlers' , $ handler , $ channel , $ priority , $ level ) ; }
Add handler to the channel with priority
22,376
public function getIntroduction ( $ ellipse = "..." ) { $ intro = $ this -> internalGetIntroduction ( ) ; if ( $ intro === null && ( $ copy = $ this -> getCopy ( ) ) !== null ) { $ copy = trim ( strip_tags ( $ this -> getCopy ( ) ) ) ; if ( ! empty ( $ copy ) ) { $ intro = $ this -> truncateWords ( $ copy , $ ellipse ) ; } } return $ intro ; }
Get introduction .
22,377
public function generateCollectionLinks ( ) { $ links = [ 'self' => $ this -> getPaginator ( ) -> getSelf ( ) , ] ; if ( $ first = $ this -> getPaginator ( ) -> getFirst ( ) ) { $ links [ 'first' ] = $ first ; } if ( $ previous = $ this -> getPaginator ( ) -> getPrevious ( ) ) { $ links [ 'previous' ] = $ previous ; } if ( $ next = $ this -> getPaginator ( ) -> getNext ( ) ) { $ links [ 'next' ] = $ next ; } if ( $ last = $ this -> getPaginator ( ) -> getLast ( ) ) { $ links [ 'last' ] = $ last ; } return $ links ; }
Generate URL links for a resource collection
22,378
protected function _getTransition ( $ key ) { $ sKey = ( string ) $ key ; return array_key_exists ( $ sKey , $ this -> transitions ) ? $ this -> transitions [ $ sKey ] : null ; }
Retrieves the transition with a specific key .
22,379
protected function _addTransition ( $ transition ) { if ( ! is_string ( $ transition ) && ! ( $ transition instanceof Stringable ) ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Argument is not a valid transition.' ) , null , null , $ transition ) ; } $ this -> transitions [ ( string ) $ transition ] = $ transition ; }
Adds a transition to this instance .
22,380
protected function log ( $ message ) { if ( $ this -> log_handle == null ) { $ this -> log_handle = fopen ( $ this -> config [ 'logfile' ] , 'a' ) ; } fwrite ( $ this -> log_handle , $ message ) ; }
Log the given message to the log file . The log file is configured as the config param logfile . This method opens the file for writing if necessary .
22,381
protected static function create ( $ message , array $ params = [ ] , $ code = 0 , \ Exception $ previous = null ) { return new static ( sprintf ( $ message , ... $ params ) , $ code , $ previous ) ; }
Create an instance of the exception with a formatted message .
22,382
protected static function getNormalizedHeaderKey ( string $ name ) { static $ convertCache = [ ] ; if ( ! isset ( $ convertCache [ $ name ] ) ) { $ convertCache [ $ name ] = ucfirst ( ucwords ( $ name , "-" ) ) ; } return $ convertCache [ $ name ] ; }
Get normalized header key .
22,383
protected static function validateHeaderName ( string $ name ) { static $ validCache = [ ] ; if ( ! isset ( $ validCache [ $ name ] ) ) { if ( 1 !== preg_match ( static :: REGEX_HEADER_NAME , $ name ) ) { throw new \ InvalidArgumentException ( "Invalid Header name given." ) ; } } $ validCache [ $ name ] = true ; }
Validate header name .
22,384
protected static function validateHeaderValue ( array $ values ) { static $ validCache = [ ] ; foreach ( $ values as $ index => $ value ) { if ( ! is_string ( $ value ) ) { throw new \ InvalidArgumentException ( "Header value must be of the type string array, " . gettype ( $ value ) . " given at index of {$index}." ) ; } if ( ! isset ( $ validCache [ $ value ] ) ) { if ( 1 !== preg_match ( static :: REGEX_HEADER_VALUE , $ value ) ) { throw new \ InvalidArgumentException ( "Invalid Header value given at index of {$index}." ) ; } } $ validCache [ $ value ] = true ; } }
Validate header value .
22,385
protected function addDefaultCommands ( ) { $ this -> addCommands ( [ new GlobalVersionCommand ( ) , new GlobalFormatCommand ( ) , new GlobalSilentModeCommand ( ) , new GlobalNoInteractionCommand ( ) , new GlobalHelpCommand ( ) , new GlobalVerbosityCommand ( ) , new GlobalPassthroughCommand ( ) , new ListCommand ( ) , new HelpCommand ( ) , ] ) ; }
Register default command handlers .
22,386
protected function addDefaultStyles ( ) { $ this -> consoleFormatter -> style ( 'error' ) -> parseStyle ( 'clr=white bg=red' ) ; $ this -> consoleFormatter -> style ( 'warning' ) -> parseStyle ( 'clr=black bg=yellow' ) ; $ this -> consoleFormatter -> style ( 'success' ) -> parseStyle ( 'clr=black bg=green' ) ; $ this -> consoleFormatter -> style ( 'question' ) -> parseStyle ( 'clr=green' ) ; $ this -> consoleFormatter -> style ( 'header' ) -> parseStyle ( 'clr=yellow' ) ; $ this -> consoleFormatter -> style ( 'title' ) -> parseStyle ( 'clr=yellow' ) ; $ this -> consoleFormatter -> style ( 'keyword' ) -> parseStyle ( 'clr=green' ) ; $ this -> consoleFormatter -> style ( 'green' ) -> parseStyle ( 'clr=green' ) ; $ this -> consoleFormatter -> style ( 'yellow' ) -> parseStyle ( 'clr=yellow' ) ; $ this -> consoleFormatter -> style ( 'red' ) -> parseStyle ( 'clr=red' ) ; $ this -> consoleFormatter -> style ( 'white' ) -> parseStyle ( 'clr=white' ) ; $ this -> consoleFormatter -> style ( 'blue' ) -> parseStyle ( 'clr=blue' ) ; $ this -> consoleFormatter -> style ( 'gray' ) -> parseStyle ( 'clr=gray' ) ; $ this -> consoleFormatter -> style ( 'black' ) -> parseStyle ( 'clr=black' ) ; $ this -> consoleFormatter -> style ( 'bold' ) -> parseStyle ( 'fmt=bold' ) ; $ this -> consoleFormatter -> style ( 'italic' ) -> parseStyle ( 'fmt=italic' ) ; $ this -> consoleFormatter -> style ( 'underline' ) -> parseStyle ( 'fmt=underline' ) ; $ this -> consoleFormatter -> style ( 'strikethrough' ) -> parseStyle ( 'fmt=strikethrough' ) ; }
Register default formatter styles .
22,387
final public function render ( $ action ) { if ( Configuration :: read ( 'mvc.view.auto_render' ) === true ) { $ this -> setView ( $ this -> controller , $ action ) ; } if ( Configuration :: read ( 'mvc.layout.auto_render' ) === true ) { $ layoutName = Configuration :: read ( 'mvc.layout.default' ) ; $ this -> setLayout ( $ layoutName ) ; } if ( method_exists ( $ this , 'initialize' ) ) { $ this -> initialize ( ) ; } ob_start ( ) ; $ actionResult = $ this -> $ action ( ) ; echo PHP_EOL ; $ bodyContent = ob_get_clean ( ) ; if ( $ actionResult !== false ) { if ( isset ( $ this -> layout ) && $ this -> layout -> getAutoRender ( ) ) { $ bodyContent .= $ this -> layout -> render ( ) ; } elseif ( isset ( $ this -> view ) && $ this -> view -> getAutoRender ( ) ) { $ bodyContent .= $ this -> view -> render ( ) ; } } return $ bodyContent ; }
Create the View and the Layout Call initialize method if exist Launch controller Get Layout and View render if enable
22,388
public function getClassConfig ( $ class , $ key = null ) { if ( ! is_string ( $ class ) ) { $ class = get_class ( $ class ) ; $ class = substr ( $ class , strrpos ( $ class , '\\' ) + 1 ) ; } return $ this -> config -> getClassConfig ( $ class , $ key ) ; }
Retrieve custom configuration for a specific class .
22,389
public function description ( ) : string { if ( 0 === $ this -> offset ) { return 'limited to ' . $ this -> count . ' elements' ; } if ( - 1 === $ this -> count ) { return 'skipped until offset ' . $ this -> offset ; } return 'limited to ' . $ this -> count . ' elements starting from offset ' . $ this -> offset ; }
returns description of this iterator
22,390
public static function set ( $ key , $ data , $ type = 'ses' ) { $ GLOBALS [ 'TSFE' ] -> fe_user -> setKey ( self :: isType ( $ type ) , $ key , serialize ( $ data ) ) ; $ GLOBALS [ 'TSFE' ] -> fe_user -> storeSessionData ( ) ; }
Write data into fe_user session
22,391
public static function get ( $ key , $ type = 'ses' ) { $ sessionData = $ GLOBALS [ 'TSFE' ] -> fe_user -> getKey ( self :: isType ( $ type ) , $ key ) ; return unserialize ( $ sessionData ) ; }
Restore data from fe_user session
22,392
public static function has ( $ key , $ type = 'ses' ) { return ( $ GLOBALS [ 'TSFE' ] -> fe_user -> getKey ( self :: isType ( $ type ) , $ key ) ) ? true : false ; }
Checks whether a key in fe_user session exists
22,393
public static function remove ( $ key , $ type = 'ses' ) { $ GLOBALS [ 'TSFE' ] -> fe_user -> setKey ( self :: isType ( $ type ) , $ key , null ) ; $ GLOBALS [ 'TSFE' ] -> fe_user -> storeSessionData ( ) ; }
Removes fe_user session data by key
22,394
public function resolve ( ) : array { $ path = $ this -> request -> query -> get ( 'path' ) ; $ method = $ this -> request -> getMethod ( ) ; $ result = $ this -> match ( "/$path" , $ method ) ; if ( empty ( $ result ) ) { $ fallback = $ this -> settings -> get ( 'Melior.Routing.fallbackRoute' ) ; $ result = [ 'target' => $ this -> settings -> get ( "Melior.Routing.routes.$fallback.target" ) , 'params' => [ ] , 'name' => $ fallback ] ; } return $ result ; }
Resolves the current route and returns it s configuration .
22,395
public static function create ( Request $ request = null , Response $ response = null , array $ user_options = array ( ) ) { return self :: getInstance ( $ request , $ response , $ user_options ) ; }
Creation of a singleton instance
22,396
public static function log ( $ message , array $ context = array ( ) , $ level = Logger :: INFO , $ logname = null ) { $ _this = self :: getInstance ( ) ; if ( $ _this -> getOption ( 'enable_logging' ) === false ) { return ; } $ default_context = array ( 'url' => $ _this -> getRequest ( ) -> getUrl ( ) ) ; return self :: getInstance ( ) -> getLogger ( ) -> log ( $ level , $ message , array_merge ( $ default_context , $ context ) , $ logname ) ; }
Shrotcut for logging message
22,397
public function display ( $ return = false ) { if ( $ this -> getStatus ( ) === null ) { $ this -> setStatus ( self :: STATUS_OK ) ; } if ( $ this -> getMessage ( ) === null ) { $ this -> setMessage ( array_key_exists ( $ this -> getStatus ( ) , self :: $ default_messages ) ? self :: $ default_messages [ $ this -> getStatus ( ) ] : '' ) ; } if ( $ this -> getResponse ( ) -> getStatus ( ) === null ) { $ this -> getResponse ( ) -> setStatus ( HttpStatus :: OK ) ; } $ this -> getResponse ( ) -> setHeaders ( $ this -> headers ) ; if ( $ return ) { return $ this -> getResponse ( ) ; } else { $ this -> getResponse ( ) -> send ( ) ; } }
Displays the request result
22,398
public function onPreAuthorizationProcess ( OAuthEvent $ event ) { if ( null !== $ client = $ event -> getClient ( ) ) { if ( $ client -> isPrivate ( ) ) { $ event -> setAuthorizedClient ( true ) ; } } }
called fos_oauth_server . pre_authorization_process
22,399
public static function gcd ( $ a , $ b ) { $ ta = abs ( $ a ) ; $ tb = abs ( $ b ) ; while ( $ tb != 0 ) { $ tmp = $ tb ; $ tb = $ ta % $ tb ; $ ta = $ tmp ; } return $ ta ; }
Computes the greatest common divisor .