idx
int64
0
60.3k
question
stringlengths
92
4.62k
target
stringlengths
7
635
49,500
public function replace ( $ args , $ assoc_args ) { list ( $ key , $ value , $ group , $ expiration ) = $ args ; $ result = wp_cache_replace ( $ key , $ value , $ group , $ expiration ) ; if ( false === $ result ) { WP_CLI :: error ( "Could not replace object '$key' in group '$group'. Does it not exist?" ) ; } WP_CLI :...
Replaces a value in the object cache if the value already exists .
49,501
public function set ( $ args , $ assoc_args ) { list ( $ key , $ value , $ group , $ expiration ) = $ args ; $ result = wp_cache_set ( $ key , $ value , $ group , $ expiration ) ; if ( false === $ result ) { WP_CLI :: error ( "Could not add object '$key' in group '$group'." ) ; } WP_CLI :: success ( "Set object '$key' ...
Sets a value to the object cache regardless of whether it already exists .
49,502
public function type ( $ args , $ assoc_args ) { $ message = WP_CLI \ Utils \ wp_get_cache_type ( ) ; WP_CLI :: line ( $ message ) ; }
Attempts to determine which object cache is being used .
49,503
public function imageVersion ( $ version , $ options = [ ] ) { $ options [ 'version' ] = $ version ; $ options [ 'image' ] = $ this ; $ options [ 'hash' ] = Configure :: read ( 'FileStorage.imageHashes.' . $ this -> _properties [ 'model' ] . '.' . $ version ) ; if ( empty ( $ options [ 'hash' ] ) ) { throw new InvalidA...
Gets the version of an image .
49,504
public function regenerate ( ) { $ operations = Configure :: read ( 'FileStorage.imageSizes.' . $ this -> args [ 0 ] ) ; $ options = [ 'overwrite' => ! $ this -> params [ 'keep-old-versions' ] ] ; if ( empty ( $ operations ) ) { $ this -> abort ( __d ( 'file_storage' , 'Invalid table or version.' ) ) ; } foreach ( $ op...
Generate all image versions .
49,505
public function generate ( $ model , $ version ) { $ operations = Configure :: read ( 'FileStorage.imageSizes.' . $ model . '.' . $ version ) ; $ options = [ 'overwrite' => ! $ this -> params [ 'keep-old-versions' ] ] ; if ( empty ( $ operations ) ) { $ this -> out ( __d ( 'file_storage' , 'Invalid table or version.' )...
Generate a given image version .
49,506
public function remove ( $ model , $ version ) { $ operations = Configure :: read ( 'FileStorage.imageSizes.' . $ model . '.' . $ version ) ; if ( empty ( $ operations ) ) { $ this -> out ( __d ( 'file_storage' , 'Invalid table or version.' ) ) ; $ this -> _stop ( ) ; } try { $ this -> _loop ( 'remove' , $ model , [ $ ...
Remove a given image version .
49,507
protected function _loop ( $ action , $ model , $ operations = [ ] , $ options = [ ] ) { if ( ! in_array ( $ action , [ 'generate' , 'remove' , 'regenerate' ] ) ) { $ this -> _stop ( ) ; } $ totalImageCount = $ this -> _getCount ( $ model ) ; if ( $ totalImageCount === 0 ) { $ this -> out ( __d ( 'file_storage' , 'No I...
Loops through image records and performs requested operation on them .
49,508
protected function _getCount ( $ identifier , array $ extensions = [ 'jpg' , 'png' , 'jpeg' ] ) { return $ this -> Table -> find ( ) -> where ( [ 'model' => $ identifier ] ) -> andWhere ( [ 'extension IN' => $ extensions ] ) -> count ( ) ; }
Gets the amount of images for a model in the DB .
49,509
protected function _getRecords ( $ identifier , $ limit , $ offset , array $ extensions = [ 'jpg' , 'png' , 'jpeg' ] ) { return $ this -> Table -> find ( ) -> where ( [ 'model' => $ identifier ] ) -> andWhere ( [ 'extension IN' => $ extensions ] ) -> limit ( $ limit ) -> offset ( $ offset ) -> all ( ) ; }
Gets the chunk of records for the image processing
49,510
public function loadImageProcessingFromConfig ( ) { $ this -> _imageVersions = ( array ) Configure :: read ( 'FileStorage.imageSizes' ) ; $ this -> _imageVersionHashes = StorageUtils :: generateHashes ( 'FileStorage' , true ) ; $ this -> _defaultOutput = ( array ) Configure :: read ( 'FileStorage.defaultOutput' ) ; }
Loads the image processing configuration into the class .
49,511
public function imageProcessor ( array $ config = [ ] , $ renew = false ) { if ( ! empty ( $ this -> _imageProcessor ) && $ renew === false ) { return $ this -> _imageProcessor ; } $ this -> loadImageProcessingFromConfig ( ) ; $ class = $ this -> _imageProcessorClass ; $ this -> _imageProcessor = new $ class ( $ config...
Gets the image processor instance .
49,512
protected function _checkImageVersions ( $ identifier , array $ versions ) { if ( ! isset ( $ this -> _imageVersions [ $ identifier ] ) ) { throw new RuntimeException ( sprintf ( 'No image version config found for identifier "%s"!' , $ identifier ) ) ; } foreach ( $ versions as $ version ) { if ( ! isset ( $ this -> _i...
Check that the image versions exist before doing something with them .
49,513
public function getAllVersionsKeysForModel ( $ identifier ) { if ( ! isset ( $ this -> _imageVersions [ $ identifier ] ) ) { throw new RuntimeException ( sprintf ( 'No image config present for identifier "%s"!' , $ identifier ) ) ; } return array_keys ( $ this -> _imageVersions [ $ identifier ] ) ; }
Gets all image version config keys for a specific identifier .
49,514
public function uploadErrors ( $ value , $ options = [ ] ) { $ defaults = [ 'allowNoFileError' => true ] ; if ( is_array ( $ options ) ) { $ options = array_merge ( $ defaults , $ options ) ; } else { $ options = $ defaults ; } if ( isset ( $ value [ 'error' ] ) && ( $ value [ 'error' ] !== null ) ) { switch ( $ value ...
Validates the error value that comes with the file input file .
49,515
public function autoProcessImageVersions ( EntityInterface $ entity , $ action ) { if ( ! in_array ( $ action , [ 'create' , 'remove' ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Action was `%s` but must be `create` or `remove`' , $ action ) ) ; } $ this -> loadImageProcessingFromConfig ( ) ; if ( ! isset ( ...
Convenience method to auto create ALL and auto remove ALL image versions for an entity .
49,516
public function getImageVersionHash ( $ model , $ version ) { if ( empty ( $ this -> _imageVersionHashes [ $ model ] [ $ version ] ) ) { throw new RuntimeException ( sprintf ( 'Version "%s" for identifier "%s" does not exist!' , $ version , $ model ) ) ; } return $ this -> _imageVersionHashes [ $ model ] [ $ version ] ...
Gets the hash of a specific image version for an entity .
49,517
public function removeImageVersions ( EntityInterface $ entity , array $ versions , array $ options = [ ] ) { $ this -> _checkImageVersions ( $ entity -> model , $ versions ) ; $ result = [ ] ; foreach ( $ versions as $ version ) { $ hash = $ this -> getImageVersionHash ( $ entity -> model , $ version ) ; $ path = $ th...
Removes image versions of an entity .
49,518
protected function _loop ( $ identifier , $ options , $ action ) { $ count = $ this -> _getCount ( $ identifier ) ; $ offset = 0 ; $ limit = $ this -> params [ 'limit' ] ; $ this -> out ( __d ( 'file_storage' , '{0} record(s) will be processed.' . "\n" , $ count ) ) ; do { $ records = $ this -> _getRecords ( $ identifi...
Loops through image records and performs requested operations on them .
49,519
protected function _removeImage ( $ record , $ options ) { $ Event = new Event ( 'ImageVersion.removeVersion' , $ this -> Table , [ 'entity' => $ record , 'operations' => $ options ] ) ; EventManager :: instance ( ) -> dispatch ( $ Event ) ; }
Triggers the event to remove image versions .
49,520
public function _getRecords ( $ identifier , $ limit , $ offset ) { return $ this -> Table -> find ( ) -> where ( [ $ this -> Table -> alias ( ) . '.model' => $ identifier ] ) -> limit ( $ limit ) -> offset ( $ offset ) -> all ( ) ; }
Gets the records for the loop .
49,521
protected function _getCount ( $ identifier ) { $ count = $ this -> _getCountQuery ( $ identifier ) -> count ( ) ; if ( $ count === 0 ) { $ this -> out ( __d ( 'file_storage' , 'No records for identifier "{0}" found.' , $ identifier ) ) ; $ this -> _stop ( ) ; } return $ count ; }
Gets the amount of records for an identifier in the DB .
49,522
protected function _getCountQuery ( $ identifier ) { return $ this -> Table -> find ( ) -> where ( [ $ this -> Table -> alias ( ) . '.model' => $ identifier ] ) ; }
Gets the query object for the count .
49,523
protected function _isFileUploadPresent ( $ entity ) { $ field = $ this -> getConfig ( 'fileField' ) ; if ( $ this -> getConfig ( 'ignoreEmptyFile' ) === true ) { if ( ! isset ( $ entity [ $ field ] [ 'error' ] ) || $ entity [ $ field ] [ 'error' ] === UPLOAD_ERR_NO_FILE ) { return false ; } } return true ; }
Checks if a file upload is present .
49,524
public function deleteOldFileOnSave ( EntityInterface $ entity , $ oldIdField = 'old_file_id' ) { if ( ! empty ( $ entity -> get ( $ oldIdField ) ) && $ entity -> get ( 'model' ) ) { $ oldEntity = $ this -> _table -> find ( ) -> contain ( [ ] ) -> where ( [ $ this -> _table -> getAlias ( ) . '.' . $ this -> _table -> g...
Deletes an old file to replace it with the new one if an old id was passed .
49,525
public function _getFileInfoFromUpload ( & $ upload , $ field = 'file' ) { if ( ! empty ( $ upload [ $ field ] [ 'tmp_name' ] ) ) { $ File = new File ( $ upload [ $ field ] [ 'tmp_name' ] ) ; $ upload [ 'filesize' ] = filesize ( $ upload [ $ field ] [ 'tmp_name' ] ) ; $ upload [ 'mime_type' ] = $ File -> mime ( ) ; } i...
Gets information about the file that is being uploaded .
49,526
public static function fileExtension ( $ name , $ realFile = false ) { if ( $ realFile ) { $ result = pathinfo ( $ name , PATHINFO_EXTENSION ) ; if ( empty ( $ result ) ) { return false ; } } return substr ( strrchr ( $ name , '.' ) , 1 ) ; }
Return file extension from a given filename .
49,527
public static function trimPath ( $ path ) { $ len = strlen ( $ path ) ; if ( $ path [ $ len - 1 ] == '\\' || $ path [ $ len - 1 ] == '/' ) { $ path = substr ( $ path , 0 , $ len - 1 ) ; } return $ path ; }
Helper method to trim last trailing slash in file path
49,528
public static function generateHashes ( $ configPath = 'FileStorage' ) { if ( is_array ( $ configPath ) ) { $ imageSizes = $ configPath ; } else { $ imageSizes = Configure :: read ( $ configPath . '.imageSizes' ) ; } if ( $ imageSizes === null ) { throw new RuntimeException ( sprintf ( 'Image processing configuration i...
Generates the hashes for the different image version configurations .
49,529
public static function fileToUploadArray ( $ file , $ filename = null ) { $ File = new File ( $ file ) ; if ( empty ( $ fileName ) ) { $ filename = basename ( $ file ) ; } return [ 'name' => $ filename , 'tmp_name' => $ file , 'error' => 0 , 'type' => $ File -> mime ( ) , 'size' => $ File -> size ( ) ] ; }
Returns an array that matches the structure of a regular upload for a local file
49,530
public static function createTmpFile ( $ folder = null , $ checkAndCreatePath = true ) { if ( $ folder === null ) { $ folder = TMP ; } if ( $ checkAndCreatePath === true && ! is_dir ( $ folder ) ) { new Folder ( $ folder , true ) ; } return $ folder . Text :: uuid ( ) ; }
Creates a temporary file name and checks the tmp path creates one if required .
49,531
public static function getFileHash ( $ file , $ method = 'sha1' ) { if ( $ method === 'md5' ) { return md5_file ( $ file ) ; } if ( $ method === 'sha1' ) { return sha1_file ( $ file ) ; } throw new InvalidArgumentException ( sprintf ( 'Invalid hash method "%s" provided!' , $ method ) ) ; }
Gets the hash of a file .
49,532
protected function _buildCloudUrl ( $ bucket , $ bucketPrefix = null , $ cfDist = null ) { $ path = $ this -> getConfig ( 'https' ) === true ? 'https://' : 'http://' ; if ( $ cfDist ) { $ path .= $ cfDist ; } else { if ( $ bucketPrefix ) { $ path .= $ bucket . '.' . $ this -> _config [ 's3Url' ] ; } else { $ path .= $ ...
Builds the cloud base URL for the given bucket and location .
49,533
public function afterSave ( Event $ event , EntityInterface $ entity ) { if ( $ this -> getConfig ( 'uploadOn' ) === 'afterSave' ) { $ this -> _handleFiles ( $ entity ) ; } }
After save callback .
49,534
public function beforeSave ( Event $ event , EntityInterface $ entity ) { if ( $ this -> getConfig ( 'uploadOn' ) === 'beforeSave' ) { $ this -> _handleFiles ( $ entity ) ; } }
Before save callback .
49,535
protected function _handleFiles ( EntityInterface $ entity ) { $ files = $ this -> getConfig ( 'file' ) ; if ( is_string ( $ files ) ) { $ files = [ $ files => $ this -> getConfig ( 'defaults' ) ] ; } $ results = [ ] ; foreach ( $ files as $ key => $ file ) { if ( is_string ( $ key ) ) { $ field = $ key ; $ options = $...
This method is looking for the actual file upload fields and processes them .
49,536
protected function _getStorageModel ( $ options ) { if ( ! empty ( $ options [ 'association' ] ) ) { return $ this -> { $ options [ 'association' ] } ; } return TableRegistry :: getTableLocator ( ) -> get ( $ options [ 'model' ] ) ; }
Gets the storage table instance .
49,537
public function store ( ) { $ this -> _storePrecheck ( ) ; $ model = $ this -> loadModel ( $ this -> params [ 'model' ] ) ; $ fileData = StorageUtils :: fileToUploadArray ( $ this -> args [ 0 ] ) ; $ entity = $ model -> newEntity ( [ 'adapter' => $ this -> params [ 'adapter' ] , 'file' => $ fileData , 'filename' => $ f...
Store a local file via command line in any storage backend .
49,538
protected function _checkEvent ( Event $ event ) { $ className = $ this -> _getAdapterClassFromConfig ( $ event -> getData ( 'entity' ) [ 'adapter' ] ) ; $ classes = $ this -> _adapterClasses ; if ( ! empty ( $ classes ) && ! in_array ( $ className , $ classes ) ) { $ message = 'The listener `%s` doesn\'t allow the `%s...
Check if the event is of a type or subject object of type model we want to process with this listener .
49,539
protected function _identifierFilter ( Event $ event ) { if ( is_array ( $ this -> _config [ 'identifiers' ] ) ) { $ identifier = $ event -> getData ( 'entity.model' ) ; if ( ! in_array ( $ identifier , $ this -> _config [ 'identifiers' ] ) ) { return false ; } } return true ; }
Detects if an entities model field has name of one of the allowed models set .
49,540
public function getAdapterClassName ( $ configName ) { $ className = $ this -> _getAdapterClassFromConfig ( $ configName ) ; if ( in_array ( $ className , $ this -> _adapterClasses ) ) { $ position = strripos ( $ className , '\\' ) ; $ this -> _adapterClass = substr ( $ className , $ position + 1 , strlen ( $ className...
Gets the adapter class name from the adapter configuration key and checks if it is in the list of supported adapters for the listener .
49,541
protected function _tmpFile ( $ Storage , $ path , $ tmpFolder = null ) { try { $ tmpFile = $ this -> createTmpFile ( $ tmpFolder ) ; file_put_contents ( $ tmpFile , $ Storage -> read ( $ path ) ) ; return $ tmpFile ; } catch ( \ Exception $ e ) { $ this -> log ( $ e -> getMessage ( ) ) ; throw new StorageException ( '...
Create a temporary file locally based on a file from an adapter .
49,542
public function getPath ( Event $ event ) { $ pathBuilder = $ this -> pathBuilder ( ) ; $ method = $ event -> getData ( 'method' ) ; if ( ! method_exists ( $ pathBuilder , $ event -> getData ( 'method' ) ) ) { throw new BadMethodCallException ( sprintf ( '`%s` does not implement the `%s` method!' , get_class ( $ pathBu...
Get the path for a storage entity .
49,543
protected function _storeFile ( Event $ event ) { try { $ beforeEvent = $ this -> _beforeStoreFile ( $ event ) ; if ( $ beforeEvent -> isStopped ( ) ) { return $ beforeEvent -> result ; } $ fileField = $ this -> getConfig ( 'fileField' ) ; $ entity = $ event -> getData ( 'entity' ) ; $ Storage = $ this -> getStorageAda...
Stores the file in the configured storage backend .
49,544
protected function _deleteFile ( Event $ event ) { try { $ this -> _beforeDeleteFile ( $ event ) ; $ entity = $ event -> getData ( 'entity' ) ; $ path = $ this -> pathBuilder ( ) -> fullPath ( $ entity ) ; if ( $ this -> getStorageAdapter ( $ entity -> adapter ) -> delete ( $ path ) ) { $ event -> result = true ; $ eve...
Deletes the file from the configured storage backend .
49,545
protected function _afterStoreFile ( Event $ event ) { $ entity = $ event -> getData ( 'entity' ) ; return $ this -> dispatchEvent ( 'FileStorage.afterStoreFile' , [ 'entity' => $ event -> getData ( 'entity' ) , 'adapter' => $ this -> getStorageAdapter ( $ entity -> get ( 'adapter' ) ) ] ) ; }
Callback to handle the case something needs to be done after the file was successfully stored in the storage backend .
49,546
protected function _afterDeleteFile ( Event $ event ) { $ entity = $ event -> getData ( 'entity' ) ; return $ this -> dispatchEvent ( 'FileStorage.afterDeleteFile' , [ 'entity' => $ entity , 'adapter' => $ this -> getStorageAdapter ( $ entity -> get ( 'adapter' ) ) ] ) ; }
Callback to handle the case something needs to be done after the file was successfully removed from the storage backend .
49,547
public function createPathBuilder ( $ name , array $ options = [ ] ) { $ className = App :: className ( $ name , 'Storage/PathBuilder' , 'PathBuilder' ) ; if ( ! class_exists ( $ className ) ) { $ className = App :: className ( 'Burzum/FileStorage.' . $ name , 'Storage/PathBuilder' , 'PathBuilder' ) ; } if ( ! class_ex...
Builds the path builder for given interface .
49,548
public function pathBuilder ( $ name = null , array $ options = [ ] ) { if ( $ name instanceof PathBuilderInterface ) { $ this -> _pathBuilder = $ name ; return $ this -> _pathBuilder ; } if ( $ name !== null ) { $ this -> _pathBuilder = $ this -> createPathBuilder ( $ name , $ options ) ; } return $ this -> _pathBuild...
Getter and setter for the local PathBuilderInterface instance .
49,549
public function setPathBuilder ( $ pathBuilder , array $ options = [ ] ) { if ( is_string ( $ pathBuilder ) ) { $ this -> _pathBuilder = $ this -> createPathBuilder ( $ pathBuilder , $ options ) ; return ; } if ( ! $ pathBuilder instanceof PathBuilderInterface ) { throw new InvalidArgumentException ( sprintf ( 'The fir...
Sets a path builder .
49,550
public function path ( EntityInterface $ entity , array $ options = [ ] ) { $ config = array_merge ( $ this -> getConfig ( ) , $ options ) ; $ path = '' ; $ path = $ this -> _pathPrefix ( $ entity , $ path , $ config ) ; $ path = $ this -> _path ( $ entity , $ path , $ config ) ; $ path = $ this -> _pathSuffix ( $ enti...
Builds the path under which the data gets stored in the storage adapter .
49,551
protected function _pathPrefix ( EntityInterface $ entity , $ path , array $ config ) { return $ this -> _pathPreAndSuffix ( $ entity , $ path , $ config , 'prefix' ) ; }
Handles the path prefix generation .
49,552
protected function _path ( EntityInterface $ entity , $ path , array $ config ) { if ( $ config [ 'modelFolder' ] === true ) { $ path .= $ entity -> model . DS ; } if ( $ config [ 'randomPath' ] === true ) { $ path .= $ this -> randomPath ( $ entity -> id ) ; } if ( is_string ( $ config [ 'randomPath' ] ) ) { $ path .=...
Builds a path .
49,553
public function splitFilename ( $ filename , $ keepDot = false ) { $ position = strrpos ( $ filename , '.' ) ; if ( $ position === false ) { $ extension = '' ; } else { $ extension = substr ( $ filename , $ position , strlen ( $ filename ) ) ; $ filename = substr ( $ filename , 0 , $ position ) ; if ( $ keepDot === fal...
Splits the filename in name and extension .
49,554
public function filename ( EntityInterface $ entity , array $ options = [ ] ) { $ config = array_merge ( $ this -> getConfig ( ) , $ options ) ; if ( $ config [ 'preserveFilename' ] === true ) { return $ this -> _preserveFilename ( $ entity , $ config ) ; } return $ this -> _buildFilename ( $ entity , $ config ) ; }
Builds the filename of under which the data gets saved in the storage adapter .
49,555
protected function _buildFilename ( EntityInterface $ entity , array $ options = [ ] ) { $ filename = $ entity -> id ; if ( $ options [ 'stripUuid' ] === true ) { $ filename = $ this -> stripDashes ( $ filename ) ; } if ( ! empty ( $ options [ 'fileSuffix' ] ) ) { $ filename = $ filename . $ options [ 'fileSuffix' ] ; ...
Used to build a completely customized filename .
49,556
protected function _preserveFilename ( EntityInterface $ entity , array $ options = [ ] ) { $ filename = $ entity [ 'filename' ] ; if ( ! empty ( $ options [ 'filePrefix' ] ) ) { $ filename = $ options [ 'filePrefix' ] . $ entity [ 'filename' ] ; } if ( ! empty ( $ options [ 'fileSuffix' ] ) ) { $ split = $ this -> spl...
Keeps the original filename but is able to inject pre - and suffix .
49,557
public function fullPath ( EntityInterface $ entity , array $ options = [ ] ) { return $ this -> path ( $ entity , $ options ) . $ this -> filename ( $ entity , $ options ) ; }
Returns the path + filename .
49,558
public static function config ( $ adapter , $ options = [ ] ) { $ _this = static :: getInstance ( ) ; if ( ! empty ( $ adapter ) && ! empty ( $ options ) ) { return $ _this -> _adapterConfig [ $ adapter ] = $ options ; } if ( isset ( $ _this -> _adapterConfig [ $ adapter ] ) ) { return $ _this -> _adapterConfig [ $ ada...
Gets the configuration array for an adapter .
49,559
public static function flush ( $ name = null ) { $ _this = static :: getInstance ( ) ; if ( isset ( $ _this -> _adapterConfig [ $ name ] ) ) { unset ( $ _this -> _adapterConfig [ $ name ] ) ; return true ; } return false ; }
Flush all or a single adapter from the config .
49,560
public static function get ( $ configName , $ renewObject = false ) { if ( empty ( $ configName ) || ! is_string ( $ configName ) ) { throw new InvalidArgumentException ( 'StorageManager::get() first arg must be a non empty string!' ) ; } $ _this = static :: getInstance ( ) ; $ isConfigured = true ; if ( ! empty ( $ _t...
Gets a configured instance of a storage adapter .
49,561
protected function _factory ( $ adapter ) { $ _this = static :: getInstance ( ) ; if ( ! isset ( $ adapter [ 'engine' ] ) ) { $ adapter [ 'engine' ] = 'Gaufrette' ; } if ( $ adapter [ 'engine' ] === static :: GAUFRETTE_ENGINE ) { return $ _this -> gaufretteFactory ( $ adapter ) ; } if ( $ adapter [ 'engine' ] === stati...
Switches between the engines
49,562
public static function gaufretteFactory ( array $ adapter ) { $ class = $ adapter [ 'adapterClass' ] ; $ Reflection = new ReflectionClass ( $ class ) ; if ( ! is_array ( $ adapter [ 'adapterOptions' ] ) ) { throw new InvalidArgumentException ( sprintf ( '%s: The adapter options must be an array!' , $ configName ) ) ; }...
Instantiates Gaufrette adapters .
49,563
public static function flysystemFactory ( array $ adapter ) { if ( class_exists ( $ adapter [ 'adapterClass' ] ) ) { return ( new ReflectionClass ( $ adapter [ 'adapterClass' ] ) ) -> newInstanceArgs ( $ adapter [ 'adapterOptions' ] ) ; } $ leagueAdapter = '\\League\\Flysystem\\Adapter\\' . $ adapter [ 'adapterClass' ]...
Instantiates Flystem adapters .
49,564
public function display ( $ image , $ version = null , $ options = [ ] ) { if ( empty ( $ image ) ) { return $ this -> fallbackImage ( $ options , $ image , $ version ) ; } $ url = $ this -> imageUrl ( $ image , $ version , $ options ) ; if ( $ url !== false ) { return $ this -> Html -> image ( $ url , $ options ) ; } ...
Generates an image url based on the image record data and the used Gaufrette adapter to store it
49,565
protected function _getHash ( $ version , $ image ) { if ( ! empty ( $ version ) ) { $ hash = Configure :: read ( 'FileStorage.imageHashes.' . $ image [ 'model' ] . '.' . $ version ) ; if ( empty ( $ hash ) ) { throw new InvalidArgumentException ( sprintf ( 'No valid version key (Identifier: `%s` Key: `%s`) passed!' , ...
Gets a hash .
49,566
public function fallbackImage ( $ options = [ ] , $ image = [ ] , $ version = null ) { if ( isset ( $ options [ 'fallback' ] ) ) { if ( $ options [ 'fallback' ] === true ) { $ imageFile = 'placeholder/' . $ version . '.jpg' ; } else { $ imageFile = $ options [ 'fallback' ] ; } unset ( $ options [ 'fallback' ] ) ; retur...
Provides a fallback image if the image record is empty
49,567
protected function _path ( $ options ) { if ( empty ( $ options [ 'method' ] ) ) { $ options [ 'method' ] = 'path' ; } $ options [ 'entity' ] = $ this ; $ event = $ this -> dispatchEvent ( 'FileStorage.path' , $ options ) ; return $ event -> getResult ( ) ; }
Gets a path for this entities file .
49,568
public function afterDelete ( Event $ event , EntityInterface $ entity ) { if ( $ this -> _checkEvent ( $ event ) ) { $ event -> result = $ this -> _deleteFile ( $ event ) ; $ event -> stopPropagation ( ) ; } }
File removal is handled AFTER the database record was deleted .
49,569
protected function _getVersionData ( $ event ) { $ data = $ event -> getData ( ) ; if ( isset ( $ data [ 'versions' ] ) ) { $ versions = $ data [ 'versions' ] ; } elseif ( isset ( $ data [ 'operations' ] ) ) { $ versions = array_keys ( $ data [ 'operations' ] ) ; } else { $ versions = [ ] ; } return $ versions ; }
This method retrieves version names from event data .
49,570
public function initialize ( Event $ event ) { $ table = $ event -> getSubject ( ) ; if ( ! in_array ( get_class ( $ table ) , $ this -> config [ 'tableClass' ] ) ) { return ; } $ this -> _setValidators ( $ table ) ; }
Model initialize event callback
49,571
protected function _setValidators ( Table $ table ) { $ methods = get_class_methods ( $ this ) ; foreach ( $ methods as $ method ) { if ( substr ( $ method , 0 , 10 ) === 'validation' ) { if ( $ this -> config [ 'passDefaultValidator' ] ) { $ validator = $ table -> getValidator ( 'default' ) ; } else { $ validator = ne...
Sets the configured validators to the table instance
49,572
public function getImageVersions ( EntityInterface $ entity , $ options = [ ] ) { $ versionData = $ this -> _getImageVersionData ( $ entity , $ options ) ; $ versions = [ ] ; foreach ( $ versionData as $ version => $ data ) { $ hash = Configure :: read ( 'FileStorage.imageHashes.' . $ entity -> get ( 'model' ) . '.' . ...
Gets a list of image versions for a file storage entity .
49,573
protected function _getImageVersionData ( EntityInterface $ entity , array $ options = [ ] ) { $ versionData = ( array ) Configure :: read ( 'FileStorage.imageSizes.' . $ entity -> get ( 'model' ) ) ; if ( isset ( $ options [ 'originalVersion' ] ) ) { $ versionData [ 'original' ] = $ options [ 'originalVersion' ] ; } e...
Gets the image version data used to generate the versions .
49,574
protected function _autoRotate ( $ imageFile , $ format ) { $ orientation = ImagineUtility :: getImageOrientation ( $ imageFile ) ; $ degree = 0 ; if ( $ orientation === false ) { return false ; } if ( $ orientation === 0 ) { return true ; } switch ( $ orientation ) { case 180 : $ degree = - 180 ; break ; case - 90 : $...
Auto rotates the image if an orientation in the exif data is found that is not 0 .
49,575
protected function _createVersions ( Table $ table , $ entity , array $ operations ) { $ Storage = StorageManager :: adapter ( $ entity [ 'adapter' ] ) ; $ path = $ this -> _buildPath ( $ entity , true ) ; $ tmpFile = $ this -> _tmpFile ( $ Storage , $ path , TMP . 'image-processing' ) ; foreach ( $ operations as $ ver...
Creates the different versions of images that are configured
49,576
public function createVersions ( Event $ Event ) { if ( $ this -> _checkEvent ( $ Event ) ) { $ table = $ Event -> getSubject ( ) ; $ record = $ Event -> getData ( 'record' ) ; $ this -> _createVersions ( $ table , $ record , $ Event -> getData ( 'operations' ) ) ; $ Event -> stopPropagation ( ) ; } }
Creates versions for a given image record
49,577
protected function _removeVersions ( Event $ Event ) { if ( $ this -> _checkEvent ( $ Event ) ) { $ data = $ Event -> getData ( ) ; $ Storage = $ data [ 'storage' ] ; $ record = $ data [ 'record' ] ; foreach ( $ data [ 'operations' ] as $ version => $ operations ) { $ hash = StorageUtils :: hashOperations ( $ operation...
Removes versions for a given image record
49,578
protected function _buildLocalPath ( Event $ Event ) { $ data = $ Event -> getData ( ) ; extract ( $ data ) ; $ path = $ this -> _buildPath ( $ image , true , $ hash ) ; $ Event -> setData ( 'path' , $ Event -> result = '/' . $ path ) ; $ Event -> stopPropagation ( ) ; }
Builds an url to the given image
49,579
protected function _buildCloudFrontDistributionUrl ( $ protocol , $ image , $ bucket , $ bucketPrefix = null , $ cfDist = null ) { $ path = $ protocol . '://' ; if ( is_string ( $ cfDist ) ) { $ path .= $ cfDist ; } else { if ( $ bucketPrefix ) { $ path .= $ bucket . '.s3.amazonaws.com' ; } else { $ path .= 's3.amazona...
Builds an url to serve content from cloudfront
49,580
protected function _buildPath ( $ record , $ extension = true , $ hash = null ) { if ( $ this -> _config [ 'pathBuilderOptions' ] [ 'preserveFilename' ] === true ) { if ( ! empty ( $ hash ) ) { $ path = $ record [ 'path' ] . preg_replace ( '/\.[^.]*$/' , '' , $ record [ 'filename' ] ) . '.' . $ hash . '.' . $ record [ ...
Builds a path to a file
49,581
public function getAdapterClassName ( $ adapterConfigName ) { $ config = StorageManager :: config ( $ adapterConfigName ) ; switch ( $ config [ 'adapterClass' ] ) { case '\Gaufrette\Adapter\Local' : $ this -> adapterClass = 'Local' ; return $ this -> adapterClass ; case '\Gaufrette\Adapter\AwsS3' : $ this -> adapterCla...
Gets the adapter class name from the adapter configuration key
49,582
protected function setParameter ( $ key , $ value ) { if ( is_array ( $ value ) && isset ( $ value [ 'value' ] ) ) { $ value = $ value [ 'value' ] ; } $ this -> parameters -> set ( $ key , $ value ) ; return $ this ; }
Check if a Amount object is used store the value
49,583
public static function createInstance ( ) : self { return new static ( [ new Factory \ Argument ( new PrettyPrinter ( ) ) , new Factory \ Class_ ( ) , new Factory \ Constant ( new PrettyPrinter ( ) ) , new Factory \ DocBlock ( DocBlockFactory :: createInstance ( ) ) , new Factory \ File ( NodesFactory :: createInstance...
Creates a new instance of this factory . With all default strategies .
49,584
public function create ( $ name , array $ files ) : ProjectInterface { $ project = new Project ( $ name ) ; foreach ( $ files as $ filePath ) { $ strategy = $ this -> strategies -> findMatching ( $ filePath ) ; $ file = $ strategy -> create ( $ filePath , $ this -> strategies ) ; if ( $ file !== null ) { $ project -> a...
Creates a project from the set of files .
49,585
private function buildNamespaces ( Project $ project ) : void { foreach ( $ project -> getFiles ( ) as $ file ) { foreach ( $ file -> getNamespaces ( ) as $ namespaceFqsen ) { $ namespace = $ this -> getNamespaceByName ( $ project , ( string ) $ namespaceFqsen ) ; $ this -> buildNamespace ( $ file , $ namespace ) ; } }...
Builds the namespace tree with all elements in the project .
49,586
private function getNamespaceByName ( Project $ project , $ name ) : Namespace_ { $ existingNamespaces = $ project -> getNamespaces ( ) ; if ( isset ( $ existingNamespaces [ $ name ] ) ) { return $ existingNamespaces [ $ name ] ; } $ namespace = new Namespace_ ( new Fqsen ( $ name ) ) ; $ project -> addNamespace ( $ na...
Gets Namespace from the project if it exists otherwise returns a new namepace
49,587
private function buildNamespace ( File $ file , Namespace_ $ namespace ) : void { foreach ( $ file -> getClasses ( ) as $ class ) { if ( $ namespace -> getFqsen ( ) . '\\' . $ class -> getName ( ) === ( string ) $ class -> getFqsen ( ) ) { $ namespace -> addClass ( $ class -> getFqsen ( ) ) ; } } foreach ( $ file -> ge...
Adds all elements belonging to the namespace to the namespace .
49,588
protected function doCreate ( $ object , StrategyContainer $ strategies , ? Context $ context = null ) { $ visibility = $ this -> buildVisibility ( $ object ) ; $ default = null ; if ( $ object -> getDefault ( ) !== null ) { $ default = $ this -> valueConverter -> prettyPrintExpr ( $ object -> getDefault ( ) ) ; } $ do...
Creates an PropertyDescriptor out of the given object .
49,589
public function addConstant ( Constant $ constant ) : void { $ this -> constants [ ( string ) $ constant -> getFqsen ( ) ] = $ constant ; }
Add Constant to this class .
49,590
public function addProperty ( Property $ property ) : void { $ this -> properties [ ( string ) $ property -> getFqsen ( ) ] = $ property ; }
Add a property to this class .
49,591
protected function doCreate ( $ object , StrategyContainer $ strategies , ? Context $ context = null ) { $ docBlock = $ this -> createDocBlock ( $ strategies , $ object -> getDocComment ( ) , $ context ) ; $ returnType = null ; if ( $ object -> getReturnType ( ) !== null ) { $ typeResolver = new TypeResolver ( ) ; if (...
Creates an FunctionDescriptor out of the given object including its child elements .
49,592
protected function doCreate ( $ object , StrategyContainer $ strategies , ? Context $ context = null ) { $ docBlock = $ this -> createDocBlock ( $ strategies , $ object -> getDocComment ( ) , $ context ) ; $ returnType = null ; if ( $ object -> getReturnType ( ) !== null ) { $ typeResolver = new TypeResolver ( ) ; if (...
Creates an MethodDescriptor out of the given object including its child elements .
49,593
private function buildVisibility ( ClassMethod $ node ) : Visibility { if ( $ node -> isPrivate ( ) ) { return new Visibility ( Visibility :: PRIVATE_ ) ; } elseif ( $ node -> isProtected ( ) ) { return new Visibility ( Visibility :: PROTECTED_ ) ; } return new Visibility ( Visibility :: PUBLIC_ ) ; }
Converts the visibility of the method to a valid Visibility object .
49,594
protected function doCreate ( $ object , StrategyContainer $ strategies , ? Context $ context = null ) { $ command = new CreateCommand ( $ object , $ strategies ) ; $ middlewareChain = $ this -> middlewareChain ; return $ middlewareChain ( $ command ) ; }
Creates an File out of the given object .
49,595
public function leaveNode ( Node $ node ) { switch ( get_class ( $ node ) ) { case Namespace_ :: class : case Class_ :: class : case ClassMethod :: class : case Trait_ :: class : case PropertyProperty :: class : case ClassConst :: class : case Const_ :: class : case Interface_ :: class : case Function_ :: class : if ( ...
Performs a reset of the added element when needed .
49,596
public function enterNode ( Node $ node ) : ? int { switch ( get_class ( $ node ) ) { case Namespace_ :: class : $ this -> resetState ( '\\' . $ node -> name . '\\' ) ; $ node -> fqsen = new Fqsen ( $ this -> buildName ( ) ) ; break ; case Class_ :: class : case Trait_ :: class : case Interface_ :: class : if ( empty (...
Adds fqsen property to a node when applicable .
49,597
private function resetState ( ? string $ namespace = null ) : void { $ this -> parts = new SplDoublyLinkedList ( ) ; $ this -> parts -> push ( $ namespace ) ; }
Resets the state of the object to an empty state .
49,598
private function buildName ( ) : string { $ name = null ; foreach ( $ this -> parts as $ part ) { $ name .= $ part ; } return rtrim ( ( string ) $ name , '\\' ) ; }
Builds the name of the current node using the parts that are pushed to the parts list .
49,599
public static function createInstance ( $ kind = ParserFactory :: PREFER_PHP7 ) : self { $ parser = ( new ParserFactory ( ) ) -> create ( $ kind ) ; $ traverser = new NodeTraverser ( ) ; $ traverser -> addVisitor ( new NameResolver ( ) ) ; $ traverser -> addVisitor ( new ElementNameResolver ( ) ) ; return new static ( ...
Creates a new instance of NodeFactory with default Parser ands Traverser .