id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
37,900
guillermomartinez/filemanager-laravel
src/Pqb/FilemanagerLaravel/plugins/rsc/cloudfiles.php
CF_Authentication.export_credentials
function export_credentials() { $arr = array(); $arr['storage_url'] = $this->storage_url; $arr['cdnm_url'] = $this->cdnm_url; $arr['auth_token'] = $this->auth_token; return $arr; }
php
function export_credentials() { $arr = array(); $arr['storage_url'] = $this->storage_url; $arr['cdnm_url'] = $this->cdnm_url; $arr['auth_token'] = $this->auth_token; return $arr; }
[ "function", "export_credentials", "(", ")", "{", "$", "arr", "=", "array", "(", ")", ";", "$", "arr", "[", "'storage_url'", "]", "=", "$", "this", "->", "storage_url", ";", "$", "arr", "[", "'cdnm_url'", "]", "=", "$", "this", "->", "cdnm_url", ";", "$", "arr", "[", "'auth_token'", "]", "=", "$", "this", "->", "auth_token", ";", "return", "$", "arr", ";", "}" ]
Grab Cloud Files info to be Cached for later use with the load_cached_credentials method. Example: <code> #Create an Auth instance $auth = new CF_Authentication("UserName","API_Key"); $auth->authenticate(); $array = $auth->export_credentials(); </code> @return array of url's and an auth token.
[ "Grab", "Cloud", "Files", "info", "to", "be", "Cached", "for", "later", "use", "with", "the", "load_cached_credentials", "method", "." ]
e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563
https://github.com/guillermomartinez/filemanager-laravel/blob/e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563/src/Pqb/FilemanagerLaravel/plugins/rsc/cloudfiles.php#L271-L279
37,901
guillermomartinez/filemanager-laravel
src/Pqb/FilemanagerLaravel/plugins/rsc/cloudfiles.php
CF_Connection.create_container
function create_container($container_name=NULL) { if ($container_name != "0" and !isset($container_name)) throw new SyntaxException("Container name not set."); if (!isset($container_name) or $container_name == "") throw new SyntaxException("Container name not set."); if (strpos($container_name, "/") !== False) { $r = "Container name '".$container_name; $r .= "' cannot contain a '/' character."; throw new SyntaxException($r); } if (strlen($container_name) > MAX_CONTAINER_NAME_LEN) { throw new SyntaxException(sprintf( "Container name exeeds %d bytes.", MAX_CONTAINER_NAME_LEN)); } $return_code = $this->cfs_http->create_container($container_name); if (!$return_code) { throw new InvalidResponseException("Invalid response (" . $return_code. "): " . $this->cfs_http->get_error()); } #if ($status == 401 && $this->_re_auth()) { # return $this->create_container($container_name); #} if ($return_code != 201 && $return_code != 202) { throw new InvalidResponseException( "Invalid response (".$return_code."): " . $this->cfs_http->get_error()); } return new CF_Container($this->cfs_auth, $this->cfs_http, $container_name); }
php
function create_container($container_name=NULL) { if ($container_name != "0" and !isset($container_name)) throw new SyntaxException("Container name not set."); if (!isset($container_name) or $container_name == "") throw new SyntaxException("Container name not set."); if (strpos($container_name, "/") !== False) { $r = "Container name '".$container_name; $r .= "' cannot contain a '/' character."; throw new SyntaxException($r); } if (strlen($container_name) > MAX_CONTAINER_NAME_LEN) { throw new SyntaxException(sprintf( "Container name exeeds %d bytes.", MAX_CONTAINER_NAME_LEN)); } $return_code = $this->cfs_http->create_container($container_name); if (!$return_code) { throw new InvalidResponseException("Invalid response (" . $return_code. "): " . $this->cfs_http->get_error()); } #if ($status == 401 && $this->_re_auth()) { # return $this->create_container($container_name); #} if ($return_code != 201 && $return_code != 202) { throw new InvalidResponseException( "Invalid response (".$return_code."): " . $this->cfs_http->get_error()); } return new CF_Container($this->cfs_auth, $this->cfs_http, $container_name); }
[ "function", "create_container", "(", "$", "container_name", "=", "NULL", ")", "{", "if", "(", "$", "container_name", "!=", "\"0\"", "and", "!", "isset", "(", "$", "container_name", ")", ")", "throw", "new", "SyntaxException", "(", "\"Container name not set.\"", ")", ";", "if", "(", "!", "isset", "(", "$", "container_name", ")", "or", "$", "container_name", "==", "\"\"", ")", "throw", "new", "SyntaxException", "(", "\"Container name not set.\"", ")", ";", "if", "(", "strpos", "(", "$", "container_name", ",", "\"/\"", ")", "!==", "False", ")", "{", "$", "r", "=", "\"Container name '\"", ".", "$", "container_name", ";", "$", "r", ".=", "\"' cannot contain a '/' character.\"", ";", "throw", "new", "SyntaxException", "(", "$", "r", ")", ";", "}", "if", "(", "strlen", "(", "$", "container_name", ")", ">", "MAX_CONTAINER_NAME_LEN", ")", "{", "throw", "new", "SyntaxException", "(", "sprintf", "(", "\"Container name exeeds %d bytes.\"", ",", "MAX_CONTAINER_NAME_LEN", ")", ")", ";", "}", "$", "return_code", "=", "$", "this", "->", "cfs_http", "->", "create_container", "(", "$", "container_name", ")", ";", "if", "(", "!", "$", "return_code", ")", "{", "throw", "new", "InvalidResponseException", "(", "\"Invalid response (\"", ".", "$", "return_code", ".", "\"): \"", ".", "$", "this", "->", "cfs_http", "->", "get_error", "(", ")", ")", ";", "}", "#if ($status == 401 && $this->_re_auth()) {", "# return $this->create_container($container_name);", "#}", "if", "(", "$", "return_code", "!=", "201", "&&", "$", "return_code", "!=", "202", ")", "{", "throw", "new", "InvalidResponseException", "(", "\"Invalid response (\"", ".", "$", "return_code", ".", "\"): \"", ".", "$", "this", "->", "cfs_http", "->", "get_error", "(", ")", ")", ";", "}", "return", "new", "CF_Container", "(", "$", "this", "->", "cfs_auth", ",", "$", "this", "->", "cfs_http", ",", "$", "container_name", ")", ";", "}" ]
Create a Container Given a Container name, return a Container instance, creating a new remote Container if it does not exit. Example: <code> # ... authentication code excluded (see previous examples) ... # $conn = new CF_Authentication($auth); $images = $conn->create_container("my photos"); </code> @param string $container_name container name @return CF_Container @throws SyntaxException invalid name @throws InvalidResponseException unexpected response
[ "Create", "a", "Container" ]
e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563
https://github.com/guillermomartinez/filemanager-laravel/blob/e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563/src/Pqb/FilemanagerLaravel/plugins/rsc/cloudfiles.php#L476-L509
37,902
guillermomartinez/filemanager-laravel
src/Pqb/FilemanagerLaravel/plugins/rsc/cloudfiles.php
CF_Object._guess_content_type
function _guess_content_type($handle) { if ($this->content_type) return true; if (function_exists("finfo_open")) { $local_magic = dirname(__FILE__) . "/share/magic"; $finfo = @finfo_open(FILEINFO_MIME, $local_magic); if (!$finfo) $finfo = @finfo_open(FILEINFO_MIME); if ($finfo) { if (is_file((string)$handle)) $ct = @finfo_file($finfo, $handle); else $ct = @finfo_buffer($finfo, $handle); /* PHP 5.3 fileinfo display extra information like charset so we remove everything after the ; since we are not into that stuff */ if ($ct) { $extra_content_type_info = strpos($ct, "; "); if ($extra_content_type_info) $ct = substr($ct, 0, $extra_content_type_info); } if ($ct && $ct != 'application/octet-stream') $this->content_type = $ct; @finfo_close($finfo); } } if (!$this->content_type && (string)is_file($handle) && function_exists("mime_content_type")) { $this->content_type = @mime_content_type($handle); } if (!$this->content_type) { throw new BadContentTypeException("Required Content-Type not set"); } return True; }
php
function _guess_content_type($handle) { if ($this->content_type) return true; if (function_exists("finfo_open")) { $local_magic = dirname(__FILE__) . "/share/magic"; $finfo = @finfo_open(FILEINFO_MIME, $local_magic); if (!$finfo) $finfo = @finfo_open(FILEINFO_MIME); if ($finfo) { if (is_file((string)$handle)) $ct = @finfo_file($finfo, $handle); else $ct = @finfo_buffer($finfo, $handle); /* PHP 5.3 fileinfo display extra information like charset so we remove everything after the ; since we are not into that stuff */ if ($ct) { $extra_content_type_info = strpos($ct, "; "); if ($extra_content_type_info) $ct = substr($ct, 0, $extra_content_type_info); } if ($ct && $ct != 'application/octet-stream') $this->content_type = $ct; @finfo_close($finfo); } } if (!$this->content_type && (string)is_file($handle) && function_exists("mime_content_type")) { $this->content_type = @mime_content_type($handle); } if (!$this->content_type) { throw new BadContentTypeException("Required Content-Type not set"); } return True; }
[ "function", "_guess_content_type", "(", "$", "handle", ")", "{", "if", "(", "$", "this", "->", "content_type", ")", "return", "true", ";", "if", "(", "function_exists", "(", "\"finfo_open\"", ")", ")", "{", "$", "local_magic", "=", "dirname", "(", "__FILE__", ")", ".", "\"/share/magic\"", ";", "$", "finfo", "=", "@", "finfo_open", "(", "FILEINFO_MIME", ",", "$", "local_magic", ")", ";", "if", "(", "!", "$", "finfo", ")", "$", "finfo", "=", "@", "finfo_open", "(", "FILEINFO_MIME", ")", ";", "if", "(", "$", "finfo", ")", "{", "if", "(", "is_file", "(", "(", "string", ")", "$", "handle", ")", ")", "$", "ct", "=", "@", "finfo_file", "(", "$", "finfo", ",", "$", "handle", ")", ";", "else", "$", "ct", "=", "@", "finfo_buffer", "(", "$", "finfo", ",", "$", "handle", ")", ";", "/* PHP 5.3 fileinfo display extra information like\n charset so we remove everything after the ; since\n we are not into that stuff */", "if", "(", "$", "ct", ")", "{", "$", "extra_content_type_info", "=", "strpos", "(", "$", "ct", ",", "\"; \"", ")", ";", "if", "(", "$", "extra_content_type_info", ")", "$", "ct", "=", "substr", "(", "$", "ct", ",", "0", ",", "$", "extra_content_type_info", ")", ";", "}", "if", "(", "$", "ct", "&&", "$", "ct", "!=", "'application/octet-stream'", ")", "$", "this", "->", "content_type", "=", "$", "ct", ";", "@", "finfo_close", "(", "$", "finfo", ")", ";", "}", "}", "if", "(", "!", "$", "this", "->", "content_type", "&&", "(", "string", ")", "is_file", "(", "$", "handle", ")", "&&", "function_exists", "(", "\"mime_content_type\"", ")", ")", "{", "$", "this", "->", "content_type", "=", "@", "mime_content_type", "(", "$", "handle", ")", ";", "}", "if", "(", "!", "$", "this", "->", "content_type", ")", "{", "throw", "new", "BadContentTypeException", "(", "\"Required Content-Type not set\"", ")", ";", "}", "return", "True", ";", "}" ]
Internal check to get the proper mimetype. This function would go over the available PHP methods to get the MIME type. By default it will try to use the PHP fileinfo library which is available from PHP 5.3 or as an PECL extension (http://pecl.php.net/package/Fileinfo). It will get the magic file by default from the system wide file which is usually available in /usr/share/magic on Unix or try to use the file specified in the source directory of the API (share directory). if fileinfo is not available it will try to use the internal mime_content_type function. @param string $handle name of file or buffer to guess the type from @return boolean <kbd>True</kbd> if successful @throws BadContentTypeException
[ "Internal", "check", "to", "get", "the", "proper", "mimetype", "." ]
e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563
https://github.com/guillermomartinez/filemanager-laravel/blob/e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563/src/Pqb/FilemanagerLaravel/plugins/rsc/cloudfiles.php#L1699-L1741
37,903
Payum/PayumLaravelPackage
src/Payum/LaravelPackage/PayumServiceProvider.php
PayumServiceProvider.defineRoutes
protected function defineRoutes() { $route = $this->app->make('router'); $route->any('/payment/authorize/{payum_token}', array( 'as' => 'payum_authorize_do', 'uses' => 'Payum\LaravelPackage\Controller\AuthorizeController@doAction' )); $route->any('/payment/capture/{payum_token}', array( 'as' => 'payum_capture_do', 'uses' => 'Payum\LaravelPackage\Controller\CaptureController@doAction' )); $route->any('/payment/refund/{payum_token}', array( 'as' => 'payum_refund_do', 'uses' => 'Payum\LaravelPackage\Controller\RefundController@doAction' )); $route->any('/payment/notify/{payum_token}', array( 'as' => 'payum_notify_do', 'uses' => 'Payum\LaravelPackage\Controller\NotifyController@doAction' )); $route->any('/payment/notify/unsafe/{gateway_name}', array( 'as' => 'payum_notify_do_unsafe', 'uses' => 'Payum\LaravelPackage\Controller\NotifyController@doUnsafeAction' )); }
php
protected function defineRoutes() { $route = $this->app->make('router'); $route->any('/payment/authorize/{payum_token}', array( 'as' => 'payum_authorize_do', 'uses' => 'Payum\LaravelPackage\Controller\AuthorizeController@doAction' )); $route->any('/payment/capture/{payum_token}', array( 'as' => 'payum_capture_do', 'uses' => 'Payum\LaravelPackage\Controller\CaptureController@doAction' )); $route->any('/payment/refund/{payum_token}', array( 'as' => 'payum_refund_do', 'uses' => 'Payum\LaravelPackage\Controller\RefundController@doAction' )); $route->any('/payment/notify/{payum_token}', array( 'as' => 'payum_notify_do', 'uses' => 'Payum\LaravelPackage\Controller\NotifyController@doAction' )); $route->any('/payment/notify/unsafe/{gateway_name}', array( 'as' => 'payum_notify_do_unsafe', 'uses' => 'Payum\LaravelPackage\Controller\NotifyController@doUnsafeAction' )); }
[ "protected", "function", "defineRoutes", "(", ")", "{", "$", "route", "=", "$", "this", "->", "app", "->", "make", "(", "'router'", ")", ";", "$", "route", "->", "any", "(", "'/payment/authorize/{payum_token}'", ",", "array", "(", "'as'", "=>", "'payum_authorize_do'", ",", "'uses'", "=>", "'Payum\\LaravelPackage\\Controller\\AuthorizeController@doAction'", ")", ")", ";", "$", "route", "->", "any", "(", "'/payment/capture/{payum_token}'", ",", "array", "(", "'as'", "=>", "'payum_capture_do'", ",", "'uses'", "=>", "'Payum\\LaravelPackage\\Controller\\CaptureController@doAction'", ")", ")", ";", "$", "route", "->", "any", "(", "'/payment/refund/{payum_token}'", ",", "array", "(", "'as'", "=>", "'payum_refund_do'", ",", "'uses'", "=>", "'Payum\\LaravelPackage\\Controller\\RefundController@doAction'", ")", ")", ";", "$", "route", "->", "any", "(", "'/payment/notify/{payum_token}'", ",", "array", "(", "'as'", "=>", "'payum_notify_do'", ",", "'uses'", "=>", "'Payum\\LaravelPackage\\Controller\\NotifyController@doAction'", ")", ")", ";", "$", "route", "->", "any", "(", "'/payment/notify/unsafe/{gateway_name}'", ",", "array", "(", "'as'", "=>", "'payum_notify_do_unsafe'", ",", "'uses'", "=>", "'Payum\\LaravelPackage\\Controller\\NotifyController@doUnsafeAction'", ")", ")", ";", "}" ]
Define all package routes with Laravel router
[ "Define", "all", "package", "routes", "with", "Laravel", "router" ]
1d02fd53f6df9234b76771c5520aee0f897099db
https://github.com/Payum/PayumLaravelPackage/blob/1d02fd53f6df9234b76771c5520aee0f897099db/src/Payum/LaravelPackage/PayumServiceProvider.php#L108-L136
37,904
guillermomartinez/filemanager-laravel
src/Pqb/FilemanagerLaravel/Filemanager.php
Filemanager.setFileRoot
public function setFileRoot($path) { if($this->config['options']['serverRoot'] === true) { $this->doc_root = $_SERVER['DOCUMENT_ROOT']. '/'. $path; } else { $this->doc_root = $path; } // necessary for retrieving path when set dynamically with $fm->setFileRoot() method $this->dynamic_fileroot = str_replace($_SERVER['DOCUMENT_ROOT'], '', $this->doc_root); $this->separator = basename($this->doc_root); $this->__log(__METHOD__ . ' $this->doc_root value overwritten : ' . $this->doc_root); $this->__log(__METHOD__ . ' $this->dynamic_fileroot value ' . $this->dynamic_fileroot); $this->__log(__METHOD__ . ' $this->separator value ' . $this->separator); }
php
public function setFileRoot($path) { if($this->config['options']['serverRoot'] === true) { $this->doc_root = $_SERVER['DOCUMENT_ROOT']. '/'. $path; } else { $this->doc_root = $path; } // necessary for retrieving path when set dynamically with $fm->setFileRoot() method $this->dynamic_fileroot = str_replace($_SERVER['DOCUMENT_ROOT'], '', $this->doc_root); $this->separator = basename($this->doc_root); $this->__log(__METHOD__ . ' $this->doc_root value overwritten : ' . $this->doc_root); $this->__log(__METHOD__ . ' $this->dynamic_fileroot value ' . $this->dynamic_fileroot); $this->__log(__METHOD__ . ' $this->separator value ' . $this->separator); }
[ "public", "function", "setFileRoot", "(", "$", "path", ")", "{", "if", "(", "$", "this", "->", "config", "[", "'options'", "]", "[", "'serverRoot'", "]", "===", "true", ")", "{", "$", "this", "->", "doc_root", "=", "$", "_SERVER", "[", "'DOCUMENT_ROOT'", "]", ".", "'/'", ".", "$", "path", ";", "}", "else", "{", "$", "this", "->", "doc_root", "=", "$", "path", ";", "}", "// necessary for retrieving path when set dynamically with $fm->setFileRoot() method", "$", "this", "->", "dynamic_fileroot", "=", "str_replace", "(", "$", "_SERVER", "[", "'DOCUMENT_ROOT'", "]", ",", "''", ",", "$", "this", "->", "doc_root", ")", ";", "$", "this", "->", "separator", "=", "basename", "(", "$", "this", "->", "doc_root", ")", ";", "$", "this", "->", "__log", "(", "__METHOD__", ".", "' $this->doc_root value overwritten : '", ".", "$", "this", "->", "doc_root", ")", ";", "$", "this", "->", "__log", "(", "__METHOD__", ".", "' $this->dynamic_fileroot value '", ".", "$", "this", "->", "dynamic_fileroot", ")", ";", "$", "this", "->", "__log", "(", "__METHOD__", ".", "' $this->separator value '", ".", "$", "this", "->", "separator", ")", ";", "}" ]
allow Filemanager to be used with dynamic folders
[ "allow", "Filemanager", "to", "be", "used", "with", "dynamic", "folders" ]
e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563
https://github.com/guillermomartinez/filemanager-laravel/blob/e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563/src/Pqb/FilemanagerLaravel/Filemanager.php#L89-L101
37,905
guillermomartinez/filemanager-laravel
src/Pqb/FilemanagerLaravel/Filemanager.php
Filemanager.formatPath
private function formatPath($path) { if($this->dynamic_fileroot != '') { $a = explode($this->separator, $path); return end($a); } else { return $path; } }
php
private function formatPath($path) { if($this->dynamic_fileroot != '') { $a = explode($this->separator, $path); return end($a); } else { return $path; } }
[ "private", "function", "formatPath", "(", "$", "path", ")", "{", "if", "(", "$", "this", "->", "dynamic_fileroot", "!=", "''", ")", "{", "$", "a", "=", "explode", "(", "$", "this", "->", "separator", ",", "$", "path", ")", ";", "return", "end", "(", "$", "a", ")", ";", "}", "else", "{", "return", "$", "path", ";", "}", "}" ]
format path regarding the initial configuration @param string $path
[ "format", "path", "regarding", "the", "initial", "configuration" ]
e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563
https://github.com/guillermomartinez/filemanager-laravel/blob/e57a1f23930829cd1c486ef0e3bf7f2bd4fa8563/src/Pqb/FilemanagerLaravel/Filemanager.php#L706-L713
37,906
yii2mod/yii2-google-maps-markers
GoogleMaps.php
GoogleMaps.getGeoCodeData
protected function getGeoCodeData() { $result = []; foreach ($this->userLocations as $data) { $result[] = [ 'country' => ArrayHelper::getValue($data['location'], 'country'), 'address' => implode(',', ArrayHelper::getValue($data, 'location')), 'htmlContent' => ArrayHelper::getValue($data, 'htmlContent'), ]; } return $result; }
php
protected function getGeoCodeData() { $result = []; foreach ($this->userLocations as $data) { $result[] = [ 'country' => ArrayHelper::getValue($data['location'], 'country'), 'address' => implode(',', ArrayHelper::getValue($data, 'location')), 'htmlContent' => ArrayHelper::getValue($data, 'htmlContent'), ]; } return $result; }
[ "protected", "function", "getGeoCodeData", "(", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "userLocations", "as", "$", "data", ")", "{", "$", "result", "[", "]", "=", "[", "'country'", "=>", "ArrayHelper", "::", "getValue", "(", "$", "data", "[", "'location'", "]", ",", "'country'", ")", ",", "'address'", "=>", "implode", "(", "','", ",", "ArrayHelper", "::", "getValue", "(", "$", "data", ",", "'location'", ")", ")", ",", "'htmlContent'", "=>", "ArrayHelper", "::", "getValue", "(", "$", "data", ",", "'htmlContent'", ")", ",", "]", ";", "}", "return", "$", "result", ";", "}" ]
Get place urls and htmlContent @return string
[ "Get", "place", "urls", "and", "htmlContent" ]
d776b0b176302c4d6cd4ee52044d1a620af29a46
https://github.com/yii2mod/yii2-google-maps-markers/blob/d776b0b176302c4d6cd4ee52044d1a620af29a46/GoogleMaps.php#L169-L181
37,907
yii2mod/yii2-google-maps-markers
GoogleMaps.php
GoogleMaps.getGoogleMapsUrlOptions
protected function getGoogleMapsUrlOptions() { if (isset(Yii::$app->params['googleMapsUrlOptions']) && empty($this->googleMapsUrlOptions)) { $this->googleMapsUrlOptions = Yii::$app->params['googleMapsUrlOptions']; } return ArrayHelper::merge([ 'v' => '3.exp', 'key' => null, 'libraries' => null, 'language' => 'en', ], $this->googleMapsUrlOptions); }
php
protected function getGoogleMapsUrlOptions() { if (isset(Yii::$app->params['googleMapsUrlOptions']) && empty($this->googleMapsUrlOptions)) { $this->googleMapsUrlOptions = Yii::$app->params['googleMapsUrlOptions']; } return ArrayHelper::merge([ 'v' => '3.exp', 'key' => null, 'libraries' => null, 'language' => 'en', ], $this->googleMapsUrlOptions); }
[ "protected", "function", "getGoogleMapsUrlOptions", "(", ")", "{", "if", "(", "isset", "(", "Yii", "::", "$", "app", "->", "params", "[", "'googleMapsUrlOptions'", "]", ")", "&&", "empty", "(", "$", "this", "->", "googleMapsUrlOptions", ")", ")", "{", "$", "this", "->", "googleMapsUrlOptions", "=", "Yii", "::", "$", "app", "->", "params", "[", "'googleMapsUrlOptions'", "]", ";", "}", "return", "ArrayHelper", "::", "merge", "(", "[", "'v'", "=>", "'3.exp'", ",", "'key'", "=>", "null", ",", "'libraries'", "=>", "null", ",", "'language'", "=>", "'en'", ",", "]", ",", "$", "this", "->", "googleMapsUrlOptions", ")", ";", "}" ]
Get google maps url options @return array
[ "Get", "google", "maps", "url", "options" ]
d776b0b176302c4d6cd4ee52044d1a620af29a46
https://github.com/yii2mod/yii2-google-maps-markers/blob/d776b0b176302c4d6cd4ee52044d1a620af29a46/GoogleMaps.php#L198-L210
37,908
yii2mod/yii2-google-maps-markers
GoogleMaps.php
GoogleMaps.getGoogleMapsOptions
protected function getGoogleMapsOptions() { if (isset(Yii::$app->params['googleMapsOptions']) && empty($this->googleMapsOptions)) { $this->googleMapsOptions = Yii::$app->params['googleMapsOptions']; } return ArrayHelper::merge([ 'mapTypeId' => 'roadmap', 'tilt' => 45, 'zoom' => 2, ], $this->googleMapsOptions); }
php
protected function getGoogleMapsOptions() { if (isset(Yii::$app->params['googleMapsOptions']) && empty($this->googleMapsOptions)) { $this->googleMapsOptions = Yii::$app->params['googleMapsOptions']; } return ArrayHelper::merge([ 'mapTypeId' => 'roadmap', 'tilt' => 45, 'zoom' => 2, ], $this->googleMapsOptions); }
[ "protected", "function", "getGoogleMapsOptions", "(", ")", "{", "if", "(", "isset", "(", "Yii", "::", "$", "app", "->", "params", "[", "'googleMapsOptions'", "]", ")", "&&", "empty", "(", "$", "this", "->", "googleMapsOptions", ")", ")", "{", "$", "this", "->", "googleMapsOptions", "=", "Yii", "::", "$", "app", "->", "params", "[", "'googleMapsOptions'", "]", ";", "}", "return", "ArrayHelper", "::", "merge", "(", "[", "'mapTypeId'", "=>", "'roadmap'", ",", "'tilt'", "=>", "45", ",", "'zoom'", "=>", "2", ",", "]", ",", "$", "this", "->", "googleMapsOptions", ")", ";", "}" ]
Get google maps options @return array
[ "Get", "google", "maps", "options" ]
d776b0b176302c4d6cd4ee52044d1a620af29a46
https://github.com/yii2mod/yii2-google-maps-markers/blob/d776b0b176302c4d6cd4ee52044d1a620af29a46/GoogleMaps.php#L217-L228
37,909
yii2mod/yii2-google-maps-markers
GoogleMaps.php
GoogleMaps.getInfoWindowOptions
protected function getInfoWindowOptions() { if (isset(Yii::$app->params['infoWindowOptions']) && empty($this->infoWindowOptions)) { $this->infoWindowOptions = Yii::$app->params['infoWindowOptions']; } return ArrayHelper::merge([ 'content' => '', 'maxWidth' => 350, ], $this->infoWindowOptions); }
php
protected function getInfoWindowOptions() { if (isset(Yii::$app->params['infoWindowOptions']) && empty($this->infoWindowOptions)) { $this->infoWindowOptions = Yii::$app->params['infoWindowOptions']; } return ArrayHelper::merge([ 'content' => '', 'maxWidth' => 350, ], $this->infoWindowOptions); }
[ "protected", "function", "getInfoWindowOptions", "(", ")", "{", "if", "(", "isset", "(", "Yii", "::", "$", "app", "->", "params", "[", "'infoWindowOptions'", "]", ")", "&&", "empty", "(", "$", "this", "->", "infoWindowOptions", ")", ")", "{", "$", "this", "->", "infoWindowOptions", "=", "Yii", "::", "$", "app", "->", "params", "[", "'infoWindowOptions'", "]", ";", "}", "return", "ArrayHelper", "::", "merge", "(", "[", "'content'", "=>", "''", ",", "'maxWidth'", "=>", "350", ",", "]", ",", "$", "this", "->", "infoWindowOptions", ")", ";", "}" ]
Get info window options @return array
[ "Get", "info", "window", "options" ]
d776b0b176302c4d6cd4ee52044d1a620af29a46
https://github.com/yii2mod/yii2-google-maps-markers/blob/d776b0b176302c4d6cd4ee52044d1a620af29a46/GoogleMaps.php#L235-L245
37,910
yii2mod/yii2-google-maps-markers
GoogleMaps.php
GoogleMaps.getClientOptions
protected function getClientOptions() { return Json::encode([ 'geocodeData' => $this->geocodeData, 'mapOptions' => $this->googleMapsOptions, 'listeners' => $this->googleMapsListeners, 'containerId' => $this->containerId, 'renderEmptyMap' => $this->renderEmptyMap, 'infoWindowOptions' => $this->infoWindowOptions, ]); }
php
protected function getClientOptions() { return Json::encode([ 'geocodeData' => $this->geocodeData, 'mapOptions' => $this->googleMapsOptions, 'listeners' => $this->googleMapsListeners, 'containerId' => $this->containerId, 'renderEmptyMap' => $this->renderEmptyMap, 'infoWindowOptions' => $this->infoWindowOptions, ]); }
[ "protected", "function", "getClientOptions", "(", ")", "{", "return", "Json", "::", "encode", "(", "[", "'geocodeData'", "=>", "$", "this", "->", "geocodeData", ",", "'mapOptions'", "=>", "$", "this", "->", "googleMapsOptions", ",", "'listeners'", "=>", "$", "this", "->", "googleMapsListeners", ",", "'containerId'", "=>", "$", "this", "->", "containerId", ",", "'renderEmptyMap'", "=>", "$", "this", "->", "renderEmptyMap", ",", "'infoWindowOptions'", "=>", "$", "this", "->", "infoWindowOptions", ",", "]", ")", ";", "}" ]
Get google map client options @return string
[ "Get", "google", "map", "client", "options" ]
d776b0b176302c4d6cd4ee52044d1a620af29a46
https://github.com/yii2mod/yii2-google-maps-markers/blob/d776b0b176302c4d6cd4ee52044d1a620af29a46/GoogleMaps.php#L252-L262
37,911
splitbrain/php-archive
src/FileInfo.php
FileInfo.fromPath
public static function fromPath($path, $as = '') { clearstatcache(false, $path); if (!file_exists($path)) { throw new FileInfoException("$path does not exist"); } $stat = stat($path); $file = new FileInfo(); $file->setPath($path); $file->setIsdir(is_dir($path)); $file->setMode(fileperms($path)); $file->setOwner(fileowner($path)); $file->setGroup(filegroup($path)); $file->setSize(filesize($path)); $file->setUid($stat['uid']); $file->setGid($stat['gid']); $file->setMtime($stat['mtime']); if ($as) { $file->setPath($as); } return $file; }
php
public static function fromPath($path, $as = '') { clearstatcache(false, $path); if (!file_exists($path)) { throw new FileInfoException("$path does not exist"); } $stat = stat($path); $file = new FileInfo(); $file->setPath($path); $file->setIsdir(is_dir($path)); $file->setMode(fileperms($path)); $file->setOwner(fileowner($path)); $file->setGroup(filegroup($path)); $file->setSize(filesize($path)); $file->setUid($stat['uid']); $file->setGid($stat['gid']); $file->setMtime($stat['mtime']); if ($as) { $file->setPath($as); } return $file; }
[ "public", "static", "function", "fromPath", "(", "$", "path", ",", "$", "as", "=", "''", ")", "{", "clearstatcache", "(", "false", ",", "$", "path", ")", ";", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "FileInfoException", "(", "\"$path does not exist\"", ")", ";", "}", "$", "stat", "=", "stat", "(", "$", "path", ")", ";", "$", "file", "=", "new", "FileInfo", "(", ")", ";", "$", "file", "->", "setPath", "(", "$", "path", ")", ";", "$", "file", "->", "setIsdir", "(", "is_dir", "(", "$", "path", ")", ")", ";", "$", "file", "->", "setMode", "(", "fileperms", "(", "$", "path", ")", ")", ";", "$", "file", "->", "setOwner", "(", "fileowner", "(", "$", "path", ")", ")", ";", "$", "file", "->", "setGroup", "(", "filegroup", "(", "$", "path", ")", ")", ";", "$", "file", "->", "setSize", "(", "filesize", "(", "$", "path", ")", ")", ";", "$", "file", "->", "setUid", "(", "$", "stat", "[", "'uid'", "]", ")", ";", "$", "file", "->", "setGid", "(", "$", "stat", "[", "'gid'", "]", ")", ";", "$", "file", "->", "setMtime", "(", "$", "stat", "[", "'mtime'", "]", ")", ";", "if", "(", "$", "as", ")", "{", "$", "file", "->", "setPath", "(", "$", "as", ")", ";", "}", "return", "$", "file", ";", "}" ]
Factory to build FileInfo from existing file or directory @param string $path path to a file on the local file system @param string $as optional path to use inside the archive @throws FileInfoException @return FileInfo
[ "Factory", "to", "build", "FileInfo", "from", "existing", "file", "or", "directory" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/FileInfo.php#L48-L74
37,912
splitbrain/php-archive
src/FileInfo.php
FileInfo.cleanPath
protected function cleanPath($path) { $path = str_replace('\\', '/', $path); $path = explode('/', $path); $newpath = array(); foreach ($path as $p) { if ($p === '' || $p === '.') { continue; } if ($p === '..') { array_pop($newpath); continue; } array_push($newpath, $p); } return trim(implode('/', $newpath), '/'); }
php
protected function cleanPath($path) { $path = str_replace('\\', '/', $path); $path = explode('/', $path); $newpath = array(); foreach ($path as $p) { if ($p === '' || $p === '.') { continue; } if ($p === '..') { array_pop($newpath); continue; } array_push($newpath, $p); } return trim(implode('/', $newpath), '/'); }
[ "protected", "function", "cleanPath", "(", "$", "path", ")", "{", "$", "path", "=", "str_replace", "(", "'\\\\'", ",", "'/'", ",", "$", "path", ")", ";", "$", "path", "=", "explode", "(", "'/'", ",", "$", "path", ")", ";", "$", "newpath", "=", "array", "(", ")", ";", "foreach", "(", "$", "path", "as", "$", "p", ")", "{", "if", "(", "$", "p", "===", "''", "||", "$", "p", "===", "'.'", ")", "{", "continue", ";", "}", "if", "(", "$", "p", "===", "'..'", ")", "{", "array_pop", "(", "$", "newpath", ")", ";", "continue", ";", "}", "array_push", "(", "$", "newpath", ",", "$", "p", ")", ";", "}", "return", "trim", "(", "implode", "(", "'/'", ",", "$", "newpath", ")", ",", "'/'", ")", ";", "}" ]
Cleans up a path and removes relative parts, also strips leading slashes @param string $path @return string
[ "Cleans", "up", "a", "path", "and", "removes", "relative", "parts", "also", "strips", "leading", "slashes" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/FileInfo.php#L263-L279
37,913
splitbrain/php-archive
src/FileInfo.php
FileInfo.strip
public function strip($strip) { $filename = $this->getPath(); $striplen = strlen($strip); if (is_int($strip)) { // if $strip is an integer we strip this many path components $parts = explode('/', $filename); if (!$this->getIsdir()) { $base = array_pop($parts); // keep filename itself } else { $base = ''; } $filename = join('/', array_slice($parts, $strip)); if ($base) { $filename .= "/$base"; } } else { // if strip is a string, we strip a prefix here if (substr($filename, 0, $striplen) == $strip) { $filename = substr($filename, $striplen); } } $this->setPath($filename); }
php
public function strip($strip) { $filename = $this->getPath(); $striplen = strlen($strip); if (is_int($strip)) { // if $strip is an integer we strip this many path components $parts = explode('/', $filename); if (!$this->getIsdir()) { $base = array_pop($parts); // keep filename itself } else { $base = ''; } $filename = join('/', array_slice($parts, $strip)); if ($base) { $filename .= "/$base"; } } else { // if strip is a string, we strip a prefix here if (substr($filename, 0, $striplen) == $strip) { $filename = substr($filename, $striplen); } } $this->setPath($filename); }
[ "public", "function", "strip", "(", "$", "strip", ")", "{", "$", "filename", "=", "$", "this", "->", "getPath", "(", ")", ";", "$", "striplen", "=", "strlen", "(", "$", "strip", ")", ";", "if", "(", "is_int", "(", "$", "strip", ")", ")", "{", "// if $strip is an integer we strip this many path components", "$", "parts", "=", "explode", "(", "'/'", ",", "$", "filename", ")", ";", "if", "(", "!", "$", "this", "->", "getIsdir", "(", ")", ")", "{", "$", "base", "=", "array_pop", "(", "$", "parts", ")", ";", "// keep filename itself", "}", "else", "{", "$", "base", "=", "''", ";", "}", "$", "filename", "=", "join", "(", "'/'", ",", "array_slice", "(", "$", "parts", ",", "$", "strip", ")", ")", ";", "if", "(", "$", "base", ")", "{", "$", "filename", ".=", "\"/$base\"", ";", "}", "}", "else", "{", "// if strip is a string, we strip a prefix here", "if", "(", "substr", "(", "$", "filename", ",", "0", ",", "$", "striplen", ")", "==", "$", "strip", ")", "{", "$", "filename", "=", "substr", "(", "$", "filename", ",", "$", "striplen", ")", ";", "}", "}", "$", "this", "->", "setPath", "(", "$", "filename", ")", ";", "}" ]
Strip given prefix or number of path segments from the filename The $strip parameter allows you to strip a certain number of path components from the filenames found in the tar file, similar to the --strip-components feature of GNU tar. This is triggered when an integer is passed as $strip. Alternatively a fixed string prefix may be passed in $strip. If the filename matches this prefix, the prefix will be stripped. It is recommended to give prefixes with a trailing slash. @param int|string $strip
[ "Strip", "given", "prefix", "or", "number", "of", "path", "segments", "from", "the", "filename" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/FileInfo.php#L292-L316
37,914
splitbrain/php-archive
src/FileInfo.php
FileInfo.match
public function match($include = '', $exclude = '') { $extract = true; if ($include && !preg_match($include, $this->getPath())) { $extract = false; } if ($exclude && preg_match($exclude, $this->getPath())) { $extract = false; } return $extract; }
php
public function match($include = '', $exclude = '') { $extract = true; if ($include && !preg_match($include, $this->getPath())) { $extract = false; } if ($exclude && preg_match($exclude, $this->getPath())) { $extract = false; } return $extract; }
[ "public", "function", "match", "(", "$", "include", "=", "''", ",", "$", "exclude", "=", "''", ")", "{", "$", "extract", "=", "true", ";", "if", "(", "$", "include", "&&", "!", "preg_match", "(", "$", "include", ",", "$", "this", "->", "getPath", "(", ")", ")", ")", "{", "$", "extract", "=", "false", ";", "}", "if", "(", "$", "exclude", "&&", "preg_match", "(", "$", "exclude", ",", "$", "this", "->", "getPath", "(", ")", ")", ")", "{", "$", "extract", "=", "false", ";", "}", "return", "$", "extract", ";", "}" ]
Does the file match the given include and exclude expressions? Exclude rules take precedence over include rules @param string $include Regular expression of files to include @param string $exclude Regular expression of files to exclude @return bool
[ "Does", "the", "file", "match", "the", "given", "include", "and", "exclude", "expressions?" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/FileInfo.php#L327-L338
37,915
splitbrain/php-archive
src/Zip.php
Zip.setCompression
public function setCompression($level = 9, $type = Archive::COMPRESS_AUTO) { if ($level < -1 || $level > 9) { throw new ArchiveIllegalCompressionException('Compression level should be between -1 and 9'); } $this->complevel = $level; }
php
public function setCompression($level = 9, $type = Archive::COMPRESS_AUTO) { if ($level < -1 || $level > 9) { throw new ArchiveIllegalCompressionException('Compression level should be between -1 and 9'); } $this->complevel = $level; }
[ "public", "function", "setCompression", "(", "$", "level", "=", "9", ",", "$", "type", "=", "Archive", "::", "COMPRESS_AUTO", ")", "{", "if", "(", "$", "level", "<", "-", "1", "||", "$", "level", ">", "9", ")", "{", "throw", "new", "ArchiveIllegalCompressionException", "(", "'Compression level should be between -1 and 9'", ")", ";", "}", "$", "this", "->", "complevel", "=", "$", "level", ";", "}" ]
Set the compression level. Compression Type is ignored for ZIP You can call this function before adding each file to set differen compression levels for each file. @param int $level Compression level (0 to 9) @param int $type Type of compression to use ignored for ZIP @throws ArchiveIllegalCompressionException
[ "Set", "the", "compression", "level", "." ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L39-L45
37,916
splitbrain/php-archive
src/Zip.php
Zip.open
public function open($file) { $this->file = $file; $this->fh = @fopen($this->file, 'rb'); if (!$this->fh) { throw new ArchiveIOException('Could not open file for reading: '.$this->file); } $this->closed = false; }
php
public function open($file) { $this->file = $file; $this->fh = @fopen($this->file, 'rb'); if (!$this->fh) { throw new ArchiveIOException('Could not open file for reading: '.$this->file); } $this->closed = false; }
[ "public", "function", "open", "(", "$", "file", ")", "{", "$", "this", "->", "file", "=", "$", "file", ";", "$", "this", "->", "fh", "=", "@", "fopen", "(", "$", "this", "->", "file", ",", "'rb'", ")", ";", "if", "(", "!", "$", "this", "->", "fh", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Could not open file for reading: '", ".", "$", "this", "->", "file", ")", ";", "}", "$", "this", "->", "closed", "=", "false", ";", "}" ]
Open an existing ZIP file for reading @param string $file @throws ArchiveIOException
[ "Open", "an", "existing", "ZIP", "file", "for", "reading" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L53-L61
37,917
splitbrain/php-archive
src/Zip.php
Zip.contents
public function contents() { if ($this->closed || !$this->file) { throw new ArchiveIOException('Can not read from a closed archive'); } $result = array(); $centd = $this->readCentralDir(); @rewind($this->fh); @fseek($this->fh, $centd['offset']); for ($i = 0; $i < $centd['entries']; $i++) { $result[] = $this->header2fileinfo($this->readCentralFileHeader()); } $this->close(); return $result; }
php
public function contents() { if ($this->closed || !$this->file) { throw new ArchiveIOException('Can not read from a closed archive'); } $result = array(); $centd = $this->readCentralDir(); @rewind($this->fh); @fseek($this->fh, $centd['offset']); for ($i = 0; $i < $centd['entries']; $i++) { $result[] = $this->header2fileinfo($this->readCentralFileHeader()); } $this->close(); return $result; }
[ "public", "function", "contents", "(", ")", "{", "if", "(", "$", "this", "->", "closed", "||", "!", "$", "this", "->", "file", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Can not read from a closed archive'", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "centd", "=", "$", "this", "->", "readCentralDir", "(", ")", ";", "@", "rewind", "(", "$", "this", "->", "fh", ")", ";", "@", "fseek", "(", "$", "this", "->", "fh", ",", "$", "centd", "[", "'offset'", "]", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "centd", "[", "'entries'", "]", ";", "$", "i", "++", ")", "{", "$", "result", "[", "]", "=", "$", "this", "->", "header2fileinfo", "(", "$", "this", "->", "readCentralFileHeader", "(", ")", ")", ";", "}", "$", "this", "->", "close", "(", ")", ";", "return", "$", "result", ";", "}" ]
Read the contents of a ZIP archive This function lists the files stored in the archive, and returns an indexed array of FileInfo objects The archive is closed afer reading the contents, for API compatibility with TAR files Reopen the file with open() again if you want to do additional operations @throws ArchiveIOException @return FileInfo[]
[ "Read", "the", "contents", "of", "a", "ZIP", "archive" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L74-L93
37,918
splitbrain/php-archive
src/Zip.php
Zip.create
public function create($file = '') { $this->file = $file; $this->memory = ''; $this->fh = 0; if ($this->file) { $this->fh = @fopen($this->file, 'wb'); if (!$this->fh) { throw new ArchiveIOException('Could not open file for writing: '.$this->file); } } $this->writeaccess = true; $this->closed = false; $this->ctrl_dir = array(); }
php
public function create($file = '') { $this->file = $file; $this->memory = ''; $this->fh = 0; if ($this->file) { $this->fh = @fopen($this->file, 'wb'); if (!$this->fh) { throw new ArchiveIOException('Could not open file for writing: '.$this->file); } } $this->writeaccess = true; $this->closed = false; $this->ctrl_dir = array(); }
[ "public", "function", "create", "(", "$", "file", "=", "''", ")", "{", "$", "this", "->", "file", "=", "$", "file", ";", "$", "this", "->", "memory", "=", "''", ";", "$", "this", "->", "fh", "=", "0", ";", "if", "(", "$", "this", "->", "file", ")", "{", "$", "this", "->", "fh", "=", "@", "fopen", "(", "$", "this", "->", "file", ",", "'wb'", ")", ";", "if", "(", "!", "$", "this", "->", "fh", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Could not open file for writing: '", ".", "$", "this", "->", "file", ")", ";", "}", "}", "$", "this", "->", "writeaccess", "=", "true", ";", "$", "this", "->", "closed", "=", "false", ";", "$", "this", "->", "ctrl_dir", "=", "array", "(", ")", ";", "}" ]
Create a new ZIP file If $file is empty, the zip file will be created in memory @param string $file @throws ArchiveIOException
[ "Create", "a", "new", "ZIP", "file" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L254-L270
37,919
splitbrain/php-archive
src/Zip.php
Zip.addFile
public function addFile($file, $fileinfo = '') { if (is_string($fileinfo)) { $fileinfo = FileInfo::fromPath($file, $fileinfo); } if ($this->closed) { throw new ArchiveIOException('Archive has been closed, files can no longer be added'); } $data = @file_get_contents($file); if ($data === false) { throw new ArchiveIOException('Could not open file for reading: '.$file); } // FIXME could we stream writing compressed data? gzwrite on a fopen handle? $this->addData($fileinfo, $data); }
php
public function addFile($file, $fileinfo = '') { if (is_string($fileinfo)) { $fileinfo = FileInfo::fromPath($file, $fileinfo); } if ($this->closed) { throw new ArchiveIOException('Archive has been closed, files can no longer be added'); } $data = @file_get_contents($file); if ($data === false) { throw new ArchiveIOException('Could not open file for reading: '.$file); } // FIXME could we stream writing compressed data? gzwrite on a fopen handle? $this->addData($fileinfo, $data); }
[ "public", "function", "addFile", "(", "$", "file", ",", "$", "fileinfo", "=", "''", ")", "{", "if", "(", "is_string", "(", "$", "fileinfo", ")", ")", "{", "$", "fileinfo", "=", "FileInfo", "::", "fromPath", "(", "$", "file", ",", "$", "fileinfo", ")", ";", "}", "if", "(", "$", "this", "->", "closed", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Archive has been closed, files can no longer be added'", ")", ";", "}", "$", "data", "=", "@", "file_get_contents", "(", "$", "file", ")", ";", "if", "(", "$", "data", "===", "false", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Could not open file for reading: '", ".", "$", "file", ")", ";", "}", "// FIXME could we stream writing compressed data? gzwrite on a fopen handle?", "$", "this", "->", "addData", "(", "$", "fileinfo", ",", "$", "data", ")", ";", "}" ]
Add a file to the current archive using an existing file in the filesystem @param string $file path to the original file @param string|FileInfo $fileinfo either the name to use in archive (string) or a FileInfo oject with all meta data, empty to take from original @throws ArchiveIOException @throws FileInfoException
[ "Add", "a", "file", "to", "the", "current", "archive", "using", "an", "existing", "file", "in", "the", "filesystem" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L288-L305
37,920
splitbrain/php-archive
src/Zip.php
Zip.readCentralDir
protected function readCentralDir() { $size = filesize($this->file); if ($size < 277) { $maximum_size = $size; } else { $maximum_size = 277; } @fseek($this->fh, $size - $maximum_size); $pos = ftell($this->fh); $bytes = 0x00000000; while ($pos < $size) { $byte = @fread($this->fh, 1); $bytes = (($bytes << 8) & 0xFFFFFFFF) | ord($byte); if ($bytes == 0x504b0506) { break; } $pos++; } $data = unpack( 'vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', fread($this->fh, 18) ); if ($data['comment_size'] != 0) { $centd['comment'] = fread($this->fh, $data['comment_size']); } else { $centd['comment'] = ''; } $centd['entries'] = $data['entries']; $centd['disk_entries'] = $data['disk_entries']; $centd['offset'] = $data['offset']; $centd['disk_start'] = $data['disk_start']; $centd['size'] = $data['size']; $centd['disk'] = $data['disk']; return $centd; }
php
protected function readCentralDir() { $size = filesize($this->file); if ($size < 277) { $maximum_size = $size; } else { $maximum_size = 277; } @fseek($this->fh, $size - $maximum_size); $pos = ftell($this->fh); $bytes = 0x00000000; while ($pos < $size) { $byte = @fread($this->fh, 1); $bytes = (($bytes << 8) & 0xFFFFFFFF) | ord($byte); if ($bytes == 0x504b0506) { break; } $pos++; } $data = unpack( 'vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size', fread($this->fh, 18) ); if ($data['comment_size'] != 0) { $centd['comment'] = fread($this->fh, $data['comment_size']); } else { $centd['comment'] = ''; } $centd['entries'] = $data['entries']; $centd['disk_entries'] = $data['disk_entries']; $centd['offset'] = $data['offset']; $centd['disk_start'] = $data['disk_start']; $centd['size'] = $data['size']; $centd['disk'] = $data['disk']; return $centd; }
[ "protected", "function", "readCentralDir", "(", ")", "{", "$", "size", "=", "filesize", "(", "$", "this", "->", "file", ")", ";", "if", "(", "$", "size", "<", "277", ")", "{", "$", "maximum_size", "=", "$", "size", ";", "}", "else", "{", "$", "maximum_size", "=", "277", ";", "}", "@", "fseek", "(", "$", "this", "->", "fh", ",", "$", "size", "-", "$", "maximum_size", ")", ";", "$", "pos", "=", "ftell", "(", "$", "this", "->", "fh", ")", ";", "$", "bytes", "=", "0x00000000", ";", "while", "(", "$", "pos", "<", "$", "size", ")", "{", "$", "byte", "=", "@", "fread", "(", "$", "this", "->", "fh", ",", "1", ")", ";", "$", "bytes", "=", "(", "(", "$", "bytes", "<<", "8", ")", "&", "0xFFFFFFFF", ")", "|", "ord", "(", "$", "byte", ")", ";", "if", "(", "$", "bytes", "==", "0x504b0506", ")", "{", "break", ";", "}", "$", "pos", "++", ";", "}", "$", "data", "=", "unpack", "(", "'vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size'", ",", "fread", "(", "$", "this", "->", "fh", ",", "18", ")", ")", ";", "if", "(", "$", "data", "[", "'comment_size'", "]", "!=", "0", ")", "{", "$", "centd", "[", "'comment'", "]", "=", "fread", "(", "$", "this", "->", "fh", ",", "$", "data", "[", "'comment_size'", "]", ")", ";", "}", "else", "{", "$", "centd", "[", "'comment'", "]", "=", "''", ";", "}", "$", "centd", "[", "'entries'", "]", "=", "$", "data", "[", "'entries'", "]", ";", "$", "centd", "[", "'disk_entries'", "]", "=", "$", "data", "[", "'disk_entries'", "]", ";", "$", "centd", "[", "'offset'", "]", "=", "$", "data", "[", "'offset'", "]", ";", "$", "centd", "[", "'disk_start'", "]", "=", "$", "data", "[", "'disk_start'", "]", ";", "$", "centd", "[", "'size'", "]", "=", "$", "data", "[", "'size'", "]", ";", "$", "centd", "[", "'disk'", "]", "=", "$", "data", "[", "'disk'", "]", ";", "return", "$", "centd", ";", "}" ]
Read the central directory This key-value list contains general information about the ZIP file @return array
[ "Read", "the", "central", "directory" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L450-L489
37,921
splitbrain/php-archive
src/Zip.php
Zip.readCentralFileHeader
protected function readCentralFileHeader() { $binary_data = fread($this->fh, 46); $header = unpack( 'vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data ); if ($header['filename_len'] != 0) { $header['filename'] = fread($this->fh, $header['filename_len']); } else { $header['filename'] = ''; } if ($header['extra_len'] != 0) { $header['extra'] = fread($this->fh, $header['extra_len']); $header['extradata'] = $this->parseExtra($header['extra']); } else { $header['extra'] = ''; $header['extradata'] = array(); } if ($header['comment_len'] != 0) { $header['comment'] = fread($this->fh, $header['comment_len']); } else { $header['comment'] = ''; } $header['mtime'] = $this->makeUnixTime($header['mdate'], $header['mtime']); $header['stored_filename'] = $header['filename']; $header['status'] = 'ok'; if (substr($header['filename'], -1) == '/') { $header['external'] = 0x41FF0010; } $header['folder'] = ($header['external'] == 0x41FF0010 || $header['external'] == 16) ? 1 : 0; return $header; }
php
protected function readCentralFileHeader() { $binary_data = fread($this->fh, 46); $header = unpack( 'vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset', $binary_data ); if ($header['filename_len'] != 0) { $header['filename'] = fread($this->fh, $header['filename_len']); } else { $header['filename'] = ''; } if ($header['extra_len'] != 0) { $header['extra'] = fread($this->fh, $header['extra_len']); $header['extradata'] = $this->parseExtra($header['extra']); } else { $header['extra'] = ''; $header['extradata'] = array(); } if ($header['comment_len'] != 0) { $header['comment'] = fread($this->fh, $header['comment_len']); } else { $header['comment'] = ''; } $header['mtime'] = $this->makeUnixTime($header['mdate'], $header['mtime']); $header['stored_filename'] = $header['filename']; $header['status'] = 'ok'; if (substr($header['filename'], -1) == '/') { $header['external'] = 0x41FF0010; } $header['folder'] = ($header['external'] == 0x41FF0010 || $header['external'] == 16) ? 1 : 0; return $header; }
[ "protected", "function", "readCentralFileHeader", "(", ")", "{", "$", "binary_data", "=", "fread", "(", "$", "this", "->", "fh", ",", "46", ")", ";", "$", "header", "=", "unpack", "(", "'vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset'", ",", "$", "binary_data", ")", ";", "if", "(", "$", "header", "[", "'filename_len'", "]", "!=", "0", ")", "{", "$", "header", "[", "'filename'", "]", "=", "fread", "(", "$", "this", "->", "fh", ",", "$", "header", "[", "'filename_len'", "]", ")", ";", "}", "else", "{", "$", "header", "[", "'filename'", "]", "=", "''", ";", "}", "if", "(", "$", "header", "[", "'extra_len'", "]", "!=", "0", ")", "{", "$", "header", "[", "'extra'", "]", "=", "fread", "(", "$", "this", "->", "fh", ",", "$", "header", "[", "'extra_len'", "]", ")", ";", "$", "header", "[", "'extradata'", "]", "=", "$", "this", "->", "parseExtra", "(", "$", "header", "[", "'extra'", "]", ")", ";", "}", "else", "{", "$", "header", "[", "'extra'", "]", "=", "''", ";", "$", "header", "[", "'extradata'", "]", "=", "array", "(", ")", ";", "}", "if", "(", "$", "header", "[", "'comment_len'", "]", "!=", "0", ")", "{", "$", "header", "[", "'comment'", "]", "=", "fread", "(", "$", "this", "->", "fh", ",", "$", "header", "[", "'comment_len'", "]", ")", ";", "}", "else", "{", "$", "header", "[", "'comment'", "]", "=", "''", ";", "}", "$", "header", "[", "'mtime'", "]", "=", "$", "this", "->", "makeUnixTime", "(", "$", "header", "[", "'mdate'", "]", ",", "$", "header", "[", "'mtime'", "]", ")", ";", "$", "header", "[", "'stored_filename'", "]", "=", "$", "header", "[", "'filename'", "]", ";", "$", "header", "[", "'status'", "]", "=", "'ok'", ";", "if", "(", "substr", "(", "$", "header", "[", "'filename'", "]", ",", "-", "1", ")", "==", "'/'", ")", "{", "$", "header", "[", "'external'", "]", "=", "0x41FF0010", ";", "}", "$", "header", "[", "'folder'", "]", "=", "(", "$", "header", "[", "'external'", "]", "==", "0x41FF0010", "||", "$", "header", "[", "'external'", "]", "==", "16", ")", "?", "1", ":", "0", ";", "return", "$", "header", ";", "}" ]
Read the next central file header Assumes the current file pointer is pointing at the right position @return array
[ "Read", "the", "next", "central", "file", "header" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L498-L535
37,922
splitbrain/php-archive
src/Zip.php
Zip.readFileHeader
protected function readFileHeader($header) { $binary_data = fread($this->fh, 30); $data = unpack( 'vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data ); $header['filename'] = fread($this->fh, $data['filename_len']); if ($data['extra_len'] != 0) { $header['extra'] = fread($this->fh, $data['extra_len']); $header['extradata'] = array_merge($header['extradata'], $this->parseExtra($header['extra'])); } else { $header['extra'] = ''; $header['extradata'] = array(); } $header['compression'] = $data['compression']; foreach (array( 'size', 'compressed_size', 'crc' ) as $hd) { // On ODT files, these headers are 0. Keep the previous value. if ($data[$hd] != 0) { $header[$hd] = $data[$hd]; } } $header['flag'] = $data['flag']; $header['mtime'] = $this->makeUnixTime($data['mdate'], $data['mtime']); $header['stored_filename'] = $header['filename']; $header['status'] = "ok"; $header['folder'] = ($header['external'] == 0x41FF0010 || $header['external'] == 16) ? 1 : 0; return $header; }
php
protected function readFileHeader($header) { $binary_data = fread($this->fh, 30); $data = unpack( 'vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len', $binary_data ); $header['filename'] = fread($this->fh, $data['filename_len']); if ($data['extra_len'] != 0) { $header['extra'] = fread($this->fh, $data['extra_len']); $header['extradata'] = array_merge($header['extradata'], $this->parseExtra($header['extra'])); } else { $header['extra'] = ''; $header['extradata'] = array(); } $header['compression'] = $data['compression']; foreach (array( 'size', 'compressed_size', 'crc' ) as $hd) { // On ODT files, these headers are 0. Keep the previous value. if ($data[$hd] != 0) { $header[$hd] = $data[$hd]; } } $header['flag'] = $data['flag']; $header['mtime'] = $this->makeUnixTime($data['mdate'], $data['mtime']); $header['stored_filename'] = $header['filename']; $header['status'] = "ok"; $header['folder'] = ($header['external'] == 0x41FF0010 || $header['external'] == 16) ? 1 : 0; return $header; }
[ "protected", "function", "readFileHeader", "(", "$", "header", ")", "{", "$", "binary_data", "=", "fread", "(", "$", "this", "->", "fh", ",", "30", ")", ";", "$", "data", "=", "unpack", "(", "'vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len'", ",", "$", "binary_data", ")", ";", "$", "header", "[", "'filename'", "]", "=", "fread", "(", "$", "this", "->", "fh", ",", "$", "data", "[", "'filename_len'", "]", ")", ";", "if", "(", "$", "data", "[", "'extra_len'", "]", "!=", "0", ")", "{", "$", "header", "[", "'extra'", "]", "=", "fread", "(", "$", "this", "->", "fh", ",", "$", "data", "[", "'extra_len'", "]", ")", ";", "$", "header", "[", "'extradata'", "]", "=", "array_merge", "(", "$", "header", "[", "'extradata'", "]", ",", "$", "this", "->", "parseExtra", "(", "$", "header", "[", "'extra'", "]", ")", ")", ";", "}", "else", "{", "$", "header", "[", "'extra'", "]", "=", "''", ";", "$", "header", "[", "'extradata'", "]", "=", "array", "(", ")", ";", "}", "$", "header", "[", "'compression'", "]", "=", "$", "data", "[", "'compression'", "]", ";", "foreach", "(", "array", "(", "'size'", ",", "'compressed_size'", ",", "'crc'", ")", "as", "$", "hd", ")", "{", "// On ODT files, these headers are 0. Keep the previous value.", "if", "(", "$", "data", "[", "$", "hd", "]", "!=", "0", ")", "{", "$", "header", "[", "$", "hd", "]", "=", "$", "data", "[", "$", "hd", "]", ";", "}", "}", "$", "header", "[", "'flag'", "]", "=", "$", "data", "[", "'flag'", "]", ";", "$", "header", "[", "'mtime'", "]", "=", "$", "this", "->", "makeUnixTime", "(", "$", "data", "[", "'mdate'", "]", ",", "$", "data", "[", "'mtime'", "]", ")", ";", "$", "header", "[", "'stored_filename'", "]", "=", "$", "header", "[", "'filename'", "]", ";", "$", "header", "[", "'status'", "]", "=", "\"ok\"", ";", "$", "header", "[", "'folder'", "]", "=", "(", "$", "header", "[", "'external'", "]", "==", "0x41FF0010", "||", "$", "header", "[", "'external'", "]", "==", "16", ")", "?", "1", ":", "0", ";", "return", "$", "header", ";", "}" ]
Reads the local file header This header precedes each individual file inside the zip file. Assumes the current file pointer is pointing at the right position already. Enhances the given central header with the data found at the local header. @param array $header the central file header read previously (see above) @return array
[ "Reads", "the", "local", "file", "header" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L546-L580
37,923
splitbrain/php-archive
src/Zip.php
Zip.parseExtra
protected function parseExtra($header) { $extra = array(); // parse all extra fields as raw values while (strlen($header) !== 0) { $set = unpack('vid/vlen', $header); $header = substr($header, 4); $value = substr($header, 0, $set['len']); $header = substr($header, $set['len']); $extra[$set['id']] = $value; } // handle known ones if(isset($extra[0x6375])) { $extra['utf8comment'] = substr($extra[0x7075], 5); // strip version and crc } if(isset($extra[0x7075])) { $extra['utf8path'] = substr($extra[0x7075], 5); // strip version and crc } return $extra; }
php
protected function parseExtra($header) { $extra = array(); // parse all extra fields as raw values while (strlen($header) !== 0) { $set = unpack('vid/vlen', $header); $header = substr($header, 4); $value = substr($header, 0, $set['len']); $header = substr($header, $set['len']); $extra[$set['id']] = $value; } // handle known ones if(isset($extra[0x6375])) { $extra['utf8comment'] = substr($extra[0x7075], 5); // strip version and crc } if(isset($extra[0x7075])) { $extra['utf8path'] = substr($extra[0x7075], 5); // strip version and crc } return $extra; }
[ "protected", "function", "parseExtra", "(", "$", "header", ")", "{", "$", "extra", "=", "array", "(", ")", ";", "// parse all extra fields as raw values", "while", "(", "strlen", "(", "$", "header", ")", "!==", "0", ")", "{", "$", "set", "=", "unpack", "(", "'vid/vlen'", ",", "$", "header", ")", ";", "$", "header", "=", "substr", "(", "$", "header", ",", "4", ")", ";", "$", "value", "=", "substr", "(", "$", "header", ",", "0", ",", "$", "set", "[", "'len'", "]", ")", ";", "$", "header", "=", "substr", "(", "$", "header", ",", "$", "set", "[", "'len'", "]", ")", ";", "$", "extra", "[", "$", "set", "[", "'id'", "]", "]", "=", "$", "value", ";", "}", "// handle known ones", "if", "(", "isset", "(", "$", "extra", "[", "0x6375", "]", ")", ")", "{", "$", "extra", "[", "'utf8comment'", "]", "=", "substr", "(", "$", "extra", "[", "0x7075", "]", ",", "5", ")", ";", "// strip version and crc", "}", "if", "(", "isset", "(", "$", "extra", "[", "0x7075", "]", ")", ")", "{", "$", "extra", "[", "'utf8path'", "]", "=", "substr", "(", "$", "extra", "[", "0x7075", "]", ",", "5", ")", ";", "// strip version and crc", "}", "return", "$", "extra", ";", "}" ]
Parse the extra headers into fields @param string $header @return array
[ "Parse", "the", "extra", "headers", "into", "fields" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L588-L609
37,924
splitbrain/php-archive
src/Zip.php
Zip.header2fileinfo
protected function header2fileinfo($header) { $fileinfo = new FileInfo(); $fileinfo->setSize($header['size']); $fileinfo->setCompressedSize($header['compressed_size']); $fileinfo->setMtime($header['mtime']); $fileinfo->setComment($header['comment']); $fileinfo->setIsdir($header['external'] == 0x41FF0010 || $header['external'] == 16); if(isset($header['extradata']['utf8path'])) { $fileinfo->setPath($header['extradata']['utf8path']); } else { $fileinfo->setPath($this->cpToUtf8($header['filename'])); } if(isset($header['extradata']['utf8comment'])) { $fileinfo->setComment($header['extradata']['utf8comment']); } else { $fileinfo->setComment($this->cpToUtf8($header['comment'])); } return $fileinfo; }
php
protected function header2fileinfo($header) { $fileinfo = new FileInfo(); $fileinfo->setSize($header['size']); $fileinfo->setCompressedSize($header['compressed_size']); $fileinfo->setMtime($header['mtime']); $fileinfo->setComment($header['comment']); $fileinfo->setIsdir($header['external'] == 0x41FF0010 || $header['external'] == 16); if(isset($header['extradata']['utf8path'])) { $fileinfo->setPath($header['extradata']['utf8path']); } else { $fileinfo->setPath($this->cpToUtf8($header['filename'])); } if(isset($header['extradata']['utf8comment'])) { $fileinfo->setComment($header['extradata']['utf8comment']); } else { $fileinfo->setComment($this->cpToUtf8($header['comment'])); } return $fileinfo; }
[ "protected", "function", "header2fileinfo", "(", "$", "header", ")", "{", "$", "fileinfo", "=", "new", "FileInfo", "(", ")", ";", "$", "fileinfo", "->", "setSize", "(", "$", "header", "[", "'size'", "]", ")", ";", "$", "fileinfo", "->", "setCompressedSize", "(", "$", "header", "[", "'compressed_size'", "]", ")", ";", "$", "fileinfo", "->", "setMtime", "(", "$", "header", "[", "'mtime'", "]", ")", ";", "$", "fileinfo", "->", "setComment", "(", "$", "header", "[", "'comment'", "]", ")", ";", "$", "fileinfo", "->", "setIsdir", "(", "$", "header", "[", "'external'", "]", "==", "0x41FF0010", "||", "$", "header", "[", "'external'", "]", "==", "16", ")", ";", "if", "(", "isset", "(", "$", "header", "[", "'extradata'", "]", "[", "'utf8path'", "]", ")", ")", "{", "$", "fileinfo", "->", "setPath", "(", "$", "header", "[", "'extradata'", "]", "[", "'utf8path'", "]", ")", ";", "}", "else", "{", "$", "fileinfo", "->", "setPath", "(", "$", "this", "->", "cpToUtf8", "(", "$", "header", "[", "'filename'", "]", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "header", "[", "'extradata'", "]", "[", "'utf8comment'", "]", ")", ")", "{", "$", "fileinfo", "->", "setComment", "(", "$", "header", "[", "'extradata'", "]", "[", "'utf8comment'", "]", ")", ";", "}", "else", "{", "$", "fileinfo", "->", "setComment", "(", "$", "this", "->", "cpToUtf8", "(", "$", "header", "[", "'comment'", "]", ")", ")", ";", "}", "return", "$", "fileinfo", ";", "}" ]
Create fileinfo object from header data @param $header @return FileInfo
[ "Create", "fileinfo", "object", "from", "header", "data" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L617-L639
37,925
splitbrain/php-archive
src/Zip.php
Zip.cpToUtf8
protected function cpToUtf8($string) { if (function_exists('iconv') && @iconv_strlen('', 'CP437') !== false) { return iconv('CP437', 'UTF-8', $string); } elseif (function_exists('mb_convert_encoding')) { return mb_convert_encoding($string, 'UTF-8', 'CP850'); } else { return $string; } }
php
protected function cpToUtf8($string) { if (function_exists('iconv') && @iconv_strlen('', 'CP437') !== false) { return iconv('CP437', 'UTF-8', $string); } elseif (function_exists('mb_convert_encoding')) { return mb_convert_encoding($string, 'UTF-8', 'CP850'); } else { return $string; } }
[ "protected", "function", "cpToUtf8", "(", "$", "string", ")", "{", "if", "(", "function_exists", "(", "'iconv'", ")", "&&", "@", "iconv_strlen", "(", "''", ",", "'CP437'", ")", "!==", "false", ")", "{", "return", "iconv", "(", "'CP437'", ",", "'UTF-8'", ",", "$", "string", ")", ";", "}", "elseif", "(", "function_exists", "(", "'mb_convert_encoding'", ")", ")", "{", "return", "mb_convert_encoding", "(", "$", "string", ",", "'UTF-8'", ",", "'CP850'", ")", ";", "}", "else", "{", "return", "$", "string", ";", "}", "}" ]
Convert the given CP437 encoded string to UTF-8 Tries iconv with the correct encoding first, falls back to mbstring with CP850 which is similar enough. CP437 seems not to be available in mbstring. Lastly falls back to keeping the string as is, which is still better than nothing. On some systems iconv is available, but the codepage is not. We also check for that. @param $string @return string
[ "Convert", "the", "given", "CP437", "encoded", "string", "to", "UTF", "-", "8" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L653-L662
37,926
splitbrain/php-archive
src/Zip.php
Zip.utf8ToCp
protected function utf8ToCp($string) { // try iconv first if (function_exists('iconv')) { $conv = @iconv('UTF-8', 'CP437//IGNORE', $string); if($conv) return $conv; // it worked } // still here? iconv failed to convert the string. Try another method // see http://php.net/manual/en/function.iconv.php#108643 if (function_exists('mb_convert_encoding')) { return mb_convert_encoding($string, 'CP850', 'UTF-8'); } else { return $string; } }
php
protected function utf8ToCp($string) { // try iconv first if (function_exists('iconv')) { $conv = @iconv('UTF-8', 'CP437//IGNORE', $string); if($conv) return $conv; // it worked } // still here? iconv failed to convert the string. Try another method // see http://php.net/manual/en/function.iconv.php#108643 if (function_exists('mb_convert_encoding')) { return mb_convert_encoding($string, 'CP850', 'UTF-8'); } else { return $string; } }
[ "protected", "function", "utf8ToCp", "(", "$", "string", ")", "{", "// try iconv first", "if", "(", "function_exists", "(", "'iconv'", ")", ")", "{", "$", "conv", "=", "@", "iconv", "(", "'UTF-8'", ",", "'CP437//IGNORE'", ",", "$", "string", ")", ";", "if", "(", "$", "conv", ")", "return", "$", "conv", ";", "// it worked", "}", "// still here? iconv failed to convert the string. Try another method", "// see http://php.net/manual/en/function.iconv.php#108643", "if", "(", "function_exists", "(", "'mb_convert_encoding'", ")", ")", "{", "return", "mb_convert_encoding", "(", "$", "string", ",", "'CP850'", ",", "'UTF-8'", ")", ";", "}", "else", "{", "return", "$", "string", ";", "}", "}" ]
Convert the given UTF-8 encoded string to CP437 Same caveats as for cpToUtf8() apply @param $string @return string
[ "Convert", "the", "given", "UTF", "-", "8", "encoded", "string", "to", "CP437" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L672-L688
37,927
splitbrain/php-archive
src/Zip.php
Zip.makeDosTime
protected function makeDosTime($time) { $timearray = getdate($time); if ($timearray['year'] < 1980) { $timearray['year'] = 1980; $timearray['mon'] = 1; $timearray['mday'] = 1; $timearray['hours'] = 0; $timearray['minutes'] = 0; $timearray['seconds'] = 0; } return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1); }
php
protected function makeDosTime($time) { $timearray = getdate($time); if ($timearray['year'] < 1980) { $timearray['year'] = 1980; $timearray['mon'] = 1; $timearray['mday'] = 1; $timearray['hours'] = 0; $timearray['minutes'] = 0; $timearray['seconds'] = 0; } return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1); }
[ "protected", "function", "makeDosTime", "(", "$", "time", ")", "{", "$", "timearray", "=", "getdate", "(", "$", "time", ")", ";", "if", "(", "$", "timearray", "[", "'year'", "]", "<", "1980", ")", "{", "$", "timearray", "[", "'year'", "]", "=", "1980", ";", "$", "timearray", "[", "'mon'", "]", "=", "1", ";", "$", "timearray", "[", "'mday'", "]", "=", "1", ";", "$", "timearray", "[", "'hours'", "]", "=", "0", ";", "$", "timearray", "[", "'minutes'", "]", "=", "0", ";", "$", "timearray", "[", "'seconds'", "]", "=", "0", ";", "}", "return", "(", "(", "$", "timearray", "[", "'year'", "]", "-", "1980", ")", "<<", "25", ")", "|", "(", "$", "timearray", "[", "'mon'", "]", "<<", "21", ")", "|", "(", "$", "timearray", "[", "'mday'", "]", "<<", "16", ")", "|", "(", "$", "timearray", "[", "'hours'", "]", "<<", "11", ")", "|", "(", "$", "timearray", "[", "'minutes'", "]", "<<", "5", ")", "|", "(", "$", "timearray", "[", "'seconds'", "]", ">>", "1", ")", ";", "}" ]
Create a DOS timestamp from a UNIX timestamp DOS timestamps start at 1980-01-01, earlier UNIX stamps will be set to this date @param $time @return int
[ "Create", "a", "DOS", "timestamp", "from", "a", "UNIX", "timestamp" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L735-L752
37,928
splitbrain/php-archive
src/Zip.php
Zip.makeUnixTime
protected function makeUnixTime($mdate = null, $mtime = null) { if ($mdate && $mtime) { $year = (($mdate & 0xFE00) >> 9) + 1980; $month = ($mdate & 0x01E0) >> 5; $day = $mdate & 0x001F; $hour = ($mtime & 0xF800) >> 11; $minute = ($mtime & 0x07E0) >> 5; $seconde = ($mtime & 0x001F) << 1; $mtime = mktime($hour, $minute, $seconde, $month, $day, $year); } else { $mtime = time(); } return $mtime; }
php
protected function makeUnixTime($mdate = null, $mtime = null) { if ($mdate && $mtime) { $year = (($mdate & 0xFE00) >> 9) + 1980; $month = ($mdate & 0x01E0) >> 5; $day = $mdate & 0x001F; $hour = ($mtime & 0xF800) >> 11; $minute = ($mtime & 0x07E0) >> 5; $seconde = ($mtime & 0x001F) << 1; $mtime = mktime($hour, $minute, $seconde, $month, $day, $year); } else { $mtime = time(); } return $mtime; }
[ "protected", "function", "makeUnixTime", "(", "$", "mdate", "=", "null", ",", "$", "mtime", "=", "null", ")", "{", "if", "(", "$", "mdate", "&&", "$", "mtime", ")", "{", "$", "year", "=", "(", "(", "$", "mdate", "&", "0xFE00", ")", ">>", "9", ")", "+", "1980", ";", "$", "month", "=", "(", "$", "mdate", "&", "0x01E0", ")", ">>", "5", ";", "$", "day", "=", "$", "mdate", "&", "0x001F", ";", "$", "hour", "=", "(", "$", "mtime", "&", "0xF800", ")", ">>", "11", ";", "$", "minute", "=", "(", "$", "mtime", "&", "0x07E0", ")", ">>", "5", ";", "$", "seconde", "=", "(", "$", "mtime", "&", "0x001F", ")", "<<", "1", ";", "$", "mtime", "=", "mktime", "(", "$", "hour", ",", "$", "minute", ",", "$", "seconde", ",", "$", "month", ",", "$", "day", ",", "$", "year", ")", ";", "}", "else", "{", "$", "mtime", "=", "time", "(", ")", ";", "}", "return", "$", "mtime", ";", "}" ]
Create a UNIX timestamp from a DOS timestamp @param $mdate @param $mtime @return int
[ "Create", "a", "UNIX", "timestamp", "from", "a", "DOS", "timestamp" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L761-L778
37,929
splitbrain/php-archive
src/Zip.php
Zip.makeCentralFileRecord
protected function makeCentralFileRecord($offset, $ts, $crc, $len, $clen, $name, $comp = null) { if(is_null($comp)) $comp = $len != $clen; $comp = $comp ? 8 : 0; $dtime = dechex($this->makeDosTime($ts)); list($name, $extra) = $this->encodeFilename($name); $header = "\x50\x4b\x01\x02"; // central file header signature $header .= pack('v', 14); // version made by - VFAT $header .= pack('v', 20); // version needed to extract - 2.0 $header .= pack('v', 0); // general purpose flag - no flags set $header .= pack('v', $comp); // compression method - deflate|none $header .= pack( 'H*', $dtime[6] . $dtime[7] . $dtime[4] . $dtime[5] . $dtime[2] . $dtime[3] . $dtime[0] . $dtime[1] ); // last mod file time and date $header .= pack('V', $crc); // crc-32 $header .= pack('V', $clen); // compressed size $header .= pack('V', $len); // uncompressed size $header .= pack('v', strlen($name)); // file name length $header .= pack('v', strlen($extra)); // extra field length $header .= pack('v', 0); // file comment length $header .= pack('v', 0); // disk number start $header .= pack('v', 0); // internal file attributes $header .= pack('V', 0); // external file attributes @todo was 0x32!? $header .= pack('V', $offset); // relative offset of local header $header .= $name; // file name $header .= $extra; // extra (utf-8 filename) return $header; }
php
protected function makeCentralFileRecord($offset, $ts, $crc, $len, $clen, $name, $comp = null) { if(is_null($comp)) $comp = $len != $clen; $comp = $comp ? 8 : 0; $dtime = dechex($this->makeDosTime($ts)); list($name, $extra) = $this->encodeFilename($name); $header = "\x50\x4b\x01\x02"; // central file header signature $header .= pack('v', 14); // version made by - VFAT $header .= pack('v', 20); // version needed to extract - 2.0 $header .= pack('v', 0); // general purpose flag - no flags set $header .= pack('v', $comp); // compression method - deflate|none $header .= pack( 'H*', $dtime[6] . $dtime[7] . $dtime[4] . $dtime[5] . $dtime[2] . $dtime[3] . $dtime[0] . $dtime[1] ); // last mod file time and date $header .= pack('V', $crc); // crc-32 $header .= pack('V', $clen); // compressed size $header .= pack('V', $len); // uncompressed size $header .= pack('v', strlen($name)); // file name length $header .= pack('v', strlen($extra)); // extra field length $header .= pack('v', 0); // file comment length $header .= pack('v', 0); // disk number start $header .= pack('v', 0); // internal file attributes $header .= pack('V', 0); // external file attributes @todo was 0x32!? $header .= pack('V', $offset); // relative offset of local header $header .= $name; // file name $header .= $extra; // extra (utf-8 filename) return $header; }
[ "protected", "function", "makeCentralFileRecord", "(", "$", "offset", ",", "$", "ts", ",", "$", "crc", ",", "$", "len", ",", "$", "clen", ",", "$", "name", ",", "$", "comp", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "comp", ")", ")", "$", "comp", "=", "$", "len", "!=", "$", "clen", ";", "$", "comp", "=", "$", "comp", "?", "8", ":", "0", ";", "$", "dtime", "=", "dechex", "(", "$", "this", "->", "makeDosTime", "(", "$", "ts", ")", ")", ";", "list", "(", "$", "name", ",", "$", "extra", ")", "=", "$", "this", "->", "encodeFilename", "(", "$", "name", ")", ";", "$", "header", "=", "\"\\x50\\x4b\\x01\\x02\"", ";", "// central file header signature", "$", "header", ".=", "pack", "(", "'v'", ",", "14", ")", ";", "// version made by - VFAT", "$", "header", ".=", "pack", "(", "'v'", ",", "20", ")", ";", "// version needed to extract - 2.0", "$", "header", ".=", "pack", "(", "'v'", ",", "0", ")", ";", "// general purpose flag - no flags set", "$", "header", ".=", "pack", "(", "'v'", ",", "$", "comp", ")", ";", "// compression method - deflate|none", "$", "header", ".=", "pack", "(", "'H*'", ",", "$", "dtime", "[", "6", "]", ".", "$", "dtime", "[", "7", "]", ".", "$", "dtime", "[", "4", "]", ".", "$", "dtime", "[", "5", "]", ".", "$", "dtime", "[", "2", "]", ".", "$", "dtime", "[", "3", "]", ".", "$", "dtime", "[", "0", "]", ".", "$", "dtime", "[", "1", "]", ")", ";", "// last mod file time and date", "$", "header", ".=", "pack", "(", "'V'", ",", "$", "crc", ")", ";", "// crc-32", "$", "header", ".=", "pack", "(", "'V'", ",", "$", "clen", ")", ";", "// compressed size", "$", "header", ".=", "pack", "(", "'V'", ",", "$", "len", ")", ";", "// uncompressed size", "$", "header", ".=", "pack", "(", "'v'", ",", "strlen", "(", "$", "name", ")", ")", ";", "// file name length", "$", "header", ".=", "pack", "(", "'v'", ",", "strlen", "(", "$", "extra", ")", ")", ";", "// extra field length", "$", "header", ".=", "pack", "(", "'v'", ",", "0", ")", ";", "// file comment length", "$", "header", ".=", "pack", "(", "'v'", ",", "0", ")", ";", "// disk number start", "$", "header", ".=", "pack", "(", "'v'", ",", "0", ")", ";", "// internal file attributes", "$", "header", ".=", "pack", "(", "'V'", ",", "0", ")", ";", "// external file attributes @todo was 0x32!?", "$", "header", ".=", "pack", "(", "'V'", ",", "$", "offset", ")", ";", "// relative offset of local header", "$", "header", ".=", "$", "name", ";", "// file name", "$", "header", ".=", "$", "extra", ";", "// extra (utf-8 filename)", "return", "$", "header", ";", "}" ]
Returns a local file header for the given data @param int $offset location of the local header @param int $ts unix timestamp @param int $crc CRC32 checksum of the uncompressed data @param int $len length of the uncompressed data @param int $clen length of the compressed data @param string $name file name @param boolean|null $comp if compression is used, if null it's determined from $len != $clen @return string
[ "Returns", "a", "local", "file", "header", "for", "the", "given", "data" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L792-L826
37,930
splitbrain/php-archive
src/Zip.php
Zip.encodeFilename
protected function encodeFilename($original) { $cp437 = $this->utf8ToCp($original); if ($cp437 === $original) { return array($original, ''); } $extra = pack( 'vvCV', 0x7075, // tag strlen($original) + 5, // length of file + version + crc 1, // version crc32($original) // crc ); $extra .= $original; return array($cp437, $extra); }
php
protected function encodeFilename($original) { $cp437 = $this->utf8ToCp($original); if ($cp437 === $original) { return array($original, ''); } $extra = pack( 'vvCV', 0x7075, // tag strlen($original) + 5, // length of file + version + crc 1, // version crc32($original) // crc ); $extra .= $original; return array($cp437, $extra); }
[ "protected", "function", "encodeFilename", "(", "$", "original", ")", "{", "$", "cp437", "=", "$", "this", "->", "utf8ToCp", "(", "$", "original", ")", ";", "if", "(", "$", "cp437", "===", "$", "original", ")", "{", "return", "array", "(", "$", "original", ",", "''", ")", ";", "}", "$", "extra", "=", "pack", "(", "'vvCV'", ",", "0x7075", ",", "// tag", "strlen", "(", "$", "original", ")", "+", "5", ",", "// length of file + version + crc", "1", ",", "// version", "crc32", "(", "$", "original", ")", "// crc", ")", ";", "$", "extra", ".=", "$", "original", ";", "return", "array", "(", "$", "cp437", ",", "$", "extra", ")", ";", "}" ]
Returns an allowed filename and an extra field header When encoding stuff outside the 7bit ASCII range it needs to be placed in a separate extra field @param $original @return array($filename, $extra)
[ "Returns", "an", "allowed", "filename", "and", "an", "extra", "field", "header" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Zip.php#L877-L894
37,931
splitbrain/php-archive
src/Tar.php
Tar.setCompression
public function setCompression($level = 9, $type = Archive::COMPRESS_AUTO) { $this->compressioncheck($type); if ($level < -1 || $level > 9) { throw new ArchiveIllegalCompressionException('Compression level should be between -1 and 9'); } $this->comptype = $type; $this->complevel = $level; if($level == 0) $this->comptype = Archive::COMPRESS_NONE; if($type == Archive::COMPRESS_NONE) $this->complevel = 0; }
php
public function setCompression($level = 9, $type = Archive::COMPRESS_AUTO) { $this->compressioncheck($type); if ($level < -1 || $level > 9) { throw new ArchiveIllegalCompressionException('Compression level should be between -1 and 9'); } $this->comptype = $type; $this->complevel = $level; if($level == 0) $this->comptype = Archive::COMPRESS_NONE; if($type == Archive::COMPRESS_NONE) $this->complevel = 0; }
[ "public", "function", "setCompression", "(", "$", "level", "=", "9", ",", "$", "type", "=", "Archive", "::", "COMPRESS_AUTO", ")", "{", "$", "this", "->", "compressioncheck", "(", "$", "type", ")", ";", "if", "(", "$", "level", "<", "-", "1", "||", "$", "level", ">", "9", ")", "{", "throw", "new", "ArchiveIllegalCompressionException", "(", "'Compression level should be between -1 and 9'", ")", ";", "}", "$", "this", "->", "comptype", "=", "$", "type", ";", "$", "this", "->", "complevel", "=", "$", "level", ";", "if", "(", "$", "level", "==", "0", ")", "$", "this", "->", "comptype", "=", "Archive", "::", "COMPRESS_NONE", ";", "if", "(", "$", "type", "==", "Archive", "::", "COMPRESS_NONE", ")", "$", "this", "->", "complevel", "=", "0", ";", "}" ]
Sets the compression to use @param int $level Compression level (0 to 9) @param int $type Type of compression to use (use COMPRESS_* constants) @throws ArchiveIllegalCompressionException
[ "Sets", "the", "compression", "to", "use" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L34-L44
37,932
splitbrain/php-archive
src/Tar.php
Tar.open
public function open($file) { $this->file = $file; // update compression to mach file if ($this->comptype == Tar::COMPRESS_AUTO) { $this->setCompression($this->complevel, $this->filetype($file)); } // open file handles if ($this->comptype === Archive::COMPRESS_GZIP) { $this->fh = @gzopen($this->file, 'rb'); } elseif ($this->comptype === Archive::COMPRESS_BZIP) { $this->fh = @bzopen($this->file, 'r'); } else { $this->fh = @fopen($this->file, 'rb'); } if (!$this->fh) { throw new ArchiveIOException('Could not open file for reading: '.$this->file); } $this->closed = false; }
php
public function open($file) { $this->file = $file; // update compression to mach file if ($this->comptype == Tar::COMPRESS_AUTO) { $this->setCompression($this->complevel, $this->filetype($file)); } // open file handles if ($this->comptype === Archive::COMPRESS_GZIP) { $this->fh = @gzopen($this->file, 'rb'); } elseif ($this->comptype === Archive::COMPRESS_BZIP) { $this->fh = @bzopen($this->file, 'r'); } else { $this->fh = @fopen($this->file, 'rb'); } if (!$this->fh) { throw new ArchiveIOException('Could not open file for reading: '.$this->file); } $this->closed = false; }
[ "public", "function", "open", "(", "$", "file", ")", "{", "$", "this", "->", "file", "=", "$", "file", ";", "// update compression to mach file", "if", "(", "$", "this", "->", "comptype", "==", "Tar", "::", "COMPRESS_AUTO", ")", "{", "$", "this", "->", "setCompression", "(", "$", "this", "->", "complevel", ",", "$", "this", "->", "filetype", "(", "$", "file", ")", ")", ";", "}", "// open file handles", "if", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_GZIP", ")", "{", "$", "this", "->", "fh", "=", "@", "gzopen", "(", "$", "this", "->", "file", ",", "'rb'", ")", ";", "}", "elseif", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_BZIP", ")", "{", "$", "this", "->", "fh", "=", "@", "bzopen", "(", "$", "this", "->", "file", ",", "'r'", ")", ";", "}", "else", "{", "$", "this", "->", "fh", "=", "@", "fopen", "(", "$", "this", "->", "file", ",", "'rb'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "fh", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Could not open file for reading: '", ".", "$", "this", "->", "file", ")", ";", "}", "$", "this", "->", "closed", "=", "false", ";", "}" ]
Open an existing TAR file for reading @param string $file @throws ArchiveIOException @throws ArchiveIllegalCompressionException
[ "Open", "an", "existing", "TAR", "file", "for", "reading" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L53-L75
37,933
splitbrain/php-archive
src/Tar.php
Tar.contents
public function contents() { if ($this->closed || !$this->file) { throw new ArchiveIOException('Can not read from a closed archive'); } $result = array(); while ($read = $this->readbytes(512)) { $header = $this->parseHeader($read); if (!is_array($header)) { continue; } $this->skipbytes(ceil($header['size'] / 512) * 512); $result[] = $this->header2fileinfo($header); } $this->close(); return $result; }
php
public function contents() { if ($this->closed || !$this->file) { throw new ArchiveIOException('Can not read from a closed archive'); } $result = array(); while ($read = $this->readbytes(512)) { $header = $this->parseHeader($read); if (!is_array($header)) { continue; } $this->skipbytes(ceil($header['size'] / 512) * 512); $result[] = $this->header2fileinfo($header); } $this->close(); return $result; }
[ "public", "function", "contents", "(", ")", "{", "if", "(", "$", "this", "->", "closed", "||", "!", "$", "this", "->", "file", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Can not read from a closed archive'", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "while", "(", "$", "read", "=", "$", "this", "->", "readbytes", "(", "512", ")", ")", "{", "$", "header", "=", "$", "this", "->", "parseHeader", "(", "$", "read", ")", ";", "if", "(", "!", "is_array", "(", "$", "header", ")", ")", "{", "continue", ";", "}", "$", "this", "->", "skipbytes", "(", "ceil", "(", "$", "header", "[", "'size'", "]", "/", "512", ")", "*", "512", ")", ";", "$", "result", "[", "]", "=", "$", "this", "->", "header2fileinfo", "(", "$", "header", ")", ";", "}", "$", "this", "->", "close", "(", ")", ";", "return", "$", "result", ";", "}" ]
Read the contents of a TAR archive This function lists the files stored in the archive The archive is closed afer reading the contents, because rewinding is not possible in bzip2 streams. Reopen the file with open() again if you want to do additional operations @throws ArchiveIOException @throws ArchiveCorruptedException @returns FileInfo[]
[ "Read", "the", "contents", "of", "a", "TAR", "archive" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L89-L108
37,934
splitbrain/php-archive
src/Tar.php
Tar.extract
public function extract($outdir, $strip = '', $exclude = '', $include = '') { if ($this->closed || !$this->file) { throw new ArchiveIOException('Can not read from a closed archive'); } $outdir = rtrim($outdir, '/'); @mkdir($outdir, 0777, true); if (!is_dir($outdir)) { throw new ArchiveIOException("Could not create directory '$outdir'"); } $extracted = array(); while ($dat = $this->readbytes(512)) { // read the file header $header = $this->parseHeader($dat); if (!is_array($header)) { continue; } $fileinfo = $this->header2fileinfo($header); // apply strip rules $fileinfo->strip($strip); // skip unwanted files if (!strlen($fileinfo->getPath()) || !$fileinfo->match($include, $exclude)) { $this->skipbytes(ceil($header['size'] / 512) * 512); continue; } // create output directory $output = $outdir.'/'.$fileinfo->getPath(); $directory = ($fileinfo->getIsdir()) ? $output : dirname($output); @mkdir($directory, 0777, true); // extract data if (!$fileinfo->getIsdir()) { $fp = @fopen($output, "wb"); if (!$fp) { throw new ArchiveIOException('Could not open file for writing: '.$output); } $size = floor($header['size'] / 512); for ($i = 0; $i < $size; $i++) { fwrite($fp, $this->readbytes(512), 512); } if (($header['size'] % 512) != 0) { fwrite($fp, $this->readbytes(512), $header['size'] % 512); } fclose($fp); @touch($output, $fileinfo->getMtime()); @chmod($output, $fileinfo->getMode()); } else { $this->skipbytes(ceil($header['size'] / 512) * 512); // the size is usually 0 for directories } if(is_callable($this->callback)) { call_user_func($this->callback, $fileinfo); } $extracted[] = $fileinfo; } $this->close(); return $extracted; }
php
public function extract($outdir, $strip = '', $exclude = '', $include = '') { if ($this->closed || !$this->file) { throw new ArchiveIOException('Can not read from a closed archive'); } $outdir = rtrim($outdir, '/'); @mkdir($outdir, 0777, true); if (!is_dir($outdir)) { throw new ArchiveIOException("Could not create directory '$outdir'"); } $extracted = array(); while ($dat = $this->readbytes(512)) { // read the file header $header = $this->parseHeader($dat); if (!is_array($header)) { continue; } $fileinfo = $this->header2fileinfo($header); // apply strip rules $fileinfo->strip($strip); // skip unwanted files if (!strlen($fileinfo->getPath()) || !$fileinfo->match($include, $exclude)) { $this->skipbytes(ceil($header['size'] / 512) * 512); continue; } // create output directory $output = $outdir.'/'.$fileinfo->getPath(); $directory = ($fileinfo->getIsdir()) ? $output : dirname($output); @mkdir($directory, 0777, true); // extract data if (!$fileinfo->getIsdir()) { $fp = @fopen($output, "wb"); if (!$fp) { throw new ArchiveIOException('Could not open file for writing: '.$output); } $size = floor($header['size'] / 512); for ($i = 0; $i < $size; $i++) { fwrite($fp, $this->readbytes(512), 512); } if (($header['size'] % 512) != 0) { fwrite($fp, $this->readbytes(512), $header['size'] % 512); } fclose($fp); @touch($output, $fileinfo->getMtime()); @chmod($output, $fileinfo->getMode()); } else { $this->skipbytes(ceil($header['size'] / 512) * 512); // the size is usually 0 for directories } if(is_callable($this->callback)) { call_user_func($this->callback, $fileinfo); } $extracted[] = $fileinfo; } $this->close(); return $extracted; }
[ "public", "function", "extract", "(", "$", "outdir", ",", "$", "strip", "=", "''", ",", "$", "exclude", "=", "''", ",", "$", "include", "=", "''", ")", "{", "if", "(", "$", "this", "->", "closed", "||", "!", "$", "this", "->", "file", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Can not read from a closed archive'", ")", ";", "}", "$", "outdir", "=", "rtrim", "(", "$", "outdir", ",", "'/'", ")", ";", "@", "mkdir", "(", "$", "outdir", ",", "0777", ",", "true", ")", ";", "if", "(", "!", "is_dir", "(", "$", "outdir", ")", ")", "{", "throw", "new", "ArchiveIOException", "(", "\"Could not create directory '$outdir'\"", ")", ";", "}", "$", "extracted", "=", "array", "(", ")", ";", "while", "(", "$", "dat", "=", "$", "this", "->", "readbytes", "(", "512", ")", ")", "{", "// read the file header", "$", "header", "=", "$", "this", "->", "parseHeader", "(", "$", "dat", ")", ";", "if", "(", "!", "is_array", "(", "$", "header", ")", ")", "{", "continue", ";", "}", "$", "fileinfo", "=", "$", "this", "->", "header2fileinfo", "(", "$", "header", ")", ";", "// apply strip rules", "$", "fileinfo", "->", "strip", "(", "$", "strip", ")", ";", "// skip unwanted files", "if", "(", "!", "strlen", "(", "$", "fileinfo", "->", "getPath", "(", ")", ")", "||", "!", "$", "fileinfo", "->", "match", "(", "$", "include", ",", "$", "exclude", ")", ")", "{", "$", "this", "->", "skipbytes", "(", "ceil", "(", "$", "header", "[", "'size'", "]", "/", "512", ")", "*", "512", ")", ";", "continue", ";", "}", "// create output directory", "$", "output", "=", "$", "outdir", ".", "'/'", ".", "$", "fileinfo", "->", "getPath", "(", ")", ";", "$", "directory", "=", "(", "$", "fileinfo", "->", "getIsdir", "(", ")", ")", "?", "$", "output", ":", "dirname", "(", "$", "output", ")", ";", "@", "mkdir", "(", "$", "directory", ",", "0777", ",", "true", ")", ";", "// extract data", "if", "(", "!", "$", "fileinfo", "->", "getIsdir", "(", ")", ")", "{", "$", "fp", "=", "@", "fopen", "(", "$", "output", ",", "\"wb\"", ")", ";", "if", "(", "!", "$", "fp", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Could not open file for writing: '", ".", "$", "output", ")", ";", "}", "$", "size", "=", "floor", "(", "$", "header", "[", "'size'", "]", "/", "512", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "size", ";", "$", "i", "++", ")", "{", "fwrite", "(", "$", "fp", ",", "$", "this", "->", "readbytes", "(", "512", ")", ",", "512", ")", ";", "}", "if", "(", "(", "$", "header", "[", "'size'", "]", "%", "512", ")", "!=", "0", ")", "{", "fwrite", "(", "$", "fp", ",", "$", "this", "->", "readbytes", "(", "512", ")", ",", "$", "header", "[", "'size'", "]", "%", "512", ")", ";", "}", "fclose", "(", "$", "fp", ")", ";", "@", "touch", "(", "$", "output", ",", "$", "fileinfo", "->", "getMtime", "(", ")", ")", ";", "@", "chmod", "(", "$", "output", ",", "$", "fileinfo", "->", "getMode", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "skipbytes", "(", "ceil", "(", "$", "header", "[", "'size'", "]", "/", "512", ")", "*", "512", ")", ";", "// the size is usually 0 for directories", "}", "if", "(", "is_callable", "(", "$", "this", "->", "callback", ")", ")", "{", "call_user_func", "(", "$", "this", "->", "callback", ",", "$", "fileinfo", ")", ";", "}", "$", "extracted", "[", "]", "=", "$", "fileinfo", ";", "}", "$", "this", "->", "close", "(", ")", ";", "return", "$", "extracted", ";", "}" ]
Extract an existing TAR archive The $strip parameter allows you to strip a certain number of path components from the filenames found in the tar file, similar to the --strip-components feature of GNU tar. This is triggered when an integer is passed as $strip. Alternatively a fixed string prefix may be passed in $strip. If the filename matches this prefix, the prefix will be stripped. It is recommended to give prefixes with a trailing slash. By default this will extract all files found in the archive. You can restrict the output using the $include and $exclude parameter. Both expect a full regular expression (including delimiters and modifiers). If $include is set only files that match this expression will be extracted. Files that match the $exclude expression will never be extracted. Both parameters can be used in combination. Expressions are matched against stripped filenames as described above. The archive is closed afer reading the contents, because rewinding is not possible in bzip2 streams. Reopen the file with open() again if you want to do additional operations @param string $outdir the target directory for extracting @param int|string $strip either the number of path components or a fixed prefix to strip @param string $exclude a regular expression of files to exclude @param string $include a regular expression of files to include @throws ArchiveIOException @throws ArchiveCorruptedException @return FileInfo[]
[ "Extract", "an", "existing", "TAR", "archive" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L136-L201
37,935
splitbrain/php-archive
src/Tar.php
Tar.create
public function create($file = '') { $this->file = $file; $this->memory = ''; $this->fh = 0; if ($this->file) { // determine compression if ($this->comptype == Archive::COMPRESS_AUTO) { $this->setCompression($this->complevel, $this->filetype($file)); } if ($this->comptype === Archive::COMPRESS_GZIP) { $this->fh = @gzopen($this->file, 'wb'.$this->complevel); } elseif ($this->comptype === Archive::COMPRESS_BZIP) { $this->fh = @bzopen($this->file, 'w'); } else { $this->fh = @fopen($this->file, 'wb'); } if (!$this->fh) { throw new ArchiveIOException('Could not open file for writing: '.$this->file); } } $this->writeaccess = true; $this->closed = false; }
php
public function create($file = '') { $this->file = $file; $this->memory = ''; $this->fh = 0; if ($this->file) { // determine compression if ($this->comptype == Archive::COMPRESS_AUTO) { $this->setCompression($this->complevel, $this->filetype($file)); } if ($this->comptype === Archive::COMPRESS_GZIP) { $this->fh = @gzopen($this->file, 'wb'.$this->complevel); } elseif ($this->comptype === Archive::COMPRESS_BZIP) { $this->fh = @bzopen($this->file, 'w'); } else { $this->fh = @fopen($this->file, 'wb'); } if (!$this->fh) { throw new ArchiveIOException('Could not open file for writing: '.$this->file); } } $this->writeaccess = true; $this->closed = false; }
[ "public", "function", "create", "(", "$", "file", "=", "''", ")", "{", "$", "this", "->", "file", "=", "$", "file", ";", "$", "this", "->", "memory", "=", "''", ";", "$", "this", "->", "fh", "=", "0", ";", "if", "(", "$", "this", "->", "file", ")", "{", "// determine compression", "if", "(", "$", "this", "->", "comptype", "==", "Archive", "::", "COMPRESS_AUTO", ")", "{", "$", "this", "->", "setCompression", "(", "$", "this", "->", "complevel", ",", "$", "this", "->", "filetype", "(", "$", "file", ")", ")", ";", "}", "if", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_GZIP", ")", "{", "$", "this", "->", "fh", "=", "@", "gzopen", "(", "$", "this", "->", "file", ",", "'wb'", ".", "$", "this", "->", "complevel", ")", ";", "}", "elseif", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_BZIP", ")", "{", "$", "this", "->", "fh", "=", "@", "bzopen", "(", "$", "this", "->", "file", ",", "'w'", ")", ";", "}", "else", "{", "$", "this", "->", "fh", "=", "@", "fopen", "(", "$", "this", "->", "file", ",", "'wb'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "fh", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Could not open file for writing: '", ".", "$", "this", "->", "file", ")", ";", "}", "}", "$", "this", "->", "writeaccess", "=", "true", ";", "$", "this", "->", "closed", "=", "false", ";", "}" ]
Create a new TAR file If $file is empty, the tar file will be created in memory @param string $file @throws ArchiveIOException @throws ArchiveIllegalCompressionException
[ "Create", "a", "new", "TAR", "file" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L212-L238
37,936
splitbrain/php-archive
src/Tar.php
Tar.addFile
public function addFile($file, $fileinfo = '') { if (is_string($fileinfo)) { $fileinfo = FileInfo::fromPath($file, $fileinfo); } if ($this->closed) { throw new ArchiveIOException('Archive has been closed, files can no longer be added'); } $fp = @fopen($file, 'rb'); if (!$fp) { throw new ArchiveIOException('Could not open file for reading: '.$file); } // create file header $this->writeFileHeader($fileinfo); // write data $read = 0; while (!feof($fp)) { $data = fread($fp, 512); $read += strlen($data); if ($data === false) { break; } if ($data === '') { break; } $packed = pack("a512", $data); $this->writebytes($packed); } fclose($fp); if($read != $fileinfo->getSize()) { $this->close(); throw new ArchiveCorruptedException("The size of $file changed while reading, archive corrupted. read $read expected ".$fileinfo->getSize()); } if(is_callable($this->callback)) { call_user_func($this->callback, $fileinfo); } }
php
public function addFile($file, $fileinfo = '') { if (is_string($fileinfo)) { $fileinfo = FileInfo::fromPath($file, $fileinfo); } if ($this->closed) { throw new ArchiveIOException('Archive has been closed, files can no longer be added'); } $fp = @fopen($file, 'rb'); if (!$fp) { throw new ArchiveIOException('Could not open file for reading: '.$file); } // create file header $this->writeFileHeader($fileinfo); // write data $read = 0; while (!feof($fp)) { $data = fread($fp, 512); $read += strlen($data); if ($data === false) { break; } if ($data === '') { break; } $packed = pack("a512", $data); $this->writebytes($packed); } fclose($fp); if($read != $fileinfo->getSize()) { $this->close(); throw new ArchiveCorruptedException("The size of $file changed while reading, archive corrupted. read $read expected ".$fileinfo->getSize()); } if(is_callable($this->callback)) { call_user_func($this->callback, $fileinfo); } }
[ "public", "function", "addFile", "(", "$", "file", ",", "$", "fileinfo", "=", "''", ")", "{", "if", "(", "is_string", "(", "$", "fileinfo", ")", ")", "{", "$", "fileinfo", "=", "FileInfo", "::", "fromPath", "(", "$", "file", ",", "$", "fileinfo", ")", ";", "}", "if", "(", "$", "this", "->", "closed", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Archive has been closed, files can no longer be added'", ")", ";", "}", "$", "fp", "=", "@", "fopen", "(", "$", "file", ",", "'rb'", ")", ";", "if", "(", "!", "$", "fp", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Could not open file for reading: '", ".", "$", "file", ")", ";", "}", "// create file header", "$", "this", "->", "writeFileHeader", "(", "$", "fileinfo", ")", ";", "// write data", "$", "read", "=", "0", ";", "while", "(", "!", "feof", "(", "$", "fp", ")", ")", "{", "$", "data", "=", "fread", "(", "$", "fp", ",", "512", ")", ";", "$", "read", "+=", "strlen", "(", "$", "data", ")", ";", "if", "(", "$", "data", "===", "false", ")", "{", "break", ";", "}", "if", "(", "$", "data", "===", "''", ")", "{", "break", ";", "}", "$", "packed", "=", "pack", "(", "\"a512\"", ",", "$", "data", ")", ";", "$", "this", "->", "writebytes", "(", "$", "packed", ")", ";", "}", "fclose", "(", "$", "fp", ")", ";", "if", "(", "$", "read", "!=", "$", "fileinfo", "->", "getSize", "(", ")", ")", "{", "$", "this", "->", "close", "(", ")", ";", "throw", "new", "ArchiveCorruptedException", "(", "\"The size of $file changed while reading, archive corrupted. read $read expected \"", ".", "$", "fileinfo", "->", "getSize", "(", ")", ")", ";", "}", "if", "(", "is_callable", "(", "$", "this", "->", "callback", ")", ")", "{", "call_user_func", "(", "$", "this", "->", "callback", ",", "$", "fileinfo", ")", ";", "}", "}" ]
Add a file to the current TAR archive using an existing file in the filesystem @param string $file path to the original file @param string|FileInfo $fileinfo either the name to us in archive (string) or a FileInfo oject with all meta data, empty to take from original @throws ArchiveCorruptedException when the file changes while reading it, the archive will be corrupt and should be deleted @throws ArchiveIOException there was trouble reading the given file, it was not added @throws FileInfoException trouble reading file info, it was not added
[ "Add", "a", "file", "to", "the", "current", "TAR", "archive", "using", "an", "existing", "file", "in", "the", "filesystem" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L249-L291
37,937
splitbrain/php-archive
src/Tar.php
Tar.getArchive
public function getArchive() { $this->close(); if ($this->comptype === Archive::COMPRESS_AUTO) { $this->comptype = Archive::COMPRESS_NONE; } if ($this->comptype === Archive::COMPRESS_GZIP) { return gzencode($this->memory, $this->complevel); } if ($this->comptype === Archive::COMPRESS_BZIP) { return bzcompress($this->memory); } return $this->memory; }
php
public function getArchive() { $this->close(); if ($this->comptype === Archive::COMPRESS_AUTO) { $this->comptype = Archive::COMPRESS_NONE; } if ($this->comptype === Archive::COMPRESS_GZIP) { return gzencode($this->memory, $this->complevel); } if ($this->comptype === Archive::COMPRESS_BZIP) { return bzcompress($this->memory); } return $this->memory; }
[ "public", "function", "getArchive", "(", ")", "{", "$", "this", "->", "close", "(", ")", ";", "if", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_AUTO", ")", "{", "$", "this", "->", "comptype", "=", "Archive", "::", "COMPRESS_NONE", ";", "}", "if", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_GZIP", ")", "{", "return", "gzencode", "(", "$", "this", "->", "memory", ",", "$", "this", "->", "complevel", ")", ";", "}", "if", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_BZIP", ")", "{", "return", "bzcompress", "(", "$", "this", "->", "memory", ")", ";", "}", "return", "$", "this", "->", "memory", ";", "}" ]
Returns the created in-memory archive data This implicitly calls close() on the Archive @throws ArchiveIOException
[ "Returns", "the", "created", "in", "-", "memory", "archive", "data" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L371-L386
37,938
splitbrain/php-archive
src/Tar.php
Tar.save
public function save($file) { if ($this->comptype === Archive::COMPRESS_AUTO) { $this->setCompression($this->complevel, $this->filetype($file)); } if (!@file_put_contents($file, $this->getArchive())) { throw new ArchiveIOException('Could not write to file: '.$file); } }
php
public function save($file) { if ($this->comptype === Archive::COMPRESS_AUTO) { $this->setCompression($this->complevel, $this->filetype($file)); } if (!@file_put_contents($file, $this->getArchive())) { throw new ArchiveIOException('Could not write to file: '.$file); } }
[ "public", "function", "save", "(", "$", "file", ")", "{", "if", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_AUTO", ")", "{", "$", "this", "->", "setCompression", "(", "$", "this", "->", "complevel", ",", "$", "this", "->", "filetype", "(", "$", "file", ")", ")", ";", "}", "if", "(", "!", "@", "file_put_contents", "(", "$", "file", ",", "$", "this", "->", "getArchive", "(", ")", ")", ")", "{", "throw", "new", "ArchiveIOException", "(", "'Could not write to file: '", ".", "$", "file", ")", ";", "}", "}" ]
Save the created in-memory archive data Note: It more memory effective to specify the filename in the create() function and let the library work on the new file directly. @param string $file @throws ArchiveIOException @throws ArchiveIllegalCompressionException
[ "Save", "the", "created", "in", "-", "memory", "archive", "data" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L398-L407
37,939
splitbrain/php-archive
src/Tar.php
Tar.readbytes
protected function readbytes($length) { if ($this->comptype === Archive::COMPRESS_GZIP) { return @gzread($this->fh, $length); } elseif ($this->comptype === Archive::COMPRESS_BZIP) { return @bzread($this->fh, $length); } else { return @fread($this->fh, $length); } }
php
protected function readbytes($length) { if ($this->comptype === Archive::COMPRESS_GZIP) { return @gzread($this->fh, $length); } elseif ($this->comptype === Archive::COMPRESS_BZIP) { return @bzread($this->fh, $length); } else { return @fread($this->fh, $length); } }
[ "protected", "function", "readbytes", "(", "$", "length", ")", "{", "if", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_GZIP", ")", "{", "return", "@", "gzread", "(", "$", "this", "->", "fh", ",", "$", "length", ")", ";", "}", "elseif", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_BZIP", ")", "{", "return", "@", "bzread", "(", "$", "this", "->", "fh", ",", "$", "length", ")", ";", "}", "else", "{", "return", "@", "fread", "(", "$", "this", "->", "fh", ",", "$", "length", ")", ";", "}", "}" ]
Read from the open file pointer @param int $length bytes to read @return string
[ "Read", "from", "the", "open", "file", "pointer" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L415-L424
37,940
splitbrain/php-archive
src/Tar.php
Tar.skipbytes
protected function skipbytes($bytes) { if ($this->comptype === Archive::COMPRESS_GZIP) { @gzseek($this->fh, $bytes, SEEK_CUR); } elseif ($this->comptype === Archive::COMPRESS_BZIP) { // there is no seek in bzip2, we simply read on // bzread allows to read a max of 8kb at once while($bytes) { $toread = min(8192, $bytes); @bzread($this->fh, $toread); $bytes -= $toread; } } else { @fseek($this->fh, $bytes, SEEK_CUR); } }
php
protected function skipbytes($bytes) { if ($this->comptype === Archive::COMPRESS_GZIP) { @gzseek($this->fh, $bytes, SEEK_CUR); } elseif ($this->comptype === Archive::COMPRESS_BZIP) { // there is no seek in bzip2, we simply read on // bzread allows to read a max of 8kb at once while($bytes) { $toread = min(8192, $bytes); @bzread($this->fh, $toread); $bytes -= $toread; } } else { @fseek($this->fh, $bytes, SEEK_CUR); } }
[ "protected", "function", "skipbytes", "(", "$", "bytes", ")", "{", "if", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_GZIP", ")", "{", "@", "gzseek", "(", "$", "this", "->", "fh", ",", "$", "bytes", ",", "SEEK_CUR", ")", ";", "}", "elseif", "(", "$", "this", "->", "comptype", "===", "Archive", "::", "COMPRESS_BZIP", ")", "{", "// there is no seek in bzip2, we simply read on", "// bzread allows to read a max of 8kb at once", "while", "(", "$", "bytes", ")", "{", "$", "toread", "=", "min", "(", "8192", ",", "$", "bytes", ")", ";", "@", "bzread", "(", "$", "this", "->", "fh", ",", "$", "toread", ")", ";", "$", "bytes", "-=", "$", "toread", ";", "}", "}", "else", "{", "@", "fseek", "(", "$", "this", "->", "fh", ",", "$", "bytes", ",", "SEEK_CUR", ")", ";", "}", "}" ]
Skip forward in the open file pointer This is basically a wrapper around seek() (and a workaround for bzip2) @param int $bytes seek to this position
[ "Skip", "forward", "in", "the", "open", "file", "pointer" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L458-L473
37,941
splitbrain/php-archive
src/Tar.php
Tar.writeFileHeader
protected function writeFileHeader(FileInfo $fileinfo) { $this->writeRawFileHeader( $fileinfo->getPath(), $fileinfo->getUid(), $fileinfo->getGid(), $fileinfo->getMode(), $fileinfo->getSize(), $fileinfo->getMtime(), $fileinfo->getIsdir() ? '5' : '0' ); }
php
protected function writeFileHeader(FileInfo $fileinfo) { $this->writeRawFileHeader( $fileinfo->getPath(), $fileinfo->getUid(), $fileinfo->getGid(), $fileinfo->getMode(), $fileinfo->getSize(), $fileinfo->getMtime(), $fileinfo->getIsdir() ? '5' : '0' ); }
[ "protected", "function", "writeFileHeader", "(", "FileInfo", "$", "fileinfo", ")", "{", "$", "this", "->", "writeRawFileHeader", "(", "$", "fileinfo", "->", "getPath", "(", ")", ",", "$", "fileinfo", "->", "getUid", "(", ")", ",", "$", "fileinfo", "->", "getGid", "(", ")", ",", "$", "fileinfo", "->", "getMode", "(", ")", ",", "$", "fileinfo", "->", "getSize", "(", ")", ",", "$", "fileinfo", "->", "getMtime", "(", ")", ",", "$", "fileinfo", "->", "getIsdir", "(", ")", "?", "'5'", ":", "'0'", ")", ";", "}" ]
Write the given file meta data as header @param FileInfo $fileinfo @throws ArchiveIOException
[ "Write", "the", "given", "file", "meta", "data", "as", "header" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L481-L492
37,942
splitbrain/php-archive
src/Tar.php
Tar.writeRawFileHeader
protected function writeRawFileHeader($name, $uid, $gid, $perm, $size, $mtime, $typeflag = '') { // handle filename length restrictions $prefix = ''; $namelen = strlen($name); if ($namelen > 100) { $file = basename($name); $dir = dirname($name); if (strlen($file) > 100 || strlen($dir) > 155) { // we're still too large, let's use GNU longlink $this->writeRawFileHeader('././@LongLink', 0, 0, 0, $namelen, 0, 'L'); for ($s = 0; $s < $namelen; $s += 512) { $this->writebytes(pack("a512", substr($name, $s, 512))); } $name = substr($name, 0, 100); // cut off name } else { // we're fine when splitting, use POSIX ustar $prefix = $dir; $name = $file; } } // values are needed in octal $uid = sprintf("%6s ", decoct($uid)); $gid = sprintf("%6s ", decoct($gid)); $perm = sprintf("%6s ", decoct($perm)); $size = sprintf("%11s ", decoct($size)); $mtime = sprintf("%11s", decoct($mtime)); $data_first = pack("a100a8a8a8a12A12", $name, $perm, $uid, $gid, $size, $mtime); $data_last = pack("a1a100a6a2a32a32a8a8a155a12", $typeflag, '', 'ustar', '', '', '', '', '', $prefix, ""); for ($i = 0, $chks = 0; $i < 148; $i++) { $chks += ord($data_first[$i]); } for ($i = 156, $chks += 256, $j = 0; $i < 512; $i++, $j++) { $chks += ord($data_last[$j]); } $this->writebytes($data_first); $chks = pack("a8", sprintf("%6s ", decoct($chks))); $this->writebytes($chks.$data_last); }
php
protected function writeRawFileHeader($name, $uid, $gid, $perm, $size, $mtime, $typeflag = '') { // handle filename length restrictions $prefix = ''; $namelen = strlen($name); if ($namelen > 100) { $file = basename($name); $dir = dirname($name); if (strlen($file) > 100 || strlen($dir) > 155) { // we're still too large, let's use GNU longlink $this->writeRawFileHeader('././@LongLink', 0, 0, 0, $namelen, 0, 'L'); for ($s = 0; $s < $namelen; $s += 512) { $this->writebytes(pack("a512", substr($name, $s, 512))); } $name = substr($name, 0, 100); // cut off name } else { // we're fine when splitting, use POSIX ustar $prefix = $dir; $name = $file; } } // values are needed in octal $uid = sprintf("%6s ", decoct($uid)); $gid = sprintf("%6s ", decoct($gid)); $perm = sprintf("%6s ", decoct($perm)); $size = sprintf("%11s ", decoct($size)); $mtime = sprintf("%11s", decoct($mtime)); $data_first = pack("a100a8a8a8a12A12", $name, $perm, $uid, $gid, $size, $mtime); $data_last = pack("a1a100a6a2a32a32a8a8a155a12", $typeflag, '', 'ustar', '', '', '', '', '', $prefix, ""); for ($i = 0, $chks = 0; $i < 148; $i++) { $chks += ord($data_first[$i]); } for ($i = 156, $chks += 256, $j = 0; $i < 512; $i++, $j++) { $chks += ord($data_last[$j]); } $this->writebytes($data_first); $chks = pack("a8", sprintf("%6s ", decoct($chks))); $this->writebytes($chks.$data_last); }
[ "protected", "function", "writeRawFileHeader", "(", "$", "name", ",", "$", "uid", ",", "$", "gid", ",", "$", "perm", ",", "$", "size", ",", "$", "mtime", ",", "$", "typeflag", "=", "''", ")", "{", "// handle filename length restrictions", "$", "prefix", "=", "''", ";", "$", "namelen", "=", "strlen", "(", "$", "name", ")", ";", "if", "(", "$", "namelen", ">", "100", ")", "{", "$", "file", "=", "basename", "(", "$", "name", ")", ";", "$", "dir", "=", "dirname", "(", "$", "name", ")", ";", "if", "(", "strlen", "(", "$", "file", ")", ">", "100", "||", "strlen", "(", "$", "dir", ")", ">", "155", ")", "{", "// we're still too large, let's use GNU longlink", "$", "this", "->", "writeRawFileHeader", "(", "'././@LongLink'", ",", "0", ",", "0", ",", "0", ",", "$", "namelen", ",", "0", ",", "'L'", ")", ";", "for", "(", "$", "s", "=", "0", ";", "$", "s", "<", "$", "namelen", ";", "$", "s", "+=", "512", ")", "{", "$", "this", "->", "writebytes", "(", "pack", "(", "\"a512\"", ",", "substr", "(", "$", "name", ",", "$", "s", ",", "512", ")", ")", ")", ";", "}", "$", "name", "=", "substr", "(", "$", "name", ",", "0", ",", "100", ")", ";", "// cut off name", "}", "else", "{", "// we're fine when splitting, use POSIX ustar", "$", "prefix", "=", "$", "dir", ";", "$", "name", "=", "$", "file", ";", "}", "}", "// values are needed in octal", "$", "uid", "=", "sprintf", "(", "\"%6s \"", ",", "decoct", "(", "$", "uid", ")", ")", ";", "$", "gid", "=", "sprintf", "(", "\"%6s \"", ",", "decoct", "(", "$", "gid", ")", ")", ";", "$", "perm", "=", "sprintf", "(", "\"%6s \"", ",", "decoct", "(", "$", "perm", ")", ")", ";", "$", "size", "=", "sprintf", "(", "\"%11s \"", ",", "decoct", "(", "$", "size", ")", ")", ";", "$", "mtime", "=", "sprintf", "(", "\"%11s\"", ",", "decoct", "(", "$", "mtime", ")", ")", ";", "$", "data_first", "=", "pack", "(", "\"a100a8a8a8a12A12\"", ",", "$", "name", ",", "$", "perm", ",", "$", "uid", ",", "$", "gid", ",", "$", "size", ",", "$", "mtime", ")", ";", "$", "data_last", "=", "pack", "(", "\"a1a100a6a2a32a32a8a8a155a12\"", ",", "$", "typeflag", ",", "''", ",", "'ustar'", ",", "''", ",", "''", ",", "''", ",", "''", ",", "''", ",", "$", "prefix", ",", "\"\"", ")", ";", "for", "(", "$", "i", "=", "0", ",", "$", "chks", "=", "0", ";", "$", "i", "<", "148", ";", "$", "i", "++", ")", "{", "$", "chks", "+=", "ord", "(", "$", "data_first", "[", "$", "i", "]", ")", ";", "}", "for", "(", "$", "i", "=", "156", ",", "$", "chks", "+=", "256", ",", "$", "j", "=", "0", ";", "$", "i", "<", "512", ";", "$", "i", "++", ",", "$", "j", "++", ")", "{", "$", "chks", "+=", "ord", "(", "$", "data_last", "[", "$", "j", "]", ")", ";", "}", "$", "this", "->", "writebytes", "(", "$", "data_first", ")", ";", "$", "chks", "=", "pack", "(", "\"a8\"", ",", "sprintf", "(", "\"%6s \"", ",", "decoct", "(", "$", "chks", ")", ")", ")", ";", "$", "this", "->", "writebytes", "(", "$", "chks", ".", "$", "data_last", ")", ";", "}" ]
Write a file header to the stream @param string $name @param int $uid @param int $gid @param int $perm @param int $size @param int $mtime @param string $typeflag Set to '5' for directories @throws ArchiveIOException
[ "Write", "a", "file", "header", "to", "the", "stream" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L506-L550
37,943
splitbrain/php-archive
src/Tar.php
Tar.parseHeader
protected function parseHeader($block) { if (!$block || strlen($block) != 512) { throw new ArchiveCorruptedException('Unexpected length of header'); } // null byte blocks are ignored if(trim($block) === '') return false; for ($i = 0, $chks = 0; $i < 148; $i++) { $chks += ord($block[$i]); } for ($i = 156, $chks += 256; $i < 512; $i++) { $chks += ord($block[$i]); } $header = @unpack( "a100filename/a8perm/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix", $block ); if (!$header) { throw new ArchiveCorruptedException('Failed to parse header'); } $return['checksum'] = OctDec(trim($header['checksum'])); if ($return['checksum'] != $chks) { throw new ArchiveCorruptedException('Header does not match it\'s checksum'); } $return['filename'] = trim($header['filename']); $return['perm'] = OctDec(trim($header['perm'])); $return['uid'] = OctDec(trim($header['uid'])); $return['gid'] = OctDec(trim($header['gid'])); $return['size'] = OctDec(trim($header['size'])); $return['mtime'] = OctDec(trim($header['mtime'])); $return['typeflag'] = $header['typeflag']; $return['link'] = trim($header['link']); $return['uname'] = trim($header['uname']); $return['gname'] = trim($header['gname']); // Handle ustar Posix compliant path prefixes if (trim($header['prefix'])) { $return['filename'] = trim($header['prefix']).'/'.$return['filename']; } // Handle Long-Link entries from GNU Tar if ($return['typeflag'] == 'L') { // following data block(s) is the filename $filename = trim($this->readbytes(ceil($return['size'] / 512) * 512)); // next block is the real header $block = $this->readbytes(512); $return = $this->parseHeader($block); // overwrite the filename $return['filename'] = $filename; } return $return; }
php
protected function parseHeader($block) { if (!$block || strlen($block) != 512) { throw new ArchiveCorruptedException('Unexpected length of header'); } // null byte blocks are ignored if(trim($block) === '') return false; for ($i = 0, $chks = 0; $i < 148; $i++) { $chks += ord($block[$i]); } for ($i = 156, $chks += 256; $i < 512; $i++) { $chks += ord($block[$i]); } $header = @unpack( "a100filename/a8perm/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix", $block ); if (!$header) { throw new ArchiveCorruptedException('Failed to parse header'); } $return['checksum'] = OctDec(trim($header['checksum'])); if ($return['checksum'] != $chks) { throw new ArchiveCorruptedException('Header does not match it\'s checksum'); } $return['filename'] = trim($header['filename']); $return['perm'] = OctDec(trim($header['perm'])); $return['uid'] = OctDec(trim($header['uid'])); $return['gid'] = OctDec(trim($header['gid'])); $return['size'] = OctDec(trim($header['size'])); $return['mtime'] = OctDec(trim($header['mtime'])); $return['typeflag'] = $header['typeflag']; $return['link'] = trim($header['link']); $return['uname'] = trim($header['uname']); $return['gname'] = trim($header['gname']); // Handle ustar Posix compliant path prefixes if (trim($header['prefix'])) { $return['filename'] = trim($header['prefix']).'/'.$return['filename']; } // Handle Long-Link entries from GNU Tar if ($return['typeflag'] == 'L') { // following data block(s) is the filename $filename = trim($this->readbytes(ceil($return['size'] / 512) * 512)); // next block is the real header $block = $this->readbytes(512); $return = $this->parseHeader($block); // overwrite the filename $return['filename'] = $filename; } return $return; }
[ "protected", "function", "parseHeader", "(", "$", "block", ")", "{", "if", "(", "!", "$", "block", "||", "strlen", "(", "$", "block", ")", "!=", "512", ")", "{", "throw", "new", "ArchiveCorruptedException", "(", "'Unexpected length of header'", ")", ";", "}", "// null byte blocks are ignored", "if", "(", "trim", "(", "$", "block", ")", "===", "''", ")", "return", "false", ";", "for", "(", "$", "i", "=", "0", ",", "$", "chks", "=", "0", ";", "$", "i", "<", "148", ";", "$", "i", "++", ")", "{", "$", "chks", "+=", "ord", "(", "$", "block", "[", "$", "i", "]", ")", ";", "}", "for", "(", "$", "i", "=", "156", ",", "$", "chks", "+=", "256", ";", "$", "i", "<", "512", ";", "$", "i", "++", ")", "{", "$", "chks", "+=", "ord", "(", "$", "block", "[", "$", "i", "]", ")", ";", "}", "$", "header", "=", "@", "unpack", "(", "\"a100filename/a8perm/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor/a155prefix\"", ",", "$", "block", ")", ";", "if", "(", "!", "$", "header", ")", "{", "throw", "new", "ArchiveCorruptedException", "(", "'Failed to parse header'", ")", ";", "}", "$", "return", "[", "'checksum'", "]", "=", "OctDec", "(", "trim", "(", "$", "header", "[", "'checksum'", "]", ")", ")", ";", "if", "(", "$", "return", "[", "'checksum'", "]", "!=", "$", "chks", ")", "{", "throw", "new", "ArchiveCorruptedException", "(", "'Header does not match it\\'s checksum'", ")", ";", "}", "$", "return", "[", "'filename'", "]", "=", "trim", "(", "$", "header", "[", "'filename'", "]", ")", ";", "$", "return", "[", "'perm'", "]", "=", "OctDec", "(", "trim", "(", "$", "header", "[", "'perm'", "]", ")", ")", ";", "$", "return", "[", "'uid'", "]", "=", "OctDec", "(", "trim", "(", "$", "header", "[", "'uid'", "]", ")", ")", ";", "$", "return", "[", "'gid'", "]", "=", "OctDec", "(", "trim", "(", "$", "header", "[", "'gid'", "]", ")", ")", ";", "$", "return", "[", "'size'", "]", "=", "OctDec", "(", "trim", "(", "$", "header", "[", "'size'", "]", ")", ")", ";", "$", "return", "[", "'mtime'", "]", "=", "OctDec", "(", "trim", "(", "$", "header", "[", "'mtime'", "]", ")", ")", ";", "$", "return", "[", "'typeflag'", "]", "=", "$", "header", "[", "'typeflag'", "]", ";", "$", "return", "[", "'link'", "]", "=", "trim", "(", "$", "header", "[", "'link'", "]", ")", ";", "$", "return", "[", "'uname'", "]", "=", "trim", "(", "$", "header", "[", "'uname'", "]", ")", ";", "$", "return", "[", "'gname'", "]", "=", "trim", "(", "$", "header", "[", "'gname'", "]", ")", ";", "// Handle ustar Posix compliant path prefixes", "if", "(", "trim", "(", "$", "header", "[", "'prefix'", "]", ")", ")", "{", "$", "return", "[", "'filename'", "]", "=", "trim", "(", "$", "header", "[", "'prefix'", "]", ")", ".", "'/'", ".", "$", "return", "[", "'filename'", "]", ";", "}", "// Handle Long-Link entries from GNU Tar", "if", "(", "$", "return", "[", "'typeflag'", "]", "==", "'L'", ")", "{", "// following data block(s) is the filename", "$", "filename", "=", "trim", "(", "$", "this", "->", "readbytes", "(", "ceil", "(", "$", "return", "[", "'size'", "]", "/", "512", ")", "*", "512", ")", ")", ";", "// next block is the real header", "$", "block", "=", "$", "this", "->", "readbytes", "(", "512", ")", ";", "$", "return", "=", "$", "this", "->", "parseHeader", "(", "$", "block", ")", ";", "// overwrite the filename", "$", "return", "[", "'filename'", "]", "=", "$", "filename", ";", "}", "return", "$", "return", ";", "}" ]
Decode the given tar file header @param string $block a 512 byte block containing the header data @return array|false returns false when this was a null block @throws ArchiveCorruptedException
[ "Decode", "the", "given", "tar", "file", "header" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L559-L617
37,944
splitbrain/php-archive
src/Tar.php
Tar.header2fileinfo
protected function header2fileinfo($header) { $fileinfo = new FileInfo(); $fileinfo->setPath($header['filename']); $fileinfo->setMode($header['perm']); $fileinfo->setUid($header['uid']); $fileinfo->setGid($header['gid']); $fileinfo->setSize($header['size']); $fileinfo->setMtime($header['mtime']); $fileinfo->setOwner($header['uname']); $fileinfo->setGroup($header['gname']); $fileinfo->setIsdir((bool) $header['typeflag']); return $fileinfo; }
php
protected function header2fileinfo($header) { $fileinfo = new FileInfo(); $fileinfo->setPath($header['filename']); $fileinfo->setMode($header['perm']); $fileinfo->setUid($header['uid']); $fileinfo->setGid($header['gid']); $fileinfo->setSize($header['size']); $fileinfo->setMtime($header['mtime']); $fileinfo->setOwner($header['uname']); $fileinfo->setGroup($header['gname']); $fileinfo->setIsdir((bool) $header['typeflag']); return $fileinfo; }
[ "protected", "function", "header2fileinfo", "(", "$", "header", ")", "{", "$", "fileinfo", "=", "new", "FileInfo", "(", ")", ";", "$", "fileinfo", "->", "setPath", "(", "$", "header", "[", "'filename'", "]", ")", ";", "$", "fileinfo", "->", "setMode", "(", "$", "header", "[", "'perm'", "]", ")", ";", "$", "fileinfo", "->", "setUid", "(", "$", "header", "[", "'uid'", "]", ")", ";", "$", "fileinfo", "->", "setGid", "(", "$", "header", "[", "'gid'", "]", ")", ";", "$", "fileinfo", "->", "setSize", "(", "$", "header", "[", "'size'", "]", ")", ";", "$", "fileinfo", "->", "setMtime", "(", "$", "header", "[", "'mtime'", "]", ")", ";", "$", "fileinfo", "->", "setOwner", "(", "$", "header", "[", "'uname'", "]", ")", ";", "$", "fileinfo", "->", "setGroup", "(", "$", "header", "[", "'gname'", "]", ")", ";", "$", "fileinfo", "->", "setIsdir", "(", "(", "bool", ")", "$", "header", "[", "'typeflag'", "]", ")", ";", "return", "$", "fileinfo", ";", "}" ]
Creates a FileInfo object from the given parsed header @param $header @return FileInfo
[ "Creates", "a", "FileInfo", "object", "from", "the", "given", "parsed", "header" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L625-L639
37,945
splitbrain/php-archive
src/Tar.php
Tar.compressioncheck
protected function compressioncheck($comptype) { if ($comptype === Archive::COMPRESS_GZIP && !function_exists('gzopen')) { throw new ArchiveIllegalCompressionException('No gzip support available'); } if ($comptype === Archive::COMPRESS_BZIP && !function_exists('bzopen')) { throw new ArchiveIllegalCompressionException('No bzip2 support available'); } }
php
protected function compressioncheck($comptype) { if ($comptype === Archive::COMPRESS_GZIP && !function_exists('gzopen')) { throw new ArchiveIllegalCompressionException('No gzip support available'); } if ($comptype === Archive::COMPRESS_BZIP && !function_exists('bzopen')) { throw new ArchiveIllegalCompressionException('No bzip2 support available'); } }
[ "protected", "function", "compressioncheck", "(", "$", "comptype", ")", "{", "if", "(", "$", "comptype", "===", "Archive", "::", "COMPRESS_GZIP", "&&", "!", "function_exists", "(", "'gzopen'", ")", ")", "{", "throw", "new", "ArchiveIllegalCompressionException", "(", "'No gzip support available'", ")", ";", "}", "if", "(", "$", "comptype", "===", "Archive", "::", "COMPRESS_BZIP", "&&", "!", "function_exists", "(", "'bzopen'", ")", ")", "{", "throw", "new", "ArchiveIllegalCompressionException", "(", "'No bzip2 support available'", ")", ";", "}", "}" ]
Checks if the given compression type is available and throws an exception if not @param $comptype @throws ArchiveIllegalCompressionException
[ "Checks", "if", "the", "given", "compression", "type", "is", "available", "and", "throws", "an", "exception", "if", "not" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L647-L656
37,946
splitbrain/php-archive
src/Tar.php
Tar.filetype
public function filetype($file) { // for existing files, try to read the magic bytes if(file_exists($file) && is_readable($file) && filesize($file) > 5) { $fh = @fopen($file, 'rb'); if(!$fh) return false; $magic = fread($fh, 5); fclose($fh); if(strpos($magic, "\x42\x5a") === 0) return Archive::COMPRESS_BZIP; if(strpos($magic, "\x1f\x8b") === 0) return Archive::COMPRESS_GZIP; } // otherwise rely on file name $file = strtolower($file); if (substr($file, -3) == '.gz' || substr($file, -4) == '.tgz') { return Archive::COMPRESS_GZIP; } elseif (substr($file, -4) == '.bz2' || substr($file, -4) == '.tbz') { return Archive::COMPRESS_BZIP; } return Archive::COMPRESS_NONE; }
php
public function filetype($file) { // for existing files, try to read the magic bytes if(file_exists($file) && is_readable($file) && filesize($file) > 5) { $fh = @fopen($file, 'rb'); if(!$fh) return false; $magic = fread($fh, 5); fclose($fh); if(strpos($magic, "\x42\x5a") === 0) return Archive::COMPRESS_BZIP; if(strpos($magic, "\x1f\x8b") === 0) return Archive::COMPRESS_GZIP; } // otherwise rely on file name $file = strtolower($file); if (substr($file, -3) == '.gz' || substr($file, -4) == '.tgz') { return Archive::COMPRESS_GZIP; } elseif (substr($file, -4) == '.bz2' || substr($file, -4) == '.tbz') { return Archive::COMPRESS_BZIP; } return Archive::COMPRESS_NONE; }
[ "public", "function", "filetype", "(", "$", "file", ")", "{", "// for existing files, try to read the magic bytes", "if", "(", "file_exists", "(", "$", "file", ")", "&&", "is_readable", "(", "$", "file", ")", "&&", "filesize", "(", "$", "file", ")", ">", "5", ")", "{", "$", "fh", "=", "@", "fopen", "(", "$", "file", ",", "'rb'", ")", ";", "if", "(", "!", "$", "fh", ")", "return", "false", ";", "$", "magic", "=", "fread", "(", "$", "fh", ",", "5", ")", ";", "fclose", "(", "$", "fh", ")", ";", "if", "(", "strpos", "(", "$", "magic", ",", "\"\\x42\\x5a\"", ")", "===", "0", ")", "return", "Archive", "::", "COMPRESS_BZIP", ";", "if", "(", "strpos", "(", "$", "magic", ",", "\"\\x1f\\x8b\"", ")", "===", "0", ")", "return", "Archive", "::", "COMPRESS_GZIP", ";", "}", "// otherwise rely on file name", "$", "file", "=", "strtolower", "(", "$", "file", ")", ";", "if", "(", "substr", "(", "$", "file", ",", "-", "3", ")", "==", "'.gz'", "||", "substr", "(", "$", "file", ",", "-", "4", ")", "==", "'.tgz'", ")", "{", "return", "Archive", "::", "COMPRESS_GZIP", ";", "}", "elseif", "(", "substr", "(", "$", "file", ",", "-", "4", ")", "==", "'.bz2'", "||", "substr", "(", "$", "file", ",", "-", "4", ")", "==", "'.tbz'", ")", "{", "return", "Archive", "::", "COMPRESS_BZIP", ";", "}", "return", "Archive", "::", "COMPRESS_NONE", ";", "}" ]
Guesses the wanted compression from the given file Uses magic bytes for existing files, the file extension otherwise You don't need to call this yourself. It's used when you pass Archive::COMPRESS_AUTO somewhere @param string $file @return int
[ "Guesses", "the", "wanted", "compression", "from", "the", "given", "file" ]
10d89013572ba1f4d4ad7fcb74860242f4c3860b
https://github.com/splitbrain/php-archive/blob/10d89013572ba1f4d4ad7fcb74860242f4c3860b/src/Tar.php#L668-L690
37,947
pyaesone17/active-state
src/Active.php
Active.checkActiveDeeply
protected function checkActiveDeeply($url,$method) { if(is_array($url)) { foreach ($url as $value) { $urls[] = $value.'*'; } return call_user_func_array(array($this->request,$method), $urls) ? $this->activeValue : $this->inActiveValue; } else { return $this->request->is($url) || $this->request->is($url . '/*') ? $this->activeValue : $this->inActiveValue; } }
php
protected function checkActiveDeeply($url,$method) { if(is_array($url)) { foreach ($url as $value) { $urls[] = $value.'*'; } return call_user_func_array(array($this->request,$method), $urls) ? $this->activeValue : $this->inActiveValue; } else { return $this->request->is($url) || $this->request->is($url . '/*') ? $this->activeValue : $this->inActiveValue; } }
[ "protected", "function", "checkActiveDeeply", "(", "$", "url", ",", "$", "method", ")", "{", "if", "(", "is_array", "(", "$", "url", ")", ")", "{", "foreach", "(", "$", "url", "as", "$", "value", ")", "{", "$", "urls", "[", "]", "=", "$", "value", ".", "'*'", ";", "}", "return", "call_user_func_array", "(", "array", "(", "$", "this", "->", "request", ",", "$", "method", ")", ",", "$", "urls", ")", "?", "$", "this", "->", "activeValue", ":", "$", "this", "->", "inActiveValue", ";", "}", "else", "{", "return", "$", "this", "->", "request", "->", "is", "(", "$", "url", ")", "||", "$", "this", "->", "request", "->", "is", "(", "$", "url", ".", "'/*'", ")", "?", "$", "this", "->", "activeValue", ":", "$", "this", "->", "inActiveValue", ";", "}", "}" ]
It checks the active state of given url deeply @param string $url < url point to check > @return string it returns wherether the state is active or no
[ "It", "checks", "the", "active", "state", "of", "given", "url", "deeply" ]
4ebeef35fe0d533e63b63de2c4774635b2783877
https://github.com/pyaesone17/active-state/blob/4ebeef35fe0d533e63b63de2c4774635b2783877/src/Active.php#L99-L107
37,948
pyaesone17/active-state
src/Active.php
Active.checkActive
protected function checkActive($url,$method) { if(is_array($url)){ return call_user_func_array(array($this->request,$method), $url) ? $this->activeValue : $this->inActiveValue; } else{ return $this->request->{$method}($url) ? $this->activeValue : $this->inActiveValue; } }
php
protected function checkActive($url,$method) { if(is_array($url)){ return call_user_func_array(array($this->request,$method), $url) ? $this->activeValue : $this->inActiveValue; } else{ return $this->request->{$method}($url) ? $this->activeValue : $this->inActiveValue; } }
[ "protected", "function", "checkActive", "(", "$", "url", ",", "$", "method", ")", "{", "if", "(", "is_array", "(", "$", "url", ")", ")", "{", "return", "call_user_func_array", "(", "array", "(", "$", "this", "->", "request", ",", "$", "method", ")", ",", "$", "url", ")", "?", "$", "this", "->", "activeValue", ":", "$", "this", "->", "inActiveValue", ";", "}", "else", "{", "return", "$", "this", "->", "request", "->", "{", "$", "method", "}", "(", "$", "url", ")", "?", "$", "this", "->", "activeValue", ":", "$", "this", "->", "inActiveValue", ";", "}", "}" ]
It checks the active state of given url specificly @param string $url < url point to check > @return string it returns wherether the state is active or no
[ "It", "checks", "the", "active", "state", "of", "given", "url", "specificly" ]
4ebeef35fe0d533e63b63de2c4774635b2783877
https://github.com/pyaesone17/active-state/blob/4ebeef35fe0d533e63b63de2c4774635b2783877/src/Active.php#L113-L120
37,949
sebbmeyer/php-microsoft-teams-connector
src/TeamsConnector.php
TeamsConnector.send
public function send(TeamsConnectorInterface $card) { $json = json_encode($card->getMessage()); $ch = curl_init($this->webhookUrl); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Content-Length: ' . strlen($json) ]); $result = curl_exec($ch); if ($result !== "1") { throw new \Exception($result); } }
php
public function send(TeamsConnectorInterface $card) { $json = json_encode($card->getMessage()); $ch = curl_init($this->webhookUrl); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json', 'Content-Length: ' . strlen($json) ]); $result = curl_exec($ch); if ($result !== "1") { throw new \Exception($result); } }
[ "public", "function", "send", "(", "TeamsConnectorInterface", "$", "card", ")", "{", "$", "json", "=", "json_encode", "(", "$", "card", "->", "getMessage", "(", ")", ")", ";", "$", "ch", "=", "curl_init", "(", "$", "this", "->", "webhookUrl", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_CUSTOMREQUEST", ",", "'POST'", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_POSTFIELDS", ",", "$", "json", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_TIMEOUT", ",", "10", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_CONNECTTIMEOUT", ",", "3", ")", ";", "curl_setopt", "(", "$", "ch", ",", "CURLOPT_HTTPHEADER", ",", "[", "'Content-Type: application/json'", ",", "'Content-Length: '", ".", "strlen", "(", "$", "json", ")", "]", ")", ";", "$", "result", "=", "curl_exec", "(", "$", "ch", ")", ";", "if", "(", "$", "result", "!==", "\"1\"", ")", "{", "throw", "new", "\\", "Exception", "(", "$", "result", ")", ";", "}", "}" ]
Sends card message as POST request @param TeamsConnectorInterface $card @throws Exception
[ "Sends", "card", "message", "as", "POST", "request" ]
8a43c54c7ec792ffa9c5577bcc5a0bd266faba28
https://github.com/sebbmeyer/php-microsoft-teams-connector/blob/8a43c54c7ec792ffa9c5577bcc5a0bd266faba28/src/TeamsConnector.php#L23-L43
37,950
fxpio/fxp-resource
Domain/BaseDomain.php
BaseDomain.doAutoCommitFlushTransaction
protected function doAutoCommitFlushTransaction(ResourceInterface $resource, $autoCommit, $skipped = false) { $hasFlushError = $resource->getErrors()->count() > 0; if ($autoCommit && !$skipped && !$hasFlushError) { $rErrors = $this->flushTransaction($resource->getRealData()); $resource->getErrors()->addAll($rErrors); $hasFlushError = $rErrors->count() > 0; } return $hasFlushError; }
php
protected function doAutoCommitFlushTransaction(ResourceInterface $resource, $autoCommit, $skipped = false) { $hasFlushError = $resource->getErrors()->count() > 0; if ($autoCommit && !$skipped && !$hasFlushError) { $rErrors = $this->flushTransaction($resource->getRealData()); $resource->getErrors()->addAll($rErrors); $hasFlushError = $rErrors->count() > 0; } return $hasFlushError; }
[ "protected", "function", "doAutoCommitFlushTransaction", "(", "ResourceInterface", "$", "resource", ",", "$", "autoCommit", ",", "$", "skipped", "=", "false", ")", "{", "$", "hasFlushError", "=", "$", "resource", "->", "getErrors", "(", ")", "->", "count", "(", ")", ">", "0", ";", "if", "(", "$", "autoCommit", "&&", "!", "$", "skipped", "&&", "!", "$", "hasFlushError", ")", "{", "$", "rErrors", "=", "$", "this", "->", "flushTransaction", "(", "$", "resource", "->", "getRealData", "(", ")", ")", ";", "$", "resource", "->", "getErrors", "(", ")", "->", "addAll", "(", "$", "rErrors", ")", ";", "$", "hasFlushError", "=", "$", "rErrors", "->", "count", "(", ")", ">", "0", ";", "}", "return", "$", "hasFlushError", ";", "}" ]
Do the flush transaction for auto commit. @param ResourceInterface $resource The resource @param bool $autoCommit The auto commit @param bool $skipped Check if the resource is skipped @return bool Returns if there is an flush error
[ "Do", "the", "flush", "transaction", "for", "auto", "commit", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L39-L50
37,951
fxpio/fxp-resource
Domain/BaseDomain.php
BaseDomain.doFlushFinalTransaction
protected function doFlushFinalTransaction(ResourceListInterface $resources, $autoCommit, $hasError): void { if (!$autoCommit) { if ($hasError) { $this->cancelTransaction(); DomainUtil::cancelAllSuccessResources($resources); } else { $errors = $this->flushTransaction(); DomainUtil::moveFlushErrorsInResource($resources, $errors); } } }
php
protected function doFlushFinalTransaction(ResourceListInterface $resources, $autoCommit, $hasError): void { if (!$autoCommit) { if ($hasError) { $this->cancelTransaction(); DomainUtil::cancelAllSuccessResources($resources); } else { $errors = $this->flushTransaction(); DomainUtil::moveFlushErrorsInResource($resources, $errors); } } }
[ "protected", "function", "doFlushFinalTransaction", "(", "ResourceListInterface", "$", "resources", ",", "$", "autoCommit", ",", "$", "hasError", ")", ":", "void", "{", "if", "(", "!", "$", "autoCommit", ")", "{", "if", "(", "$", "hasError", ")", "{", "$", "this", "->", "cancelTransaction", "(", ")", ";", "DomainUtil", "::", "cancelAllSuccessResources", "(", "$", "resources", ")", ";", "}", "else", "{", "$", "errors", "=", "$", "this", "->", "flushTransaction", "(", ")", ";", "DomainUtil", "::", "moveFlushErrorsInResource", "(", "$", "resources", ",", "$", "errors", ")", ";", "}", "}", "}" ]
Do flush the final transaction for non auto commit. @param ResourceListInterface $resources The list of object resource instance @param bool $autoCommit Commit transaction for each resource or all (continue the action even if there is an error on a resource) @param bool $hasError Check if there is an error
[ "Do", "flush", "the", "final", "transaction", "for", "non", "auto", "commit", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L60-L71
37,952
fxpio/fxp-resource
Domain/BaseDomain.php
BaseDomain.finalizeResourceStatus
protected function finalizeResourceStatus(ResourceInterface $resource, $status, $hasError) { if ($resource->isValid()) { $resource->setStatus($status); } else { $hasError = true; $resource->setStatus(ResourceStatutes::ERROR); $this->om->detach($resource->getRealData()); } return $hasError; }
php
protected function finalizeResourceStatus(ResourceInterface $resource, $status, $hasError) { if ($resource->isValid()) { $resource->setStatus($status); } else { $hasError = true; $resource->setStatus(ResourceStatutes::ERROR); $this->om->detach($resource->getRealData()); } return $hasError; }
[ "protected", "function", "finalizeResourceStatus", "(", "ResourceInterface", "$", "resource", ",", "$", "status", ",", "$", "hasError", ")", "{", "if", "(", "$", "resource", "->", "isValid", "(", ")", ")", "{", "$", "resource", "->", "setStatus", "(", "$", "status", ")", ";", "}", "else", "{", "$", "hasError", "=", "true", ";", "$", "resource", "->", "setStatus", "(", "ResourceStatutes", "::", "ERROR", ")", ";", "$", "this", "->", "om", "->", "detach", "(", "$", "resource", "->", "getRealData", "(", ")", ")", ";", "}", "return", "$", "hasError", ";", "}" ]
Finalize the action for a resource. @param ResourceInterface $resource @param string $status @param bool $hasError @return bool Returns the new hasError value
[ "Finalize", "the", "action", "for", "a", "resource", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L82-L93
37,953
fxpio/fxp-resource
Domain/BaseDomain.php
BaseDomain.beginTransaction
protected function beginTransaction($autoCommit = false): void { if (!$autoCommit && null !== $this->connection) { $this->connection->beginTransaction(); } }
php
protected function beginTransaction($autoCommit = false): void { if (!$autoCommit && null !== $this->connection) { $this->connection->beginTransaction(); } }
[ "protected", "function", "beginTransaction", "(", "$", "autoCommit", "=", "false", ")", ":", "void", "{", "if", "(", "!", "$", "autoCommit", "&&", "null", "!==", "$", "this", "->", "connection", ")", "{", "$", "this", "->", "connection", "->", "beginTransaction", "(", ")", ";", "}", "}" ]
Begin automatically the database transaction. @param bool $autoCommit Check if each resource must be flushed immediately or in the end
[ "Begin", "automatically", "the", "database", "transaction", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L100-L105
37,954
fxpio/fxp-resource
Domain/BaseDomain.php
BaseDomain.flushTransaction
protected function flushTransaction($object = null) { $violations = new ConstraintViolationList(); try { $this->om->flush(); if (null !== $this->connection && null === $object) { $this->connection->commit(); } } catch (\Exception $e) { $this->flushTransactionException($e, $violations, $object); } return $violations; }
php
protected function flushTransaction($object = null) { $violations = new ConstraintViolationList(); try { $this->om->flush(); if (null !== $this->connection && null === $object) { $this->connection->commit(); } } catch (\Exception $e) { $this->flushTransactionException($e, $violations, $object); } return $violations; }
[ "protected", "function", "flushTransaction", "(", "$", "object", "=", "null", ")", "{", "$", "violations", "=", "new", "ConstraintViolationList", "(", ")", ";", "try", "{", "$", "this", "->", "om", "->", "flush", "(", ")", ";", "if", "(", "null", "!==", "$", "this", "->", "connection", "&&", "null", "===", "$", "object", ")", "{", "$", "this", "->", "connection", "->", "commit", "(", ")", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "flushTransactionException", "(", "$", "e", ",", "$", "violations", ",", "$", "object", ")", ";", "}", "return", "$", "violations", ";", "}" ]
Flush data in database with automatic declaration of the transaction for the collection. @param null|object $object The resource for auto commit or null for flush at the end @return ConstraintViolationList
[ "Flush", "data", "in", "database", "with", "automatic", "declaration", "of", "the", "transaction", "for", "the", "collection", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L114-L129
37,955
fxpio/fxp-resource
Domain/BaseDomain.php
BaseDomain.flushTransactionException
protected function flushTransactionException(\Exception $e, ConstraintViolationListInterface $violations, $object = null): void { if (null !== $this->connection && null === $object) { $this->connection->rollback(); } if ($e instanceof ConstraintViolationException) { $violations->addAll($e->getConstraintViolations()); } else { $message = DomainUtil::getExceptionMessage($this->translator, $e, $this->debug); $violations->add(new ConstraintViolation($message, $message, [], $object, null, null)); } }
php
protected function flushTransactionException(\Exception $e, ConstraintViolationListInterface $violations, $object = null): void { if (null !== $this->connection && null === $object) { $this->connection->rollback(); } if ($e instanceof ConstraintViolationException) { $violations->addAll($e->getConstraintViolations()); } else { $message = DomainUtil::getExceptionMessage($this->translator, $e, $this->debug); $violations->add(new ConstraintViolation($message, $message, [], $object, null, null)); } }
[ "protected", "function", "flushTransactionException", "(", "\\", "Exception", "$", "e", ",", "ConstraintViolationListInterface", "$", "violations", ",", "$", "object", "=", "null", ")", ":", "void", "{", "if", "(", "null", "!==", "$", "this", "->", "connection", "&&", "null", "===", "$", "object", ")", "{", "$", "this", "->", "connection", "->", "rollback", "(", ")", ";", "}", "if", "(", "$", "e", "instanceof", "ConstraintViolationException", ")", "{", "$", "violations", "->", "addAll", "(", "$", "e", "->", "getConstraintViolations", "(", ")", ")", ";", "}", "else", "{", "$", "message", "=", "DomainUtil", "::", "getExceptionMessage", "(", "$", "this", "->", "translator", ",", "$", "e", ",", "$", "this", "->", "debug", ")", ";", "$", "violations", "->", "add", "(", "new", "ConstraintViolation", "(", "$", "message", ",", "$", "message", ",", "[", "]", ",", "$", "object", ",", "null", ",", "null", ")", ")", ";", "}", "}" ]
Do the action when there is an exception on flush transaction. @param \Exception $e The exception on flush transaction @param ConstraintViolationListInterface $violations The constraint violation list @param null|object $object The resource for auto commit or null for flush at the end @throws
[ "Do", "the", "action", "when", "there", "is", "an", "exception", "on", "flush", "transaction", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L140-L153
37,956
fxpio/fxp-resource
Domain/BaseDomain.php
BaseDomain.validateResource
protected function validateResource($resource, $type): void { if (!$resource->isValid()) { return; } $idError = $this->getErrorIdentifier($resource->getRealData(), $type); $data = $resource->getData(); if ($data instanceof FormInterface) { if (!$data->isSubmitted()) { $data->submit([]); } } else { $errors = $this->validator->validate($data); $resource->getErrors()->addAll($errors); } if (null !== $idError) { $resource->getErrors()->add(new ConstraintViolation($idError, $idError, [], $resource->getRealData(), null, null)); } }
php
protected function validateResource($resource, $type): void { if (!$resource->isValid()) { return; } $idError = $this->getErrorIdentifier($resource->getRealData(), $type); $data = $resource->getData(); if ($data instanceof FormInterface) { if (!$data->isSubmitted()) { $data->submit([]); } } else { $errors = $this->validator->validate($data); $resource->getErrors()->addAll($errors); } if (null !== $idError) { $resource->getErrors()->add(new ConstraintViolation($idError, $idError, [], $resource->getRealData(), null, null)); } }
[ "protected", "function", "validateResource", "(", "$", "resource", ",", "$", "type", ")", ":", "void", "{", "if", "(", "!", "$", "resource", "->", "isValid", "(", ")", ")", "{", "return", ";", "}", "$", "idError", "=", "$", "this", "->", "getErrorIdentifier", "(", "$", "resource", "->", "getRealData", "(", ")", ",", "$", "type", ")", ";", "$", "data", "=", "$", "resource", "->", "getData", "(", ")", ";", "if", "(", "$", "data", "instanceof", "FormInterface", ")", "{", "if", "(", "!", "$", "data", "->", "isSubmitted", "(", ")", ")", "{", "$", "data", "->", "submit", "(", "[", "]", ")", ";", "}", "}", "else", "{", "$", "errors", "=", "$", "this", "->", "validator", "->", "validate", "(", "$", "data", ")", ";", "$", "resource", "->", "getErrors", "(", ")", "->", "addAll", "(", "$", "errors", ")", ";", "}", "if", "(", "null", "!==", "$", "idError", ")", "{", "$", "resource", "->", "getErrors", "(", ")", "->", "add", "(", "new", "ConstraintViolation", "(", "$", "idError", ",", "$", "idError", ",", "[", "]", ",", "$", "resource", "->", "getRealData", "(", ")", ",", "null", ",", "null", ")", ")", ";", "}", "}" ]
Validate the resource and get the error list. @param ResourceInterface $resource The resource @param int $type The type of persist
[ "Validate", "the", "resource", "and", "get", "the", "error", "list", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L173-L194
37,957
fxpio/fxp-resource
Domain/BaseDomain.php
BaseDomain.getErrorIdentifier
protected function getErrorIdentifier($object, $type) { $idValue = DomainUtil::getIdentifier($this->om, $object); $idError = null; if (Domain::TYPE_CREATE === $type && null !== $idValue) { $idError = $this->translator->trans('domain.identifier.error_create', [], 'FxpResource'); } elseif (Domain::TYPE_UPDATE === $type && null === $idValue) { $idError = $this->translator->trans('domain.identifier.error_update', [], 'FxpResource'); } elseif (Domain::TYPE_DELETE === $type && null === $idValue) { $idError = $this->translator->trans('domain.identifier.error_delete', [], 'FxpResource'); } elseif (Domain::TYPE_UNDELETE === $type && null === $idValue) { $idError = $this->translator->trans('domain.identifier.error_undeleted', [], 'FxpResource'); } return $idError; }
php
protected function getErrorIdentifier($object, $type) { $idValue = DomainUtil::getIdentifier($this->om, $object); $idError = null; if (Domain::TYPE_CREATE === $type && null !== $idValue) { $idError = $this->translator->trans('domain.identifier.error_create', [], 'FxpResource'); } elseif (Domain::TYPE_UPDATE === $type && null === $idValue) { $idError = $this->translator->trans('domain.identifier.error_update', [], 'FxpResource'); } elseif (Domain::TYPE_DELETE === $type && null === $idValue) { $idError = $this->translator->trans('domain.identifier.error_delete', [], 'FxpResource'); } elseif (Domain::TYPE_UNDELETE === $type && null === $idValue) { $idError = $this->translator->trans('domain.identifier.error_undeleted', [], 'FxpResource'); } return $idError; }
[ "protected", "function", "getErrorIdentifier", "(", "$", "object", ",", "$", "type", ")", "{", "$", "idValue", "=", "DomainUtil", "::", "getIdentifier", "(", "$", "this", "->", "om", ",", "$", "object", ")", ";", "$", "idError", "=", "null", ";", "if", "(", "Domain", "::", "TYPE_CREATE", "===", "$", "type", "&&", "null", "!==", "$", "idValue", ")", "{", "$", "idError", "=", "$", "this", "->", "translator", "->", "trans", "(", "'domain.identifier.error_create'", ",", "[", "]", ",", "'FxpResource'", ")", ";", "}", "elseif", "(", "Domain", "::", "TYPE_UPDATE", "===", "$", "type", "&&", "null", "===", "$", "idValue", ")", "{", "$", "idError", "=", "$", "this", "->", "translator", "->", "trans", "(", "'domain.identifier.error_update'", ",", "[", "]", ",", "'FxpResource'", ")", ";", "}", "elseif", "(", "Domain", "::", "TYPE_DELETE", "===", "$", "type", "&&", "null", "===", "$", "idValue", ")", "{", "$", "idError", "=", "$", "this", "->", "translator", "->", "trans", "(", "'domain.identifier.error_delete'", ",", "[", "]", ",", "'FxpResource'", ")", ";", "}", "elseif", "(", "Domain", "::", "TYPE_UNDELETE", "===", "$", "type", "&&", "null", "===", "$", "idValue", ")", "{", "$", "idError", "=", "$", "this", "->", "translator", "->", "trans", "(", "'domain.identifier.error_undeleted'", ",", "[", "]", ",", "'FxpResource'", ")", ";", "}", "return", "$", "idError", ";", "}" ]
Get the error of identifier. @param object $object The object data @param int $type The type of persist @return null|string
[ "Get", "the", "error", "of", "identifier", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L204-L220
37,958
fxpio/fxp-resource
Domain/BaseDomain.php
BaseDomain.getSuccessStatus
protected function getSuccessStatus($type, $object) { if (Domain::TYPE_CREATE === $type) { return ResourceStatutes::CREATED; } if (Domain::TYPE_UPDATE === $type) { return ResourceStatutes::UPDATED; } if (Domain::TYPE_UNDELETE === $type) { return ResourceStatutes::UNDELETED; } return null === DomainUtil::getIdentifier($this->om, $object) ? ResourceStatutes::CREATED : ResourceStatutes::UPDATED; }
php
protected function getSuccessStatus($type, $object) { if (Domain::TYPE_CREATE === $type) { return ResourceStatutes::CREATED; } if (Domain::TYPE_UPDATE === $type) { return ResourceStatutes::UPDATED; } if (Domain::TYPE_UNDELETE === $type) { return ResourceStatutes::UNDELETED; } return null === DomainUtil::getIdentifier($this->om, $object) ? ResourceStatutes::CREATED : ResourceStatutes::UPDATED; }
[ "protected", "function", "getSuccessStatus", "(", "$", "type", ",", "$", "object", ")", "{", "if", "(", "Domain", "::", "TYPE_CREATE", "===", "$", "type", ")", "{", "return", "ResourceStatutes", "::", "CREATED", ";", "}", "if", "(", "Domain", "::", "TYPE_UPDATE", "===", "$", "type", ")", "{", "return", "ResourceStatutes", "::", "UPDATED", ";", "}", "if", "(", "Domain", "::", "TYPE_UNDELETE", "===", "$", "type", ")", "{", "return", "ResourceStatutes", "::", "UNDELETED", ";", "}", "return", "null", "===", "DomainUtil", "::", "getIdentifier", "(", "$", "this", "->", "om", ",", "$", "object", ")", "?", "ResourceStatutes", "::", "CREATED", ":", "ResourceStatutes", "::", "UPDATED", ";", "}" ]
Get the success status. @param int $type The type of persist @param object $object The resource instance @return string
[ "Get", "the", "success", "status", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/BaseDomain.php#L230-L245
37,959
larriereguichet/AdminBundle
src/Event/Subscriber/MenuSubscriber.php
MenuSubscriber.buildMenus
public function buildMenus(MenuEvent $event) { if (!$this->applicationConfiguration->getParameter('enable_menus')) { return; } $menuConfigurations = array_merge_recursive( $this->adminMenuConfigurations, $event->getMenuConfigurations() ); $configurationEvent = new MenuConfigurationEvent($menuConfigurations); // Dispatch a pre-menu build event to allow dynamic configuration modifications $this ->eventDispatcher ->dispatch(Events::MENU_CONFIGURATION, $configurationEvent) ; $menuConfigurations = $configurationEvent->getMenuConfigurations(); foreach ($menuConfigurations as $name => $menuConfiguration) { $this->menuFactory->create($name, $menuConfiguration); } }
php
public function buildMenus(MenuEvent $event) { if (!$this->applicationConfiguration->getParameter('enable_menus')) { return; } $menuConfigurations = array_merge_recursive( $this->adminMenuConfigurations, $event->getMenuConfigurations() ); $configurationEvent = new MenuConfigurationEvent($menuConfigurations); // Dispatch a pre-menu build event to allow dynamic configuration modifications $this ->eventDispatcher ->dispatch(Events::MENU_CONFIGURATION, $configurationEvent) ; $menuConfigurations = $configurationEvent->getMenuConfigurations(); foreach ($menuConfigurations as $name => $menuConfiguration) { $this->menuFactory->create($name, $menuConfiguration); } }
[ "public", "function", "buildMenus", "(", "MenuEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "applicationConfiguration", "->", "getParameter", "(", "'enable_menus'", ")", ")", "{", "return", ";", "}", "$", "menuConfigurations", "=", "array_merge_recursive", "(", "$", "this", "->", "adminMenuConfigurations", ",", "$", "event", "->", "getMenuConfigurations", "(", ")", ")", ";", "$", "configurationEvent", "=", "new", "MenuConfigurationEvent", "(", "$", "menuConfigurations", ")", ";", "// Dispatch a pre-menu build event to allow dynamic configuration modifications", "$", "this", "->", "eventDispatcher", "->", "dispatch", "(", "Events", "::", "MENU_CONFIGURATION", ",", "$", "configurationEvent", ")", ";", "$", "menuConfigurations", "=", "$", "configurationEvent", "->", "getMenuConfigurations", "(", ")", ";", "foreach", "(", "$", "menuConfigurations", "as", "$", "name", "=>", "$", "menuConfiguration", ")", "{", "$", "this", "->", "menuFactory", "->", "create", "(", "$", "name", ",", "$", "menuConfiguration", ")", ";", "}", "}" ]
Build menus according to the given configuration. @param MenuEvent $event
[ "Build", "menus", "according", "to", "the", "given", "configuration", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/MenuSubscriber.php#L71-L92
37,960
Smart-Core/CoreBundle
Pagerfanta/DoctrineORM/LegacyPaginator.php
LegacyPaginator.cloneQuery
private function cloneQuery(Query $query) { /* @var $cloneQuery Query */ $cloneQuery = clone $query; $cloneQuery->setParameters($query->getParameters()); foreach ($query->getHints() as $name => $value) { $cloneQuery->setHint($name, $value); } return $cloneQuery; }
php
private function cloneQuery(Query $query) { /* @var $cloneQuery Query */ $cloneQuery = clone $query; $cloneQuery->setParameters($query->getParameters()); foreach ($query->getHints() as $name => $value) { $cloneQuery->setHint($name, $value); } return $cloneQuery; }
[ "private", "function", "cloneQuery", "(", "Query", "$", "query", ")", "{", "/* @var $cloneQuery Query */", "$", "cloneQuery", "=", "clone", "$", "query", ";", "$", "cloneQuery", "->", "setParameters", "(", "$", "query", "->", "getParameters", "(", ")", ")", ";", "foreach", "(", "$", "query", "->", "getHints", "(", ")", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "cloneQuery", "->", "setHint", "(", "$", "name", ",", "$", "value", ")", ";", "}", "return", "$", "cloneQuery", ";", "}" ]
Clones a query. @param Query $query The query. @return Query The cloned query.
[ "Clones", "a", "query", "." ]
d74829de254237008eb92ad213c7e7f41d91aac4
https://github.com/Smart-Core/CoreBundle/blob/d74829de254237008eb92ad213c7e7f41d91aac4/Pagerfanta/DoctrineORM/LegacyPaginator.php#L142-L152
37,961
fxpio/fxp-resource
ResourceList.php
ResourceList.getStatusValue
private function getStatusValue($countPending, $countCancel, $countError, $countSuccess) { $status = ResourceListStatutes::SUCCESSFULLY; $count = $this->count(); if ($count > 0) { $status = ResourceListStatutes::MIXED; if ($count === $countPending) { $status = ResourceListStatutes::PENDING; } elseif ($count === $countCancel) { $status = ResourceListStatutes::CANCEL; } elseif ($count === $countError) { $status = ResourceListStatutes::ERROR; } elseif ($count === $countSuccess) { $status = ResourceListStatutes::SUCCESSFULLY; } } return $status; }
php
private function getStatusValue($countPending, $countCancel, $countError, $countSuccess) { $status = ResourceListStatutes::SUCCESSFULLY; $count = $this->count(); if ($count > 0) { $status = ResourceListStatutes::MIXED; if ($count === $countPending) { $status = ResourceListStatutes::PENDING; } elseif ($count === $countCancel) { $status = ResourceListStatutes::CANCEL; } elseif ($count === $countError) { $status = ResourceListStatutes::ERROR; } elseif ($count === $countSuccess) { $status = ResourceListStatutes::SUCCESSFULLY; } } return $status; }
[ "private", "function", "getStatusValue", "(", "$", "countPending", ",", "$", "countCancel", ",", "$", "countError", ",", "$", "countSuccess", ")", "{", "$", "status", "=", "ResourceListStatutes", "::", "SUCCESSFULLY", ";", "$", "count", "=", "$", "this", "->", "count", "(", ")", ";", "if", "(", "$", "count", ">", "0", ")", "{", "$", "status", "=", "ResourceListStatutes", "::", "MIXED", ";", "if", "(", "$", "count", "===", "$", "countPending", ")", "{", "$", "status", "=", "ResourceListStatutes", "::", "PENDING", ";", "}", "elseif", "(", "$", "count", "===", "$", "countCancel", ")", "{", "$", "status", "=", "ResourceListStatutes", "::", "CANCEL", ";", "}", "elseif", "(", "$", "count", "===", "$", "countError", ")", "{", "$", "status", "=", "ResourceListStatutes", "::", "ERROR", ";", "}", "elseif", "(", "$", "count", "===", "$", "countSuccess", ")", "{", "$", "status", "=", "ResourceListStatutes", "::", "SUCCESSFULLY", ";", "}", "}", "return", "$", "status", ";", "}" ]
Get the final status value. @param int $countPending @param int $countCancel @param int $countError @param int $countSuccess @return string
[ "Get", "the", "final", "status", "value", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/ResourceList.php#L100-L120
37,962
larriereguichet/AdminBundle
src/Factory/ViewFactory.php
ViewFactory.create
public function create( Request $request, $actionName, $adminName, AdminConfiguration $adminConfiguration, ActionConfiguration $actionConfiguration, $entities, array $forms = [] ) { if (key_exists('entity', $forms)) { $form = $forms['entity']; if ($this->shouldRedirect($form, $request, $adminConfiguration)) { $routeName = RoutingLoader::generateRouteName( $adminName, 'list', $adminConfiguration->getParameter('routing_name_pattern') ); $url = $this->router->generate($routeName); $view = new RedirectView( $actionName, $adminName, $actionConfiguration, $adminConfiguration ); $view->setUrl($url); return $view; } } $fields = $this ->fieldFactory ->createFields($actionConfiguration) ; $formViews = []; foreach ($forms as $identifier => $form) { $formViews[$identifier] = $form->createView(); } $view = new View( $actionName, $adminName, $actionConfiguration, $adminConfiguration, $fields, $formViews ); $view->setEntities($entities); return $view; }
php
public function create( Request $request, $actionName, $adminName, AdminConfiguration $adminConfiguration, ActionConfiguration $actionConfiguration, $entities, array $forms = [] ) { if (key_exists('entity', $forms)) { $form = $forms['entity']; if ($this->shouldRedirect($form, $request, $adminConfiguration)) { $routeName = RoutingLoader::generateRouteName( $adminName, 'list', $adminConfiguration->getParameter('routing_name_pattern') ); $url = $this->router->generate($routeName); $view = new RedirectView( $actionName, $adminName, $actionConfiguration, $adminConfiguration ); $view->setUrl($url); return $view; } } $fields = $this ->fieldFactory ->createFields($actionConfiguration) ; $formViews = []; foreach ($forms as $identifier => $form) { $formViews[$identifier] = $form->createView(); } $view = new View( $actionName, $adminName, $actionConfiguration, $adminConfiguration, $fields, $formViews ); $view->setEntities($entities); return $view; }
[ "public", "function", "create", "(", "Request", "$", "request", ",", "$", "actionName", ",", "$", "adminName", ",", "AdminConfiguration", "$", "adminConfiguration", ",", "ActionConfiguration", "$", "actionConfiguration", ",", "$", "entities", ",", "array", "$", "forms", "=", "[", "]", ")", "{", "if", "(", "key_exists", "(", "'entity'", ",", "$", "forms", ")", ")", "{", "$", "form", "=", "$", "forms", "[", "'entity'", "]", ";", "if", "(", "$", "this", "->", "shouldRedirect", "(", "$", "form", ",", "$", "request", ",", "$", "adminConfiguration", ")", ")", "{", "$", "routeName", "=", "RoutingLoader", "::", "generateRouteName", "(", "$", "adminName", ",", "'list'", ",", "$", "adminConfiguration", "->", "getParameter", "(", "'routing_name_pattern'", ")", ")", ";", "$", "url", "=", "$", "this", "->", "router", "->", "generate", "(", "$", "routeName", ")", ";", "$", "view", "=", "new", "RedirectView", "(", "$", "actionName", ",", "$", "adminName", ",", "$", "actionConfiguration", ",", "$", "adminConfiguration", ")", ";", "$", "view", "->", "setUrl", "(", "$", "url", ")", ";", "return", "$", "view", ";", "}", "}", "$", "fields", "=", "$", "this", "->", "fieldFactory", "->", "createFields", "(", "$", "actionConfiguration", ")", ";", "$", "formViews", "=", "[", "]", ";", "foreach", "(", "$", "forms", "as", "$", "identifier", "=>", "$", "form", ")", "{", "$", "formViews", "[", "$", "identifier", "]", "=", "$", "form", "->", "createView", "(", ")", ";", "}", "$", "view", "=", "new", "View", "(", "$", "actionName", ",", "$", "adminName", ",", "$", "actionConfiguration", ",", "$", "adminConfiguration", ",", "$", "fields", ",", "$", "formViews", ")", ";", "$", "view", "->", "setEntities", "(", "$", "entities", ")", ";", "return", "$", "view", ";", "}" ]
Create a view for a given Admin and Action. @param Request $request @param string $actionName @param string $adminName @param AdminConfiguration $adminConfiguration @param ActionConfiguration $actionConfiguration @param $entities @param FormInterface[] $forms @return ViewInterface
[ "Create", "a", "view", "for", "a", "given", "Admin", "and", "Action", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/ViewFactory.php#L70-L121
37,963
larriereguichet/AdminBundle
src/Factory/FieldFactory.php
FieldFactory.create
public function create(string $name, array $configuration, ActionConfiguration $actionConfiguration): FieldInterface { $resolver = new OptionsResolver(); $configuration = $this->resolveConfiguration($configuration, $actionConfiguration); // Dispatch an event to allow dynamic changes on the form type $event = new FieldEvent( $actionConfiguration->getAdminName(), $actionConfiguration->getActionName(), $name, $actionConfiguration->getAdminConfiguration()->get('entity'), $configuration['type'] ); $this->eventDispatcher->dispatch(Events::FIELD_PRE_CREATE, $event); if (null === $event->getType()) { throw new FieldTypeNotFoundException($event->getAdminName(), $event->getActionName(), $name); } $type = $event->getType(); $options = array_merge($configuration['options'], $event->getOptions()); if (!key_exists($type, $this->fieldsMapping)) { $type = 'auto'; } $field = $this->instanciateField($name, $type); $field->configureOptions($resolver, $actionConfiguration); try { $field->setOptions($resolver->resolve($options)); } catch (\Exception $exception) { throw new Exception( 'An error has occurred when resolving the options for the field "'.$name.'": '.$exception->getMessage(), $exception->getCode(), $exception ); } $event = new FieldEvent( $actionConfiguration->getAdminName(), $actionConfiguration->getActionName(), $name, $actionConfiguration->getAdminConfiguration()->get('entity'), $type, $field ); $this->eventDispatcher->dispatch(Events::FIELD_POST_CREATE, $event); return $field; }
php
public function create(string $name, array $configuration, ActionConfiguration $actionConfiguration): FieldInterface { $resolver = new OptionsResolver(); $configuration = $this->resolveConfiguration($configuration, $actionConfiguration); // Dispatch an event to allow dynamic changes on the form type $event = new FieldEvent( $actionConfiguration->getAdminName(), $actionConfiguration->getActionName(), $name, $actionConfiguration->getAdminConfiguration()->get('entity'), $configuration['type'] ); $this->eventDispatcher->dispatch(Events::FIELD_PRE_CREATE, $event); if (null === $event->getType()) { throw new FieldTypeNotFoundException($event->getAdminName(), $event->getActionName(), $name); } $type = $event->getType(); $options = array_merge($configuration['options'], $event->getOptions()); if (!key_exists($type, $this->fieldsMapping)) { $type = 'auto'; } $field = $this->instanciateField($name, $type); $field->configureOptions($resolver, $actionConfiguration); try { $field->setOptions($resolver->resolve($options)); } catch (\Exception $exception) { throw new Exception( 'An error has occurred when resolving the options for the field "'.$name.'": '.$exception->getMessage(), $exception->getCode(), $exception ); } $event = new FieldEvent( $actionConfiguration->getAdminName(), $actionConfiguration->getActionName(), $name, $actionConfiguration->getAdminConfiguration()->get('entity'), $type, $field ); $this->eventDispatcher->dispatch(Events::FIELD_POST_CREATE, $event); return $field; }
[ "public", "function", "create", "(", "string", "$", "name", ",", "array", "$", "configuration", ",", "ActionConfiguration", "$", "actionConfiguration", ")", ":", "FieldInterface", "{", "$", "resolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "configuration", "=", "$", "this", "->", "resolveConfiguration", "(", "$", "configuration", ",", "$", "actionConfiguration", ")", ";", "// Dispatch an event to allow dynamic changes on the form type", "$", "event", "=", "new", "FieldEvent", "(", "$", "actionConfiguration", "->", "getAdminName", "(", ")", ",", "$", "actionConfiguration", "->", "getActionName", "(", ")", ",", "$", "name", ",", "$", "actionConfiguration", "->", "getAdminConfiguration", "(", ")", "->", "get", "(", "'entity'", ")", ",", "$", "configuration", "[", "'type'", "]", ")", ";", "$", "this", "->", "eventDispatcher", "->", "dispatch", "(", "Events", "::", "FIELD_PRE_CREATE", ",", "$", "event", ")", ";", "if", "(", "null", "===", "$", "event", "->", "getType", "(", ")", ")", "{", "throw", "new", "FieldTypeNotFoundException", "(", "$", "event", "->", "getAdminName", "(", ")", ",", "$", "event", "->", "getActionName", "(", ")", ",", "$", "name", ")", ";", "}", "$", "type", "=", "$", "event", "->", "getType", "(", ")", ";", "$", "options", "=", "array_merge", "(", "$", "configuration", "[", "'options'", "]", ",", "$", "event", "->", "getOptions", "(", ")", ")", ";", "if", "(", "!", "key_exists", "(", "$", "type", ",", "$", "this", "->", "fieldsMapping", ")", ")", "{", "$", "type", "=", "'auto'", ";", "}", "$", "field", "=", "$", "this", "->", "instanciateField", "(", "$", "name", ",", "$", "type", ")", ";", "$", "field", "->", "configureOptions", "(", "$", "resolver", ",", "$", "actionConfiguration", ")", ";", "try", "{", "$", "field", "->", "setOptions", "(", "$", "resolver", "->", "resolve", "(", "$", "options", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "exception", ")", "{", "throw", "new", "Exception", "(", "'An error has occurred when resolving the options for the field \"'", ".", "$", "name", ".", "'\": '", ".", "$", "exception", "->", "getMessage", "(", ")", ",", "$", "exception", "->", "getCode", "(", ")", ",", "$", "exception", ")", ";", "}", "$", "event", "=", "new", "FieldEvent", "(", "$", "actionConfiguration", "->", "getAdminName", "(", ")", ",", "$", "actionConfiguration", "->", "getActionName", "(", ")", ",", "$", "name", ",", "$", "actionConfiguration", "->", "getAdminConfiguration", "(", ")", "->", "get", "(", "'entity'", ")", ",", "$", "type", ",", "$", "field", ")", ";", "$", "this", "->", "eventDispatcher", "->", "dispatch", "(", "Events", "::", "FIELD_POST_CREATE", ",", "$", "event", ")", ";", "return", "$", "field", ";", "}" ]
Create a new field instance according to the given configuration. @param string $name @param array $configuration @param ActionConfiguration $actionConfiguration @return FieldInterface @throws Exception
[ "Create", "a", "new", "field", "instance", "according", "to", "the", "given", "configuration", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/FieldFactory.php#L117-L164
37,964
larriereguichet/AdminBundle
src/Factory/FieldFactory.php
FieldFactory.getFieldClass
private function getFieldClass(string $type): string { if (!array_key_exists($type, $this->fieldsMapping)) { throw new Exception("Field type \"{$type}\" not found in field mapping. Allowed fields are \"".implode('", "', $this->fieldsMapping).'"'); } return $this->fieldsMapping[$type]; }
php
private function getFieldClass(string $type): string { if (!array_key_exists($type, $this->fieldsMapping)) { throw new Exception("Field type \"{$type}\" not found in field mapping. Allowed fields are \"".implode('", "', $this->fieldsMapping).'"'); } return $this->fieldsMapping[$type]; }
[ "private", "function", "getFieldClass", "(", "string", "$", "type", ")", ":", "string", "{", "if", "(", "!", "array_key_exists", "(", "$", "type", ",", "$", "this", "->", "fieldsMapping", ")", ")", "{", "throw", "new", "Exception", "(", "\"Field type \\\"{$type}\\\" not found in field mapping. Allowed fields are \\\"\"", ".", "implode", "(", "'\", \"'", ",", "$", "this", "->", "fieldsMapping", ")", ".", "'\"'", ")", ";", "}", "return", "$", "this", "->", "fieldsMapping", "[", "$", "type", "]", ";", "}" ]
Return field class according to the field type. If the type is not present in the field mapping array, an exception will be thrown. @param string $type @return string @throws Exception
[ "Return", "field", "class", "according", "to", "the", "field", "type", ".", "If", "the", "type", "is", "not", "present", "in", "the", "field", "mapping", "array", "an", "exception", "will", "be", "thrown", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/FieldFactory.php#L176-L183
37,965
larriereguichet/AdminBundle
src/Factory/ConfigurationFactory.php
ConfigurationFactory.createResourceMenuConfiguration
public function createResourceMenuConfiguration() { $menuConfiguration = []; foreach ($this->resourceCollection->all() as $resource) { $resourceConfiguration = $resource->getConfiguration(); // Add only entry for the "list" action if ( !key_exists('actions', $resourceConfiguration) || null === $resourceConfiguration['actions'] || !array_key_exists('list', $resourceConfiguration['actions']) ) { continue; } $menuConfiguration['items'][] = [ 'text' => ucfirst($resource->getName()), 'admin' => $resource->getName(), 'action' => 'list', ]; } return $menuConfiguration; }
php
public function createResourceMenuConfiguration() { $menuConfiguration = []; foreach ($this->resourceCollection->all() as $resource) { $resourceConfiguration = $resource->getConfiguration(); // Add only entry for the "list" action if ( !key_exists('actions', $resourceConfiguration) || null === $resourceConfiguration['actions'] || !array_key_exists('list', $resourceConfiguration['actions']) ) { continue; } $menuConfiguration['items'][] = [ 'text' => ucfirst($resource->getName()), 'admin' => $resource->getName(), 'action' => 'list', ]; } return $menuConfiguration; }
[ "public", "function", "createResourceMenuConfiguration", "(", ")", "{", "$", "menuConfiguration", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "resourceCollection", "->", "all", "(", ")", "as", "$", "resource", ")", "{", "$", "resourceConfiguration", "=", "$", "resource", "->", "getConfiguration", "(", ")", ";", "// Add only entry for the \"list\" action", "if", "(", "!", "key_exists", "(", "'actions'", ",", "$", "resourceConfiguration", ")", "||", "null", "===", "$", "resourceConfiguration", "[", "'actions'", "]", "||", "!", "array_key_exists", "(", "'list'", ",", "$", "resourceConfiguration", "[", "'actions'", "]", ")", ")", "{", "continue", ";", "}", "$", "menuConfiguration", "[", "'items'", "]", "[", "]", "=", "[", "'text'", "=>", "ucfirst", "(", "$", "resource", "->", "getName", "(", ")", ")", ",", "'admin'", "=>", "$", "resource", "->", "getName", "(", ")", ",", "'action'", "=>", "'list'", ",", "]", ";", "}", "return", "$", "menuConfiguration", ";", "}" ]
Build the resources menu items. @return array
[ "Build", "the", "resources", "menu", "items", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/ConfigurationFactory.php#L96-L119
37,966
larriereguichet/AdminBundle
src/Factory/MenuFactory.php
MenuFactory.create
public function create(string $name, array $configuration): Menu { $resolver = new OptionsResolver(); $menuConfiguration = new MenuConfiguration($name, $this->applicationConfiguration->getParameter('title')); $menuConfiguration->configureOptions($resolver); $menuConfiguration->setParameters($resolver->resolve($configuration)); $menu = new Menu($name, $menuConfiguration); foreach ($menuConfiguration->getParameter('items') as $itemName => $item) { $menu->addItem($this->createMenuItem($itemName, $item, $menuConfiguration)); } $this->menus[$name] = $menu; return $menu; }
php
public function create(string $name, array $configuration): Menu { $resolver = new OptionsResolver(); $menuConfiguration = new MenuConfiguration($name, $this->applicationConfiguration->getParameter('title')); $menuConfiguration->configureOptions($resolver); $menuConfiguration->setParameters($resolver->resolve($configuration)); $menu = new Menu($name, $menuConfiguration); foreach ($menuConfiguration->getParameter('items') as $itemName => $item) { $menu->addItem($this->createMenuItem($itemName, $item, $menuConfiguration)); } $this->menus[$name] = $menu; return $menu; }
[ "public", "function", "create", "(", "string", "$", "name", ",", "array", "$", "configuration", ")", ":", "Menu", "{", "$", "resolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "menuConfiguration", "=", "new", "MenuConfiguration", "(", "$", "name", ",", "$", "this", "->", "applicationConfiguration", "->", "getParameter", "(", "'title'", ")", ")", ";", "$", "menuConfiguration", "->", "configureOptions", "(", "$", "resolver", ")", ";", "$", "menuConfiguration", "->", "setParameters", "(", "$", "resolver", "->", "resolve", "(", "$", "configuration", ")", ")", ";", "$", "menu", "=", "new", "Menu", "(", "$", "name", ",", "$", "menuConfiguration", ")", ";", "foreach", "(", "$", "menuConfiguration", "->", "getParameter", "(", "'items'", ")", "as", "$", "itemName", "=>", "$", "item", ")", "{", "$", "menu", "->", "addItem", "(", "$", "this", "->", "createMenuItem", "(", "$", "itemName", ",", "$", "item", ",", "$", "menuConfiguration", ")", ")", ";", "}", "$", "this", "->", "menus", "[", "$", "name", "]", "=", "$", "menu", ";", "return", "$", "menu", ";", "}" ]
Create a menu item from a configuration array. @param string $name @param array $configuration @return Menu
[ "Create", "a", "menu", "item", "from", "a", "configuration", "array", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/MenuFactory.php#L54-L69
37,967
larriereguichet/AdminBundle
src/Factory/MenuFactory.php
MenuFactory.createMenuItem
public function createMenuItem(string $name, array $configuration, MenuConfiguration $parentConfiguration): MenuItem { // Resolve configuration for the current item $resolver = new OptionsResolver(); $menuItemConfiguration = new MenuItemConfiguration($name, $parentConfiguration->getParameter('position')); $menuItemConfiguration->configureOptions($resolver); $resolvedConfiguration = $resolver->resolve($configuration); if ($this->applicationConfiguration->getParameter('enable_extra_configuration')) { $this->addExtraMenuItemConfiguration($resolvedConfiguration); } $menuItemConfiguration->setParameters($resolvedConfiguration); return new MenuItem($menuItemConfiguration); }
php
public function createMenuItem(string $name, array $configuration, MenuConfiguration $parentConfiguration): MenuItem { // Resolve configuration for the current item $resolver = new OptionsResolver(); $menuItemConfiguration = new MenuItemConfiguration($name, $parentConfiguration->getParameter('position')); $menuItemConfiguration->configureOptions($resolver); $resolvedConfiguration = $resolver->resolve($configuration); if ($this->applicationConfiguration->getParameter('enable_extra_configuration')) { $this->addExtraMenuItemConfiguration($resolvedConfiguration); } $menuItemConfiguration->setParameters($resolvedConfiguration); return new MenuItem($menuItemConfiguration); }
[ "public", "function", "createMenuItem", "(", "string", "$", "name", ",", "array", "$", "configuration", ",", "MenuConfiguration", "$", "parentConfiguration", ")", ":", "MenuItem", "{", "// Resolve configuration for the current item", "$", "resolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "menuItemConfiguration", "=", "new", "MenuItemConfiguration", "(", "$", "name", ",", "$", "parentConfiguration", "->", "getParameter", "(", "'position'", ")", ")", ";", "$", "menuItemConfiguration", "->", "configureOptions", "(", "$", "resolver", ")", ";", "$", "resolvedConfiguration", "=", "$", "resolver", "->", "resolve", "(", "$", "configuration", ")", ";", "if", "(", "$", "this", "->", "applicationConfiguration", "->", "getParameter", "(", "'enable_extra_configuration'", ")", ")", "{", "$", "this", "->", "addExtraMenuItemConfiguration", "(", "$", "resolvedConfiguration", ")", ";", "}", "$", "menuItemConfiguration", "->", "setParameters", "(", "$", "resolvedConfiguration", ")", ";", "return", "new", "MenuItem", "(", "$", "menuItemConfiguration", ")", ";", "}" ]
Create a menu item according to the given configuration. @param string $name @param array $configuration @param MenuConfiguration $parentConfiguration @return MenuItem
[ "Create", "a", "menu", "item", "according", "to", "the", "given", "configuration", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/MenuFactory.php#L80-L94
37,968
larriereguichet/AdminBundle
src/Factory/MenuFactory.php
MenuFactory.getMenu
public function getMenu(string $name): Menu { if (!$this->hasMenu($name)) { throw new Exception('Invalid menu name "'.$name.'"'); } return $this->menus[$name]; }
php
public function getMenu(string $name): Menu { if (!$this->hasMenu($name)) { throw new Exception('Invalid menu name "'.$name.'"'); } return $this->menus[$name]; }
[ "public", "function", "getMenu", "(", "string", "$", "name", ")", ":", "Menu", "{", "if", "(", "!", "$", "this", "->", "hasMenu", "(", "$", "name", ")", ")", "{", "throw", "new", "Exception", "(", "'Invalid menu name \"'", ".", "$", "name", ".", "'\"'", ")", ";", "}", "return", "$", "this", "->", "menus", "[", "$", "name", "]", ";", "}" ]
Return a menu with the given name. @param string $name @return Menu @throws Exception
[ "Return", "a", "menu", "with", "the", "given", "name", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Factory/MenuFactory.php#L117-L124
37,969
fxpio/fxp-resource
Handler/FormHandler.php
FormHandler.getDataListObjects
protected function getDataListObjects(FormConfigInterface $config, array $objects) { $limit = $this->getLimit($config instanceof FormConfigListInterface ? $config->getLimit() : null); $dataList = $this->getDataList($config); if (null !== $limit && \count($dataList) > $limit) { $msg = $this->translator->trans('form_handler.size_exceeds', [ '{{ limit }}' => $limit, ], 'FxpResource'); throw new InvalidResourceException(sprintf($msg, $limit)); } if (0 === \count($objects) && $config instanceof FormConfigListInterface) { $objects = $config->convertObjects($dataList); } $dataList = array_values($dataList); $objects = array_values($objects); return [$dataList, $objects]; }
php
protected function getDataListObjects(FormConfigInterface $config, array $objects) { $limit = $this->getLimit($config instanceof FormConfigListInterface ? $config->getLimit() : null); $dataList = $this->getDataList($config); if (null !== $limit && \count($dataList) > $limit) { $msg = $this->translator->trans('form_handler.size_exceeds', [ '{{ limit }}' => $limit, ], 'FxpResource'); throw new InvalidResourceException(sprintf($msg, $limit)); } if (0 === \count($objects) && $config instanceof FormConfigListInterface) { $objects = $config->convertObjects($dataList); } $dataList = array_values($dataList); $objects = array_values($objects); return [$dataList, $objects]; }
[ "protected", "function", "getDataListObjects", "(", "FormConfigInterface", "$", "config", ",", "array", "$", "objects", ")", "{", "$", "limit", "=", "$", "this", "->", "getLimit", "(", "$", "config", "instanceof", "FormConfigListInterface", "?", "$", "config", "->", "getLimit", "(", ")", ":", "null", ")", ";", "$", "dataList", "=", "$", "this", "->", "getDataList", "(", "$", "config", ")", ";", "if", "(", "null", "!==", "$", "limit", "&&", "\\", "count", "(", "$", "dataList", ")", ">", "$", "limit", ")", "{", "$", "msg", "=", "$", "this", "->", "translator", "->", "trans", "(", "'form_handler.size_exceeds'", ",", "[", "'{{ limit }}'", "=>", "$", "limit", ",", "]", ",", "'FxpResource'", ")", ";", "throw", "new", "InvalidResourceException", "(", "sprintf", "(", "$", "msg", ",", "$", "limit", ")", ")", ";", "}", "if", "(", "0", "===", "\\", "count", "(", "$", "objects", ")", "&&", "$", "config", "instanceof", "FormConfigListInterface", ")", "{", "$", "objects", "=", "$", "config", "->", "convertObjects", "(", "$", "dataList", ")", ";", "}", "$", "dataList", "=", "array_values", "(", "$", "dataList", ")", ";", "$", "objects", "=", "array_values", "(", "$", "objects", ")", ";", "return", "[", "$", "dataList", ",", "$", "objects", "]", ";", "}" ]
Get the data list and objects. @param FormConfigInterface $config The form config @param array[]|object[] $objects The list of object instance @return array
[ "Get", "the", "data", "list", "and", "objects", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Handler/FormHandler.php#L118-L139
37,970
fxpio/fxp-resource
Handler/FormHandler.php
FormHandler.getDataList
protected function getDataList(FormConfigInterface $config) { $converter = $this->converterRegistry->get($config->getConverter()); $dataList = $converter->convert((string) $this->request->getContent()); if ($config instanceof FormConfigListInterface) { try { $dataList = $config->findList($dataList); } catch (InvalidResourceException $e) { throw new InvalidResourceException($this->translator->trans('form_handler.results_field_required', [], 'FxpResource')); } } else { $dataList = [$dataList]; } return $dataList; }
php
protected function getDataList(FormConfigInterface $config) { $converter = $this->converterRegistry->get($config->getConverter()); $dataList = $converter->convert((string) $this->request->getContent()); if ($config instanceof FormConfigListInterface) { try { $dataList = $config->findList($dataList); } catch (InvalidResourceException $e) { throw new InvalidResourceException($this->translator->trans('form_handler.results_field_required', [], 'FxpResource')); } } else { $dataList = [$dataList]; } return $dataList; }
[ "protected", "function", "getDataList", "(", "FormConfigInterface", "$", "config", ")", "{", "$", "converter", "=", "$", "this", "->", "converterRegistry", "->", "get", "(", "$", "config", "->", "getConverter", "(", ")", ")", ";", "$", "dataList", "=", "$", "converter", "->", "convert", "(", "(", "string", ")", "$", "this", "->", "request", "->", "getContent", "(", ")", ")", ";", "if", "(", "$", "config", "instanceof", "FormConfigListInterface", ")", "{", "try", "{", "$", "dataList", "=", "$", "config", "->", "findList", "(", "$", "dataList", ")", ";", "}", "catch", "(", "InvalidResourceException", "$", "e", ")", "{", "throw", "new", "InvalidResourceException", "(", "$", "this", "->", "translator", "->", "trans", "(", "'form_handler.results_field_required'", ",", "[", "]", ",", "'FxpResource'", ")", ")", ";", "}", "}", "else", "{", "$", "dataList", "=", "[", "$", "dataList", "]", ";", "}", "return", "$", "dataList", ";", "}" ]
Get the form data list. @param FormConfigInterface $config The form config @return array
[ "Get", "the", "form", "data", "list", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Handler/FormHandler.php#L148-L164
37,971
fxpio/fxp-resource
Handler/FormHandler.php
FormHandler.process
private function process(FormConfigInterface $config, array $objects) { list($dataList, $objects) = $this->getDataListObjects($config, $objects); $forms = []; if (\count($objects) !== \count($dataList)) { $msg = $this->translator->trans('form_handler.different_size_request_list', [ '{{ requestSize }}' => \count($dataList), '{{ objectSize }}' => \count($objects), ], 'FxpResource'); throw new InvalidResourceException($msg); } foreach ($objects as $i => $object) { $form = $this->formFactory->create($config->getType(), $object, $config->getOptions()); $form->submit($dataList[$i], $config->getSubmitClearMissing()); $forms[] = $form; } return $forms; }
php
private function process(FormConfigInterface $config, array $objects) { list($dataList, $objects) = $this->getDataListObjects($config, $objects); $forms = []; if (\count($objects) !== \count($dataList)) { $msg = $this->translator->trans('form_handler.different_size_request_list', [ '{{ requestSize }}' => \count($dataList), '{{ objectSize }}' => \count($objects), ], 'FxpResource'); throw new InvalidResourceException($msg); } foreach ($objects as $i => $object) { $form = $this->formFactory->create($config->getType(), $object, $config->getOptions()); $form->submit($dataList[$i], $config->getSubmitClearMissing()); $forms[] = $form; } return $forms; }
[ "private", "function", "process", "(", "FormConfigInterface", "$", "config", ",", "array", "$", "objects", ")", "{", "list", "(", "$", "dataList", ",", "$", "objects", ")", "=", "$", "this", "->", "getDataListObjects", "(", "$", "config", ",", "$", "objects", ")", ";", "$", "forms", "=", "[", "]", ";", "if", "(", "\\", "count", "(", "$", "objects", ")", "!==", "\\", "count", "(", "$", "dataList", ")", ")", "{", "$", "msg", "=", "$", "this", "->", "translator", "->", "trans", "(", "'form_handler.different_size_request_list'", ",", "[", "'{{ requestSize }}'", "=>", "\\", "count", "(", "$", "dataList", ")", ",", "'{{ objectSize }}'", "=>", "\\", "count", "(", "$", "objects", ")", ",", "]", ",", "'FxpResource'", ")", ";", "throw", "new", "InvalidResourceException", "(", "$", "msg", ")", ";", "}", "foreach", "(", "$", "objects", "as", "$", "i", "=>", "$", "object", ")", "{", "$", "form", "=", "$", "this", "->", "formFactory", "->", "create", "(", "$", "config", "->", "getType", "(", ")", ",", "$", "object", ",", "$", "config", "->", "getOptions", "(", ")", ")", ";", "$", "form", "->", "submit", "(", "$", "dataList", "[", "$", "i", "]", ",", "$", "config", "->", "getSubmitClearMissing", "(", ")", ")", ";", "$", "forms", "[", "]", "=", "$", "form", ";", "}", "return", "$", "forms", ";", "}" ]
Create the list of form for the object instances. @param FormConfigInterface $config The form config @param array[]|object[] $objects The list of object instance @throws InvalidResourceException When the size if request data and the object instances is different @return FormInterface[]
[ "Create", "the", "list", "of", "form", "for", "the", "object", "instances", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Handler/FormHandler.php#L206-L228
37,972
hnhdigital-os/laravel-frontend-assets
src/IcheckInput.php
IcheckInput.config
public static function config($skin, $colour) { if (!empty($skin) && !empty($colour)) { if (!env('APP_CDN', true)) { FrontendAsset::add('vendor/icheck/'.$skin.'/'.$colour.'.css'); } else { $version = FrontendAsset::version(class_basename(__CLASS__)); FrontendAsset::add('https://cdnjs.cloudflare.com/ajax/libs/iCheck/'.$version.'/skins/'.$skin.'/'.$colour.'.css'); } } }
php
public static function config($skin, $colour) { if (!empty($skin) && !empty($colour)) { if (!env('APP_CDN', true)) { FrontendAsset::add('vendor/icheck/'.$skin.'/'.$colour.'.css'); } else { $version = FrontendAsset::version(class_basename(__CLASS__)); FrontendAsset::add('https://cdnjs.cloudflare.com/ajax/libs/iCheck/'.$version.'/skins/'.$skin.'/'.$colour.'.css'); } } }
[ "public", "static", "function", "config", "(", "$", "skin", ",", "$", "colour", ")", "{", "if", "(", "!", "empty", "(", "$", "skin", ")", "&&", "!", "empty", "(", "$", "colour", ")", ")", "{", "if", "(", "!", "env", "(", "'APP_CDN'", ",", "true", ")", ")", "{", "FrontendAsset", "::", "add", "(", "'vendor/icheck/'", ".", "$", "skin", ".", "'/'", ".", "$", "colour", ".", "'.css'", ")", ";", "}", "else", "{", "$", "version", "=", "FrontendAsset", "::", "version", "(", "class_basename", "(", "__CLASS__", ")", ")", ";", "FrontendAsset", "::", "add", "(", "'https://cdnjs.cloudflare.com/ajax/libs/iCheck/'", ".", "$", "version", ".", "'/skins/'", ".", "$", "skin", ".", "'/'", ".", "$", "colour", ".", "'.css'", ")", ";", "}", "}", "}" ]
Load skin for iCheck. @param string $skin @param string $colour @return void
[ "Load", "skin", "for", "iCheck", "." ]
242f605bf0c052f4d82421a8b95f227d46162e34
https://github.com/hnhdigital-os/laravel-frontend-assets/blob/242f605bf0c052f4d82421a8b95f227d46162e34/src/IcheckInput.php#L27-L37
37,973
larriereguichet/AdminBundle
src/Configuration/ActionConfiguration.php
ActionConfiguration.generateRouteName
private function generateRouteName(): string { if (!array_key_exists($this->actionName, $this->adminConfiguration->getParameter('actions'))) { throw new Exception( sprintf('Invalid action name %s for admin %s (available action are: %s)', $this->actionName, $this->adminName, implode(', ', array_keys($this->adminConfiguration->getParameter('actions')))) ); } $routeName = RoutingLoader::generateRouteName( $this->adminName, $this->actionName, $this->adminConfiguration->getParameter('routing_name_pattern') ); return $routeName; }
php
private function generateRouteName(): string { if (!array_key_exists($this->actionName, $this->adminConfiguration->getParameter('actions'))) { throw new Exception( sprintf('Invalid action name %s for admin %s (available action are: %s)', $this->actionName, $this->adminName, implode(', ', array_keys($this->adminConfiguration->getParameter('actions')))) ); } $routeName = RoutingLoader::generateRouteName( $this->adminName, $this->actionName, $this->adminConfiguration->getParameter('routing_name_pattern') ); return $routeName; }
[ "private", "function", "generateRouteName", "(", ")", ":", "string", "{", "if", "(", "!", "array_key_exists", "(", "$", "this", "->", "actionName", ",", "$", "this", "->", "adminConfiguration", "->", "getParameter", "(", "'actions'", ")", ")", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "'Invalid action name %s for admin %s (available action are: %s)'", ",", "$", "this", "->", "actionName", ",", "$", "this", "->", "adminName", ",", "implode", "(", "', '", ",", "array_keys", "(", "$", "this", "->", "adminConfiguration", "->", "getParameter", "(", "'actions'", ")", ")", ")", ")", ")", ";", "}", "$", "routeName", "=", "RoutingLoader", "::", "generateRouteName", "(", "$", "this", "->", "adminName", ",", "$", "this", "->", "actionName", ",", "$", "this", "->", "adminConfiguration", "->", "getParameter", "(", "'routing_name_pattern'", ")", ")", ";", "return", "$", "routeName", ";", "}" ]
Generate an admin route name using the pattern in the configuration. @return string @throws Exception
[ "Generate", "an", "admin", "route", "name", "using", "the", "pattern", "in", "the", "configuration", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L138-L155
37,974
larriereguichet/AdminBundle
src/Configuration/ActionConfiguration.php
ActionConfiguration.getFieldsNormalizer
private function getFieldsNormalizer() { return function(Options $options, $fields) { $normalizedFields = []; foreach ($fields as $name => $field) { if (null === $field) { $field = []; } $normalizedFields[$name] = $field; } return $normalizedFields; }; }
php
private function getFieldsNormalizer() { return function(Options $options, $fields) { $normalizedFields = []; foreach ($fields as $name => $field) { if (null === $field) { $field = []; } $normalizedFields[$name] = $field; } return $normalizedFields; }; }
[ "private", "function", "getFieldsNormalizer", "(", ")", "{", "return", "function", "(", "Options", "$", "options", ",", "$", "fields", ")", "{", "$", "normalizedFields", "=", "[", "]", ";", "foreach", "(", "$", "fields", "as", "$", "name", "=>", "$", "field", ")", "{", "if", "(", "null", "===", "$", "field", ")", "{", "$", "field", "=", "[", "]", ";", "}", "$", "normalizedFields", "[", "$", "name", "]", "=", "$", "field", ";", "}", "return", "$", "normalizedFields", ";", "}", ";", "}" ]
Return the field normalizer. It will transform null configuration into array to allow field type guessing working. @return Closure
[ "Return", "the", "field", "normalizer", ".", "It", "will", "transform", "null", "configuration", "into", "array", "to", "allow", "field", "type", "guessing", "working", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L163-L178
37,975
larriereguichet/AdminBundle
src/Configuration/ActionConfiguration.php
ActionConfiguration.getOrderNormalizer
private function getOrderNormalizer() { return function(Options $options, $order) { foreach ($order as $field => $sort) { if (!is_string($sort) || !is_string($field) || !in_array(strtolower($sort), ['asc', 'desc'])) { throw new Exception( 'Order value should be an array of string (["field" => $key]), got '.gettype($sort) ); } } return $order; }; }
php
private function getOrderNormalizer() { return function(Options $options, $order) { foreach ($order as $field => $sort) { if (!is_string($sort) || !is_string($field) || !in_array(strtolower($sort), ['asc', 'desc'])) { throw new Exception( 'Order value should be an array of string (["field" => $key]), got '.gettype($sort) ); } } return $order; }; }
[ "private", "function", "getOrderNormalizer", "(", ")", "{", "return", "function", "(", "Options", "$", "options", ",", "$", "order", ")", "{", "foreach", "(", "$", "order", "as", "$", "field", "=>", "$", "sort", ")", "{", "if", "(", "!", "is_string", "(", "$", "sort", ")", "||", "!", "is_string", "(", "$", "field", ")", "||", "!", "in_array", "(", "strtolower", "(", "$", "sort", ")", ",", "[", "'asc'", ",", "'desc'", "]", ")", ")", "{", "throw", "new", "Exception", "(", "'Order value should be an array of string ([\"field\" => $key]), got '", ".", "gettype", "(", "$", "sort", ")", ")", ";", "}", "}", "return", "$", "order", ";", "}", ";", "}" ]
Return the order normalizer. It will check if the order value passed are valid. @return Closure
[ "Return", "the", "order", "normalizer", ".", "It", "will", "check", "if", "the", "order", "value", "passed", "are", "valid", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L185-L198
37,976
larriereguichet/AdminBundle
src/Configuration/ActionConfiguration.php
ActionConfiguration.getLoadStrategyNormalizer
private function getLoadStrategyNormalizer() { return function(Options $options, $value) { if (!$value) { if ('create' == $this->actionName) { $value = LAGAdminBundle::LOAD_STRATEGY_NONE; } elseif ('list' == $this->actionName) { $value = LAGAdminBundle::LOAD_STRATEGY_MULTIPLE; } else { $value = LAGAdminBundle::LOAD_STRATEGY_UNIQUE; } } return $value; }; }
php
private function getLoadStrategyNormalizer() { return function(Options $options, $value) { if (!$value) { if ('create' == $this->actionName) { $value = LAGAdminBundle::LOAD_STRATEGY_NONE; } elseif ('list' == $this->actionName) { $value = LAGAdminBundle::LOAD_STRATEGY_MULTIPLE; } else { $value = LAGAdminBundle::LOAD_STRATEGY_UNIQUE; } } return $value; }; }
[ "private", "function", "getLoadStrategyNormalizer", "(", ")", "{", "return", "function", "(", "Options", "$", "options", ",", "$", "value", ")", "{", "if", "(", "!", "$", "value", ")", "{", "if", "(", "'create'", "==", "$", "this", "->", "actionName", ")", "{", "$", "value", "=", "LAGAdminBundle", "::", "LOAD_STRATEGY_NONE", ";", "}", "elseif", "(", "'list'", "==", "$", "this", "->", "actionName", ")", "{", "$", "value", "=", "LAGAdminBundle", "::", "LOAD_STRATEGY_MULTIPLE", ";", "}", "else", "{", "$", "value", "=", "LAGAdminBundle", "::", "LOAD_STRATEGY_UNIQUE", ";", "}", "}", "return", "$", "value", ";", "}", ";", "}" ]
Return the load strategy normalizer. It will set the default strategy according to the action name, if no value is provided. @return Closure
[ "Return", "the", "load", "strategy", "normalizer", ".", "It", "will", "set", "the", "default", "strategy", "according", "to", "the", "action", "name", "if", "no", "value", "is", "provided", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L206-L221
37,977
larriereguichet/AdminBundle
src/Configuration/ActionConfiguration.php
ActionConfiguration.getCriteriaNormalizer
private function getCriteriaNormalizer() { return function(Options $options, $value) { if (!$value) { $idActions = [ 'edit', 'delete', ]; if (in_array($this->actionName, $idActions)) { $value = [ 'id', ]; } } return $value; }; }
php
private function getCriteriaNormalizer() { return function(Options $options, $value) { if (!$value) { $idActions = [ 'edit', 'delete', ]; if (in_array($this->actionName, $idActions)) { $value = [ 'id', ]; } } return $value; }; }
[ "private", "function", "getCriteriaNormalizer", "(", ")", "{", "return", "function", "(", "Options", "$", "options", ",", "$", "value", ")", "{", "if", "(", "!", "$", "value", ")", "{", "$", "idActions", "=", "[", "'edit'", ",", "'delete'", ",", "]", ";", "if", "(", "in_array", "(", "$", "this", "->", "actionName", ",", "$", "idActions", ")", ")", "{", "$", "value", "=", "[", "'id'", ",", "]", ";", "}", "}", "return", "$", "value", ";", "}", ";", "}" ]
Return the criteria normalizer. It will add the id parameters for the edit and delete actions if no value is provided. @return Closure
[ "Return", "the", "criteria", "normalizer", ".", "It", "will", "add", "the", "id", "parameters", "for", "the", "edit", "and", "delete", "actions", "if", "no", "value", "is", "provided", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L247-L265
37,978
larriereguichet/AdminBundle
src/Configuration/ActionConfiguration.php
ActionConfiguration.getFiltersNormalizer
private function getFiltersNormalizer(): Closure { return function(Options $options, $data) { $normalizedData = []; foreach ($data as $name => $field) { if (is_string($field)) { $field = [ 'type' => $field, 'options' => [], ]; } $field['name'] = $name; $resolver = new OptionsResolver(); $filterConfiguration = new FilterConfiguration(); $filterConfiguration->configureOptions($resolver); $filterConfiguration->setParameters($resolver->resolve($field)); $normalizedData[$name] = $filterConfiguration->getParameters(); } return $normalizedData; }; }
php
private function getFiltersNormalizer(): Closure { return function(Options $options, $data) { $normalizedData = []; foreach ($data as $name => $field) { if (is_string($field)) { $field = [ 'type' => $field, 'options' => [], ]; } $field['name'] = $name; $resolver = new OptionsResolver(); $filterConfiguration = new FilterConfiguration(); $filterConfiguration->configureOptions($resolver); $filterConfiguration->setParameters($resolver->resolve($field)); $normalizedData[$name] = $filterConfiguration->getParameters(); } return $normalizedData; }; }
[ "private", "function", "getFiltersNormalizer", "(", ")", ":", "Closure", "{", "return", "function", "(", "Options", "$", "options", ",", "$", "data", ")", "{", "$", "normalizedData", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "name", "=>", "$", "field", ")", "{", "if", "(", "is_string", "(", "$", "field", ")", ")", "{", "$", "field", "=", "[", "'type'", "=>", "$", "field", ",", "'options'", "=>", "[", "]", ",", "]", ";", "}", "$", "field", "[", "'name'", "]", "=", "$", "name", ";", "$", "resolver", "=", "new", "OptionsResolver", "(", ")", ";", "$", "filterConfiguration", "=", "new", "FilterConfiguration", "(", ")", ";", "$", "filterConfiguration", "->", "configureOptions", "(", "$", "resolver", ")", ";", "$", "filterConfiguration", "->", "setParameters", "(", "$", "resolver", "->", "resolve", "(", "$", "field", ")", ")", ";", "$", "normalizedData", "[", "$", "name", "]", "=", "$", "filterConfiguration", "->", "getParameters", "(", ")", ";", "}", "return", "$", "normalizedData", ";", "}", ";", "}" ]
Return the filters normalizer. @return Closure
[ "Return", "the", "filters", "normalizer", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L296-L320
37,979
larriereguichet/AdminBundle
src/Configuration/ActionConfiguration.php
ActionConfiguration.getDefaultRoutePath
private function getDefaultRoutePath(): string { $pattern = $this ->adminConfiguration ->getParameter('routing_url_pattern') ; $path = str_replace('{admin}', $this->adminName, $pattern); $path = str_replace('{action}', $this->actionName, $path); if (in_array($this->actionName, ['edit', 'delete'])) { $path .= '/{id}'; } return $path; }
php
private function getDefaultRoutePath(): string { $pattern = $this ->adminConfiguration ->getParameter('routing_url_pattern') ; $path = str_replace('{admin}', $this->adminName, $pattern); $path = str_replace('{action}', $this->actionName, $path); if (in_array($this->actionName, ['edit', 'delete'])) { $path .= '/{id}'; } return $path; }
[ "private", "function", "getDefaultRoutePath", "(", ")", ":", "string", "{", "$", "pattern", "=", "$", "this", "->", "adminConfiguration", "->", "getParameter", "(", "'routing_url_pattern'", ")", ";", "$", "path", "=", "str_replace", "(", "'{admin}'", ",", "$", "this", "->", "adminName", ",", "$", "pattern", ")", ";", "$", "path", "=", "str_replace", "(", "'{action}'", ",", "$", "this", "->", "actionName", ",", "$", "path", ")", ";", "if", "(", "in_array", "(", "$", "this", "->", "actionName", ",", "[", "'edit'", ",", "'delete'", "]", ")", ")", "{", "$", "path", ".=", "'/{id}'", ";", "}", "return", "$", "path", ";", "}" ]
Return the default route path according to the action name. @return string
[ "Return", "the", "default", "route", "path", "according", "to", "the", "action", "name", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Configuration/ActionConfiguration.php#L386-L400
37,980
larriereguichet/AdminBundle
src/Event/Subscriber/FormSubscriber.php
FormSubscriber.createForm
public function createForm(FormEvent $event): void { $admin = $event->getAdmin(); $action = $admin->getAction(); $configuration = $action->getConfiguration(); if (!$configuration->get('use_form')) { return; } $entity = null; if (LAGAdminBundle::LOAD_STRATEGY_UNIQUE === $configuration->get('load_strategy')) { if (!$admin->getEntities()->isEmpty()) { $entity = $admin->getEntities()->first(); } } if ('create' === $action->getName() || 'edit' === $action->getName()) { $form = $this->adminFormFactory->createEntityForm($admin, $event->getRequest(), $entity); $event->addForm($form, 'entity'); } if ('delete' === $action->getName()) { $form = $this->adminFormFactory->createDeleteForm($action, $event->getRequest(), $entity); $event->addForm($form, 'delete'); } }
php
public function createForm(FormEvent $event): void { $admin = $event->getAdmin(); $action = $admin->getAction(); $configuration = $action->getConfiguration(); if (!$configuration->get('use_form')) { return; } $entity = null; if (LAGAdminBundle::LOAD_STRATEGY_UNIQUE === $configuration->get('load_strategy')) { if (!$admin->getEntities()->isEmpty()) { $entity = $admin->getEntities()->first(); } } if ('create' === $action->getName() || 'edit' === $action->getName()) { $form = $this->adminFormFactory->createEntityForm($admin, $event->getRequest(), $entity); $event->addForm($form, 'entity'); } if ('delete' === $action->getName()) { $form = $this->adminFormFactory->createDeleteForm($action, $event->getRequest(), $entity); $event->addForm($form, 'delete'); } }
[ "public", "function", "createForm", "(", "FormEvent", "$", "event", ")", ":", "void", "{", "$", "admin", "=", "$", "event", "->", "getAdmin", "(", ")", ";", "$", "action", "=", "$", "admin", "->", "getAction", "(", ")", ";", "$", "configuration", "=", "$", "action", "->", "getConfiguration", "(", ")", ";", "if", "(", "!", "$", "configuration", "->", "get", "(", "'use_form'", ")", ")", "{", "return", ";", "}", "$", "entity", "=", "null", ";", "if", "(", "LAGAdminBundle", "::", "LOAD_STRATEGY_UNIQUE", "===", "$", "configuration", "->", "get", "(", "'load_strategy'", ")", ")", "{", "if", "(", "!", "$", "admin", "->", "getEntities", "(", ")", "->", "isEmpty", "(", ")", ")", "{", "$", "entity", "=", "$", "admin", "->", "getEntities", "(", ")", "->", "first", "(", ")", ";", "}", "}", "if", "(", "'create'", "===", "$", "action", "->", "getName", "(", ")", "||", "'edit'", "===", "$", "action", "->", "getName", "(", ")", ")", "{", "$", "form", "=", "$", "this", "->", "adminFormFactory", "->", "createEntityForm", "(", "$", "admin", ",", "$", "event", "->", "getRequest", "(", ")", ",", "$", "entity", ")", ";", "$", "event", "->", "addForm", "(", "$", "form", ",", "'entity'", ")", ";", "}", "if", "(", "'delete'", "===", "$", "action", "->", "getName", "(", ")", ")", "{", "$", "form", "=", "$", "this", "->", "adminFormFactory", "->", "createDeleteForm", "(", "$", "action", ",", "$", "event", "->", "getRequest", "(", ")", ",", "$", "entity", ")", ";", "$", "event", "->", "addForm", "(", "$", "form", ",", "'delete'", ")", ";", "}", "}" ]
Create a form for the loaded entity. @param FormEvent $event
[ "Create", "a", "form", "for", "the", "loaded", "entity", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/FormSubscriber.php#L77-L103
37,981
larriereguichet/AdminBundle
src/Event/Subscriber/FormSubscriber.php
FormSubscriber.handleForm
public function handleForm(FormEvent $event): void { $admin = $event->getAdmin(); $action = $admin->getAction(); if ('delete' === $action->getName()) { if (!$admin->hasForm('delete')) { return; } $form = $admin->getForm('delete'); $this->handleDeleteForm($event->getRequest(), $form, $admin); } }
php
public function handleForm(FormEvent $event): void { $admin = $event->getAdmin(); $action = $admin->getAction(); if ('delete' === $action->getName()) { if (!$admin->hasForm('delete')) { return; } $form = $admin->getForm('delete'); $this->handleDeleteForm($event->getRequest(), $form, $admin); } }
[ "public", "function", "handleForm", "(", "FormEvent", "$", "event", ")", ":", "void", "{", "$", "admin", "=", "$", "event", "->", "getAdmin", "(", ")", ";", "$", "action", "=", "$", "admin", "->", "getAction", "(", ")", ";", "if", "(", "'delete'", "===", "$", "action", "->", "getName", "(", ")", ")", "{", "if", "(", "!", "$", "admin", "->", "hasForm", "(", "'delete'", ")", ")", "{", "return", ";", "}", "$", "form", "=", "$", "admin", "->", "getForm", "(", "'delete'", ")", ";", "$", "this", "->", "handleDeleteForm", "(", "$", "event", "->", "getRequest", "(", ")", ",", "$", "form", ",", "$", "admin", ")", ";", "}", "}" ]
When the HANDLE_FORM event is dispatched, we handle the form according to the current action. @param FormEvent $event
[ "When", "the", "HANDLE_FORM", "event", "is", "dispatched", "we", "handle", "the", "form", "according", "to", "the", "current", "action", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Event/Subscriber/FormSubscriber.php#L110-L122
37,982
larriereguichet/AdminBundle
src/Bridge/Doctrine/ORM/Event/Subscriber/ORMSubscriber.php
ORMSubscriber.addOrder
public function addOrder(ORMFilterEvent $event) { $queryBuilder = $event->getQueryBuilder(); $admin = $event->getAdmin(); $actionConfiguration = $admin->getAction()->getConfiguration(); $request = $this->requestStack->getMasterRequest(); $sort = $request->get('sort'); $alias = $queryBuilder->getRootAliases()[0]; // The sort from the request override the configured one if ($sort) { $order = $request->get('order', 'asc'); $queryBuilder->addOrderBy($alias.'.'.$sort, $order); } else { foreach ($actionConfiguration->getParameter('order') as $field => $order) { $queryBuilder->addOrderBy($alias.'.'.$field, $order); } } }
php
public function addOrder(ORMFilterEvent $event) { $queryBuilder = $event->getQueryBuilder(); $admin = $event->getAdmin(); $actionConfiguration = $admin->getAction()->getConfiguration(); $request = $this->requestStack->getMasterRequest(); $sort = $request->get('sort'); $alias = $queryBuilder->getRootAliases()[0]; // The sort from the request override the configured one if ($sort) { $order = $request->get('order', 'asc'); $queryBuilder->addOrderBy($alias.'.'.$sort, $order); } else { foreach ($actionConfiguration->getParameter('order') as $field => $order) { $queryBuilder->addOrderBy($alias.'.'.$field, $order); } } }
[ "public", "function", "addOrder", "(", "ORMFilterEvent", "$", "event", ")", "{", "$", "queryBuilder", "=", "$", "event", "->", "getQueryBuilder", "(", ")", ";", "$", "admin", "=", "$", "event", "->", "getAdmin", "(", ")", ";", "$", "actionConfiguration", "=", "$", "admin", "->", "getAction", "(", ")", "->", "getConfiguration", "(", ")", ";", "$", "request", "=", "$", "this", "->", "requestStack", "->", "getMasterRequest", "(", ")", ";", "$", "sort", "=", "$", "request", "->", "get", "(", "'sort'", ")", ";", "$", "alias", "=", "$", "queryBuilder", "->", "getRootAliases", "(", ")", "[", "0", "]", ";", "// The sort from the request override the configured one", "if", "(", "$", "sort", ")", "{", "$", "order", "=", "$", "request", "->", "get", "(", "'order'", ",", "'asc'", ")", ";", "$", "queryBuilder", "->", "addOrderBy", "(", "$", "alias", ".", "'.'", ".", "$", "sort", ",", "$", "order", ")", ";", "}", "else", "{", "foreach", "(", "$", "actionConfiguration", "->", "getParameter", "(", "'order'", ")", "as", "$", "field", "=>", "$", "order", ")", "{", "$", "queryBuilder", "->", "addOrderBy", "(", "$", "alias", ".", "'.'", ".", "$", "field", ",", "$", "order", ")", ";", "}", "}", "}" ]
Add the order to query builder according to the configuration. @param ORMFilterEvent $event
[ "Add", "the", "order", "to", "query", "builder", "according", "to", "the", "configuration", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Bridge/Doctrine/ORM/Event/Subscriber/ORMSubscriber.php#L57-L77
37,983
larriereguichet/AdminBundle
src/Bridge/Doctrine/ORM/Event/Subscriber/ORMSubscriber.php
ORMSubscriber.addFilters
public function addFilters(ORMFilterEvent $event) { $queryBuilder = $event->getQueryBuilder(); foreach ($event->getFilters() as $filter) { $alias = $queryBuilder->getRootAliases()[0]; $parameterName = 'filter_'.$filter->getName(); $value = $filter->getValue(); if ('like' === $filter->getComparator()) { $value = '%'.$value.'%'; } if ('and' === $filter->getOperator()) { $method = 'andWhere'; } else { $method = 'orWhere'; } $queryBuilder->$method(sprintf( '%s.%s %s %s', $alias, $filter->getName(), $filter->getComparator(), ':'.$parameterName )); $queryBuilder->setParameter($parameterName, $value); } }
php
public function addFilters(ORMFilterEvent $event) { $queryBuilder = $event->getQueryBuilder(); foreach ($event->getFilters() as $filter) { $alias = $queryBuilder->getRootAliases()[0]; $parameterName = 'filter_'.$filter->getName(); $value = $filter->getValue(); if ('like' === $filter->getComparator()) { $value = '%'.$value.'%'; } if ('and' === $filter->getOperator()) { $method = 'andWhere'; } else { $method = 'orWhere'; } $queryBuilder->$method(sprintf( '%s.%s %s %s', $alias, $filter->getName(), $filter->getComparator(), ':'.$parameterName )); $queryBuilder->setParameter($parameterName, $value); } }
[ "public", "function", "addFilters", "(", "ORMFilterEvent", "$", "event", ")", "{", "$", "queryBuilder", "=", "$", "event", "->", "getQueryBuilder", "(", ")", ";", "foreach", "(", "$", "event", "->", "getFilters", "(", ")", "as", "$", "filter", ")", "{", "$", "alias", "=", "$", "queryBuilder", "->", "getRootAliases", "(", ")", "[", "0", "]", ";", "$", "parameterName", "=", "'filter_'", ".", "$", "filter", "->", "getName", "(", ")", ";", "$", "value", "=", "$", "filter", "->", "getValue", "(", ")", ";", "if", "(", "'like'", "===", "$", "filter", "->", "getComparator", "(", ")", ")", "{", "$", "value", "=", "'%'", ".", "$", "value", ".", "'%'", ";", "}", "if", "(", "'and'", "===", "$", "filter", "->", "getOperator", "(", ")", ")", "{", "$", "method", "=", "'andWhere'", ";", "}", "else", "{", "$", "method", "=", "'orWhere'", ";", "}", "$", "queryBuilder", "->", "$", "method", "(", "sprintf", "(", "'%s.%s %s %s'", ",", "$", "alias", ",", "$", "filter", "->", "getName", "(", ")", ",", "$", "filter", "->", "getComparator", "(", ")", ",", "':'", ".", "$", "parameterName", ")", ")", ";", "$", "queryBuilder", "->", "setParameter", "(", "$", "parameterName", ",", "$", "value", ")", ";", "}", "}" ]
Add filter to the query builder. @param ORMFilterEvent $event
[ "Add", "filter", "to", "the", "query", "builder", "." ]
794991d72b3f50b70de424be7a89c3307f9eecc1
https://github.com/larriereguichet/AdminBundle/blob/794991d72b3f50b70de424be7a89c3307f9eecc1/src/Bridge/Doctrine/ORM/Event/Subscriber/ORMSubscriber.php#L84-L112
37,984
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.getIdentifier
public static function getIdentifier(ObjectManager $om, $object) { $propertyAccess = PropertyAccess::createPropertyAccessor(); $meta = $om->getClassMetadata(ClassUtils::getClass($object)); $ids = $meta->getIdentifier(); $value = null; foreach ($ids as $id) { $idVal = $propertyAccess->getValue($object, $id); if (null !== $idVal) { $value = $idVal; break; } } return $value; }
php
public static function getIdentifier(ObjectManager $om, $object) { $propertyAccess = PropertyAccess::createPropertyAccessor(); $meta = $om->getClassMetadata(ClassUtils::getClass($object)); $ids = $meta->getIdentifier(); $value = null; foreach ($ids as $id) { $idVal = $propertyAccess->getValue($object, $id); if (null !== $idVal) { $value = $idVal; break; } } return $value; }
[ "public", "static", "function", "getIdentifier", "(", "ObjectManager", "$", "om", ",", "$", "object", ")", "{", "$", "propertyAccess", "=", "PropertyAccess", "::", "createPropertyAccessor", "(", ")", ";", "$", "meta", "=", "$", "om", "->", "getClassMetadata", "(", "ClassUtils", "::", "getClass", "(", "$", "object", ")", ")", ";", "$", "ids", "=", "$", "meta", "->", "getIdentifier", "(", ")", ";", "$", "value", "=", "null", ";", "foreach", "(", "$", "ids", "as", "$", "id", ")", "{", "$", "idVal", "=", "$", "propertyAccess", "->", "getValue", "(", "$", "object", ",", "$", "id", ")", ";", "if", "(", "null", "!==", "$", "idVal", ")", "{", "$", "value", "=", "$", "idVal", ";", "break", ";", "}", "}", "return", "$", "value", ";", "}" ]
Get the value of resource identifier. @param ObjectManager $om The doctrine object manager @param object $object The resource object @return null|int|string
[ "Get", "the", "value", "of", "resource", "identifier", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L51-L69
37,985
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.getIdentifierName
public static function getIdentifierName(ObjectManager $om, $className) { $meta = $om->getClassMetadata($className); $ids = $meta->getIdentifier(); return implode('', $ids); }
php
public static function getIdentifierName(ObjectManager $om, $className) { $meta = $om->getClassMetadata($className); $ids = $meta->getIdentifier(); return implode('', $ids); }
[ "public", "static", "function", "getIdentifierName", "(", "ObjectManager", "$", "om", ",", "$", "className", ")", "{", "$", "meta", "=", "$", "om", "->", "getClassMetadata", "(", "$", "className", ")", ";", "$", "ids", "=", "$", "meta", "->", "getIdentifier", "(", ")", ";", "return", "implode", "(", "''", ",", "$", "ids", ")", ";", "}" ]
Get the name of identifier. @param ObjectManager $om The doctrine object manager @param string $className The class name @return string
[ "Get", "the", "name", "of", "identifier", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L79-L85
37,986
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.getEventClasses
public static function getEventClasses($type) { $names = [PreUpsertsEvent::class, PostUpsertsEvent::class]; if (Domain::TYPE_CREATE === $type) { $names = [PreCreatesEvent::class, PostCreatesEvent::class]; } elseif (Domain::TYPE_UPDATE === $type) { $names = [PreUpdatesEvent::class, PostUpdatesEvent::class]; } elseif (Domain::TYPE_DELETE === $type) { $names = [PreDeletesEvent::class, PostDeletesEvent::class]; } elseif (Domain::TYPE_UNDELETE === $type) { $names = [PreUndeletesEvent::class, PostUndeletesEvent::class]; } return $names; }
php
public static function getEventClasses($type) { $names = [PreUpsertsEvent::class, PostUpsertsEvent::class]; if (Domain::TYPE_CREATE === $type) { $names = [PreCreatesEvent::class, PostCreatesEvent::class]; } elseif (Domain::TYPE_UPDATE === $type) { $names = [PreUpdatesEvent::class, PostUpdatesEvent::class]; } elseif (Domain::TYPE_DELETE === $type) { $names = [PreDeletesEvent::class, PostDeletesEvent::class]; } elseif (Domain::TYPE_UNDELETE === $type) { $names = [PreUndeletesEvent::class, PostUndeletesEvent::class]; } return $names; }
[ "public", "static", "function", "getEventClasses", "(", "$", "type", ")", "{", "$", "names", "=", "[", "PreUpsertsEvent", "::", "class", ",", "PostUpsertsEvent", "::", "class", "]", ";", "if", "(", "Domain", "::", "TYPE_CREATE", "===", "$", "type", ")", "{", "$", "names", "=", "[", "PreCreatesEvent", "::", "class", ",", "PostCreatesEvent", "::", "class", "]", ";", "}", "elseif", "(", "Domain", "::", "TYPE_UPDATE", "===", "$", "type", ")", "{", "$", "names", "=", "[", "PreUpdatesEvent", "::", "class", ",", "PostUpdatesEvent", "::", "class", "]", ";", "}", "elseif", "(", "Domain", "::", "TYPE_DELETE", "===", "$", "type", ")", "{", "$", "names", "=", "[", "PreDeletesEvent", "::", "class", ",", "PostDeletesEvent", "::", "class", "]", ";", "}", "elseif", "(", "Domain", "::", "TYPE_UNDELETE", "===", "$", "type", ")", "{", "$", "names", "=", "[", "PreUndeletesEvent", "::", "class", ",", "PostUndeletesEvent", "::", "class", "]", ";", "}", "return", "$", "names", ";", "}" ]
Get the event names of persist action. @param int $type The type of persist @return array The list of pre event name and post event name
[ "Get", "the", "event", "names", "of", "persist", "action", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L94-L109
37,987
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.extractIdentifierInObjectList
public static function extractIdentifierInObjectList(array $identifiers, array &$objects) { $searchIds = []; foreach ($identifiers as $identifier) { if (\is_object($identifier)) { $objects[] = $identifier; continue; } $searchIds[] = $identifier; } return $searchIds; }
php
public static function extractIdentifierInObjectList(array $identifiers, array &$objects) { $searchIds = []; foreach ($identifiers as $identifier) { if (\is_object($identifier)) { $objects[] = $identifier; continue; } $searchIds[] = $identifier; } return $searchIds; }
[ "public", "static", "function", "extractIdentifierInObjectList", "(", "array", "$", "identifiers", ",", "array", "&", "$", "objects", ")", "{", "$", "searchIds", "=", "[", "]", ";", "foreach", "(", "$", "identifiers", "as", "$", "identifier", ")", "{", "if", "(", "\\", "is_object", "(", "$", "identifier", ")", ")", "{", "$", "objects", "[", "]", "=", "$", "identifier", ";", "continue", ";", "}", "$", "searchIds", "[", "]", "=", "$", "identifier", ";", "}", "return", "$", "searchIds", ";", "}" ]
Extract the identifier that are not a object. @param array $identifiers The list containing identifier or object @param array $objects The real objects (by reference) @return array The identifiers that are not a object
[ "Extract", "the", "identifier", "that", "are", "not", "a", "object", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L119-L133
37,988
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.oneAction
public static function oneAction(ResourceListInterface $resources) { $resources->get(0)->getErrors()->addAll($resources->getErrors()); return $resources->get(0); }
php
public static function oneAction(ResourceListInterface $resources) { $resources->get(0)->getErrors()->addAll($resources->getErrors()); return $resources->get(0); }
[ "public", "static", "function", "oneAction", "(", "ResourceListInterface", "$", "resources", ")", "{", "$", "resources", "->", "get", "(", "0", ")", "->", "getErrors", "(", ")", "->", "addAll", "(", "$", "resources", "->", "getErrors", "(", ")", ")", ";", "return", "$", "resources", "->", "get", "(", "0", ")", ";", "}" ]
Inject the list errors in the first resource, and return the this first resource. @param ResourceListInterface $resources The resource list @return ResourceInterface The first resource
[ "Inject", "the", "list", "errors", "in", "the", "first", "resource", "and", "return", "the", "this", "first", "resource", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L142-L147
37,989
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.moveFlushErrorsInResource
public static function moveFlushErrorsInResource(ResourceListInterface $resources, ConstraintViolationListInterface $errors): void { if ($errors->count() > 0) { $maps = static::getMapErrors($errors); foreach ($resources->all() as $resource) { $resource->setStatus(ResourceStatutes::ERROR); $hash = spl_object_hash($resource->getRealData()); if (isset($maps[$hash])) { $resource->getErrors()->add($maps[$hash]); unset($maps[$hash]); } } foreach ($maps as $error) { $resources->getErrors()->add($error); } } }
php
public static function moveFlushErrorsInResource(ResourceListInterface $resources, ConstraintViolationListInterface $errors): void { if ($errors->count() > 0) { $maps = static::getMapErrors($errors); foreach ($resources->all() as $resource) { $resource->setStatus(ResourceStatutes::ERROR); $hash = spl_object_hash($resource->getRealData()); if (isset($maps[$hash])) { $resource->getErrors()->add($maps[$hash]); unset($maps[$hash]); } } foreach ($maps as $error) { $resources->getErrors()->add($error); } } }
[ "public", "static", "function", "moveFlushErrorsInResource", "(", "ResourceListInterface", "$", "resources", ",", "ConstraintViolationListInterface", "$", "errors", ")", ":", "void", "{", "if", "(", "$", "errors", "->", "count", "(", ")", ">", "0", ")", "{", "$", "maps", "=", "static", "::", "getMapErrors", "(", "$", "errors", ")", ";", "foreach", "(", "$", "resources", "->", "all", "(", ")", "as", "$", "resource", ")", "{", "$", "resource", "->", "setStatus", "(", "ResourceStatutes", "::", "ERROR", ")", ";", "$", "hash", "=", "spl_object_hash", "(", "$", "resource", "->", "getRealData", "(", ")", ")", ";", "if", "(", "isset", "(", "$", "maps", "[", "$", "hash", "]", ")", ")", "{", "$", "resource", "->", "getErrors", "(", ")", "->", "add", "(", "$", "maps", "[", "$", "hash", "]", ")", ";", "unset", "(", "$", "maps", "[", "$", "hash", "]", ")", ";", "}", "}", "foreach", "(", "$", "maps", "as", "$", "error", ")", "{", "$", "resources", "->", "getErrors", "(", ")", "->", "add", "(", "$", "error", ")", ";", "}", "}", "}" ]
Move the flush errors in each resource if the root object is present in constraint violation. @param ResourceListInterface $resources The list of resources @param ConstraintViolationListInterface $errors The list of flush errors
[ "Move", "the", "flush", "errors", "in", "each", "resource", "if", "the", "root", "object", "is", "present", "in", "constraint", "violation", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L155-L173
37,990
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.cancelAllSuccessResources
public static function cancelAllSuccessResources(ResourceListInterface $resources): void { foreach ($resources->all() as $resource) { if (ResourceStatutes::ERROR !== $resource->getStatus()) { $resource->setStatus(ResourceStatutes::CANCELED); } } }
php
public static function cancelAllSuccessResources(ResourceListInterface $resources): void { foreach ($resources->all() as $resource) { if (ResourceStatutes::ERROR !== $resource->getStatus()) { $resource->setStatus(ResourceStatutes::CANCELED); } } }
[ "public", "static", "function", "cancelAllSuccessResources", "(", "ResourceListInterface", "$", "resources", ")", ":", "void", "{", "foreach", "(", "$", "resources", "->", "all", "(", ")", "as", "$", "resource", ")", "{", "if", "(", "ResourceStatutes", "::", "ERROR", "!==", "$", "resource", "->", "getStatus", "(", ")", ")", "{", "$", "resource", "->", "setStatus", "(", "ResourceStatutes", "::", "CANCELED", ")", ";", "}", "}", "}" ]
Cancel all resource in list that have an successfully status. @param ResourceListInterface $resources The list of resources
[ "Cancel", "all", "resource", "in", "list", "that", "have", "an", "successfully", "status", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L180-L187
37,991
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.getExceptionMessage
public static function getExceptionMessage(TranslatorInterface $translator, \Exception $exception, $debug = false) { $message = $translator->trans('domain.database_error', [], 'FxpResource'); if ($debug) { $message .= ' ['.\get_class($exception).']'; } if ($exception instanceof DriverException) { return static::extractDriverExceptionMessage($exception, $message, $debug); } return $debug ? $exception->getMessage() : $message; }
php
public static function getExceptionMessage(TranslatorInterface $translator, \Exception $exception, $debug = false) { $message = $translator->trans('domain.database_error', [], 'FxpResource'); if ($debug) { $message .= ' ['.\get_class($exception).']'; } if ($exception instanceof DriverException) { return static::extractDriverExceptionMessage($exception, $message, $debug); } return $debug ? $exception->getMessage() : $message; }
[ "public", "static", "function", "getExceptionMessage", "(", "TranslatorInterface", "$", "translator", ",", "\\", "Exception", "$", "exception", ",", "$", "debug", "=", "false", ")", "{", "$", "message", "=", "$", "translator", "->", "trans", "(", "'domain.database_error'", ",", "[", "]", ",", "'FxpResource'", ")", ";", "if", "(", "$", "debug", ")", "{", "$", "message", ".=", "' ['", ".", "\\", "get_class", "(", "$", "exception", ")", ".", "']'", ";", "}", "if", "(", "$", "exception", "instanceof", "DriverException", ")", "{", "return", "static", "::", "extractDriverExceptionMessage", "(", "$", "exception", ",", "$", "message", ",", "$", "debug", ")", ";", "}", "return", "$", "debug", "?", "$", "exception", "->", "getMessage", "(", ")", ":", "$", "message", ";", "}" ]
Get the exception message. @param TranslatorInterface $translator The translator @param \Exception $exception The exception @param bool $debug The debug mode @return string
[ "Get", "the", "exception", "message", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L198-L213
37,992
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.addResourceError
public static function addResourceError(ResourceInterface $resource, $message, \Exception $e = null): void { $resource->setStatus(ResourceStatutes::ERROR); $resource->getErrors()->add(new ConstraintViolation($message, $message, [], $resource->getRealData(), null, null, null, null, null, $e)); }
php
public static function addResourceError(ResourceInterface $resource, $message, \Exception $e = null): void { $resource->setStatus(ResourceStatutes::ERROR); $resource->getErrors()->add(new ConstraintViolation($message, $message, [], $resource->getRealData(), null, null, null, null, null, $e)); }
[ "public", "static", "function", "addResourceError", "(", "ResourceInterface", "$", "resource", ",", "$", "message", ",", "\\", "Exception", "$", "e", "=", "null", ")", ":", "void", "{", "$", "resource", "->", "setStatus", "(", "ResourceStatutes", "::", "ERROR", ")", ";", "$", "resource", "->", "getErrors", "(", ")", "->", "add", "(", "new", "ConstraintViolation", "(", "$", "message", ",", "$", "message", ",", "[", "]", ",", "$", "resource", "->", "getRealData", "(", ")", ",", "null", ",", "null", ",", "null", ",", "null", ",", "null", ",", "$", "e", ")", ")", ";", "}" ]
Add the error in resource. @param ResourceInterface $resource The resource @param string $message The error message @param null|\Exception $e The exception
[ "Add", "the", "error", "in", "resource", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L222-L226
37,993
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.injectErrorMessage
public static function injectErrorMessage(TranslatorInterface $translator, ResourceInterface $resource, \Exception $e, $debug = false) { if ($e instanceof ConstraintViolationException) { $resource->setStatus(ResourceStatutes::ERROR); $resource->getErrors()->addAll($e->getConstraintViolations()); } else { static::addResourceError($resource, static::getExceptionMessage($translator, $e, $debug), $e); } return true; }
php
public static function injectErrorMessage(TranslatorInterface $translator, ResourceInterface $resource, \Exception $e, $debug = false) { if ($e instanceof ConstraintViolationException) { $resource->setStatus(ResourceStatutes::ERROR); $resource->getErrors()->addAll($e->getConstraintViolations()); } else { static::addResourceError($resource, static::getExceptionMessage($translator, $e, $debug), $e); } return true; }
[ "public", "static", "function", "injectErrorMessage", "(", "TranslatorInterface", "$", "translator", ",", "ResourceInterface", "$", "resource", ",", "\\", "Exception", "$", "e", ",", "$", "debug", "=", "false", ")", "{", "if", "(", "$", "e", "instanceof", "ConstraintViolationException", ")", "{", "$", "resource", "->", "setStatus", "(", "ResourceStatutes", "::", "ERROR", ")", ";", "$", "resource", "->", "getErrors", "(", ")", "->", "addAll", "(", "$", "e", "->", "getConstraintViolations", "(", ")", ")", ";", "}", "else", "{", "static", "::", "addResourceError", "(", "$", "resource", ",", "static", "::", "getExceptionMessage", "(", "$", "translator", ",", "$", "e", ",", "$", "debug", ")", ",", "$", "e", ")", ";", "}", "return", "true", ";", "}" ]
Inject the exception message in resource error list. @param TranslatorInterface $translator The translator @param ResourceInterface $resource The resource @param \Exception $e The exception on persist action @param bool $debug The debug mode @return bool
[ "Inject", "the", "exception", "message", "in", "resource", "error", "list", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L238-L248
37,994
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.getMapErrors
protected static function getMapErrors(ConstraintViolationListInterface $errors) { $maps = []; $size = $errors->count(); for ($i = 0; $i < $size; ++$i) { $root = $errors->get($i)->getRoot(); if (\is_object($root)) { $maps[spl_object_hash($errors->get($i)->getRoot())] = $errors->get($i); } else { $maps[] = $errors->get($i); } } return $maps; }
php
protected static function getMapErrors(ConstraintViolationListInterface $errors) { $maps = []; $size = $errors->count(); for ($i = 0; $i < $size; ++$i) { $root = $errors->get($i)->getRoot(); if (\is_object($root)) { $maps[spl_object_hash($errors->get($i)->getRoot())] = $errors->get($i); } else { $maps[] = $errors->get($i); } } return $maps; }
[ "protected", "static", "function", "getMapErrors", "(", "ConstraintViolationListInterface", "$", "errors", ")", "{", "$", "maps", "=", "[", "]", ";", "$", "size", "=", "$", "errors", "->", "count", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "size", ";", "++", "$", "i", ")", "{", "$", "root", "=", "$", "errors", "->", "get", "(", "$", "i", ")", "->", "getRoot", "(", ")", ";", "if", "(", "\\", "is_object", "(", "$", "root", ")", ")", "{", "$", "maps", "[", "spl_object_hash", "(", "$", "errors", "->", "get", "(", "$", "i", ")", "->", "getRoot", "(", ")", ")", "]", "=", "$", "errors", "->", "get", "(", "$", "i", ")", ";", "}", "else", "{", "$", "maps", "[", "]", "=", "$", "errors", "->", "get", "(", "$", "i", ")", ";", "}", "}", "return", "$", "maps", ";", "}" ]
Get the map of object hash and constraint violation list. @param ConstraintViolationListInterface $errors @return array The map of object hash and constraint violation list
[ "Get", "the", "map", "of", "object", "hash", "and", "constraint", "violation", "list", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L257-L273
37,995
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.extractDriverExceptionMessage
protected static function extractDriverExceptionMessage(DriverException $exception, $message, $debug = false) { if ($debug && null !== $exception->getPrevious()) { $prevMessage = static::getFirstException($exception)->getMessage(); $pos = strpos($prevMessage, ':'); if ($pos > 0 && 0 === strpos($prevMessage, 'SQLSTATE[')) { $message .= ': '.trim(substr($prevMessage, $pos + 1)); } } return $message; }
php
protected static function extractDriverExceptionMessage(DriverException $exception, $message, $debug = false) { if ($debug && null !== $exception->getPrevious()) { $prevMessage = static::getFirstException($exception)->getMessage(); $pos = strpos($prevMessage, ':'); if ($pos > 0 && 0 === strpos($prevMessage, 'SQLSTATE[')) { $message .= ': '.trim(substr($prevMessage, $pos + 1)); } } return $message; }
[ "protected", "static", "function", "extractDriverExceptionMessage", "(", "DriverException", "$", "exception", ",", "$", "message", ",", "$", "debug", "=", "false", ")", "{", "if", "(", "$", "debug", "&&", "null", "!==", "$", "exception", "->", "getPrevious", "(", ")", ")", "{", "$", "prevMessage", "=", "static", "::", "getFirstException", "(", "$", "exception", ")", "->", "getMessage", "(", ")", ";", "$", "pos", "=", "strpos", "(", "$", "prevMessage", ",", "':'", ")", ";", "if", "(", "$", "pos", ">", "0", "&&", "0", "===", "strpos", "(", "$", "prevMessage", ",", "'SQLSTATE['", ")", ")", "{", "$", "message", ".=", "': '", ".", "trim", "(", "substr", "(", "$", "prevMessage", ",", "$", "pos", "+", "1", ")", ")", ";", "}", "}", "return", "$", "message", ";", "}" ]
Format pdo driver exception. @param DriverException $exception The exception @param string $message The message @param bool $debug The debug mode @return string
[ "Format", "pdo", "driver", "exception", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L284-L296
37,996
fxpio/fxp-resource
Domain/DomainUtil.php
DomainUtil.getFirstException
protected static function getFirstException(\Exception $exception) { if (null !== $exception->getPrevious()) { return static::getFirstException($exception->getPrevious()); } return $exception; }
php
protected static function getFirstException(\Exception $exception) { if (null !== $exception->getPrevious()) { return static::getFirstException($exception->getPrevious()); } return $exception; }
[ "protected", "static", "function", "getFirstException", "(", "\\", "Exception", "$", "exception", ")", "{", "if", "(", "null", "!==", "$", "exception", "->", "getPrevious", "(", ")", ")", "{", "return", "static", "::", "getFirstException", "(", "$", "exception", "->", "getPrevious", "(", ")", ")", ";", "}", "return", "$", "exception", ";", "}" ]
Get the initial exception. @param \Exception $exception @return \Exception
[ "Get", "the", "initial", "exception", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Domain/DomainUtil.php#L305-L312
37,997
Smart-Core/CoreBundle
Pagerfanta/DoctrineORM/WhereInWalker.php
WhereInWalker.walkSelectStatement
public function walkSelectStatement(SelectStatement $AST) { $parent = null; $parentName = null; foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) { if (array_key_exists('parent', $qComp) && $qComp['parent'] === null && $qComp['nestingLevel'] == 0) { $parent = $qComp; $parentName = $dqlAlias; break; } } $pathExpression = new PathExpression( PathExpression::TYPE_STATE_FIELD, $parentName, $parent['metadata']->getSingleIdentifierFieldName() ); $pathExpression->type = PathExpression::TYPE_STATE_FIELD; $count = $this->_getQuery()->getHint('id.count'); if ($count > 0) { // in new doctrine 2.2 version there's a different expression if (property_exists('Doctrine\ORM\Query\AST\InExpression', 'expression')) { $arithmeticExpression = new ArithmeticExpression(); $arithmeticExpression->simpleArithmeticExpression = new SimpleArithmeticExpression( array($pathExpression) ); $inExpression = new InExpression($arithmeticExpression); } else { $inExpression = new InExpression($pathExpression); } $ns = $this->_getQuery()->getHint('pg.ns'); for ($i = 1; $i <= $count; $i++) { $inExpression->literals[] = new InputParameter(":{$ns}_$i"); } } else { $inExpression = new NullComparisonExpression($pathExpression); $inExpression->not = false; } $conditionalPrimary = new ConditionalPrimary; $conditionalPrimary->simpleConditionalExpression = $inExpression; // if no existing whereClause if ($AST->whereClause === null) { $AST->whereClause = new WhereClause( new ConditionalExpression(array( new ConditionalTerm(array( new ConditionalFactor($conditionalPrimary) )) )) ); } else { // add to the existing using AND // existing AND clause if ($AST->whereClause->conditionalExpression instanceof ConditionalTerm) { $AST->whereClause->conditionalExpression->conditionalFactors[] = $conditionalPrimary; } // single clause where elseif ($AST->whereClause->conditionalExpression instanceof ConditionalPrimary) { $AST->whereClause->conditionalExpression = new ConditionalExpression( array( new ConditionalTerm( array( $AST->whereClause->conditionalExpression, $conditionalPrimary ) ) ) ); } // an OR or NOT clause elseif ($AST->whereClause->conditionalExpression instanceof ConditionalExpression || $AST->whereClause->conditionalExpression instanceof ConditionalFactor ) { $tmpPrimary = new ConditionalPrimary; $tmpPrimary->conditionalExpression = $AST->whereClause->conditionalExpression; $AST->whereClause->conditionalExpression = new ConditionalTerm( array( $tmpPrimary, $conditionalPrimary, ) ); } else { // error check to provide a more verbose error on failure throw new \RuntimeException("Unknown conditionalExpression in WhereInWalker"); } } }
php
public function walkSelectStatement(SelectStatement $AST) { $parent = null; $parentName = null; foreach ($this->_getQueryComponents() as $dqlAlias => $qComp) { if (array_key_exists('parent', $qComp) && $qComp['parent'] === null && $qComp['nestingLevel'] == 0) { $parent = $qComp; $parentName = $dqlAlias; break; } } $pathExpression = new PathExpression( PathExpression::TYPE_STATE_FIELD, $parentName, $parent['metadata']->getSingleIdentifierFieldName() ); $pathExpression->type = PathExpression::TYPE_STATE_FIELD; $count = $this->_getQuery()->getHint('id.count'); if ($count > 0) { // in new doctrine 2.2 version there's a different expression if (property_exists('Doctrine\ORM\Query\AST\InExpression', 'expression')) { $arithmeticExpression = new ArithmeticExpression(); $arithmeticExpression->simpleArithmeticExpression = new SimpleArithmeticExpression( array($pathExpression) ); $inExpression = new InExpression($arithmeticExpression); } else { $inExpression = new InExpression($pathExpression); } $ns = $this->_getQuery()->getHint('pg.ns'); for ($i = 1; $i <= $count; $i++) { $inExpression->literals[] = new InputParameter(":{$ns}_$i"); } } else { $inExpression = new NullComparisonExpression($pathExpression); $inExpression->not = false; } $conditionalPrimary = new ConditionalPrimary; $conditionalPrimary->simpleConditionalExpression = $inExpression; // if no existing whereClause if ($AST->whereClause === null) { $AST->whereClause = new WhereClause( new ConditionalExpression(array( new ConditionalTerm(array( new ConditionalFactor($conditionalPrimary) )) )) ); } else { // add to the existing using AND // existing AND clause if ($AST->whereClause->conditionalExpression instanceof ConditionalTerm) { $AST->whereClause->conditionalExpression->conditionalFactors[] = $conditionalPrimary; } // single clause where elseif ($AST->whereClause->conditionalExpression instanceof ConditionalPrimary) { $AST->whereClause->conditionalExpression = new ConditionalExpression( array( new ConditionalTerm( array( $AST->whereClause->conditionalExpression, $conditionalPrimary ) ) ) ); } // an OR or NOT clause elseif ($AST->whereClause->conditionalExpression instanceof ConditionalExpression || $AST->whereClause->conditionalExpression instanceof ConditionalFactor ) { $tmpPrimary = new ConditionalPrimary; $tmpPrimary->conditionalExpression = $AST->whereClause->conditionalExpression; $AST->whereClause->conditionalExpression = new ConditionalTerm( array( $tmpPrimary, $conditionalPrimary, ) ); } else { // error check to provide a more verbose error on failure throw new \RuntimeException("Unknown conditionalExpression in WhereInWalker"); } } }
[ "public", "function", "walkSelectStatement", "(", "SelectStatement", "$", "AST", ")", "{", "$", "parent", "=", "null", ";", "$", "parentName", "=", "null", ";", "foreach", "(", "$", "this", "->", "_getQueryComponents", "(", ")", "as", "$", "dqlAlias", "=>", "$", "qComp", ")", "{", "if", "(", "array_key_exists", "(", "'parent'", ",", "$", "qComp", ")", "&&", "$", "qComp", "[", "'parent'", "]", "===", "null", "&&", "$", "qComp", "[", "'nestingLevel'", "]", "==", "0", ")", "{", "$", "parent", "=", "$", "qComp", ";", "$", "parentName", "=", "$", "dqlAlias", ";", "break", ";", "}", "}", "$", "pathExpression", "=", "new", "PathExpression", "(", "PathExpression", "::", "TYPE_STATE_FIELD", ",", "$", "parentName", ",", "$", "parent", "[", "'metadata'", "]", "->", "getSingleIdentifierFieldName", "(", ")", ")", ";", "$", "pathExpression", "->", "type", "=", "PathExpression", "::", "TYPE_STATE_FIELD", ";", "$", "count", "=", "$", "this", "->", "_getQuery", "(", ")", "->", "getHint", "(", "'id.count'", ")", ";", "if", "(", "$", "count", ">", "0", ")", "{", "// in new doctrine 2.2 version there's a different expression", "if", "(", "property_exists", "(", "'Doctrine\\ORM\\Query\\AST\\InExpression'", ",", "'expression'", ")", ")", "{", "$", "arithmeticExpression", "=", "new", "ArithmeticExpression", "(", ")", ";", "$", "arithmeticExpression", "->", "simpleArithmeticExpression", "=", "new", "SimpleArithmeticExpression", "(", "array", "(", "$", "pathExpression", ")", ")", ";", "$", "inExpression", "=", "new", "InExpression", "(", "$", "arithmeticExpression", ")", ";", "}", "else", "{", "$", "inExpression", "=", "new", "InExpression", "(", "$", "pathExpression", ")", ";", "}", "$", "ns", "=", "$", "this", "->", "_getQuery", "(", ")", "->", "getHint", "(", "'pg.ns'", ")", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "count", ";", "$", "i", "++", ")", "{", "$", "inExpression", "->", "literals", "[", "]", "=", "new", "InputParameter", "(", "\":{$ns}_$i\"", ")", ";", "}", "}", "else", "{", "$", "inExpression", "=", "new", "NullComparisonExpression", "(", "$", "pathExpression", ")", ";", "$", "inExpression", "->", "not", "=", "false", ";", "}", "$", "conditionalPrimary", "=", "new", "ConditionalPrimary", ";", "$", "conditionalPrimary", "->", "simpleConditionalExpression", "=", "$", "inExpression", ";", "// if no existing whereClause", "if", "(", "$", "AST", "->", "whereClause", "===", "null", ")", "{", "$", "AST", "->", "whereClause", "=", "new", "WhereClause", "(", "new", "ConditionalExpression", "(", "array", "(", "new", "ConditionalTerm", "(", "array", "(", "new", "ConditionalFactor", "(", "$", "conditionalPrimary", ")", ")", ")", ")", ")", ")", ";", "}", "else", "{", "// add to the existing using AND", "// existing AND clause", "if", "(", "$", "AST", "->", "whereClause", "->", "conditionalExpression", "instanceof", "ConditionalTerm", ")", "{", "$", "AST", "->", "whereClause", "->", "conditionalExpression", "->", "conditionalFactors", "[", "]", "=", "$", "conditionalPrimary", ";", "}", "// single clause where", "elseif", "(", "$", "AST", "->", "whereClause", "->", "conditionalExpression", "instanceof", "ConditionalPrimary", ")", "{", "$", "AST", "->", "whereClause", "->", "conditionalExpression", "=", "new", "ConditionalExpression", "(", "array", "(", "new", "ConditionalTerm", "(", "array", "(", "$", "AST", "->", "whereClause", "->", "conditionalExpression", ",", "$", "conditionalPrimary", ")", ")", ")", ")", ";", "}", "// an OR or NOT clause", "elseif", "(", "$", "AST", "->", "whereClause", "->", "conditionalExpression", "instanceof", "ConditionalExpression", "||", "$", "AST", "->", "whereClause", "->", "conditionalExpression", "instanceof", "ConditionalFactor", ")", "{", "$", "tmpPrimary", "=", "new", "ConditionalPrimary", ";", "$", "tmpPrimary", "->", "conditionalExpression", "=", "$", "AST", "->", "whereClause", "->", "conditionalExpression", ";", "$", "AST", "->", "whereClause", "->", "conditionalExpression", "=", "new", "ConditionalTerm", "(", "array", "(", "$", "tmpPrimary", ",", "$", "conditionalPrimary", ",", ")", ")", ";", "}", "else", "{", "// error check to provide a more verbose error on failure", "throw", "new", "\\", "RuntimeException", "(", "\"Unknown conditionalExpression in WhereInWalker\"", ")", ";", "}", "}", "}" ]
Replaces the whereClause in the AST Generates a clause equivalent to WHERE IN (:pgid_1, :pgid_2, ...) The parameter namespace (pgid) is retrieved from the pg.ns query hint The total number of parameters is retrieved from the id.count query hint @param SelectStatement $AST @return void
[ "Replaces", "the", "whereClause", "in", "the", "AST" ]
d74829de254237008eb92ad213c7e7f41d91aac4
https://github.com/Smart-Core/CoreBundle/blob/d74829de254237008eb92ad213c7e7f41d91aac4/Pagerfanta/DoctrineORM/WhereInWalker.php#L50-L135
37,998
systemson/common
src/Utils/Implementations/AbstractWrapper.php
AbstractWrapper.getInstance
public static function getInstance() { $accesor = static::getAccessor(); if (!static::$instance instanceof $accesor) { static::beforeConstruct(); $args = static::getArguments(); static::$instance = static::make($accesor, $args); static::afterConstruct(); } return static::$instance; }
php
public static function getInstance() { $accesor = static::getAccessor(); if (!static::$instance instanceof $accesor) { static::beforeConstruct(); $args = static::getArguments(); static::$instance = static::make($accesor, $args); static::afterConstruct(); } return static::$instance; }
[ "public", "static", "function", "getInstance", "(", ")", "{", "$", "accesor", "=", "static", "::", "getAccessor", "(", ")", ";", "if", "(", "!", "static", "::", "$", "instance", "instanceof", "$", "accesor", ")", "{", "static", "::", "beforeConstruct", "(", ")", ";", "$", "args", "=", "static", "::", "getArguments", "(", ")", ";", "static", "::", "$", "instance", "=", "static", "::", "make", "(", "$", "accesor", ",", "$", "args", ")", ";", "static", "::", "afterConstruct", "(", ")", ";", "}", "return", "static", "::", "$", "instance", ";", "}" ]
Returns the instance of the class.
[ "Returns", "the", "instance", "of", "the", "class", "." ]
00333341bbdba6cd1e4cdb7561f7e17bc756935e
https://github.com/systemson/common/blob/00333341bbdba6cd1e4cdb7561f7e17bc756935e/src/Utils/Implementations/AbstractWrapper.php#L84-L99
37,999
fxpio/fxp-resource
Handler/DomainFormConfigList.php
DomainFormConfigList.findObjects
protected function findObjects(array $ids) { $foundObjects = $this->domain->getRepository()->findBy([ $this->identifier => array_unique($ids), ]); $mapFinds = []; $objects = []; foreach ($foundObjects as $foundObject) { $id = $this->propertyAccessor->getValue($foundObject, $this->identifier); $mapFinds[$id] = $foundObject; } foreach ($ids as $i => $id) { $objects[$i] = $mapFinds[$id] ?? $this->domain->newInstance($this->defaultValueOptions); } return $objects; }
php
protected function findObjects(array $ids) { $foundObjects = $this->domain->getRepository()->findBy([ $this->identifier => array_unique($ids), ]); $mapFinds = []; $objects = []; foreach ($foundObjects as $foundObject) { $id = $this->propertyAccessor->getValue($foundObject, $this->identifier); $mapFinds[$id] = $foundObject; } foreach ($ids as $i => $id) { $objects[$i] = $mapFinds[$id] ?? $this->domain->newInstance($this->defaultValueOptions); } return $objects; }
[ "protected", "function", "findObjects", "(", "array", "$", "ids", ")", "{", "$", "foundObjects", "=", "$", "this", "->", "domain", "->", "getRepository", "(", ")", "->", "findBy", "(", "[", "$", "this", "->", "identifier", "=>", "array_unique", "(", "$", "ids", ")", ",", "]", ")", ";", "$", "mapFinds", "=", "[", "]", ";", "$", "objects", "=", "[", "]", ";", "foreach", "(", "$", "foundObjects", "as", "$", "foundObject", ")", "{", "$", "id", "=", "$", "this", "->", "propertyAccessor", "->", "getValue", "(", "$", "foundObject", ",", "$", "this", "->", "identifier", ")", ";", "$", "mapFinds", "[", "$", "id", "]", "=", "$", "foundObject", ";", "}", "foreach", "(", "$", "ids", "as", "$", "i", "=>", "$", "id", ")", "{", "$", "objects", "[", "$", "i", "]", "=", "$", "mapFinds", "[", "$", "id", "]", "??", "$", "this", "->", "domain", "->", "newInstance", "(", "$", "this", "->", "defaultValueOptions", ")", ";", "}", "return", "$", "objects", ";", "}" ]
Find the objects. @param int[] $ids The record ids @return array
[ "Find", "the", "objects", "." ]
cb786bdc04c67d242591fbde6d0723f7d6834f35
https://github.com/fxpio/fxp-resource/blob/cb786bdc04c67d242591fbde6d0723f7d6834f35/Handler/DomainFormConfigList.php#L137-L156