idx
int64
0
60.3k
question
stringlengths
99
4.85k
target
stringlengths
5
718
56,100
public function cacheSize ( $ type = self :: PERSISTED ) { switch ( $ type ) { case self :: PERSISTED : return count ( $ this -> instancesPersisted ) ; case self :: UNPERSISTED : return count ( $ this -> instancesUnpersisted ) ; case self :: ALL : return $ this -> cacheSize ( self :: PERSISTED ) + $ this -> cacheSize (...
Returns the number of cached items
56,101
public function cacheInvalidate ( $ type = self :: ALL ) { switch ( $ type ) { case self :: PERSISTED : $ return = count ( $ this -> instancesPersisted ) ; $ this -> instancesPersisted = array ( ) ; return $ return ; case self :: UNPERSISTED : $ return = count ( $ this -> instancesUnpersisted ) ; $ this -> instancesUnp...
Invalidate cache . Returns multiton to it s vanilla state . Required for unit testing .
56,102
public function garbageCollect ( $ keyOrObject = null ) { if ( $ keyOrObject == null ) { if ( ! is_int ( $ this -> instancesMaxAllowed ) ) { return 0 ; } $ removed = 0 ; reset ( $ this -> instancesPersisted ) ; while ( count ( $ this -> instancesPersisted ) >= $ this -> instancesMaxAllowed && list ( $ key , $ obj ) = e...
Removes a object from the multiton if
56,103
protected function isSpamAttempt ( ) { $ dir = $ this -> tmp_path ; $ numPrefixChars = strlen ( $ this -> file_prefix ) ; $ files = scandir ( $ dir ) ; foreach ( $ files as $ file ) { if ( is_file ( $ dir . DIRECTORY_SEPARATOR . $ file ) ) { if ( substr ( $ file , 0 , $ numPrefixChars ) == $ this -> file_prefix ) { $ l...
Detects spam attempts
56,104
public function execute ( IDS_Report $ data ) { if ( $ this -> safemode ) { if ( $ this -> isSpamAttempt ( ) ) { return false ; } } $ data = $ this -> prepareData ( $ data ) ; if ( is_string ( $ data ) ) { $ data = trim ( $ data ) ; if ( is_array ( $ this -> headers ) ) { $ headers = "" ; foreach ( $ this -> headers as...
Sends the report to registered recipients
56,105
public function toProfile ( $ uid , $ card ) { $ card [ 'canvas' ] = isset ( $ card [ 'canvas' ] ) ? $ card [ 'canvas' ] : self :: DEFAULT_CANVAS ; return $ this -> request -> send ( 'POST' , "/profiles/$uid/cards" , $ card ) ; }
Sends a card to a profile
56,106
public function toProfiles ( $ profiles , $ card ) { $ card = array_merge ( [ 'profile_uids' => $ profiles ] , $ card ) ; $ card [ 'canvas' ] = isset ( $ card [ 'canvas' ] ) ? $ card [ 'canvas' ] : self :: DEFAULT_CANVAS ; return $ this -> request -> send ( 'POST' , "/profiles/cards" , $ card ) ; }
Sends a card to a multiple profiles
56,107
public function toChannels ( $ channels , $ card ) { $ card = array_merge ( [ 'channel_uids' => $ channels ] , $ card ) ; $ card [ 'canvas' ] = isset ( $ card [ 'canvas' ] ) ? $ card [ 'canvas' ] : self :: DEFAULT_CANVAS ; return $ this -> request -> send ( 'POST' , "/channels/cards" , $ card ) ; }
Sends a card to a multiple channels
56,108
public function applyData ( $ applyEntrie = NULL , $ full = true ) { if ( is_array ( $ applyEntrie ) ) { if ( $ full ) { $ this -> values = $ applyEntrie ; } else { $ this -> values = array_replace ( $ this -> values , $ applyEntrie ) ; } } elseif ( is_string ( $ applyEntrie ) ) { if ( $ full ) { $ this -> values = exp...
apply content via string or array
56,109
private function checkCount ( ) { $ cnt = ( int ) $ this -> getMaxEntries ( ) ; if ( $ cnt !== NULL && count ( $ this -> values ) !== $ cnt ) { trigger_error ( "Wrong count of Elements. Expected are $cnt. But right now there are " . count ( $ this -> values ) ) ; } }
checks if the expected count is given triggers an error if getMaxEntries Returns a number and this number is not equal to the count of elements .
56,110
public function getHTMLGeneratorInstance ( ) { if ( ! isset ( $ this -> HTMLGenerator ) || ! $ this -> HTMLGenerator instanceof HTMLGenerator ) { $ this -> HTMLGenerator = new HTMLGenerator ( ) ; $ this -> HTMLConfig ( $ this -> HTMLGenerator ) ; } return $ this -> HTMLGenerator ; }
Get the generator instance or create one .
56,111
public static function isLongCode ( $ arg ) { $ retVal = ( strlen ( $ arg ) > 2 ) && ( '-' === $ arg [ 0 ] && '-' === $ arg [ 1 ] ) ; if ( 2 === strlen ( $ arg ) ) { return $ retVal ; } if ( ( ! is_bool ( $ arg ) && ! Util :: validIndex ( 2 , $ arg ) ) || '-' === $ arg [ 2 ] ) { throw new CommandException ( 'Unknown op...
Checks if the argument is a long code .
56,112
public static function setRequiredValue ( Option & $ option , $ arg ) { if ( self :: isShortCode ( $ arg ) || self :: isLongCode ( $ arg ) ) { throw new CommandException ( 'Missing argument for option --' . $ option -> longCode ) ; } else { if ( is_string ( $ arg ) ) { $ arg = trim ( $ arg ) ; } $ option -> value = $ a...
Sets the required argument .
56,113
public static function setOptionalValue ( Option & $ option , $ arg ) { if ( ! self :: isShortCode ( $ arg ) && ! self :: isLongCode ( $ arg ) ) { if ( is_bool ( $ arg ) ) { $ option -> value = ( bool ) $ arg ; } elseif ( is_string ( $ arg ) ) { $ arg = trim ( $ arg ) ; $ option -> value = $ arg ; } } }
Sets an optional argument if available .
56,114
public function setTableName ( $ table ) { if ( $ this -> sql ) { if ( $ this -> validateToken ( $ table ) ) { $ this -> table = $ table ; return true ; } else { throw new SimpleCache_Exception ( "`$table` is not a valid table name" ) ; } } return false ; }
Set cache table name
56,115
public function setKeyName ( $ key ) { if ( $ this -> sql ) { if ( $ this -> validateToken ( $ key ) ) { $ this -> key = $ key ; return true ; } else { throw new SimpleCache_Exception ( "`$key` is not a valid field name" ) ; } } return false ; }
Set cache key field name
56,116
public function setCacheName ( $ cache ) { if ( $ this -> sql ) { if ( $ this -> validateToken ( $ cache ) ) { $ this -> cache = $ cache ; return true ; } else { throw new SimpleCache_Exception ( "`$cache` is not a valid field name" ) ; } } return false ; }
Set cache storage field name
56,117
public function buildCache ( $ table = null , $ key = null , $ cache = null ) { if ( $ this -> sql && ( $ table === null || $ this -> setTableName ( $ table ) ) && ( $ key === null || $ this -> setKeyName ( $ key ) ) && ( $ cache === null || $ this -> setCacheName ( $ cache ) ) ) { if ( $ this -> sql -> query ( " ...
Create cache table in database
56,118
public function getCache ( $ key ) { if ( $ this -> sqlInitialized ( ) ) { if ( $ this -> sql ) { $ _key = $ this -> sql -> real_escape_string ( $ key ) ; if ( $ this -> lifetime == self :: IMMORTAL_LIFETIME ) { if ( $ response = $ this -> sql -> query ( " SELECT * FROM...
Get available cached data
56,119
protected function getExpirationTimestamp ( $ lifetimeInSeconds = false ) { if ( $ lifetimeInSeconds === false ) { $ lifetimeInSeconds = $ this -> lifetime ; } if ( $ lifetimeInSeconds === self :: IMMORTAL_LIFETIME ) { return false ; } else { return date ( self :: MYSQL_TIMESTAMP , time ( ) + $ lifetimeInSeconds ) ; } ...
Calculate the expiration timestamp
56,120
public function purgeExpired ( ) { if ( $ this -> sqlInitialized ( ) ) { if ( $ this -> sql ) { if ( $ this -> sql -> query ( " DELETE FROM `{$this->table}` WHERE `expire` < NOW() " ) ) { return true ; } } } return false ; }
Purge expired cache data
56,121
public function setCache ( $ key , $ data , $ lifetimeInSeconds = false ) { if ( $ this -> sqlInitialized ( ) ) { if ( $ this -> sql ) { $ _key = $ this -> sql -> real_escape_string ( $ key ) ; $ _data = $ this -> sql -> real_escape_string ( serialize ( $ data ) ) ; $ _expire = $ this -> getExpirationTimestamp ( $ life...
Store data in cache
56,122
public function getCacheTimestamp ( $ key ) { if ( $ this -> sqlInitialized ( ) ) { $ _key = $ this -> sql -> real_escape_string ( $ key ) ; if ( $ response = $ this -> sql -> query ( " SELECT * FROM `{$this->table}` WHERE `{$this->key}` = '$_k...
Get the timestamp of the cached data
56,123
protected function setLoaders ( array $ loaders ) { $ this -> loaders = array ( ) ; foreach ( $ loaders as $ type => $ loader ) { if ( ! $ loader instanceof FormulaLoaderInterface ) { throw new \ InvalidArgumentException ( "Not a valid formula loader with key '${type}'." ) ; } $ this -> setLoader ( $ type , $ loader ) ...
Adds a list of loaders
56,124
public function actionJsonProxyPost ( ) { $ url = Cii :: get ( $ _POST , 'url' , false ) ; if ( $ url === false ) throw new CHttpException ( 400 , Yii :: t ( 'Api.index' , 'Missing $_POST[url] parameter' ) ) ; $ hash = md5 ( $ url ) ; $ response = Yii :: app ( ) -> cache -> get ( 'CiiMS::API::Proxy::' . $ hash ) ; if (...
Global proxy for CiiMS to support JavaScript endpoints that either don t have proper CORS headers or SSL This endpoint will only process JSON and will cache data for 10 minutes .
56,125
public function compile ( $ output ) { file_exists ( $ output ) || mkdir ( $ output ) ; $ this -> clear ( ( string ) $ output ) ; $ this -> output = ( string ) $ output ; foreach ( ( array ) $ this -> pages as $ page ) { $ folder = $ this -> folder ( $ output , $ page -> uris ( ) ) ; $ html = ( string ) $ this -> html ...
Compiles the specified pages into HTML output .
56,126
public function transfer ( $ source , $ path = null ) { $ path = $ path === null ? $ this -> output : $ path ; $ path = $ this -> realpath ( $ path ) ; $ source = ( string ) $ this -> realpath ( $ source ) ; $ directory = new \ RecursiveDirectoryIterator ( $ source , 4096 ) ; $ iterator = new \ RecursiveIteratorIterato...
Transfers files from a directory into another path .
56,127
protected function clear ( $ path ) { $ directory = new \ RecursiveDirectoryIterator ( $ path , 4096 ) ; $ iterator = new \ RecursiveIteratorIterator ( $ directory , 2 ) ; foreach ( $ iterator as $ file ) { $ git = strpos ( $ file -> getRealPath ( ) , '.git' ) !== false ; $ path = ( string ) $ file -> getRealPath ( ) ;...
Removes the files recursively from the specified directory .
56,128
protected function folder ( $ output , array $ uris ) { $ folder = ( string ) '' ; foreach ( ( array ) $ uris as $ uri ) { $ directory = $ output . '/' . ( string ) $ folder ; file_exists ( $ directory ) ? : mkdir ( $ directory ) ; $ folder === $ uri ? : $ folder .= '/' . $ uri ; } return $ folder ; }
Returns the whole folder path based from specified URIs . Also creates the specified folder if it doesn t exists .
56,129
protected function html ( Page $ page ) { $ html = $ this -> content -> make ( $ content = $ page -> content ( ) ) ; if ( ( $ name = $ page -> layout ( ) ) !== null ) { $ data = array_merge ( $ this -> helpers ( ) , ( array ) $ page -> data ( ) ) ; $ layout = new Layout ( $ this -> renderer , $ this , $ data ) ; $ html...
Converts the specified page into HTML .
56,130
protected function realpath ( $ folder ) { $ separator = ( string ) DIRECTORY_SEPARATOR ; $ search = array ( '\\' , '/' , ( string ) '\\\\' ) ; $ path = str_replace ( $ search , $ separator , $ folder ) ; file_exists ( $ path ) || mkdir ( ( string ) $ path ) ; $ exists = in_array ( substr ( $ path , - 1 ) , $ search ) ...
Replaces the slashes with the DIRECTORY_SEPARATOR . Also creates the directory if it doesn t exists .
56,131
public function execute ( callable $ statusCallback ) { for ( $ this -> iterations = 0 ; $ this -> iterations < 100 ; $ this -> iterations ++ ) { usleep ( 100000 ) ; $ statusCallback ( new TaskStatus ( $ this -> iterations , "Busy bee..." ) ) ; } }
Executes the long running code .
56,132
public static function str2url ( $ str ) { $ str = self :: rus2translit ( $ str ) ; $ str = strtolower ( $ str ) ; $ str = preg_replace ( '~[^-a-z0-9_]+~u' , '-' , $ str ) ; $ str = trim ( $ str , "-" ) ; return $ str ; }
String to url
56,133
protected function addSuffixNumber ( $ slug , Page $ page , $ number = 0 ) { $ slugTmp = $ number > 0 ? $ slug . $ this -> slugSuffixSeparator . $ number : $ slug ; $ parentFullpath = $ page -> getParent ( ) -> getFullpath ( ) ; $ foundedPage = $ this -> doctrine -> getRepository ( 'FulgurioLightCMSBundle:Page' ) -> fi...
Add suffix number if page exists
56,134
public function makeFullpath ( Page $ page ) { if ( $ page -> getParent ( ) === NULL ) { $ page -> setFullpath ( '' ) ; $ page -> setSlug ( '' ) ; } else { $ parentFullpath = $ page -> getParent ( ) -> getFullpath ( ) ; $ slug = $ this -> addSuffixNumber ( $ page -> getSlug ( ) , $ page ) ; $ page -> setFullpath ( ( $ ...
Init page full path and check if it doesn t already exist
56,135
private function updatePageMenuPosition ( Page $ page ) { $ pageMenuRepository = $ this -> doctrine -> getRepository ( 'FulgurioLightCMSBundle:PageMenu' ) ; $ em = $ this -> doctrine -> getManager ( ) ; $ data = $ this -> request -> get ( 'page' ) ; if ( isset ( $ data [ 'availableMenu' ] ) ) { if ( ! is_null ( $ page ...
Update page menu position
56,136
final public function initMetaEntity ( Page $ page , $ metaName , $ metaValue ) { $ this -> initPageMetas ( $ page ) ; if ( isset ( $ this -> pageMetas [ $ metaName ] ) ) { $ entity = $ this -> pageMetas [ $ metaName ] ; } else { $ entity = new PageMeta ( ) ; $ entity -> setPage ( $ page ) ; $ entity -> setMetaKey ( $ ...
Add or update a PageMeta entity and return it for save
56,137
final protected function initPageMetas ( Page $ page ) { if ( ! isset ( $ this -> pageMetas ) ) { $ this -> pageMetas = array ( ) ; if ( $ page -> getId ( ) > 0 ) { $ metas = $ this -> doctrine -> getRepository ( 'FulgurioLightCMSBundle:PageMeta' ) -> findByPage ( $ page -> getId ( ) ) ; foreach ( $ metas as $ meta ) {...
Init page meta of page
56,138
public function getClassName ( $ name ) { if ( ! $ this -> has ( $ name ) ) { return false ; } $ helper = $ this -> get ( $ name ) ; return get_class ( $ helper ) ; }
Return full class name for a named helper
56,139
public function getItems ( $ offset , $ limit , $ sort = null ) { $ items = [ ] ; $ cnt = count ( $ this -> rawData ) ; for ( $ i = $ offset ; $ i < $ offset + $ limit && $ i < $ cnt ; $ i ++ ) { $ items [ ] = $ this -> rawData [ $ i ] ; } return $ items ; }
This method return an collection of items for a page .
56,140
public function overlaps ( IntervalInterface $ interval ) { $ startDate = $ interval -> getStart ( ) ; $ endDate = $ interval -> getEnd ( ) ; return $ this -> checkOverlaping ( $ startDate , $ endDate ) ; }
Checks if the interval overlaps another interval
56,141
public function toArray ( ) { $ start = $ this -> intervalStart ; $ end = $ this -> intervalEnd ; $ period = new \ DatePeriod ( $ start , new \ DateInterval ( 'P1D' ) , $ end ) ; $ days = array ( ) ; foreach ( $ period as $ current_day ) { $ days [ ] = $ current_day ; } $ days [ ] = $ end ; return $ days ; }
Array of \ DateTime objects
56,142
protected function initializeAttributeOnData ( $ attribute ) { $ explicitPath = $ this -> getLeadingExplicitAttributePath ( $ attribute ) ; $ data = $ this -> extractDataFromPath ( $ explicitPath ) ; if ( ! Str :: contains ( $ attribute , '*' ) || Str :: endsWith ( $ attribute , '*' ) ) { return $ data ; } return data_...
Gather a copy of the attribute data filled with any missing attributes .
56,143
protected function shouldStopValidating ( $ attribute ) { if ( ! $ this -> hasRule ( $ attribute , [ 'Bail' ] ) ) { return false ; } return $ this -> messages -> has ( $ attribute ) ; }
Stop on error if bail rule is assigned and attribute has a message .
56,144
protected function validateArray ( $ attribute , $ value ) { if ( ! $ this -> hasAttribute ( $ attribute ) ) { return true ; } return is_null ( $ value ) || is_array ( $ value ) ; }
Validate that an attribute is an array .
56,145
protected function validateInteger ( $ attribute , $ value ) { if ( ! $ this -> hasAttribute ( $ attribute ) ) { return true ; } return is_null ( $ value ) || filter_var ( $ value , FILTER_VALIDATE_INT ) !== false ; }
Validate that an attribute is an integer .
56,146
protected function validateNumeric ( $ attribute , $ value ) { if ( ! $ this -> hasAttribute ( $ attribute ) ) { return true ; } return is_null ( $ value ) || is_numeric ( $ value ) ; }
Validate that an attribute is numeric .
56,147
protected function validateString ( $ attribute , $ value ) { if ( ! $ this -> hasAttribute ( $ attribute ) ) { return true ; } return is_null ( $ value ) || is_string ( $ value ) ; }
Validate that an attribute is a string .
56,148
protected function validateActiveUrl ( $ attribute , $ value ) { if ( ! is_string ( $ value ) ) { return false ; } if ( $ url = parse_url ( $ value , PHP_URL_HOST ) ) { return count ( dns_get_record ( $ url , DNS_A | DNS_AAAA ) ) > 0 ; } return false ; }
Validate that an attribute is an active URL .
56,149
protected function validateAlphaNum ( $ attribute , $ value ) { if ( ! is_string ( $ value ) && ! is_numeric ( $ value ) ) { return false ; } return preg_match ( '/^[\pL\pM\pN]+$/u' , $ value ) ; }
Validate that an attribute contains only alpha - numeric characters .
56,150
protected function validateAlphaDash ( $ attribute , $ value ) { if ( ! is_string ( $ value ) && ! is_numeric ( $ value ) ) { return false ; } return preg_match ( '/^[\pL\pM\pN_-]+$/u' , $ value ) ; }
Validate that an attribute contains only alpha - numeric characters dashes and underscores .
56,151
public function iRunPhpspec ( $ argumentsString = '' ) { $ argumentsString = strtr ( $ argumentsString , array ( '\'' => '"' ) ) ; $ this -> process -> setWorkingDirectory ( $ this -> workingDir ) ; $ this -> process -> setCommandLine ( sprintf ( '%s %s %s --no-interaction' , $ this -> phpBin , escapeshellarg ( $ this ...
Runs phpspec command with provided parameters
56,152
public function filter ( $ value ) { $ filtered = null ; if ( ! $ this -> validate ( $ value , $ filtered ) ) { throw new \ InvalidArgumentException ( "Not a valid value for " . $ this -> __toString ( ) . ": " . WF :: str ( $ value ) ) ; } return $ filtered ; }
Return a properly typed value
56,153
public function validate ( $ value , & $ filtered = null ) { $ this -> error = null ; if ( $ value === null ) return $ this -> options [ 'nullable' ] ?? false ; $ filtered = $ value ; if ( $ this -> type === Validator :: EXISTS ) return true ; $ o = $ this -> options ; if ( $ this -> type !== Validator :: VALIDATE_CUST...
Check if the value matches the expected value
56,154
protected function numRangeCheck ( $ value , $ min , $ max ) { if ( $ min !== null && $ value < $ min ) return false ; if ( $ max !== null && $ value > $ max ) return false ; return true ; }
Check if the numeric value is between the configured minimum and maximum
56,155
public function map ( ) { $ this -> prefix ( 'statuses' ) -> as ( 'statuses.' ) -> group ( function ( ) { $ this -> get ( '/' , 'StatusesController@index' ) -> name ( 'index' ) ; $ this -> post ( 'backup' , 'StatusesController@backup' ) -> middleware ( 'ajax' ) -> name ( 'backup' ) ; $ this -> post ( 'clear' , 'Statuse...
Map the routes for the application .
56,156
protected function newDate ( $ desiredTZ , $ date = false ) { if ( $ date === false ) { $ date = 'now' ; } try { $ newDate = new Date ( is_numeric ( '' . $ date ) ? '@' . $ date : $ date , $ desiredTZ ) ; $ newDate -> setTimezone ( $ desiredTZ ) ; } catch ( Exception $ e ) { throw new DateException ( $ e ) ; } unset ( ...
Creates a new date in the desired timezone
56,157
public function make ( string $ name , int $ expireTime = 604800 , string $ path = "/" , string $ domain = "" , bool $ secure = false , bool $ httpOnly = true ) { return new PHPCookie ( $ name , $ expireTime , $ path , $ domain , $ secure , $ httpOnly ) ; }
Create a new cookie
56,158
public static function deserialize ( string $ json ) { $ deserialized = json_decode ( $ json , true ) ; $ objects = [ ] ; return self :: decode ( $ deserialized , $ objects ) ; }
Deserialize the given JSON string .
56,159
private static function setObjectProperties ( $ object , array & $ properties , bool $ isInternal , Closure $ propertyDecoder ) { Closure :: bind ( function ( ) use ( $ object , & $ properties , $ propertyDecoder ) { foreach ( $ properties as $ key => & $ value ) { $ object -> $ key = $ propertyDecoder ( $ value ) ; } ...
Set the given object properties .
56,160
public function thumb ( string $ src , string $ dst , integer $ width , integer $ height ) { $ anchor = 'center' ; return $ this -> image ( $ src ) -> thumbnail ( $ width , $ height , $ anchor ) -> toFile ( $ dst ) ; }
Miniatura da imagem
56,161
public static function between ( $ min , $ max ) : Compare { $ value = $ min > $ max ? [ $ max , $ min ] : [ $ min , $ max ] ; return new Compare ( 'bt' , $ value ) ; }
Gets a rule that requires numbers to be in a given range .
56,162
public function getInfo ( ) { if ( $ this -> info === null ) { $ this -> info = new \ SplFileInfo ( $ this -> fullPath ) ; } return $ this -> info ; }
Get the info
56,163
protected function parse ( array $ list ) { $ parsed = array ( ) ; foreach ( $ list as $ item ) { $ item = explode ( ';' , trim ( $ item ) ) ; $ entry = array ( 'encoding' => array_shift ( $ item ) , 'q' => 1 ) ; foreach ( $ item as $ param ) { $ param = explode ( '=' , $ param ) ; if ( count ( $ param ) != 2 ) { conti...
Parses a list of media types out into a normalised structure .
56,164
public function authenticate ( $ username , $ password , $ type = self :: AUTH_ANY ) { if ( false === is_string ( $ username ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type string, "%s" given' , __METHOD__ , gettype ( $ username ) ) , E_USER_ERROR ) ; } if ( false === is_string ( $...
Adds a HTTP authentication method
56,165
public function addParam ( $ key , $ value , $ encode = false ) { if ( false === is_string ( $ key ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type string, "%s" given' , __METHOD__ , gettype ( $ key ) ) , E_USER_ERROR ) ; } if ( false === is_string ( $ value ) && false === is_array ...
Add a new key value param to the url or query
56,166
public function addFile ( $ file , $ name = null , $ mime = null ) { if ( 'post' !== $ this -> method ) { return trigger_error ( 'File uploads are only supported with POST request method' , E_USER_ERROR ) ; } if ( false === $ file instanceof File && false === is_string ( $ file ) ) { return trigger_error ( sprintf ( 'A...
Attach file to request
56,167
public function userAgent ( $ useragent ) { if ( false === is_string ( $ useragent ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type string, "%s" given' , __METHOD__ , gettype ( $ useragent ) ) , E_USER_ERROR ) ; } $ this -> options [ CURLOPT_USERAGENT ] = $ useragent ; return $ this...
Set a user agent to the request
56,168
public function timeout ( $ connection = 30 , $ response = 30 ) { if ( false === ( '-' . intval ( $ connection ) == '-' . $ connection ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type integer, "%s" given' , __METHOD__ , gettype ( $ connection ) ) , E_USER_ERROR ) ; } if ( false === ...
Set the connection and response timeout in seconds for the request
56,169
public function referer ( $ referer ) { if ( false === is_string ( $ referer ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type string, "%s" given' , __METHOD__ , gettype ( $ referer ) ) , E_USER_ERROR ) ; } $ this -> options [ CURLOPT_REFERER ] = $ referer ; return $ this ; }
Set the referer
56,170
public function httpVersion ( $ version ) { if ( false === defined ( $ version ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() is not a valid HTTP protocol version' , __METHOD__ ) , E_USER_ERROR ) ; } $ this -> options [ CURLOPT_HTTP_VERSION ] = constant ( $ version ) ; return $ this ; }
Set the HTTP version protocol
56,171
public function addCookie ( $ key , $ value ) { if ( false === is_string ( $ key ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type string, "%s" given' , __METHOD__ , gettype ( $ key ) ) , E_USER_ERROR ) ; } if ( false === is_string ( $ value ) ) { return trigger_error ( sprintf ( 'Ar...
Add a cookie to the request
56,172
private function formatUrl ( ) { $ jar = [ ] ; $ query = $ this -> url -> getQuery ( ) ; if ( null !== $ query ) { $ jar [ ] = $ query ; } $ query = '' ; if ( count ( $ this -> params ) > 0 || count ( $ jar ) > 0 ) { if ( $ this -> method === 'get' ) { foreach ( $ this -> params as $ param ) { $ key = $ param -> encode...
Adds new params to existing params to format the url
56,173
private function formatParams ( ) { $ params = [ ] ; foreach ( $ this -> params as $ param ) { $ key = $ param -> encode ? urlencode ( $ param -> key ) : $ param -> key ; $ value = $ param -> encode ? urlencode ( $ param -> value ) : $ param -> value ; $ params [ $ key ] = $ value ; } foreach ( $ this -> files as $ fil...
Formats all the parameters
56,174
public function send ( ) { $ this -> response -> setStatus ( [ 'code' => 0 , 'protocol' => '' , 'status' => '' , 'text' => '' ] ) ; $ curl = curl_init ( ) ; curl_setopt_array ( $ curl , $ this -> createOptions ( ) ) ; $ response = curl_exec ( $ curl ) ; if ( false !== $ response ) { $ header_size = curl_getinfo ( $ cur...
Sends the request and sets all the response data
56,175
private function parseHeaders ( $ str ) { if ( false === is_string ( $ str ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type string, "%s" given' , __METHOD__ , gettype ( $ str ) ) , E_USER_ERROR ) ; } $ headers = [ ] ; $ status = [ ] ; foreach ( explode ( "\n" , $ str ) as $ header )...
Parses headers and forms it into an Array
56,176
private function parseCookies ( $ str ) { if ( false === is_string ( $ str ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type string, "%s" given' , __METHOD__ , gettype ( $ str ) ) , E_USER_ERROR ) ; } $ jar = [ ] ; $ headers = explode ( "\n" , trim ( $ str ) ) ; foreach ( $ headers a...
Parses the cookies from the headers and forms it into an Array
56,177
private function createOptions ( ) { $ default = [ CURLOPT_RETURNTRANSFER => true , CURLOPT_HEADER => true , CURLOPT_TIMEOUT => 30 , CURLOPT_URL => $ this -> formatUrl ( ) , CURLOPT_COOKIE => $ this -> formatCookies ( ) , CURLOPT_HTTPHEADER => $ this -> headers ] ; if ( 'get' !== $ this -> method ) { $ this -> options ...
Generates and returns all the options
56,178
private function method ( $ url , $ closure , $ method ) { if ( false === is_string ( $ url ) ) { return trigger_error ( sprintf ( 'Argument 1 passed to %s() must be of the type string, "%s" given' , __METHOD__ , gettype ( $ url ) ) , E_USER_ERROR ) ; } if ( false === is_string ( $ method ) ) { return trigger_error ( s...
Sets the method and url and executes a user closure function if given
56,179
public function addInstances ( array $ instances ) : self { foreach ( $ instances as $ _key => $ _instance ) { if ( is_string ( $ _key ) ) { $ _class_name = ltrim ( $ _key , '\\' ) ; } else { $ _class_name = get_class ( $ _instance ) ; } $ _class_key = strtolower ( $ _class_name ) ; $ this -> instances [ $ _class_key ]...
Add new instances .
56,180
public function addRule ( string $ name , array $ rule ) : self { $ name = ltrim ( $ name , '\\' ) ; $ key = strtolower ( $ name ) ; $ global_default_rule = $ this -> rules [ '*' ] ; $ this -> rules [ $ key ] = array_merge ( $ global_default_rule , $ rule ) ; $ this -> rules [ $ key ] = array_intersect_key ( $ this -> ...
Add a new rule .
56,181
protected function getRule ( string $ name , string $ key , array $ parent_names = [ ] ) : array { if ( isset ( $ this -> rules [ $ key ] ) ) { return $ this -> rules [ $ key ] ; } if ( $ this -> total_rules === 1 || ! $ parent_names ) { return $ this -> rules [ '*' ] ; } foreach ( array_map ( 'strtolower' , $ parent_n...
Gets a specific rule .
56,182
protected function resolveJitClosures ( array $ array ) { if ( isset ( $ array [ 'di::jit' ] ) ) { return $ array [ 'di::jit' ] ( $ this ) ; } foreach ( $ array as $ _key => & $ _value ) { if ( is_array ( $ _value ) ) { $ _value = $ this -> resolveJitClosures ( $ _value ) ; } } return $ array ; }
Resolve just - in - time closures .
56,183
protected function getClosure ( string $ class_name , string $ class_key ) : callable { $ parent_class_names = class_parents ( $ class_name ) ; $ all_class_names = $ parent_class_names ; $ all_class_names [ ] = $ class_name ; $ class = new \ ReflectionClass ( $ class_name ) ; $ constructor = $ class -> getConstructor (...
Get closure for a specific class .
56,184
protected function getParamsClosure ( \ ReflectionMethod $ constructor , array $ class_rule ) : callable { $ param_details = [ ] ; foreach ( $ constructor -> getParameters ( ) as $ _parameter ) { $ _name = $ _parameter -> getName ( ) ; $ _class = $ _parameter -> getClass ( ) ; $ _class_name = $ _class -> name ?? '' ; $...
Magic happens here .
56,185
protected function file ( $ key ) { return $ this -> dir . DIRECTORY_SEPARATOR . $ this -> key ( $ key ) . "." . $ this -> fileExtension ; }
Generates the filename to store based on the cachePrefix and given key
56,186
protected function isExpired ( $ key , $ storageArray = null ) { if ( ! empty ( $ key ) ) { if ( ! $ this -> containsKey ( $ key ) ) return true ; $ storageArray = $ this -> readFile ( $ this -> file ( $ key ) ) ; } if ( is_array ( $ storageArray ) ) { if ( $ storageArray [ 'expires' ] >= time ( ) && $ storageArray [ '...
Determines if the key or storage array specified is expired
56,187
protected function getData ( $ key ) { $ filename = $ this -> file ( $ key ) ; if ( ! file_exists ( $ filename ) ) return false ; else { $ data = $ this -> readFile ( $ filename ) ; if ( $ this -> isExpired ( null , $ data ) ) return false ; else { $ expire = $ data [ 'expires' ] ; $ value = $ data [ 'value' ] ; $ dura...
Performs a fetch of our data from the filecache without logging in the logger . That allows this method to be used in other locations .
56,188
protected function writeFile ( $ filename , $ value ) { try { FileSystemUtils :: safeFilePutContents ( $ filename , serialize ( $ value ) ) ; return true ; } catch ( Exception $ e ) { return false ; } }
Performs a write to the filesystem of our data .
56,189
public function flushExpired ( ) { $ this -> Logger -> debug ( 'Flush all expired called.' ) ; try { foreach ( new DirectoryIterator ( $ this -> dir ) as $ item ) { $ filename = $ item -> getPath ( ) . DIRECTORY_SEPARATOR . $ item -> getFilename ( ) ; $ pathinfo = pathinfo ( $ filename ) ; if ( $ pathinfo [ 'extension'...
Removes all expired items from the cache store
56,190
public function matches ( $ uri ) { if ( ! preg_match ( $ this -> compiledRegex , $ uri , $ matches ) ) { return false ; } $ params = array ( ) ; foreach ( $ matches as $ key => $ value ) { if ( $ key == 'controller' && substr_count ( $ value , '_' ) ) { $ temp = explode ( '_' , $ value ) ; $ value = array_pop ( $ temp...
Tests if the route matches a given URI . A successful match will return all of the routed parameters as an array . A failed match will return boolean FALSE .
56,191
protected function compile ( ) { $ regex = preg_replace ( '#' . self :: REGEX_ESCAPE . '#' , '\\\\$0' , $ this -> uri ) ; if ( strpos ( $ regex , '(' ) !== false ) { $ regex = str_replace ( array ( '(' , ')' ) , array ( '(?:' , ')?' ) , $ regex ) ; } $ regex = str_replace ( array ( '<' , '>' ) , array ( '(?P<' , '>' . ...
Returns the compiled regular expression for the route . This translates keys and optional groups to a proper PCRE regular expression .
56,192
final protected function _getTimeZone ( $ timezone = null ) { if ( $ timezone = strtoupper ( $ timezone ) and defined ( "\\DateTimeZone::{$timezone}" ) ) { $ timezone = new \ DateTimeZone ( $ timezone ) ; } elseif ( ! ( $ timezone instanceof \ DateTimeZone ) ) { @ date_default_timezone_set ( date_default_timezone_get (...
Attempts to get timezone with fallback to default which in turn defaults to UTC
56,193
protected function check ( ) { try { $ options = $ this -> getOptions ( ) ; $ response = $ this -> mcStatus -> query ( true ) ; if ( ! is_array ( $ response ) || ! array_key_exists ( 'player_count' , $ response ) ) { $ this -> setMessage ( 'No response from Minecraft server query.' ) ; $ this -> setCode ( self :: STATE...
Check the amount of players on the Minecraft server .
56,194
public function build ( ModelInterface $ model , $ relation ) { list ( $ current , $ further ) = $ this -> splitRelationName ( $ relation ) ; $ definition = $ this -> fetchDefinition ( $ model , $ current ) ; switch ( $ definition -> type ( ) ) { case self :: RELATION_ONE : $ instance = new OneRelation ( $ this -> stor...
Sets model and its relation
56,195
public function toStringFromYaml ( array $ parseResult ) { $ this -> parameters = $ parseResult ; $ this -> removeNullValues ( ) ; $ this -> removeInvalidKeys ( ) ; $ this -> ensureDefaultBrush ( ) ; $ brush = SyntaxHighlighterBrush :: fromIdentifierOrAlias ( $ this -> parameters [ 'brush' ] ) ; $ this -> eventContext ...
Parse to scalar string from YAML .
56,196
private function formatValues ( ) { array_walk ( $ this -> parameters , function ( & $ value , $ key ) { $ parameterValue = $ value ; if ( is_bool ( $ parameterValue ) ) { $ parameterValue = var_export ( $ parameterValue , true ) ; } $ formattedValue = sprintf ( self :: DEFAULT_PAIR_FORMAT , $ key , $ parameterValue ) ...
Applies formats formatting to values .
56,197
public function getObject ( $ forceInstance = false ) { if ( false === $ forceInstance && true === $ this -> getValidationResult ( ) -> hasErrors ( ) ) { throw new Exception ( 'Trying to access a configuration object which contains errors. You should first check if it is error free, then use it: "$yourObject->getValida...
Returns the real instance of the configuration object .
56,198
public function setValidationResult ( Result $ result ) { if ( false === $ this -> mapperResult -> hasErrors ( ) ) { $ this -> validationResult = $ result ; } }
Manually set the validation result . Used in the cache service .
56,199
public function refreshValidationResult ( ) { if ( false === $ this -> mapperResult -> hasErrors ( ) ) { $ validator = Core :: get ( ) -> getValidatorResolver ( ) -> getBaseValidatorConjunction ( get_class ( $ this -> object ) ) ; $ this -> validationResult = $ validator -> validate ( $ this -> object ) ; } return $ th...
If the mapping result which was passed as a constructor argument of this class contains error the validation result will be the same . Otherwise a recursive validation of the object is processed .