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_documentation_string
stringlengths
1
47.2k
func_code_url
stringlengths
85
339
fridge-project/dbal
src/Fridge/DBAL/Driver/Statement/StatementRewriter.php
StatementRewriter.rewrite
private function rewrite() { // Current positional parameter. $positionalParameter = 1; // TRUE if we are in a literal section else FALSE. $literal = false; // The statement length. $statementLength = strlen($this->statement); // Iterate each statement char. for ($placeholderPos = 0; $placeholderPos < $statementLength; $placeholderPos++) { // Switch the literal flag if the current statement char is a literal delimiter. if (in_array($this->statement[$placeholderPos], array('\'', '"'))) { $literal = !$literal; } // Check if we are not in a literal section and the current statement char is a double colon. if (!$literal && $this->statement[$placeholderPos] === ':') { // Determine placeholder length. $placeholderLength = 1; while (isset($this->statement[$placeholderPos + $placeholderLength]) && $this->isValidPlaceholderCharacter($this->statement[$placeholderPos + $placeholderLength])) { $placeholderLength++; } // Extract placeholder from the statement. $placeholder = substr($this->statement, $placeholderPos, $placeholderLength); // Initialize rewrites parameters. if (!isset($this->parameters[$placeholder])) { $this->parameters[$placeholder] = array(); } // Rewrites parameter. $this->parameters[$placeholder][] = $positionalParameter; // Rewrite statement. $this->statement = substr($this->statement, 0, $placeholderPos). '?'. substr($this->statement, $placeholderPos + $placeholderLength); // Decrement statement length. $statementLength = $statementLength - $placeholderLength + 1; // Increment position parameter. $positionalParameter++; } } }
php
private function rewrite() { // Current positional parameter. $positionalParameter = 1; // TRUE if we are in a literal section else FALSE. $literal = false; // The statement length. $statementLength = strlen($this->statement); // Iterate each statement char. for ($placeholderPos = 0; $placeholderPos < $statementLength; $placeholderPos++) { // Switch the literal flag if the current statement char is a literal delimiter. if (in_array($this->statement[$placeholderPos], array('\'', '"'))) { $literal = !$literal; } // Check if we are not in a literal section and the current statement char is a double colon. if (!$literal && $this->statement[$placeholderPos] === ':') { // Determine placeholder length. $placeholderLength = 1; while (isset($this->statement[$placeholderPos + $placeholderLength]) && $this->isValidPlaceholderCharacter($this->statement[$placeholderPos + $placeholderLength])) { $placeholderLength++; } // Extract placeholder from the statement. $placeholder = substr($this->statement, $placeholderPos, $placeholderLength); // Initialize rewrites parameters. if (!isset($this->parameters[$placeholder])) { $this->parameters[$placeholder] = array(); } // Rewrites parameter. $this->parameters[$placeholder][] = $positionalParameter; // Rewrite statement. $this->statement = substr($this->statement, 0, $placeholderPos). '?'. substr($this->statement, $placeholderPos + $placeholderLength); // Decrement statement length. $statementLength = $statementLength - $placeholderLength + 1; // Increment position parameter. $positionalParameter++; } } }
Rewrite the named statement and parameters to positional. Example: - before: - statement: SELECT * FROM foo WHERE bar = :bar - parameters: array() - after: - statement: SELECT * FROM foo WHERE bar = ? - parameters: array(':bar' => array(1))
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Driver/Statement/StatementRewriter.php#L91-L143
fridge-project/dbal
src/Fridge/DBAL/Driver/Statement/StatementRewriter.php
StatementRewriter.isValidPlaceholderCharacter
private function isValidPlaceholderCharacter($character) { $asciiCode = ord($character); return (($asciiCode >= 48) && ($asciiCode <= 57)) || (($asciiCode >= 65) && ($asciiCode <= 90)) || (($asciiCode >= 97) && ($asciiCode <= 122)); }
php
private function isValidPlaceholderCharacter($character) { $asciiCode = ord($character); return (($asciiCode >= 48) && ($asciiCode <= 57)) || (($asciiCode >= 65) && ($asciiCode <= 90)) || (($asciiCode >= 97) && ($asciiCode <= 122)); }
Checks if the character is a valid placeholder character. @param string $character The character to check. @return boolean TRUE if the character is a valid placeholder character else FALSE.
https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Driver/Statement/StatementRewriter.php#L152-L159
kambalabs/KmbBase
src/KmbBase/Factory/NavigationAbstractFactory.php
NavigationAbstractFactory.canCreateServiceWithName
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { $config = $serviceLocator->get('Config'); if (!isset($config) || !isset($config[$this->configKey])) { return false; } return (isset($config[$this->configKey][$requestedName]) && is_array($config[$this->configKey][$requestedName])); }
php
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { $config = $serviceLocator->get('Config'); if (!isset($config) || !isset($config[$this->configKey])) { return false; } return (isset($config[$this->configKey][$requestedName]) && is_array($config[$this->configKey][$requestedName])); }
Determine if we can create a service with name @param ServiceLocatorInterface $serviceLocator @param $name @param $requestedName @return bool
https://github.com/kambalabs/KmbBase/blob/ca420f247e9e4063266005e30afc4c8af492a33b/src/KmbBase/Factory/NavigationAbstractFactory.php#L39-L46
kambalabs/KmbBase
src/KmbBase/Factory/NavigationAbstractFactory.php
NavigationAbstractFactory.createServiceWithName
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { $factory = new NavigationFactory($requestedName); return $factory->createService($serviceLocator); }
php
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName) { $factory = new NavigationFactory($requestedName); return $factory->createService($serviceLocator); }
Create service with name @param ServiceLocatorInterface $serviceLocator @param $name @param $requestedName @return mixed
https://github.com/kambalabs/KmbBase/blob/ca420f247e9e4063266005e30afc4c8af492a33b/src/KmbBase/Factory/NavigationAbstractFactory.php#L56-L60
net-tools/core
src/Misc/PdoConfig.php
PdoConfig.get
public function get($k) { try { $this->_qst->execute(array($this->_prefix . $k)); $value = $this->_qst->fetchColumn(0); if ( $value === FALSE ) throw new \Exception("Config value '$k' does not exist"); return $value; } catch (\PDOException $e) { throw new \Exception("Config value '$k' can't be read (SQL error {$e->getMessage()})"); } }
php
public function get($k) { try { $this->_qst->execute(array($this->_prefix . $k)); $value = $this->_qst->fetchColumn(0); if ( $value === FALSE ) throw new \Exception("Config value '$k' does not exist"); return $value; } catch (\PDOException $e) { throw new \Exception("Config value '$k' can't be read (SQL error {$e->getMessage()})"); } }
Get value @param string $k Value key @return string @throws \Exception Throw if value does not exist
https://github.com/net-tools/core/blob/51446641cee22c0cf53d2b409c76cc8bd1a187e7/src/Misc/PdoConfig.php#L39-L54
porkchopsandwiches/silex-utilities
lib/src/PorkChopSandwiches/Silex/Utilities/Arrays.php
Arrays.index
public function index (array $array, callable $callable, $reference = false) { $indexed = array(); if ($reference) { foreach ($array as $key => &$value) { $indexed[$callable($value, $key)] = &$value; } } else { foreach ($array as $key => $value) { $indexed[$callable($value, $key)] = $value; } } return $indexed; }
php
public function index (array $array, callable $callable, $reference = false) { $indexed = array(); if ($reference) { foreach ($array as $key => &$value) { $indexed[$callable($value, $key)] = &$value; } } else { foreach ($array as $key => $value) { $indexed[$callable($value, $key)] = $value; } } return $indexed; }
@param array $array @param callable $callable @param bool $reference @return array
https://github.com/porkchopsandwiches/silex-utilities/blob/756d041f40c7980b1763c08004f1f405bfc74af6/lib/src/PorkChopSandwiches/Silex/Utilities/Arrays.php#L19-L33
porkchopsandwiches/silex-utilities
lib/src/PorkChopSandwiches/Silex/Utilities/Arrays.php
Arrays.findOne
public function findOne (array $array, $callback, $default = null) { $filtered = array_filter($array, $callback); return count($filtered) ? reset($filtered) : $default; }
php
public function findOne (array $array, $callback, $default = null) { $filtered = array_filter($array, $callback); return count($filtered) ? reset($filtered) : $default; }
@param $array @param callable|string|array $callback @param mixed $default @return mixed
https://github.com/porkchopsandwiches/silex-utilities/blob/756d041f40c7980b1763c08004f1f405bfc74af6/lib/src/PorkChopSandwiches/Silex/Utilities/Arrays.php#L60-L63
porkchopsandwiches/silex-utilities
lib/src/PorkChopSandwiches/Silex/Utilities/Arrays.php
Arrays.deepMerge
public function deepMerge (array $mergee, array $merger) { $merged = $mergee; foreach ($merger as $key => &$value) { # If key exists an an array on both sides, deep merge if (array_key_exists($key, $merged) && is_array($value) && is_array($merged[$key])) { $merged[$key] = $this -> deepMerge($merged[$key], $value); # Otherwise, simply replace } else { $merged[$key] = $value; } } return $merged; }
php
public function deepMerge (array $mergee, array $merger) { $merged = $mergee; foreach ($merger as $key => &$value) { # If key exists an an array on both sides, deep merge if (array_key_exists($key, $merged) && is_array($value) && is_array($merged[$key])) { $merged[$key] = $this -> deepMerge($merged[$key], $value); # Otherwise, simply replace } else { $merged[$key] = $value; } } return $merged; }
Performs an array merge, but when both values for a key are arrays, a deep merge will occur, retaining the unique keys of both without changing the value types. @example $a = array(1 => 2, 3 => array(4 => 5, 6 => 7)); $b = array(3 => array(4 => "Four")); deepMerge($a, $b) == array(1 => 2, 3 => array(4 => "Four", 6 => 7)); @param array &$mergee The array whose values will be overridden during merging. @param array &$merger The array whose values will override during merging. @return array
https://github.com/porkchopsandwiches/silex-utilities/blob/756d041f40c7980b1763c08004f1f405bfc74af6/lib/src/PorkChopSandwiches/Silex/Utilities/Arrays.php#L121-L137
erenmustafaozdal/laravel-modules-base
src/Controllers/BaseController.php
BaseController.setToFileOptions
protected function setToFileOptions($request, $params) { $module = getModule(get_called_class()); $model = getModelSlug(get_called_class()); $options = []; $elfinders = []; foreach($params as $column => $optionName) { $isGroup = is_integer($column) && is_array($optionName) && isset($optionName['group']); $configName = $isGroup || isset($optionName['column']) ? $optionName['config'] : $optionName; $columnParts = explode('.',($isGroup || isset($optionName['column']) ? $optionName['column'] : $column)); $inputName = count($columnParts) > 1 ? $columnParts[1] : $columnParts[0]; $inputName = isset($optionName['inputPrefix']) ? $optionName['inputPrefix'] . $inputName : $inputName; $fullColumn = implode('.', $columnParts); // options set edilir if ( ($isGroup && ( is_array($request->file($optionName['group'])) && $request->file("{$optionName['group']}.{$column}.{$inputName}") || $request->has("{$optionName['group']}.{$column}.{$inputName}") ) ) || ( (is_array($request->file($inputName)) && $request->file($inputName)[0]) || (!is_array($request->file($inputName)) && $request->file($inputName)) ) || $request->has($inputName) ) { $moduleOptions = config("{$module}.{$model}.uploads.{$configName}"); // if column is array if (is_array($moduleOptions['column'])) { $moduleOptions['column'] = $moduleOptions['column'][$inputName]; } // is group if ($isGroup) { $moduleOptions['group'] = $optionName['group']; } // add some data if ($isGroup || isset($optionName['column'])) { $moduleOptions['index'] = $column; if (isset($optionName['changeThumb'])) $moduleOptions['changeThumb'] = $optionName['changeThumb']; if (isset($optionName['changeToHasOne'])) $moduleOptions['changeToHasOne'] = $optionName['changeToHasOne']; if (isset($optionName['is_reset'])) $moduleOptions['is_reset'] = $optionName['is_reset']; $moduleOptions['add_column'] = isset($optionName['add_column']) ? $optionName['add_column'] : []; $moduleOptions['inputPrefix'] = isset($optionName['inputPrefix']) ? $optionName['inputPrefix'] : []; } array_push($options, $moduleOptions); } // elfinder mi belirtilir if ( ($isGroup && $request->has("{$optionName['group']}.{$column}.{$inputName}")) || ($request->has($inputName) && ! $request->file($inputName)[0]) ) { $elfinderOption = $isGroup || isset($optionName['column']) ? ['index' => count($options)-1, 'column' => $optionName['column']] : $fullColumn; array_push($elfinders, $elfinderOption); } } $this->setFileOptions($options); foreach($elfinders as $elfinder) { $this->setElfinderToOptions($elfinder); } }
php
protected function setToFileOptions($request, $params) { $module = getModule(get_called_class()); $model = getModelSlug(get_called_class()); $options = []; $elfinders = []; foreach($params as $column => $optionName) { $isGroup = is_integer($column) && is_array($optionName) && isset($optionName['group']); $configName = $isGroup || isset($optionName['column']) ? $optionName['config'] : $optionName; $columnParts = explode('.',($isGroup || isset($optionName['column']) ? $optionName['column'] : $column)); $inputName = count($columnParts) > 1 ? $columnParts[1] : $columnParts[0]; $inputName = isset($optionName['inputPrefix']) ? $optionName['inputPrefix'] . $inputName : $inputName; $fullColumn = implode('.', $columnParts); // options set edilir if ( ($isGroup && ( is_array($request->file($optionName['group'])) && $request->file("{$optionName['group']}.{$column}.{$inputName}") || $request->has("{$optionName['group']}.{$column}.{$inputName}") ) ) || ( (is_array($request->file($inputName)) && $request->file($inputName)[0]) || (!is_array($request->file($inputName)) && $request->file($inputName)) ) || $request->has($inputName) ) { $moduleOptions = config("{$module}.{$model}.uploads.{$configName}"); // if column is array if (is_array($moduleOptions['column'])) { $moduleOptions['column'] = $moduleOptions['column'][$inputName]; } // is group if ($isGroup) { $moduleOptions['group'] = $optionName['group']; } // add some data if ($isGroup || isset($optionName['column'])) { $moduleOptions['index'] = $column; if (isset($optionName['changeThumb'])) $moduleOptions['changeThumb'] = $optionName['changeThumb']; if (isset($optionName['changeToHasOne'])) $moduleOptions['changeToHasOne'] = $optionName['changeToHasOne']; if (isset($optionName['is_reset'])) $moduleOptions['is_reset'] = $optionName['is_reset']; $moduleOptions['add_column'] = isset($optionName['add_column']) ? $optionName['add_column'] : []; $moduleOptions['inputPrefix'] = isset($optionName['inputPrefix']) ? $optionName['inputPrefix'] : []; } array_push($options, $moduleOptions); } // elfinder mi belirtilir if ( ($isGroup && $request->has("{$optionName['group']}.{$column}.{$inputName}")) || ($request->has($inputName) && ! $request->file($inputName)[0]) ) { $elfinderOption = $isGroup || isset($optionName['column']) ? ['index' => count($options)-1, 'column' => $optionName['column']] : $fullColumn; array_push($elfinders, $elfinderOption); } } $this->setFileOptions($options); foreach($elfinders as $elfinder) { $this->setElfinderToOptions($elfinder); } }
set file options @param \Illuminate\Http\Request $request @param array $params [ ['column_name' => 'option_name'] ] @return void
https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/BaseController.php#L19-L79
erenmustafaozdal/laravel-modules-base
src/Controllers/BaseController.php
BaseController.changeOptions
protected function changeOptions($category) { $thumbnails = $category->ancestorsAndSelf()->with('thumbnails')->get()->map(function($item) { return $item->thumbnails->keyBy('slug')->map(function($item) { return [ 'width' => $item->photo_width, 'height' => $item->photo_height ]; }); })->reduce(function($carry,$item) { return $carry->merge($item); },collect())->toArray(); Config::set('laravel-document-module.document.uploads.photo.aspect_ratio', $category->aspect_ratio); Config::set('laravel-document-module.document.uploads.photo.thumbnails', $thumbnails); }
php
protected function changeOptions($category) { $thumbnails = $category->ancestorsAndSelf()->with('thumbnails')->get()->map(function($item) { return $item->thumbnails->keyBy('slug')->map(function($item) { return [ 'width' => $item->photo_width, 'height' => $item->photo_height ]; }); })->reduce(function($carry,$item) { return $carry->merge($item); },collect())->toArray(); Config::set('laravel-document-module.document.uploads.photo.aspect_ratio', $category->aspect_ratio); Config::set('laravel-document-module.document.uploads.photo.thumbnails', $thumbnails); }
change options with model category @param $category @return void
https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Controllers/BaseController.php#L87-L101
damianociarla/DCSUserCoreBundle
src/Command/CreateUserCommand.php
CreateUserCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getOption('username'); $password = $input->getOption('password'); $user = $this->getContainer()->get('dcs_user.factory')->create(); $user->setUsername($username); $this->getContainer()->get('dcs_user.core.helper.password')->updateUserPassword($user, $password); $this->getContainer()->get('dcs_user.manager.save')->__invoke($user); }
php
protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getOption('username'); $password = $input->getOption('password'); $user = $this->getContainer()->get('dcs_user.factory')->create(); $user->setUsername($username); $this->getContainer()->get('dcs_user.core.helper.password')->updateUserPassword($user, $password); $this->getContainer()->get('dcs_user.manager.save')->__invoke($user); }
{@inheritdoc}
https://github.com/damianociarla/DCSUserCoreBundle/blob/ddcf98ef9bb33520e4472317ef64175f181ae996/src/Command/CreateUserCommand.php#L27-L37
DreadLabs/VantomasWebsite
src/Disqus/Response.php
Response.setFormat
public function setFormat($format) { $this->format = $format; $this->concreteResponse = $this->responseResolver->resolve($format); }
php
public function setFormat($format) { $this->format = $format; $this->concreteResponse = $this->responseResolver->resolve($format); }
{@inheritdoc}
https://github.com/DreadLabs/VantomasWebsite/blob/7f85f2b45bdf5ed9fa9d320c805c416bf99cd668/src/Disqus/Response.php#L57-L62
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Storage/Driver/File.php
File.put
public function put($filename,$content,$type=''){ $dir = dirname($filename); if(!is_dir($dir)){ mkdir($dir,0777,true); } if(false === file_put_contents($filename,$content)){ E(L('_STORAGE_WRITE_ERROR_').':'.$filename); }else{ $this->contents[$filename]=$content; return true; } }
php
public function put($filename,$content,$type=''){ $dir = dirname($filename); if(!is_dir($dir)){ mkdir($dir,0777,true); } if(false === file_put_contents($filename,$content)){ E(L('_STORAGE_WRITE_ERROR_').':'.$filename); }else{ $this->contents[$filename]=$content; return true; } }
文件写入 @access public @param string $filename 文件名 @param string $content 文件内容 @return boolean
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Storage/Driver/File.php#L42-L53
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Storage/Driver/File.php
File.append
public function append($filename,$content,$type=''){ if(is_file($filename)){ $content = $this->read($filename,$type).$content; } return $this->put($filename,$content,$type); }
php
public function append($filename,$content,$type=''){ if(is_file($filename)){ $content = $this->read($filename,$type).$content; } return $this->put($filename,$content,$type); }
文件追加写入 @access public @param string $filename 文件名 @param string $content 追加的文件内容 @return boolean
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Storage/Driver/File.php#L62-L67
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Storage/Driver/File.php
File.unlink
public function unlink($filename,$type=''){ unset($this->contents[$filename]); return is_file($filename) ? unlink($filename) : false; }
php
public function unlink($filename,$type=''){ unset($this->contents[$filename]); return is_file($filename) ? unlink($filename) : false; }
文件删除 @access public @param string $filename 文件名 @return boolean
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Storage/Driver/File.php#L99-L102
KDF5000/EasyThink
src/ThinkPHP/Library/Think/Storage/Driver/File.php
File.get
public function get($filename,$name,$type=''){ if(!isset($this->contents[$filename])){ if(!is_file($filename)) return false; $this->contents[$filename]=file_get_contents($filename); } $content=$this->contents[$filename]; $info = array( 'mtime' => filemtime($filename), 'content' => $content ); return $info[$name]; }
php
public function get($filename,$name,$type=''){ if(!isset($this->contents[$filename])){ if(!is_file($filename)) return false; $this->contents[$filename]=file_get_contents($filename); } $content=$this->contents[$filename]; $info = array( 'mtime' => filemtime($filename), 'content' => $content ); return $info[$name]; }
读取文件信息 @access public @param string $filename 文件名 @param string $name 信息名 mtime或者content @return boolean
https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Library/Think/Storage/Driver/File.php#L111-L122
t3v/t3v_core
Classes/Service/FileService.php
FileService.saveFile
public static function saveFile($file, string $uploadsFolderPath) { if (!empty($file) && is_array($file) && !empty($uploadsFolderPath)) { $fileName = $file['name']; $temporaryFileName = $file['tmp_name']; if (GeneralUtility::verifyFilenameAgainstDenyPattern($fileName)) { $uploadsFolderPath = GeneralUtility::getFileAbsFileName($uploadsFolderPath); $fileName = self::cleanFileName($fileName); $newFileName = self::getUniqueFileName($fileName, $uploadsFolderPath); $fileCouldBeUploaded = GeneralUtility::upload_copy_move($temporaryFileName, $newFileName); if ($fileCouldBeUploaded) { return $newFileName; } } else { throw new InvalidFileNameException('File name could not be verified against deny pattern.', 1496958715); } } return null; }
php
public static function saveFile($file, string $uploadsFolderPath) { if (!empty($file) && is_array($file) && !empty($uploadsFolderPath)) { $fileName = $file['name']; $temporaryFileName = $file['tmp_name']; if (GeneralUtility::verifyFilenameAgainstDenyPattern($fileName)) { $uploadsFolderPath = GeneralUtility::getFileAbsFileName($uploadsFolderPath); $fileName = self::cleanFileName($fileName); $newFileName = self::getUniqueFileName($fileName, $uploadsFolderPath); $fileCouldBeUploaded = GeneralUtility::upload_copy_move($temporaryFileName, $newFileName); if ($fileCouldBeUploaded) { return $newFileName; } } else { throw new InvalidFileNameException('File name could not be verified against deny pattern.', 1496958715); } } return null; }
Saves a file to an uploads folder. @param object $file The file object @param string $uploadsFolderPath The uploads folder path @return string|null The file name of the saved file or null if the file could not be saved @throws \TYPO3\CMS\Core\Resource\Exception\InvalidFileNameException
https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Service/FileService.php#L56-L76
t3v/t3v_core
Classes/Service/FileService.php
FileService.cleanFileName
public static function cleanFileName(string $fileName, array $rulesets = self::FILE_NAME_RULESETS, string $separator = '-'): string { $slugify = new Slugify(['rulesets' => $rulesets, 'separator' => $separator]); $name = $slugify->slugify(pathinfo($fileName, PATHINFO_FILENAME)); $extension = pathinfo($fileName, PATHINFO_EXTENSION); if (empty($name)) { $name = uniqid(self::EMPTY_FILE_NAME_PREFIX, true); } return mb_strtolower($name . '.' . $extension); }
php
public static function cleanFileName(string $fileName, array $rulesets = self::FILE_NAME_RULESETS, string $separator = '-'): string { $slugify = new Slugify(['rulesets' => $rulesets, 'separator' => $separator]); $name = $slugify->slugify(pathinfo($fileName, PATHINFO_FILENAME)); $extension = pathinfo($fileName, PATHINFO_EXTENSION); if (empty($name)) { $name = uniqid(self::EMPTY_FILE_NAME_PREFIX, true); } return mb_strtolower($name . '.' . $extension); }
Cleans a file name. @param string $fileName The file name @param array $rulesets The optional rulesets, defaults to `FileService::FILE_NAME_RULESETS` @param string $separator The optional separator, defaults to `-` @return string The cleaned file name
https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Service/FileService.php#L96-L106
t3v/t3v_core
Classes/Service/FileService.php
FileService.normalizeFileName
public static function normalizeFileName(string $fileName, array $rulesets = self::FILE_NAME_RULESETS, string $separator = '-'): string { return self::cleanFileName($fileName, $rulesets, $separator); }
php
public static function normalizeFileName(string $fileName, array $rulesets = self::FILE_NAME_RULESETS, string $separator = '-'): string { return self::cleanFileName($fileName, $rulesets, $separator); }
Normalizes a file name, alias for `cleanFileName`. @param string $fileName The file name @param array $rulesets The optional rulesets, defaults to `FileService::FILE_NAME_RULESETS` @param string $separator The optional separator, defaults to `-` @return string The normalized file name
https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Service/FileService.php#L116-L118
t3v/t3v_core
Classes/Service/FileService.php
FileService.getUniqueFileName
public static function getUniqueFileName(string $fileName, string $directory): string { $basicFileUtility = GeneralUtility::makeInstance(BasicFileUtility::class); return $basicFileUtility->getUniqueName($fileName, $directory); }
php
public static function getUniqueFileName(string $fileName, string $directory): string { $basicFileUtility = GeneralUtility::makeInstance(BasicFileUtility::class); return $basicFileUtility->getUniqueName($fileName, $directory); }
Gets an unique file name. @param string $fileName The file name @param string $directory The directory for which to return a unique file name for, MUST be a valid directory and should be absolute @return string The unique file name
https://github.com/t3v/t3v_core/blob/8c04b7688cc2773f11fcc87fda3f7cd53d80a980/Classes/Service/FileService.php#L127-L131
bseddon/XPath20
AST/ValueNode.php
ValueNode.Execute
public function Execute( $provider, $dataPool ) { // BMS 2017-12-28 Change to return an iterable type // Seems like this should be OK but perhaps it will cause conformance problems // BMS 2018-01-24 Indeed it did cause conformance problems but changes have been made to fix // them and the XPath 2.0 minimal conformance tests are successfully passed. return $this->_content instanceof Undefined ? $this->_content : XPath2Item::fromValue( $this->_content ); // return $this->getContent(); }
php
public function Execute( $provider, $dataPool ) { // BMS 2017-12-28 Change to return an iterable type // Seems like this should be OK but perhaps it will cause conformance problems // BMS 2018-01-24 Indeed it did cause conformance problems but changes have been made to fix // them and the XPath 2.0 minimal conformance tests are successfully passed. return $this->_content instanceof Undefined ? $this->_content : XPath2Item::fromValue( $this->_content ); // return $this->getContent(); }
Execute @param IContextProvider $provider @param object[] $dataPool @return object
https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/AST/ValueNode.php#L78-L88
kitpages/KitpagesFileBundle
Model/FileManager.php
FileManager.fileDataJson
public function fileDataJson($file, $entityFileName, $widthParent = false) { $ext = strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION)); $data = array( 'id' => $file->getId(), 'fileName' => $file->getFilename(), 'fileExtension' => $ext, 'fileType' => $file->getType(), 'isPrivate' => $file->getIsPrivate(), 'url' => $this->getFileLocationPrivate($file->getId(), $entityFileName) ); $type = $this->getType($file->getType()); if (count($type) > 0) { $data['actionList']['Action'] = $this->router->generate('kitpages_file_actionOnFile_widgetEmpty'); foreach($type as $action=>$actionInfo) { if ($actionInfo['url'] != null) { $data['actionList'][$action] = $this->router->generate($actionInfo['url']); } else { $data['actionList'][$action] = $this->router->generate( 'kitpages_file_actionOnFile_widget', array( 'entityFileName' => $entityFileName, 'typeFile' => $file->getType(), 'actionFile' => $action ) ); } } } if ($widthParent && $file->getParent() instanceof FileInterface) { $data['fileParent'] = $this->fileDataJson($file->getParent(), $entityFileName); $data['publishParent'] = $file->getPublishParent(); } else { $data['fileParent'] = null; $data['publishParent'] = null; } return $data; }
php
public function fileDataJson($file, $entityFileName, $widthParent = false) { $ext = strtolower(pathinfo($file->getFilename(), PATHINFO_EXTENSION)); $data = array( 'id' => $file->getId(), 'fileName' => $file->getFilename(), 'fileExtension' => $ext, 'fileType' => $file->getType(), 'isPrivate' => $file->getIsPrivate(), 'url' => $this->getFileLocationPrivate($file->getId(), $entityFileName) ); $type = $this->getType($file->getType()); if (count($type) > 0) { $data['actionList']['Action'] = $this->router->generate('kitpages_file_actionOnFile_widgetEmpty'); foreach($type as $action=>$actionInfo) { if ($actionInfo['url'] != null) { $data['actionList'][$action] = $this->router->generate($actionInfo['url']); } else { $data['actionList'][$action] = $this->router->generate( 'kitpages_file_actionOnFile_widget', array( 'entityFileName' => $entityFileName, 'typeFile' => $file->getType(), 'actionFile' => $action ) ); } } } if ($widthParent && $file->getParent() instanceof FileInterface) { $data['fileParent'] = $this->fileDataJson($file->getParent(), $entityFileName); $data['publishParent'] = $file->getPublishParent(); } else { $data['fileParent'] = null; $data['publishParent'] = null; } return $data; }
//
https://github.com/kitpages/KitpagesFileBundle/blob/a5f3e1b069b0f4ef0b39d6308174e1d702595a5a/Model/FileManager.php#L154-L193
sil-project/VarietyBundle
src/Entity/Family.php
Family.addGenus
public function addGenus(\Librinfo\VarietiesBundle\Entity\Genus $genus) { $genus->setFamily($this); $this->genuses->add($genus); return $this; }
php
public function addGenus(\Librinfo\VarietiesBundle\Entity\Genus $genus) { $genus->setFamily($this); $this->genuses->add($genus); return $this; }
Add genus. @param \Librinfo\VarietiesBundle\Entity\Genus $genus @return Family
https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Entity/Family.php#L124-L130
sil-project/VarietyBundle
src/Entity/Family.php
Family.removeGenus
public function removeGenus(\Librinfo\VarietiesBundle\Entity\Genus $genus) { return $this->genuses->removeElement($genus); }
php
public function removeGenus(\Librinfo\VarietiesBundle\Entity\Genus $genus) { return $this->genuses->removeElement($genus); }
Remove genus. @param \Librinfo\VarietiesBundle\Entity\Genus $genus @return bool tRUE if this collection contained the specified element, FALSE otherwise
https://github.com/sil-project/VarietyBundle/blob/e9508ce13a4bb277d10bdcd925fdb84bc01f453f/src/Entity/Family.php#L139-L142
ringoteam/RingoPhpRedmonBundle
Command/LoggerCommand.php
LoggerCommand.execute
protected function execute(InputInterface $input, OutputInterface $output) { $logger = $this->getContainer()->get('ringo_php_redmon.instance_logger'); $manager = $this->getContainer()->get('ringo_php_redmon.instance_manager'); $instances = $manager->findAll(); if(is_array($instances)) { foreach($instances as $instance) { $logger ->setInstance($instance) ->execute(); } } }
php
protected function execute(InputInterface $input, OutputInterface $output) { $logger = $this->getContainer()->get('ringo_php_redmon.instance_logger'); $manager = $this->getContainer()->get('ringo_php_redmon.instance_manager'); $instances = $manager->findAll(); if(is_array($instances)) { foreach($instances as $instance) { $logger ->setInstance($instance) ->execute(); } } }
Execute task Get all redis instances and log some of infos @param \Symfony\Component\Console\Input\InputInterface $input @param \Symfony\Component\Console\Output\OutputInterface $output
https://github.com/ringoteam/RingoPhpRedmonBundle/blob/9aab989a9bee9e6152ec19f8a30bc24f3bde6012/Command/LoggerCommand.php#L45-L58
bytic/MediaLibrary
src/HasMedia/HasMediaTrait.php
HasMediaTrait.getMedia
public function getMedia(string $collectionName = 'default', $filters = []): Collection { return $this->getMediaRepository()->getFilteredCollection($collectionName, $filters); }
php
public function getMedia(string $collectionName = 'default', $filters = []): Collection { return $this->getMediaRepository()->getFilteredCollection($collectionName, $filters); }
Get media collection by its collectionName. @param string $collectionName @param array|callable $filters @return Collection
https://github.com/bytic/MediaLibrary/blob/c52783e726b512184bd72e04d829d6f93242a61d/src/HasMedia/HasMediaTrait.php#L32-L35
BenGorFile/DoctrineORMBridge
src/BenGorFile/DoctrineORMBridge/Infrastructure/Persistence/DoctrineORMFileRepository.php
DoctrineORMFileRepository.query
public function query($aSpecification) { return null === $aSpecification ? $this->findAll() : $aSpecification->buildQuery($this->createQueryBuilder('f'))->getResult(); }
php
public function query($aSpecification) { return null === $aSpecification ? $this->findAll() : $aSpecification->buildQuery($this->createQueryBuilder('f'))->getResult(); }
{@inheritdoc}
https://github.com/BenGorFile/DoctrineORMBridge/blob/c632521914d20c1bb7e837db7a3bcacbdebeeb7e/src/BenGorFile/DoctrineORMBridge/Infrastructure/Persistence/DoctrineORMFileRepository.php#L39-L44
BenGorFile/DoctrineORMBridge
src/BenGorFile/DoctrineORMBridge/Infrastructure/Persistence/DoctrineORMFileRepository.php
DoctrineORMFileRepository.length
public function length($aSpecification) { if (null === $aSpecification) { $queryBuilder = $this->getEntityManager()->createQueryBuilder(); return (int) $queryBuilder ->select($queryBuilder->expr()->count('f.id')) ->getQuery() ->getSingleScalarResult(); } return (int) $aSpecification->buildCount( $this->createQueryBuilder('f') )->getSingleScalarResult(); }
php
public function length($aSpecification) { if (null === $aSpecification) { $queryBuilder = $this->getEntityManager()->createQueryBuilder(); return (int) $queryBuilder ->select($queryBuilder->expr()->count('f.id')) ->getQuery() ->getSingleScalarResult(); } return (int) $aSpecification->buildCount( $this->createQueryBuilder('f') )->getSingleScalarResult(); }
{@inheritdoc}
https://github.com/BenGorFile/DoctrineORMBridge/blob/c632521914d20c1bb7e837db7a3bcacbdebeeb7e/src/BenGorFile/DoctrineORMBridge/Infrastructure/Persistence/DoctrineORMFileRepository.php#L57-L71
MindyPHP/FormBundle
Form/Type/FileType.php
FileType.resolveFileUrl
public function resolveFileUrl($data, string $name) { $value = ''; if (null !== $data) { if (is_array($data) && isset($data[$name])) { $value = $data[$name]; } elseif (is_object($data) && property_exists($data, $name)) { $value = $data->{$name}; } return is_string($value) ? $value : ''; } return $value; }
php
public function resolveFileUrl($data, string $name) { $value = ''; if (null !== $data) { if (is_array($data) && isset($data[$name])) { $value = $data[$name]; } elseif (is_object($data) && property_exists($data, $name)) { $value = $data->{$name}; } return is_string($value) ? $value : ''; } return $value; }
@param array|object $data @param string $name @return null|string
https://github.com/MindyPHP/FormBundle/blob/566cc965cc4e44c6ee491059c050346c7fa9c76d/Form/Type/FileType.php#L53-L67
MindyPHP/FormBundle
Form/Type/FileType.php
FileType.buildView
public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['asset_name'] = $options['asset_name']; $parent = $form->getParent(); $view->vars['file_url'] = $parent ? $this->resolveFileUrl($parent->getData(), $form->getName()) : ''; }
php
public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['asset_name'] = $options['asset_name']; $parent = $form->getParent(); $view->vars['file_url'] = $parent ? $this->resolveFileUrl($parent->getData(), $form->getName()) : ''; }
{@inheritdoc}
https://github.com/MindyPHP/FormBundle/blob/566cc965cc4e44c6ee491059c050346c7fa9c76d/Form/Type/FileType.php#L72-L80
MindyPHP/FormBundle
Form/Type/FileType.php
FileType.buildForm
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventListener( FormEvents::PRE_SUBMIT, $this->event->setFormBuilder($builder) ); }
php
public function buildForm(FormBuilderInterface $builder, array $options) { $builder->addEventListener( FormEvents::PRE_SUBMIT, $this->event->setFormBuilder($builder) ); }
{@inheritdoc}
https://github.com/MindyPHP/FormBundle/blob/566cc965cc4e44c6ee491059c050346c7fa9c76d/Form/Type/FileType.php#L93-L99
wb-crowdfusion/crowdfusion
system/core/classes/libraries/utils/FileSystemUtils.php
FileSystemUtils.humanFilesize
public static function humanFilesize($bytes, $decimal = 1) { if (is_numeric($bytes)) { $position = 0; $units = array ( " Bytes", " KB", " MB", " GB", " TB" ); while ($bytes >= 1024 && ($bytes / 1024) >= 1) { $bytes /= 1024; $position++; } return round($bytes, $decimal) . $units[$position]; } else return "0 Bytes"; }
php
public static function humanFilesize($bytes, $decimal = 1) { if (is_numeric($bytes)) { $position = 0; $units = array ( " Bytes", " KB", " MB", " GB", " TB" ); while ($bytes >= 1024 && ($bytes / 1024) >= 1) { $bytes /= 1024; $position++; } return round($bytes, $decimal) . $units[$position]; } else return "0 Bytes"; }
Returns a human-readable filesize for the {@link $bytes} specified. For example: FileSystemUtils::humanFilesize(1024) => "1.0 KB" @param int $bytes The number of bytes of the files @param int $decimal The number of places after the decimal point to show in the result (default: 1) @return string The filesize in human format
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/FileSystemUtils.php#L42-L60
wb-crowdfusion/crowdfusion
system/core/classes/libraries/utils/FileSystemUtils.php
FileSystemUtils.iniValueInBytes
public static function iniValueInBytes($iniValue) { switch (substr ($iniValue, -1)) { case 'M': case 'm': return (int)$iniValue * 1048576; case 'K': case 'k': return (int)$iniValue * 1024; case 'G': case 'g': return (int)$iniValue * 1073741824; default: return $iniValue; } }
php
public static function iniValueInBytes($iniValue) { switch (substr ($iniValue, -1)) { case 'M': case 'm': return (int)$iniValue * 1048576; case 'K': case 'k': return (int)$iniValue * 1024; case 'G': case 'g': return (int)$iniValue * 1073741824; default: return $iniValue; } }
Returns number of bytes for PHP ini values ( memory_limit = 512M ) Stas Trefilov, OpteamIS http://us3.php.net/manual/en/function.ini-get.php#96996 @static @param $iniValue @return int
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/FileSystemUtils.php#L72-L81
wb-crowdfusion/crowdfusion
system/core/classes/libraries/utils/FileSystemUtils.php
FileSystemUtils.getMimetype
public static function getMimetype($extension) { /** * A map of mime types and their default extensions. * * This list has been placed under the public domain by the Apache HTTPD project. * This list has been updated from upstream on 2013-04-23. * * @see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types * * @var array */ static $mimetypes; if (empty($mimetypes)) { $mimetypes = array( '123' => 'application/vnd.lotus-1-2-3', '323' => 'text/h323', '3dml' => 'text/vnd.in3d.3dml', '3ds' => 'image/x-3ds', '3g2' => 'video/3gpp2', '3gp' => 'video/3gpp', '7z' => 'application/x-7z-compressed', 'aab' => 'application/x-authorware-bin', 'aac' => 'audio/x-aac', 'aam' => 'application/x-authorware-map', 'aas' => 'application/x-authorware-seg', 'abw' => 'application/x-abiword', 'ac' => 'application/pkix-attr-cert', 'acc' => 'application/vnd.americandynamics.acc', 'ace' => 'application/x-ace-compressed', 'acu' => 'application/vnd.acucobol', 'acx' => 'application/internet-property-stream', 'adp' => 'audio/adpcm', 'aep' => 'application/vnd.audiograph', 'afp' => 'application/vnd.ibm.modcap', 'ahead' => 'application/vnd.ahead.space', 'ai' => 'application/postscript', 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'air' => 'application/vnd.adobe.air-application-installer-package+zip', 'ait' => 'application/vnd.dvb.ait', 'ami' => 'application/vnd.amiga.ami', 'apk' => 'application/vnd.android.package-archive', 'appcache' => 'text/cache-manifest', 'application' => 'application/x-ms-application', 'apr' => 'application/vnd.lotus-approach', 'arc' => 'application/x-freearc', 'asc' => 'application/pgp-signature', 'asf' => 'video/x-ms-asf', 'aso' => 'application/vnd.accpac.simply.aso', 'asr' => 'video/x-ms-asf', 'asx' => 'video/x-ms-asf', 'atc' => 'application/vnd.acucorp', 'atom' => 'application/atom+xml', 'atomcat' => 'application/atomcat+xml', 'atomsvc' => 'application/atomsvc+xml', 'atx' => 'application/vnd.antix.game-component', 'au' => 'audio/basic', 'avi' => 'video/quicktime', 'aw' => 'application/applixware', 'axs' => 'application/olescript', 'azf' => 'application/vnd.airzip.filesecure.azf', 'azs' => 'application/vnd.airzip.filesecure.azs', 'azw' => 'application/vnd.amazon.ebook', 'bas' => 'text/plain', 'bcpio' => 'application/x-bcpio', 'bdf' => 'application/x-font-bdf', 'bdm' => 'application/vnd.syncml.dm+wbxml', 'bed' => 'application/vnd.realvnc.bed', 'bh2' => 'application/vnd.fujitsu.oasysprs', 'bin' => 'application/octet-stream', 'blb' => 'application/x-blorb', 'bmi' => 'application/vnd.bmi', 'bmp' => 'image/bmp', 'box' => 'application/vnd.previewsystems.box', 'btif' => 'image/prs.btif', 'bz' => 'application/x-bzip', 'bz2' => 'application/x-bzip2', 'c' => 'text/plain', 'c11amc' => 'application/vnd.cluetrust.cartomobile-config', 'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg', 'c4g' => 'application/vnd.clonk.c4group', 'cab' => 'application/vnd.ms-cab-compressed', 'caf' => 'audio/x-caf', 'car' => 'application/vnd.curl.car', 'cat' => 'application/vnd.ms-pkiseccat', 'cbr' => 'application/x-cbr', 'ccxml' => 'application/ccxml+xml', 'cdbcmsg' => 'application/vnd.contact.cmsg', 'cdf' => 'application/x-cdf', 'cdkey' => 'application/vnd.mediastation.cdkey', 'cdmia' => 'application/cdmi-capability', 'cdmic' => 'application/cdmi-container', 'cdmid' => 'application/cdmi-domain', 'cdmio' => 'application/cdmi-object', 'cdmiq' => 'application/cdmi-queue', 'cdx' => 'chemical/x-cdx', 'cdxml' => 'application/vnd.chemdraw+xml', 'cdy' => 'application/vnd.cinderella', 'cer' => 'application/x-x509-ca-cert', 'cfs' => 'application/x-cfs-compressed', 'cgm' => 'image/cgm', 'chat' => 'application/x-chat', 'chm' => 'application/vnd.ms-htmlhelp', 'chrt' => 'application/vnd.kde.kchart', 'cif' => 'chemical/x-cif', 'cii' => 'application/vnd.anser-web-certificate-issue-initiation', 'cil' => 'application/vnd.ms-artgalry', 'cla' => 'application/vnd.claymore', 'class' => 'application/octet-stream', 'clkk' => 'application/vnd.crick.clicker.keyboard', 'clkp' => 'application/vnd.crick.clicker.palette', 'clkt' => 'application/vnd.crick.clicker.template', 'clkw' => 'application/vnd.crick.clicker.wordbank', 'clkx' => 'application/vnd.crick.clicker', 'clp' => 'application/x-msclip', 'cmc' => 'application/vnd.cosmocaller', 'cmdf' => 'chemical/x-cmdf', 'cml' => 'chemical/x-cml', 'cmp' => 'application/vnd.yellowriver-custom-menu', 'cmx' => 'image/x-cmx', 'cod' => 'image/cis-cod', 'cpio' => 'application/x-cpio', 'cpt' => 'application/mac-compactpro', 'crd' => 'application/x-mscardfile', 'crl' => 'application/pkix-crl', 'crt' => 'application/x-x509-ca-cert', 'cryptonote' => 'application/vnd.rig.cryptonote', 'csh' => 'application/x-csh', 'csml' => 'chemical/x-csml', 'csp' => 'application/vnd.commonspace', 'css' => 'text/css', 'csv' => 'text/comma-separated-values', 'cu' => 'application/cu-seeme', 'curl' => 'text/vnd.curl', 'cww' => 'application/prs.cww', 'dae' => 'model/vnd.collada+xml', 'daf' => 'application/vnd.mobius.daf', 'dart' => 'application/vnd.dart', 'davmount' => 'application/davmount+xml', 'dbk' => 'application/docbook+xml', 'dcr' => 'application/x-director', 'dcurl' => 'text/vnd.curl.dcurl', 'dd2' => 'application/vnd.oma.dd2+xml', 'ddd' => 'application/vnd.fujixerox.ddd', 'deb' => 'application/x-debian-package', 'der' => 'application/x-x509-ca-cert', 'dfac' => 'application/vnd.dreamfactory', 'dgc' => 'application/x-dgc-compressed', 'dir' => 'application/x-director', 'dis' => 'application/vnd.mobius.dis', 'djvu' => 'image/vnd.djvu', 'dll' => 'application/x-msdownload', 'dmg' => 'application/x-apple-diskimage', 'dms' => 'application/octet-stream', 'dna' => 'application/vnd.dna', 'doc' => 'application/msword', 'docm' => 'application/vnd.ms-word.document.macroenabled.12', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'dot' => 'application/msword', 'dotm' => 'application/vnd.ms-word.template.macroenabled.12', 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 'dp' => 'application/vnd.osgi.dp', 'dpg' => 'application/vnd.dpgraph', 'dra' => 'audio/vnd.dra', 'dsc' => 'text/prs.lines.tag', 'dssc' => 'application/dssc+der', 'dtb' => 'application/x-dtbook+xml', 'dtd' => 'application/xml-dtd', 'dts' => 'audio/vnd.dts', 'dtshd' => 'audio/vnd.dts.hd', 'dvb' => 'video/vnd.dvb.file', 'dvi' => 'application/x-dvi', 'dwf' => 'model/vnd.dwf', 'dwg' => 'image/vnd.dwg', 'dxf' => 'image/vnd.dxf', 'dxp' => 'application/vnd.spotfire.dxp', 'dxr' => 'application/x-director', 'ecelp4800' => 'audio/vnd.nuera.ecelp4800', 'ecelp7470' => 'audio/vnd.nuera.ecelp7470', 'ecelp9600' => 'audio/vnd.nuera.ecelp9600', 'ecma' => 'application/ecmascript', 'edm' => 'application/vnd.novadigm.edm', 'edx' => 'application/vnd.novadigm.edx', 'efif' => 'application/vnd.picsel', 'ei6' => 'application/vnd.pg.osasli', 'eml' => 'message/rfc822', 'emma' => 'application/emma+xml', 'eol' => 'audio/vnd.digital-winds', 'eot' => 'application/vnd.ms-fontobject', 'eps' => 'application/postscript', 'epub' => 'application/epub+zip', 'es3' => 'application/vnd.eszigno3+xml', 'esa' => 'application/vnd.osgi.subsystem', 'esf' => 'application/vnd.epson.esf', 'etx' => 'text/x-setext', 'eva' => 'application/x-eva', 'evy' => 'application/envoy', 'exe' => 'application/octet-stream', 'exi' => 'application/exi', 'ext' => 'application/vnd.novadigm.ext', 'ez' => 'application/andrew-inset', 'ez2' => 'application/vnd.ezpix-album', 'ez3' => 'application/vnd.ezpix-package', 'f' => 'text/x-fortran', 'f4v' => 'video/x-f4v', 'fbs' => 'image/vnd.fastbidsheet', 'fcdt' => 'application/vnd.adobe.formscentral.fcdt', 'fcs' => 'application/vnd.isac.fcs', 'fdf' => 'application/vnd.fdf', 'fe_launch' => 'application/vnd.denovo.fcselayout-link', 'fg5' => 'application/vnd.fujitsu.oasysgp', 'fh' => 'image/x-freehand', 'fif' => 'application/fractals', 'fig' => 'application/x-xfig', 'flac' => 'audio/x-flac', 'fli' => 'video/x-fli', 'flo' => 'application/vnd.micrografx.flo', 'flr' => 'x-world/x-vrml', 'flv' => 'video/x-flv', 'flw' => 'application/vnd.kde.kivio', 'flx' => 'text/vnd.fmi.flexstor', 'fly' => 'text/vnd.fly', 'fm' => 'application/vnd.framemaker', 'fnc' => 'application/vnd.frogans.fnc', 'fpx' => 'image/vnd.fpx', 'fsc' => 'application/vnd.fsc.weblaunch', 'fst' => 'image/vnd.fst', 'ftc' => 'application/vnd.fluxtime.clip', 'fti' => 'application/vnd.anser-web-funds-transfer-initiation', 'fvt' => 'video/vnd.fvt', 'fxp' => 'application/vnd.adobe.fxp', 'fzs' => 'application/vnd.fuzzysheet', 'g2w' => 'application/vnd.geoplan', 'g3' => 'image/g3fax', 'g3w' => 'application/vnd.geospace', 'gac' => 'application/vnd.groove-account', 'gam' => 'application/x-tads', 'gbr' => 'application/rpki-ghostbusters', 'gca' => 'application/x-gca-compressed', 'gdl' => 'model/vnd.gdl', 'geo' => 'application/vnd.dynageo', 'gex' => 'application/vnd.geometry-explorer', 'ggb' => 'application/vnd.geogebra.file', 'ggt' => 'application/vnd.geogebra.tool', 'ghf' => 'application/vnd.groove-help', 'gif' => 'image/gif', 'gim' => 'application/vnd.groove-identity-message', 'gml' => 'application/gml+xml', 'gmx' => 'application/vnd.gmx', 'gnumeric' => 'application/x-gnumeric', 'gph' => 'application/vnd.flographit', 'gpx' => 'application/gpx+xml', 'gqf' => 'application/vnd.grafeq', 'gram' => 'application/srgs', 'gramps' => 'application/x-gramps-xml', 'grv' => 'application/vnd.groove-injector', 'grxml' => 'application/srgs+xml', 'gsf' => 'application/x-font-ghostscript', 'gtar' => 'application/x-gtar', 'gtm' => 'application/vnd.groove-tool-message', 'gtw' => 'model/vnd.gtw', 'gv' => 'text/vnd.graphviz', 'gxf' => 'application/gxf', 'gxt' => 'application/vnd.geonext', 'gz' => 'application/x-gzip', 'h' => 'text/plain', 'h261' => 'video/h261', 'h263' => 'video/h263', 'h264' => 'video/h264', 'hal' => 'application/vnd.hal+xml', 'hbci' => 'application/vnd.hbci', 'hdf' => 'application/x-hdf', 'hlp' => 'application/winhlp', 'hpgl' => 'application/vnd.hp-hpgl', 'hpid' => 'application/vnd.hp-hpid', 'hps' => 'application/vnd.hp-hps', 'hqx' => 'application/mac-binhex40', 'hta' => 'application/hta', 'htc' => 'text/x-component', 'htke' => 'application/vnd.kenameaapp', 'htm' => 'text/html', 'html' => 'text/html', 'htt' => 'text/webviewhtml', 'hvd' => 'application/vnd.yamaha.hv-dic', 'hvp' => 'application/vnd.yamaha.hv-voice', 'hvs' => 'application/vnd.yamaha.hv-script', 'i2g' => 'application/vnd.intergeo', 'icc' => 'application/vnd.iccprofile', 'ice' => 'x-conference/x-cooltalk', 'ico' => 'image/x-icon', 'ics' => 'text/calendar', 'ief' => 'image/ief', 'ifm' => 'application/vnd.shana.informed.formdata', 'igl' => 'application/vnd.igloader', 'igm' => 'application/vnd.insors.igm', 'igs' => 'model/iges', 'igx' => 'application/vnd.micrografx.igx', 'iif' => 'application/vnd.shana.informed.interchange', 'iii' => 'application/x-iphone', 'imp' => 'application/vnd.accpac.simply.imp', 'ims' => 'application/vnd.ms-ims', 'ink' => 'application/inkml+xml', 'ins' => 'application/x-internet-signup', 'install' => 'application/x-install-instructions', 'iota' => 'application/vnd.astraea-software.iota', 'ipfix' => 'application/ipfix', 'ipk' => 'application/vnd.shana.informed.package', 'irm' => 'application/vnd.ibm.rights-management', 'irp' => 'application/vnd.irepository.package+xml', 'iso' => 'application/x-iso9660-image', 'isp' => 'application/x-internet-signup', 'itp' => 'application/vnd.shana.informed.formtemplate', 'ivp' => 'application/vnd.immervision-ivp', 'ivu' => 'application/vnd.immervision-ivu', 'jad' => 'text/vnd.sun.j2me.app-descriptor', 'jam' => 'application/vnd.jam', 'jar' => 'application/java-archive', 'java' => 'text/x-java-source', 'jfif' => 'image/pipeg', 'jisp' => 'application/vnd.jisp', 'jlt' => 'application/vnd.hp-jlyt', 'jnlp' => 'application/x-java-jnlp-file', 'joda' => 'application/vnd.joost.joda-archive', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpgv' => 'video/jpeg', 'jpm' => 'video/jpm', 'js' => 'application/x-javascript', 'json' => 'application/json', 'jsonml' => 'application/jsonml+json', 'karbon' => 'application/vnd.kde.karbon', 'kfo' => 'application/vnd.kde.kformula', 'kia' => 'application/vnd.kidspiration', 'kml' => 'application/vnd.google-earth.kml+xml', 'kmz' => 'application/vnd.google-earth.kmz', 'kne' => 'application/vnd.kinar', 'kon' => 'application/vnd.kde.kontour', 'kpr' => 'application/vnd.kde.kpresenter', 'kpxx' => 'application/vnd.ds-keypoint', 'ksp' => 'application/vnd.kde.kspread', 'ktx' => 'image/ktx', 'ktz' => 'application/vnd.kahootz', 'kwd' => 'application/vnd.kde.kword', 'lasxml' => 'application/vnd.las.las+xml', 'latex' => 'application/x-latex', 'lbd' => 'application/vnd.llamagraphics.life-balance.desktop', 'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml', 'les' => 'application/vnd.hhe.lesson-player', 'lha' => 'application/octet-stream', 'link66' => 'application/vnd.route66.link66+xml', 'lnk' => 'application/x-ms-shortcut', 'log' => 'text/plain', 'lostxml' => 'application/lost+xml', 'lrm' => 'application/vnd.ms-lrm', 'lsf' => 'video/x-la-asf', 'lsx' => 'video/x-la-asf', 'ltf' => 'application/vnd.frogans.ltf', 'lvp' => 'audio/vnd.lucent.voice', 'lwp' => 'application/vnd.lotus-wordpro', 'lzh' => 'application/octet-stream', 'm13' => 'application/x-msmediaview', 'm14' => 'application/x-msmediaview', 'm21' => 'application/mp21', 'm3u' => 'audio/x-mpegurl', 'm3u8' => 'application/vnd.apple.mpegurl', 'm4v' => 'video/x-m4v', 'ma' => 'application/mathematica', 'mads' => 'application/mads+xml', 'mag' => 'application/vnd.ecowin.chart', 'man' => 'application/x-troff-man', 'mathml' => 'application/mathml+xml', 'mbk' => 'application/vnd.mobius.mbk', 'mbox' => 'application/mbox', 'mc1' => 'application/vnd.medcalcdata', 'mcd' => 'application/vnd.mcd', 'mcurl' => 'text/vnd.curl.mcurl', 'mdb' => 'application/x-msaccess', 'mdi' => 'image/vnd.ms-modi', 'me' => 'application/x-troff-me', 'meta4' => 'application/metalink4+xml', 'metalink' => 'application/metalink+xml', 'mets' => 'application/mets+xml', 'mfm' => 'application/vnd.mfmp', 'mft' => 'application/rpki-manifest', 'mgp' => 'application/vnd.osgeo.mapguide.package', 'mgz' => 'application/vnd.proteus.magazine', 'mht' => 'message/rfc822', 'mhtml' => 'message/rfc822', 'mid' => 'audio/mid', 'mie' => 'application/x-mie', 'mif' => 'application/vnd.mif', 'mj2' => 'video/mj2', 'mka' => 'audio/x-matroska', 'mkv' => 'video/x-matroska', 'mlp' => 'application/vnd.dolby.mlp', 'mmd' => 'application/vnd.chipnuts.karaoke-mmd', 'mmf' => 'application/vnd.smaf', 'mmr' => 'image/vnd.fujixerox.edmics-mmr', 'mng' => 'video/x-mng', 'mny' => 'application/x-msmoney', 'mods' => 'application/mods+xml', 'mov' => 'video/quicktime', 'movie' => 'video/x-sgi-movie', 'mp2' => 'video/mpeg', 'mp3' => 'audio/mpeg', 'mp4' => 'video/mp4', 'mp4a' => 'audio/mp4', 'mp4s' => 'application/mp4', 'mpa' => 'video/mpeg', 'mpc' => 'application/vnd.mophun.certificate', 'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpga' => 'audio/mpeg', 'mpkg' => 'application/vnd.apple.installer+xml', 'mpm' => 'application/vnd.blueice.multipass', 'mpn' => 'application/vnd.mophun.application', 'mpp' => 'application/vnd.ms-project', 'mpv2' => 'video/mpeg', 'mpy' => 'application/vnd.ibm.minipay', 'mqy' => 'application/vnd.mobius.mqy', 'mrc' => 'application/marc', 'mrcx' => 'application/marcxml+xml', 'ms' => 'application/x-troff-ms', 'mscml' => 'application/mediaservercontrol+xml', 'mseed' => 'application/vnd.fdsn.mseed', 'mseq' => 'application/vnd.mseq', 'msf' => 'application/vnd.epson.msf', 'msh' => 'model/mesh', 'msl' => 'application/vnd.mobius.msl', 'msty' => 'application/vnd.muvee.style', 'mts' => 'model/vnd.mts', 'mus' => 'application/vnd.musician', 'musicxml' => 'application/vnd.recordare.musicxml+xml', 'mvb' => 'application/x-msmediaview', 'mwf' => 'application/vnd.mfer', 'mxf' => 'application/mxf', 'mxl' => 'application/vnd.recordare.musicxml', 'mxml' => 'application/xv+xml', 'mxs' => 'application/vnd.triscape.mxs', 'mxu' => 'video/vnd.mpegurl', 'n-gage' => 'application/vnd.nokia.n-gage.symbian.install', 'n3' => 'text/n3', 'nbp' => 'application/vnd.wolfram.player', 'nc' => 'application/x-netcdf', 'ncx' => 'application/x-dtbncx+xml', 'nfo' => 'text/x-nfo', 'ngdat' => 'application/vnd.nokia.n-gage.data', 'nlu' => 'application/vnd.neurolanguage.nlu', 'nml' => 'application/vnd.enliven', 'nnd' => 'application/vnd.noblenet-directory', 'nns' => 'application/vnd.noblenet-sealer', 'nnw' => 'application/vnd.noblenet-web', 'npx' => 'image/vnd.net-fpx', 'nsc' => 'application/x-conference', 'nsf' => 'application/vnd.lotus-notes', 'ntf' => 'application/vnd.nitf', 'nws' => 'message/rfc822', 'nzb' => 'application/x-nzb', 'oa2' => 'application/vnd.fujitsu.oasys2', 'oa3' => 'application/vnd.fujitsu.oasys3', 'oas' => 'application/vnd.fujitsu.oasys', 'obd' => 'application/x-msbinder', 'obj' => 'application/x-tgif', 'oda' => 'application/oda', 'odb' => 'application/vnd.oasis.opendocument.database', 'odc' => 'application/vnd.oasis.opendocument.chart', 'odf' => 'application/vnd.oasis.opendocument.formula', 'odft' => 'application/vnd.oasis.opendocument.formula-template', 'odg' => 'application/vnd.oasis.opendocument.graphics', 'odi' => 'application/vnd.oasis.opendocument.image', 'odm' => 'application/vnd.oasis.opendocument.text-master', 'odp' => 'application/vnd.oasis.opendocument.presentation', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', 'odt' => 'application/vnd.oasis.opendocument.text', 'oga' => 'audio/ogg', 'ogv' => 'video/ogg', 'ogx' => 'application/ogg', 'omdoc' => 'application/omdoc+xml', 'onetoc' => 'application/onenote', 'opf' => 'application/oebps-package+xml', 'opml' => 'text/x-opml', 'org' => 'application/vnd.lotus-organizer', 'osf' => 'application/vnd.yamaha.openscoreformat', 'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml', 'otc' => 'application/vnd.oasis.opendocument.chart-template', 'otf' => 'application/x-font-otf', 'otg' => 'application/vnd.oasis.opendocument.graphics-template', 'oth' => 'application/vnd.oasis.opendocument.text-web', 'oti' => 'application/vnd.oasis.opendocument.image-template', 'otp' => 'application/vnd.oasis.opendocument.presentation-template', 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', 'ott' => 'application/vnd.oasis.opendocument.text-template', 'oxps' => 'application/oxps', 'oxt' => 'application/vnd.openofficeorg.extension', 'p' => 'text/x-pascal', 'p10' => 'application/pkcs10', 'p12' => 'application/x-pkcs12', 'p7b' => 'application/x-pkcs7-certificates', 'p7c' => 'application/x-pkcs7-mime', 'p7m' => 'application/x-pkcs7-mime', 'p7r' => 'application/x-pkcs7-certreqresp', 'p7s' => 'application/x-pkcs7-signature', 'p8' => 'application/pkcs8', 'paw' => 'application/vnd.pawaafile', 'pbd' => 'application/vnd.powerbuilder6', 'pbm' => 'image/x-portable-bitmap', 'pcap' => 'application/vnd.tcpdump.pcap', 'pcf' => 'application/x-font-pcf', 'pcl' => 'application/vnd.hp-pcl', 'pclxl' => 'application/vnd.hp-pclxl', 'pcurl' => 'application/vnd.curl.pcurl', 'pcx' => 'image/x-pcx', 'pdb' => 'application/vnd.palm', 'pdf' => 'application/pdf', 'pfa' => 'application/x-font-type1', 'pfr' => 'application/font-tdpfr', 'pfx' => 'application/x-pkcs12', 'pgm' => 'image/x-portable-graymap', 'pgn' => 'application/x-chess-pgn', 'pgp' => 'application/pgp-encrypted', 'pic' => 'image/x-pict', 'pki' => 'application/pkixcmp', 'pkipath' => 'application/pkix-pkipath', 'pko' => 'application/ynd.ms-pkipko', 'plb' => 'application/vnd.3gpp.pic-bw-large', 'plc' => 'application/vnd.mobius.plc', 'plf' => 'application/vnd.pocketlearn', 'pls' => 'application/pls+xml', 'pma' => 'application/x-perfmon', 'pmc' => 'application/x-perfmon', 'pml' => 'application/x-perfmon', 'pmr' => 'application/x-perfmon', 'pmw' => 'application/x-perfmon', 'png' => 'image/png', 'pnm' => 'image/x-portable-anymap', 'portpkg' => 'application/vnd.macports.portpkg', 'pot' => 'application/vnd.ms-powerpoint', 'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12', 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', 'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12', 'ppd' => 'application/vnd.cups-ppd', 'ppm' => 'image/x-portable-pixmap', 'pps' => 'application/vnd.ms-powerpoint', 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12', 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', 'ppt' => 'application/vnd.ms-powerpoint', 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'prc' => 'application/x-mobipocket-ebook', 'pre' => 'application/vnd.lotus-freelance', 'prf' => 'application/pics-rules', 'ps' => 'application/postscript', 'psb' => 'application/vnd.3gpp.pic-bw-small', 'psd' => 'image/photoshop', 'psf' => 'application/x-font-linux-psf', 'pskcxml' => 'application/pskc+xml', 'ptid' => 'application/vnd.pvi.ptid1', 'pub' => 'application/x-mspublisher', 'pvb' => 'application/vnd.3gpp.pic-bw-var', 'pwn' => 'application/vnd.3m.post-it-notes', 'pya' => 'audio/vnd.ms-playready.media.pya', 'pyv' => 'video/vnd.ms-playready.media.pyv', 'qam' => 'application/vnd.epson.quickanime', 'qbo' => 'application/vnd.intu.qbo', 'qfx' => 'application/vnd.intu.qfx', 'qps' => 'application/vnd.publishare-delta-tree', 'qt' => 'video/quicktime', 'qxd' => 'application/vnd.quark.quarkxpress', 'ra' => 'audio/x-pn-realaudio', 'ram' => 'audio/x-pn-realaudio', 'rar' => 'application/x-rar-compressed', 'ras' => 'image/x-cmu-raster', 'rcprofile' => 'application/vnd.ipunplugged.rcprofile', 'rdf' => 'application/rdf+xml', 'rdz' => 'application/vnd.data-vision.rdz', 'rep' => 'application/vnd.businessobjects', 'res' => 'application/x-dtbresource+xml', 'rgb' => 'image/x-rgb', 'rif' => 'application/reginfo+xml', 'rip' => 'audio/vnd.rip', 'ris' => 'application/x-research-info-systems', 'rl' => 'application/resource-lists+xml', 'rlc' => 'image/vnd.fujixerox.edmics-rlc', 'rld' => 'application/resource-lists-diff+xml', 'rm' => 'application/vnd.rn-realmedia', 'rmi' => 'audio/mid', 'rmp' => 'audio/x-pn-realaudio-plugin', 'rms' => 'application/vnd.jcp.javame.midlet-rms', 'rmvb' => 'application/vnd.rn-realmedia-vbr', 'rnc' => 'application/relax-ng-compact-syntax', 'roa' => 'application/rpki-roa', 'roff' => 'application/x-troff', 'rp9' => 'application/vnd.cloanto.rp9', 'rpss' => 'application/vnd.nokia.radio-presets', 'rpst' => 'application/vnd.nokia.radio-preset', 'rq' => 'application/sparql-query', 'rs' => 'application/rls-services+xml', 'rsd' => 'application/rsd+xml', 'rss' => 'application/rss+xml', 'rtf' => 'application/rtf', 'rtx' => 'text/richtext', 's' => 'text/x-asm', 's3m' => 'audio/s3m', 'saf' => 'application/vnd.yamaha.smaf-audio', 'sbml' => 'application/sbml+xml', 'sc' => 'application/vnd.ibm.secure-container', 'scd' => 'application/x-msschedule', 'scm' => 'application/vnd.lotus-screencam', 'scq' => 'application/scvp-cv-request', 'scs' => 'application/scvp-cv-response', 'sct' => 'text/scriptlet', 'scurl' => 'text/vnd.curl.scurl', 'sda' => 'application/vnd.stardivision.draw', 'sdc' => 'application/vnd.stardivision.calc', 'sdd' => 'application/vnd.stardivision.impress', 'sdkm' => 'application/vnd.solent.sdkm+xml', 'sdp' => 'application/sdp', 'sdw' => 'application/vnd.stardivision.writer', 'see' => 'application/vnd.seemail', 'seed' => 'application/vnd.fdsn.seed', 'sema' => 'application/vnd.sema', 'semd' => 'application/vnd.semd', 'semf' => 'application/vnd.semf', 'ser' => 'application/java-serialized-object', 'setpay' => 'application/set-payment-initiation', 'setreg' => 'application/set-registration-initiation', 'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data', 'sfs' => 'application/vnd.spotfire.sfs', 'sfv' => 'text/x-sfv', 'sgi' => 'image/sgi', 'sgl' => 'application/vnd.stardivision.writer-global', 'sgml' => 'text/sgml', 'sh' => 'application/x-sh', 'shar' => 'application/x-shar', 'shf' => 'application/shf+xml', 'sid' => 'image/x-mrsid-image', 'sil' => 'audio/silk', 'sis' => 'application/vnd.symbian.install', 'sit' => 'application/x-stuffit', 'sitx' => 'application/x-stuffitx', 'skp' => 'application/vnd.koan', 'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12', 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', 'slt' => 'application/vnd.epson.salt', 'sm' => 'application/vnd.stepmania.stepchart', 'smf' => 'application/vnd.stardivision.math', 'smi' => 'application/smil+xml', 'smv' => 'video/x-smv', 'smzip' => 'application/vnd.stepmania.package', 'snd' => 'audio/basic', 'snf' => 'application/x-font-snf', 'spc' => 'application/x-pkcs7-certificates', 'spf' => 'application/vnd.yamaha.smaf-phrase', 'spl' => 'application/futuresplash', 'spot' => 'text/vnd.in3d.spot', 'spp' => 'application/scvp-vp-response', 'spq' => 'application/scvp-vp-request', 'sql' => 'application/x-sql', 'src' => 'application/x-wais-source', 'srt' => 'application/x-subrip', 'sru' => 'application/sru+xml', 'srx' => 'application/sparql-results+xml', 'ssdl' => 'application/ssdl+xml', 'sse' => 'application/vnd.kodak-descriptor', 'ssf' => 'application/vnd.epson.ssf', 'ssml' => 'application/ssml+xml', 'sst' => 'application/vnd.ms-pkicertstore', 'st' => 'application/vnd.sailingtracker.track', 'stc' => 'application/vnd.sun.xml.calc.template', 'std' => 'application/vnd.sun.xml.draw.template', 'stf' => 'application/vnd.wt.stf', 'sti' => 'application/vnd.sun.xml.impress.template', 'stk' => 'application/hyperstudio', 'stl' => 'application/vnd.ms-pkistl', 'stm' => 'text/html', 'str' => 'application/vnd.pg.format', 'stw' => 'application/vnd.sun.xml.writer.template', 'sub' => 'image/vnd.dvb.subtitle', 'sus' => 'application/vnd.sus-calendar', 'sv4cpio' => 'application/x-sv4cpio', 'sv4crc' => 'application/x-sv4crc', 'svc' => 'application/vnd.dvb.service', 'svd' => 'application/vnd.svd', 'svg' => 'image/svg+xml', 'swf' => 'application/x-shockwave-flash', 'swi' => 'application/vnd.aristanetworks.swi', 'sxc' => 'application/vnd.sun.xml.calc', 'sxd' => 'application/vnd.sun.xml.draw', 'sxg' => 'application/vnd.sun.xml.writer.global', 'sxi' => 'application/vnd.sun.xml.impress', 'sxm' => 'application/vnd.sun.xml.math', 'sxw' => 'application/vnd.sun.xml.writer', 't' => 'application/x-troff', 't3' => 'application/x-t3vm-image', 'taglet' => 'application/vnd.mynfc', 'tao' => 'application/vnd.tao.intent-module-archive', 'tar' => 'application/x-tar', 'tcap' => 'application/vnd.3gpp2.tcap', 'tcl' => 'application/x-tcl', 'teacher' => 'application/vnd.smart.teacher', 'tei' => 'application/tei+xml', 'tex' => 'application/x-tex', 'texi' => 'application/x-texinfo', 'texinfo' => 'application/x-texinfo', 'tfi' => 'application/thraud+xml', 'tfm' => 'application/x-tex-tfm', 'tga' => 'image/x-tga', 'tgz' => 'application/x-compressed', 'thmx' => 'application/vnd.ms-officetheme', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'tmo' => 'application/vnd.tmobile-livetv', 'torrent' => 'application/x-bittorrent', 'tpl' => 'application/vnd.groove-tool-template', 'tpt' => 'application/vnd.trid.tpt', 'tr' => 'application/x-troff', 'tra' => 'application/vnd.trueapp', 'trm' => 'application/x-msterminal', 'tsd' => 'application/timestamped-data', 'tsv' => 'text/tab-separated-values', 'ttf' => 'application/x-font-ttf', 'ttl' => 'text/turtle', 'twd' => 'application/vnd.simtech-mindmapper', 'txd' => 'application/vnd.genomatix.tuxedo', 'txf' => 'application/vnd.mobius.txf', 'txt' => 'text/plain', 'ufd' => 'application/vnd.ufdl', 'uls' => 'text/iuls', 'ulx' => 'application/x-glulx', 'umj' => 'application/vnd.umajin', 'unityweb' => 'application/vnd.unity', 'uoml' => 'application/vnd.uoml+xml', 'uri' => 'text/uri-list', 'ustar' => 'application/x-ustar', 'utz' => 'application/vnd.uiq.theme', 'uu' => 'text/x-uuencode', 'uva' => 'audio/vnd.dece.audio', 'uvf' => 'application/vnd.dece.data', 'uvh' => 'video/vnd.dece.hd', 'uvi' => 'image/vnd.dece.graphic', 'uvm' => 'video/vnd.dece.mobile', 'uvp' => 'video/vnd.dece.pd', 'uvs' => 'video/vnd.dece.sd', 'uvt' => 'application/vnd.dece.ttml+xml', 'uvu' => 'video/vnd.uvvu.mp4', 'uvv' => 'video/vnd.dece.video', 'uvx' => 'application/vnd.dece.unspecified', 'uvz' => 'application/vnd.dece.zip', 'vcard' => 'text/vcard', 'vcd' => 'application/x-cdlink', 'vcf' => 'text/x-vcard', 'vcg' => 'application/vnd.groove-vcard', 'vcs' => 'text/x-vcalendar', 'vcx' => 'application/vnd.vcx', 'vis' => 'application/vnd.visionary', 'viv' => 'video/vnd.vivo', 'vob' => 'video/x-ms-vob', 'vrml' => 'x-world/x-vrml', 'vsd' => 'application/vnd.visio', 'vsf' => 'application/vnd.vsf', 'vtu' => 'model/vnd.vtu', 'vxml' => 'application/voicexml+xml', 'wad' => 'application/x-doom', 'wav' => 'audio/x-wav', 'wax' => 'audio/x-ms-wax', 'wbmp' => 'image/vnd.wap.wbmp', 'wbs' => 'application/vnd.criticaltools.wbs+xml', 'wbxml' => 'application/vnd.wap.wbxml', 'wcm' => 'application/vnd.ms-works', 'wdb' => 'application/vnd.ms-works', 'wdp' => 'image/vnd.ms-photo', 'weba' => 'audio/webm', 'webm' => 'video/webm', 'webp' => 'image/webp', 'wg' => 'application/vnd.pmi.widget', 'wgt' => 'application/widget', 'wks' => 'application/vnd.ms-works', 'wm' => 'video/x-ms-wm', 'wma' => 'audio/x-ms-wma', 'wmd' => 'application/x-ms-wmd', 'wmf' => 'application/x-msmetafile', 'wml' => 'text/vnd.wap.wml', 'wmlc' => 'application/vnd.wap.wmlc', 'wmls' => 'text/vnd.wap.wmlscript', 'wmlsc' => 'application/vnd.wap.wmlscriptc', 'wmv' => 'video/x-ms-wmv', 'wmx' => 'video/x-ms-wmx', 'wmz' => 'application/x-ms-wmz', 'woff' => 'application/x-font-woff', 'wpd' => 'application/vnd.wordperfect', 'wpl' => 'application/vnd.ms-wpl', 'wps' => 'application/vnd.ms-works', 'wqd' => 'application/vnd.wqd', 'wri' => 'application/x-mswrite', 'wrl' => 'x-world/x-vrml', 'wrz' => 'x-world/x-vrml', 'wsdl' => 'application/wsdl+xml', 'wspolicy' => 'application/wspolicy+xml', 'wtb' => 'application/vnd.webturbo', 'wvx' => 'video/x-ms-wvx', 'x3d' => 'model/x3d+xml', 'x3db' => 'model/x3d+binary', 'x3dv' => 'model/x3d+vrml', 'xaf' => 'x-world/x-vrml', 'xaml' => 'application/xaml+xml', 'xap' => 'application/x-silverlight-app', 'xar' => 'application/vnd.xara', 'xbap' => 'application/x-ms-xbap', 'xbd' => 'application/vnd.fujixerox.docuworks.binder', 'xbm' => 'image/x-xbitmap', 'xdf' => 'application/xcap-diff+xml', 'xdm' => 'application/vnd.syncml.dm+xml', 'xdp' => 'application/vnd.adobe.xdp+xml', 'xdssc' => 'application/dssc+xml', 'xdw' => 'application/vnd.fujixerox.docuworks', 'xenc' => 'application/xenc+xml', 'xer' => 'application/patch-ops-error+xml', 'xfdf' => 'application/vnd.adobe.xfdf', 'xfdl' => 'application/vnd.xfdl', 'xhtml' => 'application/xhtml+xml', 'xif' => 'image/vnd.xiff', 'xla' => 'application/vnd.ms-excel', 'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12', 'xlc' => 'application/vnd.ms-excel', 'xlf' => 'application/x-xliff+xml', 'xlm' => 'application/vnd.ms-excel', 'xls' => 'application/vnd.ms-excel', 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12', 'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xlt' => 'application/vnd.ms-excel', 'xltm' => 'application/vnd.ms-excel.template.macroenabled.12', 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', 'xlw' => 'application/vnd.ms-excel', 'xm' => 'audio/xm', 'xml' => 'text/xml', 'xo' => 'application/vnd.olpc-sugar', 'xof' => 'x-world/x-vrml', 'xop' => 'application/xop+xml', 'xpi' => 'application/x-xpinstall', 'xpl' => 'application/xproc+xml', 'xpm' => 'image/x-xpixmap', 'xpr' => 'application/vnd.is-xpr', 'xps' => 'application/vnd.ms-xpsdocument', 'xpw' => 'application/vnd.intercon.formnet', 'xslt' => 'application/xslt+xml', 'xsm' => 'application/vnd.syncml+xml', 'xspf' => 'application/xspf+xml', 'xul' => 'application/vnd.mozilla.xul+xml', 'xwd' => 'image/x-xwindowdump', 'xyz' => 'chemical/x-xyz', 'xz' => 'application/x-xz', 'yang' => 'application/yang', 'yin' => 'application/yin+xml', 'z' => 'application/x-compress', 'z1' => 'application/x-zmachine', 'zaz' => 'application/vnd.zzazz.deck+xml', 'zip' => 'application/zip', 'zir' => 'application/vnd.zul', 'zmm' => 'application/vnd.handheld-entertainment+xml', ); } $mimetype = 'application/octet-stream'; if (isset($mimetypes[strtolower($extension)])) { $mimetype = $mimetypes[strtolower($extension)]; } return $mimetype; }
php
public static function getMimetype($extension) { /** * A map of mime types and their default extensions. * * This list has been placed under the public domain by the Apache HTTPD project. * This list has been updated from upstream on 2013-04-23. * * @see http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types * * @var array */ static $mimetypes; if (empty($mimetypes)) { $mimetypes = array( '123' => 'application/vnd.lotus-1-2-3', '323' => 'text/h323', '3dml' => 'text/vnd.in3d.3dml', '3ds' => 'image/x-3ds', '3g2' => 'video/3gpp2', '3gp' => 'video/3gpp', '7z' => 'application/x-7z-compressed', 'aab' => 'application/x-authorware-bin', 'aac' => 'audio/x-aac', 'aam' => 'application/x-authorware-map', 'aas' => 'application/x-authorware-seg', 'abw' => 'application/x-abiword', 'ac' => 'application/pkix-attr-cert', 'acc' => 'application/vnd.americandynamics.acc', 'ace' => 'application/x-ace-compressed', 'acu' => 'application/vnd.acucobol', 'acx' => 'application/internet-property-stream', 'adp' => 'audio/adpcm', 'aep' => 'application/vnd.audiograph', 'afp' => 'application/vnd.ibm.modcap', 'ahead' => 'application/vnd.ahead.space', 'ai' => 'application/postscript', 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'air' => 'application/vnd.adobe.air-application-installer-package+zip', 'ait' => 'application/vnd.dvb.ait', 'ami' => 'application/vnd.amiga.ami', 'apk' => 'application/vnd.android.package-archive', 'appcache' => 'text/cache-manifest', 'application' => 'application/x-ms-application', 'apr' => 'application/vnd.lotus-approach', 'arc' => 'application/x-freearc', 'asc' => 'application/pgp-signature', 'asf' => 'video/x-ms-asf', 'aso' => 'application/vnd.accpac.simply.aso', 'asr' => 'video/x-ms-asf', 'asx' => 'video/x-ms-asf', 'atc' => 'application/vnd.acucorp', 'atom' => 'application/atom+xml', 'atomcat' => 'application/atomcat+xml', 'atomsvc' => 'application/atomsvc+xml', 'atx' => 'application/vnd.antix.game-component', 'au' => 'audio/basic', 'avi' => 'video/quicktime', 'aw' => 'application/applixware', 'axs' => 'application/olescript', 'azf' => 'application/vnd.airzip.filesecure.azf', 'azs' => 'application/vnd.airzip.filesecure.azs', 'azw' => 'application/vnd.amazon.ebook', 'bas' => 'text/plain', 'bcpio' => 'application/x-bcpio', 'bdf' => 'application/x-font-bdf', 'bdm' => 'application/vnd.syncml.dm+wbxml', 'bed' => 'application/vnd.realvnc.bed', 'bh2' => 'application/vnd.fujitsu.oasysprs', 'bin' => 'application/octet-stream', 'blb' => 'application/x-blorb', 'bmi' => 'application/vnd.bmi', 'bmp' => 'image/bmp', 'box' => 'application/vnd.previewsystems.box', 'btif' => 'image/prs.btif', 'bz' => 'application/x-bzip', 'bz2' => 'application/x-bzip2', 'c' => 'text/plain', 'c11amc' => 'application/vnd.cluetrust.cartomobile-config', 'c11amz' => 'application/vnd.cluetrust.cartomobile-config-pkg', 'c4g' => 'application/vnd.clonk.c4group', 'cab' => 'application/vnd.ms-cab-compressed', 'caf' => 'audio/x-caf', 'car' => 'application/vnd.curl.car', 'cat' => 'application/vnd.ms-pkiseccat', 'cbr' => 'application/x-cbr', 'ccxml' => 'application/ccxml+xml', 'cdbcmsg' => 'application/vnd.contact.cmsg', 'cdf' => 'application/x-cdf', 'cdkey' => 'application/vnd.mediastation.cdkey', 'cdmia' => 'application/cdmi-capability', 'cdmic' => 'application/cdmi-container', 'cdmid' => 'application/cdmi-domain', 'cdmio' => 'application/cdmi-object', 'cdmiq' => 'application/cdmi-queue', 'cdx' => 'chemical/x-cdx', 'cdxml' => 'application/vnd.chemdraw+xml', 'cdy' => 'application/vnd.cinderella', 'cer' => 'application/x-x509-ca-cert', 'cfs' => 'application/x-cfs-compressed', 'cgm' => 'image/cgm', 'chat' => 'application/x-chat', 'chm' => 'application/vnd.ms-htmlhelp', 'chrt' => 'application/vnd.kde.kchart', 'cif' => 'chemical/x-cif', 'cii' => 'application/vnd.anser-web-certificate-issue-initiation', 'cil' => 'application/vnd.ms-artgalry', 'cla' => 'application/vnd.claymore', 'class' => 'application/octet-stream', 'clkk' => 'application/vnd.crick.clicker.keyboard', 'clkp' => 'application/vnd.crick.clicker.palette', 'clkt' => 'application/vnd.crick.clicker.template', 'clkw' => 'application/vnd.crick.clicker.wordbank', 'clkx' => 'application/vnd.crick.clicker', 'clp' => 'application/x-msclip', 'cmc' => 'application/vnd.cosmocaller', 'cmdf' => 'chemical/x-cmdf', 'cml' => 'chemical/x-cml', 'cmp' => 'application/vnd.yellowriver-custom-menu', 'cmx' => 'image/x-cmx', 'cod' => 'image/cis-cod', 'cpio' => 'application/x-cpio', 'cpt' => 'application/mac-compactpro', 'crd' => 'application/x-mscardfile', 'crl' => 'application/pkix-crl', 'crt' => 'application/x-x509-ca-cert', 'cryptonote' => 'application/vnd.rig.cryptonote', 'csh' => 'application/x-csh', 'csml' => 'chemical/x-csml', 'csp' => 'application/vnd.commonspace', 'css' => 'text/css', 'csv' => 'text/comma-separated-values', 'cu' => 'application/cu-seeme', 'curl' => 'text/vnd.curl', 'cww' => 'application/prs.cww', 'dae' => 'model/vnd.collada+xml', 'daf' => 'application/vnd.mobius.daf', 'dart' => 'application/vnd.dart', 'davmount' => 'application/davmount+xml', 'dbk' => 'application/docbook+xml', 'dcr' => 'application/x-director', 'dcurl' => 'text/vnd.curl.dcurl', 'dd2' => 'application/vnd.oma.dd2+xml', 'ddd' => 'application/vnd.fujixerox.ddd', 'deb' => 'application/x-debian-package', 'der' => 'application/x-x509-ca-cert', 'dfac' => 'application/vnd.dreamfactory', 'dgc' => 'application/x-dgc-compressed', 'dir' => 'application/x-director', 'dis' => 'application/vnd.mobius.dis', 'djvu' => 'image/vnd.djvu', 'dll' => 'application/x-msdownload', 'dmg' => 'application/x-apple-diskimage', 'dms' => 'application/octet-stream', 'dna' => 'application/vnd.dna', 'doc' => 'application/msword', 'docm' => 'application/vnd.ms-word.document.macroenabled.12', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'dot' => 'application/msword', 'dotm' => 'application/vnd.ms-word.template.macroenabled.12', 'dotx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.template', 'dp' => 'application/vnd.osgi.dp', 'dpg' => 'application/vnd.dpgraph', 'dra' => 'audio/vnd.dra', 'dsc' => 'text/prs.lines.tag', 'dssc' => 'application/dssc+der', 'dtb' => 'application/x-dtbook+xml', 'dtd' => 'application/xml-dtd', 'dts' => 'audio/vnd.dts', 'dtshd' => 'audio/vnd.dts.hd', 'dvb' => 'video/vnd.dvb.file', 'dvi' => 'application/x-dvi', 'dwf' => 'model/vnd.dwf', 'dwg' => 'image/vnd.dwg', 'dxf' => 'image/vnd.dxf', 'dxp' => 'application/vnd.spotfire.dxp', 'dxr' => 'application/x-director', 'ecelp4800' => 'audio/vnd.nuera.ecelp4800', 'ecelp7470' => 'audio/vnd.nuera.ecelp7470', 'ecelp9600' => 'audio/vnd.nuera.ecelp9600', 'ecma' => 'application/ecmascript', 'edm' => 'application/vnd.novadigm.edm', 'edx' => 'application/vnd.novadigm.edx', 'efif' => 'application/vnd.picsel', 'ei6' => 'application/vnd.pg.osasli', 'eml' => 'message/rfc822', 'emma' => 'application/emma+xml', 'eol' => 'audio/vnd.digital-winds', 'eot' => 'application/vnd.ms-fontobject', 'eps' => 'application/postscript', 'epub' => 'application/epub+zip', 'es3' => 'application/vnd.eszigno3+xml', 'esa' => 'application/vnd.osgi.subsystem', 'esf' => 'application/vnd.epson.esf', 'etx' => 'text/x-setext', 'eva' => 'application/x-eva', 'evy' => 'application/envoy', 'exe' => 'application/octet-stream', 'exi' => 'application/exi', 'ext' => 'application/vnd.novadigm.ext', 'ez' => 'application/andrew-inset', 'ez2' => 'application/vnd.ezpix-album', 'ez3' => 'application/vnd.ezpix-package', 'f' => 'text/x-fortran', 'f4v' => 'video/x-f4v', 'fbs' => 'image/vnd.fastbidsheet', 'fcdt' => 'application/vnd.adobe.formscentral.fcdt', 'fcs' => 'application/vnd.isac.fcs', 'fdf' => 'application/vnd.fdf', 'fe_launch' => 'application/vnd.denovo.fcselayout-link', 'fg5' => 'application/vnd.fujitsu.oasysgp', 'fh' => 'image/x-freehand', 'fif' => 'application/fractals', 'fig' => 'application/x-xfig', 'flac' => 'audio/x-flac', 'fli' => 'video/x-fli', 'flo' => 'application/vnd.micrografx.flo', 'flr' => 'x-world/x-vrml', 'flv' => 'video/x-flv', 'flw' => 'application/vnd.kde.kivio', 'flx' => 'text/vnd.fmi.flexstor', 'fly' => 'text/vnd.fly', 'fm' => 'application/vnd.framemaker', 'fnc' => 'application/vnd.frogans.fnc', 'fpx' => 'image/vnd.fpx', 'fsc' => 'application/vnd.fsc.weblaunch', 'fst' => 'image/vnd.fst', 'ftc' => 'application/vnd.fluxtime.clip', 'fti' => 'application/vnd.anser-web-funds-transfer-initiation', 'fvt' => 'video/vnd.fvt', 'fxp' => 'application/vnd.adobe.fxp', 'fzs' => 'application/vnd.fuzzysheet', 'g2w' => 'application/vnd.geoplan', 'g3' => 'image/g3fax', 'g3w' => 'application/vnd.geospace', 'gac' => 'application/vnd.groove-account', 'gam' => 'application/x-tads', 'gbr' => 'application/rpki-ghostbusters', 'gca' => 'application/x-gca-compressed', 'gdl' => 'model/vnd.gdl', 'geo' => 'application/vnd.dynageo', 'gex' => 'application/vnd.geometry-explorer', 'ggb' => 'application/vnd.geogebra.file', 'ggt' => 'application/vnd.geogebra.tool', 'ghf' => 'application/vnd.groove-help', 'gif' => 'image/gif', 'gim' => 'application/vnd.groove-identity-message', 'gml' => 'application/gml+xml', 'gmx' => 'application/vnd.gmx', 'gnumeric' => 'application/x-gnumeric', 'gph' => 'application/vnd.flographit', 'gpx' => 'application/gpx+xml', 'gqf' => 'application/vnd.grafeq', 'gram' => 'application/srgs', 'gramps' => 'application/x-gramps-xml', 'grv' => 'application/vnd.groove-injector', 'grxml' => 'application/srgs+xml', 'gsf' => 'application/x-font-ghostscript', 'gtar' => 'application/x-gtar', 'gtm' => 'application/vnd.groove-tool-message', 'gtw' => 'model/vnd.gtw', 'gv' => 'text/vnd.graphviz', 'gxf' => 'application/gxf', 'gxt' => 'application/vnd.geonext', 'gz' => 'application/x-gzip', 'h' => 'text/plain', 'h261' => 'video/h261', 'h263' => 'video/h263', 'h264' => 'video/h264', 'hal' => 'application/vnd.hal+xml', 'hbci' => 'application/vnd.hbci', 'hdf' => 'application/x-hdf', 'hlp' => 'application/winhlp', 'hpgl' => 'application/vnd.hp-hpgl', 'hpid' => 'application/vnd.hp-hpid', 'hps' => 'application/vnd.hp-hps', 'hqx' => 'application/mac-binhex40', 'hta' => 'application/hta', 'htc' => 'text/x-component', 'htke' => 'application/vnd.kenameaapp', 'htm' => 'text/html', 'html' => 'text/html', 'htt' => 'text/webviewhtml', 'hvd' => 'application/vnd.yamaha.hv-dic', 'hvp' => 'application/vnd.yamaha.hv-voice', 'hvs' => 'application/vnd.yamaha.hv-script', 'i2g' => 'application/vnd.intergeo', 'icc' => 'application/vnd.iccprofile', 'ice' => 'x-conference/x-cooltalk', 'ico' => 'image/x-icon', 'ics' => 'text/calendar', 'ief' => 'image/ief', 'ifm' => 'application/vnd.shana.informed.formdata', 'igl' => 'application/vnd.igloader', 'igm' => 'application/vnd.insors.igm', 'igs' => 'model/iges', 'igx' => 'application/vnd.micrografx.igx', 'iif' => 'application/vnd.shana.informed.interchange', 'iii' => 'application/x-iphone', 'imp' => 'application/vnd.accpac.simply.imp', 'ims' => 'application/vnd.ms-ims', 'ink' => 'application/inkml+xml', 'ins' => 'application/x-internet-signup', 'install' => 'application/x-install-instructions', 'iota' => 'application/vnd.astraea-software.iota', 'ipfix' => 'application/ipfix', 'ipk' => 'application/vnd.shana.informed.package', 'irm' => 'application/vnd.ibm.rights-management', 'irp' => 'application/vnd.irepository.package+xml', 'iso' => 'application/x-iso9660-image', 'isp' => 'application/x-internet-signup', 'itp' => 'application/vnd.shana.informed.formtemplate', 'ivp' => 'application/vnd.immervision-ivp', 'ivu' => 'application/vnd.immervision-ivu', 'jad' => 'text/vnd.sun.j2me.app-descriptor', 'jam' => 'application/vnd.jam', 'jar' => 'application/java-archive', 'java' => 'text/x-java-source', 'jfif' => 'image/pipeg', 'jisp' => 'application/vnd.jisp', 'jlt' => 'application/vnd.hp-jlyt', 'jnlp' => 'application/x-java-jnlp-file', 'joda' => 'application/vnd.joost.joda-archive', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpgv' => 'video/jpeg', 'jpm' => 'video/jpm', 'js' => 'application/x-javascript', 'json' => 'application/json', 'jsonml' => 'application/jsonml+json', 'karbon' => 'application/vnd.kde.karbon', 'kfo' => 'application/vnd.kde.kformula', 'kia' => 'application/vnd.kidspiration', 'kml' => 'application/vnd.google-earth.kml+xml', 'kmz' => 'application/vnd.google-earth.kmz', 'kne' => 'application/vnd.kinar', 'kon' => 'application/vnd.kde.kontour', 'kpr' => 'application/vnd.kde.kpresenter', 'kpxx' => 'application/vnd.ds-keypoint', 'ksp' => 'application/vnd.kde.kspread', 'ktx' => 'image/ktx', 'ktz' => 'application/vnd.kahootz', 'kwd' => 'application/vnd.kde.kword', 'lasxml' => 'application/vnd.las.las+xml', 'latex' => 'application/x-latex', 'lbd' => 'application/vnd.llamagraphics.life-balance.desktop', 'lbe' => 'application/vnd.llamagraphics.life-balance.exchange+xml', 'les' => 'application/vnd.hhe.lesson-player', 'lha' => 'application/octet-stream', 'link66' => 'application/vnd.route66.link66+xml', 'lnk' => 'application/x-ms-shortcut', 'log' => 'text/plain', 'lostxml' => 'application/lost+xml', 'lrm' => 'application/vnd.ms-lrm', 'lsf' => 'video/x-la-asf', 'lsx' => 'video/x-la-asf', 'ltf' => 'application/vnd.frogans.ltf', 'lvp' => 'audio/vnd.lucent.voice', 'lwp' => 'application/vnd.lotus-wordpro', 'lzh' => 'application/octet-stream', 'm13' => 'application/x-msmediaview', 'm14' => 'application/x-msmediaview', 'm21' => 'application/mp21', 'm3u' => 'audio/x-mpegurl', 'm3u8' => 'application/vnd.apple.mpegurl', 'm4v' => 'video/x-m4v', 'ma' => 'application/mathematica', 'mads' => 'application/mads+xml', 'mag' => 'application/vnd.ecowin.chart', 'man' => 'application/x-troff-man', 'mathml' => 'application/mathml+xml', 'mbk' => 'application/vnd.mobius.mbk', 'mbox' => 'application/mbox', 'mc1' => 'application/vnd.medcalcdata', 'mcd' => 'application/vnd.mcd', 'mcurl' => 'text/vnd.curl.mcurl', 'mdb' => 'application/x-msaccess', 'mdi' => 'image/vnd.ms-modi', 'me' => 'application/x-troff-me', 'meta4' => 'application/metalink4+xml', 'metalink' => 'application/metalink+xml', 'mets' => 'application/mets+xml', 'mfm' => 'application/vnd.mfmp', 'mft' => 'application/rpki-manifest', 'mgp' => 'application/vnd.osgeo.mapguide.package', 'mgz' => 'application/vnd.proteus.magazine', 'mht' => 'message/rfc822', 'mhtml' => 'message/rfc822', 'mid' => 'audio/mid', 'mie' => 'application/x-mie', 'mif' => 'application/vnd.mif', 'mj2' => 'video/mj2', 'mka' => 'audio/x-matroska', 'mkv' => 'video/x-matroska', 'mlp' => 'application/vnd.dolby.mlp', 'mmd' => 'application/vnd.chipnuts.karaoke-mmd', 'mmf' => 'application/vnd.smaf', 'mmr' => 'image/vnd.fujixerox.edmics-mmr', 'mng' => 'video/x-mng', 'mny' => 'application/x-msmoney', 'mods' => 'application/mods+xml', 'mov' => 'video/quicktime', 'movie' => 'video/x-sgi-movie', 'mp2' => 'video/mpeg', 'mp3' => 'audio/mpeg', 'mp4' => 'video/mp4', 'mp4a' => 'audio/mp4', 'mp4s' => 'application/mp4', 'mpa' => 'video/mpeg', 'mpc' => 'application/vnd.mophun.certificate', 'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpga' => 'audio/mpeg', 'mpkg' => 'application/vnd.apple.installer+xml', 'mpm' => 'application/vnd.blueice.multipass', 'mpn' => 'application/vnd.mophun.application', 'mpp' => 'application/vnd.ms-project', 'mpv2' => 'video/mpeg', 'mpy' => 'application/vnd.ibm.minipay', 'mqy' => 'application/vnd.mobius.mqy', 'mrc' => 'application/marc', 'mrcx' => 'application/marcxml+xml', 'ms' => 'application/x-troff-ms', 'mscml' => 'application/mediaservercontrol+xml', 'mseed' => 'application/vnd.fdsn.mseed', 'mseq' => 'application/vnd.mseq', 'msf' => 'application/vnd.epson.msf', 'msh' => 'model/mesh', 'msl' => 'application/vnd.mobius.msl', 'msty' => 'application/vnd.muvee.style', 'mts' => 'model/vnd.mts', 'mus' => 'application/vnd.musician', 'musicxml' => 'application/vnd.recordare.musicxml+xml', 'mvb' => 'application/x-msmediaview', 'mwf' => 'application/vnd.mfer', 'mxf' => 'application/mxf', 'mxl' => 'application/vnd.recordare.musicxml', 'mxml' => 'application/xv+xml', 'mxs' => 'application/vnd.triscape.mxs', 'mxu' => 'video/vnd.mpegurl', 'n-gage' => 'application/vnd.nokia.n-gage.symbian.install', 'n3' => 'text/n3', 'nbp' => 'application/vnd.wolfram.player', 'nc' => 'application/x-netcdf', 'ncx' => 'application/x-dtbncx+xml', 'nfo' => 'text/x-nfo', 'ngdat' => 'application/vnd.nokia.n-gage.data', 'nlu' => 'application/vnd.neurolanguage.nlu', 'nml' => 'application/vnd.enliven', 'nnd' => 'application/vnd.noblenet-directory', 'nns' => 'application/vnd.noblenet-sealer', 'nnw' => 'application/vnd.noblenet-web', 'npx' => 'image/vnd.net-fpx', 'nsc' => 'application/x-conference', 'nsf' => 'application/vnd.lotus-notes', 'ntf' => 'application/vnd.nitf', 'nws' => 'message/rfc822', 'nzb' => 'application/x-nzb', 'oa2' => 'application/vnd.fujitsu.oasys2', 'oa3' => 'application/vnd.fujitsu.oasys3', 'oas' => 'application/vnd.fujitsu.oasys', 'obd' => 'application/x-msbinder', 'obj' => 'application/x-tgif', 'oda' => 'application/oda', 'odb' => 'application/vnd.oasis.opendocument.database', 'odc' => 'application/vnd.oasis.opendocument.chart', 'odf' => 'application/vnd.oasis.opendocument.formula', 'odft' => 'application/vnd.oasis.opendocument.formula-template', 'odg' => 'application/vnd.oasis.opendocument.graphics', 'odi' => 'application/vnd.oasis.opendocument.image', 'odm' => 'application/vnd.oasis.opendocument.text-master', 'odp' => 'application/vnd.oasis.opendocument.presentation', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', 'odt' => 'application/vnd.oasis.opendocument.text', 'oga' => 'audio/ogg', 'ogv' => 'video/ogg', 'ogx' => 'application/ogg', 'omdoc' => 'application/omdoc+xml', 'onetoc' => 'application/onenote', 'opf' => 'application/oebps-package+xml', 'opml' => 'text/x-opml', 'org' => 'application/vnd.lotus-organizer', 'osf' => 'application/vnd.yamaha.openscoreformat', 'osfpvg' => 'application/vnd.yamaha.openscoreformat.osfpvg+xml', 'otc' => 'application/vnd.oasis.opendocument.chart-template', 'otf' => 'application/x-font-otf', 'otg' => 'application/vnd.oasis.opendocument.graphics-template', 'oth' => 'application/vnd.oasis.opendocument.text-web', 'oti' => 'application/vnd.oasis.opendocument.image-template', 'otp' => 'application/vnd.oasis.opendocument.presentation-template', 'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template', 'ott' => 'application/vnd.oasis.opendocument.text-template', 'oxps' => 'application/oxps', 'oxt' => 'application/vnd.openofficeorg.extension', 'p' => 'text/x-pascal', 'p10' => 'application/pkcs10', 'p12' => 'application/x-pkcs12', 'p7b' => 'application/x-pkcs7-certificates', 'p7c' => 'application/x-pkcs7-mime', 'p7m' => 'application/x-pkcs7-mime', 'p7r' => 'application/x-pkcs7-certreqresp', 'p7s' => 'application/x-pkcs7-signature', 'p8' => 'application/pkcs8', 'paw' => 'application/vnd.pawaafile', 'pbd' => 'application/vnd.powerbuilder6', 'pbm' => 'image/x-portable-bitmap', 'pcap' => 'application/vnd.tcpdump.pcap', 'pcf' => 'application/x-font-pcf', 'pcl' => 'application/vnd.hp-pcl', 'pclxl' => 'application/vnd.hp-pclxl', 'pcurl' => 'application/vnd.curl.pcurl', 'pcx' => 'image/x-pcx', 'pdb' => 'application/vnd.palm', 'pdf' => 'application/pdf', 'pfa' => 'application/x-font-type1', 'pfr' => 'application/font-tdpfr', 'pfx' => 'application/x-pkcs12', 'pgm' => 'image/x-portable-graymap', 'pgn' => 'application/x-chess-pgn', 'pgp' => 'application/pgp-encrypted', 'pic' => 'image/x-pict', 'pki' => 'application/pkixcmp', 'pkipath' => 'application/pkix-pkipath', 'pko' => 'application/ynd.ms-pkipko', 'plb' => 'application/vnd.3gpp.pic-bw-large', 'plc' => 'application/vnd.mobius.plc', 'plf' => 'application/vnd.pocketlearn', 'pls' => 'application/pls+xml', 'pma' => 'application/x-perfmon', 'pmc' => 'application/x-perfmon', 'pml' => 'application/x-perfmon', 'pmr' => 'application/x-perfmon', 'pmw' => 'application/x-perfmon', 'png' => 'image/png', 'pnm' => 'image/x-portable-anymap', 'portpkg' => 'application/vnd.macports.portpkg', 'pot' => 'application/vnd.ms-powerpoint', 'potm' => 'application/vnd.ms-powerpoint.template.macroenabled.12', 'potx' => 'application/vnd.openxmlformats-officedocument.presentationml.template', 'ppam' => 'application/vnd.ms-powerpoint.addin.macroenabled.12', 'ppd' => 'application/vnd.cups-ppd', 'ppm' => 'image/x-portable-pixmap', 'pps' => 'application/vnd.ms-powerpoint', 'ppsm' => 'application/vnd.ms-powerpoint.slideshow.macroenabled.12', 'ppsx' => 'application/vnd.openxmlformats-officedocument.presentationml.slideshow', 'ppt' => 'application/vnd.ms-powerpoint', 'pptm' => 'application/vnd.ms-powerpoint.presentation.macroenabled.12', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'prc' => 'application/x-mobipocket-ebook', 'pre' => 'application/vnd.lotus-freelance', 'prf' => 'application/pics-rules', 'ps' => 'application/postscript', 'psb' => 'application/vnd.3gpp.pic-bw-small', 'psd' => 'image/photoshop', 'psf' => 'application/x-font-linux-psf', 'pskcxml' => 'application/pskc+xml', 'ptid' => 'application/vnd.pvi.ptid1', 'pub' => 'application/x-mspublisher', 'pvb' => 'application/vnd.3gpp.pic-bw-var', 'pwn' => 'application/vnd.3m.post-it-notes', 'pya' => 'audio/vnd.ms-playready.media.pya', 'pyv' => 'video/vnd.ms-playready.media.pyv', 'qam' => 'application/vnd.epson.quickanime', 'qbo' => 'application/vnd.intu.qbo', 'qfx' => 'application/vnd.intu.qfx', 'qps' => 'application/vnd.publishare-delta-tree', 'qt' => 'video/quicktime', 'qxd' => 'application/vnd.quark.quarkxpress', 'ra' => 'audio/x-pn-realaudio', 'ram' => 'audio/x-pn-realaudio', 'rar' => 'application/x-rar-compressed', 'ras' => 'image/x-cmu-raster', 'rcprofile' => 'application/vnd.ipunplugged.rcprofile', 'rdf' => 'application/rdf+xml', 'rdz' => 'application/vnd.data-vision.rdz', 'rep' => 'application/vnd.businessobjects', 'res' => 'application/x-dtbresource+xml', 'rgb' => 'image/x-rgb', 'rif' => 'application/reginfo+xml', 'rip' => 'audio/vnd.rip', 'ris' => 'application/x-research-info-systems', 'rl' => 'application/resource-lists+xml', 'rlc' => 'image/vnd.fujixerox.edmics-rlc', 'rld' => 'application/resource-lists-diff+xml', 'rm' => 'application/vnd.rn-realmedia', 'rmi' => 'audio/mid', 'rmp' => 'audio/x-pn-realaudio-plugin', 'rms' => 'application/vnd.jcp.javame.midlet-rms', 'rmvb' => 'application/vnd.rn-realmedia-vbr', 'rnc' => 'application/relax-ng-compact-syntax', 'roa' => 'application/rpki-roa', 'roff' => 'application/x-troff', 'rp9' => 'application/vnd.cloanto.rp9', 'rpss' => 'application/vnd.nokia.radio-presets', 'rpst' => 'application/vnd.nokia.radio-preset', 'rq' => 'application/sparql-query', 'rs' => 'application/rls-services+xml', 'rsd' => 'application/rsd+xml', 'rss' => 'application/rss+xml', 'rtf' => 'application/rtf', 'rtx' => 'text/richtext', 's' => 'text/x-asm', 's3m' => 'audio/s3m', 'saf' => 'application/vnd.yamaha.smaf-audio', 'sbml' => 'application/sbml+xml', 'sc' => 'application/vnd.ibm.secure-container', 'scd' => 'application/x-msschedule', 'scm' => 'application/vnd.lotus-screencam', 'scq' => 'application/scvp-cv-request', 'scs' => 'application/scvp-cv-response', 'sct' => 'text/scriptlet', 'scurl' => 'text/vnd.curl.scurl', 'sda' => 'application/vnd.stardivision.draw', 'sdc' => 'application/vnd.stardivision.calc', 'sdd' => 'application/vnd.stardivision.impress', 'sdkm' => 'application/vnd.solent.sdkm+xml', 'sdp' => 'application/sdp', 'sdw' => 'application/vnd.stardivision.writer', 'see' => 'application/vnd.seemail', 'seed' => 'application/vnd.fdsn.seed', 'sema' => 'application/vnd.sema', 'semd' => 'application/vnd.semd', 'semf' => 'application/vnd.semf', 'ser' => 'application/java-serialized-object', 'setpay' => 'application/set-payment-initiation', 'setreg' => 'application/set-registration-initiation', 'sfd-hdstx' => 'application/vnd.hydrostatix.sof-data', 'sfs' => 'application/vnd.spotfire.sfs', 'sfv' => 'text/x-sfv', 'sgi' => 'image/sgi', 'sgl' => 'application/vnd.stardivision.writer-global', 'sgml' => 'text/sgml', 'sh' => 'application/x-sh', 'shar' => 'application/x-shar', 'shf' => 'application/shf+xml', 'sid' => 'image/x-mrsid-image', 'sil' => 'audio/silk', 'sis' => 'application/vnd.symbian.install', 'sit' => 'application/x-stuffit', 'sitx' => 'application/x-stuffitx', 'skp' => 'application/vnd.koan', 'sldm' => 'application/vnd.ms-powerpoint.slide.macroenabled.12', 'sldx' => 'application/vnd.openxmlformats-officedocument.presentationml.slide', 'slt' => 'application/vnd.epson.salt', 'sm' => 'application/vnd.stepmania.stepchart', 'smf' => 'application/vnd.stardivision.math', 'smi' => 'application/smil+xml', 'smv' => 'video/x-smv', 'smzip' => 'application/vnd.stepmania.package', 'snd' => 'audio/basic', 'snf' => 'application/x-font-snf', 'spc' => 'application/x-pkcs7-certificates', 'spf' => 'application/vnd.yamaha.smaf-phrase', 'spl' => 'application/futuresplash', 'spot' => 'text/vnd.in3d.spot', 'spp' => 'application/scvp-vp-response', 'spq' => 'application/scvp-vp-request', 'sql' => 'application/x-sql', 'src' => 'application/x-wais-source', 'srt' => 'application/x-subrip', 'sru' => 'application/sru+xml', 'srx' => 'application/sparql-results+xml', 'ssdl' => 'application/ssdl+xml', 'sse' => 'application/vnd.kodak-descriptor', 'ssf' => 'application/vnd.epson.ssf', 'ssml' => 'application/ssml+xml', 'sst' => 'application/vnd.ms-pkicertstore', 'st' => 'application/vnd.sailingtracker.track', 'stc' => 'application/vnd.sun.xml.calc.template', 'std' => 'application/vnd.sun.xml.draw.template', 'stf' => 'application/vnd.wt.stf', 'sti' => 'application/vnd.sun.xml.impress.template', 'stk' => 'application/hyperstudio', 'stl' => 'application/vnd.ms-pkistl', 'stm' => 'text/html', 'str' => 'application/vnd.pg.format', 'stw' => 'application/vnd.sun.xml.writer.template', 'sub' => 'image/vnd.dvb.subtitle', 'sus' => 'application/vnd.sus-calendar', 'sv4cpio' => 'application/x-sv4cpio', 'sv4crc' => 'application/x-sv4crc', 'svc' => 'application/vnd.dvb.service', 'svd' => 'application/vnd.svd', 'svg' => 'image/svg+xml', 'swf' => 'application/x-shockwave-flash', 'swi' => 'application/vnd.aristanetworks.swi', 'sxc' => 'application/vnd.sun.xml.calc', 'sxd' => 'application/vnd.sun.xml.draw', 'sxg' => 'application/vnd.sun.xml.writer.global', 'sxi' => 'application/vnd.sun.xml.impress', 'sxm' => 'application/vnd.sun.xml.math', 'sxw' => 'application/vnd.sun.xml.writer', 't' => 'application/x-troff', 't3' => 'application/x-t3vm-image', 'taglet' => 'application/vnd.mynfc', 'tao' => 'application/vnd.tao.intent-module-archive', 'tar' => 'application/x-tar', 'tcap' => 'application/vnd.3gpp2.tcap', 'tcl' => 'application/x-tcl', 'teacher' => 'application/vnd.smart.teacher', 'tei' => 'application/tei+xml', 'tex' => 'application/x-tex', 'texi' => 'application/x-texinfo', 'texinfo' => 'application/x-texinfo', 'tfi' => 'application/thraud+xml', 'tfm' => 'application/x-tex-tfm', 'tga' => 'image/x-tga', 'tgz' => 'application/x-compressed', 'thmx' => 'application/vnd.ms-officetheme', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'tmo' => 'application/vnd.tmobile-livetv', 'torrent' => 'application/x-bittorrent', 'tpl' => 'application/vnd.groove-tool-template', 'tpt' => 'application/vnd.trid.tpt', 'tr' => 'application/x-troff', 'tra' => 'application/vnd.trueapp', 'trm' => 'application/x-msterminal', 'tsd' => 'application/timestamped-data', 'tsv' => 'text/tab-separated-values', 'ttf' => 'application/x-font-ttf', 'ttl' => 'text/turtle', 'twd' => 'application/vnd.simtech-mindmapper', 'txd' => 'application/vnd.genomatix.tuxedo', 'txf' => 'application/vnd.mobius.txf', 'txt' => 'text/plain', 'ufd' => 'application/vnd.ufdl', 'uls' => 'text/iuls', 'ulx' => 'application/x-glulx', 'umj' => 'application/vnd.umajin', 'unityweb' => 'application/vnd.unity', 'uoml' => 'application/vnd.uoml+xml', 'uri' => 'text/uri-list', 'ustar' => 'application/x-ustar', 'utz' => 'application/vnd.uiq.theme', 'uu' => 'text/x-uuencode', 'uva' => 'audio/vnd.dece.audio', 'uvf' => 'application/vnd.dece.data', 'uvh' => 'video/vnd.dece.hd', 'uvi' => 'image/vnd.dece.graphic', 'uvm' => 'video/vnd.dece.mobile', 'uvp' => 'video/vnd.dece.pd', 'uvs' => 'video/vnd.dece.sd', 'uvt' => 'application/vnd.dece.ttml+xml', 'uvu' => 'video/vnd.uvvu.mp4', 'uvv' => 'video/vnd.dece.video', 'uvx' => 'application/vnd.dece.unspecified', 'uvz' => 'application/vnd.dece.zip', 'vcard' => 'text/vcard', 'vcd' => 'application/x-cdlink', 'vcf' => 'text/x-vcard', 'vcg' => 'application/vnd.groove-vcard', 'vcs' => 'text/x-vcalendar', 'vcx' => 'application/vnd.vcx', 'vis' => 'application/vnd.visionary', 'viv' => 'video/vnd.vivo', 'vob' => 'video/x-ms-vob', 'vrml' => 'x-world/x-vrml', 'vsd' => 'application/vnd.visio', 'vsf' => 'application/vnd.vsf', 'vtu' => 'model/vnd.vtu', 'vxml' => 'application/voicexml+xml', 'wad' => 'application/x-doom', 'wav' => 'audio/x-wav', 'wax' => 'audio/x-ms-wax', 'wbmp' => 'image/vnd.wap.wbmp', 'wbs' => 'application/vnd.criticaltools.wbs+xml', 'wbxml' => 'application/vnd.wap.wbxml', 'wcm' => 'application/vnd.ms-works', 'wdb' => 'application/vnd.ms-works', 'wdp' => 'image/vnd.ms-photo', 'weba' => 'audio/webm', 'webm' => 'video/webm', 'webp' => 'image/webp', 'wg' => 'application/vnd.pmi.widget', 'wgt' => 'application/widget', 'wks' => 'application/vnd.ms-works', 'wm' => 'video/x-ms-wm', 'wma' => 'audio/x-ms-wma', 'wmd' => 'application/x-ms-wmd', 'wmf' => 'application/x-msmetafile', 'wml' => 'text/vnd.wap.wml', 'wmlc' => 'application/vnd.wap.wmlc', 'wmls' => 'text/vnd.wap.wmlscript', 'wmlsc' => 'application/vnd.wap.wmlscriptc', 'wmv' => 'video/x-ms-wmv', 'wmx' => 'video/x-ms-wmx', 'wmz' => 'application/x-ms-wmz', 'woff' => 'application/x-font-woff', 'wpd' => 'application/vnd.wordperfect', 'wpl' => 'application/vnd.ms-wpl', 'wps' => 'application/vnd.ms-works', 'wqd' => 'application/vnd.wqd', 'wri' => 'application/x-mswrite', 'wrl' => 'x-world/x-vrml', 'wrz' => 'x-world/x-vrml', 'wsdl' => 'application/wsdl+xml', 'wspolicy' => 'application/wspolicy+xml', 'wtb' => 'application/vnd.webturbo', 'wvx' => 'video/x-ms-wvx', 'x3d' => 'model/x3d+xml', 'x3db' => 'model/x3d+binary', 'x3dv' => 'model/x3d+vrml', 'xaf' => 'x-world/x-vrml', 'xaml' => 'application/xaml+xml', 'xap' => 'application/x-silverlight-app', 'xar' => 'application/vnd.xara', 'xbap' => 'application/x-ms-xbap', 'xbd' => 'application/vnd.fujixerox.docuworks.binder', 'xbm' => 'image/x-xbitmap', 'xdf' => 'application/xcap-diff+xml', 'xdm' => 'application/vnd.syncml.dm+xml', 'xdp' => 'application/vnd.adobe.xdp+xml', 'xdssc' => 'application/dssc+xml', 'xdw' => 'application/vnd.fujixerox.docuworks', 'xenc' => 'application/xenc+xml', 'xer' => 'application/patch-ops-error+xml', 'xfdf' => 'application/vnd.adobe.xfdf', 'xfdl' => 'application/vnd.xfdl', 'xhtml' => 'application/xhtml+xml', 'xif' => 'image/vnd.xiff', 'xla' => 'application/vnd.ms-excel', 'xlam' => 'application/vnd.ms-excel.addin.macroenabled.12', 'xlc' => 'application/vnd.ms-excel', 'xlf' => 'application/x-xliff+xml', 'xlm' => 'application/vnd.ms-excel', 'xls' => 'application/vnd.ms-excel', 'xlsb' => 'application/vnd.ms-excel.sheet.binary.macroenabled.12', 'xlsm' => 'application/vnd.ms-excel.sheet.macroenabled.12', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xlt' => 'application/vnd.ms-excel', 'xltm' => 'application/vnd.ms-excel.template.macroenabled.12', 'xltx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.template', 'xlw' => 'application/vnd.ms-excel', 'xm' => 'audio/xm', 'xml' => 'text/xml', 'xo' => 'application/vnd.olpc-sugar', 'xof' => 'x-world/x-vrml', 'xop' => 'application/xop+xml', 'xpi' => 'application/x-xpinstall', 'xpl' => 'application/xproc+xml', 'xpm' => 'image/x-xpixmap', 'xpr' => 'application/vnd.is-xpr', 'xps' => 'application/vnd.ms-xpsdocument', 'xpw' => 'application/vnd.intercon.formnet', 'xslt' => 'application/xslt+xml', 'xsm' => 'application/vnd.syncml+xml', 'xspf' => 'application/xspf+xml', 'xul' => 'application/vnd.mozilla.xul+xml', 'xwd' => 'image/x-xwindowdump', 'xyz' => 'chemical/x-xyz', 'xz' => 'application/x-xz', 'yang' => 'application/yang', 'yin' => 'application/yin+xml', 'z' => 'application/x-compress', 'z1' => 'application/x-zmachine', 'zaz' => 'application/vnd.zzazz.deck+xml', 'zip' => 'application/zip', 'zir' => 'application/vnd.zul', 'zmm' => 'application/vnd.handheld-entertainment+xml', ); } $mimetype = 'application/octet-stream'; if (isset($mimetypes[strtolower($extension)])) { $mimetype = $mimetypes[strtolower($extension)]; } return $mimetype; }
Returns a mime-type based on the specified {@link $extension} @param string $extension The extension to lookup @return string The mime-type of the extension specified or 'application/octet-stream'
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/FileSystemUtils.php#L91-L966
wb-crowdfusion/crowdfusion
system/core/classes/libraries/utils/FileSystemUtils.php
FileSystemUtils.createWorkingDirectory
public static function createWorkingDirectory() { $workdir = sys_get_temp_dir() . '/tmp-' . session_id() . '/'; self::recursiveMkdir($workdir, 0777); //@chmod($workdir,0777); if (!is_dir($workdir)) { throw new Exception("cannot create directory: " . $workdir); } return $workdir; }
php
public static function createWorkingDirectory() { $workdir = sys_get_temp_dir() . '/tmp-' . session_id() . '/'; self::recursiveMkdir($workdir, 0777); //@chmod($workdir,0777); if (!is_dir($workdir)) { throw new Exception("cannot create directory: " . $workdir); } return $workdir; }
Creates a unique temporary directory and returns the absolute path @return string the absolute path to the temporary directory
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/FileSystemUtils.php#L973-L985
wb-crowdfusion/crowdfusion
system/core/classes/libraries/utils/FileSystemUtils.php
FileSystemUtils.recursiveRmdir
public static function recursiveRmdir($path, $removeParent = true) { if (!file_exists($path)) return true; if (!is_dir($path)) return @unlink($path); $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST); foreach ($objects as $item) { if ($item == '.' || $item == '..') continue; if(!is_dir($item)) { if (!@unlink($item)) return false; } else { if(!@rmdir($item)) return false; } } return $removeParent ? rmdir($path) : true; }
php
public static function recursiveRmdir($path, $removeParent = true) { if (!file_exists($path)) return true; if (!is_dir($path)) return @unlink($path); $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::CHILD_FIRST); foreach ($objects as $item) { if ($item == '.' || $item == '..') continue; if(!is_dir($item)) { if (!@unlink($item)) return false; } else { if(!@rmdir($item)) return false; } } return $removeParent ? rmdir($path) : true; }
Recursively remove a directory and its contents. @param string $path The directory to remove @param boolean $removeParent If false, then remove only the contents of the directory at $path. Default: true @return boolean true on success
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/FileSystemUtils.php#L1089-L1112
wb-crowdfusion/crowdfusion
system/core/classes/libraries/utils/FileSystemUtils.php
FileSystemUtils.secureTmpname
public static function secureTmpname($dir = null, $prefix = 'tmp', $postfix = '.tmp') { // validate arguments if (!(isset ($postfix) && is_string($postfix))) return false; if (!(isset ($prefix) && is_string($prefix))) return false; if (!isset ($dir)) $dir = getcwd(); // find a temporary name $tries = 1; do { // get a known, unique temporary file name $sysFileName = tempnam($dir, $prefix); if ($sysFileName === false) return false; // tack on the extension $newFileName = $sysFileName . $postfix; if ($sysFileName == $newFileName) return $sysFileName; // move or point the created temporary file to the new filename // NOTE: these fail if the new file name exist $newFileCreated = @rename($sysFileName, $newFileName); if ($newFileCreated) return $newFileName; unlink($sysFileName); $tries++; } while ($tries <= 5); return false; }
php
public static function secureTmpname($dir = null, $prefix = 'tmp', $postfix = '.tmp') { // validate arguments if (!(isset ($postfix) && is_string($postfix))) return false; if (!(isset ($prefix) && is_string($prefix))) return false; if (!isset ($dir)) $dir = getcwd(); // find a temporary name $tries = 1; do { // get a known, unique temporary file name $sysFileName = tempnam($dir, $prefix); if ($sysFileName === false) return false; // tack on the extension $newFileName = $sysFileName . $postfix; if ($sysFileName == $newFileName) return $sysFileName; // move or point the created temporary file to the new filename // NOTE: these fail if the new file name exist $newFileCreated = @rename($sysFileName, $newFileName); if ($newFileCreated) return $newFileName; unlink($sysFileName); $tries++; } while ($tries <= 5); return false; }
Creates a temp file with a specific extension. Creating a temporary file with a specific extension is a common requirement on dynamic websites. Largely this need arises from Microsoft browsers that identify a downloaded file's mimetype based on the file's extension. No single PHP function creates a temporary filename with a specific extension, and, as has been shown, there are race conditions involved unless you use the PHP atomic primitives. I use only primitives below and exploit OS dependent behaviour to securely create a file with a specific postfix, prefix, and directory. @param string $dir Optional. The directory in which to create the new file @param string $prefix Default 'tmp'. The prefix of the generated temporary filename. @param string $postfix Default '.tmp'. The extension or postfix for the generated filename. @see http://us.php.net/manual/en/function.tempnam.php#42052 @author bishop @return string the filename of the new file
https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/libraries/utils/FileSystemUtils.php#L1138-L1174
linpax/microphp-framework
src/logger/drivers/EmailDriver.php
EmailDriver.sendMessage
public function sendMessage($level, $message) { $mail = new Message($this->from); $mail->setTo($this->to); $mail->setText(ucfirst($level).': '.$message, $this->type); /** @var ITransport $transport */ $transport = (new TransportInjector)->build(); $transport->send($mail); }
php
public function sendMessage($level, $message) { $mail = new Message($this->from); $mail->setTo($this->to); $mail->setText(ucfirst($level).': '.$message, $this->type); /** @var ITransport $transport */ $transport = (new TransportInjector)->build(); $transport->send($mail); }
Send message in log @access public @param integer $level level number @param string $message message to write @result void @throws \Micro\Base\Exception
https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/logger/drivers/EmailDriver.php#L65-L75
Talesoft/tale-http-runtime
Http/Runtime/Middleware/Queue.php
Queue.run
public function run( ServerRequestInterface $request, ResponseInterface $response ) { if ($this->running) throw new \RuntimeException( "Failed to run middleware queue: Queue is already running" ); $this->running = true; $this->save(); $next = function ( ServerRequestInterface $request, ResponseInterface $response ) use (&$next) { if (count($this->middleware) > 0) { $middleware = array_shift($this->middleware); $response = call_user_func($middleware, $request, $response, $next); if (!($response instanceof ResponseInterface)) throw new \RuntimeException( "Failed to run middleware: Middleware didn't return ". "a valid ".ResponseInterface::class." object" ); } $this->running = false; $this->restore(); return $response; }; return $next($request, $response); }
php
public function run( ServerRequestInterface $request, ResponseInterface $response ) { if ($this->running) throw new \RuntimeException( "Failed to run middleware queue: Queue is already running" ); $this->running = true; $this->save(); $next = function ( ServerRequestInterface $request, ResponseInterface $response ) use (&$next) { if (count($this->middleware) > 0) { $middleware = array_shift($this->middleware); $response = call_user_func($middleware, $request, $response, $next); if (!($response instanceof ResponseInterface)) throw new \RuntimeException( "Failed to run middleware: Middleware didn't return ". "a valid ".ResponseInterface::class." object" ); } $this->running = false; $this->restore(); return $response; }; return $next($request, $response); }
@param ServerRequestInterface $request @param ResponseInterface $response @return ResponseInterface
https://github.com/Talesoft/tale-http-runtime/blob/dba2b3a19583f8aeef041ec3b787792f491ac31d/Http/Runtime/Middleware/Queue.php#L99-L136
niels-nijens/protocol-stream
src/StreamManager.php
StreamManager.registerStream
public function registerStream(StreamInterface $stream, $replaceWrapper = false) { $protocol = $stream->getProtocol(); if ($replaceWrapper === true && in_array($protocol, stream_get_wrappers())) { stream_wrapper_unregister($protocol); } if (stream_wrapper_register($protocol, $stream->getStreamWrapperClass())) { self::$streams[$protocol] = $stream; } return $this; }
php
public function registerStream(StreamInterface $stream, $replaceWrapper = false) { $protocol = $stream->getProtocol(); if ($replaceWrapper === true && in_array($protocol, stream_get_wrappers())) { stream_wrapper_unregister($protocol); } if (stream_wrapper_register($protocol, $stream->getStreamWrapperClass())) { self::$streams[$protocol] = $stream; } return $this; }
Registers stream instance for a protocol. @param StreamInterface $stream @param bool $replaceWrapper @return self
https://github.com/niels-nijens/protocol-stream/blob/c45b8d282bbb83f2a3d17adeb1d66500c14a868c/src/StreamManager.php#L39-L51
niels-nijens/protocol-stream
src/StreamManager.php
StreamManager.unregisterStream
public function unregisterStream($protocol) { if (isset(self::$streams[$protocol])) { $result = stream_wrapper_unregister($protocol); if ($result === true) { unset(self::$streams[$protocol]); } } return $this; }
php
public function unregisterStream($protocol) { if (isset(self::$streams[$protocol])) { $result = stream_wrapper_unregister($protocol); if ($result === true) { unset(self::$streams[$protocol]); } } return $this; }
Unregisters a stream instance by protocol. @param string $protocol @return self
https://github.com/niels-nijens/protocol-stream/blob/c45b8d282bbb83f2a3d17adeb1d66500c14a868c/src/StreamManager.php#L60-L70
kkthek/diqa-util
src/Util/FileLinkUtils.php
FileLinkUtils.ImageOverlayLinkBegin
public static function ImageOverlayLinkBegin($dummy, \Title $target, &$text, &$customAttribs, &$query, &$options, &$ret) { global $wgDIQAImageOverlayWhitelist; global $wgDIQADownloadWhitelist; if (!self::isImage($target->mNamespace)) { // don't rewrite links not pointing to images return true; } $file = wfFindFile($target); if ( !$file ) { // don't rewrite links to non-existing files return true; } $ext = $file->getExtension(); if ( in_array( $ext, $wgDIQAImageOverlayWhitelist )) { // open in overlay $ret = Html::rawElement ( 'a', array ( 'href' => $file->getFullURL(), 'class' => 'imageOverlay' ), self::getDisplayTitle($target) ); return false; } if ( in_array( $ext, $wgDIQADownloadWhitelist )) { // download $ret = Html::rawElement ( 'a', array ( 'href' => $file->getFullURL() ), self::getDisplayTitle($target) ); return false; } // don't rewrite links to files with inappropriate extensions return true; }
php
public static function ImageOverlayLinkBegin($dummy, \Title $target, &$text, &$customAttribs, &$query, &$options, &$ret) { global $wgDIQAImageOverlayWhitelist; global $wgDIQADownloadWhitelist; if (!self::isImage($target->mNamespace)) { // don't rewrite links not pointing to images return true; } $file = wfFindFile($target); if ( !$file ) { // don't rewrite links to non-existing files return true; } $ext = $file->getExtension(); if ( in_array( $ext, $wgDIQAImageOverlayWhitelist )) { // open in overlay $ret = Html::rawElement ( 'a', array ( 'href' => $file->getFullURL(), 'class' => 'imageOverlay' ), self::getDisplayTitle($target) ); return false; } if ( in_array( $ext, $wgDIQADownloadWhitelist )) { // download $ret = Html::rawElement ( 'a', array ( 'href' => $file->getFullURL() ), self::getDisplayTitle($target) ); return false; } // don't rewrite links to files with inappropriate extensions return true; }
Rewrites links to images in order to open them into a overlay @param unknown $dummy @param \Title $target @param unknown $text @param unknown $customAttribs @param unknown $query @param unknown $options @param unknown $ret @return boolean
https://github.com/kkthek/diqa-util/blob/df35d16403b5dbf0f7570daded6cfa26814ae7e0/src/Util/FileLinkUtils.php#L29-L65
kkthek/diqa-util
src/Util/FileLinkUtils.php
FileLinkUtils.getDisplayTitle
private static function getDisplayTitle( Title $title ) { $pagetitle = $title->getPrefixedText(); // remove fragment $title = Title::newFromText( $pagetitle ); $values = \PageProps::getInstance()->getProperties( $title, 'displaytitle' ); $id = $title->getArticleID(); if ( array_key_exists( $id, $values ) ) { $value = $values[$id]; if ( trim( str_replace( '&#160;', '', strip_tags( $value ) ) ) !== '' ) { return $value; } } // no display title found return $title->getPrefixedText(); }
php
private static function getDisplayTitle( Title $title ) { $pagetitle = $title->getPrefixedText(); // remove fragment $title = Title::newFromText( $pagetitle ); $values = \PageProps::getInstance()->getProperties( $title, 'displaytitle' ); $id = $title->getArticleID(); if ( array_key_exists( $id, $values ) ) { $value = $values[$id]; if ( trim( str_replace( '&#160;', '', strip_tags( $value ) ) ) !== '' ) { return $value; } } // no display title found return $title->getPrefixedText(); }
adapted from DisplayTitleHook: Get displaytitle page property text. @param Title $title the Title object for the page @return string &$displaytitle to return the display title, if set
https://github.com/kkthek/diqa-util/blob/df35d16403b5dbf0f7570daded6cfa26814ae7e0/src/Util/FileLinkUtils.php#L75-L91
story75/Raptor
src/CommandProxyGenerator.php
CommandProxyGenerator.generateCommandProxy
public function generateCommandProxy($className) { $classMeta = $this->reflectionService->getClassMetaReflection($className); $proxies = []; $cachePath = $this->getRaptorCachePath(); $this->createDirectory($cachePath); $thisNode = new Variable('this'); foreach ($classMeta->getMethods() as $methodMeta) { // skip if method is not a command or an inherited command if (!stristr($methodMeta->getName(), self::COMMAND_SUFFIX) || $methodMeta->getDeclaringClass() !== $classMeta) { continue; } $proxies[] = $this->generateProxyForMethod($cachePath, $thisNode, $methodMeta, $classMeta); } return $proxies; }
php
public function generateCommandProxy($className) { $classMeta = $this->reflectionService->getClassMetaReflection($className); $proxies = []; $cachePath = $this->getRaptorCachePath(); $this->createDirectory($cachePath); $thisNode = new Variable('this'); foreach ($classMeta->getMethods() as $methodMeta) { // skip if method is not a command or an inherited command if (!stristr($methodMeta->getName(), self::COMMAND_SUFFIX) || $methodMeta->getDeclaringClass() !== $classMeta) { continue; } $proxies[] = $this->generateProxyForMethod($cachePath, $thisNode, $methodMeta, $classMeta); } return $proxies; }
Entry point to create proxies of a bonefish command class @param string $className @return array
https://github.com/story75/Raptor/blob/e62e9e56be9d7b8ad16971b628c4c77ff4448d77/src/CommandProxyGenerator.php#L95-L116
story75/Raptor
src/CommandProxyGenerator.php
CommandProxyGenerator.getCommandName
protected function getCommandName($methodMeta, $classMeta) { $nameSpaceParts = explode('\\', $classMeta->getNamespace()); $vendor = $nameSpaceParts[0]; $package = $nameSpaceParts[1]; return strtolower($vendor . ':' . $package . ':' . str_replace(self::COMMAND_SUFFIX, '', $methodMeta->getName())); }
php
protected function getCommandName($methodMeta, $classMeta) { $nameSpaceParts = explode('\\', $classMeta->getNamespace()); $vendor = $nameSpaceParts[0]; $package = $nameSpaceParts[1]; return strtolower($vendor . ':' . $package . ':' . str_replace(self::COMMAND_SUFFIX, '', $methodMeta->getName())); }
Create a unique command name @param MethodMeta $methodMeta @param ClassMeta $classMeta @return string
https://github.com/story75/Raptor/blob/e62e9e56be9d7b8ad16971b628c4c77ff4448d77/src/CommandProxyGenerator.php#L125-L132
o100ja/Rug
lib/Rug/Gateway/Database/Document/Design/ShowGateway.php
ShowGateway.show
public function show($docID = null, array $parameters = array(), $mime = CoderManager::MIME_JSON) { if (empty($docID)) { $response = $this->_send(self::METHOD_GET, $docID, $parameters); } else { $response = $this->_send(self::METHOD_POST, $docID, $parameters); } return $this->_parse($response, __FUNCTION__, $mime); }
php
public function show($docID = null, array $parameters = array(), $mime = CoderManager::MIME_JSON) { if (empty($docID)) { $response = $this->_send(self::METHOD_GET, $docID, $parameters); } else { $response = $this->_send(self::METHOD_POST, $docID, $parameters); } return $this->_parse($response, __FUNCTION__, $mime); }
*****************************************************************************************************************
https://github.com/o100ja/Rug/blob/5a6fe447b382efeb8000791d1dc89b44113b301e/lib/Rug/Gateway/Database/Document/Design/ShowGateway.php#L22-L29
naucon/Utility
src/IteratorReverseAbstract.php
IteratorReverseAbstract.next
public function next() { $this->_itemValid = true; if (!prev($this->_items)) { // no next item $this->_itemValid = false; } else { $this->_itemPosition--; } }
php
public function next() { $this->_itemValid = true; if (!prev($this->_items)) { // no next item $this->_itemValid = false; } else { $this->_itemPosition--; } }
set next item to current item @return void
https://github.com/naucon/Utility/blob/d225bb5d09d82400917f710c9d502949a66442c4/src/IteratorReverseAbstract.php#L74-L84
naucon/Utility
src/IteratorReverseAbstract.php
IteratorReverseAbstract.rewind
public function rewind() { $this->_itemValid = true; if (!end($this->_items)) { $this->_itemValid = false; } else { if (($countItems = $this->countItems()) > 0) { $this->_itemPosition = $countItems - 1; } else { $this->_itemPosition = 0; } } }
php
public function rewind() { $this->_itemValid = true; if (!end($this->_items)) { $this->_itemValid = false; } else { if (($countItems = $this->countItems()) > 0) { $this->_itemPosition = $countItems - 1; } else { $this->_itemPosition = 0; } } }
rewind to the first item @return void
https://github.com/naucon/Utility/blob/d225bb5d09d82400917f710c9d502949a66442c4/src/IteratorReverseAbstract.php#L177-L190
Weblab-nl/restclient
src/Adapters/OAuth.php
OAuth.doRequest
public function doRequest($type, $url, $params, $options = [], $headers = []) { // get access to the curl wrapper and set the bearer $curl = CURL::setBearer($this->getAccessToken()); // set the request options foreach ($options as $var => $value) { $curl->setOption($var, $value); } // set the header values foreach ($headers as $var => $value) { $curl->setHeader($var, $value); } // execute the request $result = $curl->$type($url, $params); // done, return the result return $result; }
php
public function doRequest($type, $url, $params, $options = [], $headers = []) { // get access to the curl wrapper and set the bearer $curl = CURL::setBearer($this->getAccessToken()); // set the request options foreach ($options as $var => $value) { $curl->setOption($var, $value); } // set the header values foreach ($headers as $var => $value) { $curl->setHeader($var, $value); } // execute the request $result = $curl->$type($url, $params); // done, return the result return $result; }
Make a request to the API @param string $type @param string $url @param mixed $params @param array $options @param array $headers @return mixed @throws \Exception
https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/Adapters/OAuth.php#L167-L186
Weblab-nl/restclient
src/Adapters/OAuth.php
OAuth.getAccessToken
private function getAccessToken($expired = false) { // Refresh the access token if force refresh or the expiretime has passed if ($expired || isset($this->expireTime) && $this->expireTime <= time()) { // If there is no refresh token throw exception if (!isset($this->refreshToken)) { throw new OAuthException('Token expired but no refresh token found'); } $this->refreshAccessToken(); } // If there no access token fetch one else if (!$expired && !isset($this->accessToken)) { $this->fetchAccessToken(); } // If there still is no access token at this point. Throw exception if (!isset($this->accessToken)) { throw new OAuthException('No access token found'); } return $this->accessToken; }
php
private function getAccessToken($expired = false) { // Refresh the access token if force refresh or the expiretime has passed if ($expired || isset($this->expireTime) && $this->expireTime <= time()) { // If there is no refresh token throw exception if (!isset($this->refreshToken)) { throw new OAuthException('Token expired but no refresh token found'); } $this->refreshAccessToken(); } // If there no access token fetch one else if (!$expired && !isset($this->accessToken)) { $this->fetchAccessToken(); } // If there still is no access token at this point. Throw exception if (!isset($this->accessToken)) { throw new OAuthException('No access token found'); } return $this->accessToken; }
Get the access token @param bool $expired Pass true if you want to force refresh the access token @return string @throws \Exception
https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/Adapters/OAuth.php#L195-L216
Weblab-nl/restclient
src/Adapters/OAuth.php
OAuth.fetchAccessToken
private function fetchAccessToken() { // Setup the params $params = [ 'client_id' => $this->clientID, 'client_secret' => $this->secret, 'grant_type' => 'authorization_code', 'code' => $this->requestToken ]; if (isset($this->redirectURI)) { $params['redirect_uri'] = $this->redirectURI; } // Parse the cURL result $this->parseAccessToken(CURL::post($this->url, $params)); }
php
private function fetchAccessToken() { // Setup the params $params = [ 'client_id' => $this->clientID, 'client_secret' => $this->secret, 'grant_type' => 'authorization_code', 'code' => $this->requestToken ]; if (isset($this->redirectURI)) { $params['redirect_uri'] = $this->redirectURI; } // Parse the cURL result $this->parseAccessToken(CURL::post($this->url, $params)); }
Does a cURL to request a new access token @throws \Exception
https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/Adapters/OAuth.php#L223-L238
Weblab-nl/restclient
src/Adapters/OAuth.php
OAuth.refreshAccessToken
private function refreshAccessToken() { // Setup the params $params = [ 'client_id' => $this->clientID, 'client_secret' => $this->secret, 'grant_type' => 'refresh_token', 'refresh_token' => $this->refreshToken ]; // Parse the cURL result $this->parseAccessToken(CURL::post($this->url, $params)); }
php
private function refreshAccessToken() { // Setup the params $params = [ 'client_id' => $this->clientID, 'client_secret' => $this->secret, 'grant_type' => 'refresh_token', 'refresh_token' => $this->refreshToken ]; // Parse the cURL result $this->parseAccessToken(CURL::post($this->url, $params)); }
Refreshes the access token @throws \Exception
https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/Adapters/OAuth.php#L245-L256
Weblab-nl/restclient
src/Adapters/OAuth.php
OAuth.parseAccessToken
private function parseAccessToken(Result $result) { // If unexpected status code throw exception if ($result->getStatus() !== 200) { throw new OAuthException('Something went wrong requesting access token'); } // Get the data form the result object $data = $result->getResult(); // Store the data if available if (isset($data['access_token'])) { $this->setAccessToken($data['access_token']); } if (isset($data['refresh_token'])) { $this->setRefreshToken($data['refresh_token']); } if (isset($data['expire_time'])) { $this->setExpireTime(time() + $data['expire_time']); } }
php
private function parseAccessToken(Result $result) { // If unexpected status code throw exception if ($result->getStatus() !== 200) { throw new OAuthException('Something went wrong requesting access token'); } // Get the data form the result object $data = $result->getResult(); // Store the data if available if (isset($data['access_token'])) { $this->setAccessToken($data['access_token']); } if (isset($data['refresh_token'])) { $this->setRefreshToken($data['refresh_token']); } if (isset($data['expire_time'])) { $this->setExpireTime(time() + $data['expire_time']); } }
Parse the cURL result of the fetching / refreshing access token requests @param Result $result @throws \Exception
https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/Adapters/OAuth.php#L264-L283
Weblab-nl/restclient
src/Adapters/OAuth.php
OAuth.processRequestToken
public function processRequestToken($token) { // Setup the params $params = [ 'client_id' => $this->clientID, 'client_secret' => $this->secret, 'code' => $token, 'grant_type' => 'authorization_code', 'redirect_uri' => $this->redirectURI ]; // Parse the cURL result return CURL::post($this->url, $params); }
php
public function processRequestToken($token) { // Setup the params $params = [ 'client_id' => $this->clientID, 'client_secret' => $this->secret, 'code' => $token, 'grant_type' => 'authorization_code', 'redirect_uri' => $this->redirectURI ]; // Parse the cURL result return CURL::post($this->url, $params); }
Convert a request token to an access token @param string $token @return mixed
https://github.com/Weblab-nl/restclient/blob/6bc4e7890580b7b31e78032e40be5a67122b0dd0/src/Adapters/OAuth.php#L291-L303
Dev4Media/ngnfeed-ebay
src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php
GetSetMethodNormalizer.setCallbacks
public function setCallbacks(array $callbacks) { foreach ($callbacks as $attribute => $callback) { if (!is_callable($callback)) { throw new \InvalidArgumentException(sprintf('The given callback for attribute "%s" is not callable.', $attribute)); } } $this->callbacks = $callbacks; }
php
public function setCallbacks(array $callbacks) { foreach ($callbacks as $attribute => $callback) { if (!is_callable($callback)) { throw new \InvalidArgumentException(sprintf('The given callback for attribute "%s" is not callable.', $attribute)); } } $this->callbacks = $callbacks; }
Set normalization callbacks @param array $callbacks help normalize the result @throws InvalidArgumentException if a non-callable callback is set
https://github.com/Dev4Media/ngnfeed-ebay/blob/fb9652e30c7e4823a4e4dd571f41c8839953e72c/src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php#L30-L38
Dev4Media/ngnfeed-ebay
src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php
GetSetMethodNormalizer.normalize
public function normalize($object, $format = null, array $context = array()) { $reflectionObject = new \ReflectionObject($object); $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC); $virtualFieldsCollection = $object->getVirtualFieldsCollection(); $attributes = array(); foreach ($reflectionMethods as $method) { if ($this->isGetMethod($method)) { $attributeName = substr($method->name, 3); if (in_array($attributeName, $this->ignoredAttributes)) { continue; } $attributeValue = $method->invoke($object); if ($this->ignoreNullAttributes && is_null($attributeValue) ) { continue; } if (array_key_exists($attributeName, $this->callbacks)) { $attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue); } if (null !== $attributeValue && !is_scalar($attributeValue)) { $attributeValue = $this->serializer->normalize($attributeValue, $format); } $attributes[$attributeName] = $attributeValue; } if (count($virtualFieldsCollection) > 0) { foreach($virtualFieldsCollection as $field => $virtualFieldValues) { foreach( $virtualFieldValues as $index => $attributeValue) { $attributeName = ucfirst($field).'___'.$index; if (null !== $attributeValue && !is_scalar($attributeValue)) { $attributeValue = $this->serializer->normalize($attributeValue, $format); } $attributes[$attributeName] = $attributeValue; } } } } return $attributes; }
php
public function normalize($object, $format = null, array $context = array()) { $reflectionObject = new \ReflectionObject($object); $reflectionMethods = $reflectionObject->getMethods(\ReflectionMethod::IS_PUBLIC); $virtualFieldsCollection = $object->getVirtualFieldsCollection(); $attributes = array(); foreach ($reflectionMethods as $method) { if ($this->isGetMethod($method)) { $attributeName = substr($method->name, 3); if (in_array($attributeName, $this->ignoredAttributes)) { continue; } $attributeValue = $method->invoke($object); if ($this->ignoreNullAttributes && is_null($attributeValue) ) { continue; } if (array_key_exists($attributeName, $this->callbacks)) { $attributeValue = call_user_func($this->callbacks[$attributeName], $attributeValue); } if (null !== $attributeValue && !is_scalar($attributeValue)) { $attributeValue = $this->serializer->normalize($attributeValue, $format); } $attributes[$attributeName] = $attributeValue; } if (count($virtualFieldsCollection) > 0) { foreach($virtualFieldsCollection as $field => $virtualFieldValues) { foreach( $virtualFieldValues as $index => $attributeValue) { $attributeName = ucfirst($field).'___'.$index; if (null !== $attributeValue && !is_scalar($attributeValue)) { $attributeValue = $this->serializer->normalize($attributeValue, $format); } $attributes[$attributeName] = $attributeValue; } } } } return $attributes; }
{@inheritdoc}
https://github.com/Dev4Media/ngnfeed-ebay/blob/fb9652e30c7e4823a4e4dd571f41c8839953e72c/src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php#L68-L118
Dev4Media/ngnfeed-ebay
src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php
GetSetMethodNormalizer.denormalize
public function denormalize($data, $class, $format = null, array $context = array()) { $reflectionClass = new \ReflectionClass($class); $constructor = $reflectionClass->getConstructor(); if ($constructor) { $constructorParameters = $constructor->getParameters(); $params = array(); foreach ($constructorParameters as $constructorParameter) { $paramName = lcfirst($this->formatAttribute($constructorParameter->name)); if (isset($data[$paramName])) { $params[] = $data[$paramName]; // don't run set for a parameter passed to the constructor unset($data[$paramName]); } elseif (!$constructorParameter->isOptional()) { throw new RuntimeException( 'Cannot create an instance of '.$class. ' from serialized data because its constructor requires '. 'parameter "'.$constructorParameter->name. '" to be present.'); } } $object = $reflectionClass->newInstanceArgs($params); } else { $object = new $class; } foreach ($data as $attribute => $value) { $setter = 'set'.$this->formatAttribute($attribute); if (method_exists($object, $setter)) { $object->$setter($value); } else if(is_callable(array( $object, $setter))) { $object->$setter($value); } } return $object; }
php
public function denormalize($data, $class, $format = null, array $context = array()) { $reflectionClass = new \ReflectionClass($class); $constructor = $reflectionClass->getConstructor(); if ($constructor) { $constructorParameters = $constructor->getParameters(); $params = array(); foreach ($constructorParameters as $constructorParameter) { $paramName = lcfirst($this->formatAttribute($constructorParameter->name)); if (isset($data[$paramName])) { $params[] = $data[$paramName]; // don't run set for a parameter passed to the constructor unset($data[$paramName]); } elseif (!$constructorParameter->isOptional()) { throw new RuntimeException( 'Cannot create an instance of '.$class. ' from serialized data because its constructor requires '. 'parameter "'.$constructorParameter->name. '" to be present.'); } } $object = $reflectionClass->newInstanceArgs($params); } else { $object = new $class; } foreach ($data as $attribute => $value) { $setter = 'set'.$this->formatAttribute($attribute); if (method_exists($object, $setter)) { $object->$setter($value); } else if(is_callable(array( $object, $setter))) { $object->$setter($value); } } return $object; }
{@inheritdoc}
https://github.com/Dev4Media/ngnfeed-ebay/blob/fb9652e30c7e4823a4e4dd571f41c8839953e72c/src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php#L123-L164
Dev4Media/ngnfeed-ebay
src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php
GetSetMethodNormalizer.formatAttribute
protected function formatAttribute($attributeName) { if (in_array($attributeName, $this->camelizedAttributes)) { return preg_replace_callback( '/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); }, $attributeName ); } return $attributeName; }
php
protected function formatAttribute($attributeName) { if (in_array($attributeName, $this->camelizedAttributes)) { return preg_replace_callback( '/(^|_|\.)+(.)/', function ($match) { return ('.' === $match[1] ? '_' : '').strtoupper($match[2]); }, $attributeName ); } return $attributeName; }
Format attribute name to access parameters or methods As option, if attribute name is found on camelizedAttributes array returns attribute name in camelcase format @param string $attributeName @return string
https://github.com/Dev4Media/ngnfeed-ebay/blob/fb9652e30c7e4823a4e4dd571f41c8839953e72c/src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php#L174-L185
Dev4Media/ngnfeed-ebay
src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php
GetSetMethodNormalizer.supportsNormalization
public function supportsNormalization($data, $format = null) { return is_object($data) && $this->supports(get_class($data)); }
php
public function supportsNormalization($data, $format = null) { return is_object($data) && $this->supports(get_class($data)); }
{@inheritDoc}
https://github.com/Dev4Media/ngnfeed-ebay/blob/fb9652e30c7e4823a4e4dd571f41c8839953e72c/src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php#L190-L193
Dev4Media/ngnfeed-ebay
src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php
GetSetMethodNormalizer.supports
private function supports($class) { $class = new \ReflectionClass($class); $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { if ($this->isGetMethod($method)) { return true; } } return false; }
php
private function supports($class) { $class = new \ReflectionClass($class); $methods = $class->getMethods(\ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { if ($this->isGetMethod($method)) { return true; } } return false; }
Checks if the given class has any get{Property} method. @param string $class @return Boolean
https://github.com/Dev4Media/ngnfeed-ebay/blob/fb9652e30c7e4823a4e4dd571f41c8839953e72c/src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php#L210-L221
Dev4Media/ngnfeed-ebay
src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php
GetSetMethodNormalizer.isGetMethod
private function isGetMethod(\ReflectionMethod $method) { return ( 0 === strpos($method->name, 'get') && 3 < strlen($method->name) && 0 === $method->getNumberOfRequiredParameters() ); }
php
private function isGetMethod(\ReflectionMethod $method) { return ( 0 === strpos($method->name, 'get') && 3 < strlen($method->name) && 0 === $method->getNumberOfRequiredParameters() ); }
Checks if a method's name is get.* and can be called without parameters. @param \ReflectionMethod $method the method to check @return Boolean whether the method is a getter.
https://github.com/Dev4Media/ngnfeed-ebay/blob/fb9652e30c7e4823a4e4dd571f41c8839953e72c/src/D4m/NgnFeed/Ebay/Serializer/Normalizer/GetSetMethodNormalizer.php#L230-L237
realboard/DBInstance
src/Realboard/Component/Database/DBInstance/Service/RestServiceHandler.php
RestServiceHandler.getResult
public function getResult(array $config = array(), $sql = '', $limit = 0, $offset = 0, $single = false, $key = null, $responseType = null) { $data = array( 'error' => true, 'message' => 'Authentication failed nor No config available ', ); $this->rawConfig = $config; if ($this->authentication->getSecurity()->isValid($key) && !empty($config)) { try { $di = new DBInstance($config); if (count($this->connectionStrings)) { $di->preventNoLocalDriver(); foreach ($this->connectionStrings as $driverName => $connString) { $di->registerConnectionString($connString, $driverName); } } if (!$di->hasError()) { if ($single) { $di->setSingleQuery($sql); } else { $di->setQuery($sql); } $di->getQuery()->forceLimit(intval($limit ? $limit : 500)); $di->getQuery()->forceOffset(intval($offset)); $di->run(); if (!$di->hasError()) { $data['response'] = $di->getResult(DBInstance::FETCH_ARRAY); } } } catch (\Exception $e) { $di->getQuery()->getError()->setMessage($e->getMessage()); } $data['error'] = $di->hasError(); $data['message'] = (string) $di->getErrorMessage(); } if (null !== $this->logDir) { $logPath = rtrim($this->logDir,'/\\') . '/log-' . microtime(true) . '.json'; if (!defined('JSON_PRETTY_PRINT')) { define('JSON_PRETTY_PRINT', 1); } file_put_contents($logPath, json_encode($data, JSON_PRETTY_PRINT)); } if ($responseType == 'json') { return array('json' => json_encode($data)); } return $data; }
php
public function getResult(array $config = array(), $sql = '', $limit = 0, $offset = 0, $single = false, $key = null, $responseType = null) { $data = array( 'error' => true, 'message' => 'Authentication failed nor No config available ', ); $this->rawConfig = $config; if ($this->authentication->getSecurity()->isValid($key) && !empty($config)) { try { $di = new DBInstance($config); if (count($this->connectionStrings)) { $di->preventNoLocalDriver(); foreach ($this->connectionStrings as $driverName => $connString) { $di->registerConnectionString($connString, $driverName); } } if (!$di->hasError()) { if ($single) { $di->setSingleQuery($sql); } else { $di->setQuery($sql); } $di->getQuery()->forceLimit(intval($limit ? $limit : 500)); $di->getQuery()->forceOffset(intval($offset)); $di->run(); if (!$di->hasError()) { $data['response'] = $di->getResult(DBInstance::FETCH_ARRAY); } } } catch (\Exception $e) { $di->getQuery()->getError()->setMessage($e->getMessage()); } $data['error'] = $di->hasError(); $data['message'] = (string) $di->getErrorMessage(); } if (null !== $this->logDir) { $logPath = rtrim($this->logDir,'/\\') . '/log-' . microtime(true) . '.json'; if (!defined('JSON_PRETTY_PRINT')) { define('JSON_PRETTY_PRINT', 1); } file_put_contents($logPath, json_encode($data, JSON_PRETTY_PRINT)); } if ($responseType == 'json') { return array('json' => json_encode($data)); } return $data; }
Get DBInstance Response Data. @param array $config @param string $sql @param int $limit @param int $offset @param bool $single @param string $key @param string $responseType @return array
https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Service/RestServiceHandler.php#L62-L115
realboard/DBInstance
src/Realboard/Component/Database/DBInstance/Service/RestServiceHandler.php
RestServiceHandler.getServerVersion
public function getServerVersion() { $di = new DBInstance($this->rawConfig); $version = $di->getServerVersion(); unset($di); return array( 'version' => $version, ); }
php
public function getServerVersion() { $di = new DBInstance($this->rawConfig); $version = $di->getServerVersion(); unset($di); return array( 'version' => $version, ); }
Get DBInstance database version. @return array
https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Service/RestServiceHandler.php#L132-L141
ekyna/Resource
Configuration/ConfigurationFactory.php
ConfigurationFactory.getOptionsResolver
private function getOptionsResolver() { // TODO Use/Merge ConfigurationBuilder options resolver. if (!$this->optionsResolver) { $resolver = new OptionsResolver(); $resolver ->setRequired(['namespace', 'id', 'classes']) ->setDefaults([ 'name' => function (Options $options) { return Inflector::camelize($options['id']); }, 'parent_id' => null, 'event' => null, 'templates' => null, 'translation' => null, ]) ->setAllowedTypes('namespace', 'string') ->setAllowedTypes('id', 'string') ->setAllowedTypes('name', 'string') ->setAllowedTypes('parent_id', ['null', 'string']) ->setAllowedTypes('classes', 'array') ->setAllowedTypes('event', ['null', 'string', 'array']) ->setAllowedTypes('templates', ['null', 'string', 'array']) ->setAllowedTypes('translation', ['null', 'array']); // Classes option $classesResolver = new OptionsResolver(); $classesResolver ->setRequired(['entity']) ->setDefaults([ 'form_type' => null, // @TODO/WARNING no longer required (behavior refactoring) 'repository' => null, ]) ->setAllowedTypes('entity', 'string') ->setAllowedTypes('repository', ['null', 'string']) ->setAllowedTypes('form_type', ['null', 'string']); // @TODO/WARNING no longer required (behavior refactoring) $resolver ->setNormalizer('classes', function (Options $options, $value) use ($classesResolver) { foreach ($value as $class) { if ($class && !class_exists($class)) { throw new InvalidOptionsException(sprintf("Class '%s' does not exists.", $class)); } } $entity = $value['entity']; if (null !== $options['translation'] && !is_subclass_of($entity, TranslatableInterface::class)) { throw new InvalidOptionsException(sprintf( "Class '%s' must implements '%s'.", $entity, TranslatableInterface::class)); } $repository = array_key_exists('repository', $value) ? $value['repository'] : null; if (null === $repository) { $value['repository'] = null !== $options['translation'] ? TranslatableResourceRepository::class : ResourceRepository::class; } elseif (null !== $options['translation']) { if (!is_subclass_of($repository, TranslatableResourceRepositoryInterface::class)) { throw new InvalidOptionsException(sprintf( "Class '%s' must implements '%s'.", $repository, TranslatableResourceRepositoryInterface::class )); } } else { if (!is_subclass_of($repository, ResourceRepositoryInterface::class)) { throw new InvalidOptionsException(sprintf( "Class '%s' must implements '%s'.", $repository, ResourceRepositoryInterface::class )); } } return $classesResolver->resolve($value); }); // Translation option $translationResolver = new OptionsResolver(); $translationResolver ->setRequired(['entity', 'fields']) ->setDefault('repository', null) ->setAllowedTypes('entity', 'string') ->setAllowedTypes('fields', 'array') ->setAllowedTypes('repository', ['null', 'string']) ->setAllowedValues('entity', function ($class) { if (!class_exists($class)) { throw new InvalidOptionsException(sprintf("Class '%s' does not exists.", $class)); } if (!is_subclass_of($class, TranslationInterface::class)) { throw new InvalidOptionsException(sprintf("Class '%s' must implements '%s'.", $class, TranslationInterface::class)); } return true; }) ->setAllowedValues('fields', function ($fields) { if (empty($fields)) { throw new InvalidOptionsException("Translatable fields cannot be empty."); } return true; }) ->setAllowedValues('repository', function ($class) { if (null !== $class && !class_exists($class)) { throw new InvalidOptionsException(sprintf("Class '%s' does not exists.", $class)); } return true; }); /** @noinspection PhpUnusedParameterInspection */ $resolver->setNormalizer('translation', function (Options $options, $value) use ($translationResolver) { if (is_array($value)) { return $translationResolver->resolve($value); } return $value; }); // Event option $eventResolver = new OptionsResolver(); $eventResolver ->setRequired(['class']) ->setDefaults([ 'class' => $this->defaultEventClass, 'priority' => 0, ]) ->setAllowedTypes('class', 'string') ->setAllowedTypes('priority', 'int'); /** @noinspection PhpUnusedParameterInspection */ $resolver->setNormalizer('event', function (Options $options, $value) use ($eventResolver) { if (is_string($value)) { $value = ['class' => $value]; } $value = $eventResolver->resolve((array)$value); if (!is_subclass_of($value['class'], ResourceEventInterface::class)) { throw new InvalidOptionsException(sprintf( "Class '%s' must implements '%s'.", $value['class'], ResourceEventInterface::class )); } return $value; }); // Templates option /** @noinspection PhpUnusedParameterInspection */ $resolver->setNormalizer('templates', function (Options $options, $value) { return $this->buildTemplateList($value); }); $this->optionsResolver = $resolver; } return $this->optionsResolver; }
php
private function getOptionsResolver() { // TODO Use/Merge ConfigurationBuilder options resolver. if (!$this->optionsResolver) { $resolver = new OptionsResolver(); $resolver ->setRequired(['namespace', 'id', 'classes']) ->setDefaults([ 'name' => function (Options $options) { return Inflector::camelize($options['id']); }, 'parent_id' => null, 'event' => null, 'templates' => null, 'translation' => null, ]) ->setAllowedTypes('namespace', 'string') ->setAllowedTypes('id', 'string') ->setAllowedTypes('name', 'string') ->setAllowedTypes('parent_id', ['null', 'string']) ->setAllowedTypes('classes', 'array') ->setAllowedTypes('event', ['null', 'string', 'array']) ->setAllowedTypes('templates', ['null', 'string', 'array']) ->setAllowedTypes('translation', ['null', 'array']); // Classes option $classesResolver = new OptionsResolver(); $classesResolver ->setRequired(['entity']) ->setDefaults([ 'form_type' => null, // @TODO/WARNING no longer required (behavior refactoring) 'repository' => null, ]) ->setAllowedTypes('entity', 'string') ->setAllowedTypes('repository', ['null', 'string']) ->setAllowedTypes('form_type', ['null', 'string']); // @TODO/WARNING no longer required (behavior refactoring) $resolver ->setNormalizer('classes', function (Options $options, $value) use ($classesResolver) { foreach ($value as $class) { if ($class && !class_exists($class)) { throw new InvalidOptionsException(sprintf("Class '%s' does not exists.", $class)); } } $entity = $value['entity']; if (null !== $options['translation'] && !is_subclass_of($entity, TranslatableInterface::class)) { throw new InvalidOptionsException(sprintf( "Class '%s' must implements '%s'.", $entity, TranslatableInterface::class)); } $repository = array_key_exists('repository', $value) ? $value['repository'] : null; if (null === $repository) { $value['repository'] = null !== $options['translation'] ? TranslatableResourceRepository::class : ResourceRepository::class; } elseif (null !== $options['translation']) { if (!is_subclass_of($repository, TranslatableResourceRepositoryInterface::class)) { throw new InvalidOptionsException(sprintf( "Class '%s' must implements '%s'.", $repository, TranslatableResourceRepositoryInterface::class )); } } else { if (!is_subclass_of($repository, ResourceRepositoryInterface::class)) { throw new InvalidOptionsException(sprintf( "Class '%s' must implements '%s'.", $repository, ResourceRepositoryInterface::class )); } } return $classesResolver->resolve($value); }); // Translation option $translationResolver = new OptionsResolver(); $translationResolver ->setRequired(['entity', 'fields']) ->setDefault('repository', null) ->setAllowedTypes('entity', 'string') ->setAllowedTypes('fields', 'array') ->setAllowedTypes('repository', ['null', 'string']) ->setAllowedValues('entity', function ($class) { if (!class_exists($class)) { throw new InvalidOptionsException(sprintf("Class '%s' does not exists.", $class)); } if (!is_subclass_of($class, TranslationInterface::class)) { throw new InvalidOptionsException(sprintf("Class '%s' must implements '%s'.", $class, TranslationInterface::class)); } return true; }) ->setAllowedValues('fields', function ($fields) { if (empty($fields)) { throw new InvalidOptionsException("Translatable fields cannot be empty."); } return true; }) ->setAllowedValues('repository', function ($class) { if (null !== $class && !class_exists($class)) { throw new InvalidOptionsException(sprintf("Class '%s' does not exists.", $class)); } return true; }); /** @noinspection PhpUnusedParameterInspection */ $resolver->setNormalizer('translation', function (Options $options, $value) use ($translationResolver) { if (is_array($value)) { return $translationResolver->resolve($value); } return $value; }); // Event option $eventResolver = new OptionsResolver(); $eventResolver ->setRequired(['class']) ->setDefaults([ 'class' => $this->defaultEventClass, 'priority' => 0, ]) ->setAllowedTypes('class', 'string') ->setAllowedTypes('priority', 'int'); /** @noinspection PhpUnusedParameterInspection */ $resolver->setNormalizer('event', function (Options $options, $value) use ($eventResolver) { if (is_string($value)) { $value = ['class' => $value]; } $value = $eventResolver->resolve((array)$value); if (!is_subclass_of($value['class'], ResourceEventInterface::class)) { throw new InvalidOptionsException(sprintf( "Class '%s' must implements '%s'.", $value['class'], ResourceEventInterface::class )); } return $value; }); // Templates option /** @noinspection PhpUnusedParameterInspection */ $resolver->setNormalizer('templates', function (Options $options, $value) { return $this->buildTemplateList($value); }); $this->optionsResolver = $resolver; } return $this->optionsResolver; }
Returns the config options resolver. @return OptionsResolver
https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Configuration/ConfigurationFactory.php#L85-L252
nilstr/Flash-Messages-for-Anax-MVC
src/FlashMessages/FlashMessages.php
FlashMessages.message
public function message($type, $message) { if ( $this->session->has('flashMessages') ) { $flashMessages = $this->session->get('flashMessages'); $flashMessages[] = ['type' => $type, 'message' => $message]; $this->session->set('flashMessages', $flashMessages); } else { $this->session->set('flashMessages', [['type' => $type, 'message' => $message]]); } }
php
public function message($type, $message) { if ( $this->session->has('flashMessages') ) { $flashMessages = $this->session->get('flashMessages'); $flashMessages[] = ['type' => $type, 'message' => $message]; $this->session->set('flashMessages', $flashMessages); } else { $this->session->set('flashMessages', [['type' => $type, 'message' => $message]]); } }
Saves the message in the session. @param string $type The type of flash message. Will be the class of the output div. @param string $message The message to output. @return void
https://github.com/nilstr/Flash-Messages-for-Anax-MVC/blob/7129241dd72a91eb0fcfe0e1d25144692334230c/src/FlashMessages/FlashMessages.php#L66-L75
nilstr/Flash-Messages-for-Anax-MVC
src/FlashMessages/FlashMessages.php
FlashMessages.output
public function output() { if ( $this->session->has('flashMessages') ) { $flashMessages = $this->session->get('flashMessages'); $this->session->set('flashMessages', []); $html = null; foreach ($flashMessages as $message) { $html .= "<div class='". $message['type'] . "'>" . $message['message'] . "</div>"; } return $html; } }
php
public function output() { if ( $this->session->has('flashMessages') ) { $flashMessages = $this->session->get('flashMessages'); $this->session->set('flashMessages', []); $html = null; foreach ($flashMessages as $message) { $html .= "<div class='". $message['type'] . "'>" . $message['message'] . "</div>"; } return $html; } }
Gets and resets the flash messages from session and building html. @return string The html for the output.
https://github.com/nilstr/Flash-Messages-for-Anax-MVC/blob/7129241dd72a91eb0fcfe0e1d25144692334230c/src/FlashMessages/FlashMessages.php#L83-L94
anime-db/catalog-bundle
src/Entity/Widget/Item.php
Item.setType
public function setType(Type $type) { if ($this->type !== $type) { $this->type = $type; $type->setItem($this); } return $this; }
php
public function setType(Type $type) { if ($this->type !== $type) { $this->type = $type; $type->setItem($this); } return $this; }
Set type. @param Type $type @return Item
https://github.com/anime-db/catalog-bundle/blob/631b6f92a654e91bee84f46218c52cf42bdb8606/src/Entity/Widget/Item.php#L175-L183
mamasu/mama-log
src/log/Log.php
Log.elapsedTime
public function elapsedTime() { $currentTime = microtime(true); if ($this->startTime === null) { $this->startTime = $currentTime; $this->finishTime = $currentTime; } else { $this->finishTime = $currentTime; $this->elapsedTimeFromStart = $currentTime - $this->startTime; } }
php
public function elapsedTime() { $currentTime = microtime(true); if ($this->startTime === null) { $this->startTime = $currentTime; $this->finishTime = $currentTime; } else { $this->finishTime = $currentTime; $this->elapsedTimeFromStart = $currentTime - $this->startTime; } }
Calculated the different time of the log line.
https://github.com/mamasu/mama-log/blob/86431258fc42a3f364af2d959382d43c2a2dd3a0/src/log/Log.php#L54-L63
jmfeurprier/perf-caching
lib/perf/Caching/CacheClient.php
CacheClient.store
public function store($id, $data, $maxLifetimeSeconds = null) { $creationTimestamp = time(); if (null === $maxLifetimeSeconds) { $expirationTimestamp = null; } else { $expirationTimestamp = ($creationTimestamp + (int) $maxLifetimeSeconds); } $entry = new CacheEntry($id, $data, $creationTimestamp, $expirationTimestamp); $this->storage->store($entry); return $this; }
php
public function store($id, $data, $maxLifetimeSeconds = null) { $creationTimestamp = time(); if (null === $maxLifetimeSeconds) { $expirationTimestamp = null; } else { $expirationTimestamp = ($creationTimestamp + (int) $maxLifetimeSeconds); } $entry = new CacheEntry($id, $data, $creationTimestamp, $expirationTimestamp); $this->storage->store($entry); return $this; }
Attempts to store provided content into cache. Cache file will hold creation and expiration timestamps, and provided content. @param mixed $id Cache item unique identifier (ex: 123). @param mixed $data Content to be added to cache. @param null|int $maxLifetimeSeconds (Optional) duration in seconds after which cache file will be considered expired. @return CacheClient Fluent return. @throws \RuntimeException
https://github.com/jmfeurprier/perf-caching/blob/16cf61dae3aa4d6dcb8722e14760934457087173/lib/perf/Caching/CacheClient.php#L62-L77
jmfeurprier/perf-caching
lib/perf/Caching/CacheClient.php
CacheClient.tryFetch
public function tryFetch($id, $maxLifetimeSeconds = null) { $entry = $this->storage->tryFetch($id); if (null === $entry) { return null; } if (null !== $maxLifetimeSeconds) { if (($this->nowTimestamp - $entry->creationTimestamp()) > $maxLifetimeSeconds) { return null; } } if (null !== $entry->expirationTimestamp()) { if ($this->nowTimestamp > $entry->expirationTimestamp()) { return null; } } return $entry->data(); }
php
public function tryFetch($id, $maxLifetimeSeconds = null) { $entry = $this->storage->tryFetch($id); if (null === $entry) { return null; } if (null !== $maxLifetimeSeconds) { if (($this->nowTimestamp - $entry->creationTimestamp()) > $maxLifetimeSeconds) { return null; } } if (null !== $entry->expirationTimestamp()) { if ($this->nowTimestamp > $entry->expirationTimestamp()) { return null; } } return $entry->data(); }
Attempts to retrieve data from cache. @param mixed $id Cache entry unique identifier (ex: "123"). @param null|int $maxLifetimeSeconds Duration in seconds. If provided, will bypass expiration timestamp in cache file, using creation timestamp + provided duration to check whether cached content has expired or not. @return null|mixed
https://github.com/jmfeurprier/perf-caching/blob/16cf61dae3aa4d6dcb8722e14760934457087173/lib/perf/Caching/CacheClient.php#L88-L109
fond-of/spryker-company-business-units-rest-api
src/FondOfSpryker/Zed/CompanyBusinessUnitsRestApi/Persistence/CompanyBusinessUnitsRestApiRepository.php
CompanyBusinessUnitsRestApiRepository.findCompanyBusinessUnitByExternalReference
public function findCompanyBusinessUnitByExternalReference(string $externalReference): ?CompanyBusinessUnitTransfer { $spyCompanyBusinessUnit = $this->getFactory() ->getCompanyBusinessUnitPropelQuery() ->filterByExternalReference($externalReference) ->findOne(); if ($spyCompanyBusinessUnit === null) { return null; } $companyBusinessUnit = (new CompanyBusinessUnitTransfer())->fromArray( $spyCompanyBusinessUnit->toArray(), true ); return $companyBusinessUnit; }
php
public function findCompanyBusinessUnitByExternalReference(string $externalReference): ?CompanyBusinessUnitTransfer { $spyCompanyBusinessUnit = $this->getFactory() ->getCompanyBusinessUnitPropelQuery() ->filterByExternalReference($externalReference) ->findOne(); if ($spyCompanyBusinessUnit === null) { return null; } $companyBusinessUnit = (new CompanyBusinessUnitTransfer())->fromArray( $spyCompanyBusinessUnit->toArray(), true ); return $companyBusinessUnit; }
Specification: - Retrieve a company business unit by CompanyBusinessUnitTransfer::externalReference in the transfer @api @param string $externalReference @return \Generated\Shared\Transfer\CompanyBusinessUnitTransfer|null
https://github.com/fond-of/spryker-company-business-units-rest-api/blob/7393d6064f2618a71f092ecf8c4e62fb73f504bb/src/FondOfSpryker/Zed/CompanyBusinessUnitsRestApi/Persistence/CompanyBusinessUnitsRestApiRepository.php#L23-L40
voodoo-rocks/yii2-upload
src/Base64Source.php
Base64Source.create
public static function create($base64) { if (($pos = strpos($base64, self::STOPPER)) !== false) { $base64 = substr($base64, $pos + strlen(self::STOPPER)); } return \Yii::createObject([ 'class' => self::className(), 'base64' => $base64 ]); }
php
public static function create($base64) { if (($pos = strpos($base64, self::STOPPER)) !== false) { $base64 = substr($base64, $pos + strlen(self::STOPPER)); } return \Yii::createObject([ 'class' => self::className(), 'base64' => $base64 ]); }
@param $base64 @return $this @throws \yii\base\InvalidConfigException
https://github.com/voodoo-rocks/yii2-upload/blob/45aa514ca766e32e7ee8cdb47da30d61dedd1a3a/src/Base64Source.php#L22-L32
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.compareFiles
public function compareFiles($file1, $file2) { if ($file1 == $file2) { return 0; } $sortOrder = $this->getFileSortOrder(); if (!isset($sortOrder[$file1]) && !isset($sortOrder[$file2])) { return 0; } if (isset($sortOrder[$file1]) && !isset($sortOrder[$file2])) { return -1; } if (!isset($sortOrder[$file1]) && isset($sortOrder[$file2])) { return 1; } if ($sortOrder[$file1] < $sortOrder[$file2]) { return -1; } if ($sortOrder[$file1] > $sortOrder[$file2]) { return 1; } return 0; }
php
public function compareFiles($file1, $file2) { if ($file1 == $file2) { return 0; } $sortOrder = $this->getFileSortOrder(); if (!isset($sortOrder[$file1]) && !isset($sortOrder[$file2])) { return 0; } if (isset($sortOrder[$file1]) && !isset($sortOrder[$file2])) { return -1; } if (!isset($sortOrder[$file1]) && isset($sortOrder[$file2])) { return 1; } if ($sortOrder[$file1] < $sortOrder[$file2]) { return -1; } if ($sortOrder[$file1] > $sortOrder[$file2]) { return 1; } return 0; }
{{{ compareFiles()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L79-L108
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.isMinified
public function isMinified($file) { $minified = false; if (!$minified) { $fileInfo = $this->getFileInfo(); if (isset($fileInfo[$file])) { $minified = $fileInfo[$file]['Minify']; } } if (!$minified) { $combinesInfo = $this->getCombinesInfo(); if (isset($combinesInfo[$file])) { $minified = $combinesInfo[$file]['Minify']; } } return $minified; }
php
public function isMinified($file) { $minified = false; if (!$minified) { $fileInfo = $this->getFileInfo(); if (isset($fileInfo[$file])) { $minified = $fileInfo[$file]['Minify']; } } if (!$minified) { $combinesInfo = $this->getCombinesInfo(); if (isset($combinesInfo[$file])) { $minified = $combinesInfo[$file]['Minify']; } } return $minified; }
{{{ isMinified()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L113-L132
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getConflicts
public function getConflicts(array $files) { $conflicts = array(); // flip so the files are hash keys to speed lookups $files = array_flip($files); $fileInfo = $this->getFileInfo(); foreach ($files as $file => $garbage) { if (array_key_exists($file, $fileInfo)) { $fileFileInfo = $fileInfo[$file]; if (isset($fileFileInfo['Conflicts']) && is_array($fileFileInfo['Conflicts']) ) { foreach ($fileFileInfo['Conflicts'] as $conflict) { if (array_key_exists($conflict, $files)) { if (!isset($conflicts[$file])) { $conflicts[$file] = array(); } $conflicts[$file][] = $conflict; } } } } } return $conflicts; }
php
public function getConflicts(array $files) { $conflicts = array(); // flip so the files are hash keys to speed lookups $files = array_flip($files); $fileInfo = $this->getFileInfo(); foreach ($files as $file => $garbage) { if (array_key_exists($file, $fileInfo)) { $fileFileInfo = $fileInfo[$file]; if (isset($fileFileInfo['Conflicts']) && is_array($fileFileInfo['Conflicts']) ) { foreach ($fileFileInfo['Conflicts'] as $conflict) { if (array_key_exists($conflict, $files)) { if (!isset($conflicts[$file])) { $conflicts[$file] = array(); } $conflicts[$file][] = $conflict; } } } } } return $conflicts; }
{{{ getConflicts()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L137-L165
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getCombines
public function getCombines(array $files) { $superset = $files; $combinedSet = array(); $combines = array(); $combinesInfo = $this->getCombinesInfo(); foreach ($combinesInfo as $combine => $combineInfo) { $combinedFiles = array_keys($combineInfo['Includes']); // check if combine does not conflict with already added combines // and if combine contains one or more files in the required file // list if (count(array_intersect($combinedFiles, $combinedSet)) === 0 && count(array_intersect($combinedFiles, $files)) > 0 ) { $potentialSuperset = array_merge($superset, $combinedFiles); // make sure combining will not introduce conflicts if (count($this->getConflicts($potentialSuperset)) === 0) { $combinedSet = array_merge($combinedSet, $combinedFiles); $superset = $potentialSuperset; $combines[] = $combine; } } } // remove dupes from superset caused by combines $superset = array_unique($superset); // exclude contents of combined sets from file list foreach ($combines as $combine) { $files = array_diff( $files, array_keys($combinesInfo[$combine]['Includes']) ); $files[] = $combine; } $info = array( // 'combines' contains the combined files that will be included. 'combines' => $combines, // 'superset' contains all original files plus files pulled in by // the combined sets. The content of these files will be included. 'superset' => $superset, // 'files' contains combined files and files in the original set // that did not fit in any combined set. These are the actual files // that will be included. 'files' => $files, ); return $info; }
php
public function getCombines(array $files) { $superset = $files; $combinedSet = array(); $combines = array(); $combinesInfo = $this->getCombinesInfo(); foreach ($combinesInfo as $combine => $combineInfo) { $combinedFiles = array_keys($combineInfo['Includes']); // check if combine does not conflict with already added combines // and if combine contains one or more files in the required file // list if (count(array_intersect($combinedFiles, $combinedSet)) === 0 && count(array_intersect($combinedFiles, $files)) > 0 ) { $potentialSuperset = array_merge($superset, $combinedFiles); // make sure combining will not introduce conflicts if (count($this->getConflicts($potentialSuperset)) === 0) { $combinedSet = array_merge($combinedSet, $combinedFiles); $superset = $potentialSuperset; $combines[] = $combine; } } } // remove dupes from superset caused by combines $superset = array_unique($superset); // exclude contents of combined sets from file list foreach ($combines as $combine) { $files = array_diff( $files, array_keys($combinesInfo[$combine]['Includes']) ); $files[] = $combine; } $info = array( // 'combines' contains the combined files that will be included. 'combines' => $combines, // 'superset' contains all original files plus files pulled in by // the combined sets. The content of these files will be included. 'superset' => $superset, // 'files' contains combined files and files in the original set // that did not fit in any combined set. These are the actual files // that will be included. 'files' => $files, ); return $info; }
{{{ getCombines()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L170-L226
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getFileSortOrder
public function getFileSortOrder() { $fileSortOrder = $this->getCachedValue('fileSortOrder'); if ($fileSortOrder === false) { $data = $this->dataProvider->getData(); $fileSortOrder = array(); // get flat list of file dependencies for each file $dependsInfo = $this->getDependsInfo(); // build into graph $graph = new Concentrate_Graph(); $nodes = array(); foreach ($dependsInfo as $file => $dependencies) { if (!isset($nodes[$file])) { $nodes[$file] = new Concentrate_Graph_Node( $graph, $file ); } foreach ($dependencies as $dependentFile) { if (!isset($nodes[$dependentFile])) { $nodes[$dependentFile] = new Concentrate_Graph_Node( $graph, $dependentFile ); } } } foreach ($dependsInfo as $file => $dependencies) { foreach ($dependencies as $dependentFile) { $nodes[$file]->connectTo($nodes[$dependentFile]); } } // add combines to graph $combinesInfo = $this->getCombinesInfo(); foreach ($combinesInfo as $combine => $combineInfo) { $files = $combineInfo['Includes']; if (!isset($nodes[$combine])) { $nodes[$combine] = new Concentrate_Graph_Node( $graph, $combine ); } // get combine dependencies as difference of union of // dependencies of contained files and combined set $depends = array(); foreach ($files as $file => $info) { if (isset($dependsInfo[$file])) { $depends = array_merge( $dependsInfo[$file], $depends ); } } $depends = array_diff($depends, array_keys($files)); foreach ($depends as $depend) { $nodes[$combine]->connectTo($nodes[$depend]); } // add combine as dependency of all contained files foreach ($files as $file => $info) { if (!isset($nodes[$file])) { $nodes[$file] = new Concentrate_Graph_Node( $graph, $file ); } $nodes[$file]->connectTo($nodes[$combine]); } } $sorter = new Concentrate_Graph_TopologicalSorter(); try { $sortedNodes = $sorter->sort($graph); } catch (Concentrate_CyclicDependencyException $e) { throw new Concentrate_CyclicDependencyException( 'File dependency order can not be determined because ' . 'file dependencies contain one more more cycles. ' . 'There is likely a typo in the provides section of one ' . 'or more YAML files.' ); } $fileSortOrder = array(); foreach ($sortedNodes as $node) { $fileSortOrder[] = $node->getData(); } // Flip the sorted array so it is indexed by file with values // being the relative sort order. $fileSortOrder = array_flip($fileSortOrder); $this->setCachedValue('fileSortOrder', $fileSortOrder); } return $fileSortOrder; }
php
public function getFileSortOrder() { $fileSortOrder = $this->getCachedValue('fileSortOrder'); if ($fileSortOrder === false) { $data = $this->dataProvider->getData(); $fileSortOrder = array(); // get flat list of file dependencies for each file $dependsInfo = $this->getDependsInfo(); // build into graph $graph = new Concentrate_Graph(); $nodes = array(); foreach ($dependsInfo as $file => $dependencies) { if (!isset($nodes[$file])) { $nodes[$file] = new Concentrate_Graph_Node( $graph, $file ); } foreach ($dependencies as $dependentFile) { if (!isset($nodes[$dependentFile])) { $nodes[$dependentFile] = new Concentrate_Graph_Node( $graph, $dependentFile ); } } } foreach ($dependsInfo as $file => $dependencies) { foreach ($dependencies as $dependentFile) { $nodes[$file]->connectTo($nodes[$dependentFile]); } } // add combines to graph $combinesInfo = $this->getCombinesInfo(); foreach ($combinesInfo as $combine => $combineInfo) { $files = $combineInfo['Includes']; if (!isset($nodes[$combine])) { $nodes[$combine] = new Concentrate_Graph_Node( $graph, $combine ); } // get combine dependencies as difference of union of // dependencies of contained files and combined set $depends = array(); foreach ($files as $file => $info) { if (isset($dependsInfo[$file])) { $depends = array_merge( $dependsInfo[$file], $depends ); } } $depends = array_diff($depends, array_keys($files)); foreach ($depends as $depend) { $nodes[$combine]->connectTo($nodes[$depend]); } // add combine as dependency of all contained files foreach ($files as $file => $info) { if (!isset($nodes[$file])) { $nodes[$file] = new Concentrate_Graph_Node( $graph, $file ); } $nodes[$file]->connectTo($nodes[$combine]); } } $sorter = new Concentrate_Graph_TopologicalSorter(); try { $sortedNodes = $sorter->sort($graph); } catch (Concentrate_CyclicDependencyException $e) { throw new Concentrate_CyclicDependencyException( 'File dependency order can not be determined because ' . 'file dependencies contain one more more cycles. ' . 'There is likely a typo in the provides section of one ' . 'or more YAML files.' ); } $fileSortOrder = array(); foreach ($sortedNodes as $node) { $fileSortOrder[] = $node->getData(); } // Flip the sorted array so it is indexed by file with values // being the relative sort order. $fileSortOrder = array_flip($fileSortOrder); $this->setCachedValue('fileSortOrder', $fileSortOrder); } return $fileSortOrder; }
{{{ getFileSortOrder()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L231-L334
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getFileInfo
public function getFileInfo() { $fileInfo = $this->getCachedValue('fileInfo'); if ($fileInfo === false) { $data = $this->dataProvider->getData(); $fileInfo = array(); foreach ($data as $packageId => $info) { $provides = $this->getProvidesForPackage($packageId); foreach ($provides as $file => $providesInfo) { if (isset($providesInfo['Minify'])) { $providesInfo['Minify'] = $this->parseBoolean( $providesInfo['Minify'] ); } else { $providesInfo['Minify'] = true; } $providesInfo['Package'] = $packageId; $fileInfo[$file] = $providesInfo; } } $this->setCachedValue('fileInfo', $fileInfo); } return $fileInfo; }
php
public function getFileInfo() { $fileInfo = $this->getCachedValue('fileInfo'); if ($fileInfo === false) { $data = $this->dataProvider->getData(); $fileInfo = array(); foreach ($data as $packageId => $info) { $provides = $this->getProvidesForPackage($packageId); foreach ($provides as $file => $providesInfo) { if (isset($providesInfo['Minify'])) { $providesInfo['Minify'] = $this->parseBoolean( $providesInfo['Minify'] ); } else { $providesInfo['Minify'] = true; } $providesInfo['Package'] = $packageId; $fileInfo[$file] = $providesInfo; } } $this->setCachedValue('fileInfo', $fileInfo); } return $fileInfo; }
{{{ getFileInfo()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L339-L367
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getCombinesInfo
public function getCombinesInfo() { $combinesInfo = $this->getCachedValue('combinesInfo'); if ($combinesInfo === false) { $data = $this->dataProvider->getData(); $fileInfo = $this->getFileInfo(); $combinesInfo = array(); foreach ($data as $packageId => $info) { $combines = $this->getCombinesForPackage($packageId); foreach ($combines as $combine => $combineInfo) { // create entry for the combine set if it does // not exist if (!isset($combinesInfo[$combine])) { $combinesInfo[$combine] = array( 'Includes' => array(), 'Minify' => true, ); } // set additional attributes if (isset($combineInfo['Minify'])) { $combinesInfo[$combine]['Minify'] = $this->parseBoolean( $combinesInfo['Minify'] ); } // add entries to the set if (isset($combineInfo['Includes']) && is_array($combineInfo['Includes']) ) { foreach ($combineInfo['Includes'] as $file) { $combinesInfo[$combine]['Includes'][$file] = array( 'explicit' => true ); } } } } foreach ($combinesInfo as $combine => $info) { // Check for dependencies of each set that are not in the set. // If a missing dependency also has a dependency on an file in // the set, add it to the set. $combinesInfo[$combine]['Includes'] = $this->getImplicitCombinedFiles( $info['Includes'], $info['Includes'] ); // minification of combine depends on minification of included // files foreach (array_keys($info['Includes']) as $file) { if (isset($fileInfo[$file]) && !$fileInfo[$file]['Minify'] ) { $combinesInfo[$combine]['Minify'] = false; break; } } } // sort largest sets first uasort($combinesInfo, array($this, 'compareCombines')); $this->setCachedValue('combinesInfo', $combinesInfo); } return $combinesInfo; }
php
public function getCombinesInfo() { $combinesInfo = $this->getCachedValue('combinesInfo'); if ($combinesInfo === false) { $data = $this->dataProvider->getData(); $fileInfo = $this->getFileInfo(); $combinesInfo = array(); foreach ($data as $packageId => $info) { $combines = $this->getCombinesForPackage($packageId); foreach ($combines as $combine => $combineInfo) { // create entry for the combine set if it does // not exist if (!isset($combinesInfo[$combine])) { $combinesInfo[$combine] = array( 'Includes' => array(), 'Minify' => true, ); } // set additional attributes if (isset($combineInfo['Minify'])) { $combinesInfo[$combine]['Minify'] = $this->parseBoolean( $combinesInfo['Minify'] ); } // add entries to the set if (isset($combineInfo['Includes']) && is_array($combineInfo['Includes']) ) { foreach ($combineInfo['Includes'] as $file) { $combinesInfo[$combine]['Includes'][$file] = array( 'explicit' => true ); } } } } foreach ($combinesInfo as $combine => $info) { // Check for dependencies of each set that are not in the set. // If a missing dependency also has a dependency on an file in // the set, add it to the set. $combinesInfo[$combine]['Includes'] = $this->getImplicitCombinedFiles( $info['Includes'], $info['Includes'] ); // minification of combine depends on minification of included // files foreach (array_keys($info['Includes']) as $file) { if (isset($fileInfo[$file]) && !$fileInfo[$file]['Minify'] ) { $combinesInfo[$combine]['Minify'] = false; break; } } } // sort largest sets first uasort($combinesInfo, array($this, 'compareCombines')); $this->setCachedValue('combinesInfo', $combinesInfo); } return $combinesInfo; }
{{{ getCombinesInfo()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L372-L444
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getDependsInfo
public function getDependsInfo() { $dependsInfo = $this->getCachedValue('dependsInfo'); if ($dependsInfo === false) { $data = $this->dataProvider->getData(); $dependsInfo = array(); foreach ($this->getPackageSortOrder() as $packageId => $order) { if (!isset($data[$packageId])) { continue; } $provides = $this->getProvidesForPackage($packageId); foreach ($provides as $file => $fileInfo) { if (!isset($dependsInfo[$file])) { $dependsInfo[$file] = array(); } if (isset($fileInfo['Depends'])) { $dependsInfo[$file] = array_merge( $dependsInfo[$file], $fileInfo['Depends'] ); } // TODO: some day we could treat optional-depends // differently if (isset($fileInfo['OptionalDepends'])) { $dependsInfo[$file] = array_merge( $dependsInfo[$file], $fileInfo['OptionalDepends'] ); } } } $this->setCachedValue('dependsInfo', $dependsInfo); } return $dependsInfo; }
php
public function getDependsInfo() { $dependsInfo = $this->getCachedValue('dependsInfo'); if ($dependsInfo === false) { $data = $this->dataProvider->getData(); $dependsInfo = array(); foreach ($this->getPackageSortOrder() as $packageId => $order) { if (!isset($data[$packageId])) { continue; } $provides = $this->getProvidesForPackage($packageId); foreach ($provides as $file => $fileInfo) { if (!isset($dependsInfo[$file])) { $dependsInfo[$file] = array(); } if (isset($fileInfo['Depends'])) { $dependsInfo[$file] = array_merge( $dependsInfo[$file], $fileInfo['Depends'] ); } // TODO: some day we could treat optional-depends // differently if (isset($fileInfo['OptionalDepends'])) { $dependsInfo[$file] = array_merge( $dependsInfo[$file], $fileInfo['OptionalDepends'] ); } } } $this->setCachedValue('dependsInfo', $dependsInfo); } return $dependsInfo; }
Gets a flat list of file dependencies for each file @return array
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L454-L494
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getImplicitCombinedFiles
protected function getImplicitCombinedFiles( array $filesToCheck, array $files ) { $dependsInfo = $this->getDependsInfo(); // get depends $depends = array(); foreach ($filesToCheck as $file => $info) { if (isset($dependsInfo[$file])) { $depends = array_merge($depends, $dependsInfo[$file]); } } // get depends not in the set $depends = array_diff($depends, array_keys($files)); // check sub-dependencies to see any are in the set $implicitFiles = array(); foreach ($depends as $file) { if (isset($dependsInfo[$file])) { $subDepends = array_intersect( $dependsInfo[$file], array_keys($files) ); if (count($subDepends) > 0 && !isset($implicitFiles[$file]) ) { $files[$file] = array( 'explicit' => false, ); $implicitFiles[$file] = $file; } } } // if implicit files were added, check those if (count($implicitFiles) > 0) { $files = $this->getImplicitCombinedFiles( $implicitFiles, $files ); } return $files; }
php
protected function getImplicitCombinedFiles( array $filesToCheck, array $files ) { $dependsInfo = $this->getDependsInfo(); // get depends $depends = array(); foreach ($filesToCheck as $file => $info) { if (isset($dependsInfo[$file])) { $depends = array_merge($depends, $dependsInfo[$file]); } } // get depends not in the set $depends = array_diff($depends, array_keys($files)); // check sub-dependencies to see any are in the set $implicitFiles = array(); foreach ($depends as $file) { if (isset($dependsInfo[$file])) { $subDepends = array_intersect( $dependsInfo[$file], array_keys($files) ); if (count($subDepends) > 0 && !isset($implicitFiles[$file]) ) { $files[$file] = array( 'explicit' => false, ); $implicitFiles[$file] = $file; } } } // if implicit files were added, check those if (count($implicitFiles) > 0) { $files = $this->getImplicitCombinedFiles( $implicitFiles, $files ); } return $files; }
{{{ getImplicitCombinedFiles()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L499-L544
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getPackageSortOrder
protected function getPackageSortOrder() { $packageSortOrder = $this->getCachedValue('packageSortOrder'); if ($packageSortOrder === false) { $data = $this->dataProvider->getData(); // get flat list of package dependencies for each package $packageDependencies = array(); foreach ($data as $packageId => $info) { if (!isset($packageDependencies[$packageId])) { $packageDependencies[$packageId] = array(); } $depends = $this->getDependsForPackage($packageId); $packageDependencies[$packageId] = array_merge( $packageDependencies[$packageId], $depends ); } // build into a graph $graph = new Concentrate_Graph(); $nodes = array(); foreach ($packageDependencies as $packageId => $dependencies) { if ($packageId === '__site__') { // special package '__site__' is not sorted with other // packages. It gets put at the end. continue; } if (!isset($nodes[$packageId])) { $nodes[$packageId] = new Concentrate_Graph_Node( $graph, $packageId ); } foreach ($dependencies as $dependentPackageId) { if ($dependentPackageId === '__site__') { // special package '__site__' is not sorted with other // packages. It gets put at the end. continue; } if (!isset($nodes[$dependentPackageId])) { $nodes[$dependentPackageId] = new Concentrate_Graph_Node( $graph, $dependentPackageId ); } } } foreach ($packageDependencies as $packageId => $dependencies) { foreach ($dependencies as $dependentPackageId) { $nodes[$packageId]->connectTo($nodes[$dependentPackageId]); } } $sorter = new Concentrate_Graph_TopologicalSorter(); try { $sortedNodes = $sorter->sort($graph); } catch (Concentrate_CyclicDependencyException $e) { throw new Concentrate_CyclicDependencyException( 'Package dependency order can not be determined because ' . 'package dependencies contain one more more cycles. ' . 'There is likely a typo in the package dependency ' . 'section of one or more YAML files.' ); } $order = array(); foreach ($sortedNodes as $node) { $order[] = $node->getData(); } // special package __site__ is always counted last by default $order[] = '__site__'; // return indexed by package id, with values being the relative // sort order $packageSortOrder = array_flip($order); $this->setCachedValue('packageSortOrder', $packageSortOrder); } return $packageSortOrder; }
php
protected function getPackageSortOrder() { $packageSortOrder = $this->getCachedValue('packageSortOrder'); if ($packageSortOrder === false) { $data = $this->dataProvider->getData(); // get flat list of package dependencies for each package $packageDependencies = array(); foreach ($data as $packageId => $info) { if (!isset($packageDependencies[$packageId])) { $packageDependencies[$packageId] = array(); } $depends = $this->getDependsForPackage($packageId); $packageDependencies[$packageId] = array_merge( $packageDependencies[$packageId], $depends ); } // build into a graph $graph = new Concentrate_Graph(); $nodes = array(); foreach ($packageDependencies as $packageId => $dependencies) { if ($packageId === '__site__') { // special package '__site__' is not sorted with other // packages. It gets put at the end. continue; } if (!isset($nodes[$packageId])) { $nodes[$packageId] = new Concentrate_Graph_Node( $graph, $packageId ); } foreach ($dependencies as $dependentPackageId) { if ($dependentPackageId === '__site__') { // special package '__site__' is not sorted with other // packages. It gets put at the end. continue; } if (!isset($nodes[$dependentPackageId])) { $nodes[$dependentPackageId] = new Concentrate_Graph_Node( $graph, $dependentPackageId ); } } } foreach ($packageDependencies as $packageId => $dependencies) { foreach ($dependencies as $dependentPackageId) { $nodes[$packageId]->connectTo($nodes[$dependentPackageId]); } } $sorter = new Concentrate_Graph_TopologicalSorter(); try { $sortedNodes = $sorter->sort($graph); } catch (Concentrate_CyclicDependencyException $e) { throw new Concentrate_CyclicDependencyException( 'Package dependency order can not be determined because ' . 'package dependencies contain one more more cycles. ' . 'There is likely a typo in the package dependency ' . 'section of one or more YAML files.' ); } $order = array(); foreach ($sortedNodes as $node) { $order[] = $node->getData(); } // special package __site__ is always counted last by default $order[] = '__site__'; // return indexed by package id, with values being the relative // sort order $packageSortOrder = array_flip($order); $this->setCachedValue('packageSortOrder', $packageSortOrder); } return $packageSortOrder; }
{{{ getPackageSortOrder()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L549-L633
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getProvidesForPackage
protected function getProvidesForPackage($packageId) { $cacheKey = 'packageProvides.'.$packageId; $packageProvides = $this->getCachedValue($cacheKey); if ($packageProvides === false) { $packageProvides = array(); $data = $this->dataProvider->getData(); if (isset($data[$packageId])) { $info = $data[$packageId]; if (isset($info['Provides']) && is_array($info['Provides'])) { $packageProvides = $info['Provides']; } } $this->setCachedValue($cacheKey, $packageProvides); } return $packageProvides; }
php
protected function getProvidesForPackage($packageId) { $cacheKey = 'packageProvides.'.$packageId; $packageProvides = $this->getCachedValue($cacheKey); if ($packageProvides === false) { $packageProvides = array(); $data = $this->dataProvider->getData(); if (isset($data[$packageId])) { $info = $data[$packageId]; if (isset($info['Provides']) && is_array($info['Provides'])) { $packageProvides = $info['Provides']; } } $this->setCachedValue($cacheKey, $packageProvides); } return $packageProvides; }
{{{ getProvidesForPackage()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L638-L657
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getDependsForPackage
protected function getDependsForPackage($packageId) { $cacheKey = 'packageDepends.'.$packageId; $packageDepends = $this->getCachedValue($cacheKey); if ($packageDepends === false) { $packageDepends = array(); $data = $this->dataProvider->getData(); if (isset($data[$packageId])) { $info = $data[$packageId]; if (isset($info['Depends']) && is_array($info['Depends'])) { $packageDepends = $info['Depends']; } } $this->setCachedValue($cacheKey, $packageDepends); } return $packageDepends; }
php
protected function getDependsForPackage($packageId) { $cacheKey = 'packageDepends.'.$packageId; $packageDepends = $this->getCachedValue($cacheKey); if ($packageDepends === false) { $packageDepends = array(); $data = $this->dataProvider->getData(); if (isset($data[$packageId])) { $info = $data[$packageId]; if (isset($info['Depends']) && is_array($info['Depends'])) { $packageDepends = $info['Depends']; } } $this->setCachedValue($cacheKey, $packageDepends); } return $packageDepends; }
{{{ getDependsForPackage()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L662-L681
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getCombinesForPackage
protected function getCombinesForPackage($packageId) { $cacheKey = 'packageCombines.'.$packageId; $packageCombines = $this->getCachedValue($cacheKey); if ($packageCombines === false) { $packageCombines = array(); $data = $this->dataProvider->getData(); if (isset($data[$packageId])) { $info = $data[$packageId]; if (isset($info['Combines']) && is_array($info['Combines'])) { $packageCombines = $info['Combines']; } } $this->setCachedValue($cacheKey, $packageCombines); } return $packageCombines; }
php
protected function getCombinesForPackage($packageId) { $cacheKey = 'packageCombines.'.$packageId; $packageCombines = $this->getCachedValue($cacheKey); if ($packageCombines === false) { $packageCombines = array(); $data = $this->dataProvider->getData(); if (isset($data[$packageId])) { $info = $data[$packageId]; if (isset($info['Combines']) && is_array($info['Combines'])) { $packageCombines = $info['Combines']; } } $this->setCachedValue($cacheKey, $packageCombines); } return $packageCombines; }
{{{ getCombinesForPackage()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L686-L705
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.compareCombines
protected function compareCombines(array $combine1, array $combine2) { if (count($combine1['Includes']) < count($combine2['Includes'])) { return 1; } if (count($combine1['Includes']) > count($combine2['Includes'])) { return -1; } return 0; }
php
protected function compareCombines(array $combine1, array $combine2) { if (count($combine1['Includes']) < count($combine2['Includes'])) { return 1; } if (count($combine1['Includes']) > count($combine2['Includes'])) { return -1; } return 0; }
{{{ compareCombines()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L710-L721
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.getCachedValue
protected function getCachedValue($key) { $this->cache->setPrefix($this->dataProvider->getCachePrefix()); return $this->cache->get($key); }
php
protected function getCachedValue($key) { $this->cache->setPrefix($this->dataProvider->getCachePrefix()); return $this->cache->get($key); }
{{{ getCachedValue()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L726-L730
silverorange/Concentrate
Concentrate/Concentrator.php
Concentrate_Concentrator.setCachedValue
protected function setCachedValue($key, $value) { $this->cache->setPrefix($this->dataProvider->getCachePrefix()); return $this->cache->set($key, $value); }
php
protected function setCachedValue($key, $value) { $this->cache->setPrefix($this->dataProvider->getCachePrefix()); return $this->cache->set($key, $value); }
{{{ setCachedValue()
https://github.com/silverorange/Concentrate/blob/e0b679bedc105dc4280bb68a233c31246d20e6c5/Concentrate/Concentrator.php#L735-L739
freialib/freia.autoloader
src/SymbolLoader.php
SymbolLoader.instance
static function instance($syspath, $conf) { $i = new static; $i->env = $i->environementInstance($syspath, $conf); return $i; }
php
static function instance($syspath, $conf) { $i = new static; $i->env = $i->environementInstance($syspath, $conf); return $i; }
You may set debugMode to true to use debug modules, otherwise if modules with a debug type in the autoload rules section are found they will be ignored. @return static
https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolLoader.php#L24-L29
freialib/freia.autoloader
src/SymbolLoader.php
SymbolLoader.exists
function exists($symbol, $autoload = false) { return class_exists($symbol, $autoload) || interface_exists($symbol, $autoload) || trait_exists($symbol, $autoload); }
php
function exists($symbol, $autoload = false) { return class_exists($symbol, $autoload) || interface_exists($symbol, $autoload) || trait_exists($symbol, $autoload); }
Maintained for backwards comaptibility. @param string symbol (class, interface, traits, etc) @param boolean autoload while checking? @return boolean symbol exists
https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolLoader.php#L48-L52
freialib/freia.autoloader
src/SymbolLoader.php
SymbolLoader.load
function load($symbol) { if ($this->env->knownUnknown($symbol)) { return false; } if ($this->env->autoresolve($symbol)) { return true; } $ns_pos = \strripos($symbol, '\\'); if ($ns_pos !== false && $ns_pos != 0) { $ns = \substr($symbol, 0, $ns_pos + 1); // Validate Main Segment // ===================== $mainsegment = null; $firstslash = \strpos($ns, '\\'); if ($firstslash !== false || $firstslash == 0) { $mainsegment = \substr($ns, 0, $firstslash); } else { // no \ in namespace // the namespace is the main segment itself $mainsegment = $ns; } if ( ! $this->env->knownSegment($mainsegment)) { $this->env->unknownSymbol($symbol); $this->env->save(); return false; } // Continue Loading Process // ======================== $name = \substr($symbol, $ns_pos + 1); $filename = \str_replace('_', '/', $name); $dirbreak = \strlen($name) - \strcspn(strrev($name), 'ABCDEFGHJIJKLMNOPQRSTUVWXYZ') - 1; if ($dirbreak > 0 && $dirbreak != \strlen($name) - 1) { $filename = \substr($name, $dirbreak).'/'.\substr($name, 0, $dirbreak); } else { // dirbreak == 0 $filename = $name; } $nextPtr = \strrpos($ns, '\\next\\'); $resolution = null; if ($nextPtr === false) { $resolution = $this->env->findFirstFileMatching($ns, $name, $filename); } else { // "\next\" is present in string $resolution = $this->env->findFirstFileMatchingAfterNext($ns, $name, $filename); } if ($resolution != null) { list($targetfile, $targetns, $target) = $resolution; if ( ! $this->env->isLoadedSymbol($target)) { $this->env->loadSymbol($target, $targetfile); } if ($targetns != $ns) { $this->env->aliasSymbol($target, $symbol); } $this->env->save(); return true; } } # else: symbol belongs to global namespace $this->env->unknownSymbol($symbol); $this->env->save(); return false; // failed to resolve symbol; pass to next autoloader }
php
function load($symbol) { if ($this->env->knownUnknown($symbol)) { return false; } if ($this->env->autoresolve($symbol)) { return true; } $ns_pos = \strripos($symbol, '\\'); if ($ns_pos !== false && $ns_pos != 0) { $ns = \substr($symbol, 0, $ns_pos + 1); // Validate Main Segment // ===================== $mainsegment = null; $firstslash = \strpos($ns, '\\'); if ($firstslash !== false || $firstslash == 0) { $mainsegment = \substr($ns, 0, $firstslash); } else { // no \ in namespace // the namespace is the main segment itself $mainsegment = $ns; } if ( ! $this->env->knownSegment($mainsegment)) { $this->env->unknownSymbol($symbol); $this->env->save(); return false; } // Continue Loading Process // ======================== $name = \substr($symbol, $ns_pos + 1); $filename = \str_replace('_', '/', $name); $dirbreak = \strlen($name) - \strcspn(strrev($name), 'ABCDEFGHJIJKLMNOPQRSTUVWXYZ') - 1; if ($dirbreak > 0 && $dirbreak != \strlen($name) - 1) { $filename = \substr($name, $dirbreak).'/'.\substr($name, 0, $dirbreak); } else { // dirbreak == 0 $filename = $name; } $nextPtr = \strrpos($ns, '\\next\\'); $resolution = null; if ($nextPtr === false) { $resolution = $this->env->findFirstFileMatching($ns, $name, $filename); } else { // "\next\" is present in string $resolution = $this->env->findFirstFileMatchingAfterNext($ns, $name, $filename); } if ($resolution != null) { list($targetfile, $targetns, $target) = $resolution; if ( ! $this->env->isLoadedSymbol($target)) { $this->env->loadSymbol($target, $targetfile); } if ($targetns != $ns) { $this->env->aliasSymbol($target, $symbol); } $this->env->save(); return true; } } # else: symbol belongs to global namespace $this->env->unknownSymbol($symbol); $this->env->save(); return false; // failed to resolve symbol; pass to next autoloader }
Load given symbol @return boolean
https://github.com/freialib/freia.autoloader/blob/45e0dfcd56d55cf533f12255db647e8a05fcd494/src/SymbolLoader.php#L59-L141
Wedeto/HTTP
src/CachePolicy.php
CachePolicy.setExpireDate
public function setExpireDate(DateTimeInterface $dt) { $this->expire_time = (int)$dt->format('U') - time(); return $this; }
php
public function setExpireDate(DateTimeInterface $dt) { $this->expire_time = (int)$dt->format('U') - time(); return $this; }
Set the exact moment when the cache should expire. @param DateTimeInterface $dt When the cache should expire @return CachePolicy Provides fluent interface
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/CachePolicy.php#L58-L62
Wedeto/HTTP
src/CachePolicy.php
CachePolicy.setExpiresIn
public function setExpiresIn(DateInterval $interval) { $now = new DateTimeImmutable(); $expire = $now->add($interval); $this->setExpiresInSeconds($expire->getTimestamp() - $now->getTimestamp()); return $this; }
php
public function setExpiresIn(DateInterval $interval) { $now = new DateTimeImmutable(); $expire = $now->add($interval); $this->setExpiresInSeconds($expire->getTimestamp() - $now->getTimestamp()); return $this; }
Set the time until the cache should expire. @param DateInterval $interval In what time the cache should expire. @return CachePolicy Provides fluent interface
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/CachePolicy.php#L80-L86
Wedeto/HTTP
src/CachePolicy.php
CachePolicy.setExpires
public function setExpires($period) { if (is_int($period)) return $this->setExpiresInSeconds($period); if ($period instanceof DateTimeInterface) return $this->setExpireDate($period); if ($period instanceof DateInterval) return $this->setExpiresIn($period); throw new \InvalidArgumentException("A DateTime, DateInterval or int number of seconds is required"); }
php
public function setExpires($period) { if (is_int($period)) return $this->setExpiresInSeconds($period); if ($period instanceof DateTimeInterface) return $this->setExpireDate($period); if ($period instanceof DateInterval) return $this->setExpiresIn($period); throw new \InvalidArgumentException("A DateTime, DateInterval or int number of seconds is required"); }
Set the when the cache should expire. Wrapper for setExpiresIn, setExpiresInSeconds and setExpireDate, with type detection. @param mixed $period Can be int (seconds), DateTimeInterface or DateInterval. @return CachePolicy Provides fluent interface
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/CachePolicy.php#L95-L105
Wedeto/HTTP
src/CachePolicy.php
CachePolicy.setCachePolicy
public function setCachePolicy(string $policy) { if ($policy !== self::CACHE_DISABLE && $policy !== self::CACHE_PUBLIC && $policy !== self::CACHE_PRIVATE) throw new \InvalidArgumentException("Invalid cache policy: " . $policy); $this->cache_policy = $policy; return $this; }
php
public function setCachePolicy(string $policy) { if ($policy !== self::CACHE_DISABLE && $policy !== self::CACHE_PUBLIC && $policy !== self::CACHE_PRIVATE) throw new \InvalidArgumentException("Invalid cache policy: " . $policy); $this->cache_policy = $policy; return $this; }
Set the cache policy for this response. @param string $policy One of CachePolicy::CACHE_PUBLIC, CACHE_PRIVATE or CACHE_DISABLED. @return CachePolicy Provides fluent interface
https://github.com/Wedeto/HTTP/blob/7318eff1b81a3c103c4263466d09b7f3593b70b9/src/CachePolicy.php#L120-L127
sil-project/StockBundle
src/Domain/Entity/Operation.php
Operation.addMovement
public function addMovement(Movement $mvt): void { if (!$mvt->getState()->isDraft()) { throw new \InvalidArgumentException( 'Only Draft Movement can be added'); } if ($this->hasMovement($mvt)) { throw new \InvalidArgumentException( 'The same Movement cannot be added twice'); } $mvt->setOperation($this); $this->movements->add($mvt); }
php
public function addMovement(Movement $mvt): void { if (!$mvt->getState()->isDraft()) { throw new \InvalidArgumentException( 'Only Draft Movement can be added'); } if ($this->hasMovement($mvt)) { throw new \InvalidArgumentException( 'The same Movement cannot be added twice'); } $mvt->setOperation($this); $this->movements->add($mvt); }
@param Movement $mvt @throws InvalidArgumentException
https://github.com/sil-project/StockBundle/blob/c1af70e000d56cd53e8ad0dedaed9841bd2ea8a8/src/Domain/Entity/Operation.php#L251-L265
sil-project/StockBundle
src/Domain/Entity/Operation.php
Operation.removeMovement
public function removeMovement(Movement $mvt): void { if (!$this->hasMovement($mvt)) { throw new \InvalidArgumentException( 'The Movement is not part of this Operation and cannot be removed from there'); } $this->movements->removeElement($mvt); }
php
public function removeMovement(Movement $mvt): void { if (!$this->hasMovement($mvt)) { throw new \InvalidArgumentException( 'The Movement is not part of this Operation and cannot be removed from there'); } $this->movements->removeElement($mvt); }
@param Movement $mvt @throws InvalidArgumentException
https://github.com/sil-project/StockBundle/blob/c1af70e000d56cd53e8ad0dedaed9841bd2ea8a8/src/Domain/Entity/Operation.php#L272-L279
Brainsware/sauce
lib/Sauce/SString.php
SString.starts_with
public function starts_with ($needle) { ensure('Argument', $needle, 'is_a_string', __CLASS__, __METHOD__); if ($needle instanceof self) { $needle = $needle->to_s(); } return 0 === strcmp($this->slice(0, strlen($needle))->to_s(), $needle); }
php
public function starts_with ($needle) { ensure('Argument', $needle, 'is_a_string', __CLASS__, __METHOD__); if ($needle instanceof self) { $needle = $needle->to_s(); } return 0 === strcmp($this->slice(0, strlen($needle))->to_s(), $needle); }
/* Checks whether the stored string starts with given string. If given argument is not a string or a String instance, an InvalidArgumentException is thrown. Returns boolean. TODO: Examples
https://github.com/Brainsware/sauce/blob/2294fd27286bf42cfac6d744e242b2bd9eea353d/lib/Sauce/SString.php#L74-L83
Brainsware/sauce
lib/Sauce/SString.php
SString.ends_with
public function ends_with ($needle) { ensure('Argument', $needle, 'is_a_string', __CLASS__, __METHOD__); if ($needle instanceof self) { $needle = $needle->to_s(); } $len = strlen($needle); return 0 === strcmp($this->slice(-$len, $len)->to_s(), $needle); }
php
public function ends_with ($needle) { ensure('Argument', $needle, 'is_a_string', __CLASS__, __METHOD__); if ($needle instanceof self) { $needle = $needle->to_s(); } $len = strlen($needle); return 0 === strcmp($this->slice(-$len, $len)->to_s(), $needle); }
/* Checks whether the stored string ends with given string. If given argument is not a string or a String instance, an InvalidArgumentException is thrown. Returns boolean. TODO: Examples
https://github.com/Brainsware/sauce/blob/2294fd27286bf42cfac6d744e242b2bd9eea353d/lib/Sauce/SString.php#L94-L105
Brainsware/sauce
lib/Sauce/SString.php
SString.includes
public function includes ($needle) { ensure('Argument', $needle, 'is_a_string', __CLASS__, __METHOD__); return false !== strpos($this->string, $needle); }
php
public function includes ($needle) { ensure('Argument', $needle, 'is_a_string', __CLASS__, __METHOD__); return false !== strpos($this->string, $needle); }
/* Checks whether the stored string includes given string. If given argument is not a string or a String instance, an InvalidArgumentException is thrown. Returns boolean. TODO: Examples
https://github.com/Brainsware/sauce/blob/2294fd27286bf42cfac6d744e242b2bd9eea353d/lib/Sauce/SString.php#L116-L121