idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
9,100
static public function removeRecursive ( $ directory ) { $ sourceDir = realpath ( $ directory ) ; if ( ! $ sourceDir ) { throw new ezcBaseFileNotFoundException ( $ directory , 'directory' ) ; } $ d = @ dir ( $ sourceDir ) ; if ( ! $ d ) { throw new ezcBaseFilePermissionException ( $ directory , ezcBaseFileException :: READ ) ; } $ parentDir = realpath ( $ directory . DIRECTORY_SEPARATOR . '..' ) ; if ( ! is_writable ( $ parentDir ) ) { throw new ezcBaseFilePermissionException ( $ parentDir , ezcBaseFileException :: WRITE ) ; } while ( ( $ entry = $ d -> read ( ) ) !== false ) { if ( $ entry == '.' || $ entry == '..' ) { continue ; } if ( is_dir ( $ sourceDir . DIRECTORY_SEPARATOR . $ entry ) ) { self :: removeRecursive ( $ sourceDir . DIRECTORY_SEPARATOR . $ entry ) ; } else { if ( @ unlink ( $ sourceDir . DIRECTORY_SEPARATOR . $ entry ) === false ) { throw new ezcBaseFilePermissionException ( $ directory . DIRECTORY_SEPARATOR . $ entry , ezcBaseFileException :: REMOVE ) ; } } } $ d -> close ( ) ; rmdir ( $ sourceDir ) ; }
Removes files and directories recursively from a file system
9,101
static public function copyRecursive ( $ source , $ destination , $ depth = - 1 , $ dirMode = 0775 , $ fileMode = 0664 ) { if ( ! is_file ( $ source ) && ! is_dir ( $ source ) ) { throw new ezcBaseFileNotFoundException ( $ source ) ; } if ( is_file ( $ destination ) || is_dir ( $ destination ) ) { throw new ezcBaseFilePermissionException ( $ destination , ezcBaseFileException :: WRITE ) ; } if ( ! is_readable ( $ source ) ) { return ; } if ( is_dir ( $ source ) ) { mkdir ( $ destination ) ; chmod ( $ destination , $ dirMode ) ; } elseif ( is_file ( $ source ) ) { copy ( $ source , $ destination ) ; chmod ( $ destination , $ fileMode ) ; } if ( ( $ depth === 0 ) || ( ! is_dir ( $ source ) ) ) { return ; } $ dh = opendir ( $ source ) ; while ( ( $ file = readdir ( $ dh ) ) !== false ) { if ( ( $ file === '.' ) || ( $ file === '..' ) ) { continue ; } self :: copyRecursive ( $ source . '/' . $ file , $ destination . '/' . $ file , $ depth - 1 , $ dirMode , $ fileMode ) ; } }
Recursively copy a file or directory .
9,102
public function request ( $ path , $ body = null , $ httpMethod = 'GET' , array $ options = array ( ) ) { $ headers = array ( ) ; $ options = array_merge ( $ this -> options , $ options ) ; if ( isset ( $ options [ 'headers' ] ) ) { $ headers = $ options [ 'headers' ] ; unset ( $ options [ 'headers' ] ) ; } $ headers = array_merge ( $ this -> headers , array_change_key_case ( $ headers ) ) ; unset ( $ options [ 'body' ] ) ; unset ( $ options [ 'base' ] ) ; unset ( $ options [ 'user_agent' ] ) ; $ request = $ this -> createRequest ( $ httpMethod , $ path , null , $ headers , $ options ) ; if ( $ httpMethod != 'GET' ) { $ request = $ this -> setBody ( $ request , $ body , $ options ) ; } try { $ response = $ this -> client -> send ( $ request ) ; } catch ( \ LogicException $ e ) { throw new \ ErrorException ( $ e -> getMessage ( ) ) ; } catch ( \ RuntimeException $ e ) { throw new \ RuntimeException ( $ e -> getMessage ( ) ) ; } return new Response ( $ this -> getBody ( $ response ) , $ response -> getStatusCode ( ) , $ response -> getHeaders ( ) ) ; }
Intermediate function which does three main things
9,103
public function createRequest ( $ httpMethod , $ path , $ body = null , array $ headers = array ( ) , array $ options = array ( ) ) { $ version = ( isset ( $ options [ 'api_version' ] ) ? "/" . $ options [ 'api_version' ] : "" ) ; $ path = $ version . $ path ; return $ this -> client -> createRequest ( $ httpMethod , $ path , $ headers , $ body , $ options ) ; }
Creating a request with the given arguments
9,104
public function setBody ( RequestInterface $ request , $ body , $ options ) { return RequestHandler :: setBody ( $ request , $ body , $ options ) ; }
Set request body in correct format
9,105
public function getClient ( ) { if ( ! $ this -> client ) { $ client = new GuzzleHelper ( ) ; $ this -> configureClient ( $ client ) ; return $ this -> client = $ client -> getClient ( ) ; } return $ this -> client ; }
Get new Curl instance
9,106
public function performRequest ( $ url ) { $ client = $ this -> getClient ( ) ; return $ this -> response = $ client -> get ( $ url ) ; }
Perform HTTP request
9,107
public function getPageTitle ( ) { if ( ! $ this -> parser ) { return ; } $ node = $ this -> parser -> find ( 'title' , 0 ) ; if ( $ node ) { return $ node -> innertext ; } }
Get page title
9,108
public function getPageDescription ( ) { if ( ! $ this -> parser ) { return ; } $ node = $ this -> parser -> find ( 'meta[name=description]' , 0 ) ; if ( $ node ) { return $ node -> getAttribute ( 'content' ) ; } }
Get page description
9,109
public function getPageKeywords ( ) { if ( ! $ this -> parser ) { return ; } $ node = $ this -> parser -> find ( 'meta[name=keywords]' , 0 ) ; if ( $ node ) { return $ node -> getAttribute ( 'content' ) ; } }
Get page keywords
9,110
public function getPageCanonical ( ) { if ( ! $ this -> parser ) { return ; } $ node = $ this -> parser -> find ( 'link[rel=canonical]' , 0 ) ; if ( $ node ) { return $ node -> getAttribute ( 'href' ) ; } }
Get page canonical url
9,111
public function getPageFavicon ( ) { if ( ! $ this -> parser ) { return ; } $ node = $ this -> parser -> find ( 'link[rel=shortcut], link[rel=icon], link[rel=shortcut icon]' , 0 ) ; if ( $ node ) { return $ node -> getAttribute ( 'href' ) ; } }
Get page favicon url
9,112
public function getPageMetas ( ) { if ( ! $ this -> parser ) { return ; } $ nodes = $ this -> parser -> find ( 'meta' ) ; $ metas = array ( ) ; foreach ( $ nodes as $ node ) { if ( $ node -> hasAttribute ( 'name' ) ) { $ metas [ $ node -> getAttribute ( 'name' ) ] = $ node -> getAttribute ( 'content' ) ; } elseif ( $ node -> hasAttribute ( 'property' ) ) { $ metas [ $ node -> getAttribute ( 'property' ) ] = $ node -> getAttribute ( 'content' ) ; } } return $ metas ; }
Get meta description
9,113
public function getPageFeeds ( ) { if ( ! $ this -> parser ) { return ; } $ nodes = $ this -> parser -> find ( 'link' ) ; $ feeds = array ( ) ; $ types = array ( 'application/rss+xml' , 'application/atom+xml' , 'text/xml' , ) ; foreach ( $ nodes as $ node ) { $ type = strtolower ( $ node -> getAttribute ( 'type' ) ) ; if ( in_array ( $ type , $ types ) ) { $ feeds [ ] = $ node -> getAttribute ( 'href' ) ; } } return $ feeds ; }
Get rss feeds urls
9,114
public function clear ( ) { $ this -> response = null ; if ( $ this -> parser ) { $ this -> parser -> clear ( ) ; } $ this -> parser = null ; }
Clean up memory
9,115
private static function data_type ( $ column ) { global $ wpdb ; $ sql = $ column [ 'type' ] ; if ( self :: DECIMAL == $ column [ 'type' ] ) { $ sql .= sprintf ( '(%d, %d)' , $ column [ 'max_digit' ] , $ column [ 'float' ] ) ; } if ( isset ( $ column [ 'length' ] ) ) { $ sql .= sprintf ( '(%d)' , $ column [ 'length' ] ) ; } if ( self :: is_set ( $ column [ 'type' ] ) ) { $ values = [ ] ; foreach ( $ column [ 'values' ] as $ val ) { $ values [ ] = $ wpdb -> prepare ( '%s' , $ val ) ; } $ sql .= sprintf ( '(%s)' , implode ( ', ' , $ values ) ) ; } if ( self :: is_numeric ( $ column [ 'type' ] ) && isset ( $ column [ 'signed' ] ) && ! $ column [ 'signed' ] ) { $ sql .= ' UNSIGNED' ; } if ( ! $ column [ 'null' ] ) { $ sql .= ' NOT NULL' ; } if ( isset ( $ column [ 'auto_increment' ] ) && $ column [ 'auto_increment' ] ) { $ sql .= ' AUTO_INCREMENT' ; } if ( isset ( $ column [ 'primary' ] ) && $ column [ 'primary' ] ) { $ sql .= ' PRIMARY KEY' ; } if ( isset ( $ column [ 'default' ] ) ) { if ( self :: is_numeric ( $ column [ 'default' ] ) ) { $ repl = ' DEFAULT ' . $ column [ 'default' ] ; } else { switch ( $ column [ 'default' ] ) { case 'CURRENT_TIMESTAMP' : $ sql .= " DEFAULT {$column['default']}" ; break ; default : $ sql .= $ wpdb -> prepare ( ' DEFAULT %s' , $ column [ 'default' ] ) ; break ; } } } return $ sql ; }
Build data type on create statement
9,116
public static function filter ( $ column ) { $ column = wp_parse_args ( $ column , [ 'type' => '' , 'null' => false , ] ) ; if ( ! self :: exists ( $ column [ 'type' ] ) ) { throw new \ Exception ( 'You must properly specify the data type of column.' ) ; } if ( self :: is_length_required ( $ column [ 'type' ] ) && ! isset ( $ column [ 'length' ] ) ) { throw new \ Exception ( sprintf ( 'Column %s requires length property.' , $ column [ 'type' ] ) ) ; } if ( self :: is_numeric ( $ column [ 'type' ] ) ) { $ column [ 'signed' ] = isset ( $ column [ 'signed' ] ) ? ( bool ) $ column [ 'signed' ] : true ; } if ( $ column [ 'type' ] == self :: DECIMAL ) { if ( ! isset ( $ column [ 'max_digit' ] , $ column [ 'float' ] ) ) { throw new \ Exception ( sprintf ( 'Column %s requires max_digit and float property.' , self :: DECIMAL ) ) ; } } if ( self :: is_set ( $ column [ 'type' ] ) && ( ! is_array ( $ column [ 'values' ] ) || empty ( $ column [ 'values' ] ) ) ) { throw new \ Exception ( sprintf ( 'Column %s requires values property as array.' , $ column [ 'type' ] ) ) ; } return $ column ; }
Filter column array
9,117
protected function convertArgs ( $ step ) { if ( $ step instanceof Operator ) { $ arguments = $ step -> getArguments ( ) ; } else { $ arguments = $ step ; } if ( is_array ( $ arguments ) ) { $ values = [ ] ; foreach ( $ arguments as $ key => $ args ) { if ( $ args instanceof Operator ) { if ( is_string ( $ key ) ) { $ values [ $ key ] = [ $ this -> cmd . $ args -> getOperatorName ( ) => $ this -> convertArgs ( $ args ) ] ; } else { $ values [ ] = [ $ this -> cmd . $ args -> getOperatorName ( ) => $ this -> convertArgs ( $ args ) ] ; } } else { if ( is_string ( $ key ) ) { $ values [ $ key ] = $ this -> convertArgs ( $ args ) ; } else { $ values [ ] = $ args ; } } } return $ values ; } elseif ( $ arguments instanceof Operator ) { return [ $ this -> cmd . $ arguments -> getOperatorName ( ) => $ this -> convertArgs ( $ arguments ) ] ; } else { return $ arguments ; } }
Recursive convert args
9,118
public function makeCall ( array $ input ) { $ input = array_replace_recursive ( array ( 'function' => null , ) , $ input , array ( 'arguments' => array ( ) , 'options' => array ( ) , 'headers' => array ( ) , ) ) ; if ( empty ( $ input [ 'function' ] ) ) { throw new EssenceException ( 'The SOAP function is not set' ) ; } try { $ this -> client -> __soapCall ( $ input [ 'function' ] , array ( $ input [ 'arguments' ] ) , $ input [ 'options' ] , $ input [ 'headers' ] , $ this -> lastResponseHeaders ) ; $ this -> lastRequest = $ this -> client -> __getLastRequest ( ) ; $ this -> lastResponse = $ this -> client -> __getLastResponse ( ) ; return $ this -> lastResponse ; } catch ( SoapFault $ e ) { $ this -> lastRequest = $ this -> client -> __getLastRequest ( ) ; $ this -> lastResponse = $ this -> client -> __getLastResponse ( ) ; throw new EssenceException ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } }
Make SOAP call
9,119
public function ask ( $ question , $ weight = "y" ) { $ question = self :: format ( $ question ) ; $ y = $ weight == 'y' ? 'Y' : 'y' ; $ n = $ weight == 'n' ? 'N' : 'n' ; $ answer = $ this -> prompt ( "$question [$y/$n]" ) ; $ line = trim ( strtolower ( $ answer ) ) ; if ( empty ( $ line ) ) { $ line = $ weight ; } return in_array ( $ line , array ( 'y' , 'yes' ) ) ; }
Asks the user a question . If a y value is entered returns true
9,120
public function prompt ( $ question ) { $ question = self :: format ( $ question ) ; $ this -> write ( "$question: " ) ; $ handle = fopen ( "php://stdin" , "r" ) ; return fgets ( $ handle ) ; }
Prompts the user for input
9,121
public function updateProgress ( $ text ) { $ text = self :: format ( $ text ) ; if ( $ this -> progressValue ) { $ len = strlen ( $ this -> progressValue ) ; fwrite ( STDOUT , "\033[{$len}D" ) ; } $ this -> progressValue = $ text ; fwrite ( STDOUT , $ this -> progressValue ) ; }
Updates the output with new text
9,122
public function setBackplaneProperties ( array $ params ) { if ( ! isset ( $ params [ 'server' ] ) ) { throw new MissingArgumentException ( 'server' ) ; } if ( ! isset ( $ params [ 'bus' ] ) ) { throw new MissingArgumentException ( 'bus' ) ; } return $ this -> post ( 'set_backplane_properties' , $ params ) ; }
Configures Backplane server used to communicate with all of the Backplane enabled widgets on a page .
9,123
public function build ( $ name , Collection $ fields = null ) { $ path = $ this -> getClassFilePath ( $ name ) ; $ contents = view ( '_hierarchy::entities.form' , [ 'name' => $ this -> getClassName ( $ name ) , 'fields' => $ fields ? : [ ] ] ) -> render ( ) ; $ this -> write ( $ path , $ contents ) ; }
Builds a source form
9,124
protected function getFileNames ( string $ directory = 'default' ) : array { $ directoryIterator = $ this -> getDirectoryIterator ( $ directory ) ; $ files = [ ] ; foreach ( $ directoryIterator as $ file ) { $ this -> resolveFile ( $ file , $ files ) ; } return $ files ; }
Get list of paths in directory
9,125
private function resolveFile ( \ DirectoryIterator $ file , array & $ files ) { if ( $ file -> isDir ( ) && ! $ file -> isDot ( ) ) { $ files = Tools :: resolvePath ( $ files , $ this -> getFileNames ( ) ) ; } if ( $ file -> isFile ( ) && ! $ file -> isLink ( ) && $ file -> isReadable ( ) ) { $ files = Tools :: resolvePath ( $ files , $ file -> getRealPath ( ) ) ; } }
Add file to list or scan directory
9,126
private function getDirectoryIterator ( string $ directory ) : \ DirectoryIterator { if ( $ directory === 'default' ) { return new \ DirectoryIterator ( $ this -> dataDirectory ) ; } return new \ DirectoryIterator ( $ directory ) ; }
Get Directory Iterator
9,127
protected function getDateTimeFormat ( $ parameters ) { $ format = 'Y-m-d H:i:s' ; $ parametersCount = count ( $ parameters ) ; if ( $ parametersCount > $ this -> amountOfParameters ) { $ format = $ parameters [ $ parametersCount - 1 ] ; } return $ format ; }
Gets a date time format from the parameters if given or a default one .
9,128
protected function getDateTimes ( array $ parameters , $ format ) { if ( ! $ this -> dateTimeParameters ) { return [ ] ; } $ datetimes = [ ] ; for ( $ i = 0 ; $ i < $ this -> amountOfParameters ; ++ $ i ) { $ datetime = \ DateTime :: createFromFormat ( $ format , $ parameters [ $ i ] ) ; if ( $ datetime === false ) { throw new ValidationException ( '"' . $ this -> type . '" expects a date of the format "' . $ format . '".' ) ; } $ datetimes [ ] = $ datetime ; } return $ datetimes ; }
Interprets the given parameters as date times and returns them .
9,129
public function jsonSerialize ( ) { $ json = array ( ) ; foreach ( get_object_vars ( $ this ) as $ var => $ val ) { if ( $ val instanceof \ DateTime ) $ json [ $ var ] = $ val -> getTimestamp ( ) ; else $ json [ $ var ] = $ val ; } return $ json ; }
Get a json serialized version of this object .
9,130
protected function doSaveDependingOnFiles ( $ id , $ data , array $ files , $ lifeTime = 0 ) { $ dependencies = [ NetteCache :: TAGS => [ 'doctrine' ] , NetteCache :: FILES => $ files ] ; if ( $ lifeTime != 0 ) { $ dependencies [ NetteCache :: EXPIRE ] = time ( ) + $ lifeTime ; } $ this -> cache -> save ( $ id , $ data , $ dependencies ) ; return TRUE ; }
Puts data into the cache and makes them depending on the files .
9,131
protected function toMarkdown ( $ content ) { $ tmpfname = tempnam ( sys_get_temp_dir ( ) , 'fillet' ) ; file_put_contents ( $ tmpfname , $ content ) ; $ cmd = $ this -> config [ 'pandoc' ] [ 'bin' ] . ' --no-wrap -f html -t markdown ' . $ tmpfname ; $ content = shell_exec ( $ cmd ) ; unlink ( $ tmpfname ) ; return $ content ; }
Converts content from HTML to Markdown via pandoc
9,132
public function get ( $ id ) { $ resource = self :: $ BASE_URI . '/' . $ this -> cityId . '/bairros/' . $ this -> neighborhoodId . '/logradouro/' . $ id ; $ data = $ this -> execute ( self :: HTTP_GET , $ resource ) ; return $ data ; }
Gets the street data according to the id parameter
9,133
public function addBefore ( $ before , $ name , SymfonyRoute $ route ) { $ newRoute = $ route ; foreach ( $ this -> all ( ) as $ routeName => $ route ) { if ( null !== $ newRoute && $ before === $ routeName ) { $ this -> add ( $ name , $ newRoute ) ; $ newRoute = null ; } if ( null === $ newRoute ) { $ this -> add ( $ routeName , $ route ) ; } } if ( null !== $ newRoute ) { throw new \ InvalidArgumentException ( sprintf ( 'The route "%s" cannot be added before "%s", because the route "%2$s" was not found.' , $ name , $ before ) ) ; } }
Adds a route before another .
9,134
public function key_search ( array $ array , $ key , $ value ) { foreach ( $ array as $ key => $ a ) { if ( isset ( $ a [ $ key ] ) && $ a [ $ key ] == $ value ) { return $ key ; } } return false ; }
Get index of array member with specified key
9,135
public function prop_search ( array $ array , $ property , $ value ) { foreach ( $ array as $ key => $ a ) { if ( property_exists ( $ a , $ property ) && $ a -> { $ property } == $ value ) { return $ key ; } } return false ; }
Search array member with specified property
9,136
private function queueConfigs ( ) { $ config = $ this -> getConfig ( ) ; if ( ! isset ( $ config [ 'schedulers' ] ) ) { yield $ config ; return ; } foreach ( $ config [ 'schedulers' ] as $ child_config ) { yield mergeConfigOptions ( $ config , $ child_config ) ; } }
return only the normalized queue configurations
9,137
public function parseBody ( $ line ) { $ this -> mailParser -> parseBody ( $ line ) ; $ this -> size += strlen ( $ line ) ; }
Parses each line of the digest body .
9,138
public function finish ( ) { $ digest = new ezcMailRfc822Digest ( $ this -> mailParser -> finish ( ) ) ; ezcMailPartParser :: parsePartHeaders ( $ this -> headers , $ digest ) ; $ digest -> size = $ this -> size ; return $ digest ; }
Returns a ezcMailRfc822Digest with the digested mail in it .
9,139
protected function typeEnum ( Fluent $ column ) { $ allowed = array_map ( function ( $ a ) { return "'{$a}'" ; } , $ column -> allowed ) ; return "varchar(255) check (\"{$column->name}\" in (" . implode ( ', ' , $ allowed ) . '))' ; }
Create the column definition for an enum type .
9,140
public function tunnel ( $ host , $ port ) { $ stream = @ ssh2_tunnel ( $ this -> connection , $ command ) ; if ( ! $ stream ) { throw new \ Exception ( 'Cannot create tunnel to: ' . $ host . ' on port' . $ port ) ; } return $ stream ; }
Tunnels a connection
9,141
public function merge ( array $ logics ) { foreach ( $ logics as $ name => $ specs ) { $ this -> set ( $ name , $ specs ) ; } return $ this ; }
Merge multiple logics
9,142
protected function before ( Context $ context ) { $ context -> forwarder = $ context -> forwarder ? : [ $ this , 'forward' ] ; return parent :: before ( $ context ) ; }
Setup context before process
9,143
protected function route ( Context $ context ) { $ this -> logger -> debug ( 'kernel.route: find route from http query' ) ; if ( $ context -> logic ) { $ this -> logger -> debug ( 'kernel.route: forward to #' . $ context -> logic -> name . ', skip routing' ) ; return $ context ; } $ query = $ context -> request -> method . ' ' . $ context -> request -> uri -> path ; $ route = $ this -> router -> find ( $ query ) ; if ( ! $ route ) { throw new NotFoundException ( 'No route found for query ' . $ query ) ; } $ context -> route = $ route ; $ context -> params = $ route -> params ; $ context -> logic = $ route -> resource ; $ this -> logger -> debug ( 'kernel.route: #' . $ context -> logic -> name . ' found for query ' . $ query ) ; return $ context ; }
Find route from context
9,144
public static function formatAttributes ( $ destroy_callback = null , $ create_callback = null , $ sticky = null , $ life = null , $ classname = null , $ width = null ) { $ options = [ ] ; if ( $ destroy_callback !== null ) { $ options [ 'destroyed' ] = $ destroy_callback ; } if ( $ create_callback !== null ) { $ options [ 'created' ] = $ create_callback ; } if ( $ sticky !== null ) { $ options [ 'sticky' ] = ! ! $ sticky ; } if ( $ life !== null ) { $ options [ 'life' ] = $ life ; } if ( $ classname !== null ) { $ options [ 'className' ] = $ classname ; } if ( $ width !== null ) { $ options [ 'width' ] = $ width ; } return $ options ; }
Static method for retrieving the options - array .
9,145
private function getFacebookSession ( $ accessToken ) { $ facebookSession = new FacebookSession ( $ accessToken ) ; try { $ facebookSession -> validate ( ) ; return $ facebookSession ; } catch ( FacebookRequestException $ ex ) { throw new FacebookException ( $ ex -> getMessage ( ) ) ; } catch ( \ Exception $ ex ) { throw new FacebookException ( $ ex -> getMessage ( ) ) ; } }
Get the FacebookSession through an access_token .
9,146
public function connect ( $ accessToken = null ) { if ( is_null ( $ accessToken ) ) { return $ this -> getRedirectLoginHelper ( ) ; } else { return $ this -> getFacebookSession ( $ accessToken ) ; } }
Trigger method that can get either a facebook session with access token or a redirect login helper .
9,147
public function process ( ) { try { $ redirectLoginHelper = $ this -> getRedirectLoginHelper ( ) ; return $ this -> connect ( $ redirectLoginHelper -> getSessionFromRedirect ( ) -> getToken ( ) ) ; } catch ( FacebookRequestException $ ex ) { throw new FacebookException ( $ ex -> getMessage ( ) ) ; } catch ( \ Exception $ ex ) { throw new FacebookException ( $ ex -> getMessage ( ) ) ; } }
Get the redirect postback sent from facebook processed ready to a facebook session .
9,148
public function api ( FacebookSession $ fbsession , $ method , $ call ) { try { $ facebookResponse = ( new FacebookRequest ( $ fbsession , $ method , $ call ) ) -> execute ( ) ; return $ graphObject = $ facebookResponse -> getGraphObject ( ) ; } catch ( FacebookRequestException $ ex ) { throw new FacebookException ( $ ex -> getMessage ( ) ) ; } catch ( \ Exception $ ex ) { throw new FacebookException ( $ ex -> getMessage ( ) ) ; } }
Make a request into facebook api .
9,149
public function change ( $ appId , $ appSecret , $ redirectUrl = null ) { \ Config :: set ( 'facebook::app.appId' , $ appId ) ; \ Config :: set ( 'facebook::app.appSecret' , $ appSecret ) ; if ( ! is_null ( $ redirectUrl ) ) \ Config :: set ( 'facebook::app.redirectUrl' , $ redirectUrl ) ; return $ this ; }
Change the appId appSecret and redirectUrl before connecting .
9,150
public function has ( $ name ) : bool { try { $ this -> container -> get ( $ name ) ; return true ; } catch ( \ Exception $ e ) { return false ; } }
Check if service is registered .
9,151
public function transform ( $ translation ) { $ translation = $ this -> entityToArray ( BlockTranslation :: class , $ translation ) ; return [ 'id' => ( int ) $ translation [ 'id' ] , 'langCode' => $ translation [ 'lang_code' ] , 'title' => $ translation [ 'title' ] , 'body' => $ translation [ 'body' ] , 'customFields' => $ this -> transformCustomFields ( $ translation ) , 'isActive' => ( bool ) $ translation [ 'is_active' ] , 'createdAt' => $ translation [ 'created_at' ] , 'updatedAt' => $ translation [ 'updated_at' ] , ] ; }
Transforms block translation entity
9,152
public function toSeconds ( ) { $ seconds = $ this -> s ; $ seconds += $ this -> i * 60 ; $ seconds += $ this -> h * 3600 ; if ( $ this -> days ) { $ seconds += $ this -> days * 86400 ; } else { if ( $ this -> d ) { $ seconds += $ this -> d * 86400 ; } if ( $ this -> m ) { trigger_error ( 'Calculating seconds for interval with months property. Result may not be accurate.' , E_USER_WARNING ) ; $ seconds += 2629800 ; } if ( $ this -> y ) { trigger_error ( 'Calculating seconds for interval with years property. Result may not be accurate.' , E_USER_WARNING ) ; $ seconds += $ this -> y * 31557600 ; } } return $ seconds ; }
Convert interval to number of seconds
9,153
protected static function isQuirkMode ( ) { if ( null === self :: $ quirkMode ) { self :: $ quirkMode = version_compare ( PHP_VERSION , '5.5.4' , '<' ) && version_compare ( PHP_VERSION , '5.5.0' , '>' ) || version_compare ( PHP_VERSION , '5.4.20' , '<' ) ; } return self :: $ quirkMode ; }
Test if PHP version has quirks
9,154
protected function compileInitialization ( Buffer $ buffer ) { $ buffer -> write ( '$app = new Zicht\Tool\Application(' ) -> asPhp ( $ this -> appName ) -> raw ( ', Zicht\Version\Version::fromString(' ) -> asPhp ( $ this -> appVersion ) -> raw ( ') ?: new Zicht\Version\Version(), Zicht\Tool\Configuration\ConfigurationLoader::fromEnv(' ) -> asPhp ( $ this -> configFilename ) -> raw ( ')' ) -> raw ( ');' ) -> eol ( ) ; }
Writes the initialization code for a dynamic build
9,155
public function reset ( ) { $ this -> _current_cfg = [ ] ; $ this -> _cfg = [ ] ; $ this -> _root_element = false ; $ this -> _current_element = false ; foreach ( $ this -> _defaults as $ k => $ v ) { $ this -> _current_cfg [ $ k ] = $ v ; } return $ this ; }
Sets the configuration back to its default value
9,156
public function export_config ( ) { if ( isset ( $ this -> _root_element ) ) { return bbn \ str :: make_readable ( $ this -> _root_element -> get_config ( ) ) ; } return bbn \ str :: make_readable ( $ this -> _cfg ) ; }
Returns the current configuration
9,157
public function option ( $ opt ) { $ args = \ func_get_args ( ) ; if ( \ is_array ( $ opt ) && isset ( $ opt [ 0 ] , $ this -> _defaults [ $ opt [ 0 ] ] ) ) { $ this -> _current_cfg [ $ opt [ 0 ] ] = $ opt [ 1 ] ; } else if ( isset ( $ args [ 0 ] , $ args [ 1 ] , $ this -> _defaults [ $ args [ 0 ] ] ) ) { $ this -> _current_cfg [ $ args [ 0 ] ] = $ args [ 1 ] ; } else { throw new InvalidArgumentException ( 'This configuration argument is imaginary... Sorry! :)' ) ; } return $ this ; }
Change an option in the current configuration - Chainable
9,158
public function passesOrFail ( $ action = null ) { if ( ! $ this -> passes ( $ action ) ) { throw new ValidatorException ( $ this -> errorsBag ( ) ) ; } return true ; }
Pass the data and the rules to the validator or throws ValidatorException
9,159
protected function parserValidationRules ( $ rules , $ id = null ) { if ( $ id === null ) { return $ rules ; } array_walk ( $ rules , function ( & $ rules , $ field ) use ( $ id ) { if ( ! is_array ( $ rules ) ) { $ rules = explode ( "|" , $ rules ) ; } foreach ( $ rules as $ ruleIdx => $ rule ) { @ list ( $ name , $ params ) = array_pad ( explode ( ":" , $ rule ) , 2 , null ) ; if ( strtolower ( $ name ) != "unique" ) { continue ; } $ p = array_map ( "trim" , explode ( "," , $ params ) ) ; if ( ! isset ( $ p [ 1 ] ) ) { $ p [ 1 ] = $ field ; } $ p [ 2 ] = $ id ; $ params = implode ( "," , $ p ) ; $ rules [ $ ruleIdx ] = $ name . ":" . $ params ; } } ) ; return $ rules ; }
Parser Validation Rules
9,160
public function convert ( ResponseInterface $ psrResponse ) { return new BrowserKitResponse ( ( string ) $ psrResponse -> getBody ( ) , $ psrResponse -> getStatusCode ( ) ? : 200 , $ this -> flattenHeaders ( $ psrResponse -> getHeaders ( ) ) ) ; }
Convert a PSR - 7 response to a codeception response
9,161
public static function fromObjects ( $ array , $ key ) { $ elements = array ( ) ; foreach ( $ array as $ element ) { $ result = call_user_func ( array ( $ element , $ key ) ) ; $ elements = array_merge ( $ elements , is_array ( $ result ) ? $ result : array ( $ result ) ) ; } return new self ( $ elements ) ; }
Creates a partition from a set of objects .
9,162
public function partitionBy ( $ key ) { $ partition = array ( ) ; foreach ( $ this -> elements as $ element ) { $ newEquivalenceClass = true ; for ( $ i = 0 ; $ i < count ( $ partition ) ; $ i ++ ) if ( call_user_func ( array ( $ element , $ key ) , $ partition [ $ i ] [ 0 ] ) ) { $ partition [ $ i ] [ ] = $ element ; $ newEquivalenceClass = false ; } if ( $ newEquivalenceClass ) $ partition [ ] = array ( $ element ) ; } return $ partition ; }
Partitions the elements using an equivalence relation .
9,163
public static function escape ( $ mixed , $ quote_style = ENT_QUOTES , $ charset = 'UTF-8' ) { if ( is_string ( $ mixed ) ) { $ mixed = htmlspecialchars ( $ mixed , $ quote_style , $ charset ) ; } elseif ( is_object ( $ mixed ) || is_array ( $ mixed ) ) { foreach ( $ mixed as $ k => & $ v ) { if ( $ v ) { if ( is_object ( $ mixed ) ) { $ mixed -> $ k = self :: escape ( $ v , $ quote_style , $ charset ) ; } else { $ mixed [ $ k ] = self :: escape ( $ v , $ quote_style , $ charset ) ; } } } } return $ mixed ; }
Recursively htmlspecialchars string properties of objects and arrays
9,164
public static function unescape ( $ mixed , $ quote_style = ENT_QUOTES , $ charset = 'UTF-8' ) { if ( is_string ( $ mixed ) ) { $ mixed = str_replace ( '&amp;' , '&' , $ mixed ) ; $ mixed = str_replace ( '&#039;' , '\'' , $ mixed ) ; $ mixed = str_replace ( '&quot;' , '"' , $ mixed ) ; $ mixed = str_replace ( '&lt;' , '<' , $ mixed ) ; $ mixed = str_replace ( '&gt;' , '>' , $ mixed ) ; } elseif ( is_object ( $ mixed ) || is_array ( $ mixed ) ) { foreach ( $ mixed as $ k => & $ v ) { if ( $ v ) { if ( is_object ( $ mixed ) ) { $ mixed -> $ k = self :: unescape ( $ v ) ; } else { $ mixed [ $ k ] = self :: unescape ( $ v ) ; } } } } return $ mixed ; }
Recursively unhtmlspecialchars string properties of objects and arrays
9,165
public function authenticate ( Request $ request ) { $ email = $ request -> input ( self :: AUTH_PARAM_EMAIL , null ) ; $ password = $ request -> input ( self :: AUTH_PARAM_PASSWORD , null ) ; if ( $ email !== null && $ password !== null && ( $ user = User :: query ( ) -> where ( User :: FIELD_EMAIL , '=' , strtolower ( $ email ) ) -> first ( ) ) !== null ) { $ hasher = app ( HasherInterface :: class ) ; if ( $ hasher -> check ( $ password , $ user -> { User :: FIELD_PASSWORD_HASH } ) === true ) { $ codec = app ( TokenCodecInterface :: class ) ; $ token = $ codec -> encode ( $ user ) ; $ this -> getLogger ( ) -> debug ( 'Account login success.' , [ User :: FIELD_EMAIL => $ email , User :: FIELD_ID => $ user -> getKey ( ) ] ) ; return response ( $ token ) ; } } $ this -> getLogger ( ) -> debug ( 'Account login failed.' , [ User :: FIELD_EMAIL => $ email ] ) ; return response ( null , Response :: HTTP_UNAUTHORIZED ) ; }
Issue auth token .
9,166
public function getFilteredParameter ( $ name ) { if ( array_key_exists ( $ name , $ this -> parameters ) == false ) { throw new \ Exception ( 'Parameter ' . $ name . ' does not exist.' ) ; } $ value = $ this -> parameters [ $ name ] ; return $ value ; }
Apply any filters necessary to the parameter
9,167
public function get_extension ( ) { parent :: get_extension ( ) ; if ( ! $ this -> ext2 && $ this -> file ) { if ( function_exists ( 'exif_imagetype' ) ) { if ( $ r = exif_imagetype ( $ this -> file ) ) { if ( ! array_key_exists ( $ r , bbn \ file \ image :: $ allowed_extensions ) ) { $ this -> ext = false ; } } else { $ this -> ext = false ; } } if ( $ this -> ext ) { $ this -> ext2 = $ this -> ext ; if ( $ this -> ext2 === 'jpg' ) { $ this -> ext2 = 'jpeg' ; } } } return $ this -> ext ; }
Returns the extension of the image . If the file has jpg extension will return jpeg .
9,168
public function display ( ) { if ( $ this -> test ( ) ) { if ( ! headers_sent ( ) ) { header ( 'Content-Type: image/' . $ this -> ext2 ) ; } if ( class_exists ( '\\Imagick' ) ) { echo $ this -> img ; $ this -> img -> clear ( ) ; $ this -> img -> destroy ( ) ; } else { \ call_user_func ( 'image' . $ this -> ext2 , $ this -> img ) ; imagedestroy ( $ this -> img ) ; } } return $ this ; }
Sends the image with Content - Type .
9,169
public function crop ( $ w , $ h , $ x , $ y ) { if ( $ this -> test ( ) ) { $ args = \ func_get_args ( ) ; foreach ( $ args as $ arg ) { if ( ! is_numeric ( $ arg ) ) { $ this -> error = \ defined ( 'BBN_ARGUMENTS_MUST_BE_NUMERIC' ) ? BBN_ARGUMENTS_MUST_BE_NUMERIC : 'Arguments must be numeric' ; } } if ( $ w + $ x > $ this -> w ) { return false ; } if ( $ h + $ y > $ this -> h ) { return false ; } if ( class_exists ( '\\Imagick' ) ) { if ( ! $ this -> img -> cropImage ( $ w , $ h , $ x , $ y ) ) { $ this -> error = \ defined ( 'BBN_THERE_HAS_BEEN_A_PROBLEM' ) ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem' ; } } else { $ img = imagecreatetruecolor ( $ w , $ h ) ; if ( $ this -> ext == 'png' || $ this -> ext == 'gif' || $ this -> ext == 'svg' ) { imageColorAllocateAlpha ( $ img , 0 , 0 , 0 , 127 ) ; imagealphablending ( $ img , false ) ; imagesavealpha ( $ img , true ) ; } if ( imagecopyresampled ( $ img , $ this -> img , 0 , 0 , $ x , $ y , $ w , $ h , $ w , $ h ) ) { $ this -> img = $ img ; } else { $ this -> error = \ defined ( 'BBN_THERE_HAS_BEEN_A_PROBLEM' ) ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem' ; } } } return $ this ; }
Returns a crop of the image .
9,170
public function brightness ( $ val = '+' ) { if ( $ this -> test ( ) ) { if ( class_exists ( '\\Imagick' ) ) { $ p = ( $ val == '-' ) ? 90 : 110 ; if ( ! $ this -> img -> modulateImage ( $ p , 100 , 100 ) ) { $ this -> error = \ defined ( 'BBN_THERE_HAS_BEEN_A_PROBLEM' ) ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem' ; } } else if ( function_exists ( 'imagefilter' ) ) { $ p = ( $ val == '-' ) ? - 20 : 20 ; if ( ! imagefilter ( $ this -> img , IMG_FILTER_BRIGHTNESS , - 20 ) ) { $ this -> error = \ defined ( 'BBN_THERE_HAS_BEEN_A_PROBLEM' ) ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem' ; } } } return $ this ; }
Adjusts the image s brightness .
9,171
public function contrast ( $ val = '+' ) { if ( $ this -> test ( ) ) { if ( class_exists ( '\\Imagick' ) ) { $ p = ( $ val == '-' ) ? 0 : 1 ; if ( ! $ this -> img -> contrastImage ( $ p ) ) { $ this -> error = \ defined ( 'BBN_THERE_HAS_BEEN_A_PROBLEM' ) ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem' ; } } else if ( function_exists ( 'imagefilter' ) ) { $ p = ( $ val == '-' ) ? - 20 : 20 ; if ( ! imagefilter ( $ this -> img , IMG_FILTER_CONTRAST , - 20 ) ) { $ this -> error = \ defined ( 'BBN_THERE_HAS_BEEN_A_PROBLEM' ) ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem' ; } } } return $ this ; }
Adjusts the image contrast .
9,172
public function grayscale ( ) { if ( $ this -> test ( ) ) { if ( class_exists ( '\\Imagick' ) ) { if ( ! $ this -> img -> modulateImage ( 100 , 0 , 100 ) ) { $ this -> error = \ defined ( 'BBN_THERE_HAS_BEEN_A_PROBLEM' ) ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem' ; } } else if ( function_exists ( 'imagefilter' ) ) { if ( ! imagefilter ( $ this -> img , IMG_FILTER_GRAYSCALE ) ) { $ this -> error = \ defined ( 'BBN_THERE_HAS_BEEN_A_PROBLEM' ) ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem' ; } } } return $ this ; }
Converts the image s color to grayscale .
9,173
public function negate ( ) { if ( $ this -> test ( ) ) { if ( class_exists ( '\\Imagick' ) ) { if ( ! $ this -> img -> negateImage ( false ) ) { $ this -> error = \ defined ( 'BBN_THERE_HAS_BEEN_A_PROBLEM' ) ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem' ; } } else if ( function_exists ( 'imagefilter' ) ) { if ( ! imagefilter ( $ this -> img , IMG_FILTER_NEGATE ) ) { $ this -> error = \ defined ( 'BBN_THERE_HAS_BEEN_A_PROBLEM' ) ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem' ; } } } return $ this ; }
Converts the image s color to negative .
9,174
public function polaroid ( ) { if ( $ this -> test ( ) ) { if ( class_exists ( '\\Imagick' ) ) { if ( ! $ this -> img -> polaroidImage ( new \ ImagickDraw ( ) , 0 ) ) { $ this -> error = \ defined ( 'BBN_THERE_HAS_BEEN_A_PROBLEM' ) ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem' ; } } } return $ this ; }
Converts the image s color with polaroid filter .
9,175
public function thumbs ( $ dest = '.' , $ sizes = [ [ false , 960 ] , [ false , 480 ] , [ false , 192 ] , [ false , 96 ] , [ false , 48 ] ] , $ mask = '_%s' , $ crop = false , $ bigger = false ) { if ( $ this -> test ( ) && is_dir ( $ dest ) ) { $ this -> get_extension ( ) ; $ w = $ this -> get_width ( ) ; $ h = $ this -> get_height ( ) ; $ d = $ w >= $ h ? 'w' : 'h' ; $ res = [ ] ; if ( bbn \ str :: is_integer ( $ sizes ) ) { $ sizes = [ [ $ sizes , false ] ] ; } if ( $ $ d / ( $ d === 'w' ? $ h : $ w ) < 5 ) { $ mask = ( $ dest === '.' ? '' : $ dest . '/' ) . $ this -> title . $ mask . '.' . $ this -> ext ; foreach ( $ sizes as $ s ) { if ( bbn \ str :: is_integer ( $ s ) ) { $ s = [ $ s , false ] ; } if ( ( ! empty ( $ s [ 0 ] ) && ( $ w > $ s [ 0 ] ) ) || ( ! empty ( $ s [ 1 ] ) && ( $ h > $ s [ 1 ] ) ) || $ bigger ) { $ smask = ( empty ( $ s [ 0 ] ) ? '' : 'w' . $ s [ 0 ] ) . ( empty ( $ s [ 1 ] ) ? '' : 'h' . $ s [ 1 ] ) ; $ fn = sprintf ( $ mask , $ smask ) ; if ( $ s [ 0 ] && $ s [ 1 ] ) { if ( $ crop ) { $ this -> resize ( $ s [ 0 ] , $ s [ 1 ] , true ) ; } else { $ this -> resize ( $ d === 'w' ? $ s [ 0 ] : false , $ d === 'h' ? $ s [ 1 ] : false , false , $ s [ 0 ] , $ s [ 1 ] ) ; } } else { $ this -> resize ( $ s [ 0 ] , $ s [ 1 ] , $ crop ) ; } $ this -> save ( $ fn ) ; $ res [ $ smask ] = $ fn ; } } return $ res ; } } return false ; }
Creates miniature of the image
9,176
public function toString ( ) { if ( $ this -> test ( ) ) { if ( class_exists ( '\\Imagick' ) ) $ m = $ this -> img ; else { ob_start ( ) ; \ call_user_func ( 'image' . $ this -> ext2 , $ this -> img ) ; $ m = ob_get_contents ( ) ; ob_end_clean ( ) ; } return 'data:image/' . $ this -> ext . ';base64,' . base64_encode ( $ m ) ; } }
Return the image as string .
9,177
public function addProvider ( PathProviderInterface $ provider , $ priority = 0 ) { $ this -> providers [ $ priority ] [ ] = $ provider ; $ this -> sorted = null ; }
For automatically injecting provider should be registered as DI service with tag layout . resource . path_provider
9,178
public function getLastVersion ( $ page_id ) { $ qb = $ this -> createQueryBuilder ( 'p' ) ; $ qb -> where ( 'p.original=:page_id' ) -> orderBy ( 'p.createdAt' , 'DESC' ) -> setParameter ( ':page_id' , $ page_id ) ; $ result = $ qb -> getQuery ( ) -> setMaxResults ( 1 ) -> getResult ( ) ; if ( is_null ( $ result ) ) { $ qb2 = $ this -> createQueryBuilder ( 'p' ) ; $ qb2 -> where ( 'p.id=:page_id' ) -> setParameter ( ':page_id' , $ page_id ) ; $ result = $ qb -> getQuery ( ) -> getResult ( ) ; } return $ result [ 0 ] ; }
Get last version for a page
9,179
public function findBySlug ( $ path ) { $ qb = $ this -> createQueryBuilder ( 'p' ) ; $ qb instanceof QueryBuilder ; $ qb -> add ( 'where' , $ qb -> expr ( ) -> like ( 'p.slug' , $ qb -> expr ( ) -> lower ( ':searched_term' ) ) ) -> setParameter ( 'searched_term' , $ path ) ; return $ qb -> getQuery ( ) -> getResult ( ) ; }
Find page by slug
9,180
protected function initializeState ( RawLayout $ rawLayout , ContextInterface $ context ) { $ this -> rawLayout = $ rawLayout ; $ this -> context = $ context ; $ this -> dataAccessor = new DataAccessor ( $ this -> registry , $ this -> context ) ; $ this -> optionsResolver = new BlockOptionsResolver ( $ this -> registry ) ; $ this -> typeHelper = new BlockTypeHelper ( $ this -> registry ) ; $ this -> blockBuilder = new BlockBuilder ( $ this -> layoutManipulator , $ this -> rawLayout , $ this -> typeHelper , $ this -> context ) ; $ this -> block = new Block ( $ this -> rawLayout , $ this -> typeHelper , $ this -> context , $ this -> dataAccessor ) ; }
Initializes the state of this factory
9,181
protected function clearState ( ) { $ this -> rawLayout = null ; $ this -> context = null ; $ this -> dataAccessor = null ; $ this -> optionsResolver = null ; $ this -> typeHelper = null ; $ this -> blockBuilder = null ; $ this -> block = null ; }
Clears the state of this factory
9,182
protected function buildBlocks ( $ rootId ) { if ( ! $ this -> rawLayout -> hasProperty ( $ rootId , RawLayout :: RESOLVED_OPTIONS , true ) ) { $ this -> buildBlock ( $ rootId ) ; } $ iterator = $ this -> rawLayout -> getHierarchyIterator ( $ rootId ) ; foreach ( $ iterator as $ id ) { if ( ! $ this -> rawLayout -> has ( $ id ) || $ this -> rawLayout -> hasProperty ( $ id , RawLayout :: RESOLVED_OPTIONS , true ) ) { continue ; } if ( ! $ this -> isContainerBlock ( $ iterator -> getParent ( ) ) ) { $ blockType = $ this -> rawLayout -> getProperty ( $ iterator -> getParent ( ) , RawLayout :: BLOCK_TYPE , true ) ; throw new Exception \ LogicException ( sprintf ( 'The "%s" item cannot be added as a child to "%s" item (block type: %s) ' . 'because only container blocks can have children.' , $ id , $ iterator -> getParent ( ) , $ blockType instanceof BlockTypeInterface ? $ blockType -> getName ( ) : $ blockType ) ) ; } $ this -> buildBlock ( $ id ) ; } $ this -> layoutManipulator -> applyChanges ( $ this -> context ) ; if ( $ this -> layoutManipulator -> getNumberOfAddedItems ( ) !== 0 ) { $ this -> buildBlocks ( $ rootId ) ; } }
Builds all blocks starting with and including the given root block
9,183
protected function buildBlockViews ( $ rootId ) { $ views = [ ] ; $ rootView = $ this -> buildBlockView ( $ rootId ) ; $ views [ $ rootId ] = $ rootView ; $ iterator = $ this -> rawLayout -> getHierarchyIterator ( $ rootId ) ; foreach ( $ iterator as $ id ) { $ parentView = $ views [ $ iterator -> getParent ( ) ] ; $ view = $ this -> buildBlockView ( $ id , $ parentView ) ; $ parentView -> children [ $ id ] = $ view ; $ views [ $ id ] = $ view ; } $ viewsCollection = new BlockViewCollection ( $ views ) ; foreach ( $ views as $ view ) { $ view -> blocks = $ viewsCollection ; } $ this -> finishBlockView ( $ rootView , $ rootId ) ; foreach ( $ iterator as $ id ) { $ this -> finishBlockView ( $ views [ $ id ] , $ id ) ; } return $ rootView ; }
Builds views for all blocks starting with and including the given root block
9,184
protected function buildBlock ( $ id ) { $ blockType = $ this -> rawLayout -> getProperty ( $ id , RawLayout :: BLOCK_TYPE , true ) ; $ options = $ this -> rawLayout -> getProperty ( $ id , RawLayout :: OPTIONS , true ) ; $ types = $ this -> typeHelper -> getTypes ( $ blockType ) ; $ this -> setBlockResolvedOptions ( $ id , $ blockType , $ options , $ types ) ; }
Builds the block
9,185
protected function buildBlockView ( $ id , BlockView $ parentView = null ) { $ blockType = $ this -> rawLayout -> getProperty ( $ id , RawLayout :: BLOCK_TYPE , true ) ; $ resolvedOptions = $ this -> rawLayout -> getProperty ( $ id , RawLayout :: RESOLVED_OPTIONS , true ) ; $ types = $ this -> typeHelper -> getTypes ( $ blockType ) ; $ view = new BlockView ( $ parentView ) ; if ( is_null ( $ resolvedOptions ) ) { $ options = $ this -> rawLayout -> getProperty ( $ id , RawLayout :: OPTIONS , true ) ; $ resolvedOptions = $ this -> setBlockResolvedOptions ( $ id , $ blockType , $ options , $ types ) ; } $ this -> block -> initialize ( $ id ) ; foreach ( $ types as $ type ) { $ type -> buildView ( $ view , $ this -> block , $ resolvedOptions ) ; $ this -> registry -> buildView ( $ type -> getName ( ) , $ view , $ this -> block , $ resolvedOptions ) ; } array_walk_recursive ( $ view -> vars , function ( & $ var ) { if ( $ var instanceof Options ) { $ var = $ var -> toArray ( ) ; } } ) ; return $ view ; }
Created and builds the block view
9,186
protected function finishBlockView ( BlockView $ view , $ id ) { $ blockType = $ this -> rawLayout -> getProperty ( $ id , RawLayout :: BLOCK_TYPE , true ) ; $ types = $ this -> typeHelper -> getTypes ( $ blockType ) ; $ this -> block -> initialize ( $ id ) ; foreach ( $ types as $ type ) { $ type -> finishView ( $ view , $ this -> block ) ; $ this -> registry -> finishView ( $ type -> getName ( ) , $ view , $ this -> block ) ; } }
Finishes the building of the block view
9,187
protected function isContainerBlock ( $ id ) { return $ this -> typeHelper -> isInstanceOf ( $ this -> rawLayout -> getProperty ( $ id , RawLayout :: BLOCK_TYPE , true ) , ContainerType :: NAME ) ; }
Checks whether the given block is a container for other blocks
9,188
protected function processExpressions ( Options $ options ) { if ( ! $ this -> context -> getOr ( 'expressions_evaluate' ) ) { return ; } $ values = $ options -> toArray ( ) ; if ( $ this -> context -> getOr ( 'expressions_evaluate_deferred' ) ) { $ this -> expressionProcessor -> processExpressions ( $ values , $ this -> context , null , true , null ) ; } else { $ this -> expressionProcessor -> processExpressions ( $ values , $ this -> context , $ this -> dataAccessor , true , $ this -> context -> getOr ( 'expressions_encoding' ) ) ; } $ options -> setMultiple ( $ values ) ; }
Processes expressions that don t work with data
9,189
protected function setBlockResolvedOptions ( $ id , $ blockType , $ options , $ types ) { $ resolvedOptions = new Options ( $ this -> optionsResolver -> resolveOptions ( $ blockType , $ options ) ) ; $ this -> processExpressions ( $ resolvedOptions ) ; $ resolvedOptions = $ this -> resolveValueBags ( $ resolvedOptions ) ; if ( $ resolvedOptions -> get ( 'visible' , false ) !== false ) { $ this -> blockBuilder -> initialize ( $ id ) ; foreach ( $ types as $ type ) { $ type -> buildBlock ( $ this -> blockBuilder , $ resolvedOptions ) ; $ this -> registry -> buildBlock ( $ type -> getName ( ) , $ this -> blockBuilder , $ resolvedOptions ) ; } $ this -> rawLayout -> setProperty ( $ id , RawLayout :: RESOLVED_OPTIONS , $ resolvedOptions ) ; } else { $ this -> rawLayout -> remove ( $ id ) ; } return $ resolvedOptions ; }
Setting resolved options for block
9,190
public function log ( $ level , $ message , array $ context = [ ] ) { $ category = ArrayHelper :: remove ( $ context , 'category' , $ this -> category ) ; $ level = ArrayHelper :: getValue ( $ this -> map , $ level , $ this -> level ) ; $ this -> logger -> log ( $ this -> interpolate ( $ message , $ context ) , $ level , $ category ) ; }
Log a message transforming from PSR3 to the closest Yii2 .
9,191
protected function generateSchemaAsSql ( ) { $ prefix = ezcDbSchema :: $ options -> tableNamePrefix ; foreach ( $ this -> schema as $ tableName => $ tableDefinition ) { $ this -> generateDropTableSql ( $ prefix . $ tableName ) ; $ this -> generateCreateTableSql ( $ prefix . $ tableName , $ tableDefinition ) ; } }
Creates SQL DDL statements from a schema definitin .
9,192
public function getValidators ( ) { $ allValidatorData = $ this -> validators -> toArray ( PriorityQueue :: EXTR_DATA ) ; foreach ( $ allValidatorData as $ key => $ validatorData ) { $ allValidatorData [ $ key ] = $ validatorData [ 'instance' ] ; } return $ allValidatorData ; }
Returns array of all validators .
9,193
protected function encodeArray ( array $ action_result , ResponseInterface $ response , $ status = 200 ) { return $ response -> write ( json_encode ( $ action_result ) ) -> withStatus ( $ status ) ; }
Encode regular array response with status 200 .
9,194
protected function encodeScalar ( $ action_result , ResponseInterface $ response , $ status = 200 ) { return $ response -> write ( json_encode ( $ action_result ) ) -> withStatus ( $ status ) ; }
Encode scalar value with status 200 .
9,195
protected function encodeStatus ( StatusResponse $ action_result , ResponseInterface $ response ) { $ response = $ response -> withStatus ( $ action_result -> getHttpCode ( ) , $ action_result -> getMessage ( ) ) ; if ( $ action_result -> getHttpCode ( ) >= 400 ) { $ response = $ response -> write ( json_encode ( [ 'message' => $ action_result -> getMessage ( ) ] ) ) ; } return $ response ; }
Encode and return status response .
9,196
protected function encodeException ( $ exception , ResponseInterface $ response , $ status = 500 ) { $ error = [ 'message' => $ exception -> getMessage ( ) , 'type' => get_class ( $ exception ) ] ; if ( $ this -> getDisplayErrorDetails ( ) ) { $ error [ 'exception' ] = [ ] ; do { $ error [ 'exception' ] [ ] = [ 'type' => get_class ( $ exception ) , 'code' => $ exception -> getCode ( ) , 'message' => $ exception -> getMessage ( ) , 'file' => $ exception -> getFile ( ) , 'line' => $ exception -> getLine ( ) , 'trace' => explode ( "\n" , $ exception -> getTraceAsString ( ) ) , ] ; } while ( $ exception = $ exception -> getPrevious ( ) ) ; } return $ response -> write ( json_encode ( $ error ) ) -> withStatus ( $ status ) ; }
Encode and return exception .
9,197
public function renderException ( $ e , $ output ) { if ( $ output -> getVerbosity ( ) > OutputInterface :: VERBOSITY_VERBOSE ) { parent :: renderException ( $ e , $ output ) ; } else { $ ancestry = array ( ) ; $ maxLength = 0 ; do { $ ancestry [ ] = $ e ; $ maxLength = max ( $ maxLength , strlen ( get_class ( $ e ) ) ) ; $ last = $ e ; } while ( $ e = $ e -> getPrevious ( ) ) ; if ( $ last instanceof VerboseException ) { $ last -> output ( $ output ) ; } else { $ depth = 0 ; foreach ( $ ancestry as $ e ) { $ output -> writeln ( sprintf ( '%s%-40s %s' , ( $ depth > 0 ? str_repeat ( ' ' , $ depth - 1 ) . '-> ' : '' ) , '<fg=red;options=bold>' . $ e -> getMessage ( ) . '</fg=red;options=bold>' , $ depth == count ( $ ancestry ) - 1 ? str_pad ( '[' . get_class ( $ e ) . ']' , $ maxLength + 15 , ' ' ) : '' ) ) ; $ depth ++ ; } } } $ output -> writeln ( '[' . join ( '::' , Debug :: $ scope ) . ']' ) ; }
Custom exception rendering renders only the exception types and messages hierarchically but with regular formatting if verbosity is higher .
9,198
public function getContainer ( $ forceRecompile = false ) { if ( null === $ this -> container ) { $ config = $ this -> loader -> processConfiguration ( ) ; $ config [ 'z' ] [ 'sources' ] = $ this -> loader -> getSourceFiles ( ) ; $ config [ 'z' ] [ 'cache_file' ] = sys_get_temp_dir ( ) . '/z_' . $ this -> getCacheKey ( $ config ) . '.php' ; if ( $ forceRecompile && is_file ( $ config [ 'z' ] [ 'cache_file' ] ) ) { unlink ( $ config [ 'z' ] [ 'cache_file' ] ) ; clearstatcache ( ) ; } $ compiler = new ContainerCompiler ( $ config , $ this -> loader -> getPlugins ( ) , $ config [ 'z' ] [ 'cache_file' ] ) ; $ this -> container = $ compiler -> getContainer ( ) ; } return $ this -> container ; }
Returns the container instance and initializes it if not yet available .
9,199
public function newAction ( Request $ request ) { $ series = $ this -> get ( 'oktolab_media' ) -> createSeries ( ) ; $ form = $ this -> createForm ( SeriesType :: class , $ series ) ; $ form -> add ( 'submit' , SubmitType :: class , [ 'label' => 'oktolab_media.new_series_button' , 'attr' => [ 'class' => 'btn btn-primary' ] ] ) ; if ( $ request -> getMethod ( ) == "POST" ) { $ form -> handleRequest ( $ request ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; if ( $ form -> isValid ( ) ) { if ( $ form -> get ( 'submit' ) -> isClicked ( ) ) { $ em -> persist ( $ series ) ; $ em -> flush ( ) ; $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'oktolab_media.success_create_series' ) ; return $ this -> redirect ( $ this -> generateUrl ( 'oktolab_series_show' , [ 'series' => $ series -> getUniqId ( ) ] ) ) ; } else { $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'success' , 'oktolab_media.unknown_action_series' ) ; return $ this -> redirect ( $ this -> generateUrl ( 'oktolab_series' ) ) ; } } $ this -> get ( 'session' ) -> getFlashBag ( ) -> add ( 'error' , 'oktolab_media.error_create_series' ) ; } return [ 'form' => $ form -> createView ( ) ] ; }
Displays a form to create a new Series entity .