idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
19,300 | protected function prepareForeignConstraint ( DOMElement $ table , DOMXPath $ xpath , Table $ schemaTable ) { $ foreignKeys = $ xpath -> query ( sprintf ( '/database/table[@name="%s"]/foreign' , $ table -> getAttribute ( 'name' ) ) ) ; foreach ( $ foreignKeys as $ foreignKey ) { $ foreignTable = $ foreignKey -> getAttribute ( 'foreignTable' ) ; $ references = $ foreignKey -> getElementsByTagName ( 'reference' ) ; foreach ( $ references as $ reference ) { $ localColumn = $ reference -> getAttribute ( 'local' ) ; $ foreignColumn = $ reference -> getAttribute ( 'foreign' ) ; $ constraintName = sprintf ( '%s_%s_%s_%s_foreign' , $ table -> getAttribute ( 'name' ) , $ foreignTable , $ localColumn , $ foreignColumn ) ; $ schemaTable -> addConstraint ( $ constraintName , [ 'type' => 'foreign' , 'columns' => [ $ localColumn ] , 'references' => [ $ foreignTable , $ foreignColumn ] , 'update' => $ foreignKey -> getAttribute ( 'onUpdate' ) , 'delete' => $ foreignKey -> getAttribute ( 'onDelete' ) ] ) ; } } } | Prepare foreign key constraint |
19,301 | protected function prepareUniqueConstraint ( DOMElement $ table , DOMXPath $ xpath , Table $ schemaTable ) { $ uniqueTags = $ xpath -> query ( sprintf ( '/database/table[@name="%s"]/unique' , $ table -> getAttribute ( 'name' ) ) ) ; foreach ( $ uniqueTags as $ uniqueTag ) { $ uniqueColumns = $ uniqueTag -> getElementsByTagName ( 'unique-column' ) ; $ constraintName = $ uniqueTag -> getAttribute ( 'name' ) ; $ tmpUniqueColumn = [ ] ; foreach ( $ uniqueColumns as $ uniqueColumn ) { $ tmpUniqueColumn [ ] = $ uniqueColumn -> getAttribute ( 'name' ) ; } if ( empty ( trim ( $ constraintName ) ) ) { $ constraintName = sprintf ( '%s_%s_%s' , $ table -> getAttribute ( 'name' ) , implode ( '_' , $ tmpUniqueColumn ) , 'unique' ) ; } $ schemaTable -> addConstraint ( $ constraintName , [ 'type' => 'unique' , 'columns' => $ tmpUniqueColumn ] ) ; } } | Prepare unique constraint |
19,302 | protected function preparePrimaryConstraint ( DOMElement $ table , DOMXPath $ xpath , Table $ schemaTable ) { $ primaryTags = $ xpath -> query ( sprintf ( '/database/table[@name="%s"]/primary' , $ table -> getAttribute ( 'name' ) ) ) ; foreach ( $ primaryTags as $ primaryTag ) { $ primaryColumns = $ primaryTag -> getElementsByTagName ( 'primary-column' ) ; $ constraintName = $ primaryTag -> getAttribute ( 'name' ) ; $ tmpPrimaryColumn = [ ] ; foreach ( $ primaryColumns as $ primaryColumn ) { $ tmpPrimaryColumn [ ] = $ primaryColumn -> getAttribute ( 'name' ) ; } if ( empty ( trim ( $ constraintName ) ) ) { $ constraintName = sprintf ( '%s_%s_%s' , $ table -> getAttribute ( 'name' ) , implode ( '_' , $ tmpPrimaryColumn ) , 'primary' ) ; } $ schemaTable -> addConstraint ( $ constraintName , [ 'type' => 'primary' , 'columns' => $ tmpPrimaryColumn ] ) ; } } | Prepare primary constraint |
19,303 | protected function getBootstrapSassJavascripts ( ) { $ process = new Process ( "gem which bootstrap-sass" ) ; $ process -> run ( ) ; if ( ! $ process -> isSuccessful ( ) ) { throw new WatcherCompileException ( "`bootstrap-sass` gem was not found\n\n" . $ process -> getOutput ( ) ) ; } $ gemPath = trim ( $ process -> getOutput ( ) ) ; $ bjsRootPath = dirname ( dirname ( $ gemPath ) ) . "/assets/javascripts" ; $ bjsPath = $ bjsRootPath . "/bootstrap-sprockets.js" ; $ bjs = file_get_contents ( $ bjsPath ) ; $ inputs = array ( ) ; $ matches = array ( ) ; if ( preg_match_all ( "/\/\/= require (.*)/i" , $ bjs , $ matches ) ) { foreach ( $ matches [ 1 ] as $ asset ) { $ inputs [ ] = $ bjsRootPath . "/" . $ asset . ".js" ; } } else { $ inputs [ ] = $ bjsPath ; } return $ inputs ; } | Get a list of js files |
19,304 | public static function addListener ( string $ event , $ function , int $ priority = 10 , array $ args = null ) : void { Event :: $ listeners [ $ event ] [ $ priority ] [ ] = [ 'function' => $ function , 'args' => $ args ] ; } | Add new listener |
19,305 | public static function removeAllListeners ( string $ event ) : void { if ( Event :: hasListeners ( $ event ) ) { unset ( Event :: $ listeners [ $ event ] ) ; } } | Remove all listeners for current event . |
19,306 | public static function hasListeners ( string $ event ) : bool { if ( ! isset ( Event :: $ listeners [ $ event ] ) || count ( Event :: $ listeners [ $ event ] ) === 0 ) { return false ; } return true ; } | Check is listeners exists for current event . |
19,307 | public static function dispatch ( string $ event , array $ args = [ ] , bool $ return = false ) { if ( isset ( Event :: $ listeners [ $ event ] ) && count ( Event :: $ listeners [ $ event ] ) > 0 ) { $ listeners = Event :: $ listeners [ $ event ] ; krsort ( $ listeners ) ; foreach ( $ listeners as $ listener ) { foreach ( $ listener as $ _listener ) { if ( $ return ) { return call_user_func_array ( $ _listener [ 'function' ] , ( isset ( $ args ) ? $ args : $ _listener [ 'args' ] ) ) ; } else { call_user_func_array ( $ _listener [ 'function' ] , ( isset ( $ args ) ? $ args : $ _listener [ 'args' ] ) ) ; } } } } } | Dispatch all listeners of the given event . |
19,308 | public function setErrorHandle ( $ err , $ message , $ file , $ line ) { $ oJsonRpc = JsonRpc :: getInstance ( ) ; $ content = explode ( "\n" , file_get_contents ( $ file ) ) ; header ( 'Content-Type: application/json' ) ; $ id = $ oJsonRpc -> extractId ( ) ; $ error = array ( "code" => 100 , "message" => "Server error" , "error" => array ( "name" => "PHPErorr" , "code" => $ err , "message" => $ message , "file" => $ file , "at" => $ line , "line" => $ content [ $ line - 1 ] ) ) ; ob_end_clean ( ) ; echo $ oJsonRpc -> response ( null , $ id , $ error ) ; exit ( ) ; } | set error handler |
19,309 | public function response ( $ result , $ id , $ error ) { if ( $ error ) { $ error [ 'name' ] = 'JSONRPCError' ; } return json_encode ( array ( "jsonrpc" => "2.0" , 'result' => $ result , 'id' => $ id , 'error' => $ error ) ) ; } | make the response |
19,310 | public function extractId ( ) { $ regex = '/[\'"]id[\'"] *: *([0-9]*)/' ; $ rawData = $ this -> getRawPostData ( ) ; if ( preg_match ( $ regex , $ rawData , $ m ) ) { return intval ( $ m [ 1 ] ) ; } else { return null ; } } | try to extract id from broken json |
19,311 | private function currentURL ( ) { $ pageURL = 'http' ; if ( isset ( $ _SERVER [ "HTTPS" ] ) && $ _SERVER [ "HTTPS" ] == "on" ) { $ pageURL .= "s" ; } $ pageURL .= "://" ; if ( $ _SERVER [ "SERVER_PORT" ] != "80" ) { $ pageURL .= $ _SERVER [ "SERVER_NAME" ] . ":" . $ _SERVER [ "SERVER_PORT" ] . $ _SERVER [ "REQUEST_URI" ] ; } else { $ pageURL .= $ _SERVER [ "SERVER_NAME" ] . $ _SERVER [ "REQUEST_URI" ] ; } return $ pageURL ; } | get the current URL |
19,312 | private function serviceDescription ( $ object ) { $ class_name = get_class ( $ object ) ; $ methods = get_class_methods ( $ class_name ) ; $ service = [ "sdversion" => "1.0" , "name" => "DemoService" , "address" => $ this -> currentURL ( ) , "id" => "urn:md5:" . md5 ( $ this -> currentURL ( ) ) ] ; $ static = get_class_vars ( $ class_name ) ; foreach ( $ methods as $ method_name ) { $ proc = array ( "name" => $ method_name ) ; $ method = new \ ReflectionMethod ( $ class_name , $ method_name ) ; $ params = array ( ) ; foreach ( $ method -> getParameters ( ) as $ param ) { $ params [ ] = $ param -> name ; } $ proc [ 'params' ] = $ params ; $ help_str_name = $ method_name . "_documentation" ; if ( array_key_exists ( $ help_str_name , $ static ) ) { $ proc [ 'help' ] = $ static [ $ help_str_name ] ; } $ service [ 'procs' ] [ ] = $ proc ; } return $ service ; } | get service description of the class |
19,313 | private function getJsonRequest ( ) { $ request = $ this -> getRawPostData ( ) ; if ( $ request == "" ) { throw new JsonRpcExeption ( 101 , "Parse Error: no data" ) ; } $ encoding = mb_detect_encoding ( $ request , 'auto' ) ; if ( $ encoding != 'UTF-8' ) { $ request = iconv ( $ encoding , 'UTF-8' , $ request ) ; } $ request = json_decode ( $ request ) ; if ( $ request == NULL ) { $ error = $ this -> getJsonError ( ) ; throw new JsonRpcExeption ( 101 , "Parse Error: $error" ) ; } return $ request ; } | get the json request |
19,314 | protected function setFirewallsAndAccessRules ( Application $ app ) { $ app -> extend ( 'security.firewalls' , function ( $ firewalls , $ app ) { $ createUser = new RequestMatcher ( '^/users$' , null , [ 'POST' ] ) ; $ verifyRegistration = new RequestMatcher ( '^/users/[0-9]+/verify-registration$' , null , [ 'POST' ] ) ; $ userFirewalls = [ 'create-users' => [ 'pattern' => $ createUser , 'anonymous' => true , ] , 'verify-registration' => [ 'pattern' => $ verifyRegistration , 'anonymous' => true , ] , 'reset-password' => [ 'pattern' => '^/user/reset-password$' , 'anonymous' => true , ] , ] ; return array_merge ( $ userFirewalls , $ firewalls ) ; } ) ; $ app -> extend ( 'security.access_rules' , function ( $ rules , $ app ) { $ usersAdminFunctionRequestMatcher = new RequestMatcher ( '^/users/\d+$' , null , [ 'GET' ] ) ; $ newRules = [ [ $ usersAdminFunctionRequestMatcher , 'ROLE_ADMIN' ] ] ; return array_merge ( $ newRules , $ rules ) ; } ) ; } | Set user related firewalls |
19,315 | protected function driverAction ( $ action , $ item ) { if ( is_null ( $ item ) ) { return $ this -> getDriver ( ) -> { $ action } ( ) ; } else { return $ this -> getDriver ( ) -> { $ action } ( $ item ) ; } } | Execute an action with the driver |
19,316 | public function merge ( $ data ) { if ( ! is_array ( $ data ) ) { $ data = $ this -> makeArray ( $ data ) ; } $ this -> _data = array_merge ( $ this -> _data , $ data ) ; } | Merges the given items into the collection . |
19,317 | public function replace ( $ data ) { if ( ! is_array ( $ data ) ) { $ data = $ this -> makeArray ( $ data ) ; } $ this -> _data = array_replace ( $ this -> _data , $ data ) ; } | Replaces items in the collection with those given . |
19,318 | public function intersect ( $ data ) { if ( ! is_array ( $ data ) ) { $ data = $ this -> makeArray ( $ data ) ; } return new static ( array_intersect_assoc ( $ this -> _data , $ data ) ) ; } | Computes the intersection with the given array and returns a new collection . |
19,319 | public function keyFilter ( $ func ) { $ filtered = array_filter ( $ this -> keys ( ) , $ func ) ; return new static ( array_intersect_key ( $ this -> _data , array_flip ( $ filtered ) ) ) ; } | Filters the items by key and returns a new collection . |
19,320 | public function addJob ( $ job = [ ] ) { if ( ! isset ( $ job [ 'msg' ] ) ) throw new RuntimeException ( 'Job without a message' ) ; if ( ! isset ( $ job [ 'schedule' ] ) ) throw new RuntimeException ( 'Job without a CRON expression' ) ; if ( ! isset ( $ job [ 'function' ] ) ) throw new RuntimeException ( 'Job without a function' ) ; if ( $ this -> isDue ( $ job [ 'schedule' ] ) ) $ this -> jobs [ ] = $ job ; } | Load the cron jobs that should be runned and register them into the jobs array . |
19,321 | public function getJob ( $ msg ) { $ found = false ; foreach ( $ this -> jobs as $ job ) { if ( $ job [ 'msg' ] === $ msg ) { $ found = $ job ; break ; } } return $ found ; } | Get a particular job by msg |
19,322 | public function output ( $ args = null ) { $ i = 0 ; foreach ( $ this -> jobs as $ job ) if ( $ job [ 'function' ] ( $ job [ 'msg' ] ) === TRUE ) $ i ++ ; $ this -> jobs = [ ] ; return $ i ; } | Load the cron jobs to run and execute them . |
19,323 | public function removeListener ( string $ event , callable $ listener ) { if ( $ this -> _events [ $ event ] ?? false ) { $ key = array_search ( $ listener , $ this -> _events [ $ event ] , true ) ; if ( $ key !== false ) { array_splice ( $ this -> _events [ $ event ] , $ key , 1 ) ; } } return $ this ; } | Remove specific listener of an event . |
19,324 | public function setResponseCode ( $ code ) { if ( ! ResponseCode :: isValid ( $ code ) ) { throw new \ InvalidArgumentException ( 'setResponseCode(): Invalid HTTP response code given of value ' . strval ( $ code ) ) ; } $ this -> statusCode = $ code ; return $ this ; } | Sets the HTTP response code . |
19,325 | public function doRedirect ( $ url , $ permanent = false ) { $ this -> setResponseCode ( $ permanent ? ResponseCode :: HTTP_MOVED_PERMANENTLY : ResponseCode :: HTTP_FOUND ) ; $ this -> setHeader ( 'Location' , $ url ) ; return $ this ; } | Redirect the user to a specific URL . Performs a HTTP 301 or HTTP 302 redirect . |
19,326 | public function setHeader ( $ key , $ value ) { $ this -> headers [ strval ( $ key ) ] = strval ( $ value ) ; return $ this ; } | Sets a HTTP header to a certain value . |
19,327 | public function setCookie ( $ name , $ value , $ expire = 0 , $ path = null , $ domain = null , $ secure = false , $ httpOnly = false ) { return $ this -> addCookie ( ( new Cookie ( ) ) -> setName ( $ name ) -> setValue ( $ value ) -> setExpireTimestamp ( $ expire ) -> setPath ( $ path ) -> setDomain ( $ domain ) -> setSecure ( $ secure ) -> setHttpOnly ( $ httpOnly ) ) ; } | Creates or updates a cookie . |
19,328 | protected function sendCookies ( ) { foreach ( $ this -> cookies as $ cookie ) { setcookie ( $ cookie -> getName ( ) , $ cookie -> getValue ( ) , $ cookie -> getExpireTimestamp ( ) , $ cookie -> getPath ( ) , $ cookie -> getDomain ( ) , $ cookie -> isSecure ( ) , $ cookie -> isHttpOnly ( ) ) ; } } | Sends the HTTP cookies to the client . Causes output! |
19,329 | protected function sendHeaders ( ) { header ( sprintf ( '%s %s' , self :: PROTOCOL_VERSION , ResponseCode :: getMessageForCode ( $ this -> statusCode ) ) ) ; foreach ( $ this -> headers as $ name => $ value ) { header ( sprintf ( "%s: %s" , $ name , $ value ) ) ; } } | Sends the HTTP headers to the client . Causes output! |
19,330 | public function send ( ) { $ this -> sendHeaders ( ) ; $ this -> sendCookies ( ) ; if ( ResponseCode :: canHaveBody ( $ this -> statusCode ) ) { $ this -> sendBody ( ) ; } } | Sends the HTTP response to the client . Causes output! |
19,331 | private function applyIdentifier ( Siteroot $ siteroot ) { $ reflectionClass = new \ ReflectionClass ( get_class ( $ siteroot ) ) ; $ reflectionProperty = $ reflectionClass -> getProperty ( 'id' ) ; $ reflectionProperty -> setAccessible ( true ) ; $ reflectionProperty -> setValue ( $ siteroot , UuidUtil :: generate ( ) ) ; } | Apply UUID as identifier when entity doesn t have one yet . |
19,332 | public function filter ( $ request ) { foreach ( $ this -> _filters as $ filter ) { if ( ! $ request = $ filter -> filter ( $ request ) ) { throw new Exception ( "Filter returned a null request" ) ; } } return $ request ; } | Filter a request fail if a null result is returned |
19,333 | protected function getCorrespondingSaucelabsJob ( ) { $ jobs = $ this -> sauceApi ( ) -> getJobs ( $ from = 0 , $ to = null , $ limit = 1 , $ skip = null , $ username = null ) ; return $ jobs [ 'jobs' ] [ 0 ] ; } | We currently assume that the firstmost job is the current test for which we should update metadata . This is not always true but at the moment there seems to be little to be done in this matter . |
19,334 | protected function gatherMetaData ( $ test ) { $ metadata = array ( 'tags' => isset ( $ this -> config [ 'tags' ] ) ? explode ( "," , $ this -> config [ 'tags' ] ) : array ( ) , 'custom-data' => array ( ) , ) ; $ metadata [ 'tags' ] [ ] = "test:" . $ test -> toString ( ) ; $ metadata [ 'custom-data' ] [ 'options' ] = $ this -> options ; return $ metadata ; } | Gather metadata about the current test to send to saucelabs making it easier to filter tests |
19,335 | public function initConfig ( $ force = false ) { $ pluginName = $ this -> _getPluginName ( ) ; $ checkPath = $ this -> _getCheckPath ( ) ; $ configFile = $ this -> _getConfigFile ( ) ; $ language = ( string ) Configure :: read ( 'Config.language' ) ; if ( ! $ force && ! empty ( $ checkPath ) && Configure :: check ( $ checkPath ) ) { return ; } $ conf = $ this -> getConfig ( ) ; $ cachePath = 'static_cfg_' . Inflector :: underscore ( $ pluginName ) . '_' . $ language ; $ cached = Cache :: read ( $ cachePath , CAKE_CONFIG_PLUGIN_CACHE_CFG ) ; if ( $ cached !== false ) { $ conf = Hash :: mergeDiff ( $ conf , ( array ) $ cached ) ; Configure :: write ( $ pluginName , $ conf ) ; return ; } Configure :: config ( 'phpcfg' , new PhpReader ( $ this -> path ) ) ; Configure :: load ( $ pluginName . '.' . $ configFile , 'phpcfg' , false ) ; $ defaultConf = $ this -> getConfig ( ) ; if ( file_exists ( $ this -> path . $ configFile . '.php' ) ) { Configure :: load ( $ configFile , 'phpcfg' , false ) ; $ localConf = $ this -> getConfig ( ) ; $ conf = Hash :: mergeDiff ( $ conf , $ localConf ) ; } Configure :: drop ( 'phpcfg' ) ; $ conf = Hash :: mergeDiff ( $ conf , $ defaultConf ) ; Cache :: write ( $ cachePath , $ conf , CAKE_CONFIG_PLUGIN_CACHE_CFG ) ; Configure :: write ( $ pluginName , $ conf ) ; } | Initializes configuration for plugin . |
19,336 | public static function fromInt ( $ int ) { if ( ! \ is_int ( $ int ) ) { throw new \ InvalidArgumentException ( '$int must be an integer' ) ; } $ flags = new static ( ) ; foreach ( static :: getEnumValues ( ) as $ const ) { if ( ( $ int & $ const ) === $ const ) { $ flags -> addFlag ( $ const ) ; } } return $ flags ; } | Converts an integer value to an enum of this type |
19,337 | public function getNames ( ) { $ isSet = PHPArray :: filter ( static :: getConstants ( ) , function ( $ value ) { return $ this -> hasFlag ( $ value ) ; } ) ; return \ array_keys ( $ isSet ) ; } | Returns an array of this class constant names which are defined in this instance |
19,338 | protected function _filterAsset ( CakeEvent $ event ) { $ url = $ event -> data [ 'request' ] -> url ; $ response = $ event -> data [ 'response' ] ; $ filters = Configure :: read ( 'Asset.filter' ) ; $ isCss = ( strpos ( $ url , 'ccss/' ) === 0 || preg_match ( '#^(theme/([^/]+)/ccss/)|(([^/]+)(?<!css)/ccss)/#i' , $ url ) ) ; $ isJs = ( strpos ( $ url , 'cjs/' ) === 0 || preg_match ( '#^/((theme/[^/]+)/cjs/)|(([^/]+)(?<!js)/cjs)/#i' , $ url ) ) ; if ( ( $ isCss && empty ( $ filters [ 'css' ] ) ) || ( $ isJs && empty ( $ filters [ 'js' ] ) ) ) { $ response -> statusCode ( 404 ) ; return $ response ; } if ( $ isCss ) { include WWW_ROOT . DS . $ filters [ 'css' ] ; return $ response ; } if ( $ isJs ) { include WWW_ROOT . DS . $ filters [ 'js' ] ; return $ response ; } } | Checks if the client is requesting a filtered asset and runs the corresponding filter if any is configured |
19,339 | public function setRoutes ( ) : void { if ( is_null ( $ this -> routes ) ) { $ this -> routes = [ ] ; $ routesConfig = $ this -> config -> getParam ( 'routes' ) ?? [ ] ; foreach ( $ routesConfig as $ routeName => $ routeArr ) { $ route = new Route ( $ routeName , $ routeArr [ 'methods' ] , $ routeArr [ 'path' ] , $ routeArr [ 'params_defaults' ] , $ routeArr [ 'params_requirements' ] , $ routeArr [ 'handler' ] , $ routeArr [ 'handler_method' ] ?? null ) ; $ this -> routes [ ] = $ route ; } } } | Sets \ Duktig \ Core \ Route \ Route objects from config values |
19,340 | protected function get ( ) { $ url = '' ; if ( $ this -> scheme ) { $ url = $ this -> scheme . ':' ; } if ( $ this -> host ) { $ url .= '//' . $ this -> authority ( ) ; } if ( $ this -> path ) { $ url .= '/' . ltrim ( $ this -> path , '/' ) ; } if ( $ this -> query ) { $ url .= '?' . $ this -> query ; } if ( $ this -> fragment ) { $ url .= '#' . $ this -> fragment ; } return $ url ; } | Get URL as string |
19,341 | protected function set ( $ url ) { $ parts = parse_url ( $ url ) ; if ( ! $ parts ) { throw new \ InvalidArgumentException ( 'URL malformed' ) ; } $ this -> scheme = isset ( $ parts [ 'scheme' ] ) ? strtolower ( $ parts [ 'scheme' ] ) : '' ; $ this -> username = $ parts [ 'user' ] ?? '' ; $ this -> password = $ parts [ 'pass' ] ?? '' ; $ this -> host = isset ( $ parts [ 'host' ] ) ? strtolower ( $ parts [ 'host' ] ) : '' ; $ this -> port = isset ( $ parts [ 'port' ] ) ? intval ( $ parts [ 'port' ] ) : null ; $ this -> path = $ parts [ 'path' ] ?? '' ; $ this -> query = $ parts [ 'query' ] ?? '' ; $ this -> fragment = $ parts [ 'fragment' ] ?? '' ; } | Set URL as string |
19,342 | public function authority ( ) { $ userInfo = $ this -> username ; if ( $ this -> password ) { $ userInfo .= ':' . $ this -> password ; } $ port = $ this -> port ( ) ; $ authority = $ this -> host ; if ( $ authority && $ userInfo ) { $ authority = $ userInfo . '@' . $ authority ; } if ( $ authority && $ port ) { $ authority .= ':' . $ port ; } return $ authority ; } | Get authority component of the URL |
19,343 | public static function capture ( array $ server = null ) { if ( ! $ server ) { $ server = $ _SERVER ; } $ source = 'http:' ; if ( isset ( $ server [ 'HTTPS' ] ) && $ server [ 'HTTPS' ] && $ server [ 'HTTPS' ] != 'off' ) { $ source = 'https:' ; } if ( isset ( $ server [ 'HTTP_HOST' ] ) ) { $ source .= '//' . $ server [ 'HTTP_HOST' ] ; } if ( isset ( $ server [ 'REQUEST_URI' ] ) ) { $ source .= $ server [ 'REQUEST_URI' ] ; } $ url = new static ( $ source ) ; $ url -> username = $ server [ 'PHP_AUTH_USER' ] ?? null ; $ url -> password = $ server [ 'PHP_AUTH_PW' ] ?? null ; return $ url ; } | Capture the URL from the SERVER super global |
19,344 | public function create_taxonomy ( $ options ) { if ( ! $ options instanceof WP_Taxonomy_Options ) { trigger_error ( 'Options must be passed as a WP_Taxonomy_Options.' ) ; return ; } if ( ! $ options -> has_required_properties ( ) ) { trigger_error ( 'WP_Taxonomy_Options are missing required properties.' ) ; return ; } $ labels = array ( 'add_new_item' => __ ( 'Add New ' . $ options -> get_singular_name ( ) ) , 'all_items' => __ ( 'All ' . $ options -> get_plural_name ( ) ) , 'edit_item' => __ ( 'Edit ' . $ options -> get_singular_name ( ) ) , 'menu_name' => __ ( $ options -> get_plural_name ( ) ) , 'name' => __ ( $ options -> get_plural_name ( ) ) , 'new_item_name' => __ ( 'New ' . $ options -> get_singular_name ( ) . ' Name' ) , 'parent_item' => __ ( 'Parent ' . $ options -> get_singular_name ( ) ) , 'parent_item_colon' => __ ( 'Parent ' . $ options -> get_singular_name ( ) . ':' ) , 'search_items' => __ ( 'Search ' . $ options -> get_plural_name ( ) ) , 'singular_name' => __ ( $ options -> get_singular_name ( ) ) , 'update_item' => __ ( 'Update ' . $ options -> get_singular_name ( ) ) , ) ; $ args = array ( 'hierarchical' => $ options -> get_hierarchical ( ) , 'labels' => $ labels , 'query_var' => true , 'rewrite' => array ( 'slug' => $ options -> get_slug ( ) ) , 'show_admin_column' => true , 'show_ui' => true , ) ; register_taxonomy ( $ options -> get_slug ( ) , array ( $ options -> get_post_type ( ) ) , $ args ) ; } | Creates a custom taxonomy . |
19,345 | public function getTitle ( ) { $ title = '' ; if ( trim ( $ this -> title ) != '' ) { $ title = trim ( $ this -> title ) ; } if ( trim ( $ this -> name ) != '' ) { if ( trim ( $ title ) != '' ) { $ title .= $ this -> delimiter ; } $ title .= trim ( $ this -> name ) ; } if ( trim ( $ title ) == '' ) { $ title = 'zepi Turbo' ; } return $ title ; } | Returns the title for the request |
19,346 | protected function addConfigListeners ( $ id , $ event ) { if ( isset ( $ this -> configuredEvents [ $ id ] [ $ event ] ) || ! $ this -> canAddConfig || ! $ this -> config ) { return $ this ; } $ this -> canAddConfig = false ; $ this -> config -> configureEventManager ( $ this , $ id , $ event ) ; $ this -> configuredEvents [ $ id ] [ $ event ] = true ; if ( ! isset ( $ this -> configuredEvents [ $ id ] [ '*' ] ) ) { $ this -> config -> configureEventManager ( $ this , $ id , '*' ) ; $ this -> configuredEvents [ $ id ] [ '*' ] = true ; } $ this -> canAddConfig = true ; return $ this ; } | Add config events |
19,347 | public function close ( Line $ closerLine ) : string { if ( isset ( $ this -> config [ 'close_by' ] ) && $ closerLine -> indentLevel == $ this -> line -> indentLevel ) { foreach ( $ this -> config [ 'close_by' ] as $ key => $ value ) { if ( $ closerLine -> pregMatch ( $ key ) ) { return $ this -> withParam ( $ value ) ; } } } if ( isset ( $ this -> config [ 'closer' ] ) ) { return $ this -> withParam ( $ this -> config [ 'closer' ] ) ; } return '' ; } | Close this control node and returning node closer . |
19,348 | private function withParam ( string $ input ) { return str_replace ( '$_FLAG_$' , "__HTSL_CTRL_FLAG_{$this->id}__" , preg_replace_callback ( '/(?<!%)%s((?:\\/.+?(?<!\\\\)\\/.+?(?<!\\\\)\\/)+)?/' , function ( array $ matches ) { $ param = $ this -> param ; if ( isset ( $ matches [ 1 ] ) ) { array_map ( ... [ function ( $ replacer ) use ( & $ param ) { list ( $ pattern , $ replacement , ) = preg_split ( '/(?<!\\\\)\\//' , $ replacer ) ; $ param = preg_replace ( ... [ "/$pattern/" , preg_replace ( '/^\\\\_$/' , '' , $ replacement ) , $ param , ] ) ; } , preg_split ( '/(?<!\\\\)\\/\\//' , trim ( $ matches [ 1 ] , '/' ) ) , ] ) ; } return $ param ; } , $ input ) ) ; } | Parse opener or closer with parameters . |
19,349 | protected function dispatchCommandFrom ( $ command , ArrayAccess $ source , array $ extras = [ ] ) { return app ( 'tactician.dispatcher' ) -> dispatchFrom ( $ command , $ source , $ extras ) ; } | Marshal a command and dispatch it to its respective handler . |
19,350 | public function remove ( $ key ) { if ( array_key_exists ( $ key , $ this -> map ) ) { $ tmp = $ this -> map [ $ key ] ; unset ( $ this -> map [ $ key ] ) ; return $ tmp ; } else return NULL ; } | Remove a name and its value if present . |
19,351 | public static function stringToValue ( $ string ) { if ( $ string == '' ) { return $ string ; } if ( is_float ( $ string ) ) { return ( float ) $ string ; } if ( is_int ( $ string ) ) { return ( int ) $ string ; } if ( strtolower ( $ string ) == 'true' ) { return true ; } if ( strtolower ( $ string ) == 'false' ) { return false ; } if ( strtolower ( $ string ) == 'null' ) { return NULL ; } return $ string ; } | Try to convert a string into a number boolean or null . If the string can t be converted return the string . |
19,352 | private static function isAssoc ( $ value ) { if ( ! is_array ( $ value ) ) return false ; return array_keys ( $ value ) !== range ( 0 , count ( $ value ) - 1 ) ; } | Determines if an value is an associative array |
19,353 | public static function numberToString ( $ number = NULL ) { if ( $ number === NULL ) { throw new JSONException ( 'Null pointer' ) ; } self :: testValidity ( $ number ) ; $ number = ( string ) $ number ; if ( strpos ( $ number , '.' ) > 0 && strpos ( $ number , 'e' ) < 0 && strpos ( $ number , 'E' ) < 0 ) { while ( substr ( $ number , - 1 ) == '0' ) { $ number = substr ( 0 , strlen ( $ number ) - 1 ) ; } if ( substr ( $ number , - 1 ) == '.' ) { $ number = substr ( 0 , strlen ( $ number ) - 1 ) ; } } return $ number ; } | Produce a string from a number . |
19,354 | public function toJSONArray ( $ names = NULL ) { if ( $ names == NULL || count ( $ names ) == 0 ) { return NULL ; } $ ja = new JSONArray ( ) ; foreach ( $ this -> map as $ key => $ value ) { $ ja -> put ( $ this -> opt ( $ key ) ) ; } return $ ja ; } | Produce a JSONArray containing the values of the members of this JSONObject . |
19,355 | public function write ( ) { $ returnstring = '{' ; foreach ( $ this -> map as $ key => $ value ) { $ returnstring .= '"' . $ key . '":' ; if ( $ value instanceof JSONObject || $ value instanceof JSONArray ) $ returnstring .= $ value -> write ( ) ; elseif ( gettype ( $ value ) == 'integer' || gettype ( $ value ) == 'double' ) $ returnstring .= $ value ; elseif ( gettype ( $ value ) == 'boolean' ) $ returnstring .= ( ( $ value ) ? 'true' : 'false' ) ; elseif ( gettype ( $ value ) == 'NULL' ) $ returnstring .= 'null' ; elseif ( gettype ( $ value ) == 'string' ) $ returnstring .= '"' . $ value . '"' ; else throw new JSONException ( 'Invalid type ' . gettype ( $ value ) ) ; if ( $ value !== end ( $ this -> map ) ) $ returnstring .= ',' ; } $ returnstring .= '}' ; return $ returnstring ; } | Returns the contents of the JSONObject as a JSONString . For compactness no whitespace is added . |
19,356 | public function render ( ) { $ this -> latte -> setLoader ( $ this -> file ? new FileLoader ( ) : new StringLoader ( ) ) ; $ this -> latte -> render ( $ this -> file ? : $ this -> source , $ this -> params ) ; } | Renders template to output . |
19,357 | public static function fromXml ( \ DOMDocument $ xml ) { $ static = new static ( ) ; $ loans = $ xml -> getElementsByTagName ( 'loan' ) ; $ static -> loans = LoanCollection :: fromXml ( $ loans ) ; $ loanHistory = $ xml -> getElementsByTagName ( 'loanHistory' ) ; $ static -> loanHistory = LoanCollection :: fromXml ( $ loanHistory ) ; $ holds = $ xml -> getElementsByTagName ( 'hold' ) ; $ static -> holds = HoldCollection :: fromXml ( $ holds ) ; $ expenses = $ xml -> getElementsByTagName ( 'fine' ) ; $ static -> expenses = ExpenseCollection :: fromXml ( $ expenses ) ; $ totalFine = $ xml -> getElementsByTagName ( 'totalFine' ) ; $ static -> totalFine = FloatLiteral :: fromXml ( $ totalFine ) ; $ totalCost = $ xml -> getElementsByTagName ( 'totalCost' ) ; $ static -> totalCost = FloatLiteral :: fromXml ( $ totalCost ) ; $ message = $ xml -> getElementsByTagName ( 'message' ) ; $ static -> message = StringLiteral :: fromXml ( $ message ) ; $ loanHistoryConfig = $ xml -> getElementsByTagName ( 'loanHistoryConfigurable' ) ; $ static -> loanHistoryConfigurable = BoolLiteral :: fromXml ( $ loanHistoryConfig ) ; return $ static ; } | Builds a UserActivities object from XML . |
19,358 | function givePdo ( \ PDO $ conn ) { if ( $ this -> pdo ) throw new exImmutable ; $ this -> pdo = $ conn ; return $ this ; } | Set PDO Instance |
19,359 | public static function createFromGlobals ( array $ globals ) { $ env = new \ Sofi \ Base \ Collection ( $ globals ) ; if ( is_array ( $ env [ 'slim.files' ] ) && $ env -> has ( 'slim.files' ) ) { return $ env [ 'slim.files' ] ; } elseif ( isset ( $ _FILES ) ) { return static :: parseUploadedFiles ( $ _FILES ) ; } return [ ] ; } | Create a normalized tree of UploadedFile instances from global server variables . |
19,360 | public function getConfig ( ) { if ( $ this -> cache instanceof Cache \ CacheInterface && ! empty ( $ configs = $ this -> cache -> getConfig ( ) ) ) { return $ configs ; } $ configs = $ this -> moduleHandler -> getModulesConfig ( ) ; foreach ( $ this -> files as $ file ) { $ config = require $ file ; if ( ! is_array ( $ config ) ) { throw new Exception \ RuntimeException ( sprintf ( 'The config in "%s" file must be array data type' , $ file ) ) ; } $ configs = ArrayUtils :: merge ( $ configs , require $ file ) ; } return $ this -> cleanUp ( $ configs ) ; } | Get entire configurations in application and modules |
19,361 | protected function filterViewPath ( $ configViewPaths ) { if ( ! ArrayUtils :: isHashTable ( $ configViewPaths ) ) { throw new Exception \ InvalidArgumentException ( 'Config view path is not valid' ) ; } foreach ( $ configViewPaths as $ moduleName => $ viewPath ) { $ viewPath = realpath ( $ viewPath ) ; if ( ! $ viewPath ) { $ errMsg = sprintf ( 'Config view path for "%s" module is invalid' , $ moduleName ) ; throw new Exception \ RuntimeException ( $ errMsg ) ; } $ configViewPaths [ $ moduleName ] = $ viewPath ; } return $ configViewPaths ; } | Get real path for view path configs |
19,362 | protected function filterVoltPath ( $ configVolt ) { foreach ( $ configVolt as $ moduleName => $ config ) { $ path = false ; if ( isset ( $ config [ 'path' ] ) ) { unset ( $ configVolt [ $ moduleName ] [ 'path' ] ) ; $ path = realpath ( $ config [ 'path' ] ) ; } if ( $ path ) { $ configVolt [ $ moduleName ] [ 'path' ] = $ path ; } } return $ configVolt ; } | Filter config volt template engine |
19,363 | protected function cleanUp ( array $ configs ) { $ configs [ 'view' ] = ! isset ( $ configs [ 'view' ] ) ? [ ] : $ this -> filterViewPath ( $ configs [ 'view' ] ) ; $ configs [ 'volt' ] = ! isset ( $ configs [ 'volt' ] ) ? [ ] : $ this -> filterVoltPath ( $ configs [ 'volt' ] ) ; if ( $ this -> cache instanceof Cache \ CacheInterface ) { $ this -> cache -> setConfig ( $ configs ) ; } return $ configs ; } | Clean up entire application config |
19,364 | public function regexp ( $ value , string $ expression ) : bool { return is_string ( $ value ) && preg_match ( $ expression , $ value ) ; } | Check string using regexp . |
19,365 | public function shorter ( $ value , int $ length ) : bool { return is_string ( $ value ) && mb_strlen ( trim ( $ value ) ) <= $ length ; } | Check if string length is shorter or equal that specified value . |
19,366 | public function range ( $ value , int $ min , int $ max ) : bool { return is_string ( $ value ) && ( mb_strlen ( $ trimmed = trim ( $ value ) ) >= $ min ) && ( mb_strlen ( $ trimmed ) <= $ max ) ; } | Check if string length are fits in specified range . |
19,367 | public function _getByPath ( $ path ) { $ result = null ; $ steps = $ this -> _pathAsArray ( $ path ) ; $ depth = count ( $ steps ) ; if ( $ depth == 0 ) { $ result = $ this -> data ; } else { $ pointer = $ this -> data ; $ level = 0 ; foreach ( $ steps as $ step ) { if ( is_array ( $ pointer ) ) { if ( isset ( $ pointer [ $ step ] ) ) { $ pointer = $ pointer [ $ step ] ; } else { break ; } } elseif ( $ pointer instanceof \ Flancer32 \ Lib \ Data ) { if ( ! is_null ( $ pointer -> get ( $ step ) ) ) { $ pointer = $ pointer -> get ( $ step ) ; } else { break ; } } elseif ( is_object ( $ pointer ) ) { if ( isset ( $ pointer -> $ step ) ) { $ pointer = $ pointer -> $ step ; } else { break ; } } else { break ; } $ level ++ ; } if ( $ level >= $ depth ) { $ result = $ pointer ; } } return $ result ; } | Recursive method to get some attribute of the DataObject by path . |
19,368 | public function getData ( ) { $ this -> validate ( 'amount' , 'currency' ) ; $ data = array ( ) ; $ data [ 'timestamp' ] = $ this -> getTimestamp ( ) ; $ data [ 'transaction[amount]' ] = $ this -> getAmountInteger ( ) ; $ data [ 'transaction[cancel_url]' ] = $ this -> getCancelUrl ( ) ; $ data [ 'transaction[currency]' ] = strtoupper ( $ this -> getCurrency ( ) ) ; $ data [ 'transaction[external_order_num]' ] = $ this -> getTransactionReference ( ) ; $ data [ 'transaction[return_url]' ] = $ this -> getReturnUrl ( ) ; $ data [ 'transaction[tax]' ] = $ this -> getTax ( ) ; return $ data ; } | Assemble the data to send with the request . |
19,369 | protected function GetResourceNamespace ( $ prefix , $ resourceKey ) { $ resourceNamespace = $ prefix . ucfirst ( strtolower ( $ resourceKey ) ) . "Resx_" . $ this -> CultureValue ; return $ resourceNamespace ; } | Computes the resource namespace from the context . |
19,370 | public function executeAction ( ) { $ moduleClass = $ this -> get ( 'request' ) -> get ( '_module.module' ) ; $ actionName = $ this -> get ( 'request' ) -> get ( '_module.action' ) ; $ module = $ this -> get ( 'module_manager' ) -> get ( $ moduleClass ) ; foreach ( $ module -> getControllerPreExecutes ( ) as $ controllerPreExecute ) { if ( null !== $ retval = call_user_func ( $ controllerPreExecute , $ module ) ) { return $ retval ; } } return $ module -> getAction ( $ actionName ) -> executeController ( ) ; } | Executes an action . |
19,371 | public function offsetGet ( $ key ) { $ result = array_get ( $ this -> items , $ key ) ; if ( is_array ( $ result ) ) return new static ( $ result ) ; return $ result ; } | Get an item at a given offset using Dot - notation . |
19,372 | public function get ( $ key , $ default = null ) { if ( $ this -> offsetExists ( $ key ) ) { return $ this -> offsetGet ( $ key ) ; } return value ( $ default ) ; } | Get an item from the collection by key using Dot - notation . |
19,373 | public function setName ( $ name ) { if ( ! is_string ( $ name ) || strlen ( trim ( $ name ) ) == 0 ) throw new InvalidArgumentException ( __METHOD__ . '; Invalid name, must be a non empty string' ) ; $ this -> name = $ name ; } | Set name of this Provider |
19,374 | public function setType ( $ type ) { if ( ! is_string ( $ type ) || strlen ( trim ( $ type ) ) == 0 ) throw new InvalidArgumentException ( __METHOD__ . '; Invalid type, must be a non empty string' ) ; $ this -> type = $ type ; } | Set type of this Provider |
19,375 | public function log ( $ level , $ message , array $ context = [ ] ) { if ( ! is_string ( $ level ) || ! is_string ( $ message ) ) { throw new \ InvalidArgumentException ( 'Level or message must be a string' ) ; } $ file = $ this -> logPath . '/' . $ level . '.log' ; $ stream = $ this -> streamFactory -> createStreamFromFile ( $ file , 'a+' ) ; $ content = $ this -> interpolate ( $ message . "\n" , $ context ) ; $ stream -> write ( $ content ) ; } | Write log . |
19,376 | public static function loadThemes ( ) { $ themesFolder = new Folder ( ROOT . DS . 'themes' ) ; $ themes = $ themesFolder -> read ( ) [ 0 ] ; $ loader = require ROOT . DS . 'vendor' . DS . 'autoload.php' ; foreach ( $ themes as $ theme ) { $ loader -> addPsr4 ( 'WasabiTheme\\' . $ theme . '\\' , [ $ themesFolder -> path . DS . $ theme . DS . 'src' ] ) ; Plugin :: load ( 'WasabiTheme/' . $ theme , [ 'path' => $ themesFolder -> path . DS . $ theme . DS , 'bootstrap' => true , 'routes' => false ] ) ; } } | Register all available themes in the composer classloader and load them as plugin . |
19,377 | public static function init ( ) { foreach ( self :: $ _registeredThemes as $ registeredTheme ) { $ theme = self :: _initializeTheme ( $ registeredTheme ) ; self :: $ _themes [ $ theme -> id ( ) ] = $ theme ; } self :: $ _initialized = true ; } | Initialize all available themes . |
19,378 | public static function theme ( $ theme = null ) { if ( ! self :: $ _initialized ) { self :: init ( ) ; } if ( $ theme !== null ) { if ( ! isset ( self :: $ _themes [ $ theme ] ) ) { throw new Exception ( __d ( 'wasabi_cms' , 'Theme "{0}" does not exist.' , $ theme ) ) ; } self :: $ _theme = self :: $ _themes [ $ theme ] ; } return self :: $ _theme ; } | Get or set the currently active theme . |
19,379 | public static function getThemesForSelect ( ) { if ( ! self :: $ _initialized ) { self :: init ( ) ; } $ results = [ ] ; foreach ( self :: $ _themes as $ theme ) { $ results [ $ theme -> id ( ) ] = $ theme -> name ( ) ; } return $ results ; } | Get all themes for a form select input . |
19,380 | protected static function _initializeTheme ( $ registeredTheme ) { list ( $ theme , $ themeName ) = pluginSplit ( $ registeredTheme ) ; $ themeNamespace = preg_replace ( '/\\//' , '\\' , $ theme ) ; $ themeClass = $ themeNamespace . '\\' . $ themeName ; try { $ theme = new $ themeClass ( ) ; } catch ( Exception $ e ) { throw new Exception ( __d ( 'wasabi_core' , 'The theme "{0}" could not be instatiated. Check the namespace and file location.' , $ themeClass ) ) ; } return $ theme ; } | Initialize a single registered theme . |
19,381 | private function loadServiceProvider ( ) { \ Tiga \ Framework \ Facade \ Facade :: setFacadeContainer ( $ this ) ; $ providers = $ this [ 'config' ] -> get ( 'provider' ) ; $ providers = array_unique ( $ providers ) ; foreach ( $ providers as $ provider ) { $ instance = new $ provider ( $ this ) ; $ instance -> register ( ) ; } $ aliases = $ this [ 'config' ] -> get ( 'alias' ) ; $ aliases = array_unique ( $ aliases ) ; $ aliasMapper = \ Tonjoo \ Almari \ AliasMapper :: getInstance ( ) ; $ aliasMapper -> classAlias ( $ aliases ) ; } | Load registered service provider in the main plugin and child plugin . |
19,382 | private function removeLogs ( Schedule $ scheduler ) { $ scheduler -> call ( function ( ) { $ searchDir = Config :: $ root . 'storage' . DIRECTORY_SEPARATOR . 'logs' . DIRECTORY_SEPARATOR ; $ prefix = config ( 'app.logger.name' ) ; $ logs = glob ( $ searchDir . $ prefix . '-*-*-*.log' ) ; if ( count ( $ logs ) < 1 ) return ; foreach ( $ logs as $ log ) { $ date = str_replace ( $ prefix . '-' , '' , Filesystem :: name ( $ log ) ) ; $ end = new Carbon ( $ date ) ; $ now = Carbon :: now ( ) ; if ( $ now -> diffInDays ( $ end ) > config ( 'app.logger.keep' ) ) { try { Filesystem :: delete ( $ log ) ; } catch ( \ Exception $ e ) { } } } } ) -> daily ( ) ; } | Remove application logs |
19,383 | public static function getExceptionNameHierarchy ( \ Exception $ e , $ separator = ' >> ' ) { $ names = array ( ) ; do { $ names [ ] = get_class ( $ e ) ; } while ( ( $ e = $ e -> getPrevious ( ) ) !== null ) ; $ names = implode ( $ separator , $ names ) ; return $ names ; } | Returns a formatted string containing the class names of the exeptions thrown . |
19,384 | public static function getFormattedExceptionMessage ( \ Exception $ e ) { $ name = static :: getExceptionNameHierarchy ( $ e ) ; list ( $ file , $ line , $ stackTrace ) = static :: getOriginalExceptionFileAndLineNumber ( $ e ) ; $ message = "{$name}: {$e->getMessage()} ({$e->getcode()})\n{$file} {$line}\n{$stackTrace}" ; return $ message ; } | Returns the formatted message of a passed in exception . |
19,385 | public static function getOriginalExceptionFileAndLineNumber ( \ Exception $ e ) { $ names = array ( ) ; do { $ p = $ e ; $ names [ ] = get_class ( $ e ) ; } while ( ( $ e = $ e -> getPrevious ( ) ) !== null ) ; return array ( $ p -> getFile ( ) , $ p -> getLine ( ) , $ p -> getTraceAsString ( ) ) ; } | Returns the file name line number and stack trace where the original exception was thrown . |
19,386 | public function transform ( $ data ) : File { $ file = file_exists ( $ data ) ? $ data : null ; $ file = is_null ( $ file ) ? new File ( '' , false ) : new File ( $ file , true ) ; return $ file ; } | Transforms an string to File |
19,387 | private function getJSONVersionOfSchema ( ) { $ cacheFile = dirname ( dirname ( __DIR__ ) ) . '/data/schemaorg.cache' ; if ( ! file_exists ( $ cacheFile ) ) { if ( ! file_exists ( dirname ( $ cacheFile ) ) ) { mkdir ( dirname ( $ cacheFile ) , 0777 , true ) ; } $ graph = new \ EasyRdf_Graph ( self :: RDFA_SCHEMA ) ; $ graph -> load ( self :: RDFA_SCHEMA , 'rdfa' ) ; $ format = \ EasyRdf_Format :: getFormat ( 'jsonld' ) ; $ output = $ graph -> serialise ( $ format ) ; if ( ! is_scalar ( $ output ) ) { $ output = var_export ( $ output , true ) ; } $ this -> schema = \ ML \ JsonLD \ JsonLD :: compact ( $ graph -> serialise ( $ format ) , 'http://schema.org/' ) ; file_put_contents ( $ cacheFile , serialize ( $ this -> schema ) ) ; } else { $ this -> schema = unserialize ( file_get_contents ( $ cacheFile ) ) ; } } | Retrieve the latest RDFA version of schema . org and converts it to JSON - LD . |
19,388 | public function migrate ( $ direction = 'up' ) { if ( ! $ this -> tableExists ( 'schema_migrations' ) ) { $ this -> createMigrationsTable ( ) ; } foreach ( get_declared_classes ( ) as $ declaredClass ) { if ( is_subclass_of ( $ declaredClass , "Avalon\\Database\\Migration" ) ) { if ( $ direction === 'up' ) { $ this -> up ( $ declaredClass ) ; } elseif ( $ direction === 'down' ) { $ this -> down ( $ declaredClass ) ; } } } } | Handles the execution of migrations . |
19,389 | protected function up ( $ className ) { if ( $ fileName = $ this -> migrated ( $ className ) ) { $ migration = new $ className ; $ migration -> up ( ) ; $ migration -> execute ( ) ; $ this -> connection -> insert ( "schema_migrations" , [ 'version' => $ fileName , 'date' => date ( "Y-m-d" ) ] ) ; } } | Migrates the database forward . |
19,390 | protected function migrated ( $ className ) { $ classInfo = new ReflectionClass ( $ className ) ; $ fileName = str_replace ( '.php' , '' , basename ( $ classInfo -> getFileName ( ) ) ) ; $ result = $ this -> connection -> createQueryBuilder ( ) -> select ( 'version' ) -> from ( 'schema_migrations' ) -> where ( 'version = ?' ) -> setParameter ( 0 , $ fileName ) -> execute ( ) ; if ( ! count ( $ result -> fetchAll ( ) ) ) { return $ fileName ; } else { return false ; } } | Checks if the migration has been executed and returns the migrations base file name . |
19,391 | protected function createMigrationsTable ( ) { $ schema = new Schema ; $ table = $ schema -> createTable ( "schema_migrations" ) ; $ table -> addColumn ( "version" , "string" ) ; $ table -> addColumn ( "date" , "date" ) ; $ queries = $ schema -> toSql ( $ this -> connection -> getDatabasePlatform ( ) ) ; foreach ( $ queries as $ query ) { $ this -> connection -> query ( $ query ) ; } } | Creates the migration log table . |
19,392 | public static function toXML ( $ data , $ rootNodeName = 'entity' , & $ xml = null ) { if ( ini_get ( 'zend.ze1_compatibility_mode' ) == 1 ) ini_set ( 'zend.ze1_compatibility_mode' , 0 ) ; if ( is_null ( $ xml ) ) $ xml = simplexml_load_string ( "<?xml version='1.0' encoding='utf-8'?><$rootNodeName />" ) ; foreach ( $ data as $ key => $ value ) { $ numeric = false ; if ( is_numeric ( $ key ) ) { $ numeric = 1 ; $ key = $ rootNodeName ; } $ key = preg_replace ( '/[^a-z0-9\-\_\.\:]/i' , '' , $ key ) ; if ( is_array ( $ value ) ) { $ node = self :: isAssoc ( $ value ) || $ numeric ? $ xml -> addChild ( $ key ) : $ xml ; if ( $ numeric ) $ key = 'anon' ; self :: toXml ( $ value , $ key , $ node ) ; } else { $ value = Html :: encode ( $ value ) ; $ xml -> addChild ( $ key , $ value ) ; } } return $ xml -> asXML ( ) ; } | Converts a multidimensional associative array to an XML document . |
19,393 | public function to ( $ destination , array $ defaults = [ ] ) { if ( $ this -> name === null ) { $ this -> name = strtolower ( str_replace ( [ '\\' , '::' ] , '_' , $ destination ) ) ; } $ this -> destination = $ destination ; $ this -> defaults = $ defaults ; return $ this ; } | Destination class and method of route . |
19,394 | public function method ( $ method ) { if ( ! is_array ( $ method ) ) { $ method = [ $ method ] ; } $ this -> method = $ method ; return $ this ; } | HTTP methods to accept . |
19,395 | public function generateUrl ( array $ tokens = [ ] ) { $ path = $ this -> path ; foreach ( $ tokens as $ key => $ value ) { $ path = str_replace ( ":{$key}" , $ value , $ path ) ; } return $ path ; } | Generates the path replacing tokens with specified values . |
19,396 | public function & SetForm ( \ MvcCore \ Ext \ Forms \ IForm & $ form ) { $ this -> form = & $ form ; return $ this ; } | Set form instance to render . |
19,397 | public function & SetField ( \ MvcCore \ Ext \ Forms \ IField & $ field ) { $ this -> __protected [ 'fieldRendering' ] = TRUE ; $ this -> field = & $ field ; return $ this ; } | Set rendered field . |
19,398 | public function RenderTemplate ( ) { $ formViewScript = $ this -> form -> GetViewScript ( ) ; return $ this -> Render ( static :: $ formsDir , is_bool ( $ formViewScript ) ? $ this -> form -> GetId ( ) : $ formViewScript ) ; } | Render configured form template . |
19,399 | public function RenderErrors ( ) { $ this -> form -> PreDispatch ( ) ; $ result = '' ; $ errors = & $ this -> form -> GetErrors ( ) ; if ( $ errors && $ this -> form -> GetErrorsRenderMode ( ) == \ MvcCore \ Ext \ Forms \ IForm :: ERROR_RENDER_MODE_ALL_TOGETHER ) { $ result .= '<div class="errors">' ; foreach ( $ errors as & $ errorMessageAndFieldNames ) { list ( $ errorMessage , $ fieldNames ) = $ errorMessageAndFieldNames ; $ result .= '<div class="error ' . implode ( ' ' , $ fieldNames ) . '">' . $ errorMessage . '</div>' ; } $ result .= '</div>' ; } return $ result ; } | Render form errors . If form is configured to render all errors together at form beginning this function completes all form errors into div . errors with div . error elements inside containing each single errors message . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.