idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
16,500
public static function combo ( $ name , array $ options , $ value = null , array $ attributes = array ( ) ) { $ input = self :: setAttr ( $ attributes , '<select{{attr}}>' , $ name , 'select' ) ; foreach ( $ options as $ key => $ val ) { $ input .= '<option value="' . self :: entities ( $ val ) . '"' ; if ( $ value === $ val ) { $ input .= ' selected' ; } $ input .= '>' . $ key . '</option>' ; } return $ input . '</select>' ; }
Create a select combo based in an array
16,501
public static function input ( $ type , $ name , $ value = null , array $ attributes = array ( ) ) { if ( $ type === 'textarea' ) { $ input = '<textarea{{attr}}>' ; if ( $ value !== null ) { $ input .= self :: entities ( $ value ) ; } $ input .= '</textarea>' ; } elseif ( preg_match ( '#^(' . self :: $ alloweds . ')$#' , $ type ) ) { $ input = '<input type="' . $ type . '" value="' ; if ( $ value !== null ) { $ input .= self :: entities ( $ value ) ; } $ input .= '"{{attr}}' . self :: $ useXhtml . '>' ; } else { throw new Exception ( 'Invalid type' ) ; } return self :: setAttr ( $ attributes , $ input , $ name , $ type ) ; }
Create a input or textarea
16,502
private static function setAttr ( array $ attributes , $ field , $ name , $ type ) { $ attrs = '' ; if ( in_array ( $ type , array_keys ( self :: $ preAttrs ) ) ) { $ attributes = self :: $ preAttrs [ $ type ] + $ attributes ; } if ( $ name !== null ) { $ attributes = array ( 'name' => $ name ) + $ attributes ; } if ( $ type !== 'select' && $ type !== 'textarea' && $ type !== 'form' ) { $ attributes = array ( 'type' => $ type ) + $ attributes ; } foreach ( $ attributes as $ key => $ val ) { $ attrs .= ' ' . $ key . '="' . self :: entities ( $ val ) . '"' ; } return str_replace ( '{{attr}}' , $ attrs , $ field ) ; }
set attributes in an element
16,503
protected static function isCallbackPattern ( $ patternKey ) { $ patternKeyPrefix = self :: getPatternKeyPrefix ( $ patternKey ) ; $ patternPrefixesOptions = self :: getFunctionalPatternPrefixesOptions ( ) ; return ArrayHelper :: keyExists ( $ patternKeyPrefix , $ patternPrefixesOptions ) ; }
Returns true if its functional pattern key that need to run callback function .
16,504
public static function replace ( $ patternString , $ model ) { $ replacedString = '' ; $ patterns = self :: findPatterns ( $ patternString ) ; $ replacements = [ ] ; foreach ( $ patterns as $ patternKey ) { if ( self :: isCallbackPattern ( $ patternKey ) ) { $ replacement = self :: callbackRetrievedStaticFunction ( $ patternKey , $ model ) ; } if ( self :: isSeparatorPattern ( $ patternKey ) ) { $ replacement = self :: retrieveSeparator ( ) ; } if ( isset ( $ replacement ) ) { $ patternKey = self :: addPatternDelimeter ( $ patternKey ) ; $ replacements [ $ patternKey ] = $ replacement ; } unset ( $ replacement ) ; } $ replacedString = ( is_array ( $ replacements ) && $ replacements !== [ ] ) ? str_replace ( array_keys ( $ replacements ) , array_values ( $ replacements ) , $ patternString ) : $ patternString ; $ replacedString = self :: sanitizeReplacedString ( $ replacedString ) ; return $ replacedString ; }
Function that replace patterns with theirs values .
16,505
protected static function findPatterns ( $ patternString ) { $ patternString = self :: sanitizePatternString ( $ patternString ) ; $ patternRegExp = self :: getPatternRegExp ( ) ; return ( preg_match_all ( $ patternRegExp , $ patternString , $ patternsMatches ) ) ? $ patternsMatches [ 1 ] : [ ] ; }
Returns array with patterns finded in string .
16,506
protected static function callbackRetrievedStaticFunction ( $ patternKey , $ model ) { $ patternPrefixesOptions = self :: getFunctionalPatternPrefixesOptions ( ) ; $ patternKeyPrefix = self :: getPatternKeyPrefix ( $ patternKey ) ; $ patternKeyValue = self :: getPatternKeyValue ( $ patternKey ) ; $ patternPrefixFunctionName = ArrayHelper :: getValue ( $ patternPrefixesOptions , $ patternKeyPrefix ) ; if ( ! method_exists ( __CLASS__ , $ patternPrefixFunctionName ) ) { throw new InvalidConfigException ( '"' . __CLASS__ . '" does not exist function with name "' . $ patternPrefixFunctionName . '"' ) ; } return call_user_func ( [ __CLASS__ , $ patternPrefixFunctionName ] , $ patternKeyValue , $ model ) ; }
Callback retrieved function based on callback pattern key prefix .
16,507
public static function retrieveAppConfigValue ( $ patternKeyValue , $ model ) { return ( property_exists ( Yii :: $ app , $ patternKeyValue ) || Yii :: $ app -> canGetProperty ( $ patternKeyValue ) ) ? Yii :: $ app -> { $ patternKeyValue } : '' ; }
Returns application global config value compared with pattern key .
16,508
public static function retrieveViewParamValue ( $ patternKeyValue , $ model ) { return ArrayHelper :: getValue ( Yii :: $ app -> view -> params , $ patternKeyValue ) ; }
Returns view parameter value compared with pattern key .
16,509
public static function retrieveSeparator ( ) { $ separatorViewParamKey = self :: SEPARATOR_VIEW_PARAMETER_KEY ; return ( ArrayHelper :: keyExists ( $ separatorViewParamKey , Yii :: $ app -> view -> params ) ) ? Yii :: $ app -> view -> params [ $ separatorViewParamKey ] : self :: SEPARATOR_DEFAULT ; }
Returns separator . If yii parameters don t have parameter with such key returns empty string . If yii parameters don t have parameter with such key returns empty string .
16,510
public function getStandardPort ( ) { $ scheme = $ this -> getScheme ( ) ; if ( isset ( self :: $ standardPorts [ $ scheme ] ) ) { return self :: $ standardPorts [ $ scheme ] ; } return null ; }
Returns the standard port for the current scheme .
16,511
public function getUsername ( ) { $ info = $ this -> getUserInfo ( ) ; $ username = strstr ( $ info , ':' , true ) ; return rawurldecode ( $ username === false ? $ info : $ username ) ; }
Returns the decoded username from the URI .
16,512
public function getPassword ( ) { $ password = strstr ( $ this -> getUserInfo ( ) , ':' ) ; return $ password === false ? '' : rawurldecode ( substr ( $ password , 1 ) ) ; }
Returns the decoded password from the URI .
16,513
public function getIpAddress ( ) { $ pattern = new UriPattern ( ) ; $ pattern -> matchHost ( $ this -> getHost ( ) , $ match ) ; if ( isset ( $ match [ 'IPv4address' ] ) ) { return $ match [ 'IPv4address' ] ; } elseif ( isset ( $ match [ 'IP_literal' ] ) ) { return preg_replace ( '/^\\[(v[^.]+\\.)?([^\\]]+)\\]$/' , '$2' , $ match [ 'IP_literal' ] ) ; } return null ; }
Returns the IP address from the host component .
16,514
public function getTopLevelDomain ( ) { if ( $ this -> getIpAddress ( ) !== null ) { return '' ; } $ host = rawurldecode ( $ this -> getHost ( ) ) ; $ tld = strrchr ( $ host , '.' ) ; if ( $ tld === '.' ) { $ host = substr ( $ host , 0 , - 1 ) ; $ tld = strrchr ( $ host , '.' ) ; } return $ tld === false ? $ host : substr ( $ tld , 1 ) ; }
Returns the top level domain from the host component .
16,515
public function getPathExtension ( ) { $ segments = $ this -> getPathSegments ( ) ; $ filename = array_pop ( $ segments ) ; $ extension = strrchr ( $ filename , '.' ) ; if ( $ extension === false ) { return '' ; } return substr ( $ extension , 1 ) ; }
Returns the file extension for the last segment in the path .
16,516
final public function getName ( ) : string { try { $ reflexionConstant = new ReflectionClassConstant ( $ this , 'NAME' ) ; $ this -> name = $ reflexionConstant -> getValue ( ) ; } catch ( Exception $ e ) { } return $ this -> name ; }
Returns the theme name .
16,517
final public function getDescription ( ) : string { try { $ reflexionConstant = new ReflectionClassConstant ( $ this , 'DESCRIPTION' ) ; $ this -> description = $ reflexionConstant -> getValue ( ) ; } catch ( Exception $ e ) { } return $ this -> description ; }
Returns the theme description .
16,518
public function getPreview ( ) : ? string { $ array = glob ( $ this -> getPath ( ) . '/assets/images/preview.{jpg,jpeg,png,gif}' , GLOB_BRACE ) ; if ( isset ( $ array [ 0 ] ) ) { return sprintf ( '/themes/%s/images/%s' , $ this -> shortName , ( new SplFileInfo ( $ array [ 0 ] ) ) -> getBasename ( ) ) ; } return null ; }
Returns the theme preview image .
16,519
public function doPathValidate ( string $ pathValue = null , $ isWritable = true ) { if ( $ pathValue != null ) { if ( ! is_dir ( $ pathValue ) ) { throw new ConfigSettingFailException ( "`{$pathValue}` does NOT existed" , '400' ) ; } if ( $ isWritable == true ) { if ( ! is_writable ( $ pathValue ) ) { throw new ConfigSettingFailException ( "`{$pathValue}`is NOT writable" , '400' ) ; } } } }
to do validate config params .
16,520
public static function encodepath ( $ text , $ type = null ) { $ text = preg_replace ( '#[`\'"\^~{}\[\]()]#' , '' , $ text ) ; $ text = preg_replace ( '#[\n\s\/\p{P}]#u' , '-' , $ text ) ; if ( $ type === self :: UNICODE ) { $ text = preg_replace ( '#[^\d\p{L}\p{N}\-]#u' , '' , $ text ) ; } elseif ( $ type === self :: ASCII ) { $ text = preg_replace ( '#[^\d\p{L}\-]#u' , '' , $ text ) ; $ text = self :: encodepath ( $ text ) ; } else { $ text = Helper :: toAscii ( $ text ) ; $ text = preg_replace ( '#[^a-z\d\-]#i' , '' , $ text ) ; } return trim ( preg_replace ( '#--+#' , '-' , $ text ) , '-' ) ; }
Convert text to URL format
16,521
public static function normalize ( $ url ) { $ u = parse_url ( preg_replace ( '#^file:/+([a-z]+:)#i' , '$1' , $ url ) ) ; if ( $ u === false ) { return $ url ; } if ( empty ( $ u [ 'scheme' ] ) ) { $ u = null ; return false ; } $ scheme = strtolower ( $ u [ 'scheme' ] ) ; if ( strlen ( $ scheme ) > 1 ) { $ normalized = $ scheme . '://' ; } else { $ normalized = strtoupper ( $ scheme ) . ':' ; } if ( isset ( $ u [ 'user' ] ) ) { $ normalized .= $ u [ 'user' ] ; $ normalized .= isset ( $ u [ 'pass' ] ) ? ( ':' . $ u [ 'pass' ] ) : '' ; $ normalized .= '@' ; } if ( isset ( $ u [ 'host' ] ) ) { if ( in_array ( $ scheme , static :: $ defaultSchemes ) ) { $ host = urldecode ( $ u [ 'host' ] ) ; $ normalized .= mb_strtolower ( $ host , mb_detect_encoding ( $ host ) ) ; } else { $ normalized .= $ u [ 'host' ] ; } } if ( isset ( $ u [ 'port' ] ) && ! in_array ( $ scheme . ':' . $ u [ 'port' ] , static :: $ defaultPorts ) ) { $ normalized .= ':' . $ u [ 'port' ] ; } if ( empty ( $ u [ 'path' ] ) || $ u [ 'path' ] === '/' ) { $ normalized .= '/' ; } else { $ normalized .= '/' . ltrim ( self :: canonpath ( $ u [ 'path' ] ) , '/' ) ; } if ( isset ( $ u [ 'query' ] ) ) { $ normalized .= self :: canonquery ( $ u [ 'query' ] , '?' ) ; } if ( isset ( $ u [ 'fragment' ] ) ) { $ normalized .= '#' . $ u [ 'fragment' ] ; } $ u = null ; return $ normalized ; }
Normalize URL include canonicalized path
16,522
public function start ( $ type ) { if ( $ this -> enabled ) { $ this -> start = microtime ( true ) ; $ this -> hydrations [ ++ $ this -> currentHydration ] [ 'type' ] = $ type ; } }
Marks a hydration as started . Timing is started
16,523
public function stop ( $ resultNum , $ aliasMap ) { if ( $ this -> enabled ) { $ this -> hydrations [ $ this -> currentHydration ] [ 'executionMS' ] = microtime ( true ) - $ this -> start ; $ this -> hydrations [ $ this -> currentHydration ] [ 'resultNum' ] = $ resultNum ; $ this -> hydrations [ $ this -> currentHydration ] [ 'aliasMap' ] = $ aliasMap ; } }
Marks a hydration as stopped . Number of hydrated entities and alias map is passed to method .
16,524
public function getRuntime ( int $ precision = 10 ) { if ( $ this -> startTime == $ this :: NOT_INITIALIZED || $ this -> endTime == $ this :: NOT_INITIALIZED ) { return FALSE ; } $ runTime = round ( $ this -> endTime - $ this -> startTime , $ precision ) ; return $ runTime ; }
to get the runtime .
16,525
private function checkNow ( string $ storeVarName ) : bool { $ now = $ this -> microtimeFloat ( ) ; $ this -> { $ storeVarName } = $ now ; return true ; }
to set the current micro time .
16,526
protected function _renderFunc ( Func $ func ) { if ( $ func -> getName ( ) != 'CONCAT' ) return parent :: _renderFunc ( $ func ) ; $ args = $ func -> getArgs ( ) ; array_walk ( $ args , function ( & $ arg ) { $ arg = $ this -> _renderValue ( $ arg ) ; } ) ; return implode ( ' + ' , $ args ) ; }
Override in order to get the string concatenation right
16,527
public function formatData ( string $ interface , string $ version , string $ method , array $ params ) : array { return [ 'interface' => $ interface , 'version' => $ version , 'method' => $ method , 'params' => $ params , 'logid' => RequestContext :: getLogid ( ) , 'spanid' => RequestContext :: getSpanid ( ) + 1 , ] ; }
Format the data for packer
16,528
final public function getNamespace ( ) : string { if ( null === $ this -> namespace ) { $ pos = strrpos ( static :: class , '\\' ) ; $ this -> namespace = false === $ pos ? '' : substr ( static :: class , 0 , $ pos ) ; } return $ this -> namespace ; }
Gets the Extension namespace .
16,529
public function getContainerExtension ( ) : ? ExtensionInterface { if ( null === $ this -> extension ) { $ extension = $ this -> createContainerExtension ( ) ; if ( null !== $ extension ) { if ( ! $ extension instanceof ExtensionInterface ) { throw new \ LogicException ( sprintf ( 'Extension %s must implement Symfony\Component\DependencyInjection\Extension\ExtensionInterface.' , \ get_class ( $ extension ) ) ) ; } $ basename = str_replace ( [ 'Component' , 'Module' , 'Plugin' ] , [ '' , '' , '' ] , $ this -> getIdentifier ( ) ) ; $ expectedAlias = Container :: underscore ( $ basename ) ; if ( $ expectedAlias != $ extension -> getAlias ( ) ) { throw new \ LogicException ( sprintf ( 'Users will expect the alias of the default extension of a bundle to be the underscored version of the bundle name ("%s"). You can override "Bundle::getContainerExtension()" if you want to use "%s" or another alias.' , $ expectedAlias , $ extension -> getAlias ( ) ) ) ; } $ this -> extension = $ extension ; } } return $ this -> extension ; }
Returns the container extension that should be implicitly loaded .
16,530
public static function only ( $ path , $ code = 302 , $ trigger = true ) { self :: $ debuglvl = 3 ; self :: to ( $ path , $ code , $ trigger ) ; Response :: dispatch ( ) ; exit ; }
Redirect and stop application execution
16,531
public static function to ( $ path , $ code = 302 , $ trigger = true ) { $ debuglvl = self :: $ debuglvl ; self :: $ debuglvl = 2 ; if ( headers_sent ( ) ) { throw new Exception ( 'Headers already sent' , $ debuglvl ) ; } elseif ( $ code < 300 || $ code > 399 ) { throw new Exception ( 'Invalid redirect HTTP status' , $ debuglvl ) ; } elseif ( empty ( $ path ) ) { throw new Exception ( 'Path is not defined' , $ debuglvl ) ; } elseif ( strpos ( $ path , '/' ) === 0 ) { $ path = Uri :: root ( $ path ) ; } Response :: status ( $ code , $ trigger ) ; Response :: putHeader ( 'Location' , $ path ) ; }
Redirects to a valid path within the application
16,532
public static function back ( $ only = false , $ trigger = true ) { $ referer = Request :: header ( 'referer' ) ; if ( $ referer === false ) { return false ; } self :: $ debuglvl = 3 ; if ( $ only ) { static :: only ( $ referer , 302 , $ trigger ) ; } else { static :: to ( $ referer , 302 , $ trigger ) ; } }
Return to redirect to new path
16,533
public function domain ( $ domain ) { if ( empty ( $ domain ) || trim ( $ domain ) !== $ domain ) { throw new Exception ( 'Invalid domain "' . $ domain . '"' , 2 ) ; } else { $ this -> domain = $ domain ; } return $ this ; }
Define domain for group
16,534
public function path ( $ path ) { if ( $ path !== '/' . trim ( $ path , '/' ) . '/' ) { throw new Exception ( 'Invalid path "' . $ path . '", use like this /foo/' , 2 ) ; } $ this -> path = $ path ; return $ this ; }
Define path for group
16,535
public function secure ( $ level ) { if ( $ level < 1 || $ level > 3 ) { throw new Exception ( 'Invalid security level' , 2 ) ; } $ this -> levelSecure = ( int ) $ level ; return $ this ; }
Access only with HTTPS or only HTTP or both
16,536
public function then ( \ Closure $ callback ) { if ( $ this -> ready ) { return null ; } $ this -> ready = true ; if ( ! $ this -> checkDomain ( ) || ! $ this -> checkPath ( ) || ! $ this -> checkSecurity ( ) ) { return null ; } $ oNS = parent :: $ prefixNS ; $ oPP = parent :: $ prefixPath ; if ( $ this -> ns ) { parent :: $ prefixNS = $ this -> ns ; } if ( $ this -> path ) { parent :: $ prefixPath = rtrim ( $ this -> currentPrefixPath , '/' ) ; } call_user_func_array ( $ callback , $ this -> arguments ) ; parent :: $ prefixNS = $ oNS ; parent :: $ prefixPath = $ oPP ; }
Define callback for group this callback is executed if the request meets the group settings
16,537
protected function checkSecurity ( ) { if ( ! $ this -> levelSecure || $ this -> levelSecure === self :: BOTH ) { return true ; } $ secure = Request :: is ( 'secure' ) ; return ( $ this -> levelSecure === self :: SECURE && $ secure ) || ( $ this -> levelSecure === self :: NONSECURE && ! $ secure ) ; }
Method is used for check if HTTPS or HTTP or both
16,538
protected function checkDomain ( ) { if ( $ this -> domain === null ) { return true ; } if ( self :: $ cachehost !== null ) { $ host = self :: $ cachehost ; } else { $ fhost = Request :: header ( 'Host' ) ; $ host = strstr ( $ fhost , ':' , true ) ; $ host = $ host ? $ host : $ fhost ; self :: $ cachehost = $ host ; } if ( $ host === $ this -> domain ) { return true ; } elseif ( $ host ) { $ re = Regex :: parse ( $ this -> domain ) ; if ( $ re === false || preg_match ( '#^' . $ re . '$#' , $ host , $ matches ) === 0 ) { return false ; } array_shift ( $ matches ) ; $ this -> arguments = array_merge ( $ this -> arguments , $ matches ) ; return true ; } return false ; }
Method is used for check domain and return arguments if using regex
16,539
protected function checkPath ( ) { if ( $ this -> path === null ) { return true ; } $ pathinfo = \ UtilsPath ( ) ; if ( strpos ( $ pathinfo , $ this -> path ) === 0 ) { $ this -> currentPrefixPath = $ this -> path ; return true ; } else { $ re = Regex :: parse ( $ this -> path ) ; if ( $ re !== false && preg_match ( '#^' . $ re . '#' , $ pathinfo , $ matches ) ) { $ this -> currentPrefixPath = $ matches [ 0 ] ; array_shift ( $ matches ) ; $ this -> arguments = array_merge ( $ this -> arguments , $ matches ) ; return true ; } } return false ; }
Method is used for check path
16,540
public function getProperty ( $ name ) { if ( isset ( $ this -> $ name ) ) { return $ this -> $ name ; } if ( isset ( static :: $ name ) ) { return static :: $ name ; } return null ; }
fetch current property value
16,541
private function underlineToUppercase ( $ str ) { $ fnc = function ( $ matches ) { return strtoupper ( $ matches [ 1 ] ) ; } ; $ str = preg_replace_callback ( '/_+([a-z])/' , $ fnc , $ str ) ; return $ str ; }
Underline to uppercase
16,542
private function handleCtrlResult ( $ ret ) { if ( $ ret === null ) { return ; } register_shutdown_function ( "closeResources" ) ; if ( isset ( $ _GET [ 'format' ] ) && $ _GET [ 'format' ] == 'xml' ) { header ( 'Content-type: application/xml; charset=utf-8' ) ; $ ret = ( object ) $ ret ; echo $ this -> objectToXml ( $ ret ) ; die ; } header ( 'Content-type: application/json; charset=utf-8' ) ; echo json_encode ( $ ret ) ; die ; }
Handle controller s result
16,543
private function initialize ( ) { $ this -> undefinedCardResolution = isset ( $ this -> config [ 'options' ] [ 'undefined_card' ] ) ? static :: translateUndefinedCardResolution ( $ this -> config [ 'options' ] [ 'undefined_card' ] ) : UndefinedCardResolution :: DEFAULT_CARD ; if ( isset ( $ this -> config [ 'options' ] [ 'delimiter' ] ) ) { $ this -> delimiter = $ this -> config [ 'options' ] [ 'delimiter' ] ; } foreach ( $ this -> config [ 'slots' ] as $ slotName => & $ slotData ) { $ slotData [ 'name' ] = $ slotName ; if ( is_string ( $ slotData [ 'reel' ] ) ) { $ slotData [ 'reel' ] = $ this -> config [ 'reels' ] [ $ slotData [ 'reel' ] ] ; } if ( ! isset ( $ slotData [ 'nested' ] ) ) { $ slotData [ 'nested' ] = array ( ) ; } $ slotData [ 'undefined_card' ] = ( ! isset ( $ slotData [ 'undefined_card' ] ) ) ? $ this -> undefinedCardResolution : static :: translateUndefinedCardResolution ( $ slotData [ 'undefined_card' ] ) ; $ this -> offsetSet ( $ slotName , function ( ) use ( $ slotData ) { return new Slot ( $ slotData ) ; } ) ; } }
Set up the SlotMachine in a ready to use state
16,544
public static function interpolate ( $ card , array $ nestedCards = array ( ) , array $ delimiter = array ( '{' , '}' ) ) { if ( 2 > $ tokens = count ( $ delimiter ) ) { throw new \ LengthException ( 'Number of delimiter tokens too short. Method requires exactly 2.' ) ; } if ( $ tokens > 2 ) { trigger_error ( 'Too many delimiter tokens given' , E_USER_WARNING ) ; } $ replace = array ( ) ; foreach ( $ nestedCards as $ slot => $ nestedCard ) { $ replace [ $ delimiter [ 0 ] . $ slot . $ delimiter [ 1 ] ] = $ nestedCard ; } return strtr ( $ card , $ replace ) ; }
Interpolates cards values into the cards nested slot placeholders . Based on the example given in the PSR - 3 specification .
16,545
public function count ( ) { $ c = 0 ; foreach ( $ this -> keys ( ) as $ valueName ) { if ( $ this [ $ valueName ] instanceof Slot ) { ++ $ c ; } } return $ c ; }
The number of Slots in the machine
16,546
public function all ( ) { $ all = array ( ) ; foreach ( $ this -> keys ( ) as $ slotName ) { $ all [ $ slotName ] = $ this -> get ( $ slotName ) ; } return $ all ; }
Return all the slots .
16,547
public function addCss ( $ handle = null , $ src = null , $ dependency = null , array $ attributes = [ ] ) { if ( ! isset ( $ attributes [ 'media' ] ) ) { $ attributes [ 'media' ] = 'all' ; } return $ this -> styles [ $ handle ] = new Css ( $ handle , $ src , $ dependency , $ attributes ) ; }
CSS wrapper .
16,548
public function removeCss ( $ handle = null ) { if ( is_null ( $ handle ) ) { return $ this -> styles = [ ] ; } unset ( $ this -> styles [ $ handle ] ) ; }
Remove a CSS asset or all .
16,549
public function renderStyles ( ) { $ this -> loadPackageCss ( ) ; if ( empty ( $ this -> styles ) ) { return PHP_EOL ; } $ assets = [ ] ; foreach ( $ this -> sort ( $ this -> styles ) as $ handle => $ data ) { $ assets [ ] = $ this -> getCss ( $ handle ) ; } return implode ( PHP_EOL , $ assets ) ; }
Get all CSS assets sorted by dependencies .
16,550
public function containersStart ( $ container = NULL ) { $ this -> validateConfig ( ) ; $ this -> title ( 'Starting containers' ) ; $ command = $ this -> taskDockerComposeUp ( ) ; if ( $ container ) { $ this -> limitComposeContainer ( $ command , $ container ) ; } $ command -> file ( $ this -> dockerComposeFile ) -> projectName ( $ this -> config -> get ( 'name' ) ) -> detachedMode ( ) -> run ( ) ; }
Compose all the docker containers .
16,551
public function containersDestroy ( ) { $ this -> validateConfig ( ) ; $ this -> title ( 'Destroying containers' ) ; $ this -> taskDockerComposeDown ( ) -> file ( $ this -> dockerComposeFile ) -> projectName ( $ this -> config -> get ( 'name' ) ) -> removeOrphans ( ) -> rmi ( 'all' ) -> run ( ) ; }
Destroy docker containers .
16,552
public function containersExec ( $ container , $ execute_command ) { $ this -> validateConfig ( ) ; $ this -> title ( 'Executing in container: ' . $ container , FALSE ) ; $ this -> taskDockerComposeExecute ( ) -> file ( $ this -> dockerComposeFile ) -> projectName ( $ this -> config -> get ( 'name' ) ) -> disablePseudoTty ( ) -> setContainer ( ' ' . $ container ) -> exec ( $ execute_command ) -> run ( ) ; }
Execute a command on a given container .
16,553
public function containersActive ( ) { $ ps = $ this -> taskDockerComposePs ( ) -> file ( $ this -> dockerComposeFile ) -> projectName ( $ this -> config -> get ( 'name' ) ) -> setVerbosityThreshold ( VerbosityThresholdInterface :: VERBOSITY_DEBUG ) -> printOutput ( FALSE ) -> run ( ) -> getMessage ( ) ; $ this -> say ( "$ps" ) ; }
Lists the currently active containers .
16,554
protected static function allowHeaders ( ) { if ( self :: $ needHeaders !== null ) { return self :: $ needHeaders ; } return self :: $ needHeaders = Request :: is ( 'GET' ) || Request :: is ( 'HEAD' ) ; }
Check if is HEAD or GET you can overwrite this method
16,555
public static function match ( $ modified , $ etag = null ) { $ modifiedsince = Request :: header ( 'If-Modified-Since' ) ; if ( $ modifiedsince && preg_match ( '#^[a-z]{3}[,] \d{2} [a-z]{3} \d{4} \d{2}[:]\d{2}[:]\d{2} GMT$#i' , $ modifiedsince ) !== 0 && strtotime ( $ modifiedsince ) == $ modified ) { return true ; } $ nonematch = Request :: header ( 'If-None-Match' ) ; return $ nonematch && trim ( $ nonematch ) === $ etag ; }
Check HTTP_IF_MODIFIED_SINCE and HTTP_IF_NONE_MATCH from server If true you can send 304 Not Modified
16,556
public function decode ( string $ json ) { $ result = json_decode ( $ json , $ this -> decodeObjectAsArray , $ this -> maxDepth + 1 , $ this -> options ) ; $ this -> checkLastError ( ) ; return $ result ; }
Decodes data in JSON format .
16,557
public function grant ( $ flag ) { if ( is_string ( $ flag ) && defined ( 'static::' . strtoupper ( $ flag ) ) ) { $ flag = constant ( 'static::' . strtoupper ( $ flag ) ) ; } $ this -> mask |= $ flag ; return $ this ; }
Grant a permission on this calendar
16,558
public function revoke ( $ flag ) { if ( is_string ( $ flag ) && defined ( 'static::' . strtoupper ( $ flag ) ) ) { $ flag = constant ( 'static::' . strtoupper ( $ flag ) ) ; } $ this -> mask &= ~ $ flag ; return $ this ; }
Revoke a permission on this calendar
16,559
protected function sort ( $ assets ) { $ original = $ assets ; $ sorted = [ ] ; while ( count ( $ assets ) > 0 ) { foreach ( $ assets as $ handle => $ asset ) { if ( ! $ asset -> hasDependency ( ) ) { $ sorted [ $ handle ] = $ asset ; unset ( $ assets [ $ handle ] ) ; } else { foreach ( $ asset -> getDependency ( ) as $ dep ) { if ( ! isset ( $ original [ $ dep ] ) or $ dep === $ handle or ( isset ( $ assets [ $ dep ] ) and $ assets [ $ dep ] -> hasDependency ( $ handle ) ) ) { $ assets [ $ handle ] -> removeDependency ( $ dep ) ; continue ; } if ( ! isset ( $ sorted [ $ dep ] ) ) { continue ; } $ assets [ $ handle ] -> removeDependency ( $ dep ) ; } } } } return $ sorted ; }
Sorts assets based on dependencies .
16,560
public static function createAppCSR ( $ keyPair , $ dn ) { $ privKey = new \ Crypt_RSA ( ) ; $ privKey -> loadKey ( $ keyPair [ 'privatekey' ] ) ; $ pubKey = new \ Crypt_RSA ( ) ; $ pubKey -> loadKey ( $ keyPair [ 'publickey' ] ) ; $ pubKey -> setPublicKey ( ) ; $ x509 = new \ File_X509 ( ) ; $ x509 -> setPrivateKey ( $ privKey ) ; $ x509 -> setDN ( $ dn ) ; $ x509 -> loadCSR ( $ x509 -> saveCSR ( $ x509 -> signCSR ( Constants :: CERT_SIGNATURE_ALGORITHM ) ) ) ; $ x509 -> setExtension ( 'id-ce-keyUsage' , array ( 'keyEncipherment' ) ) ; $ csrData = $ x509 -> signCSR ( Constants :: CERT_SIGNATURE_ALGORITHM ) ; return $ x509 -> saveCSR ( $ csrData ) ; }
Create a CSR for a CiviConnect application .
16,561
public static function createCrlDistCSR ( $ keyPair , $ dn ) { $ privKey = new \ Crypt_RSA ( ) ; $ privKey -> loadKey ( $ keyPair [ 'privatekey' ] ) ; $ pubKey = new \ Crypt_RSA ( ) ; $ pubKey -> loadKey ( $ keyPair [ 'publickey' ] ) ; $ pubKey -> setPublicKey ( ) ; $ csr = new \ File_X509 ( ) ; $ csr -> setPrivateKey ( $ privKey ) ; $ csr -> setPublicKey ( $ pubKey ) ; $ csr -> setDN ( $ dn ) ; $ csr -> loadCSR ( $ csr -> saveCSR ( $ csr -> signCSR ( Constants :: CERT_SIGNATURE_ALGORITHM ) ) ) ; $ csr -> setExtension ( 'id-ce-keyUsage' , array ( 'cRLSign' ) ) ; $ csrData = $ csr -> signCSR ( Constants :: CERT_SIGNATURE_ALGORITHM ) ; return $ csr -> saveCSR ( $ csrData ) ; }
Create a CSR for an authority that can issue CRLs .
16,562
public static function localDelete ( string $ path , string $ fileName ) : bool { if ( is_file ( $ path . $ fileName ) ) { unlink ( $ path . $ fileName ) ; } else { return false ; } return true ; }
delete local file and return bool type
16,563
public static function getUUID ( ) : string { mt_srand ( ( double ) microtime ( ) * 10000 ) ; $ charId = strtolower ( md5 ( uniqid ( rand ( ) , true ) ) ) ; $ hyphen = chr ( 45 ) ; return substr ( $ charId , 0 , 8 ) . $ hyphen . substr ( $ charId , 8 , 4 ) . $ hyphen . substr ( $ charId , 12 , 4 ) . $ hyphen . substr ( $ charId , 16 , 4 ) . $ hyphen . substr ( $ charId , 20 , 12 ) ; }
create uuid and return it
16,564
public static function getRandomString ( int $ length = 64 ) : string { $ characters = "01234567890123456789" ; $ characters .= "abcdefghijklmnopqrstuvwxyz" ; $ string_generated = "" ; while ( $ length -- ) { $ string_generated .= $ characters [ mt_rand ( 0 , 45 ) ] ; } return $ string_generated ; }
create random string and return it
16,565
public static function arrayToXml ( $ arr , $ num_prefix = "num_" ) : string { if ( ! is_array ( $ arr ) ) return $ arr ; $ result = '' ; foreach ( $ arr as $ key => $ val ) { $ key = ( is_numeric ( $ key ) ? $ num_prefix . $ key : $ key ) ; $ result .= '<' . $ key . '>' . self :: arrayToXml ( $ val , $ num_prefix ) . '</' . $ key . '>' ; } return $ result ; }
convert data from array to xml
16,566
public function get ( $ apiPath , $ queryParams = [ ] ) { $ response = $ this -> guzzleClient -> get ( $ this -> baseUrl . $ apiPath , [ 'query' => $ queryParams , 'future' => false , 'auth' => [ $ this -> id , $ this -> secret , self :: $ AUTH_TYPE ] , ] ) ; return $ this -> resolve ( $ response ) ; }
Execute a GET request against the API
16,567
public static function compiles ( ) { return [ base_path ( 'vendor\kodicms\laravel-assets\src\Contracts\MetaInterface.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Contracts\AssetsInterface.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Contracts\PackageManagerInterface.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Contracts\AssetElementInterface.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Contracts\PackageInterface.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Contracts\SocialMediaTagsInterface.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Traits\Groups.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Traits\Vars.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Traits\Packages.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Traits\Styles.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Traits\Scripts.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\AssetElement.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Css.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Javascript.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Html.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Meta.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Package.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\PackageManager.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Assets.php' ) , base_path ( 'vendor\kodicms\laravel-assets\src\Facades\Meta.php' ) , ] ; }
Get a list of files that should be compiled for the package .
16,568
public function setSecurityLevel ( $ rawData ) { switch ( $ this -> securityLevel ) { case "low" : break ; case "normal" : $ rawData = \ str_replace ( "<" , "&lt;" , $ rawData ) ; $ rawData = \ str_replace ( ">" , "&gt;" , $ rawData ) ; $ rawData = \ str_replace ( "\"" , "&quot;" , $ rawData ) ; $ rawData = \ str_replace ( "'" , "&apos;" , $ rawData ) ; break ; case "high" : $ rawData = \ str_replace ( "<" , "" , $ rawData ) ; $ rawData = \ str_replace ( ">" , "" , $ rawData ) ; $ rawData = \ str_replace ( "\"" , "" , $ rawData ) ; $ rawData = \ str_replace ( "'" , "" , $ rawData ) ; break ; } return $ rawData ; }
to make more security
16,569
private function setGet ( ) { if ( isset ( $ _GET ) ) { foreach ( $ _GET as $ k => $ v ) { $ this -> log -> debug ( "[ GET Params ]" . $ k . ": " . $ v , [ ] ) ; $ this -> get -> $ k = $ this -> setSecurityLevel ( $ v ) ; $ this -> parameters [ "get" ] [ $ k ] = $ this -> setSecurityLevel ( $ v ) ; } unset ( $ _GET ) ; } }
GET Method and Parameter Information and assign via for framework
16,570
private function setConfig ( $ config ) { $ this -> securityLevel = $ config -> config [ 'project' ] [ 'security_level' ] ; if ( $ config -> config [ 'config' ] ) { foreach ( $ config -> config [ 'config' ] as $ k => $ v ) { $ this -> log -> debug ( "[ CONFIG Params ]" . $ k . ": " . $ v , [ ] ) ; $ this -> config -> $ k = $ this -> setSecurityLevel ( $ v ) ; $ this -> parameters [ "config" ] [ $ k ] = $ this -> setSecurityLevel ( $ v ) ; } } }
Add Option Data
16,571
private function setPost ( ) { if ( $ this -> parameters [ 'header' ] [ "Content-Type" ] == "application/x-www-form-urlencoded" ) { if ( isset ( $ _GET ) ) { foreach ( $ _GET as $ k => $ v ) { $ this -> log -> debug ( "[ _POST Params ]" . $ k . ": " . $ v , [ ] ) ; $ this -> post -> $ k = $ this -> setSecurityLevel ( $ v ) ; $ this -> parameters [ "post" ] [ $ k ] = $ this -> setSecurityLevel ( $ v ) ; } unset ( $ _GET ) ; } } if ( isset ( $ _POST ) ) { foreach ( $ _POST as $ k => $ v ) { if ( is_array ( $ v ) == true ) { $ this -> log -> debug ( "[ _POST Params ]" . $ k . ": " . json_encode ( $ v ) , [ ] ) ; } else { $ this -> log -> debug ( "[ _POST Params ]" . $ k . ": " . $ v , [ ] ) ; } $ this -> post -> $ k = $ this -> setSecurityLevel ( $ v ) ; $ this -> parameters [ "post" ] [ $ k ] = $ this -> setSecurityLevel ( $ v ) ; } $ rawData = file_get_contents ( "php://input" ) ; if ( isset ( $ rawData ) ) { $ this -> log -> debug ( "[ POST RawData ] : " . $ rawData , [ ] ) ; $ this -> parameters [ "post" ] [ "raw" ] = $ rawData ; $ this -> post -> raw = $ rawData ; } unset ( $ _POST ) ; } }
POST Method and Parameter Information and assign via for framework
16,572
private function setPut ( ) { if ( $ this -> parameters [ 'header' ] [ "Content-Type" ] == "application/x-www-form-urlencoded" ) { if ( isset ( $ _GET ) ) { foreach ( $ _GET as $ k => $ v ) { $ this -> log -> debug ( "[ PUT Params ]" . $ k . ": " . $ v , [ ] ) ; $ this -> put -> $ k = $ this -> setSecurityLevel ( $ v ) ; $ this -> parameters [ "put" ] [ $ k ] = $ this -> setSecurityLevel ( $ v ) ; } unset ( $ _GET ) ; } $ rawData = file_get_contents ( "php://input" ) ; parse_str ( $ rawData , $ _PUT ) ; foreach ( $ _PUT as $ k => $ v ) { $ this -> log -> debug ( "[ PUT Params ]" . $ k . ": " . $ v , [ ] ) ; $ this -> put -> $ k = $ this -> setSecurityLevel ( $ v ) ; $ this -> parameters [ "put" ] [ $ k ] = $ this -> setSecurityLevel ( $ v ) ; } if ( $ rawData ) { $ this -> parameters [ "put" ] [ 'raw' ] = $ rawData ; $ this -> log -> debug ( "[ PUT RawData ] raw: " . $ rawData , [ ] ) ; } } }
PUT Method and Parameter Information and assign via for framework
16,573
private function setDelete ( ) { if ( $ this -> parameters [ 'header' ] [ "Content-Type" ] == "application/x-www-form-urlencoded" ) { if ( isset ( $ _GET ) ) { foreach ( $ _GET as $ k => $ v ) { $ this -> log -> debug ( "[ DELETE Params ]" . $ k . ": " . $ v , [ ] ) ; $ this -> delete -> $ k = $ this -> setSecurityLevel ( $ v ) ; $ this -> parameters [ "delete" ] [ $ k ] = $ this -> setSecurityLevel ( $ v ) ; } unset ( $ _GET ) ; } $ rawData = file_get_contents ( "php://input" ) ; parse_str ( $ rawData , $ _DELETE ) ; foreach ( $ _DELETE as $ k => $ v ) { $ this -> log -> debug ( "[ DELETE Params ]" . $ k . ": " . $ v , [ ] ) ; $ this -> delete -> $ k = $ this -> setSecurityLevel ( $ v ) ; $ this -> parameters [ "delete" ] [ $ k ] = $ this -> setSecurityLevel ( $ v ) ; } if ( $ rawData ) { $ this -> parameters [ "delete" ] [ 'raw' ] = $ rawData ; $ this -> log -> debug ( "[ DELETE RawData ] raw: " . $ rawData , [ ] ) ; } } }
DELETE Method and Parameter Information and assign via for framework
16,574
private function setCookie ( ) { if ( isset ( $ _COOKIE ) ) { foreach ( $ _COOKIE as $ k => $ v ) { $ this -> log -> debug ( "[ COOKIE Params ]" . $ k . ": " . $ v , [ ] ) ; $ this -> cookie -> $ k = $ this -> setSecurityLevel ( $ v ) ; $ this -> parameters [ "cookie" ] [ $ k ] = $ this -> setSecurityLevel ( $ v ) ; } unset ( $ _COOKIE ) ; } }
Set Cookie Info
16,575
private function setHeader ( ) { foreach ( getallheaders ( ) as $ k => $ v ) { $ this -> log -> debug ( "[ HEADER Params ]" . $ k . ": " . $ v , [ ] ) ; $ this -> header -> $ k = $ this -> setSecurityLevel ( $ v ) ; $ this -> parameters [ "header" ] [ $ k ] = $ this -> setSecurityLevel ( $ v ) ; } }
Set Header Info
16,576
private function setServer ( ) { if ( isset ( $ _SERVER ) ) { foreach ( $ _SERVER as $ k => $ v ) { $ this -> log -> debug ( "[ SERVER Params ]" . $ k . ": " . $ v , [ ] ) ; $ this -> server -> $ k = $ v ; $ this -> parameters [ "server" ] [ $ k ] = $ v ; } unset ( $ _SERVER ) ; } }
Set _SERVER info
16,577
private function setSession ( ) { if ( isset ( $ _SESSION ) ) { foreach ( $ _SESSION as $ k => $ v ) { $ this -> log -> debug ( "[ SESSION Params ]" . $ k . ": " . $ v , [ ] ) ; $ this -> session -> $ k = $ this -> setSecurityLevel ( $ v ) ; $ this -> parameters [ "session" ] [ $ k ] = $ this -> setSecurityLevel ( $ v ) ; } } }
Set _SESSION Info
16,578
public function addJs ( $ handle = false , $ src = null , $ dependency = null , $ footer = false ) { return $ this -> scripts [ $ handle ] = new Javascript ( $ handle , $ src , $ dependency , $ footer ) ; }
Javascript wrapper .
16,579
public function removeJs ( $ handle = null ) { if ( is_null ( $ handle ) ) { return $ this -> scripts = [ ] ; } if ( is_bool ( $ handle ) ) { foreach ( $ this -> scripts as $ i => $ javaScript ) { if ( $ javaScript -> isFooter ( ) === $ handle ) { unset ( $ this -> scripts [ $ i ] ) ; } } return ; } unset ( $ this -> scripts [ $ handle ] ) ; }
Remove a javascript asset or all .
16,580
public static function data ( $ key , $ value ) { if ( $ value === null ) { unset ( self :: $ shared [ $ key ] ) ; } else { self :: $ shared [ $ key ] = $ value ; } }
Share or remove shared data to Views shared variables will be added as variables to the views that will be executed later
16,581
public static function render ( $ view , array $ data = array ( ) ) { if ( self :: $ force || App :: state ( ) > 2 ) { \ UtilsSandboxLoader ( 'application/View/' . strtr ( $ view , '.' , '/' ) . '.php' , self :: $ shared + $ data ) ; return $ data = null ; } return array_push ( self :: $ views , array ( strtr ( $ view , '.' , '/' ) , $ data ) ) - 1 ; }
Register or render a View . If View is registered this method returns the index number from View
16,582
public static function remove ( $ index ) { if ( isset ( self :: $ views [ $ index ] ) ) { self :: $ views [ $ index ] = null ; } }
Remove a registered View by index
16,583
protected function getContainerName ( $ container ) { $ this -> validateConfig ( ) ; $ project_lowercase = strtolower ( $ this -> config -> get ( 'name' ) ) ; return str_replace ( ' ' , '' , $ project_lowercase ) . '_' . $ container ; }
Returns Docker Compose - style container name with project name as prefix .
16,584
protected function cleanFileName ( $ identifier ) { $ filter = [ ' ' => '-' , '_' => '-' , '/' => '-' , '[' => '-' , ']' => '' , ] ; $ identifier = strtr ( $ identifier , $ filter ) ; $ identifier = preg_replace ( '/[^\\x{002D}\\x{002E}\\x{0030}-\\x{0039}\\x{0041}-\\x{005A}\\x{005F}\\x{0061}-\\x{007A}\\x{00A1}-\\x{FFFF}]/u' , '' , $ identifier ) ; return strtolower ( $ identifier ) ; }
Converts random strings to clean filenames .
16,585
public function createRequest ( $ method , $ url , array $ options = [ ] ) { $ request = parent :: createRequest ( $ method , $ url , $ options ) ; $ query = $ request -> getQuery ( ) ; $ auth = $ request -> getConfig ( ) -> get ( 'auth' ) ; if ( ( ! is_array ( $ auth ) ) || ( count ( $ auth ) < 3 ) || ( $ auth [ 2 ] != Client :: $ AUTH_TYPE ) ) { throw new RuntimeException ( "Authorization information not provided" ) ; } $ id = $ auth [ 0 ] ; $ secret = $ auth [ 1 ] ; $ query -> set ( 'api_id' , $ id ) ; if ( ! $ query -> hasKey ( 'api_ts' ) ) { $ query -> set ( 'api_ts' , time ( ) ) ; } $ query -> set ( 'api_ver' , '2' ) ; $ hash = $ this -> generateMac ( $ request -> getUrl ( ) , $ request -> getQuery ( ) -> toArray ( ) , $ secret ) ; $ query -> set ( 'api_mac' , $ hash ) ; return $ request ; }
Create a new request based on the HTTP method .
16,586
private function generateMac ( $ url , $ query , $ secret ) { $ urlParts = parse_url ( $ url ) ; if ( substr ( $ urlParts [ 'path' ] , 0 , 2 ) == '//' ) { $ urlParts [ 'path' ] = substr ( $ urlParts [ 'path' ] , 1 ) ; } $ queryString = urldecode ( http_build_query ( $ query ) ) ; $ signingString = $ query [ 'api_id' ] . "\n" . $ query [ 'api_ts' ] . "\n" . $ urlParts [ 'path' ] . "\n" . $ queryString ; $ mac = hash_hmac ( 'sha1' , $ signingString , $ secret ) ; return $ mac ; }
Creates a hash based on request parameters
16,587
public function createResponse ( $ statusCode , array $ headers = [ ] , $ body = null , array $ options = [ ] ) { return parent :: createResponse ( $ statusCode , $ headers , $ body , $ options ) ; }
Creates a response
16,588
public function setMaxDepth ( int $ maxDepth ) : void { if ( $ maxDepth < 0 || $ maxDepth >= 0x7fffffff ) { throw new \ InvalidArgumentException ( 'Invalid max depth.' ) ; } $ this -> maxDepth = $ maxDepth ; }
Sets the max recursion depth . Defaults to 512 .
16,589
protected function setOption ( int $ option , bool $ bool ) : void { if ( $ bool ) { $ this -> options |= $ option ; } else { $ this -> options &= ~ $ option ; } }
Sets or resets a bitmask option .
16,590
public function get ( $ ip = '' ) { if ( empty ( $ ip ) ) $ this -> getIP ( ) ; else if ( ! filter_var ( $ ip , FILTER_VALIDATE_IP , FILTER_FLAG_IPV4 ) ) { return false ; } else { $ this -> ip = $ ip ; $ this -> ipAsLong = sprintf ( '%u' , ip2long ( $ ip ) ) ; } $ this -> getSypexGeo ( ) ; $ data = $ this -> _sypex -> getCityFull ( $ this -> ip ) ; if ( isset ( $ data [ 'city' ] ) ) $ this -> city = $ data [ 'city' ] ; if ( isset ( $ data [ 'region' ] ) ) $ this -> region = $ data [ 'region' ] ; if ( isset ( $ data [ 'country' ] ) ) $ this -> country = $ data [ 'country' ] ; return empty ( $ data ) ? false : $ data ; }
Get full geo info by remote IP - address
16,591
public static function unregister ( ) { $ nc = '\\' . get_called_class ( ) ; App :: off ( 'error' , array ( $ nc , 'renderError' ) ) ; App :: off ( 'terminate' , array ( $ nc , 'renderPerformance' ) ) ; App :: off ( 'terminate' , array ( $ nc , 'renderClasses' ) ) ; if ( false === empty ( self :: $ displayErrors ) ) { function_exists ( 'init_set' ) && ini_set ( 'display_errors' , self :: $ displayErrors ) ; self :: $ displayErrors = null ; } }
Unregister debug events
16,592
public static function renderError ( $ type , $ message , $ file , $ line ) { if ( empty ( self :: $ views [ 'error' ] ) ) { return null ; } elseif ( preg_match ( '#allowed\s+memory\s+size\s+of\s+\d+\s+bytes\s+exhausted\s+\(tried\s+to\s+allocate\s+\d+\s+bytes\)#i' , $ message ) ) { die ( '<br><strong>Fatal error:</strong> ' . $ message . ' in <strong>' . $ file . '</strong> on line <strong>' . $ line . '</strong>' ) ; } $ data = self :: details ( $ type , $ message , $ file , $ line ) ; if ( ! headers_sent ( ) && strcasecmp ( Request :: header ( 'accept' ) , 'application/json' ) === 0 ) { ob_start ( ) ; self :: unregister ( ) ; Response :: cache ( 0 ) ; Response :: type ( 'application/json' ) ; echo json_encode ( $ data ) ; App :: stop ( 500 ) ; } if ( in_array ( $ type , self :: $ fatal ) ) { View :: dispatch ( ) ; } self :: render ( self :: $ views [ 'error' ] , $ data ) ; }
Render a View to error
16,593
public static function renderPerformance ( ) { if ( ! empty ( self :: $ views [ 'performance' ] ) ) { self :: render ( self :: $ views [ 'performance' ] , self :: performance ( ) ) ; } }
Render a View to show performance memory and time to display page
16,594
public static function renderClasses ( ) { if ( ! empty ( self :: $ views [ 'classes' ] ) ) { self :: render ( self :: $ views [ 'classes' ] , array ( 'classes' => self :: classes ( ) ) ) ; } }
Render a View to show performance and show declared classes
16,595
public static function view ( $ type , $ view ) { if ( $ view !== null && View :: exists ( $ view ) === false ) { throw new Exception ( $ view . ' view is not found' , 2 ) ; } $ callRender = array ( '\\' . get_called_class ( ) , 'render' . ucfirst ( $ type ) ) ; switch ( $ type ) { case 'error' : self :: $ views [ $ type ] = $ view ; App :: on ( 'error' , $ callRender ) ; if ( empty ( self :: $ displayErrors ) ) { self :: $ displayErrors = ini_get ( 'display_errors' ) ; function_exists ( 'ini_set' ) && ini_set ( 'display_errors' , '0' ) ; } break ; case 'classes' : case 'performance' : self :: $ views [ $ type ] = $ view ; App :: on ( 'terminate' , $ callRender ) ; break ; case 'before' : self :: $ views [ $ type ] = $ view ; break ; default : throw new Exception ( $ type . ' is not valid event' , 2 ) ; } }
Register a debug views
16,596
public static function classes ( ) { $ objs = array ( ) ; foreach ( get_declared_classes ( ) as $ value ) { $ value = ltrim ( $ value , '\\' ) ; $ cname = new \ ReflectionClass ( $ value ) ; if ( false === $ cname -> isInternal ( ) ) { $ objs [ $ value ] = $ cname -> getDefaultProperties ( ) ; } $ cname = null ; } return $ objs ; }
Get declared classes
16,597
public static function source ( $ file , $ line ) { if ( $ line <= 0 || is_file ( $ file ) === false ) { return null ; } elseif ( $ line > 5 ) { $ init = $ line - 5 ; $ end = $ line + 5 ; $ breakpoint = 6 ; } else { $ init = 0 ; $ end = 5 ; $ breakpoint = $ line ; } return array ( 'breakpoint' => $ breakpoint , 'preview' => preg_split ( '#\r\n|\n#' , trim ( File :: portion ( $ file , $ init , $ end , true ) , "\r\n" ) ) ) ; }
Get snippet from a file
16,598
private function readCurrent ( ) : void { $ row = $ this -> readRow ( ) ; if ( $ this -> columns === null || $ row === null ) { $ this -> current = $ row ; } else { $ this -> current = [ ] ; foreach ( $ this -> columns as $ key => $ name ) { $ this -> current [ $ name ] = isset ( $ row [ $ key ] ) ? $ row [ $ key ] : null ; } } }
Reads the current CSV row .
16,599
public function has ( $ object ) : bool { $ hash = spl_object_hash ( $ object ) ; return isset ( $ this -> objects [ $ hash ] ) ; }
Returns whether this storage contains the given object .