repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
burzum/cakephp-file-storage
src/Model/Behavior/FileStorageBehavior.php
FileStorageBehavior.afterSave
public function afterSave(Event $event, EntityInterface $entity, $options) { $this->dispatchEvent('FileStorage.afterSave', [ 'entity' => $entity, 'storageAdapter' => $this->getStorageAdapter($entity->get('adapter')) ], $this->_table); }
php
public function afterSave(Event $event, EntityInterface $entity, $options) { $this->dispatchEvent('FileStorage.afterSave', [ 'entity' => $entity, 'storageAdapter' => $this->getStorageAdapter($entity->get('adapter')) ], $this->_table); }
[ "public", "function", "afterSave", "(", "Event", "$", "event", ",", "EntityInterface", "$", "entity", ",", "$", "options", ")", "{", "$", "this", "->", "dispatchEvent", "(", "'FileStorage.afterSave'", ",", "[", "'entity'", "=>", "$", "entity", ",", "'storage...
afterSave callback @param \Cake\Event\Event $event @param \Cake\Datasource\EntityInterface $entity @param array $options @return void
[ "afterSave", "callback" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Model/Behavior/FileStorageBehavior.php#L117-L122
burzum/cakephp-file-storage
src/Model/Behavior/FileStorageBehavior.php
FileStorageBehavior._checkEntityBeforeSave
protected function _checkEntityBeforeSave(EntityInterface &$entity) { if ($entity->isNew()) { if (!$entity->has('model')) { $entity->set('model', $this->_table->getTable()); } if (!$entity->has('adapter')) { $entity->set('adapter', $this->getConfig('defaultStorageConfig')); } $fileHashMethod = $this->getConfig('getFileHash'); if ($fileHashMethod) { if ($fileHashMethod === true) { $fileHashMethod = 'sha1'; } $entity->set('hash', StorageUtils::getFileHash($entity->get('file')['tmp_name'], $fileHashMethod)); } } }
php
protected function _checkEntityBeforeSave(EntityInterface &$entity) { if ($entity->isNew()) { if (!$entity->has('model')) { $entity->set('model', $this->_table->getTable()); } if (!$entity->has('adapter')) { $entity->set('adapter', $this->getConfig('defaultStorageConfig')); } $fileHashMethod = $this->getConfig('getFileHash'); if ($fileHashMethod) { if ($fileHashMethod === true) { $fileHashMethod = 'sha1'; } $entity->set('hash', StorageUtils::getFileHash($entity->get('file')['tmp_name'], $fileHashMethod)); } } }
[ "protected", "function", "_checkEntityBeforeSave", "(", "EntityInterface", "&", "$", "entity", ")", "{", "if", "(", "$", "entity", "->", "isNew", "(", ")", ")", "{", "if", "(", "!", "$", "entity", "->", "has", "(", "'model'", ")", ")", "{", "$", "ent...
_checkEntityBeforeSave @param \Cake\Datasource\EntityInterface $entity @return void
[ "_checkEntityBeforeSave" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Model/Behavior/FileStorageBehavior.php#L130-L148
burzum/cakephp-file-storage
src/Model/Behavior/FileStorageBehavior.php
FileStorageBehavior.deleteOldFileOnSave
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->getPrimaryKey() => $entity->get($oldIdField), 'model' => $entity->get('model') ]) ->first(); if (!empty($oldEntity)) { return $this->_table->delete($oldEntity); } } return false; }
php
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->getPrimaryKey() => $entity->get($oldIdField), 'model' => $entity->get('model') ]) ->first(); if (!empty($oldEntity)) { return $this->_table->delete($oldEntity); } } return false; }
[ "public", "function", "deleteOldFileOnSave", "(", "EntityInterface", "$", "entity", ",", "$", "oldIdField", "=", "'old_file_id'", ")", "{", "if", "(", "!", "empty", "(", "$", "entity", "->", "get", "(", "$", "oldIdField", ")", ")", "&&", "$", "entity", "...
Deletes an old file to replace it with the new one if an old id was passed. Thought to be called in Table::afterSave() but can be used from any other place as well like Table::beforeSave() as long as the field data is present. The old id has to be the UUID of the file_storage record that should be deleted. Table::deleteAll() is intentionally not used because it doesn't trigger callbacks. @param \Cake\Datasource\EntityInterface $entity @param string $oldIdField Name of the field in the data that holds the old id. @return bool Returns true if the old record was deleted
[ "Deletes", "an", "old", "file", "to", "replace", "it", "with", "the", "new", "one", "if", "an", "old", "id", "was", "passed", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Model/Behavior/FileStorageBehavior.php#L179-L195
burzum/cakephp-file-storage
src/Model/Behavior/FileStorageBehavior.php
FileStorageBehavior._getFileInfoFromUpload
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(); } if (!empty($upload[$field]['name'])) { $upload['extension'] = pathinfo($upload[$field]['name'], PATHINFO_EXTENSION); $upload['filename'] = $upload[$field]['name']; } }
php
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(); } if (!empty($upload[$field]['name'])) { $upload['extension'] = pathinfo($upload[$field]['name'], PATHINFO_EXTENSION); $upload['filename'] = $upload[$field]['name']; } }
[ "public", "function", "_getFileInfoFromUpload", "(", "&", "$", "upload", ",", "$", "field", "=", "'file'", ")", "{", "if", "(", "!", "empty", "(", "$", "upload", "[", "$", "field", "]", "[", "'tmp_name'", "]", ")", ")", "{", "$", "File", "=", "new"...
Gets information about the file that is being uploaded. - gets the file size - gets the mime type - gets the extension if present @param array|\ArrayAccess $upload @param string $field @return void
[ "Gets", "information", "about", "the", "file", "that", "is", "being", "uploaded", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Model/Behavior/FileStorageBehavior.php#L208-L219
burzum/cakephp-file-storage
src/Model/Behavior/FileStorageBehavior.php
FileStorageBehavior.deleteAllFiles
public function deleteAllFiles($conditions) { $results = $this->find() ->select((array)$this->primaryKey()) ->where($conditions) ->all(); if ($results->count() > 0) { foreach ($results as $result) { $this->delete($result); } } return $results->count(); }
php
public function deleteAllFiles($conditions) { $results = $this->find() ->select((array)$this->primaryKey()) ->where($conditions) ->all(); if ($results->count() > 0) { foreach ($results as $result) { $this->delete($result); } } return $results->count(); }
[ "public", "function", "deleteAllFiles", "(", "$", "conditions", ")", "{", "$", "results", "=", "$", "this", "->", "find", "(", ")", "->", "select", "(", "(", "array", ")", "$", "this", "->", "primaryKey", "(", ")", ")", "->", "where", "(", "$", "co...
Don't use Table::deleteAll() if you don't want to end up with orphaned files! The reason for that is that deleteAll() doesn't fire the callbacks. So the events that will remove the files won't get fired. @param array $conditions Query::where() array structure. @return int Number of deleted records / files
[ "Don", "t", "use", "Table", "::", "deleteAll", "()", "if", "you", "don", "t", "want", "to", "end", "up", "with", "orphaned", "files!", "The", "reason", "for", "that", "is", "that", "deleteAll", "()", "doesn", "t", "fire", "the", "callbacks", ".", "So",...
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Model/Behavior/FileStorageBehavior.php#L229-L242
burzum/cakephp-file-storage
src/Storage/StorageUtils.php
StorageUtils.fileExtension
public static function fileExtension($name, $realFile = false) { if ($realFile) { $result = pathinfo($name, PATHINFO_EXTENSION); if (empty($result)) { return false; } } return substr(strrchr($name, '.'), 1); }
php
public static function fileExtension($name, $realFile = false) { if ($realFile) { $result = pathinfo($name, PATHINFO_EXTENSION); if (empty($result)) { return false; } } return substr(strrchr($name, '.'), 1); }
[ "public", "static", "function", "fileExtension", "(", "$", "name", ",", "$", "realFile", "=", "false", ")", "{", "if", "(", "$", "realFile", ")", "{", "$", "result", "=", "pathinfo", "(", "$", "name", ",", "PATHINFO_EXTENSION", ")", ";", "if", "(", "...
Return file extension from a given filename. @param string $name File name @param bool|bool $realFile @link http://php.net/manual/en/function.pathinfo.php @return false|string string or false
[ "Return", "file", "extension", "from", "a", "given", "filename", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageUtils.php#L28-L37
burzum/cakephp-file-storage
src/Storage/StorageUtils.php
StorageUtils.trimPath
public static function trimPath($path) { $len = strlen($path); if ($path[$len - 1] == '\\' || $path[$len - 1] == '/') { $path = substr($path, 0, $len - 1); } return $path; }
php
public static function trimPath($path) { $len = strlen($path); if ($path[$len - 1] == '\\' || $path[$len - 1] == '/') { $path = substr($path, 0, $len - 1); } return $path; }
[ "public", "static", "function", "trimPath", "(", "$", "path", ")", "{", "$", "len", "=", "strlen", "(", "$", "path", ")", ";", "if", "(", "$", "path", "[", "$", "len", "-", "1", "]", "==", "'\\\\'", "||", "$", "path", "[", "$", "len", "-", "1...
Helper method to trim last trailing slash in file path @param string $path Path to trim @return string Trimmed path
[ "Helper", "method", "to", "trim", "last", "trailing", "slash", "in", "file", "path" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageUtils.php#L68-L75
burzum/cakephp-file-storage
src/Storage/StorageUtils.php
StorageUtils.normalizeGlobalFilesArray
public static function normalizeGlobalFilesArray($files = null) { if (empty($files)) { $files = $_FILES; } $array = []; $fileCount = count($files['name']); $fileKeys = array_keys($files); for ($i = 0; $i < $fileCount; $i++) { foreach ($fileKeys as $key) { $array[$i][$key] = $files[$key][$i]; } } return $array; }
php
public static function normalizeGlobalFilesArray($files = null) { if (empty($files)) { $files = $_FILES; } $array = []; $fileCount = count($files['name']); $fileKeys = array_keys($files); for ($i = 0; $i < $fileCount; $i++) { foreach ($fileKeys as $key) { $array[$i][$key] = $files[$key][$i]; } } return $array; }
[ "public", "static", "function", "normalizeGlobalFilesArray", "(", "$", "files", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "files", ")", ")", "{", "$", "files", "=", "$", "_FILES", ";", "}", "$", "array", "=", "[", "]", ";", "$", "fileCou...
Method to normalize the annoying inconsistency of the $_FILE array structure @link http://de2.php.net/manual/en/features.file-upload.multiple.php#53240 @param array|null $files Files array @return array Empty array if $_FILE is empty, if not normalize array of Filedata.{n}
[ "Method", "to", "normalize", "the", "annoying", "inconsistency", "of", "the", "$_FILE", "array", "structure" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageUtils.php#L98-L114
burzum/cakephp-file-storage
src/Storage/StorageUtils.php
StorageUtils.generateHashes
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 in `%s` is missing!', $configPath . '.imageSizes')); } static::ksortRecursive($imageSizes); foreach ($imageSizes as $model => $version) { foreach ($version as $name => $operations) { Configure::write($configPath . '.imageHashes.' . $model . '.' . $name, static::hashOperations($operations)); } } return Configure::read($configPath . '.imageHashes'); }
php
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 in `%s` is missing!', $configPath . '.imageSizes')); } static::ksortRecursive($imageSizes); foreach ($imageSizes as $model => $version) { foreach ($version as $name => $operations) { Configure::write($configPath . '.imageHashes.' . $model . '.' . $name, static::hashOperations($operations)); } } return Configure::read($configPath . '.imageHashes'); }
[ "public", "static", "function", "generateHashes", "(", "$", "configPath", "=", "'FileStorage'", ")", "{", "if", "(", "is_array", "(", "$", "configPath", ")", ")", "{", "$", "imageSizes", "=", "$", "configPath", ";", "}", "else", "{", "$", "imageSizes", "...
Generates the hashes for the different image version configurations. @param string|array $configPath @return array
[ "Generates", "the", "hashes", "for", "the", "different", "image", "version", "configurations", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageUtils.php#L134-L152
burzum/cakephp-file-storage
src/Storage/StorageUtils.php
StorageUtils.ksortRecursive
public static function ksortRecursive(&$array, $sortFlags = SORT_REGULAR) { if (!is_array($array)) { return false; } ksort($array, $sortFlags); foreach ($array as &$arr) { static::ksortRecursive($arr, $sortFlags); } return true; }
php
public static function ksortRecursive(&$array, $sortFlags = SORT_REGULAR) { if (!is_array($array)) { return false; } ksort($array, $sortFlags); foreach ($array as &$arr) { static::ksortRecursive($arr, $sortFlags); } return true; }
[ "public", "static", "function", "ksortRecursive", "(", "&", "$", "array", ",", "$", "sortFlags", "=", "SORT_REGULAR", ")", "{", "if", "(", "!", "is_array", "(", "$", "array", ")", ")", "{", "return", "false", ";", "}", "ksort", "(", "$", "array", ","...
Recursive ksort() implementation @param array $array Array @param int Sort flags @return bool @link https://gist.github.com/601849
[ "Recursive", "ksort", "()", "implementation" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageUtils.php#L162-L173
burzum/cakephp-file-storage
src/Storage/StorageUtils.php
StorageUtils.fileToUploadArray
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() ]; }
php
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() ]; }
[ "public", "static", "function", "fileToUploadArray", "(", "$", "file", ",", "$", "filename", "=", "null", ")", "{", "$", "File", "=", "new", "File", "(", "$", "file", ")", ";", "if", "(", "empty", "(", "$", "fileName", ")", ")", "{", "$", "filename...
Returns an array that matches the structure of a regular upload for a local file @param string $file The file you want to get an upload array for. @param string|null Name of the file to use in the upload array. @return array Array that matches the structure of a regular upload
[ "Returns", "an", "array", "that", "matches", "the", "structure", "of", "a", "regular", "upload", "for", "a", "local", "file" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageUtils.php#L182-L195
burzum/cakephp-file-storage
src/Storage/StorageUtils.php
StorageUtils.createTmpFile
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(); }
php
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(); }
[ "public", "static", "function", "createTmpFile", "(", "$", "folder", "=", "null", ",", "$", "checkAndCreatePath", "=", "true", ")", "{", "if", "(", "$", "folder", "===", "null", ")", "{", "$", "folder", "=", "TMP", ";", "}", "if", "(", "$", "checkAnd...
Creates a temporary file name and checks the tmp path, creates one if required. This method is thought to be used to generate tmp file locations for use cases like audio or image process were you need copies of a file and want to avoid conflicts. By default the tmp file is generated using cakes TMP constant + folder if passed and a uuid as filename. @param string|null $folder @param bool|bool $checkAndCreatePath @return string For example /var/www/app/tmp/<uuid> or /var/www/app/tmp/<my-folder>/<uuid>
[ "Creates", "a", "temporary", "file", "name", "and", "checks", "the", "tmp", "path", "creates", "one", "if", "required", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageUtils.php#L209-L218
burzum/cakephp-file-storage
src/Storage/StorageUtils.php
StorageUtils.getFileHash
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)); }
php
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)); }
[ "public", "static", "function", "getFileHash", "(", "$", "file", ",", "$", "method", "=", "'sha1'", ")", "{", "if", "(", "$", "method", "===", "'md5'", ")", "{", "return", "md5_file", "(", "$", "file", ")", ";", "}", "if", "(", "$", "method", "==="...
Gets the hash of a file. You can use this to compare if you got two times the same file uploaded. @param string $file Path to the file on your local machine. @param string $method 'md5' or 'sha1' @throws \InvalidArgumentException @link http://php.net/manual/en/function.md5-file.php @link http://php.net/manual/en/function.sha1-file.php @link http://php.net/manual/en/function.sha1-file.php#104748 @return string
[ "Gets", "the", "hash", "of", "a", "file", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageUtils.php#L244-L253
burzum/cakephp-file-storage
src/Storage/PathBuilder/S3PathBuilder.php
S3PathBuilder._buildCloudUrl
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 .= $this->_config['s3Url'] . '/' . $bucket; } } return $path; }
php
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 .= $this->_config['s3Url'] . '/' . $bucket; } } return $path; }
[ "protected", "function", "_buildCloudUrl", "(", "$", "bucket", ",", "$", "bucketPrefix", "=", "null", ",", "$", "cfDist", "=", "null", ")", "{", "$", "path", "=", "$", "this", "->", "getConfig", "(", "'https'", ")", "===", "true", "?", "'https://'", ":...
Builds the cloud base URL for the given bucket and location. @param string $bucket @param string|null $bucketPrefix @param string|null $cfDist @return string
[ "Builds", "the", "cloud", "base", "URL", "for", "the", "given", "bucket", "and", "location", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/S3PathBuilder.php#L47-L60
burzum/cakephp-file-storage
src/Storage/PathBuilder/S3PathBuilder.php
S3PathBuilder.url
public function url(EntityInterface $entity, array $options = []) { $bucket = $this->_getBucket($entity->adapter); $pathPrefix = $this->ensureSlash($this->_buildCloudUrl($bucket), 'after'); $path = parent::path($entity); $path = str_replace('\\', '/', $path); return $pathPrefix . $path . $this->filename($entity, $options); }
php
public function url(EntityInterface $entity, array $options = []) { $bucket = $this->_getBucket($entity->adapter); $pathPrefix = $this->ensureSlash($this->_buildCloudUrl($bucket), 'after'); $path = parent::path($entity); $path = str_replace('\\', '/', $path); return $pathPrefix . $path . $this->filename($entity, $options); }
[ "public", "function", "url", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "bucket", "=", "$", "this", "->", "_getBucket", "(", "$", "entity", "->", "adapter", ")", ";", "$", "pathPrefix", "=", "$"...
Builds the URL under which the file is accessible. This is for example important for S3 and Dropbox but also the Local adapter if you symlink a folder to your webroot and allow direct access to a file. @param \Cake\Datasource\EntityInterface $entity @param array $options @return string
[ "Builds", "the", "URL", "under", "which", "the", "file", "is", "accessible", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/S3PathBuilder.php#L72-L79
burzum/cakephp-file-storage
src/Model/Behavior/UploadBehavior.php
UploadBehavior.afterSave
public function afterSave(Event $event, EntityInterface $entity) { if ($this->getConfig('uploadOn') === 'afterSave') { $this->_handleFiles($entity); } }
php
public function afterSave(Event $event, EntityInterface $entity) { if ($this->getConfig('uploadOn') === 'afterSave') { $this->_handleFiles($entity); } }
[ "public", "function", "afterSave", "(", "Event", "$", "event", ",", "EntityInterface", "$", "entity", ")", "{", "if", "(", "$", "this", "->", "getConfig", "(", "'uploadOn'", ")", "===", "'afterSave'", ")", "{", "$", "this", "->", "_handleFiles", "(", "$"...
After save callback. @param \Cake\Event\Event $event Event @param \Cake\Datasource\EntityInterface $entity Entity @return void
[ "After", "save", "callback", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Model/Behavior/UploadBehavior.php#L55-L59
burzum/cakephp-file-storage
src/Model/Behavior/UploadBehavior.php
UploadBehavior.beforeSave
public function beforeSave(Event $event, EntityInterface $entity) { if ($this->getConfig('uploadOn') === 'beforeSave') { $this->_handleFiles($entity); } }
php
public function beforeSave(Event $event, EntityInterface $entity) { if ($this->getConfig('uploadOn') === 'beforeSave') { $this->_handleFiles($entity); } }
[ "public", "function", "beforeSave", "(", "Event", "$", "event", ",", "EntityInterface", "$", "entity", ")", "{", "if", "(", "$", "this", "->", "getConfig", "(", "'uploadOn'", ")", "===", "'beforeSave'", ")", "{", "$", "this", "->", "_handleFiles", "(", "...
Before save callback. @param \Cake\Event\Event $event @param \Cake\Datasource\EntityInterface $entity @return void
[ "Before", "save", "callback", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Model/Behavior/UploadBehavior.php#L68-L72
burzum/cakephp-file-storage
src/Model/Behavior/UploadBehavior.php
UploadBehavior._handleFiles
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->getConfig('defaults'); $options += $file; } if (is_string($file)) { $field = $file; $options = $this->getConfig('defaults'); } $results[$field] = $this->saveFile($entity->{$field}, $options); } return $results; }
php
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->getConfig('defaults'); $options += $file; } if (is_string($file)) { $field = $file; $options = $this->getConfig('defaults'); } $results[$field] = $this->saveFile($entity->{$field}, $options); } return $results; }
[ "protected", "function", "_handleFiles", "(", "EntityInterface", "$", "entity", ")", "{", "$", "files", "=", "$", "this", "->", "getConfig", "(", "'file'", ")", ";", "if", "(", "is_string", "(", "$", "files", ")", ")", "{", "$", "files", "=", "[", "$...
This method is looking for the actual file upload fields and processes them. @param \Cake\Datasource\EntityInterface @return array
[ "This", "method", "is", "looking", "for", "the", "actual", "file", "upload", "fields", "and", "processes", "them", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Model/Behavior/UploadBehavior.php#L80-L101
burzum/cakephp-file-storage
src/Model/Behavior/UploadBehavior.php
UploadBehavior._getStorageModel
protected function _getStorageModel($options) { if (!empty($options['association'])) { return $this->{$options['association']}; } return TableRegistry::getTableLocator()->get($options['model']); }
php
protected function _getStorageModel($options) { if (!empty($options['association'])) { return $this->{$options['association']}; } return TableRegistry::getTableLocator()->get($options['model']); }
[ "protected", "function", "_getStorageModel", "(", "$", "options", ")", "{", "if", "(", "!", "empty", "(", "$", "options", "[", "'association'", "]", ")", ")", "{", "return", "$", "this", "->", "{", "$", "options", "[", "'association'", "]", "}", ";", ...
Gets the storage table instance. @param array $options Options. @return \Cake\ORM\Table
[ "Gets", "the", "storage", "table", "instance", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Model/Behavior/UploadBehavior.php#L109-L115
burzum/cakephp-file-storage
src/Model/Behavior/UploadBehavior.php
UploadBehavior.saveFile
public function saveFile($file, $options = []) { $defaults = $this->getConfig('defaults'); $defaults += $options; $options = $defaults; if (is_string($file)) { $file = StorageUtils::fileToUploadArray($file); } $model = $this->_getStorageModel($options); $entity = $this->_composeEntity($file, $model, $options); $model->save($entity); return $entity; }
php
public function saveFile($file, $options = []) { $defaults = $this->getConfig('defaults'); $defaults += $options; $options = $defaults; if (is_string($file)) { $file = StorageUtils::fileToUploadArray($file); } $model = $this->_getStorageModel($options); $entity = $this->_composeEntity($file, $model, $options); $model->save($entity); return $entity; }
[ "public", "function", "saveFile", "(", "$", "file", ",", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "$", "this", "->", "getConfig", "(", "'defaults'", ")", ";", "$", "defaults", "+=", "$", "options", ";", "$", "options", "=", "$...
Save a file. @param array|string $file @param array $options @return \Cake\Datasource\EntityInterface
[ "Save", "a", "file", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Model/Behavior/UploadBehavior.php#L149-L164
burzum/cakephp-file-storage
config/Migrations/20141213004653_initial_migration.php
InitialMigration.up
public function up() { $this->table('file_storage', ['id' => false, 'primary_key' => 'id']) ->addColumn('id', 'char', ['limit' => 36]) ->addColumn('user_id', 'char', ['limit' => 36, 'null' => true, 'default' => null]) ->addColumn('foreign_key', 'char', ['limit' => 36, 'null' => true, 'default' => null]) ->addColumn('model', 'string', ['limit' => 128, 'null' => true, 'default' => null]) ->addColumn('filename', 'string', ['limit' => 255, 'null' => true, 'default' => null]) ->addColumn('filesize', 'integer', ['limit' => 16, 'null' => true, 'default' => null]) ->addColumn('mime_type', 'string', ['limit' => 32, 'null' => true, 'default' => null]) ->addColumn('extension', 'string', ['limit' => 5, 'null' => true, 'default' => null]) ->addColumn('hash', 'string', ['limit' => 64, 'null' => true, 'default' => null]) ->addColumn('path', 'string', ['null' => true, 'default' => null]) ->addColumn('adapter', 'string', ['limit' => 32, 'null' => true, 'default' => null]) ->addColumn('created', 'datetime', ['null' => true, 'default' => null]) ->addColumn('modified', 'datetime', ['null' => true, 'default' => null]) ->create(); }
php
public function up() { $this->table('file_storage', ['id' => false, 'primary_key' => 'id']) ->addColumn('id', 'char', ['limit' => 36]) ->addColumn('user_id', 'char', ['limit' => 36, 'null' => true, 'default' => null]) ->addColumn('foreign_key', 'char', ['limit' => 36, 'null' => true, 'default' => null]) ->addColumn('model', 'string', ['limit' => 128, 'null' => true, 'default' => null]) ->addColumn('filename', 'string', ['limit' => 255, 'null' => true, 'default' => null]) ->addColumn('filesize', 'integer', ['limit' => 16, 'null' => true, 'default' => null]) ->addColumn('mime_type', 'string', ['limit' => 32, 'null' => true, 'default' => null]) ->addColumn('extension', 'string', ['limit' => 5, 'null' => true, 'default' => null]) ->addColumn('hash', 'string', ['limit' => 64, 'null' => true, 'default' => null]) ->addColumn('path', 'string', ['null' => true, 'default' => null]) ->addColumn('adapter', 'string', ['limit' => 32, 'null' => true, 'default' => null]) ->addColumn('created', 'datetime', ['null' => true, 'default' => null]) ->addColumn('modified', 'datetime', ['null' => true, 'default' => null]) ->create(); }
[ "public", "function", "up", "(", ")", "{", "$", "this", "->", "table", "(", "'file_storage'", ",", "[", "'id'", "=>", "false", ",", "'primary_key'", "=>", "'id'", "]", ")", "->", "addColumn", "(", "'id'", ",", "'char'", ",", "[", "'limit'", "=>", "36...
Migrate Up.
[ "Migrate", "Up", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/config/Migrations/20141213004653_initial_migration.php#L9-L25
burzum/cakephp-file-storage
src/Shell/StorageShell.php
StorageShell._storePrecheck
protected function _storePrecheck() { if (empty($this->args[0])) { $this->abort('No file provided!'); } if (!file_exists($this->args[0])) { $this->abort('The file does not exist!'); } $adapterConfig = StorageManager::config($this->params['adapter']); if (empty($adapterConfig)) { $this->abort(sprintf('Invalid adapter config `%s` provided!', $this->params['adapter'])); } }
php
protected function _storePrecheck() { if (empty($this->args[0])) { $this->abort('No file provided!'); } if (!file_exists($this->args[0])) { $this->abort('The file does not exist!'); } $adapterConfig = StorageManager::config($this->params['adapter']); if (empty($adapterConfig)) { $this->abort(sprintf('Invalid adapter config `%s` provided!', $this->params['adapter'])); } }
[ "protected", "function", "_storePrecheck", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "args", "[", "0", "]", ")", ")", "{", "$", "this", "->", "abort", "(", "'No file provided!'", ")", ";", "}", "if", "(", "!", "file_exists", "(", "...
Does the arg and params checks for store(). @return void
[ "Does", "the", "arg", "and", "params", "checks", "for", "store", "()", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Shell/StorageShell.php#L68-L81
burzum/cakephp-file-storage
src/Shell/StorageShell.php
StorageShell.store
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' => $fileData['name'] ]); if ($model->save($entity)) { $this->out('File successfully saved!'); $this->out('UUID: ' . $entity->id); $this->out('Path: ' . $entity->path()); } else { $this->abort('Failed to save the file.'); } }
php
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' => $fileData['name'] ]); if ($model->save($entity)) { $this->out('File successfully saved!'); $this->out('UUID: ' . $entity->id); $this->out('Path: ' . $entity->path()); } else { $this->abort('Failed to save the file.'); } }
[ "public", "function", "store", "(", ")", "{", "$", "this", "->", "_storePrecheck", "(", ")", ";", "$", "model", "=", "$", "this", "->", "loadModel", "(", "$", "this", "->", "params", "[", "'model'", "]", ")", ";", "$", "fileData", "=", "StorageUtils"...
Store a local file via command line in any storage backend. @return void
[ "Store", "a", "local", "file", "via", "command", "line", "in", "any", "storage", "backend", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Shell/StorageShell.php#L88-L105
burzum/cakephp-file-storage
src/Storage/Listener/AbstractListener.php
AbstractListener._checkEvent
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` adapter class! Probably because it can\'t work with it.'; throw new StorageException(sprintf( $message, get_class($this), $className )); } return $event->getSubject() instanceof Table && $this->_modelFilter($event); }
php
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` adapter class! Probably because it can\'t work with it.'; throw new StorageException(sprintf( $message, get_class($this), $className )); } return $event->getSubject() instanceof Table && $this->_modelFilter($event); }
[ "protected", "function", "_checkEvent", "(", "Event", "$", "event", ")", "{", "$", "className", "=", "$", "this", "->", "_getAdapterClassFromConfig", "(", "$", "event", "->", "getData", "(", "'entity'", ")", "[", "'adapter'", "]", ")", ";", "$", "classes",...
Check if the event is of a type or subject object of type model we want to process with this listener. @param \Cake\Event\Event $event @return bool @throws \Burzum\FileStorage\Storage\StorageException
[ "Check", "if", "the", "event", "is", "of", "a", "type", "or", "subject", "object", "of", "type", "model", "we", "want", "to", "process", "with", "this", "listener", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/AbstractListener.php#L156-L170
burzum/cakephp-file-storage
src/Storage/Listener/AbstractListener.php
AbstractListener._identifierFilter
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; }
php
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; }
[ "protected", "function", "_identifierFilter", "(", "Event", "$", "event", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "_config", "[", "'identifiers'", "]", ")", ")", "{", "$", "identifier", "=", "$", "event", "->", "getData", "(", "'entity.m...
Detects if an entities model field has name of one of the allowed models set. @param \Cake\Event\Event $event @return bool
[ "Detects", "if", "an", "entities", "model", "field", "has", "name", "of", "one", "of", "the", "allowed", "models", "set", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/AbstractListener.php#L182-L191
burzum/cakephp-file-storage
src/Storage/Listener/AbstractListener.php
AbstractListener._getAdapterClassFromConfig
protected function _getAdapterClassFromConfig($configName) { $config = $this->getStorageConfig($configName); if (!empty($config['adapterClass'])) { return $config['adapterClass']; } return false; }
php
protected function _getAdapterClassFromConfig($configName) { $config = $this->getStorageConfig($configName); if (!empty($config['adapterClass'])) { return $config['adapterClass']; } return false; }
[ "protected", "function", "_getAdapterClassFromConfig", "(", "$", "configName", ")", "{", "$", "config", "=", "$", "this", "->", "getStorageConfig", "(", "$", "configName", ")", ";", "if", "(", "!", "empty", "(", "$", "config", "[", "'adapterClass'", "]", "...
Gets the adapter class name from the adapter config @param string $configName Name of the configuration @return bool|string False if the config is not present
[ "Gets", "the", "adapter", "class", "name", "from", "the", "adapter", "config" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/AbstractListener.php#L199-L207
burzum/cakephp-file-storage
src/Storage/Listener/AbstractListener.php
AbstractListener.getAdapterClassName
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)); return $this->_adapterClass; } return false; }
php
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)); return $this->_adapterClass; } return false; }
[ "public", "function", "getAdapterClassName", "(", "$", "configName", ")", "{", "$", "className", "=", "$", "this", "->", "_getAdapterClassFromConfig", "(", "$", "configName", ")", ";", "if", "(", "in_array", "(", "$", "className", ",", "$", "this", "->", "...
Gets the adapter class name from the adapter configuration key and checks if it is in the list of supported adapters for the listener. You must define a list of supported classes via AbstractStorageEventListener::$_adapterClasses. @param string $configName Name of the adapter configuration. @return string|false String, the adapter class name or false if it was not found.
[ "Gets", "the", "adapter", "class", "name", "from", "the", "adapter", "configuration", "key", "and", "checks", "if", "it", "is", "in", "the", "list", "of", "supported", "adapters", "for", "the", "listener", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/AbstractListener.php#L218-L228
burzum/cakephp-file-storage
src/Storage/Listener/AbstractListener.php
AbstractListener._tmpFile
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('Failed to create the temporary file.', 0, $e); } }
php
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('Failed to create the temporary file.', 0, $e); } }
[ "protected", "function", "_tmpFile", "(", "$", "Storage", ",", "$", "path", ",", "$", "tmpFolder", "=", "null", ")", "{", "try", "{", "$", "tmpFile", "=", "$", "this", "->", "createTmpFile", "(", "$", "tmpFolder", ")", ";", "file_put_contents", "(", "$...
Create a temporary file locally based on a file from an adapter. A common case is image manipulation or video processing for example. It is required to get the file first from the adapter and then write it to a tmp file. Then manipulate it and upload the changed file. The adapter might not be one that is using a local file system, so we first get the file from the storage system, store it locally in a tmp file and later load the new file that was generated based on the tmp file into the storage adapter. This method here just generates the tmp file. @param Adapter $Storage Storage adapter @param string $path Path / key of the storage adapter file @param string|null $tmpFolder @throws \Burzum\FileStorage\Storage\StorageException @return string
[ "Create", "a", "temporary", "file", "locally", "based", "on", "a", "file", "from", "an", "adapter", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/AbstractListener.php#L248-L258
burzum/cakephp-file-storage
src/Storage/Listener/AbstractListener.php
AbstractListener.getPath
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($pathBuilder), $method)); }; $event = $this->dispatchEvent('FileStorage.beforeGetPath', [ 'entity' => $event->getData('entity'), 'storageAdapter' => $this->getStorageAdapter($event->getData('entity')->get('adapter')), 'pathBuilder' => $pathBuilder ]); if ($event->isStopped()) { return $event->result; } if ($event->getSubject() instanceof EntityInterface) { $event->getData('entity'); } if (empty($event->getData('entity'))) { throw new RuntimeException('No entity present!'); } $path = $pathBuilder->{$method}($event->getData('entity'), $event->getData()); $entity = $event->getData('entity'); $event = $this->dispatchEvent('FileStorage.afterGetPath', [ 'entity' => $entity, 'storageAdapter' => $this->getStorageAdapter($entity->get('adapter')), 'pathBuilder' => $pathBuilder, 'path' => $path ]); if ($event->isStopped()) { return $event->getResult(); } return $path; }
php
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($pathBuilder), $method)); }; $event = $this->dispatchEvent('FileStorage.beforeGetPath', [ 'entity' => $event->getData('entity'), 'storageAdapter' => $this->getStorageAdapter($event->getData('entity')->get('adapter')), 'pathBuilder' => $pathBuilder ]); if ($event->isStopped()) { return $event->result; } if ($event->getSubject() instanceof EntityInterface) { $event->getData('entity'); } if (empty($event->getData('entity'))) { throw new RuntimeException('No entity present!'); } $path = $pathBuilder->{$method}($event->getData('entity'), $event->getData()); $entity = $event->getData('entity'); $event = $this->dispatchEvent('FileStorage.afterGetPath', [ 'entity' => $entity, 'storageAdapter' => $this->getStorageAdapter($entity->get('adapter')), 'pathBuilder' => $pathBuilder, 'path' => $path ]); if ($event->isStopped()) { return $event->getResult(); } return $path; }
[ "public", "function", "getPath", "(", "Event", "$", "event", ")", "{", "$", "pathBuilder", "=", "$", "this", "->", "pathBuilder", "(", ")", ";", "$", "method", "=", "$", "event", "->", "getData", "(", "'method'", ")", ";", "if", "(", "!", "method_exi...
Get the path for a storage entity. @param \Cake\Event\Event $event @return string
[ "Get", "the", "path", "for", "a", "storage", "entity", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/AbstractListener.php#L293-L333
burzum/cakephp-file-storage
src/Storage/Listener/AbstractListener.php
AbstractListener._storeFile
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->getStorageAdapter($entity['adapter']); $Storage->write($entity['path'], file_get_contents($entity[$fileField]['tmp_name']), true); $event->result = $event->getSubject()->save($entity, [ 'checkRules' => false ]); $this->_afterStoreFile($event); if ($event->isStopped()) { return $event->result; } return true; } catch (\Exception $e) { $this->log($e->getMessage(), LogLevel::ERROR, ['scope' => ['storage']]); throw new StorageException($e->getMessage(), $e->getCode(), $e); } return false; }
php
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->getStorageAdapter($entity['adapter']); $Storage->write($entity['path'], file_get_contents($entity[$fileField]['tmp_name']), true); $event->result = $event->getSubject()->save($entity, [ 'checkRules' => false ]); $this->_afterStoreFile($event); if ($event->isStopped()) { return $event->result; } return true; } catch (\Exception $e) { $this->log($e->getMessage(), LogLevel::ERROR, ['scope' => ['storage']]); throw new StorageException($e->getMessage(), $e->getCode(), $e); } return false; }
[ "protected", "function", "_storeFile", "(", "Event", "$", "event", ")", "{", "try", "{", "$", "beforeEvent", "=", "$", "this", "->", "_beforeStoreFile", "(", "$", "event", ")", ";", "if", "(", "$", "beforeEvent", "->", "isStopped", "(", ")", ")", "{", ...
Stores the file in the configured storage backend. @param \Cake\Event\Event $event @return bool @throws \Burzum\FileStorage\Storage\StorageException
[ "Stores", "the", "file", "in", "the", "configured", "storage", "backend", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/AbstractListener.php#L342-L370
burzum/cakephp-file-storage
src/Storage/Listener/AbstractListener.php
AbstractListener._deleteFile
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; $event->setData('path', $path); $event->setData('entity', $entity); $this->_afterDeleteFile($event); return true; } } catch (\Exception $e) { $this->log($e->getMessage(), LogLevel::ERROR, ['scope' => ['storage']]); throw new StorageException($e->getMessage(), $e->getCode(), $e); } return false; }
php
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; $event->setData('path', $path); $event->setData('entity', $entity); $this->_afterDeleteFile($event); return true; } } catch (\Exception $e) { $this->log($e->getMessage(), LogLevel::ERROR, ['scope' => ['storage']]); throw new StorageException($e->getMessage(), $e->getCode(), $e); } return false; }
[ "protected", "function", "_deleteFile", "(", "Event", "$", "event", ")", "{", "try", "{", "$", "this", "->", "_beforeDeleteFile", "(", "$", "event", ")", ";", "$", "entity", "=", "$", "event", "->", "getData", "(", "'entity'", ")", ";", "$", "path", ...
Deletes the file from the configured storage backend. @param \Cake\Event\Event $event @return bool @throws \Burzum\FileStorage\Storage\StorageException
[ "Deletes", "the", "file", "from", "the", "configured", "storage", "backend", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/AbstractListener.php#L379-L399
burzum/cakephp-file-storage
src/Storage/Listener/AbstractListener.php
AbstractListener._afterStoreFile
protected function _afterStoreFile(Event $event) { $entity = $event->getData('entity'); return $this->dispatchEvent('FileStorage.afterStoreFile', [ 'entity' => $event->getData('entity'), 'adapter' => $this->getStorageAdapter($entity->get('adapter')) ]); }
php
protected function _afterStoreFile(Event $event) { $entity = $event->getData('entity'); return $this->dispatchEvent('FileStorage.afterStoreFile', [ 'entity' => $event->getData('entity'), 'adapter' => $this->getStorageAdapter($entity->get('adapter')) ]); }
[ "protected", "function", "_afterStoreFile", "(", "Event", "$", "event", ")", "{", "$", "entity", "=", "$", "event", "->", "getData", "(", "'entity'", ")", ";", "return", "$", "this", "->", "dispatchEvent", "(", "'FileStorage.afterStoreFile'", ",", "[", "'ent...
Callback to handle the case something needs to be done after the file was successfully stored in the storage backend. By default this will trigger an event FileStorage.afterStoreFile but you can also just overload this method and implement your own logic here. This method is a good place to flag a file for some post processing or directly doing the post processing like image versions or video compression. @param \Cake\Event\Event $event @return \Cake\Event\Event
[ "Callback", "to", "handle", "the", "case", "something", "needs", "to", "be", "done", "after", "the", "file", "was", "successfully", "stored", "in", "the", "storage", "backend", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/AbstractListener.php#L430-L437
burzum/cakephp-file-storage
src/Storage/Listener/AbstractListener.php
AbstractListener._afterDeleteFile
protected function _afterDeleteFile(Event $event) { $entity = $event->getData('entity'); return $this->dispatchEvent('FileStorage.afterDeleteFile', [ 'entity' => $entity, 'adapter' => $this->getStorageAdapter($entity->get('adapter')) ]); }
php
protected function _afterDeleteFile(Event $event) { $entity = $event->getData('entity'); return $this->dispatchEvent('FileStorage.afterDeleteFile', [ 'entity' => $entity, 'adapter' => $this->getStorageAdapter($entity->get('adapter')) ]); }
[ "protected", "function", "_afterDeleteFile", "(", "Event", "$", "event", ")", "{", "$", "entity", "=", "$", "event", "->", "getData", "(", "'entity'", ")", ";", "return", "$", "this", "->", "dispatchEvent", "(", "'FileStorage.afterDeleteFile'", ",", "[", "'e...
Callback to handle the case something needs to be done after the file was successfully removed from the storage backend. By default this will trigger an event FileStorage.afterStoreFile but you can also just overload this method. @param \Cake\Event\Event $event @return \Cake\Event\Event
[ "Callback", "to", "handle", "the", "case", "something", "needs", "to", "be", "done", "after", "the", "file", "was", "successfully", "removed", "from", "the", "storage", "backend", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/AbstractListener.php#L468-L475
burzum/cakephp-file-storage
src/Storage/PathBuilder/PathBuilderTrait.php
PathBuilderTrait.createPathBuilder
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_exists($className)) { throw new RuntimeException(sprintf('Could not find path builder "%s"!', $name)); } $pathBuilder = new $className($options); if (!$pathBuilder instanceof PathBuilderInterface) { throw new RuntimeException(sprintf('Path builder class "%s" does not implement the PathBuilderInterface interface!', $name)); } return $this->_pathBuilder = $pathBuilder; }
php
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_exists($className)) { throw new RuntimeException(sprintf('Could not find path builder "%s"!', $name)); } $pathBuilder = new $className($options); if (!$pathBuilder instanceof PathBuilderInterface) { throw new RuntimeException(sprintf('Path builder class "%s" does not implement the PathBuilderInterface interface!', $name)); } return $this->_pathBuilder = $pathBuilder; }
[ "public", "function", "createPathBuilder", "(", "$", "name", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "className", "=", "App", "::", "className", "(", "$", "name", ",", "'Storage/PathBuilder'", ",", "'PathBuilder'", ")", ";", "if", "("...
Builds the path builder for given interface. @param string $name @param array $options @return \Burzum\FileStorage\Storage\PathBuilder\PathBuilderInterface
[ "Builds", "the", "path", "builder", "for", "given", "interface", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/PathBuilderTrait.php#L30-L46
burzum/cakephp-file-storage
src/Storage/PathBuilder/PathBuilderTrait.php
PathBuilderTrait.pathBuilder
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->_pathBuilder; }
php
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->_pathBuilder; }
[ "public", "function", "pathBuilder", "(", "$", "name", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "$", "name", "instanceof", "PathBuilderInterface", ")", "{", "$", "this", "->", "_pathBuilder", "=", "$", "name", ";",...
Getter and setter for the local PathBuilderInterface instance. @param string|\Burzum\FileStorage\Storage\PathBuilder\PathBuilderInterface|null $name @param array $options @return \Burzum\FileStorage\Storage\PathBuilder\PathBuilderInterface
[ "Getter", "and", "setter", "for", "the", "local", "PathBuilderInterface", "instance", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/PathBuilderTrait.php#L55-L67
burzum/cakephp-file-storage
src/Storage/PathBuilder/PathBuilderTrait.php
PathBuilderTrait.setPathBuilder
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 first arg does not implement %s', PathBuilderInterface::class)); } $this->_pathBuilder = $pathBuilder; }
php
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 first arg does not implement %s', PathBuilderInterface::class)); } $this->_pathBuilder = $pathBuilder; }
[ "public", "function", "setPathBuilder", "(", "$", "pathBuilder", ",", "array", "$", "options", "=", "[", "]", ")", "{", "if", "(", "is_string", "(", "$", "pathBuilder", ")", ")", "{", "$", "this", "->", "_pathBuilder", "=", "$", "this", "->", "createPa...
Sets a path builder. @param string|\Burzum\FileStorage\Storage\PathBuilder\PathBuilderInterface $pathBuilder @param array Path builder options. @return void
[ "Sets", "a", "path", "builder", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/PathBuilderTrait.php#L85-L97
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder.path
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($entity, $path, $config); return $this->ensureSlash($path, 'after'); }
php
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($entity, $path, $config); return $this->ensureSlash($path, 'after'); }
[ "public", "function", "path", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "config", "=", "array_merge", "(", "$", "this", "->", "getConfig", "(", ")", ",", "$", "options", ")", ";", "$", "path", ...
Builds the path under which the data gets stored in the storage adapter. @param \Cake\Datasource\EntityInterface $entity @param array $options @return string
[ "Builds", "the", "path", "under", "which", "the", "data", "gets", "stored", "in", "the", "storage", "adapter", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L75-L83
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder._pathPrefix
protected function _pathPrefix(EntityInterface $entity, $path, array $config) { return $this->_pathPreAndSuffix($entity, $path, $config, 'prefix'); }
php
protected function _pathPrefix(EntityInterface $entity, $path, array $config) { return $this->_pathPreAndSuffix($entity, $path, $config, 'prefix'); }
[ "protected", "function", "_pathPrefix", "(", "EntityInterface", "$", "entity", ",", "$", "path", ",", "array", "$", "config", ")", "{", "return", "$", "this", "->", "_pathPreAndSuffix", "(", "$", "entity", ",", "$", "path", ",", "$", "config", ",", "'pre...
Handles the path prefix generation. Overload this method as needed with your custom implementation. @param \Cake\Datasource\EntityInterface $entity @param $path string @param $config array @return string
[ "Handles", "the", "path", "prefix", "generation", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L95-L97
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder._path
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 .= $this->randomPath($entity->id, 3, $config['randomPath']); } // uuidFolder for backward compatibility if ($config['uuidFolder'] === true || $config['idFolder'] === true) { $path .= $this->stripDashes($entity->id) . DS; } return $path; }
php
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 .= $this->randomPath($entity->id, 3, $config['randomPath']); } // uuidFolder for backward compatibility if ($config['uuidFolder'] === true || $config['idFolder'] === true) { $path .= $this->stripDashes($entity->id) . DS; } return $path; }
[ "protected", "function", "_path", "(", "EntityInterface", "$", "entity", ",", "$", "path", ",", "array", "$", "config", ")", "{", "if", "(", "$", "config", "[", "'modelFolder'", "]", "===", "true", ")", "{", "$", "path", ".=", "$", "entity", "->", "m...
Builds a path. @param \Cake\Datasource\EntityInterface $entity @param string $path @param array $config @return string
[ "Builds", "a", "path", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L107-L123
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder._pathSuffix
protected function _pathSuffix(EntityInterface $entity, $path, array $config) { return $this->_pathPreAndSuffix($entity, $path, $config, 'suffix'); }
php
protected function _pathSuffix(EntityInterface $entity, $path, array $config) { return $this->_pathPreAndSuffix($entity, $path, $config, 'suffix'); }
[ "protected", "function", "_pathSuffix", "(", "EntityInterface", "$", "entity", ",", "$", "path", ",", "array", "$", "config", ")", "{", "return", "$", "this", "->", "_pathPreAndSuffix", "(", "$", "entity", ",", "$", "path", ",", "$", "config", ",", "'suf...
Handles the path suffix generation. Overload this method as needed with your custom implementation. @param \Cake\Datasource\EntityInterface $entity @param $path string @param $config array @return string
[ "Handles", "the", "path", "suffix", "generation", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L135-L137
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder._pathPreAndSuffix
protected function _pathPreAndSuffix(EntityInterface $entity, $path, array $config, $type = 'suffix') { $type = ucfirst($type); if (!in_array($type, ['Suffix', 'Prefix'])) { throw new InvalidArgumentException(sprintf('Invalid argument "%s" for $type!', $type)); } $type = 'path' . $type; if (!empty($config[$type]) && is_string($config[$type])) { $path = $path . $config[$type] . DS; } if (!empty($config[$type]) && is_callable($config[$type])) { $path = $config[$type]($entity, $path); } return $path; }
php
protected function _pathPreAndSuffix(EntityInterface $entity, $path, array $config, $type = 'suffix') { $type = ucfirst($type); if (!in_array($type, ['Suffix', 'Prefix'])) { throw new InvalidArgumentException(sprintf('Invalid argument "%s" for $type!', $type)); } $type = 'path' . $type; if (!empty($config[$type]) && is_string($config[$type])) { $path = $path . $config[$type] . DS; } if (!empty($config[$type]) && is_callable($config[$type])) { $path = $config[$type]($entity, $path); } return $path; }
[ "protected", "function", "_pathPreAndSuffix", "(", "EntityInterface", "$", "entity", ",", "$", "path", ",", "array", "$", "config", ",", "$", "type", "=", "'suffix'", ")", "{", "$", "type", "=", "ucfirst", "(", "$", "type", ")", ";", "if", "(", "!", ...
Handles the path suffix generation. By default prefix and suffix are handled the same but just use a different config array key. This methods handles both and just changes the config key conditionally. Overload _pathSuffix() and _pathPrefix() for your custom implementation instead of touching this methods. @see BasePathBuilder::_pathSuffix() @see BasePathBuilder::_pathPrefix() @param \Cake\Datasource\EntityInterface $entity @param $path string @param $config array @param $type|string string @return string
[ "Handles", "the", "path", "suffix", "generation", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L155-L169
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder.splitFilename
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 === false) { $extension = substr($extension, 1); } } return compact('filename', 'extension'); }
php
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 === false) { $extension = substr($extension, 1); } } return compact('filename', 'extension'); }
[ "public", "function", "splitFilename", "(", "$", "filename", ",", "$", "keepDot", "=", "false", ")", "{", "$", "position", "=", "strrpos", "(", "$", "filename", ",", "'.'", ")", ";", "if", "(", "$", "position", "===", "false", ")", "{", "$", "extensi...
Splits the filename in name and extension. @param string $filename Filename to split in name and extension. @param bool|bool $keepDot Keeps the dot in front of the extension. @return array
[ "Splits", "the", "filename", "in", "name", "and", "extension", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L178-L191
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder.filename
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); }
php
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); }
[ "public", "function", "filename", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "config", "=", "array_merge", "(", "$", "this", "->", "getConfig", "(", ")", ",", "$", "options", ")", ";", "if", "("...
Builds the filename of under which the data gets saved in the storage adapter. @param \Cake\Datasource\EntityInterface $entity @param array $options @return string
[ "Builds", "the", "filename", "of", "under", "which", "the", "data", "gets", "saved", "in", "the", "storage", "adapter", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L200-L207
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder._buildFilename
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']; } if ($options['preserveExtension'] === true) { $filename = $filename . '.' . $entity['extension']; } if (!empty($options['filePrefix'])) { $filename = $options['filePrefix'] . $filename; } return $filename; }
php
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']; } if ($options['preserveExtension'] === true) { $filename = $filename . '.' . $entity['extension']; } if (!empty($options['filePrefix'])) { $filename = $options['filePrefix'] . $filename; } return $filename; }
[ "protected", "function", "_buildFilename", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "filename", "=", "$", "entity", "->", "id", ";", "if", "(", "$", "options", "[", "'stripUuid'", "]", "===", "t...
Used to build a completely customized filename. The default behavior is to use the UUID from the entities primary key to generate a filename based of the UUID that gets the dashes stripped and the extension added if you configured the path builder to preserve it. The filePrefix and fileSuffix options are also supported. @param \Cake\Datasource\EntityInterface $entity @param array $options @return string
[ "Used", "to", "build", "a", "completely", "customized", "filename", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L222-L238
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder._preserveFilename
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->splitFilename($filename, true); $filename = $split['filename'] . $options['fileSuffix']; if ($options['preserveExtension'] === true) { $filename .= $split['extension']; } } return $filename; }
php
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->splitFilename($filename, true); $filename = $split['filename'] . $options['fileSuffix']; if ($options['preserveExtension'] === true) { $filename .= $split['extension']; } } return $filename; }
[ "protected", "function", "_preserveFilename", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "filename", "=", "$", "entity", "[", "'filename'", "]", ";", "if", "(", "!", "empty", "(", "$", "options", ...
Keeps the original filename but is able to inject pre- and suffix. This can be useful to create versions of files for example. @param \Cake\Datasource\EntityInterface $entity @param array $options @return string
[ "Keeps", "the", "original", "filename", "but", "is", "able", "to", "inject", "pre", "-", "and", "suffix", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L249-L263
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder.fullPath
public function fullPath(EntityInterface $entity, array $options = []) { return $this->path($entity, $options) . $this->filename($entity, $options); }
php
public function fullPath(EntityInterface $entity, array $options = []) { return $this->path($entity, $options) . $this->filename($entity, $options); }
[ "public", "function", "fullPath", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "return", "$", "this", "->", "path", "(", "$", "entity", ",", "$", "options", ")", ".", "$", "this", "->", "filename", "("...
Returns the path + filename. @param \Cake\Datasource\EntityInterface $entity @param array $options @return string
[ "Returns", "the", "path", "+", "filename", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L272-L274
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder.url
public function url(EntityInterface $entity, array $options = []) { $url = $this->path($entity, $options) . $this->filename($entity, $options); return str_replace('\\', '/', $url); }
php
public function url(EntityInterface $entity, array $options = []) { $url = $this->path($entity, $options) . $this->filename($entity, $options); return str_replace('\\', '/', $url); }
[ "public", "function", "url", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "url", "=", "$", "this", "->", "path", "(", "$", "entity", ",", "$", "options", ")", ".", "$", "this", "->", "filename",...
Builds the URL under which the file is accessible. This is for example important for S3 and Dropbox but also the Local adapter if you symlink a folder to your webroot and allow direct access to a file. @param \Cake\Datasource\EntityInterface $entity @param array $options @return string
[ "Builds", "the", "URL", "under", "which", "the", "file", "is", "accessible", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L286-L290
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder.randomPath
public function randomPath($string, $level = 3, $method = 'sha1') { // Keeping this for backward compatibility but please stop using crc32()! if ($method === 'crc32') { return $this->_randomPathCrc32($string, $level); } if ($method === 'sha1') { return $this->_randomPathSha1($string, $level); } if (is_callable($method)) { return $method($string, $level); } if (method_exists($this, $method)) { return $this->{$method}($string, $level); } throw new InvalidArgumentException(sprintf('BasepathBuilder::randomPath() invalid hash `%s` method provided!', $method)); }
php
public function randomPath($string, $level = 3, $method = 'sha1') { // Keeping this for backward compatibility but please stop using crc32()! if ($method === 'crc32') { return $this->_randomPathCrc32($string, $level); } if ($method === 'sha1') { return $this->_randomPathSha1($string, $level); } if (is_callable($method)) { return $method($string, $level); } if (method_exists($this, $method)) { return $this->{$method}($string, $level); } throw new InvalidArgumentException(sprintf('BasepathBuilder::randomPath() invalid hash `%s` method provided!', $method)); }
[ "public", "function", "randomPath", "(", "$", "string", ",", "$", "level", "=", "3", ",", "$", "method", "=", "'sha1'", ")", "{", "// Keeping this for backward compatibility but please stop using crc32()!", "if", "(", "$", "method", "===", "'crc32'", ")", "{", "...
Creates a semi-random path based on a string. Makes it possible to overload this functionality. @param string $string Input string @param int $level Depth of the path to generate. @param string $method Hash method, crc32 or sha1. @throws \InvalidArgumentException @return string
[ "Creates", "a", "semi", "-", "random", "path", "based", "on", "a", "string", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L303-L318
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder._randomPathCrc32
protected function _randomPathCrc32($string, $level) { $string = crc32($string); $decrement = 0; $path = null; for ($i = 0; $i < $level; $i++) { $decrement = $decrement - 2; $path .= sprintf('%02d' . DS, substr(str_pad('', 2 * $level, '0') . $string, $decrement, 2)); } return $path; }
php
protected function _randomPathCrc32($string, $level) { $string = crc32($string); $decrement = 0; $path = null; for ($i = 0; $i < $level; $i++) { $decrement = $decrement - 2; $path .= sprintf('%02d' . DS, substr(str_pad('', 2 * $level, '0') . $string, $decrement, 2)); } return $path; }
[ "protected", "function", "_randomPathCrc32", "(", "$", "string", ",", "$", "level", ")", "{", "$", "string", "=", "crc32", "(", "$", "string", ")", ";", "$", "decrement", "=", "0", ";", "$", "path", "=", "null", ";", "for", "(", "$", "i", "=", "0...
Creates a semi-random path based on a string. Please STOP USING CR32! See the huge warning on the php documentation page. of the crc32() function. @deprecated Stop using it, see the methods doc block for more info. @link http://php.net/manual/en/function.crc32.php @link https://www.box.com/blog/crc32-checksums-the-good-the-bad-and-the-ugly/ @param string $string Input string @param int $level Depth of the path to generate. @return string
[ "Creates", "a", "semi", "-", "random", "path", "based", "on", "a", "string", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L333-L343
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder._randomPathSha1
protected function _randomPathSha1($string, $level) { $result = sha1($string); $randomString = ''; $counter = 0; for ($i = 1; $i <= $level; $i++) { $counter = $counter + 2; $randomString .= substr($result, $counter, 2) . DS; } return $randomString; }
php
protected function _randomPathSha1($string, $level) { $result = sha1($string); $randomString = ''; $counter = 0; for ($i = 1; $i <= $level; $i++) { $counter = $counter + 2; $randomString .= substr($result, $counter, 2) . DS; } return $randomString; }
[ "protected", "function", "_randomPathSha1", "(", "$", "string", ",", "$", "level", ")", "{", "$", "result", "=", "sha1", "(", "$", "string", ")", ";", "$", "randomString", "=", "''", ";", "$", "counter", "=", "0", ";", "for", "(", "$", "i", "=", ...
Creates a semi-random path based on a string. Makes it possible to overload this functionality. @param string $string Input string @param int $level Depth of the path to generate. @return string
[ "Creates", "a", "semi", "-", "random", "path", "based", "on", "a", "string", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L354-L364
burzum/cakephp-file-storage
src/Storage/PathBuilder/BasePathBuilder.php
BasePathBuilder.ensureSlash
public function ensureSlash($string, $position, $ds = null) { if (!in_array($position, ['before', 'after', 'both'])) { $method = get_class($this) . '::ensureSlash(): '; throw new InvalidArgumentException(sprintf($method . 'Invalid position `%s`!', $position)); } if ($ds === null) { $ds = DS; } if ($position === 'before' || $position === 'both') { if (strpos($string, $ds) !== 0) { $string = $ds . $string; } } if ($position === 'after' || $position === 'both') { if (substr($string, -1, 1) !== $ds) { $string = $string . $ds; } } return $string; }
php
public function ensureSlash($string, $position, $ds = null) { if (!in_array($position, ['before', 'after', 'both'])) { $method = get_class($this) . '::ensureSlash(): '; throw new InvalidArgumentException(sprintf($method . 'Invalid position `%s`!', $position)); } if ($ds === null) { $ds = DS; } if ($position === 'before' || $position === 'both') { if (strpos($string, $ds) !== 0) { $string = $ds . $string; } } if ($position === 'after' || $position === 'both') { if (substr($string, -1, 1) !== $ds) { $string = $string . $ds; } } return $string; }
[ "public", "function", "ensureSlash", "(", "$", "string", ",", "$", "position", ",", "$", "ds", "=", "null", ")", "{", "if", "(", "!", "in_array", "(", "$", "position", ",", "[", "'before'", ",", "'after'", ",", "'both'", "]", ")", ")", "{", "$", ...
Ensures that a path has a leading and/or trailing (back-) slash. @param string $string @param string $position Can be `before`, `after` or `both` @param string|null $ds Directory separator should be / or \, if not set the DS constant is used. @throws \InvalidArgumentException @return string
[ "Ensures", "that", "a", "path", "has", "a", "leading", "and", "/", "or", "trailing", "(", "back", "-", ")", "slash", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/PathBuilder/BasePathBuilder.php#L375-L395
burzum/cakephp-file-storage
src/Storage/StorageManager.php
StorageManager.config
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[$adapter]; } return false; }
php
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[$adapter]; } return false; }
[ "public", "static", "function", "config", "(", "$", "adapter", ",", "$", "options", "=", "[", "]", ")", "{", "$", "_this", "=", "static", "::", "getInstance", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "adapter", ")", "&&", "!", "empty", "...
Gets the configuration array for an adapter. @param string $adapter @param array $options @throws \InvalidArgumentException @return mixed
[ "Gets", "the", "configuration", "array", "for", "an", "adapter", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageManager.php#L55-L67
burzum/cakephp-file-storage
src/Storage/StorageManager.php
StorageManager.flush
public static function flush($name = null) { $_this = static::getInstance(); if (isset($_this->_adapterConfig[$name])) { unset($_this->_adapterConfig[$name]); return true; } return false; }
php
public static function flush($name = null) { $_this = static::getInstance(); if (isset($_this->_adapterConfig[$name])) { unset($_this->_adapterConfig[$name]); return true; } return false; }
[ "public", "static", "function", "flush", "(", "$", "name", "=", "null", ")", "{", "$", "_this", "=", "static", "::", "getInstance", "(", ")", ";", "if", "(", "isset", "(", "$", "_this", "->", "_adapterConfig", "[", "$", "name", "]", ")", ")", "{", ...
Flush all or a single adapter from the config. @param string|null $name Config name, if none all adapters are flushed. @return bool True on success.
[ "Flush", "all", "or", "a", "single", "adapter", "from", "the", "config", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageManager.php#L75-L85
burzum/cakephp-file-storage
src/Storage/StorageManager.php
StorageManager.get
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($_this->_adapterConfig[$configName])) { $adapter = $_this->_adapterConfig[$configName]; } else { throw new RuntimeException(sprintf('Invalid Storage Adapter %s!', $configName)); } if (!empty($_this->_adapterConfig[$configName]['object']) && $renewObject === false) { return $_this->_adapterConfig[$configName]['object']; } $engineObject = $_this->_factory($adapter); if ($isConfigured) { $_this->_adapterConfig[$configName]['object'] = &$engineObject; } return $engineObject; }
php
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($_this->_adapterConfig[$configName])) { $adapter = $_this->_adapterConfig[$configName]; } else { throw new RuntimeException(sprintf('Invalid Storage Adapter %s!', $configName)); } if (!empty($_this->_adapterConfig[$configName]['object']) && $renewObject === false) { return $_this->_adapterConfig[$configName]['object']; } $engineObject = $_this->_factory($adapter); if ($isConfigured) { $_this->_adapterConfig[$configName]['object'] = &$engineObject; } return $engineObject; }
[ "public", "static", "function", "get", "(", "$", "configName", ",", "$", "renewObject", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "configName", ")", "||", "!", "is_string", "(", "$", "configName", ")", ")", "{", "throw", "new", "InvalidArgu...
Gets a configured instance of a storage adapter. @param string $configName string of adapter configuration or array of settings @param bool|bool $renewObject Creates a new instance of the given adapter in the configuration @throws \RuntimeException @throws \InvalidArgumentException @return \Gaufrette\Filesystem
[ "Gets", "a", "configured", "instance", "of", "a", "storage", "adapter", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageManager.php#L107-L133
burzum/cakephp-file-storage
src/Storage/StorageManager.php
StorageManager._factory
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'] === static::FLYSYSTEM_ENGINE) { return $_this->flysystemFactory($adapter); } throw new RuntimeException(); }
php
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'] === static::FLYSYSTEM_ENGINE) { return $_this->flysystemFactory($adapter); } throw new RuntimeException(); }
[ "protected", "function", "_factory", "(", "$", "adapter", ")", "{", "$", "_this", "=", "static", "::", "getInstance", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "adapter", "[", "'engine'", "]", ")", ")", "{", "$", "adapter", "[", "'engine'", ...
Switches between the engines @param array $adapter Adapter config @return mixed
[ "Switches", "between", "the", "engines" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageManager.php#L141-L155
burzum/cakephp-file-storage
src/Storage/StorageManager.php
StorageManager.gaufretteFactory
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)); } $adapterObject = $Reflection->newInstanceArgs($adapter['adapterOptions']); return new $adapter['class']($adapterObject); }
php
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)); } $adapterObject = $Reflection->newInstanceArgs($adapter['adapterOptions']); return new $adapter['class']($adapterObject); }
[ "public", "static", "function", "gaufretteFactory", "(", "array", "$", "adapter", ")", "{", "$", "class", "=", "$", "adapter", "[", "'adapterClass'", "]", ";", "$", "Reflection", "=", "new", "ReflectionClass", "(", "$", "class", ")", ";", "if", "(", "!",...
Instantiates Gaufrette adapters. @param array $adapter @return object
[ "Instantiates", "Gaufrette", "adapters", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageManager.php#L163-L174
burzum/cakephp-file-storage
src/Storage/StorageManager.php
StorageManager.flysystemFactory
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']; if (class_exists($leagueAdapter)) { return (new ReflectionClass($leagueAdapter))->newInstanceArgs($adapter['adapterOptions']); } $leagueAdapter = '\\League\\Flysystem\\' . $adapter['adapterClass'] . '\\' . $adapter['adapterClass'] . 'Adapter'; if (class_exists($leagueAdapter)) { return (new ReflectionClass($leagueAdapter))->newInstanceArgs($adapter['adapterOptions']); } throw new InvalidArgumentException('Unknown adapter'); }
php
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']; if (class_exists($leagueAdapter)) { return (new ReflectionClass($leagueAdapter))->newInstanceArgs($adapter['adapterOptions']); } $leagueAdapter = '\\League\\Flysystem\\' . $adapter['adapterClass'] . '\\' . $adapter['adapterClass'] . 'Adapter'; if (class_exists($leagueAdapter)) { return (new ReflectionClass($leagueAdapter))->newInstanceArgs($adapter['adapterOptions']); } throw new InvalidArgumentException('Unknown adapter'); }
[ "public", "static", "function", "flysystemFactory", "(", "array", "$", "adapter", ")", "{", "if", "(", "class_exists", "(", "$", "adapter", "[", "'adapterClass'", "]", ")", ")", "{", "return", "(", "new", "ReflectionClass", "(", "$", "adapter", "[", "'adap...
Instantiates Flystem adapters. @param array $adapter @return object
[ "Instantiates", "Flystem", "adapters", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/StorageManager.php#L182-L198
burzum/cakephp-file-storage
src/View/Helper/ImageHelper.php
ImageHelper.display
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); } return $this->fallbackImage($options, $image, $version); }
php
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); } return $this->fallbackImage($options, $image, $version); }
[ "public", "function", "display", "(", "$", "image", ",", "$", "version", "=", "null", ",", "$", "options", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "image", ")", ")", "{", "return", "$", "this", "->", "fallbackImage", "(", "$", "opt...
Generates an image url based on the image record data and the used Gaufrette adapter to store it @param array $image FileStorage array record or whatever else table that matches this helpers needs without the model, we just want the record fields @param string|null $version Image version string @param array $options HtmlHelper::image(), 2nd arg options array @return string
[ "Generates", "an", "image", "url", "based", "on", "the", "image", "record", "data", "and", "the", "used", "Gaufrette", "adapter", "to", "store", "it" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/View/Helper/ImageHelper.php#L50-L61
burzum/cakephp-file-storage
src/View/Helper/ImageHelper.php
ImageHelper._getHash
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!', @$image['model'], $version)); } return $hash; } return null; }
php
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!', @$image['model'], $version)); } return $hash; } return null; }
[ "protected", "function", "_getHash", "(", "$", "version", ",", "$", "image", ")", "{", "if", "(", "!", "empty", "(", "$", "version", ")", ")", "{", "$", "hash", "=", "Configure", "::", "read", "(", "'FileStorage.imageHashes.'", ".", "$", "image", "[", ...
Gets a hash. @param string $version @param array $image @return string|null
[ "Gets", "a", "hash", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/View/Helper/ImageHelper.php#L70-L81
burzum/cakephp-file-storage
src/View/Helper/ImageHelper.php
ImageHelper.imageUrl
public function imageUrl($image, $version = null, $options = []) { $fileInfo = pathinfo($image['path']); $hash = $this->_getHash($version, $image); $version = $fileInfo['dirname'] . DS . $fileInfo['filename']; if ($hash !== null) { $version .= '.' . $hash; } if (!empty($fileInfo['extension'])) { $version .= '.' . $fileInfo['extension']; } if (!empty($options['pathPrefix'])) { return $this->normalizePath($options['pathPrefix'] . $version); } $pathPrefix = $this->getConfig('pathPrefix'); if (!empty($pathPrefix)) { return $this->normalizePath($pathPrefix . $version); } return $this->normalizePath($version); }
php
public function imageUrl($image, $version = null, $options = []) { $fileInfo = pathinfo($image['path']); $hash = $this->_getHash($version, $image); $version = $fileInfo['dirname'] . DS . $fileInfo['filename']; if ($hash !== null) { $version .= '.' . $hash; } if (!empty($fileInfo['extension'])) { $version .= '.' . $fileInfo['extension']; } if (!empty($options['pathPrefix'])) { return $this->normalizePath($options['pathPrefix'] . $version); } $pathPrefix = $this->getConfig('pathPrefix'); if (!empty($pathPrefix)) { return $this->normalizePath($pathPrefix . $version); } return $this->normalizePath($version); }
[ "public", "function", "imageUrl", "(", "$", "image", ",", "$", "version", "=", "null", ",", "$", "options", "=", "[", "]", ")", "{", "$", "fileInfo", "=", "pathinfo", "(", "$", "image", "[", "'path'", "]", ")", ";", "$", "hash", "=", "$", "this",...
URL @param array $image FileStorage array record or whatever else table that matches this helpers needs without the model, we just want the record fields @param string|null $version Image version string @param array $options HtmlHelper::image(), 2nd arg options array @throws \InvalidArgumentException @return string
[ "URL" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/View/Helper/ImageHelper.php#L92-L114
burzum/cakephp-file-storage
src/View/Helper/ImageHelper.php
ImageHelper.fallbackImage
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']); return $this->Html->image($imageFile, $options); } return ''; }
php
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']); return $this->Html->image($imageFile, $options); } return ''; }
[ "public", "function", "fallbackImage", "(", "$", "options", "=", "[", "]", ",", "$", "image", "=", "[", "]", ",", "$", "version", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'fallback'", "]", ")", ")", "{", "if", "(", ...
Provides a fallback image if the image record is empty @param array $options @param array $image @param string|null $version @return string
[ "Provides", "a", "fallback", "image", "if", "the", "image", "record", "is", "empty" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/View/Helper/ImageHelper.php#L124-L137
burzum/cakephp-file-storage
src/Model/Entity/FileStorage.php
FileStorage._path
protected function _path($options) { if (empty($options['method'])) { $options['method'] = 'path'; } $options['entity'] = $this; $event = $this->dispatchEvent('FileStorage.path', $options); return $event->getResult(); }
php
protected function _path($options) { if (empty($options['method'])) { $options['method'] = 'path'; } $options['entity'] = $this; $event = $this->dispatchEvent('FileStorage.path', $options); return $event->getResult(); }
[ "protected", "function", "_path", "(", "$", "options", ")", "{", "if", "(", "empty", "(", "$", "options", "[", "'method'", "]", ")", ")", "{", "$", "options", "[", "'method'", "]", "=", "'path'", ";", "}", "$", "options", "[", "'entity'", "]", "=",...
Gets a path for this entities file. @param array $options Path options. @return string
[ "Gets", "a", "path", "for", "this", "entities", "file", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Model/Entity/FileStorage.php#L131-L140
burzum/cakephp-file-storage
src/Storage/Listener/BaseListener.php
BaseListener.afterDelete
public function afterDelete(Event $event, EntityInterface $entity) { if ($this->_checkEvent($event)) { $event->result = $this->_deleteFile($event); $event->stopPropagation(); } }
php
public function afterDelete(Event $event, EntityInterface $entity) { if ($this->_checkEvent($event)) { $event->result = $this->_deleteFile($event); $event->stopPropagation(); } }
[ "public", "function", "afterDelete", "(", "Event", "$", "event", ",", "EntityInterface", "$", "entity", ")", "{", "if", "(", "$", "this", "->", "_checkEvent", "(", "$", "event", ")", ")", "{", "$", "event", "->", "result", "=", "$", "this", "->", "_d...
File removal is handled AFTER the database record was deleted. No need to use an adapter here, just delete the whole folder using cakes Folder class @param \Cake\Event\Event $event @param \Cake\Datasource\EntityInterface $entity @return void
[ "File", "removal", "is", "handled", "AFTER", "the", "database", "record", "was", "deleted", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/BaseListener.php#L83-L88
burzum/cakephp-file-storage
src/Storage/Listener/BaseListener.php
BaseListener.afterSave
public function afterSave(Event $event, EntityInterface $entity) { if ($this->_checkEvent($event) && $entity->isNew()) { $fileField = $this->getConfig('fileField'); $hash = StorageUtils::getFileHash($entity->get($fileField)['tmp_name']); $path = $this->pathBuilder()->fullPath($entity); $entity->set('hash', $hash); $entity->set('path', $path); if (!$this->_storeFile($event)) { return; } $event->result = true; $event->stopPropagation(); } }
php
public function afterSave(Event $event, EntityInterface $entity) { if ($this->_checkEvent($event) && $entity->isNew()) { $fileField = $this->getConfig('fileField'); $hash = StorageUtils::getFileHash($entity->get($fileField)['tmp_name']); $path = $this->pathBuilder()->fullPath($entity); $entity->set('hash', $hash); $entity->set('path', $path); if (!$this->_storeFile($event)) { return; } $event->result = true; $event->stopPropagation(); } }
[ "public", "function", "afterSave", "(", "Event", "$", "event", ",", "EntityInterface", "$", "entity", ")", "{", "if", "(", "$", "this", "->", "_checkEvent", "(", "$", "event", ")", "&&", "$", "entity", "->", "isNew", "(", ")", ")", "{", "$", "fileFie...
Save the file to the storage backend after the record was created. @param \Cake\Event\Event $event @param \Cake\Datasource\EntityInterface $entity @return void
[ "Save", "the", "file", "to", "the", "storage", "backend", "after", "the", "record", "was", "created", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/BaseListener.php#L97-L114
burzum/cakephp-file-storage
src/Storage/Listener/BaseListener.php
BaseListener.imagePath
public function imagePath(Event $event) { $event->setData($event->getData() + [ 'image' => null, 'version' => null, 'options' => [], 'pathType' => 'fullPath' ]); $data = $event->getData() + [ 'image' => null, 'version' => null, 'options' => [], 'pathType' => 'fullPath' ]; if ($event->getSubject() instanceof EntityInterface) { $data['image'] = $event->getSubject(); } $entity = $data['image']; $version = $data['version']; $options = $data['options']; $type = $data['pathType']; if (!$entity) { throw new InvalidArgumentException('No image entity provided.'); } $this->loadImageProcessingFromConfig(); $path = $this->imageVersionPath($entity, $version, $type, $options); $event->result = $path; $event->setData('path', $path); $event->stopPropagation(); }
php
public function imagePath(Event $event) { $event->setData($event->getData() + [ 'image' => null, 'version' => null, 'options' => [], 'pathType' => 'fullPath' ]); $data = $event->getData() + [ 'image' => null, 'version' => null, 'options' => [], 'pathType' => 'fullPath' ]; if ($event->getSubject() instanceof EntityInterface) { $data['image'] = $event->getSubject(); } $entity = $data['image']; $version = $data['version']; $options = $data['options']; $type = $data['pathType']; if (!$entity) { throw new InvalidArgumentException('No image entity provided.'); } $this->loadImageProcessingFromConfig(); $path = $this->imageVersionPath($entity, $version, $type, $options); $event->result = $path; $event->setData('path', $path); $event->stopPropagation(); }
[ "public", "function", "imagePath", "(", "Event", "$", "event", ")", "{", "$", "event", "->", "setData", "(", "$", "event", "->", "getData", "(", ")", "+", "[", "'image'", "=>", "null", ",", "'version'", "=>", "null", ",", "'options'", "=>", "[", "]",...
Generates the path the image url / path for viewing it in a browser depending on the storage adapter @param \Cake\Event\Event $event @throws \InvalidArgumentException @return void
[ "Generates", "the", "path", "the", "image", "url", "/", "path", "for", "viewing", "it", "in", "a", "browser", "depending", "on", "the", "storage", "adapter" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/BaseListener.php#L123-L157
burzum/cakephp-file-storage
src/Storage/Listener/BaseListener.php
BaseListener._getVersionData
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; }
php
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; }
[ "protected", "function", "_getVersionData", "(", "$", "event", ")", "{", "$", "data", "=", "$", "event", "->", "getData", "(", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'versions'", "]", ")", ")", "{", "$", "versions", "=", "$", "data",...
This method retrieves version names from event data. For backward compatibility version names are resolved from operations data keys because in old ImageProcessingListener operations were required in event data. ImageProcessingTrait need only version names so operations can be read from the config. @param \Cake\Event\Event $event @return array
[ "This", "method", "retrieves", "version", "names", "from", "event", "data", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/BaseListener.php#L211-L222
burzum/cakephp-file-storage
src/Storage/Listener/ValidationListener.php
ValidationListener.initialize
public function initialize(Event $event) { $table = $event->getSubject(); if (!in_array(get_class($table), $this->config['tableClass'])) { return; } $this->_setValidators($table); }
php
public function initialize(Event $event) { $table = $event->getSubject(); if (!in_array(get_class($table), $this->config['tableClass'])) { return; } $this->_setValidators($table); }
[ "public", "function", "initialize", "(", "Event", "$", "event", ")", "{", "$", "table", "=", "$", "event", "->", "getSubject", "(", ")", ";", "if", "(", "!", "in_array", "(", "get_class", "(", "$", "table", ")", ",", "$", "this", "->", "config", "[...
Model initialize event callback @param \Cake\Event\Event $event Event @return void
[ "Model", "initialize", "event", "callback" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/ValidationListener.php#L58-L65
burzum/cakephp-file-storage
src/Storage/Listener/ValidationListener.php
ValidationListener._setValidators
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 = new Validator(); } $validator = $this->{$method}($validator); if (!$validator instanceof Validator) { throw new RuntimeException('Object must be of type ' . Validator::class . '. Method ' . $method . ' returned ' . get_class($validator)); } $table->setValidator(lcfirst(substr($method, 10)), $validator); } } }
php
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 = new Validator(); } $validator = $this->{$method}($validator); if (!$validator instanceof Validator) { throw new RuntimeException('Object must be of type ' . Validator::class . '. Method ' . $method . ' returned ' . get_class($validator)); } $table->setValidator(lcfirst(substr($method, 10)), $validator); } } }
[ "protected", "function", "_setValidators", "(", "Table", "$", "table", ")", "{", "$", "methods", "=", "get_class_methods", "(", "$", "this", ")", ";", "foreach", "(", "$", "methods", "as", "$", "method", ")", "{", "if", "(", "substr", "(", "$", "method...
Sets the configured validators to the table instance @param \Cake\ORM\Table $table @return void
[ "Sets", "the", "configured", "validators", "to", "the", "table", "instance" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/ValidationListener.php#L73-L92
burzum/cakephp-file-storage
src/Storage/ImageVersionsTrait.php
ImageVersionsTrait.getImageVersions
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') . '.' . $version); $eventData = [ 'hash' => $hash, 'image' => $entity, 'version' => $version, 'options' => [] ]; if (method_exists($this, 'dispatchEvent')) { $event = $this->dispatchEvent('ImageVersion.getVersions', $eventData); } else { $event = new Event('ImageVersion.getVersions', $eventData); EventManager::instance()->dispatch($event); } if ($event->isStopped()) { $versions[$version] = str_replace('\\', '/', $event->getData('path')); } } return $versions; }
php
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') . '.' . $version); $eventData = [ 'hash' => $hash, 'image' => $entity, 'version' => $version, 'options' => [] ]; if (method_exists($this, 'dispatchEvent')) { $event = $this->dispatchEvent('ImageVersion.getVersions', $eventData); } else { $event = new Event('ImageVersion.getVersions', $eventData); EventManager::instance()->dispatch($event); } if ($event->isStopped()) { $versions[$version] = str_replace('\\', '/', $event->getData('path')); } } return $versions; }
[ "public", "function", "getImageVersions", "(", "EntityInterface", "$", "entity", ",", "$", "options", "=", "[", "]", ")", "{", "$", "versionData", "=", "$", "this", "->", "_getImageVersionData", "(", "$", "entity", ",", "$", "options", ")", ";", "$", "ve...
Gets a list of image versions for a file storage entity. Use this method to get a list of ALL versions when needed or to cache all the versions somewhere. This method will return all configured versions for an image. For example you could store them serialized along with the file data by adding a "versions" field to the DB table and extend this model. @param \Cake\Datasource\EntityInterface $entity An ImageStorage database record @param array $options Options for the version. @return array A list of versions for this image file. Key is the version, value is the path or URL to that image.
[ "Gets", "a", "list", "of", "image", "versions", "for", "a", "file", "storage", "entity", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/ImageVersionsTrait.php#L23-L48
burzum/cakephp-file-storage
src/Storage/ImageVersionsTrait.php
ImageVersionsTrait._getImageVersionData
protected function _getImageVersionData(EntityInterface $entity, array $options = []) { $versionData = (array)Configure::read('FileStorage.imageSizes.' . $entity->get('model')); if (isset($options['originalVersion'])) { $versionData['original'] = $options['originalVersion']; } else { Configure::write('FileStorage.imageSizes.' . $entity->get('model') . '.original', []); $versionData['original'] = []; } $versionData['original'] = isset($options['originalVersion']) ? $options['originalVersion'] : 'original'; return $versionData; }
php
protected function _getImageVersionData(EntityInterface $entity, array $options = []) { $versionData = (array)Configure::read('FileStorage.imageSizes.' . $entity->get('model')); if (isset($options['originalVersion'])) { $versionData['original'] = $options['originalVersion']; } else { Configure::write('FileStorage.imageSizes.' . $entity->get('model') . '.original', []); $versionData['original'] = []; } $versionData['original'] = isset($options['originalVersion']) ? $options['originalVersion'] : 'original'; return $versionData; }
[ "protected", "function", "_getImageVersionData", "(", "EntityInterface", "$", "entity", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "versionData", "=", "(", "array", ")", "Configure", "::", "read", "(", "'FileStorage.imageSizes.'", ".", "$", ...
Gets the image version data used to generate the versions. @param \Cake\Datasource\EntityInterface $entity An ImageStorage database record. @param array $options Options for the version. @return array Version data information as array.
[ "Gets", "the", "image", "version", "data", "used", "to", "generate", "the", "versions", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/ImageVersionsTrait.php#L57-L69
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener._autoRotate
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: $degree = 90; break; case 90: $degree = -90; break; } $processor = new ImageProcessor(); $image = $processor->open($imageFile); $processor->rotate($image, ['degree' => $degree]); $image->save(['format' => $format]); return true; }
php
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: $degree = 90; break; case 90: $degree = -90; break; } $processor = new ImageProcessor(); $image = $processor->open($imageFile); $processor->rotate($image, ['degree' => $degree]); $image->save(['format' => $format]); return true; }
[ "protected", "function", "_autoRotate", "(", "$", "imageFile", ",", "$", "format", ")", "{", "$", "orientation", "=", "ImagineUtility", "::", "getImageOrientation", "(", "$", "imageFile", ")", ";", "$", "degree", "=", "0", ";", "if", "(", "$", "orientation...
Auto rotates the image if an orientation in the exif data is found that is not 0. @param string $imageFile Path to the image file. @param string $format Format of the image to save. Workaround for imagines save(). :( @return boolean
[ "Auto", "rotates", "the", "image", "if", "an", "orientation", "in", "the", "exif", "data", "is", "found", "that", "is", "not", "0", "." ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L102-L128
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener._createVersions
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 $version => $imageOperations) { $hash = StorageUtils::hashOperations($imageOperations); $string = $this->_buildPath($entity, true, $hash); if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') { $string = str_replace('\\', '/', $string); } if ($Storage->has($string)) { return false; } try { $image = $table->processImage($tmpFile, null, ['format' => $entity['extension']], $imageOperations); $Storage->write($string, $image->get($entity['extension']), true); } catch (\Exception $e) { $this->log($e->getMessage()); unlink($tmpFile); throw $e; } } unlink($tmpFile); }
php
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 $version => $imageOperations) { $hash = StorageUtils::hashOperations($imageOperations); $string = $this->_buildPath($entity, true, $hash); if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') { $string = str_replace('\\', '/', $string); } if ($Storage->has($string)) { return false; } try { $image = $table->processImage($tmpFile, null, ['format' => $entity['extension']], $imageOperations); $Storage->write($string, $image->get($entity['extension']), true); } catch (\Exception $e) { $this->log($e->getMessage()); unlink($tmpFile); throw $e; } } unlink($tmpFile); }
[ "protected", "function", "_createVersions", "(", "Table", "$", "table", ",", "$", "entity", ",", "array", "$", "operations", ")", "{", "$", "Storage", "=", "StorageManager", "::", "adapter", "(", "$", "entity", "[", "'adapter'", "]", ")", ";", "$", "path...
Creates the different versions of images that are configured @param \Cake\ORM\Table $table @param array $entity @param array $operations @throws \Burzum\FileStorage\Event\Exception @throws \Exception @return false|null
[ "Creates", "the", "different", "versions", "of", "images", "that", "are", "configured" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L140-L168
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener.createVersions
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(); } }
php
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(); } }
[ "public", "function", "createVersions", "(", "Event", "$", "Event", ")", "{", "if", "(", "$", "this", "->", "_checkEvent", "(", "$", "Event", ")", ")", "{", "$", "table", "=", "$", "Event", "->", "getSubject", "(", ")", ";", "$", "record", "=", "$"...
Creates versions for a given image record @param Event $Event @return void
[ "Creates", "versions", "for", "a", "given", "image", "record" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L176-L183
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener._removeVersions
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($operations); $string = $this->_buildPath($record, true, $hash); if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') { $string = str_replace('\\', '/', $string); } try { if ($Storage->has($string)) { $Storage->delete($string); } } catch (\Exception $e) { $this->log($e->getMessage()); } } $Event->stopPropagation(); } }
php
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($operations); $string = $this->_buildPath($record, true, $hash); if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') { $string = str_replace('\\', '/', $string); } try { if ($Storage->has($string)) { $Storage->delete($string); } } catch (\Exception $e) { $this->log($e->getMessage()); } } $Event->stopPropagation(); } }
[ "protected", "function", "_removeVersions", "(", "Event", "$", "Event", ")", "{", "if", "(", "$", "this", "->", "_checkEvent", "(", "$", "Event", ")", ")", "{", "$", "data", "=", "$", "Event", "->", "getData", "(", ")", ";", "$", "Storage", "=", "$...
Removes versions for a given image record @param Event $Event @return void
[ "Removes", "versions", "for", "a", "given", "image", "record" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L200-L222
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener.afterDelete
public function afterDelete(Event $Event) { if ($this->_checkEvent($Event)) { $record = $Event->getData('record'); $string = $this->_buildPath($record, true, null); if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') { $string = str_replace('\\', '/', $string); } try { $Storage = StorageManager::adapter($record['adapter']); if (!$Storage->has($string)) { $Event->stopPropagation(); $Event->result = false; return false; } $Storage->delete($string); } catch (\Exception $e) { $this->log($e->getMessage()); $Event->stopPropagation(); $Event->result = false; return false; } $operations = Configure::read('FileStorage.imageSizes.' . $record['model']); if (!empty($operations)) { $Event->setData('operations', $operations); $this->_removeVersions($Event); } $Event->stopPropagation(); $Event->result = true; return true; } }
php
public function afterDelete(Event $Event) { if ($this->_checkEvent($Event)) { $record = $Event->getData('record'); $string = $this->_buildPath($record, true, null); if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') { $string = str_replace('\\', '/', $string); } try { $Storage = StorageManager::adapter($record['adapter']); if (!$Storage->has($string)) { $Event->stopPropagation(); $Event->result = false; return false; } $Storage->delete($string); } catch (\Exception $e) { $this->log($e->getMessage()); $Event->stopPropagation(); $Event->result = false; return false; } $operations = Configure::read('FileStorage.imageSizes.' . $record['model']); if (!empty($operations)) { $Event->setData('operations', $operations); $this->_removeVersions($Event); } $Event->stopPropagation(); $Event->result = true; return true; } }
[ "public", "function", "afterDelete", "(", "Event", "$", "Event", ")", "{", "if", "(", "$", "this", "->", "_checkEvent", "(", "$", "Event", ")", ")", "{", "$", "record", "=", "$", "Event", "->", "getData", "(", "'record'", ")", ";", "$", "string", "...
afterDelete @param Event $Event @return boolean|null @throws \Burzum\FileStorage\Storage\StorageException
[ "afterDelete" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L231-L264
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener.beforeSave
public function beforeSave(Event $Event) { if ($this->_checkEvent($Event)) { $data = $Event->getData(); if (in_array($data['record']['model'], (array)$this->getConfig('autoRotate'))) { $imageFile = $data['record']['file']['tmp_name']; $format = StorageUtils::fileExtension($data['record']['file']['name']); $this->_autoRotate($imageFile, $format); } } }
php
public function beforeSave(Event $Event) { if ($this->_checkEvent($Event)) { $data = $Event->getData(); if (in_array($data['record']['model'], (array)$this->getConfig('autoRotate'))) { $imageFile = $data['record']['file']['tmp_name']; $format = StorageUtils::fileExtension($data['record']['file']['name']); $this->_autoRotate($imageFile, $format); } } }
[ "public", "function", "beforeSave", "(", "Event", "$", "Event", ")", "{", "if", "(", "$", "this", "->", "_checkEvent", "(", "$", "Event", ")", ")", "{", "$", "data", "=", "$", "Event", "->", "getData", "(", ")", ";", "if", "(", "in_array", "(", "...
beforeSave @param Event $Event @return void @throws \Burzum\FileStorage\Storage\StorageException
[ "beforeSave" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L273-L283
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener.afterSave
public function afterSave(Event $Event) { if ($this->_checkEvent($Event)) { $table = $Event->getSubject(); $record = $Event->getData('record'); $Storage = StorageManager::adapter($record->adapter); try { $id = $record->{$table->primaryKey()}; $filename = $this->stripDashes($id); $file = $record['file']; $record['path'] = $this->fsPath('images' . DS . $record['model'], $id); if ($this->_config['preserveFilename'] === true) { $path = $record['path'] . $record['filename']; } else { $path = $record['path'] . $filename . '.' . $record['extension']; } if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') { $path = str_replace('\\', '/', $path); $record['path'] = str_replace('\\', '/', $record['path']); } $Storage->write($path, file_get_contents($file['tmp_name']), true); $data = $table->save($record, [ 'validate' => false, 'callbacks' => false ]); $operations = Configure::read('FileStorage.imageSizes.' . $record['model']); if (!empty($operations)) { $this->_createVersions($table, $record, $operations); } $table->data = $data; } catch (\Exception $e) { $this->log($e->getMessage()); } } }
php
public function afterSave(Event $Event) { if ($this->_checkEvent($Event)) { $table = $Event->getSubject(); $record = $Event->getData('record'); $Storage = StorageManager::adapter($record->adapter); try { $id = $record->{$table->primaryKey()}; $filename = $this->stripDashes($id); $file = $record['file']; $record['path'] = $this->fsPath('images' . DS . $record['model'], $id); if ($this->_config['preserveFilename'] === true) { $path = $record['path'] . $record['filename']; } else { $path = $record['path'] . $filename . '.' . $record['extension']; } if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') { $path = str_replace('\\', '/', $path); $record['path'] = str_replace('\\', '/', $record['path']); } $Storage->write($path, file_get_contents($file['tmp_name']), true); $data = $table->save($record, [ 'validate' => false, 'callbacks' => false ]); $operations = Configure::read('FileStorage.imageSizes.' . $record['model']); if (!empty($operations)) { $this->_createVersions($table, $record, $operations); } $table->data = $data; } catch (\Exception $e) { $this->log($e->getMessage()); } } }
[ "public", "function", "afterSave", "(", "Event", "$", "Event", ")", "{", "if", "(", "$", "this", "->", "_checkEvent", "(", "$", "Event", ")", ")", "{", "$", "table", "=", "$", "Event", "->", "getSubject", "(", ")", ";", "$", "record", "=", "$", "...
afterSave @param Event $Event @return void @throws \Burzum\FileStorage\Storage\StorageException
[ "afterSave" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L292-L329
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener.imagePath
public function imagePath(Event $Event) { $data = $Event->getData(); extract($data); if (!isset($data['image']['adapter'])) { throw new \RuntimeException(__d('file_storage', 'No adapter config key passed!')); } $adapterClass = $this->getAdapterClassName($data['image']['adapter']); $buildMethod = '_build' . $adapterClass . 'Path'; if (method_exists($this, $buildMethod)) { return $this->$buildMethod($Event); } throw new \RuntimeException(__d('file_storage', 'No callback image url callback implemented for adapter %s', $adapterClass)); }
php
public function imagePath(Event $Event) { $data = $Event->getData(); extract($data); if (!isset($data['image']['adapter'])) { throw new \RuntimeException(__d('file_storage', 'No adapter config key passed!')); } $adapterClass = $this->getAdapterClassName($data['image']['adapter']); $buildMethod = '_build' . $adapterClass . 'Path'; if (method_exists($this, $buildMethod)) { return $this->$buildMethod($Event); } throw new \RuntimeException(__d('file_storage', 'No callback image url callback implemented for adapter %s', $adapterClass)); }
[ "public", "function", "imagePath", "(", "Event", "$", "Event", ")", "{", "$", "data", "=", "$", "Event", "->", "getData", "(", ")", ";", "extract", "(", "$", "data", ")", ";", "if", "(", "!", "isset", "(", "$", "data", "[", "'image'", "]", "[", ...
Generates the path the image url / path for viewing it in a browser depending on the storage adapter @param Event $Event @throws RuntimeException @return void
[ "Generates", "the", "path", "the", "image", "url", "/", "path", "for", "viewing", "it", "in", "a", "browser", "depending", "on", "the", "storage", "adapter" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L338-L354
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener._buildLocalPath
protected function _buildLocalPath(Event $Event) { $data = $Event->getData(); extract($data); $path = $this->_buildPath($image, true, $hash); $Event->setData('path', $Event->result = '/' . $path); $Event->stopPropagation(); }
php
protected function _buildLocalPath(Event $Event) { $data = $Event->getData(); extract($data); $path = $this->_buildPath($image, true, $hash); $Event->setData('path', $Event->result = '/' . $path); $Event->stopPropagation(); }
[ "protected", "function", "_buildLocalPath", "(", "Event", "$", "Event", ")", "{", "$", "data", "=", "$", "Event", "->", "getData", "(", ")", ";", "extract", "(", "$", "data", ")", ";", "$", "path", "=", "$", "this", "->", "_buildPath", "(", "$", "i...
Builds an url to the given image @param Event $Event @return void
[ "Builds", "an", "url", "to", "the", "given", "image" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L362-L369
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener._buildAmazonS3Path
protected function _buildAmazonS3Path(Event $Event) { $data = $Event->getData(); extract($data); $path = '/' . $this->_buildPath($image, true, $hash); $config = StorageManager::config($Event->getData('image.adapter')); $bucket = $config['adapterOptions'][1]; if (!empty($config['cloudFrontUrl'])) { $cfDist = $config['cloudFrontUrl']; } else { $cfDist = null; } $http = 'http'; $data = $Event->getData(); if (!empty($data['options']['ssl']) && $data['options']['ssl'] === true) { $http = 'https'; } $path = str_replace('\\', '/', $path); $bucketPrefix = !empty($data['options']['bucketPrefix']) && $data['options']['bucketPrefix'] === true; $Event->result = $this->_buildCloudFrontDistributionUrl($http, $path, $bucket, $bucketPrefix, $cfDist); $Event->setData('path', $Event->result); $Event->stopPropagation(); }
php
protected function _buildAmazonS3Path(Event $Event) { $data = $Event->getData(); extract($data); $path = '/' . $this->_buildPath($image, true, $hash); $config = StorageManager::config($Event->getData('image.adapter')); $bucket = $config['adapterOptions'][1]; if (!empty($config['cloudFrontUrl'])) { $cfDist = $config['cloudFrontUrl']; } else { $cfDist = null; } $http = 'http'; $data = $Event->getData(); if (!empty($data['options']['ssl']) && $data['options']['ssl'] === true) { $http = 'https'; } $path = str_replace('\\', '/', $path); $bucketPrefix = !empty($data['options']['bucketPrefix']) && $data['options']['bucketPrefix'] === true; $Event->result = $this->_buildCloudFrontDistributionUrl($http, $path, $bucket, $bucketPrefix, $cfDist); $Event->setData('path', $Event->result); $Event->stopPropagation(); }
[ "protected", "function", "_buildAmazonS3Path", "(", "Event", "$", "Event", ")", "{", "$", "data", "=", "$", "Event", "->", "getData", "(", ")", ";", "extract", "(", "$", "data", ")", ";", "$", "path", "=", "'/'", ".", "$", "this", "->", "_buildPath",...
Builds an url to the given image for the amazon s3 adapter http(s)://<bucket>.s3.amazonaws.com/<object> http(s)://s3.amazonaws.com/<bucket>/<object> @param Event $Event @return void
[ "Builds", "an", "url", "to", "the", "given", "image", "for", "the", "amazon", "s3", "adapter", "http", "(", "s", ")", ":", "//", "<bucket", ">", ".", "s3", ".", "amazonaws", ".", "com", "/", "<object", ">", "http", "(", "s", ")", ":", "//", "s3",...
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L389-L414
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener._buildCloudFrontDistributionUrl
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.amazonaws.com/' . $bucket; } } $path .= $image; return $path; }
php
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.amazonaws.com/' . $bucket; } } $path .= $image; return $path; }
[ "protected", "function", "_buildCloudFrontDistributionUrl", "(", "$", "protocol", ",", "$", "image", ",", "$", "bucket", ",", "$", "bucketPrefix", "=", "null", ",", "$", "cfDist", "=", "null", ")", "{", "$", "path", "=", "$", "protocol", ".", "'://'", ";...
Builds an url to serve content from cloudfront @param string $protocol @param string $image @param string $bucket @param string null $bucketPrefix @param string $cfDist @param bool $bucketPrefix @return string
[ "Builds", "an", "url", "to", "serve", "content", "from", "cloudfront" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L427-L441
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener._buildPath
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['extension']; } else { $path = $record['path'] . $record['filename']; } } else { $path = $record['path'] . str_replace('-', '', $record['id']); if (!empty($hash)) { $path .= '.' . $hash; } if ($extension === true) { $path .= '.' . $record['extension']; } } if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') { return str_replace('\\', '/', $path); } return $path; }
php
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['extension']; } else { $path = $record['path'] . $record['filename']; } } else { $path = $record['path'] . str_replace('-', '', $record['id']); if (!empty($hash)) { $path .= '.' . $hash; } if ($extension === true) { $path .= '.' . $record['extension']; } } if ($this->adapterClass === 'AmazonS3' || $this->adapterClass === 'AwsS3') { return str_replace('\\', '/', $path); } return $path; }
[ "protected", "function", "_buildPath", "(", "$", "record", ",", "$", "extension", "=", "true", ",", "$", "hash", "=", "null", ")", "{", "if", "(", "$", "this", "->", "_config", "[", "'pathBuilderOptions'", "]", "[", "'preserveFilename'", "]", "===", "tru...
Builds a path to a file @param array $record @param bool $extension @param string $hash @return string
[ "Builds", "a", "path", "to", "a", "file" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L451-L473
burzum/cakephp-file-storage
src/Storage/Listener/LegacyImageProcessingListener.php
LegacyImageProcessingListener.getAdapterClassName
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->adapterClass = 'AwsS3'; return $this->adapterClass; case '\Gaufrette\Adapter\AmazonS3': $this->adapterClass = 'AwsS3'; return $this->adapterClass; case '\Gaufrette\Adapter\AwsS3': $this->adapterClass = 'AwsS3'; return $this->adapterClass; default: return false; } }
php
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->adapterClass = 'AwsS3'; return $this->adapterClass; case '\Gaufrette\Adapter\AmazonS3': $this->adapterClass = 'AwsS3'; return $this->adapterClass; case '\Gaufrette\Adapter\AwsS3': $this->adapterClass = 'AwsS3'; return $this->adapterClass; default: return false; } }
[ "public", "function", "getAdapterClassName", "(", "$", "adapterConfigName", ")", "{", "$", "config", "=", "StorageManager", "::", "config", "(", "$", "adapterConfigName", ")", ";", "switch", "(", "$", "config", "[", "'adapterClass'", "]", ")", "{", "case", "...
Gets the adapter class name from the adapter configuration key @param string @return string|false
[ "Gets", "the", "adapter", "class", "name", "from", "the", "adapter", "configuration", "key" ]
train
https://github.com/burzum/cakephp-file-storage/blob/e0cc17e262ad314a904cf57069f619b9561b48e9/src/Storage/Listener/LegacyImageProcessingListener.php#L481-L504
thephpleague/omnipay-mollie
src/Item.php
Item.setParameter
protected function setParameter($key, $value) { if (is_array($value) && isset($value['value'])) { $value = $value['value']; } $this->parameters->set($key, $value); return $this; }
php
protected function setParameter($key, $value) { if (is_array($value) && isset($value['value'])) { $value = $value['value']; } $this->parameters->set($key, $value); return $this; }
[ "protected", "function", "setParameter", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "&&", "isset", "(", "$", "value", "[", "'value'", "]", ")", ")", "{", "$", "value", "=", "$", "value", "[", "'va...
Check if a Amount object is used, store the value @param $key @param $value @return $this
[ "Check", "if", "a", "Amount", "object", "is", "used", "store", "the", "value" ]
train
https://github.com/thephpleague/omnipay-mollie/blob/d9885d0052dae1aa19d9fd5164d50686dbfa0f72/src/Item.php#L14-L23
thephpleague/omnipay-mollie
src/Message/Response/FetchPaymentMethodsResponse.php
FetchPaymentMethodsResponse.getPaymentMethods
public function getPaymentMethods() { if (isset($this->data['_embedded']["methods"]) === false) { return []; } $paymentMethods = []; foreach ($this->data['_embedded']["methods"] as $method) { $paymentMethods[] = new PaymentMethod($method['id'], $method['description']); } return $paymentMethods; }
php
public function getPaymentMethods() { if (isset($this->data['_embedded']["methods"]) === false) { return []; } $paymentMethods = []; foreach ($this->data['_embedded']["methods"] as $method) { $paymentMethods[] = new PaymentMethod($method['id'], $method['description']); } return $paymentMethods; }
[ "public", "function", "getPaymentMethods", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "'_embedded'", "]", "[", "\"methods\"", "]", ")", "===", "false", ")", "{", "return", "[", "]", ";", "}", "$", "paymentMethods", "=", "...
Return available payment methods as an associative array. @return PaymentMethod[]
[ "Return", "available", "payment", "methods", "as", "an", "associative", "array", "." ]
train
https://github.com/thephpleague/omnipay-mollie/blob/d9885d0052dae1aa19d9fd5164d50686dbfa0f72/src/Message/Response/FetchPaymentMethodsResponse.php#L18-L30
thephpleague/omnipay-mollie
src/Message/Response/FetchIssuersResponse.php
FetchIssuersResponse.getIssuers
public function getIssuers() { if (isset($this->data['issuers']) === false) { return []; } $issuers = []; foreach ($this->data['issuers'] as $issuer) { $issuers[] = new Issuer($issuer['id'], $issuer['name'], $this->data['id']); } return $issuers; }
php
public function getIssuers() { if (isset($this->data['issuers']) === false) { return []; } $issuers = []; foreach ($this->data['issuers'] as $issuer) { $issuers[] = new Issuer($issuer['id'], $issuer['name'], $this->data['id']); } return $issuers; }
[ "public", "function", "getIssuers", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "'issuers'", "]", ")", "===", "false", ")", "{", "return", "[", "]", ";", "}", "$", "issuers", "=", "[", "]", ";", "foreach", "(", "$", ...
Return available issuers as an associative array. @return Issuer[]
[ "Return", "available", "issuers", "as", "an", "associative", "array", "." ]
train
https://github.com/thephpleague/omnipay-mollie/blob/d9885d0052dae1aa19d9fd5164d50686dbfa0f72/src/Message/Response/FetchIssuersResponse.php#L18-L30
thephpleague/omnipay-mollie
src/Message/Request/AbstractMollieRequest.php
AbstractMollieRequest.setItems
public function setItems($items) { $orderItems = []; foreach ($items as $item) { if (is_array($item)) { $orderItems[] = new Item($item); } elseif (! ($item instanceof Item)) { throw new \InvalidArgumentException('Item should be an instance of ' . Item::class); } } return parent::setItems($orderItems); }
php
public function setItems($items) { $orderItems = []; foreach ($items as $item) { if (is_array($item)) { $orderItems[] = new Item($item); } elseif (! ($item instanceof Item)) { throw new \InvalidArgumentException('Item should be an instance of ' . Item::class); } } return parent::setItems($orderItems); }
[ "public", "function", "setItems", "(", "$", "items", ")", "{", "$", "orderItems", "=", "[", "]", ";", "foreach", "(", "$", "items", "as", "$", "item", ")", "{", "if", "(", "is_array", "(", "$", "item", ")", ")", "{", "$", "orderItems", "[", "]", ...
Set the items in this order @param Item[] $items An array of items in this order @return $this
[ "Set", "the", "items", "in", "this", "order" ]
train
https://github.com/thephpleague/omnipay-mollie/blob/d9885d0052dae1aa19d9fd5164d50686dbfa0f72/src/Message/Request/AbstractMollieRequest.php#L70-L82
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/ProjectFactory.php
ProjectFactory.createInstance
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()), new Factory\Function_(), new Factory\Interface_(), new Factory\Method(), new Factory\Property(new PrettyPrinter()), new Factory\Trait_(), ] ); }
php
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()), new Factory\Function_(), new Factory\Interface_(), new Factory\Method(), new Factory\Property(new PrettyPrinter()), new Factory\Trait_(), ] ); }
[ "public", "static", "function", "createInstance", "(", ")", ":", "self", "{", "return", "new", "static", "(", "[", "new", "Factory", "\\", "Argument", "(", "new", "PrettyPrinter", "(", ")", ")", ",", "new", "Factory", "\\", "Class_", "(", ")", ",", "ne...
Creates a new instance of this factory. With all default strategies.
[ "Creates", "a", "new", "instance", "of", "this", "factory", ".", "With", "all", "default", "strategies", "." ]
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/ProjectFactory.php#L48-L64
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/ProjectFactory.php
ProjectFactory.create
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->addFile($file); } } $this->buildNamespaces($project); return $project; }
php
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->addFile($file); } } $this->buildNamespaces($project); return $project; }
[ "public", "function", "create", "(", "$", "name", ",", "array", "$", "files", ")", ":", "ProjectInterface", "{", "$", "project", "=", "new", "Project", "(", "$", "name", ")", ";", "foreach", "(", "$", "files", "as", "$", "filePath", ")", "{", "$", ...
Creates a project from the set of files. @param string $name @param SourceFile[] $files @throws Exception when no matching strategy was found.
[ "Creates", "a", "project", "from", "the", "set", "of", "files", "." ]
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/ProjectFactory.php#L73-L88
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/ProjectFactory.php
ProjectFactory.buildNamespaces
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); } } }
php
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); } } }
[ "private", "function", "buildNamespaces", "(", "Project", "$", "project", ")", ":", "void", "{", "foreach", "(", "$", "project", "->", "getFiles", "(", ")", "as", "$", "file", ")", "{", "foreach", "(", "$", "file", "->", "getNamespaces", "(", ")", "as"...
Builds the namespace tree with all elements in the project.
[ "Builds", "the", "namespace", "tree", "with", "all", "elements", "in", "the", "project", "." ]
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/ProjectFactory.php#L93-L101
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/ProjectFactory.php
ProjectFactory.getNamespaceByName
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($namespace); return $namespace; }
php
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($namespace); return $namespace; }
[ "private", "function", "getNamespaceByName", "(", "Project", "$", "project", ",", "$", "name", ")", ":", "Namespace_", "{", "$", "existingNamespaces", "=", "$", "project", "->", "getNamespaces", "(", ")", ";", "if", "(", "isset", "(", "$", "existingNamespace...
Gets Namespace from the project if it exists, otherwise returns a new namepace
[ "Gets", "Namespace", "from", "the", "project", "if", "it", "exists", "otherwise", "returns", "a", "new", "namepace" ]
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/ProjectFactory.php#L106-L117
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/ProjectFactory.php
ProjectFactory.buildNamespace
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->getInterfaces() as $interface) { if ($namespace->getFqsen() . '\\' . $interface->getName() === (string) $interface->getFqsen()) { $namespace->addInterface($interface->getFqsen()); } } foreach ($file->getFunctions() as $function) { if ($namespace->getFqsen() . '\\' . $function->getName() . '()' === (string) $function->getFqsen()) { $namespace->addFunction($function->getFqsen()); } } foreach ($file->getConstants() as $constant) { if ($namespace->getFqsen() . '::' . $constant->getName() === (string) $constant->getFqsen()) { $namespace->addConstant($constant->getFqsen()); } } foreach ($file->getTraits() as $trait) { if ($namespace->getFqsen() . '\\' . $trait->getName() === (string) $trait->getFqsen()) { $namespace->addTrait($trait->getFqsen()); } } }
php
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->getInterfaces() as $interface) { if ($namespace->getFqsen() . '\\' . $interface->getName() === (string) $interface->getFqsen()) { $namespace->addInterface($interface->getFqsen()); } } foreach ($file->getFunctions() as $function) { if ($namespace->getFqsen() . '\\' . $function->getName() . '()' === (string) $function->getFqsen()) { $namespace->addFunction($function->getFqsen()); } } foreach ($file->getConstants() as $constant) { if ($namespace->getFqsen() . '::' . $constant->getName() === (string) $constant->getFqsen()) { $namespace->addConstant($constant->getFqsen()); } } foreach ($file->getTraits() as $trait) { if ($namespace->getFqsen() . '\\' . $trait->getName() === (string) $trait->getFqsen()) { $namespace->addTrait($trait->getFqsen()); } } }
[ "private", "function", "buildNamespace", "(", "File", "$", "file", ",", "Namespace_", "$", "namespace", ")", ":", "void", "{", "foreach", "(", "$", "file", "->", "getClasses", "(", ")", "as", "$", "class", ")", "{", "if", "(", "$", "namespace", "->", ...
Adds all elements belonging to the namespace to the namespace.
[ "Adds", "all", "elements", "belonging", "to", "the", "namespace", "to", "the", "namespace", "." ]
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/ProjectFactory.php#L122-L153
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/Factory/Property.php
Property.doCreate
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()); } $docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context); return new PropertyDescriptor( $object->getFqsen(), $visibility, $docBlock, $default, $object->isStatic(), new Location($object->getLine()) ); }
php
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()); } $docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context); return new PropertyDescriptor( $object->getFqsen(), $visibility, $docBlock, $default, $object->isStatic(), new Location($object->getLine()) ); }
[ "protected", "function", "doCreate", "(", "$", "object", ",", "StrategyContainer", "$", "strategies", ",", "?", "Context", "$", "context", "=", "null", ")", "{", "$", "visibility", "=", "$", "this", "->", "buildVisibility", "(", "$", "object", ")", ";", ...
Creates an PropertyDescriptor out of the given object. Since an object might contain other objects that need to be converted the $factory is passed so it can be used to create nested Elements. @param PropertyIterator $object object to convert to an PropertyDescriptor @param StrategyContainer $strategies used to convert nested objects. @return PropertyDescriptor
[ "Creates", "an", "PropertyDescriptor", "out", "of", "the", "given", "object", "." ]
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/Factory/Property.php#L61-L79
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/Factory/Constant.php
Constant.doCreate
protected function doCreate($object, StrategyContainer $strategies, ?Context $context = null) { $docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context); $default = null; if ($object->getValue() !== null) { $default = $this->valueConverter->prettyPrintExpr($object->getValue()); } return new ConstantElement($object->getFqsen(), $docBlock, $default, new Location($object->getLine())); }
php
protected function doCreate($object, StrategyContainer $strategies, ?Context $context = null) { $docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context); $default = null; if ($object->getValue() !== null) { $default = $this->valueConverter->prettyPrintExpr($object->getValue()); } return new ConstantElement($object->getFqsen(), $docBlock, $default, new Location($object->getLine())); }
[ "protected", "function", "doCreate", "(", "$", "object", ",", "StrategyContainer", "$", "strategies", ",", "?", "Context", "$", "context", "=", "null", ")", "{", "$", "docBlock", "=", "$", "this", "->", "createDocBlock", "(", "$", "strategies", ",", "$", ...
Creates an Constant out of the given object. Since an object might contain other objects that need to be converted the $factory is passed so it can be used to create nested Elements. @param ClassConstantIterator $object object to convert to an Element @param StrategyContainer $strategies used to convert nested objects. @param Context $context of the created object @return ConstantElement
[ "Creates", "an", "Constant", "out", "of", "the", "given", "object", ".", "Since", "an", "object", "might", "contain", "other", "objects", "that", "need", "to", "be", "converted", "the", "$factory", "is", "passed", "so", "it", "can", "be", "used", "to", "...
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/Factory/Constant.php#L59-L68
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/Class_.php
Class_.addConstant
public function addConstant(Constant $constant): void { $this->constants[(string) $constant->getFqsen()] = $constant; }
php
public function addConstant(Constant $constant): void { $this->constants[(string) $constant->getFqsen()] = $constant; }
[ "public", "function", "addConstant", "(", "Constant", "$", "constant", ")", ":", "void", "{", "$", "this", "->", "constants", "[", "(", "string", ")", "$", "constant", "->", "getFqsen", "(", ")", "]", "=", "$", "constant", ";", "}" ]
Add Constant to this class.
[ "Add", "Constant", "to", "this", "class", "." ]
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/Class_.php#L162-L165
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/Class_.php
Class_.addMethod
public function addMethod(Method $method): void { $this->methods[(string) $method->getFqsen()] = $method; }
php
public function addMethod(Method $method): void { $this->methods[(string) $method->getFqsen()] = $method; }
[ "public", "function", "addMethod", "(", "Method", "$", "method", ")", ":", "void", "{", "$", "this", "->", "methods", "[", "(", "string", ")", "$", "method", "->", "getFqsen", "(", ")", "]", "=", "$", "method", ";", "}" ]
Add a method to this class.
[ "Add", "a", "method", "to", "this", "class", "." ]
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/Class_.php#L180-L183
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/Class_.php
Class_.addProperty
public function addProperty(Property $property): void { $this->properties[(string) $property->getFqsen()] = $property; }
php
public function addProperty(Property $property): void { $this->properties[(string) $property->getFqsen()] = $property; }
[ "public", "function", "addProperty", "(", "Property", "$", "property", ")", ":", "void", "{", "$", "this", "->", "properties", "[", "(", "string", ")", "$", "property", "->", "getFqsen", "(", ")", "]", "=", "$", "property", ";", "}" ]
Add a property to this class.
[ "Add", "a", "property", "to", "this", "class", "." ]
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/Class_.php#L198-L201
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/Factory/Function_.php
Function_.doCreate
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 ($object->getReturnType() instanceof NullableType) { $typeString = '?' . $object->getReturnType()->type; } else { $typeString = (string) $object->getReturnType(); } $returnType = $typeResolver->resolve($typeString, $context); } $function = new FunctionDescriptor($object->fqsen, $docBlock, new Location($object->getLine()), $returnType); foreach ($object->params as $param) { $strategy = $strategies->findMatching($param); $function->addArgument($strategy->create($param, $strategies, $context)); } return $function; }
php
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 ($object->getReturnType() instanceof NullableType) { $typeString = '?' . $object->getReturnType()->type; } else { $typeString = (string) $object->getReturnType(); } $returnType = $typeResolver->resolve($typeString, $context); } $function = new FunctionDescriptor($object->fqsen, $docBlock, new Location($object->getLine()), $returnType); foreach ($object->params as $param) { $strategy = $strategies->findMatching($param); $function->addArgument($strategy->create($param, $strategies, $context)); } return $function; }
[ "protected", "function", "doCreate", "(", "$", "object", ",", "StrategyContainer", "$", "strategies", ",", "?", "Context", "$", "context", "=", "null", ")", "{", "$", "docBlock", "=", "$", "this", "->", "createDocBlock", "(", "$", "strategies", ",", "$", ...
Creates an FunctionDescriptor out of the given object including its child elements. @param \PhpParser\Node\Stmt\Function_ $object object to convert to an Element @param StrategyContainer $strategies used to convert nested objects. @param Context $context of the created object @return FunctionDescriptor
[ "Creates", "an", "FunctionDescriptor", "out", "of", "the", "given", "object", "including", "its", "child", "elements", "." ]
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/Factory/Function_.php#L49-L73
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/Factory/Class_.php
Class_.doCreate
protected function doCreate($object, StrategyContainer $strategies, ?Context $context = null) { $docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context); $classElement = new ClassElement( $object->fqsen, $docBlock, $object->extends ? new Fqsen('\\' . $object->extends) : null, $object->isAbstract(), $object->isFinal(), new Location($object->getLine()) ); if (isset($object->implements)) { foreach ($object->implements as $interfaceClassName) { $classElement->addInterface( new Fqsen('\\' . $interfaceClassName->toString()) ); } } if (isset($object->stmts)) { foreach ($object->stmts as $stmt) { switch (get_class($stmt)) { case TraitUse::class: foreach ($stmt->traits as $use) { $classElement->addUsedTrait(new Fqsen('\\' . $use->toString())); } break; case PropertyNode::class: $properties = new PropertyIterator($stmt); foreach ($properties as $property) { $element = $this->createMember($property, $strategies, $context); $classElement->addProperty($element); } break; case ClassMethod::class: $method = $this->createMember($stmt, $strategies, $context); $classElement->addMethod($method); break; case ClassConst::class: $constants = new ClassConstantIterator($stmt); foreach ($constants as $const) { $element = $this->createMember($const, $strategies, $context); $classElement->addConstant($element); } break; } } } return $classElement; }
php
protected function doCreate($object, StrategyContainer $strategies, ?Context $context = null) { $docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context); $classElement = new ClassElement( $object->fqsen, $docBlock, $object->extends ? new Fqsen('\\' . $object->extends) : null, $object->isAbstract(), $object->isFinal(), new Location($object->getLine()) ); if (isset($object->implements)) { foreach ($object->implements as $interfaceClassName) { $classElement->addInterface( new Fqsen('\\' . $interfaceClassName->toString()) ); } } if (isset($object->stmts)) { foreach ($object->stmts as $stmt) { switch (get_class($stmt)) { case TraitUse::class: foreach ($stmt->traits as $use) { $classElement->addUsedTrait(new Fqsen('\\' . $use->toString())); } break; case PropertyNode::class: $properties = new PropertyIterator($stmt); foreach ($properties as $property) { $element = $this->createMember($property, $strategies, $context); $classElement->addProperty($element); } break; case ClassMethod::class: $method = $this->createMember($stmt, $strategies, $context); $classElement->addMethod($method); break; case ClassConst::class: $constants = new ClassConstantIterator($stmt); foreach ($constants as $const) { $element = $this->createMember($const, $strategies, $context); $classElement->addConstant($element); } break; } } } return $classElement; }
[ "protected", "function", "doCreate", "(", "$", "object", ",", "StrategyContainer", "$", "strategies", ",", "?", "Context", "$", "context", "=", "null", ")", "{", "$", "docBlock", "=", "$", "this", "->", "createDocBlock", "(", "$", "strategies", ",", "$", ...
Creates an ClassElement out of the given object. Since an object might contain other objects that need to be converted the $factory is passed so it can be used to create nested Elements. @param ClassNode $object object to convert to an Element @param StrategyContainer $strategies used to convert nested objects. @param Context $context of the created object @return ClassElement
[ "Creates", "an", "ClassElement", "out", "of", "the", "given", "object", ".", "Since", "an", "object", "might", "contain", "other", "objects", "that", "need", "to", "be", "converted", "the", "$factory", "is", "passed", "so", "it", "can", "be", "used", "to",...
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/Factory/Class_.php#L51-L103
phpDocumentor/Reflection
src/phpDocumentor/Reflection/Php/Factory/DocBlock.php
DocBlock.create
public function create($object, StrategyContainer $strategies, ?Context $context = null): ?DocBlockDescriptor { if ($object === null) { return null; } if (!$this->matches($object)) { throw new InvalidArgumentException( sprintf( '%s cannot handle objects with the type %s', __CLASS__, is_object($object) ? get_class($object) : gettype($object) ) ); } return $this->docblockFactory->create($object->getText(), $context, new Location($object->getLine())); }
php
public function create($object, StrategyContainer $strategies, ?Context $context = null): ?DocBlockDescriptor { if ($object === null) { return null; } if (!$this->matches($object)) { throw new InvalidArgumentException( sprintf( '%s cannot handle objects with the type %s', __CLASS__, is_object($object) ? get_class($object) : gettype($object) ) ); } return $this->docblockFactory->create($object->getText(), $context, new Location($object->getLine())); }
[ "public", "function", "create", "(", "$", "object", ",", "StrategyContainer", "$", "strategies", ",", "?", "Context", "$", "context", "=", "null", ")", ":", "?", "DocBlockDescriptor", "{", "if", "(", "$", "object", "===", "null", ")", "{", "return", "nul...
Creates an Element out of the given object. Since an object might contain other objects that need to be converted the $factory is passed so it can be used to create nested Elements. @param Doc $object object to convert to an Element @param StrategyContainer $strategies used to convert nested objects. @param Context $context of the created object @return null|DocBlockDescriptor
[ "Creates", "an", "Element", "out", "of", "the", "given", "object", ".", "Since", "an", "object", "might", "contain", "other", "objects", "that", "need", "to", "be", "converted", "the", "$factory", "is", "passed", "so", "it", "can", "be", "used", "to", "c...
train
https://github.com/phpDocumentor/Reflection/blob/0548704854fdaf6630ccc39fb92dc37487d05ad3/src/phpDocumentor/Reflection/Php/Factory/DocBlock.php#L62-L79