idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
16,600
public function get ( $ object ) { $ hash = spl_object_hash ( $ object ) ; if ( isset ( $ this -> data [ $ hash ] ) ) { return $ this -> data [ $ hash ] ; } return null ; }
Returns the data associated to the given object .
16,601
public function set ( $ object , $ data = null ) : void { $ hash = spl_object_hash ( $ object ) ; $ this -> objects [ $ hash ] = $ object ; $ this -> data [ $ hash ] = $ data ; }
Stores an object with associated data .
16,602
public function remove ( $ object ) : void { $ hash = spl_object_hash ( $ object ) ; unset ( $ this -> objects [ $ hash ] ) ; unset ( $ this -> data [ $ hash ] ) ; }
Removes the given object from this storage along with associated data .
16,603
public function getIterator ( ) : \ Traversable { foreach ( $ this -> objects as $ hash => $ object ) { yield $ object => $ this -> data [ $ hash ] ; } }
Returns an iterator for this storage .
16,604
public function call ( $ reqData ) { $ respData = $ this -> createError ( 'Unrecognized entity or action' ) ; if ( $ reqData [ 'entity' ] == 'Cxn' && preg_match ( '/^[a-zA-Z]+$/' , $ reqData [ 'action' ] ) ) { $ func = 'on' . $ reqData [ 'entity' ] . strtoupper ( $ reqData [ 'action' ] { 0 } ) . substr ( $ reqData [ 'action' ] , 1 ) ; if ( is_callable ( array ( $ this , $ func ) ) ) { $ respData = call_user_func ( array ( $ this , $ func ) , $ reqData [ 'cxn' ] , $ reqData [ 'params' ] ) ; } } return $ respData ; }
Delegate handling of hte registration message to a callback function .
16,605
public function onCxnRegister ( $ cxn , $ params ) { $ storedCxn = $ this -> cxnStore -> getByCxnId ( $ cxn [ 'cxnId' ] ) ; if ( ! $ storedCxn || $ storedCxn [ 'secret' ] == $ cxn [ 'secret' ] ) { $ this -> log -> notice ( 'Register cxnId="{cxnId}" siteUrl={siteUrl}: OK' , array ( 'cxnId' => $ cxn [ 'cxnId' ] , 'siteUrl' => $ cxn [ 'siteUrl' ] , ) ) ; $ this -> cxnStore -> add ( $ cxn ) ; return $ this -> createSuccess ( array ( 'cxn_id' => $ cxn [ 'cxnId' ] , ) ) ; } else { $ this -> log -> warning ( 'Register cxnId="{cxnId}" siteUrl="{siteUrl}": Secret does not match.' , array ( 'cxnId' => $ cxn [ 'cxnId' ] , 'siteUrl' => $ cxn [ 'siteUrl' ] , ) ) ; $ this -> createError ( 'Secret does not match previous registration.' ) ; } }
Callback for Cxn . register .
16,606
public function onCxnUnregister ( $ cxn , $ params ) { $ storedCxn = $ this -> cxnStore -> getByCxnId ( $ cxn [ 'cxnId' ] ) ; if ( ! $ storedCxn ) { $ this -> log -> warning ( 'Unregister cxnId="{cxnId} siteUrl="{siteUrl}"": Non-existent' , array ( 'cxnId' => $ cxn [ 'cxnId' ] , 'siteUrl' => $ cxn [ 'siteUrl' ] , ) ) ; return $ this -> createSuccess ( array ( 'cxn_id' => $ cxn [ 'cxnId' ] , ) ) ; } elseif ( $ storedCxn [ 'secret' ] == $ cxn [ 'secret' ] ) { $ this -> log -> notice ( 'Unregister cxnId="{cxnId} siteUrl="{siteUrl}": OK"' , array ( 'cxnId' => $ cxn [ 'cxnId' ] , 'siteUrl' => $ cxn [ 'siteUrl' ] , ) ) ; $ this -> cxnStore -> remove ( $ cxn [ 'cxnId' ] ) ; return $ this -> createSuccess ( array ( 'cxn_id' => $ cxn [ 'cxnId' ] , ) ) ; } else { $ this -> log -> warning ( 'Unregister cxnId="{cxnId}" siteUrl="{siteUrl}": Secret does not match.' , array ( 'cxnId' => $ cxn [ 'cxnId' ] , 'siteUrl' => $ cxn [ 'siteUrl' ] , ) ) ; $ this -> createError ( 'Incorrect cxnId or secret.' ) ; } }
Callback for Cxn . unregister .
16,607
public function addPlugin ( Plugin $ plugin ) : Builder { $ this -> plugins [ ] = $ plugin ; $ this -> httpClientModified = true ; return $ this ; }
Add a new plugin to the end of the plugin chain .
16,608
public static function set ( $ method , $ path , $ action ) { if ( is_array ( $ method ) ) { foreach ( $ method as $ value ) { self :: set ( $ value , $ path , $ action ) ; } } else { if ( is_string ( $ action ) ) { $ action = parent :: $ prefixNS . $ action ; } elseif ( $ action !== null && ! $ action instanceof \ Closure ) { return null ; } $ method = strtoupper ( trim ( $ method ) ) ; $ path = parent :: $ prefixPath . $ path ; if ( ! isset ( parent :: $ httpRoutes [ $ path ] ) ) { parent :: $ httpRoutes [ $ path ] = array ( ) ; } parent :: $ httpRoutes [ $ path ] [ $ method ] = $ action ; } }
Register or remove a action from controller for a route
16,609
public static function get ( ) { if ( self :: $ current !== null ) { return self :: $ current ; } $ resp = 404 ; $ args = array ( ) ; $ routes = parent :: $ httpRoutes ; $ path = \ UtilsPath ( ) ; $ method = $ _SERVER [ 'REQUEST_METHOD' ] ; if ( isset ( $ routes [ $ path ] ) ) { $ verbs = $ routes [ $ path ] ; } else { foreach ( $ routes as $ route => $ actions ) { if ( parent :: find ( $ route , $ path , $ args ) ) { $ verbs = $ actions ; break ; } } } if ( isset ( $ verbs [ $ method ] ) ) { $ resp = $ verbs [ $ method ] ; } elseif ( isset ( $ verbs [ 'ANY' ] ) ) { $ resp = $ verbs [ 'ANY' ] ; } elseif ( isset ( $ verbs ) ) { $ resp = 405 ; } if ( is_numeric ( $ resp ) ) { self :: $ current = $ resp ; } else { self :: $ current = array ( 'callback' => $ resp , 'args' => $ args ) ; } $ routes = null ; return self :: $ current ; }
Get action controller from current route
16,610
public static function run ( callable $ function ) { set_error_handler ( static function ( $ severity , $ message , $ file , $ line ) { throw new \ ErrorException ( $ message , 0 , $ severity , $ file , $ line ) ; } ) ; try { $ result = $ function ( ) ; } finally { restore_error_handler ( ) ; } return $ result ; }
Runs the given function catching PHP errors and throwing exceptions .
16,611
public static function emergency ( $ message , $ context = [ ] , $ channel = 'tastphp.logger' ) { $ logger = static :: getLoggerByLevelAndChannel ( Monolog :: ALERT , $ channel ) ; $ logger -> addEmergency ( $ message , $ context ) ; }
system is unusable .
16,612
public static function dispatch ( ) { if ( empty ( self :: $ headers ) === false ) { self :: $ dispatchedHeaders = true ; foreach ( self :: $ headers as $ value ) { self :: putHeader ( $ value [ 0 ] , $ value [ 1 ] , $ value [ 2 ] ) ; } } }
Define registered headers to response
16,613
public static function status ( $ code = null , $ trigger = true ) { if ( self :: $ httpCode === null ) { self :: $ httpCode = \ UtilsStatusCode ( ) ; } if ( $ code === null || self :: $ httpCode === $ code ) { return self :: $ httpCode ; } elseif ( headers_sent ( ) || $ code < 100 || $ code > 599 ) { return false ; } header ( 'X-PHP-Response-Code: ' . $ code , true , $ code ) ; $ lastCode = self :: $ httpCode ; self :: $ httpCode = $ code ; if ( $ trigger ) { App :: trigger ( 'changestatus' , array ( $ code , null ) ) ; } return $ lastCode ; }
Get or set status code and return last status code
16,614
public static function removeHeader ( $ name ) { self :: $ headers = array_filter ( self :: $ headers , function ( $ header ) use ( $ name ) { return strcasecmp ( $ header [ 0 ] , $ name ) !== 0 ; } ) ; }
Remove registered header
16,615
public static function download ( $ name = null , $ contentLength = 0 ) { if ( $ name ) { $ name = '; filename="' . strtr ( $ name , '"' , '-' ) . '"' ; } else { $ name = '' ; } self :: putHeader ( 'Content-Transfer-Encoding' , 'Binary' ) ; self :: putHeader ( 'Content-Disposition' , 'attachment' . $ name ) ; if ( $ contentLength > 0 ) { self :: putHeader ( 'Content-Length' , $ contentLength ) ; } }
Force download current page
16,616
public function addViewData ( $ key , $ value ) { if ( $ key ) { $ this -> modelVar [ $ key ] = $ value ; } else { $ this -> modelVar = $ value ; } return $ this ; }
to add view data
16,617
public function inputObserver ( $ callback , $ exitCicle = null ) { if ( self :: isCli ( ) === false || is_callable ( $ callback ) === false ) { return false ; } $ this -> io = $ callback ; $ this -> ec = $ exitCicle ? $ exitCicle : $ this -> ec ; if ( $ this -> started ) { return true ; } $ this -> started = true ; $ this -> fireInputObserver ( ) ; return true ; }
Add callback event to input
16,618
protected function fireInputObserver ( ) { $ response = rtrim ( self :: input ( ) , PHP_EOL ) ; if ( strcasecmp ( $ response , $ this -> ec ) === 0 ) { return null ; } $ callback = $ this -> io ; $ callback ( $ response ) ; usleep ( 100 ) ; $ this -> fireInputObserver ( ) ; }
Trigger observer input
16,619
public function get ( string $ pattern , callable $ callback ) { if ( $ this -> requestMethod === "GET" ) { $ this -> mapRoute ( $ pattern , $ callback ) ; } }
allow to access via the get request
16,620
public function post ( string $ pattern , callable $ callback ) { if ( $ this -> requestMethod === "POST" ) { $ this -> mapRoute ( $ pattern , $ callback ) ; } }
allow to access via the post request
16,621
private static function getPattern ( string $ pattern ) { $ keywords = preg_split ( "/\\//" , $ pattern ) ; $ i = '0' ; $ word = "" ; foreach ( $ keywords as $ keyword ) { $ i ++ ; if ( preg_match ( "/:/i" , $ keyword ) ) { $ word .= "([a-zA-Z0-9-._]+)" ; } else { $ word .= $ keyword ; } if ( count ( $ keywords ) != $ i ) { $ word .= "/" ; } } return $ word ; }
input patten re change
16,622
private function normalizeConfig ( array $ embedConfig ) { $ config = $ embedConfig ; if ( array_key_exists ( 'video_player' , $ embedConfig ) ) { $ config [ 'video' ] [ 'player' ] = $ embedConfig [ 'video_player' ] ; } if ( array_key_exists ( 'video_autoplay' , $ embedConfig ) ) { $ config [ 'video' ] [ 'autoplay' ] = $ embedConfig [ 'video_autoplay' ] ; } if ( array_key_exists ( 'video_available_speeds' , $ embedConfig ) ) { $ config [ 'video' ] [ 'available-speeds' ] = $ embedConfig [ 'video_available_speeds' ] ; } if ( array_key_exists ( 'audio_player' , $ embedConfig ) ) { $ config [ 'audio' ] [ 'player' ] = $ embedConfig [ 'audio_player' ] ; } if ( array_key_exists ( 'audio_autoplay' , $ embedConfig ) ) { $ config [ 'audio' ] [ 'autoplay' ] = $ embedConfig [ 'audio_autoplay' ] ; } if ( array_key_exists ( 'audio_available_speeds' , $ embedConfig ) ) { $ config [ 'audio' ] [ 'available-speeds' ] = $ embedConfig [ 'audio_available_speeds' ] ; } if ( array_key_exists ( 'enable_pdfjs' , $ embedConfig [ 'document' ] ) ) { $ config [ 'document' ] [ 'enable-pdfjs' ] = $ embedConfig [ 'document' ] [ 'enable_pdfjs' ] ; } return $ config ; }
apply deprecated configuration keys
16,623
public function group ( $ group , $ handle = null , $ content = null ) { $ this -> groups [ $ group ] [ $ handle ] = $ content ; return $ this ; }
Group wrapper .
16,624
public function removeGroup ( $ group = null , $ handle = null ) { if ( is_null ( $ group ) ) { return $ this -> groups = [ ] ; } if ( is_null ( $ handle ) ) { unset ( $ this -> groups [ $ group ] ) ; return ; } unset ( $ this -> groups [ $ group ] [ $ handle ] ) ; }
Remove a group asset all of a groups assets or all group assets .
16,625
public function renderGroup ( $ group ) { if ( ! isset ( $ this -> groups [ $ group ] ) ) { return PHP_EOL ; } foreach ( $ this -> groups [ $ group ] as $ handle => $ data ) { $ assets [ ] = $ this -> getGroup ( $ group , $ handle ) ; } return implode ( PHP_EOL , $ assets ) ; }
Get all of a groups assets sorted by dependencies .
16,626
public function saveSeoContent ( ) { $ model = $ this -> getSeoContentModel ( ) ; if ( ! $ model -> is_global ) { $ model -> title = $ this -> owner -> { $ this -> titleAttribute } ; $ model -> keywords = $ this -> owner -> { $ this -> keywordsAttribute } ; $ model -> description = $ this -> owner -> { $ this -> descriptionAttribute } ; $ model -> save ( ) ; } }
Saving seo content
16,627
public function deleteSeoContent ( ) { $ model = $ this -> getSeoContentModel ( ) ; if ( $ model && ! $ model -> getIsNewRecord ( ) && ! $ model -> is_global ) { $ model -> delete ( ) ; } }
Deleting seo content
16,628
protected static function find ( $ route , $ path , array & $ matches ) { $ re = Regex :: parse ( $ route ) ; if ( $ re !== false && preg_match ( '#^' . $ re . '$#' , $ path , $ matches ) ) { array_shift ( $ matches ) ; return true ; } return false ; }
Get params from routes using regex
16,629
private static function verbs ( array $ methods ) { $ list = array ( ) ; $ reMatch = '#^(any|get|post|patch|put|head|delete|options|trace|connect)([A-Z0-9]\w+)$#' ; foreach ( $ methods as $ value ) { $ verb = array ( ) ; if ( preg_match ( $ reMatch , $ value , $ verb ) ) { if ( strcasecmp ( 'index' , $ verb [ 2 ] ) === 0 ) { $ verb [ 2 ] = '' ; } else { $ verb [ 2 ] = strtolower ( preg_replace ( '#([a-z])([A-Z])#' , '$1-$2' , $ verb [ 2 ] ) ) ; } $ list [ ] = array ( strtoupper ( $ verb [ 1 ] ) , $ verb [ 2 ] , $ value ) ; } } return $ list ; }
Extract valid methods
16,630
public function prepare ( ) { if ( $ this -> ready ) { return null ; } $ this -> ready = true ; $ format = $ this -> format ; $ controller = $ this -> controller ; foreach ( $ this -> classMethods as $ value ) { if ( $ format === self :: BOTH || $ format === self :: SLASH ) { $ route = '/' . ( empty ( $ value [ 1 ] ) ? '' : ( $ value [ 1 ] . '/' ) ) ; Route :: set ( $ value [ 0 ] , $ route , $ controller . ':' . $ value [ 2 ] ) ; } if ( $ format === self :: BOTH || $ format === self :: NOSLASH ) { $ route = empty ( $ value [ 1 ] ) ? '' : ( '/' . $ value [ 1 ] ) ; Route :: set ( $ value [ 0 ] , $ route , $ controller . ':' . $ value [ 2 ] ) ; } } $ controller = $ classMethods = null ; }
Create routes by configurations
16,631
public static function authenticateThenDecrypt ( $ secret , $ body , $ signature ) { $ keys = self :: deriveAesKeys ( $ secret ) ; $ localHmac = hash_hmac ( 'sha256' , $ body , $ keys [ 'auth' ] ) ; if ( ! self :: hash_compare ( $ signature , $ localHmac ) ) { throw new InvalidMessageException ( "Incorrect hash" ) ; } list ( $ jsonEnvelope , $ jsonEncrypted ) = explode ( Constants :: PROTOCOL_DELIM , $ body , 2 ) ; if ( strlen ( $ jsonEnvelope ) > Constants :: MAX_ENVELOPE_BYTES ) { throw new InvalidMessageException ( "Oversized envelope" ) ; } $ envelope = json_decode ( $ jsonEnvelope , TRUE ) ; if ( ! $ envelope ) { throw new InvalidMessageException ( "Malformed envelope" ) ; } if ( ! is_numeric ( $ envelope [ 'ttl' ] ) || Time :: getTime ( ) > $ envelope [ 'ttl' ] ) { throw new InvalidMessageException ( "Invalid TTL" ) ; } if ( ! is_string ( $ envelope [ 'iv' ] ) || strlen ( $ envelope [ 'iv' ] ) !== Constants :: AES_BYTES * 2 || ! preg_match ( '/^[a-f0-9]+$/' , $ envelope [ 'iv' ] ) ) { throw new InvalidMessageException ( "Malformed initialization vector" ) ; } $ jsonPlaintext = UserError :: adapt ( 'Civi\Cxn\Rpc\Exception\InvalidMessageException' , function ( ) use ( $ jsonEncrypted , $ envelope , $ keys ) { $ cipher = new \ Crypt_AES ( CRYPT_AES_MODE_CBC ) ; $ cipher -> setKeyLength ( Constants :: AES_BYTES ) ; $ cipher -> setKey ( $ keys [ 'enc' ] ) ; $ cipher -> setIV ( BinHex :: hex2bin ( $ envelope [ 'iv' ] ) ) ; return $ cipher -> decrypt ( $ jsonEncrypted ) ; } ) ; return $ jsonPlaintext ; }
Validate the signature and date of the message then decrypt it .
16,632
private static function hash_compare ( $ a , $ b ) { if ( ! is_string ( $ a ) || ! is_string ( $ b ) ) { return FALSE ; } $ len = strlen ( $ a ) ; if ( $ len !== strlen ( $ b ) ) { return FALSE ; } $ status = 0 ; for ( $ i = 0 ; $ i < $ len ; $ i ++ ) { $ status |= ord ( $ a [ $ i ] ) ^ ord ( $ b [ $ i ] ) ; } return $ status === 0 ; }
Comparison function which resists timing attacks .
16,633
public static function exists ( $ path ) { if ( file_exists ( $ path ) === false ) { return false ; } $ path = preg_replace ( '#^file:/+([a-z]:/|/)#i' , '$1' , $ path ) ; $ pinfo = pathinfo ( $ path ) ; $ rpath = strtr ( realpath ( $ path ) , '\\' , '/' ) ; if ( $ pinfo [ 'dirname' ] !== '.' ) { $ path = Uri :: canonpath ( $ pinfo [ 'dirname' ] ) . '/' . $ pinfo [ 'basename' ] ; } $ pinfo = null ; return $ rpath === $ path || substr ( $ rpath , strlen ( $ rpath ) - strlen ( $ path ) ) === $ path ; }
Check if file exists using case - sensitive For help developers who using Windows OS and using unix - like for production
16,634
public static function mime ( $ path ) { $ mime = false ; if ( is_readable ( $ path ) ) { if ( function_exists ( 'finfo_open' ) ) { $ buffer = file_get_contents ( $ path , false , null , - 1 , 5012 ) ; $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mime = finfo_buffer ( $ finfo , $ buffer ) ; finfo_close ( $ finfo ) ; $ buffer = null ; } elseif ( function_exists ( 'mime_content_type' ) ) { $ mime = mime_content_type ( $ path ) ; } } if ( $ mime !== false && strpos ( $ mime , 'application/' ) === 0 ) { $ size = filesize ( $ path ) ; $ mime = $ size >= 0 && $ size < 2 ? 'text/plain' : $ mime ; } return $ mime ; }
Get mimetype from file return false if file is invalid
16,635
public static function output ( $ path , $ length = 102400 , $ delay = 0 ) { if ( is_readable ( $ path ) === false ) { return false ; } $ buffer = ob_get_level ( ) !== 0 ; $ handle = fopen ( $ path , 'rb' ) ; $ length = is_int ( $ length ) && $ length > 0 ? $ length : 102400 ; while ( false === feof ( $ handle ) ) { echo fread ( $ handle , $ length ) ; if ( $ delay > 0 ) { usleep ( $ delay ) ; } if ( $ buffer ) { ob_flush ( ) ; } flush ( ) ; } }
Show file in output if use ob_start is auto used ob_flush . You can set delay for cycles
16,636
public function send ( ) { list ( $ headers , $ blob , $ code ) = $ this -> toHttp ( ) ; header ( 'Content-Type: ' . Constants :: MIME_TYPE ) ; header ( "X-PHP-Response-Code: $code" , TRUE , $ code ) ; foreach ( $ headers as $ n => $ v ) { header ( "$n: $v" ) ; } echo $ blob ; }
Send this message immediately .
16,637
public function toSymfonyResponse ( ) { $ headers = array_merge ( array ( 'Content-Type' => Constants :: MIME_TYPE ) , $ this -> getHeaders ( ) ) ; return new \ Symfony \ Component \ HttpFoundation \ Response ( $ this -> encode ( ) , $ this -> code , $ headers ) ; }
Convert this message a Symfony Response object .
16,638
protected function doParse ( $ className , $ visited = array ( ) , array $ groups = array ( ) ) { $ meta = $ this -> factory -> getMetadataForClass ( $ className ) ; if ( null === $ meta ) { throw new \ InvalidArgumentException ( sprintf ( 'No metadata found for class %s' , $ className ) ) ; } $ exclusionStrategies = array ( ) ; if ( $ groups ) { $ exclusionStrategies [ ] = new GroupsExclusionStrategy ( $ groups ) ; } $ params = array ( ) ; foreach ( $ meta -> propertyMetadata as $ item ) { if ( ! is_null ( $ item -> type ) ) { $ name = $ this -> namingStrategy -> translateName ( $ item ) ; $ dataType = $ this -> processDataType ( $ item ) ; foreach ( $ exclusionStrategies as $ strategy ) { if ( true === $ strategy -> shouldSkipProperty ( $ item , SerializationContext :: create ( ) ) ) { continue 2 ; } } $ params [ $ name ] = array ( 'dataType' => $ dataType [ 'normalized' ] , 'required' => false , 'readonly' => $ item -> readOnly , 'sinceVersion' => $ item -> sinceVersion , 'untilVersion' => $ item -> untilVersion , ) ; if ( ! is_null ( $ dataType [ 'class' ] ) ) { $ params [ $ name ] [ 'class' ] = $ dataType [ 'class' ] ; } if ( in_array ( $ dataType [ 'class' ] , $ visited ) ) { continue ; } if ( $ dataType [ 'class' ] && null !== $ this -> factory -> getMetadataForClass ( $ dataType [ 'class' ] ) ) { $ visited [ ] = $ dataType [ 'class' ] ; $ params [ $ name ] [ 'children' ] = $ this -> doParse ( $ dataType [ 'class' ] , $ visited , $ groups ) ; } } } return $ params ; }
Recursively parse all metadata for a class .
16,639
public static function header ( $ name = null ) { if ( self :: $ reqHeaders === null ) { self :: generate ( ) ; } if ( is_string ( $ name ) ) { $ name = strtolower ( $ name ) ; return isset ( self :: $ reqHeadersLower [ $ name ] ) ? self :: $ reqHeadersLower [ $ name ] : false ; } return self :: $ reqHeaders ; }
Get HTTP headers from current request
16,640
public static function raw ( $ binary = true ) { if ( is_readable ( 'php://input' ) ) { return false ; } $ mode = $ binary ? 'rb' : 'r' ; if ( PHP_VERSION_ID >= 50600 ) { return fopen ( 'php://input' , $ mode ) ; } $ tmp = Storage :: temp ( ) ; return copy ( 'php://input' , $ tmp ) ? fopen ( $ tmp , $ mode ) : false ; }
Get a value input handler
16,641
protected static function behavior ( Component $ model ) { foreach ( $ model -> getBehaviors ( ) as $ b ) { if ( $ b instanceof SeoBehavior ) { return $ b ; } } throw new InvalidConfigException ( 'Model ' . $ model -> className ( ) . ' must have SeoBehavior' ) ; }
Getting behavior object from given model
16,642
protected static function registerSeoMetaTag ( Component $ model , string $ modelSeoAttributeName , string $ metaTagKey ) { $ value = $ model -> { $ modelSeoAttributeName } ; if ( $ value ) Yii :: $ app -> view -> registerMetaTag ( [ 'name' => $ metaTagKey , 'content' => $ value ] , $ metaTagKey ) ; }
Register seo meta tag
16,643
public static function registerAllSeoMeta ( Component $ model ) { self :: registerMetaTitle ( $ model ) ; self :: registerMetaKeywords ( $ model ) ; self :: registerMetaDescription ( $ model ) ; }
Register seo metadata . You can register part of it using methods below right in view code .
16,644
public static function setTitle ( Component $ model ) { $ title = $ model -> { self :: behavior ( $ model ) -> titleAttribute } ; if ( $ title ) Yii :: $ app -> view -> title = $ title ; }
Sets page title . If your layout
16,645
public static function registerMetaTitle ( Component $ model ) { $ modelSeoAttributeName = self :: behavior ( $ model ) -> titleAttribute ; self :: registerSeoMetaTag ( $ model , $ modelSeoAttributeName , 'title' ) ; }
Register meta title
16,646
public static function registerMetaKeywords ( Component $ model ) { $ modelSeoAttributeName = self :: behavior ( $ model ) -> keywordsAttribute ; self :: registerSeoMetaTag ( $ model , $ modelSeoAttributeName , 'keywords' ) ; }
Register meta keywords
16,647
public static function registerMetaDescription ( Component $ model ) { $ modelSeoAttributeName = self :: behavior ( $ model ) -> descriptionAttribute ; self :: registerSeoMetaTag ( $ model , $ modelSeoAttributeName , 'description' ) ; }
Register meta description
16,648
public function gets ( ? int $ maxLength = null ) : string { if ( $ this -> closed ) { throw new IoException ( 'The stream is closed.' ) ; } try { $ data = ErrorCatcher :: run ( function ( ) use ( $ maxLength ) { if ( $ maxLength === null ) { return fgets ( $ this -> handle ) ; } else { return fgets ( $ this -> handle , $ maxLength + 1 ) ; } } ) ; } catch ( \ ErrorException $ e ) { throw new IoException ( $ e -> getMessage ( ) , 0 , $ e ) ; } if ( $ data === false ) { return '' ; } return $ data ; }
Reads a line from the stream .
16,649
public function lock ( bool $ exclusive ) : void { if ( $ this -> closed ) { throw new IoException ( 'The stream is closed.' ) ; } try { $ result = ErrorCatcher :: run ( function ( ) use ( $ exclusive ) { return flock ( $ this -> handle , $ exclusive ? LOCK_EX : LOCK_SH ) ; } ) ; } catch ( \ ErrorException $ e ) { throw new IoException ( $ e -> getMessage ( ) , 0 , $ e ) ; } if ( $ result === false ) { throw new IoException ( 'Failed to obtain a lock.' ) ; } }
Obtains an advisory lock .
16,650
public function unlock ( ) : void { if ( $ this -> closed ) { throw new IoException ( 'The stream is closed.' ) ; } try { $ result = ErrorCatcher :: run ( function ( ) { return flock ( $ this -> handle , LOCK_UN ) ; } ) ; } catch ( \ ErrorException $ e ) { throw new IoException ( $ e -> getMessage ( ) , 0 , $ e ) ; } if ( $ result === false ) { throw new IoException ( 'Failed to release the lock.' ) ; } }
Releases an advisory lock .
16,651
public function withScheme ( $ scheme ) { $ scheme = strtolower ( $ scheme ) ; $ pattern = new UriPattern ( ) ; if ( strlen ( $ scheme ) === 0 || $ pattern -> matchScheme ( $ scheme ) ) { return $ this -> with ( 'scheme' , $ scheme ) ; } throw new \ InvalidArgumentException ( "Invalid scheme '$scheme'" ) ; }
Returns a URI instance with the specified scheme .
16,652
public function withUserInfo ( $ user , $ password = null ) { $ username = rawurlencode ( $ user ) ; if ( strlen ( $ username ) > 0 ) { return $ this -> with ( 'userInfo' , $ this -> constructString ( [ '%s%s' => $ username , '%s:%s' => rawurlencode ( $ password ) , ] ) ) ; } return $ this -> with ( 'userInfo' , '' ) ; }
Returns a URI instance with the specified user information .
16,653
public function withHost ( $ host ) { $ pattern = new UriPattern ( ) ; if ( $ pattern -> matchHost ( $ host ) ) { return $ this -> with ( 'host' , $ this -> normalize ( strtolower ( $ host ) ) ) ; } throw new \ InvalidArgumentException ( "Invalid host '$host'" ) ; }
Returns a URI instance with the specified host .
16,654
public function withPort ( $ port ) { if ( $ port !== null ) { $ port = ( int ) $ port ; if ( max ( 0 , min ( 65535 , $ port ) ) !== $ port ) { throw new \ InvalidArgumentException ( "Invalid port number '$port'" ) ; } } return $ this -> with ( 'port' , $ port ) ; }
Returns a URI instance with the specified port .
16,655
private function with ( $ variable , $ value ) { if ( $ value === $ this -> $ variable ) { return $ this ; } $ uri = clone $ this ; $ uri -> $ variable = $ value ; return $ uri ; }
Returns an Uri instance with the given value .
16,656
private function encode ( $ string , $ extra = '' ) { $ pattern = sprintf ( '/[^0-9a-zA-Z%s]|%%(?![0-9A-F]{2})/' , preg_quote ( "%-._~!$&'()*+,;=" . $ extra , '/' ) ) ; return preg_replace_callback ( $ pattern , function ( $ match ) { return sprintf ( '%%%02X' , ord ( $ match [ 0 ] ) ) ; } , $ this -> normalize ( $ string ) ) ; }
Percent encodes the value without double encoding .
16,657
private function constructString ( array $ components ) { $ formats = array_keys ( $ components ) ; $ values = array_values ( $ components ) ; $ keys = array_keys ( array_filter ( $ values , 'strlen' ) ) ; return array_reduce ( $ keys , function ( $ string , $ key ) use ( $ formats , $ values ) { return sprintf ( $ formats [ $ key ] , $ string , $ values [ $ key ] ) ; } , '' ) ; }
Constructs the string from the non empty parts with specific formats .
16,658
private function getNormalizedUriPath ( ) { $ path = $ this -> getPath ( ) ; if ( $ this -> getAuthority ( ) === '' ) { return preg_replace ( '#^/+#' , '/' , $ path ) ; } elseif ( $ path === '' || $ path [ 0 ] === '/' ) { return $ path ; } return '/' . $ path ; }
Returns the path normalized for the string representation .
16,659
public function hGet ( $ hashKey , $ key ) { $ value = $ this -> redis -> hGet ( $ hashKey , $ key ) ; if ( $ value ) { $ value = gzinflate ( $ value ) ; } $ jsonData = json_decode ( $ value , true ) ; return ( $ jsonData === NULL ) ? $ value : $ jsonData ; }
get hash cache
16,660
public function hSet ( $ hashKey , $ key , $ data , $ expireTime = 3600 ) { $ data = ( is_object ( $ data ) || is_array ( $ data ) ) ? json_encode ( $ data ) : $ data ; $ data = gzdeflate ( $ data , 0 ) ; if ( strlen ( $ data ) > 4096 ) { $ data = gzdeflate ( $ data , 6 ) ; } $ status = $ this -> redis -> hSet ( $ hashKey , $ key , $ data ) ; $ this -> redis -> expire ( $ hashKey , $ expireTime ) ; return $ status ; }
set hash cache
16,661
public function header ( $ header , $ level = self :: HIGH ) { $ header = strtolower ( $ header ) ; if ( empty ( $ this -> headers [ $ header ] ) ) { return false ; } return self :: qFactor ( $ this -> headers [ $ header ] , $ level ) ; }
Parse any header like TE header or headers with Accepet - prefix
16,662
public static function qFactor ( $ value , $ level = self :: HIGH ) { $ multivalues = explode ( ',' , $ value ) ; $ headers = array ( ) ; foreach ( $ multivalues as $ hvalues ) { if ( substr_count ( $ hvalues , ';' ) > 1 ) { throw new Exception ( 'Header contains a value with multiple semicolons: "' . $ value . '"' , 2 ) ; } $ current = explode ( ';' , $ hvalues , 2 ) ; if ( empty ( $ current [ 1 ] ) ) { $ qvalue = 1.0 ; } else { $ qvalue = self :: parseQValue ( $ current [ 1 ] ) ; } $ headers [ trim ( $ current [ 0 ] ) ] = $ qvalue ; } $ multivalues = null ; if ( $ level === self :: ALL ) { return array_keys ( $ headers ) ; } if ( $ level === self :: LOW ) { asort ( $ headers , SORT_NUMERIC ) ; } else { arsort ( $ headers , SORT_NUMERIC ) ; } return $ headers ; }
Parse and sort a custom value with q - factor
16,663
public function joinCondition ( ) { if ( ! isset ( $ this -> _joinCondition ) ) { $ this -> _joinCondition = Factory :: filter ( $ this ) ; } return $ this -> _joinCondition ; }
The filter used for the ON clause of a JOIN
16,664
public static function portion ( $ path , $ init = 0 , $ end = 1024 , $ lines = false ) { self :: fullpath ( $ path ) ; if ( $ lines !== true ) { return file_get_contents ( $ path , false , null , $ init , $ end ) ; } $ i = 1 ; $ output = '' ; $ handle = fopen ( $ path , 'rb' ) ; while ( false === feof ( $ handle ) && $ i <= $ end ) { $ data = fgets ( $ handle ) ; if ( $ i >= $ init ) { $ output .= $ data ; } ++ $ i ; } fclose ( $ handle ) ; return $ output ; }
Read a script excerpt
16,665
public static function isBinary ( $ path ) { self :: fullpath ( $ path ) ; $ size = filesize ( $ path ) ; if ( $ size >= 0 && $ size < 2 ) { return false ; } $ finfo = finfo_open ( FILEINFO_MIME_ENCODING ) ; $ encode = finfo_buffer ( $ finfo , file_get_contents ( $ path , false , null , 0 , 5012 ) ) ; finfo_close ( $ finfo ) ; return strcasecmp ( $ encode , 'binary' ) === 0 ; }
Determines whether the file is binary
16,666
public static function size ( $ path ) { $ path = ltrim ( self :: fullpath ( $ path ) , '/' ) ; $ ch = curl_init ( 'file://' . $ path ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_HEADER , true ) ; curl_setopt ( $ ch , CURLOPT_NOBODY , true ) ; $ headers = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; $ ch = null ; if ( preg_match ( '#content-length:(\s+?|)(\d+)#i' , $ headers , $ matches ) ) { return $ matches [ 2 ] ; } return false ; }
Get file size support for read files with more of 2GB in 32bit . Return false if file is not found
16,667
public function get ( $ selector , \ DOMNode $ context = null , $ registerNodeNS = true ) { return $ this -> exec ( 'query' , $ selector , $ context , $ registerNodeNS ) ; }
Returns a \ DOMNodeList containing all nodes matching the given CSS selector
16,668
public function isRunning ( Datetime $ current = null ) { $ current = $ current ? : new Datetime ; return $ this -> hasStarted ( $ current ) && ! $ this -> hasEnded ( $ current ) ; }
Checks if this event is currently running
16,669
public function detach ( ) { $ this -> calendar -> getEvents ( ) -> removeEvent ( $ this ) ; $ this -> calendar = null ; return $ this ; }
Detach this event from the associated Calendar
16,670
public function validateCert ( $ certPem ) { if ( $ this -> getCaCert ( ) ) { self :: validate ( $ certPem , $ this -> getCaCert ( ) , $ this -> getCrl ( ) , $ this -> getCrlDistCert ( ) ) ; } }
Determine whether an X . 509 certificate is currently valid .
16,671
public function getCrlUrl ( ) { if ( $ this -> crlUrl === self :: AUTOLOAD ) { $ this -> crlUrl = NULL ; $ caCertObj = X509Util :: loadCACert ( $ this -> getCaCert ( ) ) ; $ crlDPs = $ caCertObj -> getExtension ( 'id-ce-cRLDistributionPoints' ) ; if ( is_array ( $ crlDPs ) ) { foreach ( $ crlDPs as $ crlDP ) { foreach ( $ crlDP [ 'distributionPoint' ] [ 'fullName' ] as $ fullName ) { if ( isset ( $ fullName [ 'uniformResourceIdentifier' ] ) ) { $ this -> crlUrl = $ fullName [ 'uniformResourceIdentifier' ] ; break 2 ; } } } } } return $ this -> crlUrl ; }
Determine the CRL URL which corresponds to this CA .
16,672
public function matchUri ( $ uri , & $ matches = [ ] ) { if ( $ this -> matchAbsoluteUri ( $ uri , $ matches ) ) { return true ; } return $ this -> matchRelativeUri ( $ uri , $ matches ) ; }
Matches the string against URI or relative - ref ABNF .
16,673
private function match ( $ pattern , $ subject , & $ matches ) { $ matches = [ ] ; $ subject = ( string ) $ subject ; if ( $ this -> allowNonAscii || preg_match ( '/^[\\x00-\\x7F]*$/' , $ subject ) ) { if ( preg_match ( $ pattern , $ subject , $ match ) ) { $ matches = $ this -> getNamedPatterns ( $ match ) ; return true ; } } return false ; }
Matches the subject against the pattern and provides the literal sub patterns .
16,674
private function getNamedPatterns ( $ matches ) { foreach ( $ matches as $ key => $ value ) { if ( ! is_string ( $ key ) || strlen ( $ value ) < 1 ) { unset ( $ matches [ $ key ] ) ; } } return $ matches ; }
Returns nonempty named sub patterns from the match set .
16,675
private static function buildPatterns ( ) { $ alpha = 'A-Za-z' ; $ digit = '0-9' ; $ hex = $ digit . 'A-Fa-f' ; $ unreserved = "$alpha$digit\\-._~" ; $ delimiters = "!$&'()*+,;=" ; $ utf8 = '\\x80-\\xFF' ; $ octet = "(?:[$digit]|[1-9][$digit]|1[$digit]{2}|2[0-4]$digit|25[0-5])" ; $ ipv4address = "(?>$octet\\.$octet\\.$octet\\.$octet)" ; $ encoded = "%[$hex]{2}" ; $ h16 = "[$hex]{1,4}" ; $ ls32 = "(?:$h16:$h16|$ipv4address)" ; $ data = "[$unreserved$delimiters:@$utf8]++|$encoded" ; $ scheme = "(?'scheme'(?>[$alpha][$alpha$digit+\\-.]*+))" ; $ ipv6address = "(?'IPv6address'" . "(?:(?:$h16:){6}$ls32)|" . "(?:::(?:$h16:){5}$ls32)|" . "(?:(?:$h16)?::(?:$h16:){4}$ls32)|" . "(?:(?:(?:$h16:){0,1}$h16)?::(?:$h16:){3}$ls32)|" . "(?:(?:(?:$h16:){0,2}$h16)?::(?:$h16:){2}$ls32)|" . "(?:(?:(?:$h16:){0,3}$h16)?::$h16:$ls32)|" . "(?:(?:(?:$h16:){0,4}$h16)?::$ls32)|" . "(?:(?:(?:$h16:){0,5}$h16)?::$h16)|" . "(?:(?:(?:$h16:){0,6}$h16)?::))" ; $ regularName = "(?'reg_name'(?>(?:[$unreserved$delimiters$utf8]++|$encoded)*))" ; $ ipvFuture = "(?'IPvFuture'v[$hex]++\\.[$unreserved$delimiters:]++)" ; $ ipLiteral = "(?'IP_literal'\\[(?>$ipv6address|$ipvFuture)\\])" ; $ port = "(?'port'(?>[$digit]*+))" ; $ host = "(?'host'$ipLiteral|(?'IPv4address'$ipv4address)|$regularName)" ; $ userInfo = "(?'userinfo'(?>(?:[$unreserved$delimiters:$utf8]++|$encoded)*))" ; $ authority = "(?'authority'(?:$userInfo@)?$host(?::$port)?)" ; $ segment = "(?>(?:$data)*)" ; $ segmentNotEmpty = "(?>(?:$data)+)" ; $ segmentNoScheme = "(?>([$unreserved$delimiters@$utf8]++|$encoded)+)" ; $ pathAbsoluteEmpty = "(?'path_abempty'(?:/$segment)*)" ; $ pathAbsolute = "(?'path_absolute'/(?:$segmentNotEmpty(?:/$segment)*)?)" ; $ pathNoScheme = "(?'path_noscheme'$segmentNoScheme(?:/$segment)*)" ; $ pathRootless = "(?'path_rootless'$segmentNotEmpty(?:/$segment)*)" ; $ pathEmpty = "(?'path_empty')" ; $ query = "(?'query'(?>(?:$data|[/?])*))" ; $ fragment = "(?'fragment'(?>(?:$data|[/?])*))" ; $ absolutePath = "(?'hier_part'//$authority$pathAbsoluteEmpty|$pathAbsolute|$pathRootless|$pathEmpty)" ; $ relativePath = "(?'relative_part'//$authority$pathAbsoluteEmpty|$pathAbsolute|$pathNoScheme|$pathEmpty)" ; self :: $ absoluteUri = "#^$scheme:$absolutePath(?:\\?$query)?(?:\\#$fragment)?$#" ; self :: $ relativeUri = "#^$relativePath(?:\\?$query)?(?:\\#$fragment)?$#" ; self :: $ scheme = "#^$scheme$#" ; self :: $ host = "#^$host$#" ; }
Builds the PCRE patterns according to the ABNF definitions .
16,676
public static function createDirectories ( string $ path , int $ mode = 0777 ) : void { $ exception = null ; try { $ success = ErrorCatcher :: run ( static function ( ) use ( $ path , $ mode ) { return mkdir ( $ path , $ mode , true ) ; } ) ; if ( $ success === true ) { return ; } } catch ( \ ErrorException $ e ) { $ exception = $ e ; } if ( self :: isDirectory ( $ path ) ) { return ; } throw new IoException ( 'Error creating directories ' . $ path , 0 , $ exception ) ; }
Creates a directory by creating all nonexistent parent directories first .
16,677
public static function isFile ( string $ path ) : bool { try { return ErrorCatcher :: run ( static function ( ) use ( $ path ) { return is_file ( $ path ) ; } ) ; } catch ( \ ErrorException $ e ) { throw new IoException ( 'Error checking if ' . $ path . ' is a file' , 0 , $ e ) ; } }
Checks whether the path points to a regular file .
16,678
public static function isDirectory ( string $ path ) : bool { try { return ErrorCatcher :: run ( static function ( ) use ( $ path ) { return is_dir ( $ path ) ; } ) ; } catch ( \ ErrorException $ e ) { throw new IoException ( 'Error checking if ' . $ path . ' is a directory' , 0 , $ e ) ; } }
Checks whether the path points to a directory .
16,679
public static function isSymbolicLink ( string $ path ) : bool { try { return ErrorCatcher :: run ( static function ( ) use ( $ path ) { return is_link ( $ path ) ; } ) ; } catch ( \ ErrorException $ e ) { throw new IoException ( 'Error checking if ' . $ path . ' is a symbolic link' , 0 , $ e ) ; } }
Checks whether the path points to a symbolic link .
16,680
public static function createSymbolicLink ( string $ link , string $ target ) : void { $ exception = null ; try { $ success = ErrorCatcher :: run ( static function ( ) use ( $ link , $ target ) { return symlink ( $ target , $ link ) ; } ) ; if ( $ success === true ) { return ; } } catch ( \ ErrorException $ e ) { $ exception = $ e ; } throw new IoException ( 'Error creating symbolic link ' . $ link . ' to ' . $ target , 0 , $ exception ) ; }
Creates a symbolic link to a target .
16,681
public static function readSymbolicLink ( string $ path ) : string { $ exception = null ; try { $ result = ErrorCatcher :: run ( static function ( ) use ( $ path ) { return readlink ( $ path ) ; } ) ; if ( $ result !== false ) { return $ result ; } } catch ( \ ErrorException $ e ) { $ exception = $ e ; } throw new IoException ( 'Error reading symbolic link ' . $ path , 0 , $ exception ) ; }
Returns the target of a symbolic link .
16,682
public static function getRealPath ( string $ path ) : string { $ exception = null ; try { $ result = ErrorCatcher :: run ( static function ( ) use ( $ path ) { return realpath ( $ path ) ; } ) ; if ( $ result !== false ) { return $ result ; } } catch ( \ ErrorException $ e ) { $ exception = $ e ; } throw new IoException ( 'Error getting real path of ' . $ path . ', check that the path exists' , 0 , $ exception ) ; }
Returns the canonicalized absolute pathname .
16,683
public static function write ( string $ path , $ data , bool $ append = false , bool $ lock = false ) : int { $ flags = 0 ; if ( $ append ) { $ flags |= FILE_APPEND ; } if ( $ lock ) { $ flags |= LOCK_EX ; } $ exception = null ; try { $ result = ErrorCatcher :: run ( static function ( ) use ( $ path , $ data , $ flags ) { return file_put_contents ( $ path , $ data , $ flags ) ; } ) ; if ( $ result !== false ) { return $ result ; } } catch ( \ ErrorException $ e ) { $ exception = $ e ; } throw new IoException ( 'Error writing to ' . $ path , 0 , $ exception ) ; }
Writes data to a file .
16,684
public static function read ( string $ path , int $ offset = 0 , int $ maxLength = null ) : string { $ exception = null ; try { $ result = ErrorCatcher :: run ( static function ( ) use ( $ path , $ offset , $ maxLength ) { if ( $ maxLength === null ) { return file_get_contents ( $ path , false , null , $ offset ) ; } return file_get_contents ( $ path , false , null , $ offset , $ maxLength ) ; } ) ; if ( $ result !== false ) { return $ result ; } } catch ( \ ErrorException $ e ) { $ exception = $ e ; } throw new IoException ( 'Error reading from ' . $ path , 0 , $ exception ) ; }
Reads data from a file .
16,685
public function getInfo ( int $ opt = null ) { if ( $ opt === null ) { return curl_getinfo ( $ this -> curl ) ; } return curl_getinfo ( $ this -> curl , $ opt ) ; }
Returns information about the last transfer .
16,686
public function parse ( $ uri ) { if ( ! $ this -> isValidString ( $ uri ) ) { return null ; } $ pattern = new UriPattern ( ) ; $ pattern -> allowNonAscii ( $ this -> mode !== self :: MODE_RFC3986 ) ; if ( $ pattern -> matchUri ( $ uri , $ match ) ) { try { return $ this -> buildUri ( $ match ) ; } catch ( \ InvalidArgumentException $ exception ) { return null ; } } return null ; }
Parses the URL using the generic URI syntax .
16,687
private function isValidString ( $ uri ) { if ( preg_match ( '/^[\\x00-\\x7F]*$/' , $ uri ) ) { return true ; } elseif ( $ this -> mode === self :: MODE_RFC3986 ) { return false ; } $ pattern = '/^(?> [\x00-\x7F]+ # ASCII | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding over longs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 )*$/x' ; return ( bool ) preg_match ( $ pattern , $ uri ) ; }
Tells if the URI string is valid for the current parser mode .
16,688
private function buildUri ( array $ components ) { $ uri = new Uri ( ) ; if ( isset ( $ components [ 'reg_name' ] ) ) { $ components [ 'host' ] = $ this -> decodeHost ( $ components [ 'host' ] ) ; } foreach ( array_intersect_key ( self :: $ setters , $ components ) as $ key => $ method ) { $ uri = call_user_func ( [ $ uri , $ method ] , $ components [ $ key ] ) ; } if ( isset ( $ components [ 'userinfo' ] ) ) { list ( $ username , $ password ) = preg_split ( '/:|$/' , $ components [ 'userinfo' ] , 2 ) ; $ uri = $ uri -> withUserInfo ( rawurldecode ( $ username ) , rawurldecode ( $ password ) ) ; } return $ uri ; }
Builds the Uri instance from the parsed components .
16,689
private function decodeHost ( $ hostname ) { if ( preg_match ( '/^[\\x00-\\x7F]*$/' , $ hostname ) ) { return $ hostname ; } elseif ( $ this -> mode !== self :: MODE_IDNA2003 ) { throw new \ InvalidArgumentException ( "Invalid hostname '$hostname'" ) ; } $ hostname = idn_to_ascii ( $ hostname ) ; if ( $ hostname === false ) { throw new \ InvalidArgumentException ( "Invalid hostname '$hostname'" ) ; } return $ hostname ; }
Decodes the hostname component according to parser mode .
16,690
public static function env ( $ key , $ value = null ) { if ( is_string ( $ value ) || is_bool ( $ value ) || is_numeric ( $ value ) ) { self :: $ configs [ $ key ] = $ value ; } elseif ( $ value === null && isset ( self :: $ configs [ $ key ] ) ) { return self :: $ configs [ $ key ] ; } }
Set or get environment value
16,691
public static function config ( $ path ) { $ data = \ UtilsSandboxLoader ( 'application/Config/' . strtr ( $ path , '.' , '/' ) . '.php' ) ; foreach ( $ data as $ key => $ value ) { self :: env ( $ key , $ value ) ; } $ data = null ; }
Set environment variables by config files
16,692
public static function trigger ( $ name , array $ args = array ( ) ) { if ( $ name === 'error' ) { self :: $ state = 5 ; } if ( empty ( self :: $ events [ $ name ] ) ) { return null ; } $ listen = self :: $ events [ $ name ] ; usort ( $ listen , function ( $ a , $ b ) { return $ b [ 1 ] >= $ a [ 1 ] ; } ) ; foreach ( $ listen as $ callback ) { call_user_func_array ( $ callback [ 0 ] , $ args ) ; } $ listen = null ; }
Trigger registered event
16,693
public static function off ( $ name , $ callback = null ) { if ( empty ( self :: $ events [ $ name ] ) ) { return null ; } elseif ( $ callback === null ) { self :: $ events [ $ name ] = array ( ) ; return null ; } $ evts = self :: $ events [ $ name ] ; foreach ( $ evts as $ key => $ value ) { if ( $ value [ 0 ] === $ callback ) { unset ( $ evts [ $ key ] ) ; } } self :: $ events [ $ name ] = $ evts ; $ evts = null ; }
Unregister 1 or all events
16,694
public static function stop ( $ code , $ msg = null ) { Response :: status ( $ code , false ) && self :: trigger ( 'changestatus' , array ( $ code , $ msg ) ) ; if ( self :: $ state < 4 ) { self :: $ state = 4 ; self :: trigger ( 'finish' ) ; } exit ; }
Stop application send HTTP status
16,695
public static function exec ( ) { if ( self :: $ state > 0 ) { return null ; } self :: $ state = 1 ; self :: trigger ( 'init' ) ; if ( self :: env ( 'maintenance' ) ) { self :: $ state = 4 ; self :: stop ( 503 ) ; } self :: trigger ( 'changestatus' , array ( \ UtilsStatusCode ( ) , null ) ) ; $ resp = Route :: get ( ) ; if ( is_integer ( $ resp ) ) { self :: $ state = 5 ; self :: stop ( $ resp , 'Invalid route' ) ; } $ callback = $ resp [ 'callback' ] ; if ( ! $ callback instanceof \ Closure ) { $ parsed = explode ( ':' , $ callback , 2 ) ; $ callback = '\\Controller\\' . strtr ( $ parsed [ 0 ] , '.' , '\\' ) ; $ callback = array ( new $ callback , $ parsed [ 1 ] ) ; } $ output = call_user_func_array ( $ callback , $ resp [ 'args' ] ) ; if ( class_exists ( '\\Inphinit\\Http\\Response' , false ) ) { Response :: dispatch ( ) ; } if ( class_exists ( '\\Inphinit\\Viewing\\View' , false ) ) { View :: dispatch ( ) ; } if ( self :: $ state < 2 ) { self :: $ state = 2 ; } self :: trigger ( 'ready' ) ; if ( $ output || is_numeric ( $ output ) ) { echo $ output ; } if ( self :: $ state < 3 ) { self :: $ state = 3 ; } self :: trigger ( 'finish' ) ; if ( self :: $ state < 4 ) { self :: $ state = 4 ; } }
Start application using routes
16,696
public function swap ( int $ index1 , int $ index2 ) : void { if ( $ index1 !== $ index2 ) { $ value = $ this [ $ index1 ] ; $ this [ $ index1 ] = $ this [ $ index2 ] ; $ this [ $ index2 ] = $ value ; } }
Swaps two entries in this FixedArray .
16,697
public function shiftUp ( int $ index ) : void { if ( $ index + 1 === $ this -> count ( ) ) { return ; } $ this -> swap ( $ index , $ index + 1 ) ; }
Shifts an entry to the next index .
16,698
public function shiftTo ( int $ index , int $ newIndex ) : void { while ( $ index > $ newIndex ) { $ this -> shiftDown ( $ index ) ; $ index -- ; } while ( $ index < $ newIndex ) { $ this -> shiftUp ( $ index ) ; $ index ++ ; } }
Shifts an entry to an arbitrary index shifting all the entries between those indexes .
16,699
public function padStringFilter ( $ value , $ padCharacter , $ maxLength , $ padType = 'STR_PAD_RIGHT' ) { if ( $ this -> isNullOrEmptyString ( $ padCharacter ) ) { throw new \ InvalidArgumentException ( 'Pad String Filter cannot accept a null value or empty string as its first argument' ) ; } if ( ! is_int ( $ maxLength ) ) { throw new \ InvalidArgumentException ( 'Pad String Filter expects its second argument to be an integer' ) ; } $ diff = ( function_exists ( 'mb_strlen' ) ) ? strlen ( $ value ) - mb_strlen ( $ value ) : 0 ; $ padType = constant ( $ padType ) ; return str_pad ( $ value , $ maxLength + $ diff , $ padCharacter , $ padType ) ; }
Pads string on right or left with given padCharacter until string reaches maxLength