idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
14,400
|
public function getCacheInfo ( ) { if ( ( $ cachePath = $ this -> folder -> getCachePath ( TRUE ) ) ) { $ size = 0 ; $ count = 0 ; $ di = new \ DirectoryIterator ( $ cachePath ) ; foreach ( $ di as $ fileinfo ) { if ( $ fileinfo -> isDot ( ) || ! $ fileinfo -> isFile ( ) || strpos ( $ fileinfo -> getFilename ( ) , $ this -> filename ) !== 0 ) { continue ; } ++ $ count ; $ size += $ fileinfo -> getSize ( ) ; } return [ 'count' => $ count , 'totalSize' => $ size ] ; } return FALSE ; }
|
retrieve information about cached files
|
14,401
|
public static function getFilesystemFilesInFolder ( FilesystemFolder $ folder ) { $ files = [ ] ; $ glob = glob ( $ folder -> getPath ( ) . '*' , GLOB_NOSORT ) ; if ( $ glob !== FALSE ) { foreach ( $ glob as $ f ) { if ( ! is_dir ( $ f ) ) { if ( ! isset ( self :: $ instances [ $ f ] ) ) { self :: $ instances [ $ f ] = new self ( basename ( $ f ) , $ folder ) ; } $ files [ ] = self :: $ instances [ $ f ] ; } } } return $ files ; }
|
return all filesystem files instances within a certain folder
|
14,402
|
public function setFetchOptions ( $ fetchOptions ) { if ( $ fetchOptions === null ) { return $ this -> fetchOptions ; } if ( ! is_integer ( $ fetchOptions ) ) { throw new BadTypeException ( $ fetchOptions , 'int' ) ; } $ fetchOptions += $ fetchOptions & ( self :: TYPE_DETECT | self :: TYPE_AGNOSTIC ) ? 0 : self :: TYPE_DEFAULT ; $ fetchOptions += $ fetchOptions & ( self :: FLATTEN_IF_POSSIBLE | self :: FLATTEN_PREVENT ) ? 0 : self :: FLATTEN_DEFAULT ; $ fetchOptions += $ fetchOptions & ( self :: STYLE_ASSOC | self :: STYLE_NUM ) ? 0 : self :: STYLE_DEFAULT ; $ fetchOptions += $ fetchOptions & ( self :: FETCH_SINGLE | self :: FETCH_MULTIPLE ) ? 0 : self :: FETCH_DEFAULT ; $ fetchOptions += $ fetchOptions & ( self :: CACHE | self :: CACHE_NOT ) ? 0 : self :: CACHE_DEFAULT ; $ flatten = ( bool ) ( $ fetchOptions & self :: FLATTEN_IF_POSSIBLE ) && ( $ this -> numFields ( ) === 1 ) ; $ this -> buildFetchCallback ( $ fetchOptions , $ flatten ) ; $ this -> fetchOptions = $ fetchOptions ; return $ this ; }
|
Set the result fetchOptions
|
14,403
|
private function buildFetchCallback ( $ fetchOptions , $ flatten ) { $ original = $ this -> fetchOptions & ( self :: TYPE_DETECT | self :: TYPE_AGNOSTIC | self :: FLATTEN_IF_POSSIBLE | self :: FLATTEN_PREVENT | self :: STYLE_ASSOC | self :: STYLE_NUM ) ; $ new = $ fetchOptions & ( self :: TYPE_DETECT | self :: TYPE_AGNOSTIC | self :: FLATTEN_IF_POSSIBLE | self :: FLATTEN_PREVENT | self :: STYLE_ASSOC | self :: STYLE_NUM ) ; if ( $ original === $ new ) { return false ; } $ this -> fetchType = ( $ fetchOptions & self :: STYLE_ASSOC and ! $ flatten ) ? PGSQL_ASSOC : PGSQL_NUM ; if ( $ fetchOptions & self :: TYPE_DETECT ) { $ typeCallbacks = $ this -> getFieldTypeCallbacks ( ) ; if ( $ this -> fetchType === PGSQL_ASSOC ) { $ keys = array_keys ( $ typeCallbacks ) ; } else { $ keys = range ( 0 , count ( $ typeCallbacks ) - 1 ) ; } if ( $ flatten ) { $ typeCallback = array_pop ( $ typeCallbacks ) ; $ this -> fetchCallback = function ( $ row ) use ( $ keys , $ typeCallback ) { return call_user_func ( $ typeCallback , $ row [ 0 ] ) ; } ; } else { $ this -> fetchCallback = function ( $ row ) use ( $ keys , $ typeCallbacks ) { return array_combine ( $ keys , array_map ( 'call_user_func' , $ typeCallbacks , $ row ) ) ; } ; } } elseif ( $ flatten ) { $ this -> fetchCallback = function ( $ row ) { return array_shift ( $ row ) ; } ; } else { $ this -> fetchCallback = function ( $ row ) { return $ row ; } ; } return true ; }
|
Build a row processing callback based on the TYPE_DETECT and row flattening
|
14,404
|
public function getFetchOptions ( & $ humanReadable = null ) { if ( func_num_args ( ) ) { $ humanReadable = [ ] ; $ refl = new \ ReflectionClass ( __CLASS__ ) ; foreach ( $ refl -> getConstants ( ) as $ name => $ value ) { if ( $ value & $ this -> fetchOptions and strpos ( $ name , 'DEFAULT' ) === false ) { $ humanReadable [ ] = $ name ; } } } return $ this -> fetchOptions ; }
|
Return the bitmask
|
14,405
|
public function fetch ( $ options = null , $ keyResultsByColumn = null ) { $ this -> setFetchOptions ( $ options ) ; if ( $ this -> fetchOptions & self :: CACHE ) { $ cacheKey = $ this -> fetchOptions & ( self :: TYPE_DETECT | self :: TYPE_AGNOSTIC | self :: FLATTEN_IF_POSSIBLE | self :: FLATTEN_PREVENT | self :: STYLE_ASSOC | self :: STYLE_NUM | self :: FETCH_SINGLE | self :: FETCH_MULTIPLE ) ; if ( isset ( $ this -> cacheFetch [ $ cacheKey ] ) ) { return $ this -> cacheFetch [ $ cacheKey ] ; } } $ output = array ( ) ; pg_result_seek ( $ this -> resource , 0 ) ; if ( null === $ keyResultsByColumn ) { while ( $ row = pg_fetch_array ( $ this -> resource , NULL , $ this -> fetchType ) ) { $ output [ ] = call_user_func ( $ this -> fetchCallback , $ row ) ; } } else { while ( $ row = pg_fetch_array ( $ this -> resource , NULL , $ this -> fetchType ) ) { $ row = call_user_func ( $ this -> fetchCallback , $ row ) ; $ output [ $ row [ $ keyResultsByColumn ] ] = $ row ; } } if ( ! isset ( $ this -> numRows ) ) { $ this -> numRows = count ( $ output ) ; } $ this -> fetchRowNumber = $ this -> numRows ; if ( $ this -> fetchOptions & self :: FETCH_SINGLE ) { if ( $ this -> numRows ( ) == 0 and $ this -> numFields ( ) > 1 ) { $ output = array ( ) ; } elseif ( $ this -> numRows ( ) <= 1 ) { $ output = array_pop ( $ output ) ; } else { throw new MoreThanOneRowReturnedException ( "{$this->numRows()} returned, FETCH_SINGLE doesn't apply here." ) ; } } if ( isset ( $ cacheKey ) ) { $ this -> cacheFetch [ $ cacheKey ] = $ output ; } return $ output ; }
|
Here be the magic!
|
14,406
|
public function getFieldTypeCallbacks ( ) { $ types = array ( ) ; $ numFields = $ this -> numFields ( ) ; for ( $ i = 0 ; $ i < $ numFields ; $ i ++ ) { $ types [ pg_field_name ( $ this -> resource , $ i ) ] = TypeConversionFactory :: get ( pg_field_type ( $ this -> resource , $ i ) , $ this ) ; } return $ types ; }
|
Return a array of php callbacks to be applied to a result set
|
14,407
|
public function getOption ( $ char = '' , $ name = '' , $ required = null ) { if ( ! $ char && ! $ name ) { return false ; } if ( $ char && ( 1 < strlen ( $ char ) || 1 !== preg_match ( '/^\w$/' , $ char ) ) ) { return false ; } if ( $ name && ( 1 !== preg_match ( '/^\w+$/' , $ name ) ) ) { return false ; } switch ( $ required ) { case true : $ char = $ char ? $ char . ':' : $ char ; $ name = $ name ? $ name . ':' : $ name ; break ; case false : $ char = $ char ? $ char . '::' : $ char ; $ name = $ name ? $ name . '::' : $ name ; break ; } $ argv = ( $ opts = getopt ( $ char , [ $ name ] ) ) ? array_shift ( $ opts ) : [ ] ; return is_array ( $ argv ) ? array_shift ( $ argv ) : $ argv ; }
|
Get arguments from command line
|
14,408
|
public function writeLines ( array $ bytes ) : int { $ bytesWritten = 0 ; foreach ( $ bytes as $ line ) { $ bytesWritten += $ this -> writeLine ( $ line ) ; } return $ bytesWritten ; }
|
writes given bytes and appends a line break after each one
|
14,409
|
protected function setDataEditSettings ( ) { $ header = $ this -> getData ( 'settings.header' ) ; if ( is_array ( $ header ) ) { $ string = '' ; foreach ( $ header as $ key => $ value ) { $ string .= "$key $value" . PHP_EOL ; } $ this -> setData ( 'settings.header' , trim ( $ string ) ) ; } }
|
Prepare data before rendering
|
14,410
|
protected function validateHeaderSettings ( ) { $ errors = $ header = array ( ) ; $ lines = gplcart_string_explode_multiline ( $ this -> getSubmitted ( 'header' , '' ) ) ; foreach ( $ lines as $ pos => $ line ) { $ pos ++ ; $ data = array_filter ( array_map ( 'trim' , explode ( ' ' , $ line , 2 ) ) ) ; if ( count ( $ data ) != 2 ) { $ errors [ ] = $ pos ; continue ; } list ( $ key , $ label ) = $ data ; if ( preg_match ( '/^[a-z_]+$/' , $ key ) !== 1 ) { $ errors [ ] = $ pos ; continue ; } $ header [ $ key ] = $ label ; } if ( empty ( $ errors ) ) { $ this -> setSubmitted ( 'header' , $ header ) ; } else { $ vars = array ( '@num' => implode ( ',' , $ errors ) ) ; $ this -> setError ( 'header' , $ this -> text ( 'Error on line @num' , $ vars ) ) ; } }
|
Validate header mapping
|
14,411
|
public static function addDecoder ( string $ class , string ... $ contentTypes ) { $ interface = decoder \ DecoderInterface :: class ; if ( ! is_subclass_of ( $ class , $ interface ) ) { throw new \ InvalidArgumentException ( "invalid value provided for 'class'; " . "expecting the name of a class that implements '$interface'" ) ; } foreach ( $ contentTypes as $ type ) { static :: $ decoders [ $ class ] = $ type ; } }
|
Replace existing decoders or add additional decoders
|
14,412
|
protected function getDecoder ( string $ stream , string $ contentType , int $ contentLength , decoder \ DecoderOptions $ options ) { $ type = \ sndsgd \ Str :: before ( $ contentType , ";" ) ; if ( ! isset ( static :: $ decoders [ $ type ] ) ) { throw new exception \ BadRequestException ( "failed to decode request body; " . "unknown content-type '$contentType'" ) ; } $ class = static :: $ decoders [ $ type ] ; return new $ class ( $ stream , $ contentType , $ contentLength , $ options ) ; }
|
Stubbable method for creating a decoder instance
|
14,413
|
private function checkMessage ( $ defMsg , array $ options ) { if ( is_array ( $ options ) && isset ( $ options [ 'message' ] ) ) return $ options [ 'message' ] ? $ options [ 'message' ] : null ; return $ defMsg ; }
|
Checks if a custom message exists or returns the default
|
14,414
|
public function required ( $ options ) { if ( ( is_array ( $ options ) || ( ! is_array ( $ options ) && $ options ) ) ) { if ( ( is_array ( $ this -> elementData ) && ( empty ( $ this -> elementData ) || ( empty ( $ this -> elementData [ 0 ] ) && count ( $ this -> elementData ) === 1 ) ) ) || ( ! is_array ( $ this -> elementData ) && trim ( $ this -> elementData ) === '' ) ) { if ( is_bool ( $ options ) ) $ this -> addError ( 'Field is required' ) ; else if ( is_array ( $ options ) && isset ( $ options [ 'message' ] ) ) { $ this -> addError ( $ options [ 'message' ] ) ; } else $ this -> addError ( ( ! is_array ( $ options ) && ! is_object ( $ options ) ) ? $ options : 'Field is required' ) ; return false ; } return true ; } return true ; }
|
Makes an element required
|
14,415
|
public function match ( array $ options ) { if ( isset ( $ options [ 'element' ] ) ) { if ( isset ( $ this -> data [ $ options [ 'element' ] ] ) ) { if ( $ this -> elementData == $ this -> data [ $ options [ 'element' ] ] ) { return true ; } } else { return true ; } } else if ( isset ( $ options [ 'value' ] ) ) { if ( $ this -> elementData == $ options [ 'value' ] ) { return true ; } } $ this -> addError ( $ this -> checkMessage ( 'Values mismatch' , $ options ) ) ; return false ; }
|
Checks if the value of the element matches the given option
|
14,416
|
public function email ( array $ options ) { if ( empty ( $ this -> elementData ) || filter_var ( $ this -> elementData , FILTER_VALIDATE_EMAIL ) ) { $ this -> elementData = filter_var ( $ this -> elementData , FILTER_SANITIZE_EMAIL ) ; return true ; } $ this -> addError ( $ this -> checkMessage ( 'Invalid email adddress' , $ options ) ) ; return false ; }
|
Checks if the value of the element is a valid email address
|
14,417
|
public function url ( array $ options ) { if ( empty ( $ this -> elementData ) || filter_var ( $ this -> elementData , FILTER_VALIDATE_URL ) ) { $ this -> elementData = filter_var ( $ this -> elementData , FILTER_SANITIZE_URL ) ; return true ; } $ this -> addError ( $ this -> checkMessage ( 'Value is not a valid url' , $ options ) ) ; return false ; }
|
Checks if the values of the element is a valid url
|
14,418
|
public function alpha ( array $ options ) { if ( ! $ options [ 'regex' ] ) $ options [ 'regex' ] = ( $ options [ 'acceptSpace' ] ) ? '/[^a-zA-Z\s]/' : '/[^a-zA-Z]/' ; if ( ! preg_match ( $ options [ 'regex' ] , $ this -> elementData ) ) return true ; $ this -> addError ( $ this -> checkMessage ( 'Value can only contain alphabets' , $ options ) ) ; return false ; }
|
Checks if the contents of the element are all alphabets
|
14,419
|
public function decimal ( array $ options ) { if ( ctype_digit ( $ this -> elementData ) ) return true ; $ this -> addError ( $ this -> checkMessage ( 'Value can only contain numbers and a dot' , $ options ) ) ; return false ; }
|
Checks if the content of the element is decimal
|
14,420
|
public function greaterThan ( array $ options ) { if ( isset ( $ options [ 'element' ] ) ) { if ( isset ( $ this -> data [ $ options [ 'element' ] ] ) ) { $ than = ' "' . $ this -> cleanElement ( $ options [ 'element' ] ) . '"' ; if ( $ this -> elementData > $ this -> data [ $ options [ 'element' ] ] || ( empty ( $ this -> elementData ) && $ this -> elementData !== 0 ) ) { return true ; } } } else if ( isset ( $ options [ 'value' ] ) ) { $ than = $ options [ 'value' ] ; if ( $ this -> elementData > $ options [ 'value' ] ) { return true ; } } $ this -> addError ( $ this -> checkMessage ( 'Value must be greater than ' . $ than , $ options ) ) ; return false ; }
|
Checks if the value of the element is greater than the given value
|
14,421
|
public function lessThan ( array $ options ) { if ( isset ( $ options [ 'element' ] ) ) { if ( isset ( $ this -> data [ $ options [ 'element' ] ] ) ) { $ than = ' "' . $ this -> cleanElement ( $ options [ 'element' ] ) . '"' ; if ( $ this -> elementData < $ this -> data [ $ options [ 'element' ] ] ) { return true ; } } } else if ( isset ( $ options [ 'value' ] ) ) { $ than = $ options [ 'value' ] ; if ( $ this -> elementData < $ options [ 'value' ] ) { return true ; } } $ this -> addError ( $ this -> checkMessage ( 'Value must be less than ' . $ than , $ options ) ) ; return false ; }
|
Checks if the value of the element is less than the given value
|
14,422
|
public function minLength ( array $ options ) { if ( $ options [ 'value' ] && strlen ( $ this -> elementData ) >= $ options [ 'value' ] ) return true ; $ this -> addError ( $ this -> checkMessage ( 'Length must not be less than ' . $ options [ 'value' ] , $ options ) ) ; return false ; }
|
Checks if the length of the value of the element is not less than the required length
|
14,423
|
public function main ( ) { $ this -> out ( 'CodeBlastr Queue Plugin:' ) ; $ this -> hr ( ) ; $ this -> out ( 'Usage:' ) ; $ this -> out ( ' cake CodeBlastr.Queue help' ) ; $ this -> out ( ' -> Display this Help message' ) ; $ this -> out ( ' cake Queue.Queue runworker' ) ; $ this -> out ( ' -> run a queue worker, which will look for a pending task it can execute.' ) ; $ this -> out ( ' -> the worker will always try to find jobs matching its installed Tasks' ) ; $ this -> out ( ' -> see "Available Tasks" below.' ) ; $ this -> out ( ' cake Queue.Queue runworker' ) ; $ this -> out ( ' -> run a queue worker, which will look for a pending task it can execute.' ) ; $ this -> out ( ' -> the worker will always try to find jobs matching its installed Tasks' ) ; $ this -> out ( ' -> see "Available Tasks" below.' ) ; $ this -> out ( ' cake Queue.Queue stats' ) ; $ this -> out ( ' -> Display some general Statistics.' ) ; $ this -> out ( ' cake Queue.Queue clean' ) ; $ this -> out ( ' -> Manually call cleanup function to delete task data of completed tasks.' ) ; }
|
Output some basic usage Info .
|
14,424
|
public final function dispose ( ) { if ( $ this -> disposed ) { return ; } if ( \ is_resource ( $ this -> r ) ) { \ imagedestroy ( $ this -> r ) ; } $ this -> r = null ; $ this -> size = null ; $ this -> colors = [ ] ; $ this -> mimeType = null ; $ this -> _file = null ; $ this -> disposed = true ; }
|
Disposes the current image resource .
|
14,425
|
public final function output ( int $ quality = 60 , string $ filename = null ) { \ header ( 'Expires: 0' ) ; \ header ( 'Cache-Control: private' ) ; \ header ( 'Pragma: cache' ) ; if ( empty ( $ filename ) ) { $ filename = \ basename ( $ this -> _file ) ; } else { $ filename = \ basename ( $ filename ) ; } if ( ! empty ( $ filename ) ) { \ header ( "Content-Disposition: inline; filename=\"{$filename}\"" ) ; $ mime = MimeTypeTool :: GetByFileName ( $ filename ) ; \ header ( "Content-Type: {$mime}" ) ; switch ( $ mime ) { case 'image/png' : \ imagepng ( $ this -> r ) ; break ; case 'image/gif' : \ imagegif ( $ this -> r ) ; break ; default : \ imagejpeg ( $ this -> r , null , $ quality ) ; break ; } exit ; } \ header ( "Content-Type: {$this->mimeType}" ) ; switch ( $ this -> mimeType ) { case 'image/png' : \ imagepng ( $ this -> r ) ; break ; case 'image/gif' : \ imagegif ( $ this -> r ) ; break ; default : \ imagejpeg ( $ this -> r , null , $ quality ) ; break ; } exit ; }
|
Outputs the current image including all required HTTP headers and exit the script .
|
14,426
|
public final function negate ( bool $ internal = false ) : GdImage { if ( ! $ internal ) { $ clon = clone $ this ; return $ clon -> negate ( true ) ; } $ w = $ this -> getWidth ( ) ; $ h = $ this -> getHeight ( ) ; $ im = \ imagecreatetruecolor ( $ w , $ h ) ; for ( $ y = 0 ; $ y < $ h ; ++ $ y ) { for ( $ x = 0 ; $ x < $ w ; $ x ++ ) { $ colors = \ imagecolorsforindex ( $ this -> r , \ imagecolorat ( $ this -> r , $ x , $ y ) ) ; $ r = 255 - $ colors [ 'red' ] ; $ g = 255 - $ colors [ 'green' ] ; $ b = 255 - $ colors [ 'blue' ] ; $ newColor = \ imagecolorallocate ( $ im , $ r , $ g , $ b ) ; \ imagesetpixel ( $ im , $ x , $ y , $ newColor ) ; } } \ imagedestroy ( $ this -> r ) ; $ this -> r = null ; $ this -> r = $ im ; return $ this ; }
|
Creates a negative of current image .
|
14,427
|
public final function cropRect ( Rectangle $ rect , bool $ internal = true ) : IImage { $ thumb = \ imagecreatetruecolor ( $ rect -> size -> getWidth ( ) , $ rect -> size -> getHeight ( ) ) ; if ( $ this -> mimeType == 'image/gif' || $ this -> mimeType == 'image/png' ) { \ imagealphablending ( $ thumb , false ) ; \ imagesavealpha ( $ thumb , true ) ; } \ imagecopyresampled ( $ thumb , $ this -> r , 0 , 0 , $ rect -> point -> x , $ rect -> point -> y , $ rect -> size -> getWidth ( ) , $ rect -> size -> getHeight ( ) , $ rect -> size -> getWidth ( ) , $ rect -> size -> getHeight ( ) ) ; if ( $ internal ) { $ this -> size -> setHeight ( $ rect -> size -> getHeight ( ) ) ; $ this -> size -> setWidth ( $ rect -> size -> getWidth ( ) ) ; if ( \ is_resource ( $ this -> r ) ) { \ imagedestroy ( $ this -> r ) ; $ this -> r = null ; } $ this -> r = $ thumb ; return $ this ; } return new GdImage ( $ thumb , $ rect -> size , $ this -> mimeType , $ this -> _file ) ; }
|
Crop the defined image part and returns the current or new image instance .
|
14,428
|
public final function contract ( int $ percent , bool $ internal = true ) : IImage { if ( $ percent < 1 || $ percent >= 100 ) { throw new ArgumentError ( 'percent' , $ percent , 'Drawing.Image' , 'Image dimension contraction must produce a smaller, non zero sized image!' ) ; } $ newWidth = \ intval ( \ floor ( $ this -> getWidth ( ) * $ percent / 100 ) ) ; $ newHeight = \ intval ( \ floor ( $ this -> getHeight ( ) * $ percent / 100 ) ) ; if ( $ this -> isTrueColor ( ) ) { $ dst = \ imagecreatetruecolor ( $ newWidth , $ newHeight ) ; } else { $ dst = \ imagecreate ( $ newWidth , $ newHeight ) ; } if ( $ this -> canUseTransparency ( ) ) { \ imagealphablending ( $ dst , false ) ; \ imagesavealpha ( $ dst , true ) ; } \ imagecopyresized ( $ dst , $ this -> r , 0 , 0 , 0 , 0 , $ newWidth , $ newHeight , $ this -> getWidth ( ) , $ this -> getHeight ( ) ) ; if ( $ internal ) { if ( ! \ is_null ( $ this -> r ) ) { \ imagedestroy ( $ this -> r ) ; $ this -> r = null ; } $ this -> r = $ dst ; $ this -> size -> setWidth ( $ newWidth ) ; $ this -> size -> setHeight ( $ newHeight ) ; return $ this ; } return new GdImage ( $ dst , new Size ( $ newWidth , $ newHeight ) , $ this -> mimeType , $ this -> _file ) ; }
|
Reduce the original image size by the specified percentage value .
|
14,429
|
public final function contractToMaxSize ( Size $ maxsize , bool $ internal = true ) : IImage { if ( $ maxsize -> getWidth ( ) >= $ this -> size -> getWidth ( ) && $ maxsize -> getHeight ( ) >= $ this -> size -> getHeight ( ) ) { return $ this -> returnSelf ( $ internal ) ; } $ newSize = new Size ( $ this -> size -> getWidth ( ) , $ this -> size -> getHeight ( ) ) ; $ newSize -> reduceToMaxSize ( $ maxsize ) ; return $ this -> createImageAfterResize ( $ newSize , $ internal ) ; }
|
Reduce the original image size by holding the image size proportion to fit best the declared maximum size .
|
14,430
|
public final function drawSingleBorder ( $ borderColor , bool $ internal = true ) : IImage { $ borderColor = $ this -> getGdColorObject ( $ borderColor , 'bordercolor' ) ; if ( $ internal ) { \ imagerectangle ( $ this -> r , 1 , 1 , $ this -> getWidth ( ) - 2 , $ this -> getHeight ( ) - 2 , $ borderColor -> getGdValue ( ) ) ; return $ this ; } $ res = clone $ this ; \ imagerectangle ( $ res -> r , 1 , 1 , $ this -> getWidth ( ) - 2 , $ this -> getHeight ( ) - 2 , $ borderColor -> getGdValue ( ) ) ; return $ res ; }
|
Draws a single border with defined color around the image .
|
14,431
|
public final function drawDoubleBorder ( $ innerBorderColor , $ outerBorderColor , bool $ internal = true ) : IImage { $ innerBorderColor = $ this -> getGdColorObject ( $ innerBorderColor , 'bordercolor' ) ; $ outerBorderColor = $ this -> getGdColorObject ( $ outerBorderColor , 'outerbordercolor' ) ; if ( $ internal ) { \ imagerectangle ( $ this -> r , 0 , 0 , $ this -> getWidth ( ) - 1 , $ this -> getHeight ( ) - 1 , $ outerBorderColor -> getGdValue ( ) ) ; \ imagerectangle ( $ this -> r , 1 , 1 , $ this -> getWidth ( ) - 2 , $ this -> getHeight ( ) - 2 , $ innerBorderColor -> getGdValue ( ) ) ; return $ this ; } $ res = clone $ this ; \ imagerectangle ( $ res -> r , 0 , 0 , $ this -> getWidth ( ) - 1 , $ this -> getHeight ( ) - 1 , $ outerBorderColor -> getGdValue ( ) ) ; \ imagerectangle ( $ res -> r , 1 , 1 , $ this -> getWidth ( ) - 2 , $ this -> getHeight ( ) - 2 , $ innerBorderColor -> getGdValue ( ) ) ; return $ res ; }
|
Draws a double border with defined colors around the image .
|
14,432
|
public final function drawText ( string $ text , $ font , $ fontSize , $ color , Point $ point , bool $ internal = true ) : IImage { $ color = $ this -> getGdColorObject ( $ color , 'textcolor' ) ; if ( ! empty ( $ font ) && \ file_exists ( $ font ) ) { if ( $ internal ) { \ imagettftext ( $ this -> r , $ fontSize , 0 , $ point -> x , $ point -> y , $ color -> getGdValue ( ) , $ font , $ text ) ; return $ this ; } $ res = clone $ this ; \ imagettftext ( $ res -> r , $ fontSize , 0 , $ point -> x , $ point -> y , $ color -> getGdValue ( ) , $ font , $ text ) ; return $ res ; } if ( $ internal ) { \ imagestring ( $ this -> r , $ fontSize , $ point -> x , $ point -> y , $ text , $ color -> getGdValue ( ) ) ; return $ this ; } $ res = clone $ this ; \ imagestring ( $ res -> r , $ fontSize , $ point -> x , $ point -> y , $ text , $ color -> getGdValue ( ) ) ; return $ res ; }
|
Draws a text at declared position into current image .
|
14,433
|
public function commit ( ) { if ( $ this -> _initialized && $ this -> _dirty ) { $ this -> _saveCache ( ) ; $ this -> _dirty = false ; } }
|
Commit cache content updates to storage
|
14,434
|
protected function redirectToRoute ( string $ route , $ parameters = [ ] , int $ status = 302 ) : RedirectResponse { return $ this -> redirect ( $ this -> generateUrl ( $ route , $ parameters ) , $ status ) ; }
|
Returns a RedirectResponse to the given route with the given parameters . Overwrites Controller - trait to allow parameters as object as well .
|
14,435
|
protected function isDeletable ( $ object ) : bool { $ em = $ this -> getEntityManager ( ) ; $ em -> beginTransaction ( ) ; try { if ( $ object instanceof SoftDeleteableInterface ) { $ object -> setDeletedAt ( new \ DateTime ( ) ) ; } $ em -> remove ( $ object ) ; $ em -> flush ( ) ; $ em -> rollback ( ) ; return true ; } catch ( ForeignKeyConstraintViolationException $ exception ) { $ em -> rollback ( ) ; return false ; } }
|
Tries to delete an object without actually deleting it . Returns false if ForeignKeyConstraintViolationException would be thrown ; true otherwise .
|
14,436
|
public function createFromFile ( $ file ) { if ( ! $ file || ! file_exists ( $ file ) ) { throw new \ Exception ( "Configuration file \"{$file}\" could not be found." ) ; } $ config = @ include ( $ file ) ; if ( ! $ config ) { throw new \ Exception ( "Configuration file \"{$file}\" could not be included." ) ; } $ this -> useAuthorization = $ config [ 'useAuthorization' ] ; $ this -> authorizationMode = $ config [ 'authorizationMode' ] ; $ this -> redirectAuthorization = $ config [ 'redirectAuthorization' ] ; $ this -> authorizationForm = $ config [ 'authorizationForm' ] ; $ this -> dsn = $ config [ 'dsn' ] ; $ this -> username = $ config [ 'username' ] ; $ this -> password = $ config [ 'password' ] ; $ this -> responseType = $ config [ 'responseType' ] ; $ this -> clientResponseType = $ config [ 'clientResponseType' ] ; return $ this ; }
|
Creates a configuration object by loading the parameters from a file . This file has to be a PHP file returning an array with the parameters .
|
14,437
|
public static function TryParseArray ( & $ refLocale , array $ requestData , array $ acceptedKeys = [ 'locale' , 'language' , 'lang' , 'loc' , 'lc' , 'lng' ] ) : bool { if ( \ count ( $ requestData ) < 1 ) { return false ; } $ requestData = \ array_change_key_case ( $ requestData , \ CASE_LOWER ) ; $ acceptedKeys = \ array_change_key_case ( $ acceptedKeys , \ CASE_LOWER ) ; $ language = null ; foreach ( $ acceptedKeys as $ key ) { if ( ! isset ( $ requestData [ $ key ] ) ) { continue ; } $ language = \ trim ( $ requestData [ 'language' ] ) ; break ; } if ( empty ( $ language ) ) { return false ; } if ( ! \ preg_match ( '~^([a-zA-Z]{2})([_-]([a-zA-Z]{2}))?~' , $ language , $ matches ) ) { return false ; } $ lid = \ strtolower ( $ matches [ 1 ] ) ; $ cid = empty ( $ matches [ 2 ] ) ? null : \ strtoupper ( $ matches [ 3 ] ) ; $ refLocale = new Locale ( $ lid , $ cid ) ; return true ; }
|
Tries to create a new Locale instance from defined array . It accepts one of the following array keys to declare an
|
14,438
|
public function get ( array $ adapters , CacheableInterface $ item ) { foreach ( $ adapters as $ adapter ) { try { return $ adapter -> get ( $ item ) ; } catch ( \ Exception $ e ) { continue ; } } throw new UnhandledCacheException ( 'No cache system is available' ) ; }
|
Get cache from first up adapter
|
14,439
|
public function remove ( array $ adapters , CacheableInterface $ item ) { foreach ( $ adapters as $ adapter ) { $ adapter -> remove ( $ item ) ; } }
|
Remove cache from all adapters
|
14,440
|
public function queueUnresolvedObjects ( $ data , $ relations ) { if ( is_object ( $ data ) ) { if ( $ data instanceof Model ) { $ data = $ data -> getData ( ) ; } if ( ! $ this -> resolved ( $ data ) ) { $ this -> addToQueue ( $ data , $ relations ) ; return ; } $ data = get_object_vars ( $ data ) ; } if ( is_array ( $ data ) ) { foreach ( $ data as $ key => $ value ) { if ( is_int ( $ key ) ) { $ this -> queueUnresolvedObjects ( $ value , $ relations ) ; } if ( $ this -> hasRelation ( $ key , $ relations ) ) { $ nestedRelations = $ this -> getNestedRelations ( $ key , $ relations ) ; $ this -> queueUnresolvedObjects ( $ value , $ nestedRelations ) ; } } } }
|
Add unresovled objects to load queue
|
14,441
|
protected function resolved ( $ obj ) { if ( ! is_object ( $ obj ) ) { return true ; } $ data = get_object_vars ( $ obj ) ; if ( count ( $ data ) == 2 && array_key_exists ( 'id' , $ data ) && array_key_exists ( 'type' , $ data ) ) { return false ; } return true ; }
|
Check if object is resolved
|
14,442
|
protected function addToQueue ( $ object , $ relations ) { if ( ! array_key_exists ( $ object -> type , self :: $ loadQueue ) ) { self :: $ loadQueue [ $ object -> type ] = [ ] ; } $ relationsKey = base64_encode ( json_encode ( $ relations ) ) ; if ( ! array_key_exists ( $ relationsKey , self :: $ loadQueue [ $ object -> type ] ) ) { self :: $ loadQueue [ $ object -> type ] [ $ relationsKey ] = [ 'type' => $ object -> type , 'ids' => [ ] , 'relations' => $ relations ] ; } self :: $ loadQueue [ $ object -> type ] [ $ relationsKey ] [ 'ids' ] [ ] = $ object -> id ; }
|
Add object to loadQueue if it s specified in relations
|
14,443
|
protected function _scheduleVars ( ) { global $ argv ; $ path = $ argv [ 2 ] . DS ; $ shellName = $ argv [ 3 ] ; $ taskName = $ argv [ 4 ] ; if ( isset ( $ this -> args [ 0 ] ) && $ this -> hasMethod ( $ this -> args [ 0 ] ) ) { $ methodName = $ this -> args [ 0 ] ; array_shift ( $ this -> args ) ; } else { $ methodName = null ; } $ command = implode ( ' ' , array_filter ( array ( 'Console/cake' , $ shellName , $ taskName , $ methodName ) ) ) ; $ arguments = $ this -> args ; foreach ( $ this -> params as $ name => $ value ) { if ( in_array ( $ name , array ( 'scheduled' , 'scheduled-depends-on' , 'scheduled-wait-prev' , 'skip-unlogged' , 'scheduled-process-timeout' ) , true ) ) { continue ; } if ( is_bool ( $ value ) && $ value ) { $ arguments [ ] = '--' . $ name ; } elseif ( ! is_bool ( $ value ) ) { $ arguments [ '--' . $ name ] = $ value ; } } $ options = array ( 'timeout' => $ this -> params [ 'scheduled-process-timeout' ] , 'dependsOn' => empty ( $ this -> params [ 'scheduled-depends-on' ] ) ? array ( ) : explode ( ',' , $ this -> params [ 'scheduled-depends-on' ] ) ) ; return array ( $ command , $ path , $ arguments , $ options ) ; }
|
Returns variables for schedule
|
14,444
|
protected function _schedule ( $ command , $ path , array $ arguments , array $ options ) { $ TaskClient = ClassRegistry :: init ( 'Task.TaskClient' ) ; $ task = $ TaskClient -> add ( $ command , $ path , $ arguments , $ options ) ; if ( $ task ) { $ waitFor = empty ( $ options [ 'dependsOn' ] ) ? 'none' : implode ( ', ' , $ options [ 'dependsOn' ] ) . ' task(s)' ; $ this -> out ( "Task #{$TaskClient->id} successfuly added, wait for $waitFor" ) ; } else { $ this -> err ( 'Error! Task not added!' ) ; } return $ task ; }
|
Adds script to sceduler
|
14,445
|
protected function _getInterval ( $ interval ) { if ( $ interval !== null ) { return $ interval ; } elseif ( ! empty ( $ this -> params [ 'interval' ] ) ) { return $ this -> params [ 'interval' ] ; } else { return '1 day' ; } }
|
Returns interval value specified by parameter or default value
|
14,446
|
public function getTaxesAmounts ( ) { $ amounts = new TaxesAmounts ( ) ; $ amounts -> addTaxAmount ( new TaxAmount ( $ this -> tax , $ this -> getTaxAmount ( ) ) ) ; return $ amounts ; }
|
Returns the taxes amounts .
|
14,447
|
public function config ( $ parameter ) { $ value = $ this -> configService -> getParameter ( $ parameter ) ; return is_array ( $ value ) ? json_encode ( $ value ) : $ value ; }
|
Returns the specified parameter
|
14,448
|
public function actionGetPaymentMethodInfo ( $ id ) { if ( \ Yii :: $ app -> request -> isAjax ) { if ( ! empty ( $ id ) ) { $ method = PaymentMethod :: findOne ( $ id ) ; $ methodTranslation = $ method -> translation ; $ method = ArrayHelper :: toArray ( $ method ) ; $ method [ 'translation' ] = ArrayHelper :: toArray ( $ methodTranslation ) ; $ method [ 'image' ] = '/images/payment/' . FileHelper :: getFullName ( \ Yii :: $ app -> shop_imagable -> get ( 'payment' , 'small' , $ method [ 'image' ] ) ) ; return json_encode ( [ 'paymentMethod' => $ method , ] ) ; } } throw new NotFoundHttpException ( ) ; }
|
Returns payment method model if request is Ajax .
|
14,449
|
public static function getItem ( $ namespace , $ key ) { if ( isset ( static :: $ _STORAGE [ $ namespace ] ) ) { if ( isset ( static :: $ _STORAGE [ $ namespace ] [ $ key ] ) ) { return static :: $ _STORAGE [ $ namespace ] [ $ key ] ; } } return NULL ; }
|
Get an Item from the Static Storage array
|
14,450
|
public static function setItem ( $ namespace , $ key , $ value ) { if ( ! isset ( static :: $ _STORAGE [ $ namespace ] ) ) { static :: $ _STORAGE [ $ namespace ] = array ( ) ; } static :: $ _STORAGE [ $ namespace ] [ $ key ] = $ value ; return TRUE ; }
|
Set an Item in the Static Storage array for a particular Namespace
|
14,451
|
public function addErrors ( Collection $ errors ) { $ this -> errors = $ this -> getErrors ( ) -> merge ( $ errors ) ; return $ this ; }
|
Add errors .
|
14,452
|
protected function createItem ( $ key ) { $ this -> validateKey ( $ key ) ; if ( is_callable ( $ this -> item_factory ) ) { $ func = $ this -> item_factory ; $ item = $ func ( $ key , $ this , $ this -> item_config ) ; } else { $ item = new CacheItem ( $ key , $ this , $ this -> item_config ) ; } return $ item ; }
|
Create item object
|
14,453
|
public function toArray ( ) { $ classData = [ ] ; foreach ( $ this -> getReflector ( ) -> getProperties ( \ ReflectionProperty :: IS_PROTECTED ) as $ reflectionProperty ) { if ( ! $ reflectionProperty -> isStatic ( ) ) { $ reflectionProperty -> setAccessible ( true ) ; $ classData [ $ reflectionProperty -> getName ( ) ] = $ reflectionProperty -> getValue ( $ this ) ; } } return $ classData ; }
|
Fetch the array representation of the protected properties of an object .
|
14,454
|
public function fromArray ( array $ source ) { foreach ( $ this -> getReflector ( ) -> getProperties ( \ ReflectionProperty :: IS_PROTECTED ) as $ reflectionProperty ) { if ( ! $ reflectionProperty -> isStatic ( ) && isset ( $ source [ $ reflectionProperty -> getName ( ) ] ) ) { $ reflectionProperty -> setAccessible ( true ) ; $ reflectionProperty -> setValue ( $ this , $ source [ $ reflectionProperty -> getName ( ) ] ) ; } } return $ this ; }
|
Set protected propertie according to provided source .
|
14,455
|
public function getFieldsConfig ( ) { if ( null === $ this -> fieldsConfigList ) { $ this -> fieldsConfigList = [ ] ; foreach ( $ this -> getFields ( ) as $ field ) { $ reflectionProperty = $ this -> getReflector ( ) -> getProperty ( $ field ) ; $ docBlock = $ reflectionProperty -> getDocComment ( ) ; preg_match ( '/@var\s([a-z]*).*/' , $ docBlock , $ matches ) ; $ this -> fieldsConfigList [ $ field ] = [ 'type' => isset ( $ matches [ 1 ] ) ? $ matches [ 1 ] : null ] ; } } return $ this -> fieldsConfigList ; }
|
Fetch the var metadata for a field and store it in the config .
|
14,456
|
public function getFieldType ( $ field ) { return isset ( $ this -> getFieldsConfig ( ) [ $ field ] ) ? $ this -> getFieldsConfig ( ) [ $ field ] [ 'type' ] : null ; }
|
Fetch a field type according to var metadata .
|
14,457
|
public function getUrlAttribute ( $ suffix = '' ) { if ( ! $ this -> exists ) { return Cache :: rememberForever ( 'missing_photo' , function ( ) { return static :: placeholder ( 'No photo provided' ) ; } ) ; } if ( ! $ this -> processed ) { return Cache :: rememberForever ( 'processing_photo' , function ( ) { return static :: placeholder ( "This photo is\nbeing processed\nand will appear\nshortly" ) ; } ) ; } return "/photo/{$this->photoId}$suffix.jpg" ; }
|
Return the public URL for the photo .
|
14,458
|
public function delete ( ) { $ disk = Storage :: disk ( config ( 'mustard.storage.disk' , 'local' ) ) ; $ disk -> delete ( $ this -> getPath ( ) ) ; $ disk -> delete ( $ this -> getSmallPath ( ) ) ; $ disk -> delete ( $ this -> getLargePath ( ) ) ; parent :: delete ( ) ; }
|
Delete the record and data from the filesystem .
|
14,459
|
private static function placeholder ( $ text ) { $ image_manager = new ImageManager ( [ 'driver' => 'imagick' ] ) ; $ image = $ image_manager -> canvas ( 640 , 480 , '#efefef' ) ; $ image -> text ( $ text , 320 , 240 - ( 70 * substr_count ( $ text , "\n" ) ) , function ( $ font ) { $ font -> file ( base_path ( 'vendor/webfontkit/open-sans/fonts/opensans-regular.woff' ) ) ; $ font -> size ( 60 ) ; $ font -> color ( '#cbcbcb' ) ; $ font -> align ( 'center' ) ; $ font -> valign ( 'center' ) ; } ) ; $ image_data = ( string ) $ image -> encode ( 'gif' ) ; return 'data:image/gif;base64,' . base64_encode ( $ image_data ) ; }
|
Return a placeholder image containing the provided text .
|
14,460
|
public static function upload ( $ file ) { $ photo = self :: create ( ) ; $ image_manager = new ImageManager ( [ 'driver' => 'imagick' ] ) ; $ disk = Storage :: disk ( config ( 'mustard.storage.disk' , 'local' ) ) ; if ( ! file_exists ( $ file ) ) { RuntimeException ( "File $file does not exist" ) ; } $ dest_dir = config ( 'mustard.storage.photo.dir' , 'mustard/photos' ) ; $ quality = config ( 'mustard.storage.photo.quality' , 90 ) ; $ disk -> makeDirectory ( $ dest_dir ) ; $ photo_id = $ photo -> getKey ( ) ; Queue :: push ( function ( $ job ) use ( $ file , $ quality , $ dest_dir , $ photo_id ) { if ( ! file_exists ( $ file ) ) { RuntimeException ( "File $file no longer exists" ) ; } $ image_manager = new ImageManager ( [ 'driver' => 'imagick' ] ) ; $ disk = Storage :: disk ( config ( 'mustard.storage.disk' , 'local' ) ) ; if ( $ file != "$dest_dir/$photo_id.jpg" ) { $ image = $ image_manager -> make ( $ file ) ; $ disk -> put ( "$dest_dir/$photo_id.jpg" , ( string ) $ image -> encode ( 'jpg' , $ quality ) ) ; $ image -> destroy ( ) ; } $ image = $ image_manager -> make ( $ file ) -> heighten ( 83 ) ; $ disk -> put ( "$dest_dir/{$photo_id}_s.jpg" , ( string ) $ image -> encode ( 'jpg' , $ quality ) ) ; $ image -> destroy ( ) ; $ image = $ image_manager -> make ( $ file ) -> widen ( 500 ) ; $ disk -> put ( "$dest_dir/{$photo_id}_l.jpg" , ( string ) $ image -> encode ( 'jpg' , $ quality ) ) ; $ image -> destroy ( ) ; $ photo = Photo :: find ( $ photo_id ) ; $ photo -> processed = true ; $ photo -> save ( ) ; $ job -> delete ( ) ; } ) ; return $ photo ; }
|
Process a photo and create a record .
|
14,461
|
public function boot ( ) { $ source = realpath ( $ raw = __DIR__ . '/Config.php' ) ? : $ raw ; if ( $ this -> app instanceof LaravelApplication && $ this -> app -> runningInConsole ( ) ) { $ this -> publishes ( [ $ source => config_path ( 'mutex.php' ) ] ) ; } elseif ( $ this -> app instanceof LumenApplication ) { $ this -> app -> configure ( 'mutex' ) ; } $ this -> mergeConfigFrom ( $ source , 'mutex' ) ; }
|
Bootstrap the configuration
|
14,462
|
public static function find ( array $ query ) { $ employees = Client :: get ( "employee" , $ query ) ; return array_map ( function ( $ data ) { return new self ( $ data ) ; } , $ employees ) ; }
|
Retrieve an array of Employee objects according to a search query .
|
14,463
|
public function getWorkPhone ( ) { if ( ! isset ( $ this -> workPhone ) ) { $ wp = trim ( $ this -> getRawWorkPhone ( ) ) ; if ( empty ( $ wp ) ) { $ this -> workPhone = null ; } else { if ( preg_match ( '/^\+?[-\d\s()]+/' , $ wp , $ matches ) ) { $ wp = $ matches [ 0 ] ; $ wp = trim ( str_replace ( [ '(' , ')' ] , '' , $ wp ) ) ; if ( strlen ( str_replace ( ' ' , '' , $ wp ) ) === 4 ) { $ wp = self :: phonePrefixForExt ( $ wp ) . $ wp ; } if ( $ wp [ 0 ] !== '0' && $ wp [ 0 ] !== '+' ) { $ wp = '08' . $ wp ; } $ phoneUtil = \ libphonenumber \ PhoneNumberUtil :: getInstance ( ) ; try { $ this -> workPhone = $ phoneUtil -> parse ( $ wp , 'SE' ) ; } catch ( \ libphonenumber \ NumberParseException $ e ) { $ this -> workPhone = $ this -> getRawWorkPhone ( ) ; } } else { $ this -> workPhone = $ this -> getRawWorkPhone ( ) ; } } } return $ this -> workPhone ; }
|
Get work phone number of this employee . Try to parse it to a PhoneNumber otherwise return the raw string .
|
14,464
|
public function find ( $ id , $ scopes = [ ] ) { return $ this -> _get ( 'servers/' . $ this -> server_id . '/software/' . $ id , null , $ scopes ) ; }
|
Gets a single software object on the server
|
14,465
|
public function exploits ( $ scopes = [ ] ) { if ( ! $ this -> id ) { throw new Exception ( "The software has no ID, can\'t get exploits" ) ; } if ( ! $ this -> server_id ) { throw new Exception ( "The software has no server ID, can\'t get exploits" ) ; } $ exploit = new Exploit ( $ this -> patrol ) ; $ exploit -> defaults ( [ 'software_id' => $ this -> id , 'server_id' => $ this -> server_id ] ) ; return $ exploit -> all ( ) ; }
|
Gets a list of exploits from this software
|
14,466
|
protected function __valueSet ( $ key , $ value ) { if ( $ key === "exploits" ) { $ casted = [ ] ; foreach ( $ value as $ exploit ) { $ casted [ ] = new Exploit ( $ this -> patrol , $ exploit ) ; } return $ casted ; } return $ value ; }
|
This is a casting hook when a new value is set in PatrolModel this hook will be called in this case when exploits are set in the model cast them to a PatrolSdk \ Exploit object
|
14,467
|
protected function deduplicate ( $ lines ) { $ unique = array ( ) ; $ comments = array ( ) ; foreach ( $ lines as $ line ) { if ( strpos ( $ line , '/*' ) === 0 ) { $ comments [ ] = $ line ; continue ; } if ( ! in_array ( $ line , $ unique ) ) { $ unique [ ] = $ line ; } array_splice ( $ unique , array_search ( $ line , $ unique ) , 0 , $ comments ) ; $ comments = array ( ) ; } return array_merge ( $ unique , $ comments ) ; }
|
Deduplicate lines in a block . Comments are not deduplicated . If a duplicate rule is detected the comments immediately preceding each occurence are consolidated .
|
14,468
|
protected function findBlocks ( $ searchIn , $ path , $ orderedArgs , $ keywordArgs , $ seen = array ( ) ) { if ( $ searchIn == null ) return null ; if ( isset ( $ seen [ $ searchIn -> id ] ) ) return null ; $ seen [ $ searchIn -> id ] = true ; $ name = $ path [ 0 ] ; if ( isset ( $ searchIn -> children [ $ name ] ) ) { $ blocks = $ searchIn -> children [ $ name ] ; if ( count ( $ path ) == 1 ) { $ matches = $ this -> patternMatchAll ( $ blocks , $ orderedArgs , $ keywordArgs , $ seen ) ; if ( ! empty ( $ matches ) ) { return $ matches ; } } else { $ matches = array ( ) ; foreach ( $ blocks as $ subBlock ) { $ subMatches = $ this -> findBlocks ( $ subBlock , array_slice ( $ path , 1 ) , $ orderedArgs , $ keywordArgs , $ seen ) ; if ( ! is_null ( $ subMatches ) ) { foreach ( $ subMatches as $ sm ) { $ matches [ ] = $ sm ; } } } return count ( $ matches ) > 0 ? $ matches : null ; } } if ( $ searchIn -> parent === $ searchIn ) return null ; return $ this -> findBlocks ( $ searchIn -> parent , $ path , $ orderedArgs , $ keywordArgs , $ seen ) ; }
|
attempt to find blocks matched by path and args
|
14,469
|
protected function lib_data_uri ( $ value ) { $ mime = ( $ value [ 0 ] === 'list' ) ? $ value [ 2 ] [ 0 ] [ 2 ] : null ; $ url = ( $ value [ 0 ] === 'list' ) ? $ value [ 2 ] [ 1 ] [ 2 ] [ 0 ] : $ value [ 2 ] [ 0 ] ; $ fullpath = $ this -> findImport ( $ url ) ; if ( $ fullpath && ( $ fsize = filesize ( $ fullpath ) ) !== false ) { if ( $ fsize / 1024 < 32 ) { if ( is_null ( $ mime ) ) { if ( class_exists ( 'finfo' ) ) { $ finfo = new finfo ( FILEINFO_MIME ) ; $ mime = explode ( '; ' , $ finfo -> file ( $ fullpath ) ) ; $ mime = $ mime [ 0 ] ; } elseif ( function_exists ( 'mime_content_type' ) ) { $ mime = mime_content_type ( $ fullpath ) ; } } if ( ! is_null ( $ mime ) ) $ url = sprintf ( 'data:%s;base64,%s' , $ mime , base64_encode ( file_get_contents ( $ fullpath ) ) ) ; } } return 'url("' . $ url . '")' ; }
|
Given an url decide whether to output a regular link or the base64 - encoded contents of the file
|
14,470
|
protected function toRGB ( $ color ) { if ( $ color [ 0 ] == 'color' ) return $ color ; $ H = $ color [ 1 ] / 360 ; $ S = $ color [ 2 ] / 100 ; $ L = $ color [ 3 ] / 100 ; if ( $ S == 0 ) { $ r = $ g = $ b = $ L ; } else { $ temp2 = $ L < 0.5 ? $ L * ( 1.0 + $ S ) : $ L + $ S - $ L * $ S ; $ temp1 = 2.0 * $ L - $ temp2 ; $ r = $ this -> toRGB_helper ( $ H + 1 / 3 , $ temp1 , $ temp2 ) ; $ g = $ this -> toRGB_helper ( $ H , $ temp1 , $ temp2 ) ; $ b = $ this -> toRGB_helper ( $ H - 1 / 3 , $ temp1 , $ temp2 ) ; } $ out = array ( 'color' , $ r * 255 , $ g * 255 , $ b * 255 ) ; if ( count ( $ color ) > 4 ) $ out [ ] = $ color [ 4 ] ; return $ out ; }
|
Converts a hsl array into a color value in rgb . Expects H to be in range of 0 to 360 S and L in 0 to 100
|
14,471
|
protected function funcToColor ( $ func ) { $ fname = $ func [ 1 ] ; if ( $ func [ 2 ] [ 0 ] != 'list' ) return false ; $ rawComponents = $ func [ 2 ] [ 2 ] ; if ( $ fname == 'hsl' || $ fname == 'hsla' ) { $ hsl = array ( 'hsl' ) ; $ i = 0 ; foreach ( $ rawComponents as $ c ) { $ val = $ this -> reduce ( $ c ) ; $ val = isset ( $ val [ 1 ] ) ? floatval ( $ val [ 1 ] ) : 0 ; if ( $ i == 0 ) $ clamp = 360 ; elseif ( $ i < 3 ) $ clamp = 100 ; else $ clamp = 1 ; $ hsl [ ] = $ this -> clamp ( $ val , $ clamp ) ; $ i ++ ; } while ( count ( $ hsl ) < 4 ) $ hsl [ ] = 0 ; return $ this -> toRGB ( $ hsl ) ; } elseif ( $ fname == 'rgb' || $ fname == 'rgba' ) { $ components = array ( ) ; $ i = 1 ; foreach ( $ rawComponents as $ c ) { $ c = $ this -> reduce ( $ c ) ; if ( $ i < 4 ) { if ( $ c [ 0 ] == "number" && $ c [ 2 ] == "%" ) { $ components [ ] = 255 * ( $ c [ 1 ] / 100 ) ; } else { $ components [ ] = floatval ( $ c [ 1 ] ) ; } } elseif ( $ i == 4 ) { if ( $ c [ 0 ] == "number" && $ c [ 2 ] == "%" ) { $ components [ ] = 1.0 * ( $ c [ 1 ] / 100 ) ; } else { $ components [ ] = floatval ( $ c [ 1 ] ) ; } } else break ; $ i ++ ; } while ( count ( $ components ) < 3 ) $ components [ ] = 0 ; array_unshift ( $ components , 'color' ) ; return $ this -> fixColor ( $ components ) ; } return false ; }
|
Convert the rgb rgba hsl color literals of function type as returned by the parser into values of color type .
|
14,472
|
protected function get ( $ name ) { $ current = $ this -> env ; $ isArguments = $ name == $ this -> vPrefix . 'arguments' ; while ( $ current ) { if ( $ isArguments && isset ( $ current -> arguments ) ) { return array ( 'list' , ' ' , $ current -> arguments ) ; } if ( isset ( $ current -> store [ $ name ] ) ) return $ current -> store [ $ name ] ; else { $ current = isset ( $ current -> storeParent ) ? $ current -> storeParent : $ current -> parent ; } } $ this -> throwError ( "variable $name is undefined" ) ; }
|
get the highest occurrence entry for a name
|
14,473
|
public function propertyValue ( & $ value , $ keyName = null ) { $ values = array ( ) ; if ( $ keyName !== null ) $ this -> env -> currentProperty = $ keyName ; $ s = null ; while ( $ this -> expressionList ( $ v ) ) { $ values [ ] = $ v ; $ s = $ this -> seek ( ) ; if ( ! $ this -> literal ( ',' ) ) break ; } if ( $ s ) $ this -> seek ( $ s ) ; if ( $ keyName !== null ) unset ( $ this -> env -> currentProperty ) ; if ( count ( $ values ) == 0 ) return false ; $ value = \ ATPCore \ Lessc :: compressList ( $ values , ', ' ) ; return true ; }
|
consume a list of values for a property
|
14,474
|
protected function tag ( & $ tag , $ simple = false ) { if ( $ simple ) $ chars = '^@,:;{}\][>\(\) "\'' ; else $ chars = '^@,;{}["\'' ; $ s = $ this -> seek ( ) ; $ hasExpression = false ; $ parts = array ( ) ; while ( $ this -> tagBracket ( $ parts , $ hasExpression ) ) ; $ oldWhite = $ this -> eatWhiteDefault ; $ this -> eatWhiteDefault = false ; while ( true ) { if ( $ this -> match ( '([' . $ chars . '0-9][' . $ chars . ']*)' , $ m ) ) { $ parts [ ] = $ m [ 1 ] ; if ( $ simple ) break ; while ( $ this -> tagBracket ( $ parts , $ hasExpression ) ) ; continue ; } if ( isset ( $ this -> buffer [ $ this -> count ] ) && $ this -> buffer [ $ this -> count ] == "@" ) { if ( $ this -> interpolation ( $ interp ) ) { $ hasExpression = true ; $ interp [ 2 ] = true ; $ parts [ ] = $ interp ; continue ; } if ( $ this -> literal ( "@" ) ) { $ parts [ ] = "@" ; continue ; } } if ( $ this -> unit ( $ unit ) ) { $ parts [ ] = $ unit [ 1 ] ; $ parts [ ] = $ unit [ 2 ] ; continue ; } break ; } $ this -> eatWhiteDefault = $ oldWhite ; if ( ! $ parts ) { $ this -> seek ( $ s ) ; return false ; } if ( $ hasExpression ) { $ tag = array ( "exp" , array ( "string" , "" , $ parts ) ) ; } else { $ tag = trim ( implode ( $ parts ) ) ; } $ this -> whitespace ( ) ; return true ; }
|
a space separated list of selectors
|
14,475
|
protected function func ( & $ func ) { $ s = $ this -> seek ( ) ; if ( $ this -> match ( '(%|[\w\-_][\w\-_:\.]+|[\w_])' , $ m ) && $ this -> literal ( '(' ) ) { $ fname = $ m [ 1 ] ; $ sPreArgs = $ this -> seek ( ) ; $ args = array ( ) ; while ( true ) { $ ss = $ this -> seek ( ) ; if ( $ this -> keyword ( $ name ) && $ this -> literal ( '=' ) && $ this -> expressionList ( $ value ) ) { $ args [ ] = array ( "string" , "" , array ( $ name , "=" , $ value ) ) ; } else { $ this -> seek ( $ ss ) ; if ( $ this -> expressionList ( $ value ) ) { $ args [ ] = $ value ; } } if ( ! $ this -> literal ( ',' ) ) break ; } $ args = array ( 'list' , ',' , $ args ) ; if ( $ this -> literal ( ')' ) ) { $ func = array ( 'function' , $ fname , $ args ) ; return true ; } elseif ( $ fname == 'url' ) { $ this -> seek ( $ sPreArgs ) ; if ( $ this -> openString ( ")" , $ string ) && $ this -> literal ( ")" ) ) { $ func = array ( 'function' , $ fname , $ string ) ; return true ; } } } $ this -> seek ( $ s ) ; return false ; }
|
a css function
|
14,476
|
protected function assign ( $ name = null ) { if ( $ name ) $ this -> currentProperty = $ name ; return $ this -> literal ( ':' ) || $ this -> literal ( '=' ) ; }
|
Consume an assignment operator Can optionally take a name that will be set to the current property name
|
14,477
|
protected function append ( $ prop , $ pos = null ) { if ( $ pos !== null ) $ prop [ - 1 ] = $ pos ; $ this -> env -> props [ ] = $ prop ; }
|
append a property to the current block
|
14,478
|
public static function instance_from_curl ( $ ch , $ body ) { $ transfer_info = curl_getinfo ( $ ch ) ; $ statuscode = ( ! empty ( $ transfer_info [ 'http_code' ] ) ) ? ( int ) $ transfer_info [ 'http_code' ] : 404 ; $ errors = [ ] ; $ err = static :: decode_error_code ( curl_errno ( $ ch ) ) ; if ( $ err !== 'SUCCESS' ) { $ errors [ ] = $ err ; } $ mime = ( ! empty ( $ transfer_info [ 'content_type' ] ) ) ? $ transfer_info [ 'content_type' ] : 'text/plain' ; return new HttpClientResponse ( $ statuscode , $ mime , $ body , $ errors ) ; }
|
Create an instance from a curl handle and body .
|
14,479
|
public function get_debug_string ( ) { return 'status: ' . $ this -> statuscode . ' body:' . htmlentities ( $ this -> body ) . ' errors: ' . print_r ( $ this -> errors , true ) ; }
|
Get a string with some basic information about the request . Usually put into the logs .
|
14,480
|
public function status_type ( ) { $ status_code_type = ( ! empty ( $ this -> statuscode ) ) ? ( int ) mb_substr ( $ this -> statuscode , 0 , 1 ) : 0 ; if ( $ status_code_type === 1 ) { $ status_type = 'informational' ; } elseif ( $ status_code_type === 2 ) { $ status_type = 'success' ; } elseif ( $ status_code_type === 3 ) { $ status_type = 'redirect' ; } elseif ( $ status_code_type === 4 ) { $ status_type = 'client_err' ; } elseif ( $ status_code_type === 5 ) { $ status_type = 'server_err' ; } else { $ status_type = 'bad' ; } return $ status_type ; }
|
Get the status type .
|
14,481
|
private function generateCode ( $ className , $ primaryKey ) { $ tags = $ this -> config -> getTags ( ) ; $ class = new ClassGenerator ( ) ; $ docblock = DocBlockGenerator :: fromArray ( array ( 'shortDescription' => ucfirst ( $ className ) . ' model class' , 'longDescription' => 'This is a model class generated with DavidePastore\ParisModelGenerator.' , 'tags' => $ tags ) ) ; $ idColumn = new PropertyGenerator ( '_id_column' ) ; $ idColumn -> setStatic ( true ) -> setDefaultValue ( $ primaryKey ) ; $ table = new PropertyGenerator ( '_table' ) ; $ table -> setStatic ( true ) -> setDefaultValue ( $ className ) ; $ tableUseShortName = new PropertyGenerator ( '_table_use_short_name' ) ; $ tableUseShortName -> setStatic ( true ) -> setDefaultValue ( true ) ; $ namespace = $ this -> config -> getNamespace ( ) ; $ extendedClass = '\Model' ; if ( isset ( $ namespace ) && ! empty ( $ namespace ) ) { $ class -> setNamespaceName ( $ this -> config -> getNamespace ( ) ) ; } $ class -> setName ( ucfirst ( $ className ) ) -> setDocblock ( $ docblock ) -> setExtendedClass ( $ extendedClass ) -> addProperties ( array ( $ idColumn , $ table , $ tableUseShortName ) ) ; $ file = FileGenerator :: fromArray ( array ( 'classes' => array ( $ class ) , 'docblock' => DocBlockGenerator :: fromArray ( array ( 'shortDescription' => ucfirst ( $ className ) . ' class file' , 'longDescription' => null , 'tags' => $ tags ) ) ) ) ; $ generatedCode = $ file -> generate ( ) ; $ directory = $ this -> config -> getDestinationFolder ( ) . $ namespace ; if ( ! file_exists ( $ directory ) ) { mkdir ( $ directory , 0777 , true ) ; } $ filePath = $ directory . "/" . $ class -> getName ( ) . ".php" ; if ( file_exists ( $ filePath ) && ! $ this -> force ) { $ helper = $ this -> getHelper ( 'question' ) ; $ realPath = realpath ( $ filePath ) ; $ this -> output -> writeln ( "\n" ) ; $ question = new ConfirmationQuestion ( 'Do you want to overwrite the file "' . $ realPath . '"?' , false ) ; if ( $ helper -> ask ( $ this -> input , $ this -> output , $ question ) ) { $ this -> writeInFile ( $ filePath , $ generatedCode ) ; } } else { $ this -> writeInFile ( $ filePath , $ generatedCode ) ; } }
|
Generate the code for the given className and primaryKey and write it in a file .
|
14,482
|
public function set ( $ key , $ value , $ expire = 3600 , $ path = '/' ) { if ( $ expire == false ) { setcookie ( $ key , serialize ( $ value ) , false , $ path ) ; } else { setcookie ( $ key , serialize ( $ value ) , time ( ) + $ expire , $ path ) ; } }
|
Adds to the session .
|
14,483
|
public function first ( callable $ fn = null , $ default = null ) { if ( is_null ( $ fn ) ) { return count ( $ this -> items ) > 0 ? reset ( $ this -> items ) : $ default ; } foreach ( $ this -> getIterator ( ) as $ value ) { if ( call_user_func ( $ fn , $ value ) ) { return $ value ; } } return $ default ; }
|
Retrieve the first element that matches the optional callback
|
14,484
|
public function last ( callable $ fn = null , $ default = null ) { if ( is_null ( $ fn ) ) { return count ( $ this -> items ) > 0 ? end ( $ this -> items ) : $ default ; } foreach ( array_reverse ( $ this -> items ) as $ value ) { if ( call_user_func ( $ fn , $ value ) ) { return $ value ; } } return $ default ; }
|
Receive the last element that matches the optional callback
|
14,485
|
public static function One ( $ id ) { $ class = get_called_class ( ) ; if ( ! isset ( self :: $ refs [ $ class ] [ $ id ] ) ) { $ file = self :: File ( $ id ) ; $ obj = unserialize ( file_get_contents ( $ file ) ) ; self :: $ refs [ $ class ] [ $ id ] = $ obj ; } return self :: $ refs [ $ class ] [ $ id ] ; }
|
Fetch one saved object by id
|
14,486
|
public static function SetDirectory ( $ dir ) { if ( ! is_dir ( $ dir ) ) { if ( ! @ \ mkdir ( $ dir , 0700 , TRUE ) ) { throw new \ InvalidArgumentException ( "dir $dir does not exist and could not be created" ) ; } } self :: $ DIR = realpath ( $ dir ) ; }
|
Set directory where all persistent objects and relations will be saved .
|
14,487
|
public function Save ( ) { if ( ! $ this -> Validate ( ) ) { throw new \ Exception ( "Validation failed" ) ; } $ file = self :: File ( $ this -> id ) ; if ( ! is_dir ( dirname ( $ file ) ) ) { mkdir ( dirname ( $ file ) , 0755 , true ) ; } file_put_contents ( $ file , serialize ( $ this ) , LOCK_EX ) ; return $ this ; }
|
Save this object .
|
14,488
|
public static function extensionIdentifier ( string $ extensionKey ) : string { $ extensionIdentifier = GeneralUtility :: underscoredToUpperCamelCase ( $ extensionKey ) ; $ extensionIdentifier = mb_strtolower ( $ extensionIdentifier ) ; return $ extensionIdentifier ; }
|
Gets an extension identifier from an extension key .
|
14,489
|
public static function extensionSignature ( string $ namespace , string $ extensionKey , string $ separator = '.' ) : string { $ namespace = GeneralUtility :: underscoredToUpperCamelCase ( $ namespace ) ; $ extensionKey = GeneralUtility :: underscoredToUpperCamelCase ( $ extensionKey ) ; return "${namespace}${separator}${extensionKey}" ; }
|
Gets an extension signature from a namespace and extension key .
|
14,490
|
public static function getExtensionSignature ( string $ namespace , string $ extensionKey , string $ separator = '.' ) : string { return self :: extensionSignature ( $ namespace , $ extensionKey , $ separator ) ; }
|
Alias for the extensionSignature function .
|
14,491
|
public static function locallang ( string $ extensionKey , string $ fileName = 'locallang.xlf' , string $ prefix = 'LLL:EXT:' , string $ separator = ':' ) : string { $ languageFolder = self :: languageFolder ( $ extensionKey , $ prefix ) ; return "${languageFolder}/${fileName}${separator}" ; }
|
Gets the locallang file from an extension key .
|
14,492
|
public static function getConfigurationFolder ( string $ extensionKey , string $ prefix = 'FILE:EXT:' ) : string { return self :: configurationFolder ( $ extensionKey , $ prefix ) ; }
|
Alias for the configurationFolder function .
|
14,493
|
public static function flexFormsFolder ( string $ extensionKey , string $ prefix = 'FILE:EXT:' ) : string { $ configurationFolder = self :: configurationFolder ( $ extensionKey , $ prefix ) ; return "${configurationFolder}/FlexForms" ; }
|
Gets the FlexForms folder from an extension key .
|
14,494
|
public static function getFlexFormsFolder ( string $ extensionKey , string $ prefix = 'FILE:EXT:' ) : string { return self :: flexFormsFolder ( $ extensionKey , $ prefix ) ; }
|
Alias for the flexFormsFolder function .
|
14,495
|
public static function getResourcesFolder ( string $ extensionKey , string $ prefix = 'EXT:' ) : string { return self :: resourcesFolder ( $ extensionKey , $ prefix ) ; }
|
Alias for the resourcesFolder function .
|
14,496
|
public static function privateFolder ( string $ extensionKey , string $ prefix = 'EXT:' ) : string { $ resourcesFolder = self :: resourcesFolder ( $ extensionKey , $ prefix ) ; return "${resourcesFolder}/Private" ; }
|
Gets the private folder from an extension key .
|
14,497
|
public static function getPrivateFolder ( string $ extensionKey , string $ prefix = 'EXT:' ) : string { return self :: privateFolder ( $ extensionKey , $ prefix ) ; }
|
Alias for the privateFolder function .
|
14,498
|
public static function languageFolder ( string $ extensionKey , string $ prefix = 'EXT:' ) : string { $ privateFolder = self :: privateFolder ( $ extensionKey , $ prefix ) ; return "${privateFolder}/Language" ; }
|
Gets the language folder from an extension key .
|
14,499
|
public static function getLanguageFolder ( string $ extensionKey , string $ prefix = 'EXT:' ) : string { return self :: languageFolder ( $ extensionKey , $ prefix ) ; }
|
Alias for the languageFolder function .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.