repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
dappur/dappurware
app/src/Dappurware/Cookies.php
Cookies.modifyRequestCookie
public function modifyRequestCookie($request, $name, $value = null) { $modify = function (Cookie $cookie) { $value = $cookie->getValue(); return $cookie->withValue($value); }; $request = FigRequestCookies::modify($request, $name, $modify); return $request; }
php
public function modifyRequestCookie($request, $name, $value = null) { $modify = function (Cookie $cookie) { $value = $cookie->getValue(); return $cookie->withValue($value); }; $request = FigRequestCookies::modify($request, $name, $modify); return $request; }
[ "public", "function", "modifyRequestCookie", "(", "$", "request", ",", "$", "name", ",", "$", "value", "=", "null", ")", "{", "$", "modify", "=", "function", "(", "Cookie", "$", "cookie", ")", "{", "$", "value", "=", "$", "cookie", "->", "getValue", "(", ")", ";", "return", "$", "cookie", "->", "withValue", "(", "$", "value", ")", ";", "}", ";", "$", "request", "=", "FigRequestCookies", "::", "modify", "(", "$", "request", ",", "$", "name", ",", "$", "modify", ")", ";", "return", "$", "request", ";", "}" ]
Modify Request Cookie
[ "Modify", "Request", "Cookie" ]
train
https://github.com/dappur/dappurware/blob/453ca999047693a1f009618820f8497a287f6a05/app/src/Dappurware/Cookies.php#L98-L109
kecik-framework/kecik
Kecik/Request.php
Request.get
public static function get( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $_GET[ $name ] = $value; } if ( empty( $name ) ) { return $_GET; } else { return ( isset( $_GET[ $name ] ) ) ? $_GET[ $name ] : NULL; } }
php
public static function get( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $_GET[ $name ] = $value; } if ( empty( $name ) ) { return $_GET; } else { return ( isset( $_GET[ $name ] ) ) ? $_GET[ $name ] : NULL; } }
[ "public", "static", "function", "get", "(", "$", "name", "=", "''", ",", "$", "value", "=", "''", ")", "{", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "_GET", "[", "$", "name", "]", "=", "$", "value", ";", "}", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "return", "$", "_GET", ";", "}", "else", "{", "return", "(", "isset", "(", "$", "_GET", "[", "$", "name", "]", ")", ")", "?", "$", "_GET", "[", "$", "name", "]", ":", "NULL", ";", "}", "}" ]
Get/Set variable from Get Method @param string $name @param string $value @return mixed|null
[ "Get", "/", "Set", "variable", "from", "Get", "Method" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Request.php#L38-L50
kecik-framework/kecik
Kecik/Request.php
Request.post
public static function post( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $_POST[ $name ] = $value; } if ( empty( $name ) ) { return $_POST; } else { return ( isset( $_POST[ $name ] ) ) ? $_POST[ $name ] : NULL; } }
php
public static function post( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $_POST[ $name ] = $value; } if ( empty( $name ) ) { return $_POST; } else { return ( isset( $_POST[ $name ] ) ) ? $_POST[ $name ] : NULL; } }
[ "public", "static", "function", "post", "(", "$", "name", "=", "''", ",", "$", "value", "=", "''", ")", "{", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "_POST", "[", "$", "name", "]", "=", "$", "value", ";", "}", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "return", "$", "_POST", ";", "}", "else", "{", "return", "(", "isset", "(", "$", "_POST", "[", "$", "name", "]", ")", ")", "?", "$", "_POST", "[", "$", "name", "]", ":", "NULL", ";", "}", "}" ]
Get/Set variable from Post Method @param string $name @param string $value @return mixed|null
[ "Get", "/", "Set", "variable", "from", "Post", "Method" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Request.php#L60-L72
kecik-framework/kecik
Kecik/Request.php
Request.put
public static function put( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $GLOBALS['_PUT'][ $name ] = $value; } if ( empty( $name ) ) { return ( isset( $GLOBALS['_PUT'] ) ) ? $GLOBALS['_PUT'] : NULL; } else { return ( isset( $GLOBALS['_PUT'][ $name ] ) ) ? $GLOBALS['_PUT'][ $name ] : NULL; } }
php
public static function put( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $GLOBALS['_PUT'][ $name ] = $value; } if ( empty( $name ) ) { return ( isset( $GLOBALS['_PUT'] ) ) ? $GLOBALS['_PUT'] : NULL; } else { return ( isset( $GLOBALS['_PUT'][ $name ] ) ) ? $GLOBALS['_PUT'][ $name ] : NULL; } }
[ "public", "static", "function", "put", "(", "$", "name", "=", "''", ",", "$", "value", "=", "''", ")", "{", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "GLOBALS", "[", "'_PUT'", "]", "[", "$", "name", "]", "=", "$", "value", ";", "}", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "return", "(", "isset", "(", "$", "GLOBALS", "[", "'_PUT'", "]", ")", ")", "?", "$", "GLOBALS", "[", "'_PUT'", "]", ":", "NULL", ";", "}", "else", "{", "return", "(", "isset", "(", "$", "GLOBALS", "[", "'_PUT'", "]", "[", "$", "name", "]", ")", ")", "?", "$", "GLOBALS", "[", "'_PUT'", "]", "[", "$", "name", "]", ":", "NULL", ";", "}", "}" ]
Get/Set variable from Put Method @param string $name @param string $value @return mixed|null
[ "Get", "/", "Set", "variable", "from", "Put", "Method" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Request.php#L82-L94
kecik-framework/kecik
Kecik/Request.php
Request.delete
public static function delete( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $GLOBALS['_DELETE'][ $name ] = $value; } if ( empty( $name ) ) { return ( isset( $GLOBALS['_DELETE'] ) ) ? $GLOBALS['_DELETE'] : NULL; } else { return ( isset( $GLOBALS['_DELETE'][ $name ] ) ) ? $GLOBALS['_DELETE'][ $name ] : NULL; } }
php
public static function delete( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $GLOBALS['_DELETE'][ $name ] = $value; } if ( empty( $name ) ) { return ( isset( $GLOBALS['_DELETE'] ) ) ? $GLOBALS['_DELETE'] : NULL; } else { return ( isset( $GLOBALS['_DELETE'][ $name ] ) ) ? $GLOBALS['_DELETE'][ $name ] : NULL; } }
[ "public", "static", "function", "delete", "(", "$", "name", "=", "''", ",", "$", "value", "=", "''", ")", "{", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "GLOBALS", "[", "'_DELETE'", "]", "[", "$", "name", "]", "=", "$", "value", ";", "}", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "return", "(", "isset", "(", "$", "GLOBALS", "[", "'_DELETE'", "]", ")", ")", "?", "$", "GLOBALS", "[", "'_DELETE'", "]", ":", "NULL", ";", "}", "else", "{", "return", "(", "isset", "(", "$", "GLOBALS", "[", "'_DELETE'", "]", "[", "$", "name", "]", ")", ")", "?", "$", "GLOBALS", "[", "'_DELETE'", "]", "[", "$", "name", "]", ":", "NULL", ";", "}", "}" ]
Get/Set variable from Delete Method @param string $name @param string $value @return mixed|null
[ "Get", "/", "Set", "variable", "from", "Delete", "Method" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Request.php#L104-L116
kecik-framework/kecik
Kecik/Request.php
Request.patch
public static function patch( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $GLOBALS['_PATCH'][ $name ] = $value; } if ( empty( $name ) ) { return ( isset( $GLOBALS['_PATCH'] ) ) ? $GLOBALS['_PATCH'] : NULL; } else { return ( isset( $GLOBALS['_PATCH'][ $name ] ) ) ? $GLOBALS['_PATCH'][ $name ] : NULL; } }
php
public static function patch( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $GLOBALS['_PATCH'][ $name ] = $value; } if ( empty( $name ) ) { return ( isset( $GLOBALS['_PATCH'] ) ) ? $GLOBALS['_PATCH'] : NULL; } else { return ( isset( $GLOBALS['_PATCH'][ $name ] ) ) ? $GLOBALS['_PATCH'][ $name ] : NULL; } }
[ "public", "static", "function", "patch", "(", "$", "name", "=", "''", ",", "$", "value", "=", "''", ")", "{", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "GLOBALS", "[", "'_PATCH'", "]", "[", "$", "name", "]", "=", "$", "value", ";", "}", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "return", "(", "isset", "(", "$", "GLOBALS", "[", "'_PATCH'", "]", ")", ")", "?", "$", "GLOBALS", "[", "'_PATCH'", "]", ":", "NULL", ";", "}", "else", "{", "return", "(", "isset", "(", "$", "GLOBALS", "[", "'_PATCH'", "]", "[", "$", "name", "]", ")", ")", "?", "$", "GLOBALS", "[", "'_PATCH'", "]", "[", "$", "name", "]", ":", "NULL", ";", "}", "}" ]
Get/Set variable from Patch Method @param string $name @param string $value @return mixed|null
[ "Get", "/", "Set", "variable", "from", "Patch", "Method" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Request.php#L126-L138
kecik-framework/kecik
Kecik/Request.php
Request.options
public static function options( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $GLOBALS['_OPTIONS'][ $name ] = $value; } if ( empty( $name ) ) { return ( isset( $GLOBALS['_OPTIONS'] ) ) ? $GLOBALS['_OPTIONS'] : NULL; } else { return ( isset( $GLOBALS['_OPTIONS'][ $name ] ) ) ? $GLOBALS['_OPTIONS'][ $value ] : NULL; } }
php
public static function options( $name = '', $value = '' ) { if ( ! empty( $value ) ) { $GLOBALS['_OPTIONS'][ $name ] = $value; } if ( empty( $name ) ) { return ( isset( $GLOBALS['_OPTIONS'] ) ) ? $GLOBALS['_OPTIONS'] : NULL; } else { return ( isset( $GLOBALS['_OPTIONS'][ $name ] ) ) ? $GLOBALS['_OPTIONS'][ $value ] : NULL; } }
[ "public", "static", "function", "options", "(", "$", "name", "=", "''", ",", "$", "value", "=", "''", ")", "{", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "GLOBALS", "[", "'_OPTIONS'", "]", "[", "$", "name", "]", "=", "$", "value", ";", "}", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "return", "(", "isset", "(", "$", "GLOBALS", "[", "'_OPTIONS'", "]", ")", ")", "?", "$", "GLOBALS", "[", "'_OPTIONS'", "]", ":", "NULL", ";", "}", "else", "{", "return", "(", "isset", "(", "$", "GLOBALS", "[", "'_OPTIONS'", "]", "[", "$", "name", "]", ")", ")", "?", "$", "GLOBALS", "[", "'_OPTIONS'", "]", "[", "$", "value", "]", ":", "NULL", ";", "}", "}" ]
Get/Set variable from Options Method @param string $name @param string $value @return mixed|null
[ "Get", "/", "Set", "variable", "from", "Options", "Method" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Request.php#L148-L160
kecik-framework/kecik
Kecik/Request.php
UploadFile.move
public function move( $destination, $newName = '' ) { $source = $this->file['tmp_name']; if ( $destination != '' && substr( $destination, - 1 ) != '/' ) { $destination .= '/'; } if ( ! empty( $newName ) ) { $target = $destination . $newName; } else { $target = $destination . $this->file['name']; } if ( ! @move_uploaded_file( $source, $target ) ) { $error = error_get_last(); throw new FileException( sprintf( 'Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags( $error['message'] ) ) ); } @chmod( $target, 0666 & ~umask() ); return $target; }
php
public function move( $destination, $newName = '' ) { $source = $this->file['tmp_name']; if ( $destination != '' && substr( $destination, - 1 ) != '/' ) { $destination .= '/'; } if ( ! empty( $newName ) ) { $target = $destination . $newName; } else { $target = $destination . $this->file['name']; } if ( ! @move_uploaded_file( $source, $target ) ) { $error = error_get_last(); throw new FileException( sprintf( 'Could not move the file "%s" to "%s" (%s)', $this->getPathname(), $target, strip_tags( $error['message'] ) ) ); } @chmod( $target, 0666 & ~umask() ); return $target; }
[ "public", "function", "move", "(", "$", "destination", ",", "$", "newName", "=", "''", ")", "{", "$", "source", "=", "$", "this", "->", "file", "[", "'tmp_name'", "]", ";", "if", "(", "$", "destination", "!=", "''", "&&", "substr", "(", "$", "destination", ",", "-", "1", ")", "!=", "'/'", ")", "{", "$", "destination", ".=", "'/'", ";", "}", "if", "(", "!", "empty", "(", "$", "newName", ")", ")", "{", "$", "target", "=", "$", "destination", ".", "$", "newName", ";", "}", "else", "{", "$", "target", "=", "$", "destination", ".", "$", "this", "->", "file", "[", "'name'", "]", ";", "}", "if", "(", "!", "@", "move_uploaded_file", "(", "$", "source", ",", "$", "target", ")", ")", "{", "$", "error", "=", "error_get_last", "(", ")", ";", "throw", "new", "FileException", "(", "sprintf", "(", "'Could not move the file \"%s\" to \"%s\" (%s)'", ",", "$", "this", "->", "getPathname", "(", ")", ",", "$", "target", ",", "strip_tags", "(", "$", "error", "[", "'message'", "]", ")", ")", ")", ";", "}", "@", "chmod", "(", "$", "target", ",", "0666", "&", "~", "umask", "(", ")", ")", ";", "return", "$", "target", ";", "}" ]
Move file from temporary to actual location @param $destination @param string $newName @return string @throws FileException
[ "Move", "file", "from", "temporary", "to", "actual", "location" ]
train
https://github.com/kecik-framework/kecik/blob/fa87e593affe1c9c51a2acd264b85ec06df31d7c/Kecik/Request.php#L225-L255
heidelpay/PhpDoc
src/phpDocumentor/Transformer/Router/Rule.php
Rule.translateToUrlEncodedPath
protected function translateToUrlEncodedPath($generatedPathAsUtf8) { $iso88591Path = explode('/', $generatedPathAsUtf8); foreach ($iso88591Path as &$part) { // identify and skip schemes if (substr($part, -1) == ':') { continue; } // only encode and transliterate that which comes before the anchor $subparts = explode('#', $part); if (extension_loaded('iconv')) { $subparts[0] = iconv('UTF-8', 'ASCII//TRANSLIT', $subparts[0]); } $subparts[0] = urlencode($subparts[0]); $part = implode('#', $subparts); } return implode('/', $iso88591Path); }
php
protected function translateToUrlEncodedPath($generatedPathAsUtf8) { $iso88591Path = explode('/', $generatedPathAsUtf8); foreach ($iso88591Path as &$part) { // identify and skip schemes if (substr($part, -1) == ':') { continue; } // only encode and transliterate that which comes before the anchor $subparts = explode('#', $part); if (extension_loaded('iconv')) { $subparts[0] = iconv('UTF-8', 'ASCII//TRANSLIT', $subparts[0]); } $subparts[0] = urlencode($subparts[0]); $part = implode('#', $subparts); } return implode('/', $iso88591Path); }
[ "protected", "function", "translateToUrlEncodedPath", "(", "$", "generatedPathAsUtf8", ")", "{", "$", "iso88591Path", "=", "explode", "(", "'/'", ",", "$", "generatedPathAsUtf8", ")", ";", "foreach", "(", "$", "iso88591Path", "as", "&", "$", "part", ")", "{", "// identify and skip schemes", "if", "(", "substr", "(", "$", "part", ",", "-", "1", ")", "==", "':'", ")", "{", "continue", ";", "}", "// only encode and transliterate that which comes before the anchor", "$", "subparts", "=", "explode", "(", "'#'", ",", "$", "part", ")", ";", "if", "(", "extension_loaded", "(", "'iconv'", ")", ")", "{", "$", "subparts", "[", "0", "]", "=", "iconv", "(", "'UTF-8'", ",", "'ASCII//TRANSLIT'", ",", "$", "subparts", "[", "0", "]", ")", ";", "}", "$", "subparts", "[", "0", "]", "=", "urlencode", "(", "$", "subparts", "[", "0", "]", ")", ";", "$", "part", "=", "implode", "(", "'#'", ",", "$", "subparts", ")", ";", "}", "return", "implode", "(", "'/'", ",", "$", "iso88591Path", ")", ";", "}" ]
Translates the provided path, with UTF-8 characters, into a web- and windows-safe variant. Windows does not support the use of UTF-8 characters on their file-system. In order to be sure that both the web and windows can support the given filename we decode the UTF-8 characters and then url encode them so that they will be plain characters that are suitable for the web. If an anchor is found in the path, then it is neither url_encoded not transliterated because it should not result in a filename (otherwise another part of the application has made an error) but may be used during rendering of templates. @param string $generatedPathAsUtf8 @return string
[ "Translates", "the", "provided", "path", "with", "UTF", "-", "8", "characters", "into", "a", "web", "-", "and", "windows", "-", "safe", "variant", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Router/Rule.php#L88-L110
inhere/php-librarys
src/Traits/LogProfileTrait.php
LogProfileTrait.profile
public function profile($name, array $context = [], $category = 'application') { $data = [ '_profile_stats' => [ 'startTime' => microtime(true), 'startMem' => memory_get_usage(), ], '_profile_start' => $context, '_profile_end' => null, ]; $this->activeKey = $category . '|' . $name; $this->profiles[$category][$name] = $data; }
php
public function profile($name, array $context = [], $category = 'application') { $data = [ '_profile_stats' => [ 'startTime' => microtime(true), 'startMem' => memory_get_usage(), ], '_profile_start' => $context, '_profile_end' => null, ]; $this->activeKey = $category . '|' . $name; $this->profiles[$category][$name] = $data; }
[ "public", "function", "profile", "(", "$", "name", ",", "array", "$", "context", "=", "[", "]", ",", "$", "category", "=", "'application'", ")", "{", "$", "data", "=", "[", "'_profile_stats'", "=>", "[", "'startTime'", "=>", "microtime", "(", "true", ")", ",", "'startMem'", "=>", "memory_get_usage", "(", ")", ",", "]", ",", "'_profile_start'", "=>", "$", "context", ",", "'_profile_end'", "=>", "null", ",", "]", ";", "$", "this", "->", "activeKey", "=", "$", "category", ".", "'|'", ".", "$", "name", ";", "$", "this", "->", "profiles", "[", "$", "category", "]", "[", "$", "name", "]", "=", "$", "data", ";", "}" ]
mark data analysis start @param $name @param array $context @param string $category
[ "mark", "data", "analysis", "start" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/LogProfileTrait.php#L36-L49
inhere/php-librarys
src/Traits/LogProfileTrait.php
LogProfileTrait.profileEnd
public function profileEnd($title = null, array $context = []) { if (!$this->activeKey) { return; } list($category, $name) = explode('|', $this->activeKey); if (isset($this->profiles[$category][$name])) { $data = $this->profiles[$category][$name]; $old = $data['_profile_stats']; $data['_profile_stats'] = PhpHelper::runtime($old['startTime'], $old['startMem']); $data['_profile_end'] = $context; $title = $category . ' - ' . ($title ?: $name); $this->activeKey = null; $this->log(Logger::DEBUG, $title, $data); } }
php
public function profileEnd($title = null, array $context = []) { if (!$this->activeKey) { return; } list($category, $name) = explode('|', $this->activeKey); if (isset($this->profiles[$category][$name])) { $data = $this->profiles[$category][$name]; $old = $data['_profile_stats']; $data['_profile_stats'] = PhpHelper::runtime($old['startTime'], $old['startMem']); $data['_profile_end'] = $context; $title = $category . ' - ' . ($title ?: $name); $this->activeKey = null; $this->log(Logger::DEBUG, $title, $data); } }
[ "public", "function", "profileEnd", "(", "$", "title", "=", "null", ",", "array", "$", "context", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "activeKey", ")", "{", "return", ";", "}", "list", "(", "$", "category", ",", "$", "name", ")", "=", "explode", "(", "'|'", ",", "$", "this", "->", "activeKey", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "profiles", "[", "$", "category", "]", "[", "$", "name", "]", ")", ")", "{", "$", "data", "=", "$", "this", "->", "profiles", "[", "$", "category", "]", "[", "$", "name", "]", ";", "$", "old", "=", "$", "data", "[", "'_profile_stats'", "]", ";", "$", "data", "[", "'_profile_stats'", "]", "=", "PhpHelper", "::", "runtime", "(", "$", "old", "[", "'startTime'", "]", ",", "$", "old", "[", "'startMem'", "]", ")", ";", "$", "data", "[", "'_profile_end'", "]", "=", "$", "context", ";", "$", "title", "=", "$", "category", ".", "' - '", ".", "(", "$", "title", "?", ":", "$", "name", ")", ";", "$", "this", "->", "activeKey", "=", "null", ";", "$", "this", "->", "log", "(", "Logger", "::", "DEBUG", ",", "$", "title", ",", "$", "data", ")", ";", "}", "}" ]
mark data analysis end @param string|null $title @param array $context
[ "mark", "data", "analysis", "end" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/LogProfileTrait.php#L56-L76
DevGroup-ru/yii2-measure
src/actions/UpdateAction.php
UpdateAction.run
public function run($id = null) { if ($id === null) { $model = new Measure; $model->loadDefaultValues(); } else { $model = $this->controller->findModel($id); } $isLoaded = $model->load(\Yii::$app->request->post()); $hasAccess = ($model->isNewRecord && \Yii::$app->user->can('measure-create-measure')) || (!$model->isNewRecord && \Yii::$app->user->can('measure-edit-measure')); if ($isLoaded && !$hasAccess) { throw new ForbiddenHttpException; } if ($isLoaded && $model->save()) { return $this->controller->redirect(['update', 'id' => $model->id]); } else { return $this->controller->render( 'update', [ 'hasAccess' => $hasAccess, 'model' => $model, ] ); } }
php
public function run($id = null) { if ($id === null) { $model = new Measure; $model->loadDefaultValues(); } else { $model = $this->controller->findModel($id); } $isLoaded = $model->load(\Yii::$app->request->post()); $hasAccess = ($model->isNewRecord && \Yii::$app->user->can('measure-create-measure')) || (!$model->isNewRecord && \Yii::$app->user->can('measure-edit-measure')); if ($isLoaded && !$hasAccess) { throw new ForbiddenHttpException; } if ($isLoaded && $model->save()) { return $this->controller->redirect(['update', 'id' => $model->id]); } else { return $this->controller->render( 'update', [ 'hasAccess' => $hasAccess, 'model' => $model, ] ); } }
[ "public", "function", "run", "(", "$", "id", "=", "null", ")", "{", "if", "(", "$", "id", "===", "null", ")", "{", "$", "model", "=", "new", "Measure", ";", "$", "model", "->", "loadDefaultValues", "(", ")", ";", "}", "else", "{", "$", "model", "=", "$", "this", "->", "controller", "->", "findModel", "(", "$", "id", ")", ";", "}", "$", "isLoaded", "=", "$", "model", "->", "load", "(", "\\", "Yii", "::", "$", "app", "->", "request", "->", "post", "(", ")", ")", ";", "$", "hasAccess", "=", "(", "$", "model", "->", "isNewRecord", "&&", "\\", "Yii", "::", "$", "app", "->", "user", "->", "can", "(", "'measure-create-measure'", ")", ")", "||", "(", "!", "$", "model", "->", "isNewRecord", "&&", "\\", "Yii", "::", "$", "app", "->", "user", "->", "can", "(", "'measure-edit-measure'", ")", ")", ";", "if", "(", "$", "isLoaded", "&&", "!", "$", "hasAccess", ")", "{", "throw", "new", "ForbiddenHttpException", ";", "}", "if", "(", "$", "isLoaded", "&&", "$", "model", "->", "save", "(", ")", ")", "{", "return", "$", "this", "->", "controller", "->", "redirect", "(", "[", "'update'", ",", "'id'", "=>", "$", "model", "->", "id", "]", ")", ";", "}", "else", "{", "return", "$", "this", "->", "controller", "->", "render", "(", "'update'", ",", "[", "'hasAccess'", "=>", "$", "hasAccess", ",", "'model'", "=>", "$", "model", ",", "]", ")", ";", "}", "}" ]
Updates an existing Measure model. If update is successful, the browser will be redirected to the 'view' page. @param integer $id @return mixed
[ "Updates", "an", "existing", "Measure", "model", ".", "If", "update", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "view", "page", "." ]
train
https://github.com/DevGroup-ru/yii2-measure/blob/1d41a4af6ad3f2e34cabc32fa1c97bfd3643269c/src/actions/UpdateAction.php#L22-L47
mothership-ec/composer
src/Composer/IO/ConsoleIO.php
ConsoleIO.overwrite
public function overwrite($messages, $newline = true, $size = null) { $this->doOverwrite($messages, $newline, $size, false); }
php
public function overwrite($messages, $newline = true, $size = null) { $this->doOverwrite($messages, $newline, $size, false); }
[ "public", "function", "overwrite", "(", "$", "messages", ",", "$", "newline", "=", "true", ",", "$", "size", "=", "null", ")", "{", "$", "this", "->", "doOverwrite", "(", "$", "messages", ",", "$", "newline", ",", "$", "size", ",", "false", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/IO/ConsoleIO.php#L142-L145
mothership-ec/composer
src/Composer/IO/ConsoleIO.php
ConsoleIO.overwriteError
public function overwriteError($messages, $newline = true, $size = null) { $this->doOverwrite($messages, $newline, $size, true); }
php
public function overwriteError($messages, $newline = true, $size = null) { $this->doOverwrite($messages, $newline, $size, true); }
[ "public", "function", "overwriteError", "(", "$", "messages", ",", "$", "newline", "=", "true", ",", "$", "size", "=", "null", ")", "{", "$", "this", "->", "doOverwrite", "(", "$", "messages", ",", "$", "newline", ",", "$", "size", ",", "true", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/IO/ConsoleIO.php#L150-L153
mothership-ec/composer
src/Composer/IO/ConsoleIO.php
ConsoleIO.askConfirmation
public function askConfirmation($question, $default = true) { $output = $this->output; if ($output instanceof ConsoleOutputInterface) { $output = $output->getErrorOutput(); } /** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */ $helper = $this->helperSet->get('question'); $question = new ConfirmationQuestion($question, $default); return $helper->ask($this->input, $output, $question); }
php
public function askConfirmation($question, $default = true) { $output = $this->output; if ($output instanceof ConsoleOutputInterface) { $output = $output->getErrorOutput(); } /** @var \Symfony\Component\Console\Helper\QuestionHelper $helper */ $helper = $this->helperSet->get('question'); $question = new ConfirmationQuestion($question, $default); return $helper->ask($this->input, $output, $question); }
[ "public", "function", "askConfirmation", "(", "$", "question", ",", "$", "default", "=", "true", ")", "{", "$", "output", "=", "$", "this", "->", "output", ";", "if", "(", "$", "output", "instanceof", "ConsoleOutputInterface", ")", "{", "$", "output", "=", "$", "output", "->", "getErrorOutput", "(", ")", ";", "}", "/** @var \\Symfony\\Component\\Console\\Helper\\QuestionHelper $helper */", "$", "helper", "=", "$", "this", "->", "helperSet", "->", "get", "(", "'question'", ")", ";", "$", "question", "=", "new", "ConfirmationQuestion", "(", "$", "question", ",", "$", "default", ")", ";", "return", "$", "helper", "->", "ask", "(", "$", "this", "->", "input", ",", "$", "output", ",", "$", "question", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/IO/ConsoleIO.php#L217-L230
mothership-ec/composer
src/Composer/IO/ConsoleIO.php
ConsoleIO.askAndHideAnswer
public function askAndHideAnswer($question) { $this->writeError($question, false); return \Seld\CliPrompt\CliPrompt::hiddenPrompt(true); }
php
public function askAndHideAnswer($question) { $this->writeError($question, false); return \Seld\CliPrompt\CliPrompt::hiddenPrompt(true); }
[ "public", "function", "askAndHideAnswer", "(", "$", "question", ")", "{", "$", "this", "->", "writeError", "(", "$", "question", ",", "false", ")", ";", "return", "\\", "Seld", "\\", "CliPrompt", "\\", "CliPrompt", "::", "hiddenPrompt", "(", "true", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/IO/ConsoleIO.php#L255-L260
technote-space/wordpress-plugin-base
src/classes/models/lib/loader.php
Loader.initialize
protected function initialize() { $scan_dir = $this->app->define->lib_src_dir . DS . 'classes' . DS . 'models' . DS . 'lib' . DS . 'loader'; $namespace = $this->app->define->lib_namespace . '\\Classes\\Models\\Lib\\Loader\\'; foreach ( $this->app->utility->scan_dir_namespace_class( $scan_dir, false, $namespace ) as $class ) { if ( class_exists( $class ) && is_subclass_of( $class, '\Technote\Interfaces\Singleton' ) ) { try { /** @var \Technote\Traits\Singleton $class */ $loader = $class::get_instance( $this->app ); if ( $loader instanceof \Technote\Interfaces\Loader ) { /** @var \Technote\Interfaces\Loader $loader */ $name = $loader->get_loader_name(); $this->$name = $loader; } } catch ( \Exception $e ) { } } } }
php
protected function initialize() { $scan_dir = $this->app->define->lib_src_dir . DS . 'classes' . DS . 'models' . DS . 'lib' . DS . 'loader'; $namespace = $this->app->define->lib_namespace . '\\Classes\\Models\\Lib\\Loader\\'; foreach ( $this->app->utility->scan_dir_namespace_class( $scan_dir, false, $namespace ) as $class ) { if ( class_exists( $class ) && is_subclass_of( $class, '\Technote\Interfaces\Singleton' ) ) { try { /** @var \Technote\Traits\Singleton $class */ $loader = $class::get_instance( $this->app ); if ( $loader instanceof \Technote\Interfaces\Loader ) { /** @var \Technote\Interfaces\Loader $loader */ $name = $loader->get_loader_name(); $this->$name = $loader; } } catch ( \Exception $e ) { } } } }
[ "protected", "function", "initialize", "(", ")", "{", "$", "scan_dir", "=", "$", "this", "->", "app", "->", "define", "->", "lib_src_dir", ".", "DS", ".", "'classes'", ".", "DS", ".", "'models'", ".", "DS", ".", "'lib'", ".", "DS", ".", "'loader'", ";", "$", "namespace", "=", "$", "this", "->", "app", "->", "define", "->", "lib_namespace", ".", "'\\\\Classes\\\\Models\\\\Lib\\\\Loader\\\\'", ";", "foreach", "(", "$", "this", "->", "app", "->", "utility", "->", "scan_dir_namespace_class", "(", "$", "scan_dir", ",", "false", ",", "$", "namespace", ")", "as", "$", "class", ")", "{", "if", "(", "class_exists", "(", "$", "class", ")", "&&", "is_subclass_of", "(", "$", "class", ",", "'\\Technote\\Interfaces\\Singleton'", ")", ")", "{", "try", "{", "/** @var \\Technote\\Traits\\Singleton $class */", "$", "loader", "=", "$", "class", "::", "get_instance", "(", "$", "this", "->", "app", ")", ";", "if", "(", "$", "loader", "instanceof", "\\", "Technote", "\\", "Interfaces", "\\", "Loader", ")", "{", "/** @var \\Technote\\Interfaces\\Loader $loader */", "$", "name", "=", "$", "loader", "->", "get_loader_name", "(", ")", ";", "$", "this", "->", "$", "name", "=", "$", "loader", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "}", "}", "}" ]
initialize
[ "initialize" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/loader.php#L47-L64
InactiveProjects/limoncello-illuminate
app/Database/Migrations/MigratePosts.php
MigratePosts.apply
public function apply() { Schema::create(Model::TABLE_NAME, function (Blueprint $table) { $table->increments(Model::FIELD_ID); $table->unsignedInteger(Model::FIELD_ID_BOARD); $table->unsignedInteger(Model::FIELD_ID_USER); $table->string(Model::FIELD_TITLE, Model::LENGTH_TITLE); $table->text(Model::FIELD_TEXT); $table->softDeletes(); $table->timestamps(); /** @noinspection PhpUndefinedMethodInspection */ $table->foreign(Model::FIELD_ID_BOARD) ->references(Board::FIELD_ID)->on(Board::TABLE_NAME)->onDelete('cascade'); /** @noinspection PhpUndefinedMethodInspection */ $table->foreign(Model::FIELD_ID_USER) ->references(User::FIELD_ID)->on(User::TABLE_NAME)->onDelete('cascade'); }); }
php
public function apply() { Schema::create(Model::TABLE_NAME, function (Blueprint $table) { $table->increments(Model::FIELD_ID); $table->unsignedInteger(Model::FIELD_ID_BOARD); $table->unsignedInteger(Model::FIELD_ID_USER); $table->string(Model::FIELD_TITLE, Model::LENGTH_TITLE); $table->text(Model::FIELD_TEXT); $table->softDeletes(); $table->timestamps(); /** @noinspection PhpUndefinedMethodInspection */ $table->foreign(Model::FIELD_ID_BOARD) ->references(Board::FIELD_ID)->on(Board::TABLE_NAME)->onDelete('cascade'); /** @noinspection PhpUndefinedMethodInspection */ $table->foreign(Model::FIELD_ID_USER) ->references(User::FIELD_ID)->on(User::TABLE_NAME)->onDelete('cascade'); }); }
[ "public", "function", "apply", "(", ")", "{", "Schema", "::", "create", "(", "Model", "::", "TABLE_NAME", ",", "function", "(", "Blueprint", "$", "table", ")", "{", "$", "table", "->", "increments", "(", "Model", "::", "FIELD_ID", ")", ";", "$", "table", "->", "unsignedInteger", "(", "Model", "::", "FIELD_ID_BOARD", ")", ";", "$", "table", "->", "unsignedInteger", "(", "Model", "::", "FIELD_ID_USER", ")", ";", "$", "table", "->", "string", "(", "Model", "::", "FIELD_TITLE", ",", "Model", "::", "LENGTH_TITLE", ")", ";", "$", "table", "->", "text", "(", "Model", "::", "FIELD_TEXT", ")", ";", "$", "table", "->", "softDeletes", "(", ")", ";", "$", "table", "->", "timestamps", "(", ")", ";", "/** @noinspection PhpUndefinedMethodInspection */", "$", "table", "->", "foreign", "(", "Model", "::", "FIELD_ID_BOARD", ")", "->", "references", "(", "Board", "::", "FIELD_ID", ")", "->", "on", "(", "Board", "::", "TABLE_NAME", ")", "->", "onDelete", "(", "'cascade'", ")", ";", "/** @noinspection PhpUndefinedMethodInspection */", "$", "table", "->", "foreign", "(", "Model", "::", "FIELD_ID_USER", ")", "->", "references", "(", "User", "::", "FIELD_ID", ")", "->", "on", "(", "User", "::", "TABLE_NAME", ")", "->", "onDelete", "(", "'cascade'", ")", ";", "}", ")", ";", "}" ]
@inheritdoc @SuppressWarnings(PHPMD.StaticAccess)
[ "@inheritdoc" ]
train
https://github.com/InactiveProjects/limoncello-illuminate/blob/cae6fc26190efcf090495a5c3582c10fa2430897/app/Database/Migrations/MigratePosts.php#L18-L37
Laralum/Users
src/Models/User.php
User.avatar
public function avatar($size = 100) { /* if(File::exists(public_path('/avatars'.'/'.md5($this->email)))){ return asset('/avatars'.'/'.md5($this->email)); } return "https://tracker.moodle.org/secure/attachment/30912/f3.png"; */ // Get gavatar avatar if (Utilities::validGravatar($this->email)) { return Utilities::gavatar($this->email); } $color = Packages::installed('customization') ? \Laralum\Customization\Models\Customization::first()->navbar_color : '#1e87f0'; return MaterialFunctions::materialAvatar($this->name, $size, $color); }
php
public function avatar($size = 100) { /* if(File::exists(public_path('/avatars'.'/'.md5($this->email)))){ return asset('/avatars'.'/'.md5($this->email)); } return "https://tracker.moodle.org/secure/attachment/30912/f3.png"; */ // Get gavatar avatar if (Utilities::validGravatar($this->email)) { return Utilities::gavatar($this->email); } $color = Packages::installed('customization') ? \Laralum\Customization\Models\Customization::first()->navbar_color : '#1e87f0'; return MaterialFunctions::materialAvatar($this->name, $size, $color); }
[ "public", "function", "avatar", "(", "$", "size", "=", "100", ")", "{", "/*\n if(File::exists(public_path('/avatars'.'/'.md5($this->email)))){\n return asset('/avatars'.'/'.md5($this->email));\n }\n return \"https://tracker.moodle.org/secure/attachment/30912/f3.png\";\n */", "// Get gavatar avatar", "if", "(", "Utilities", "::", "validGravatar", "(", "$", "this", "->", "email", ")", ")", "{", "return", "Utilities", "::", "gavatar", "(", "$", "this", "->", "email", ")", ";", "}", "$", "color", "=", "Packages", "::", "installed", "(", "'customization'", ")", "?", "\\", "Laralum", "\\", "Customization", "\\", "Models", "\\", "Customization", "::", "first", "(", ")", "->", "navbar_color", ":", "'#1e87f0'", ";", "return", "MaterialFunctions", "::", "materialAvatar", "(", "$", "this", "->", "name", ",", "$", "size", ",", "$", "color", ")", ";", "}" ]
Returns the user avatar.
[ "Returns", "the", "user", "avatar", "." ]
train
https://github.com/Laralum/Users/blob/788851d4cdf4bff548936faf1b12cf4697d13428/src/Models/User.php#L47-L63
vuer/token
src/Traits/Tokenable.php
Tokenable.getLastToken
public function getLastToken($type, $key = 'type') { return $this->token()->orderBy('tokens.created_at', 'desc')->where($key, $type)->first(); }
php
public function getLastToken($type, $key = 'type') { return $this->token()->orderBy('tokens.created_at', 'desc')->where($key, $type)->first(); }
[ "public", "function", "getLastToken", "(", "$", "type", ",", "$", "key", "=", "'type'", ")", "{", "return", "$", "this", "->", "token", "(", ")", "->", "orderBy", "(", "'tokens.created_at'", ",", "'desc'", ")", "->", "where", "(", "$", "key", ",", "$", "type", ")", "->", "first", "(", ")", ";", "}" ]
Get the last Token by the type. @param string $type @param string $key @return Token
[ "Get", "the", "last", "Token", "by", "the", "type", "." ]
train
https://github.com/vuer/token/blob/096ba1820c850d5e29062a304bdc399789388714/src/Traits/Tokenable.php#L55-L58
vuer/token
src/Traits/Tokenable.php
Tokenable.checkToken
public function checkToken($token) { return (bool) $this->token()->where('token', $token)->where('expiration_date', '>', Carbon::now())->count(); }
php
public function checkToken($token) { return (bool) $this->token()->where('token', $token)->where('expiration_date', '>', Carbon::now())->count(); }
[ "public", "function", "checkToken", "(", "$", "token", ")", "{", "return", "(", "bool", ")", "$", "this", "->", "token", "(", ")", "->", "where", "(", "'token'", ",", "$", "token", ")", "->", "where", "(", "'expiration_date'", ",", "'>'", ",", "Carbon", "::", "now", "(", ")", ")", "->", "count", "(", ")", ";", "}" ]
Check the token. @param string $token @return boolean
[ "Check", "the", "token", "." ]
train
https://github.com/vuer/token/blob/096ba1820c850d5e29062a304bdc399789388714/src/Traits/Tokenable.php#L76-L79
vuer/token
src/Traits/Tokenable.php
Tokenable.createToken
public function createToken($type, $expire = 60, $length = 48, $customProperties = null) { return $this->token()->create([ 'token' => $this->generateTokenString($length), 'expiration_date' => Carbon::now()->addMinutes($expire), 'type' => $type, 'custom_properties' => $customProperties, ]); }
php
public function createToken($type, $expire = 60, $length = 48, $customProperties = null) { return $this->token()->create([ 'token' => $this->generateTokenString($length), 'expiration_date' => Carbon::now()->addMinutes($expire), 'type' => $type, 'custom_properties' => $customProperties, ]); }
[ "public", "function", "createToken", "(", "$", "type", ",", "$", "expire", "=", "60", ",", "$", "length", "=", "48", ",", "$", "customProperties", "=", "null", ")", "{", "return", "$", "this", "->", "token", "(", ")", "->", "create", "(", "[", "'token'", "=>", "$", "this", "->", "generateTokenString", "(", "$", "length", ")", ",", "'expiration_date'", "=>", "Carbon", "::", "now", "(", ")", "->", "addMinutes", "(", "$", "expire", ")", ",", "'type'", "=>", "$", "type", ",", "'custom_properties'", "=>", "$", "customProperties", ",", "]", ")", ";", "}" ]
Create new token and return the instance. @param string $type token type @param integer $expire expire in minutes @param integer $length key length @return Token
[ "Create", "new", "token", "and", "return", "the", "instance", "." ]
train
https://github.com/vuer/token/blob/096ba1820c850d5e29062a304bdc399789388714/src/Traits/Tokenable.php#L99-L107
ouropencode/dachi
src/Router.php
Router.route
public static function route() { if(defined('DACHI_CLI')) return false; $uri = Request::getFullUri(); $route = self::findRoute($uri); self::performRoute($route); return Template::render(); }
php
public static function route() { if(defined('DACHI_CLI')) return false; $uri = Request::getFullUri(); $route = self::findRoute($uri); self::performRoute($route); return Template::render(); }
[ "public", "static", "function", "route", "(", ")", "{", "if", "(", "defined", "(", "'DACHI_CLI'", ")", ")", "return", "false", ";", "$", "uri", "=", "Request", "::", "getFullUri", "(", ")", ";", "$", "route", "=", "self", "::", "findRoute", "(", "$", "uri", ")", ";", "self", "::", "performRoute", "(", "$", "route", ")", ";", "return", "Template", "::", "render", "(", ")", ";", "}" ]
Performs routing based upon the loaded routing information and the incoming request @return null
[ "Performs", "routing", "based", "upon", "the", "loaded", "routing", "information", "and", "the", "incoming", "request" ]
train
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Router.php#L28-L37
ouropencode/dachi
src/Router.php
Router.findRoute
public static function findRoute($uri) { if(self::$routes === array()) self::load(); $count = count($uri); $position = &self::$routes; for($i = 0; $i < $count; $i++) { if($i == $count - 1) { if(isset($position[$uri[$i]]) && isset($position[$uri[$i]]["route"])) { return $position[$uri[$i]]["route"]; } else if(isset($position["*"]) && isset($position["*"]["route"])) { return $position["*"]["route"]; } else { throw new ValidRouteNotFoundException; } } else { if(isset($position[$uri[$i]])) { $position = &$position[$uri[$i]]["children"]; } elseif(isset($position["*"])) { $position = &$position["*"]["children"]; } else { throw new ValidRouteNotFoundException; } } } throw new ValidRouteNotFoundException; }
php
public static function findRoute($uri) { if(self::$routes === array()) self::load(); $count = count($uri); $position = &self::$routes; for($i = 0; $i < $count; $i++) { if($i == $count - 1) { if(isset($position[$uri[$i]]) && isset($position[$uri[$i]]["route"])) { return $position[$uri[$i]]["route"]; } else if(isset($position["*"]) && isset($position["*"]["route"])) { return $position["*"]["route"]; } else { throw new ValidRouteNotFoundException; } } else { if(isset($position[$uri[$i]])) { $position = &$position[$uri[$i]]["children"]; } elseif(isset($position["*"])) { $position = &$position["*"]["children"]; } else { throw new ValidRouteNotFoundException; } } } throw new ValidRouteNotFoundException; }
[ "public", "static", "function", "findRoute", "(", "$", "uri", ")", "{", "if", "(", "self", "::", "$", "routes", "===", "array", "(", ")", ")", "self", "::", "load", "(", ")", ";", "$", "count", "=", "count", "(", "$", "uri", ")", ";", "$", "position", "=", "&", "self", "::", "$", "routes", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "if", "(", "$", "i", "==", "$", "count", "-", "1", ")", "{", "if", "(", "isset", "(", "$", "position", "[", "$", "uri", "[", "$", "i", "]", "]", ")", "&&", "isset", "(", "$", "position", "[", "$", "uri", "[", "$", "i", "]", "]", "[", "\"route\"", "]", ")", ")", "{", "return", "$", "position", "[", "$", "uri", "[", "$", "i", "]", "]", "[", "\"route\"", "]", ";", "}", "else", "if", "(", "isset", "(", "$", "position", "[", "\"*\"", "]", ")", "&&", "isset", "(", "$", "position", "[", "\"*\"", "]", "[", "\"route\"", "]", ")", ")", "{", "return", "$", "position", "[", "\"*\"", "]", "[", "\"route\"", "]", ";", "}", "else", "{", "throw", "new", "ValidRouteNotFoundException", ";", "}", "}", "else", "{", "if", "(", "isset", "(", "$", "position", "[", "$", "uri", "[", "$", "i", "]", "]", ")", ")", "{", "$", "position", "=", "&", "$", "position", "[", "$", "uri", "[", "$", "i", "]", "]", "[", "\"children\"", "]", ";", "}", "elseif", "(", "isset", "(", "$", "position", "[", "\"*\"", "]", ")", ")", "{", "$", "position", "=", "&", "$", "position", "[", "\"*\"", "]", "[", "\"children\"", "]", ";", "}", "else", "{", "throw", "new", "ValidRouteNotFoundException", ";", "}", "}", "}", "throw", "new", "ValidRouteNotFoundException", ";", "}" ]
Find and process a valid route from the uri @internal @param array $uri Array of uri parts (split by /) @throws ValidRouteNotFoundException @return array
[ "Find", "and", "process", "a", "valid", "route", "from", "the", "uri" ]
train
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Router.php#L46-L74
ouropencode/dachi
src/Router.php
Router.performRoute
public static function performRoute($route) { $api_mode = isset($route["api-mode"]); Request::setRequestVariables($route["variables"], $api_mode); $controller = new $route["class"]; $response = $controller->$route["method"](); if(!Request::isAjax() && !Request::isAPI() && isset($route["render-path"])) { Request::setRenderPath($route["render-path"]); try { $route = self::findRoute(explode('/', $route["render-path"])); } catch(ValidRouteNotFoundException $e) { throw new ValidRenderRouteNotFoundException($e); } $response = self::performRoute($route); } return $response; }
php
public static function performRoute($route) { $api_mode = isset($route["api-mode"]); Request::setRequestVariables($route["variables"], $api_mode); $controller = new $route["class"]; $response = $controller->$route["method"](); if(!Request::isAjax() && !Request::isAPI() && isset($route["render-path"])) { Request::setRenderPath($route["render-path"]); try { $route = self::findRoute(explode('/', $route["render-path"])); } catch(ValidRouteNotFoundException $e) { throw new ValidRenderRouteNotFoundException($e); } $response = self::performRoute($route); } return $response; }
[ "public", "static", "function", "performRoute", "(", "$", "route", ")", "{", "$", "api_mode", "=", "isset", "(", "$", "route", "[", "\"api-mode\"", "]", ")", ";", "Request", "::", "setRequestVariables", "(", "$", "route", "[", "\"variables\"", "]", ",", "$", "api_mode", ")", ";", "$", "controller", "=", "new", "$", "route", "[", "\"class\"", "]", ";", "$", "response", "=", "$", "controller", "->", "$", "route", "[", "\"method\"", "]", "(", ")", ";", "if", "(", "!", "Request", "::", "isAjax", "(", ")", "&&", "!", "Request", "::", "isAPI", "(", ")", "&&", "isset", "(", "$", "route", "[", "\"render-path\"", "]", ")", ")", "{", "Request", "::", "setRenderPath", "(", "$", "route", "[", "\"render-path\"", "]", ")", ";", "try", "{", "$", "route", "=", "self", "::", "findRoute", "(", "explode", "(", "'/'", ",", "$", "route", "[", "\"render-path\"", "]", ")", ")", ";", "}", "catch", "(", "ValidRouteNotFoundException", "$", "e", ")", "{", "throw", "new", "ValidRenderRouteNotFoundException", "(", "$", "e", ")", ";", "}", "$", "response", "=", "self", "::", "performRoute", "(", "$", "route", ")", ";", "}", "return", "$", "response", ";", "}" ]
Perform routing based upon the discovered route @internal @param array $route Format: array(class, method, uri_variables) @see Request::setRequestVariables() @return mixed Return value of last route to be executed
[ "Perform", "routing", "based", "upon", "the", "discovered", "route" ]
train
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Router.php#L83-L101
digipolisgent/robo-digipolis-general
src/Common/DigipolisPropertiesAware.php
DigipolisPropertiesAware.readProperties
public function readProperties($root = null, $web = null, $vendor = null) { if (!$this->propertiesRead) { if (is_null($root)) { if (is_callable([$this, 'taskDetermineProjectRoot'])) { $this->taskDetermineProjectRoot()->run(); } $root = $this->getConfig()->get('digipolis.root.project', getcwd()); } if (is_null($web)) { if (is_callable([$this, 'taskDetermineWebRoot'])) { $this->taskDetermineWebRoot()->run(); } $web = $this->getConfig()->get('digipolis.root.web', $root); } if (is_null($vendor)) { $vendor = $root . '/vendor'; } $this->taskReadProperties([$web, $vendor])->run(); $this->propertiesRead = true; } }
php
public function readProperties($root = null, $web = null, $vendor = null) { if (!$this->propertiesRead) { if (is_null($root)) { if (is_callable([$this, 'taskDetermineProjectRoot'])) { $this->taskDetermineProjectRoot()->run(); } $root = $this->getConfig()->get('digipolis.root.project', getcwd()); } if (is_null($web)) { if (is_callable([$this, 'taskDetermineWebRoot'])) { $this->taskDetermineWebRoot()->run(); } $web = $this->getConfig()->get('digipolis.root.web', $root); } if (is_null($vendor)) { $vendor = $root . '/vendor'; } $this->taskReadProperties([$web, $vendor])->run(); $this->propertiesRead = true; } }
[ "public", "function", "readProperties", "(", "$", "root", "=", "null", ",", "$", "web", "=", "null", ",", "$", "vendor", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "propertiesRead", ")", "{", "if", "(", "is_null", "(", "$", "root", ")", ")", "{", "if", "(", "is_callable", "(", "[", "$", "this", ",", "'taskDetermineProjectRoot'", "]", ")", ")", "{", "$", "this", "->", "taskDetermineProjectRoot", "(", ")", "->", "run", "(", ")", ";", "}", "$", "root", "=", "$", "this", "->", "getConfig", "(", ")", "->", "get", "(", "'digipolis.root.project'", ",", "getcwd", "(", ")", ")", ";", "}", "if", "(", "is_null", "(", "$", "web", ")", ")", "{", "if", "(", "is_callable", "(", "[", "$", "this", ",", "'taskDetermineWebRoot'", "]", ")", ")", "{", "$", "this", "->", "taskDetermineWebRoot", "(", ")", "->", "run", "(", ")", ";", "}", "$", "web", "=", "$", "this", "->", "getConfig", "(", ")", "->", "get", "(", "'digipolis.root.web'", ",", "$", "root", ")", ";", "}", "if", "(", "is_null", "(", "$", "vendor", ")", ")", "{", "$", "vendor", "=", "$", "root", ".", "'/vendor'", ";", "}", "$", "this", "->", "taskReadProperties", "(", "[", "$", "web", ",", "$", "vendor", "]", ")", "->", "run", "(", ")", ";", "$", "this", "->", "propertiesRead", "=", "true", ";", "}", "}" ]
Read the properties from the YAML files. Determine project and web root if needed. @param string|null $root The path to the project root, if null the project root will be determined by taskDetermineProjectRoot(). @param string|null $web The path to the project web root, if null the web root will be determined by taskDetermineWebRoot(). @param string|null $vendor The path to the vendor dir, if null defaults to $root/vendor.
[ "Read", "the", "properties", "from", "the", "YAML", "files", ".", "Determine", "project", "and", "web", "root", "if", "needed", "." ]
train
https://github.com/digipolisgent/robo-digipolis-general/blob/66f0806c9ed7bd4e5aaf3f57ae1363f6aaae7cd9/src/Common/DigipolisPropertiesAware.php#L27-L48
nabab/bbn
src/bbn/mvc/output.php
output.run
public function run() { if ( \count((array)$this->obj) === 0 ){ header('HTTP/1.0 404 Not Found'); exit(); } if ( $this->mode === 'cli' ){ if ( !headers_sent() && !$this->obj->content ){ exit('No output...'); } if ( $this->obj->content ){ echo $this->obj->content; } @ob_end_flush(); exit(); } if ( isset($this->obj->prescript) ){ if ( empty($this->obj->prescript) ){ unset($this->obj->prescript); } else if ( !BBN_IS_DEV ){ try{ $tmp = \JShrink\Minifier::minify($this->obj->prescript); } catch ( \RuntimeException $e ){ \bbn\x::log($this->obj->prescript, 'js_shrink'); } if ( $tmp ){ $this->obj->prescript = $tmp; } } } if ( isset($this->obj->script) ){ if ( empty($this->obj->script) ){ unset($this->obj->script); } else if ( !BBN_IS_DEV ){ try{ $tmp = \JShrink\Minifier::minify($this->obj->script); } catch ( \RuntimeException $e ){ \bbn\x::log($this->obj->script, 'js_shrink'); } if ( $tmp ){ $this->obj->script = $tmp; } } } if ( isset($this->obj->postscript) ){ if ( empty($this->obj->postscript) ){ unset($this->obj->postscript); } else if ( !BBN_IS_DEV ){ try{ $tmp = \JShrink\Minifier::minify($this->obj->postscript); } catch ( \RuntimeException $e ){ \bbn\x::log($this->obj->postscript, 'js_shrink'); } if ( $tmp ){ $this->obj->postscript = $tmp; } } } if ( empty($this->obj->content) || ( ($this->mode === 'file') || ($this->mode === 'image') ) ){ if (!empty($this->obj->file)){ if (\is_string($this->obj->file) && is_file($this->obj->file)){ $this->obj->file = new bbn\file($this->obj->file); } if (\is_object($this->obj->file) && method_exists($this->obj->file, 'download') && method_exists($this->obj->file, 'test') && $this->obj->file->test() ){ $this->mode = 'file'; } } else if (!empty($this->obj->img)){ if (\is_string($this->obj->img) && is_file($this->obj->img)){ $this->obj->img = new bbn\file\image($this->obj->img); } if (\is_object($this->obj->img) && method_exists($this->obj->img, 'display') && method_exists($this->obj->img, 'test') && $this->obj->img->test() ){ $this->mode = 'image'; } } } switch ( $this->mode ){ case 'public': case 'json': case 'js': case 'css': case 'doc': case 'html': if ( !ob_start("ob_gzhandler" ) ){ ob_start(); } else{ header('Content-Encoding: gzip'); } break; default: ob_start(); } if ( (empty($this->obj->content) && empty($this->obj->file) && empty($this->obj->img) && ($this->mode !== 'public')) || (($this->mode === 'public') && empty($this->obj)) ){ $this->mode = ''; } else if ( !empty($this->obj->content) && !empty($this->obj->help) ){ $Parsedown = new \Parsedown(); $this->obj->help = $Parsedown->text($this->obj->help); } switch ( $this->mode ){ case 'public': header('Content-type: application/json; charset=utf-8'); echo json_encode($this->obj); break; case 'js': header('Content-type: application/javascript; charset=utf-8'); echo $this->obj->content; break; case 'css': header('Content-type: text/css; charset=utf-8'); echo $this->obj->content; break; case 'text': header('Content-type: text/plain; charset=utf-8'); echo $this->obj->content; break; case 'xml': header('Content-type: text/xml; charset=utf-8'); echo $this->obj->content; break; case 'image': if ( isset($this->obj->img) && \is_object($this->obj->img) ){ $this->obj->img->display(); } else{ $this->log("Impossible to display the following image: ".$this->obj->img->name); header('HTTP/1.0 404 Not Found'); } break; case 'file': if ( isset($this->obj->file) && \is_object($this->obj->file) && method_exists($this->obj->file, 'download') ){ $this->obj->file->download(); } else{ $this->log("Impossible to display the following controller", $this); header('HTTP/1.0 404 Not Found'); exit(); } break; default: header('Content-type: text/html; charset=utf-8'); echo isset($this->obj->content) ? $this->obj->content : ''; } }
php
public function run() { if ( \count((array)$this->obj) === 0 ){ header('HTTP/1.0 404 Not Found'); exit(); } if ( $this->mode === 'cli' ){ if ( !headers_sent() && !$this->obj->content ){ exit('No output...'); } if ( $this->obj->content ){ echo $this->obj->content; } @ob_end_flush(); exit(); } if ( isset($this->obj->prescript) ){ if ( empty($this->obj->prescript) ){ unset($this->obj->prescript); } else if ( !BBN_IS_DEV ){ try{ $tmp = \JShrink\Minifier::minify($this->obj->prescript); } catch ( \RuntimeException $e ){ \bbn\x::log($this->obj->prescript, 'js_shrink'); } if ( $tmp ){ $this->obj->prescript = $tmp; } } } if ( isset($this->obj->script) ){ if ( empty($this->obj->script) ){ unset($this->obj->script); } else if ( !BBN_IS_DEV ){ try{ $tmp = \JShrink\Minifier::minify($this->obj->script); } catch ( \RuntimeException $e ){ \bbn\x::log($this->obj->script, 'js_shrink'); } if ( $tmp ){ $this->obj->script = $tmp; } } } if ( isset($this->obj->postscript) ){ if ( empty($this->obj->postscript) ){ unset($this->obj->postscript); } else if ( !BBN_IS_DEV ){ try{ $tmp = \JShrink\Minifier::minify($this->obj->postscript); } catch ( \RuntimeException $e ){ \bbn\x::log($this->obj->postscript, 'js_shrink'); } if ( $tmp ){ $this->obj->postscript = $tmp; } } } if ( empty($this->obj->content) || ( ($this->mode === 'file') || ($this->mode === 'image') ) ){ if (!empty($this->obj->file)){ if (\is_string($this->obj->file) && is_file($this->obj->file)){ $this->obj->file = new bbn\file($this->obj->file); } if (\is_object($this->obj->file) && method_exists($this->obj->file, 'download') && method_exists($this->obj->file, 'test') && $this->obj->file->test() ){ $this->mode = 'file'; } } else if (!empty($this->obj->img)){ if (\is_string($this->obj->img) && is_file($this->obj->img)){ $this->obj->img = new bbn\file\image($this->obj->img); } if (\is_object($this->obj->img) && method_exists($this->obj->img, 'display') && method_exists($this->obj->img, 'test') && $this->obj->img->test() ){ $this->mode = 'image'; } } } switch ( $this->mode ){ case 'public': case 'json': case 'js': case 'css': case 'doc': case 'html': if ( !ob_start("ob_gzhandler" ) ){ ob_start(); } else{ header('Content-Encoding: gzip'); } break; default: ob_start(); } if ( (empty($this->obj->content) && empty($this->obj->file) && empty($this->obj->img) && ($this->mode !== 'public')) || (($this->mode === 'public') && empty($this->obj)) ){ $this->mode = ''; } else if ( !empty($this->obj->content) && !empty($this->obj->help) ){ $Parsedown = new \Parsedown(); $this->obj->help = $Parsedown->text($this->obj->help); } switch ( $this->mode ){ case 'public': header('Content-type: application/json; charset=utf-8'); echo json_encode($this->obj); break; case 'js': header('Content-type: application/javascript; charset=utf-8'); echo $this->obj->content; break; case 'css': header('Content-type: text/css; charset=utf-8'); echo $this->obj->content; break; case 'text': header('Content-type: text/plain; charset=utf-8'); echo $this->obj->content; break; case 'xml': header('Content-type: text/xml; charset=utf-8'); echo $this->obj->content; break; case 'image': if ( isset($this->obj->img) && \is_object($this->obj->img) ){ $this->obj->img->display(); } else{ $this->log("Impossible to display the following image: ".$this->obj->img->name); header('HTTP/1.0 404 Not Found'); } break; case 'file': if ( isset($this->obj->file) && \is_object($this->obj->file) && method_exists($this->obj->file, 'download') ){ $this->obj->file->download(); } else{ $this->log("Impossible to display the following controller", $this); header('HTTP/1.0 404 Not Found'); exit(); } break; default: header('Content-type: text/html; charset=utf-8'); echo isset($this->obj->content) ? $this->obj->content : ''; } }
[ "public", "function", "run", "(", ")", "{", "if", "(", "\\", "count", "(", "(", "array", ")", "$", "this", "->", "obj", ")", "===", "0", ")", "{", "header", "(", "'HTTP/1.0 404 Not Found'", ")", ";", "exit", "(", ")", ";", "}", "if", "(", "$", "this", "->", "mode", "===", "'cli'", ")", "{", "if", "(", "!", "headers_sent", "(", ")", "&&", "!", "$", "this", "->", "obj", "->", "content", ")", "{", "exit", "(", "'No output...'", ")", ";", "}", "if", "(", "$", "this", "->", "obj", "->", "content", ")", "{", "echo", "$", "this", "->", "obj", "->", "content", ";", "}", "@", "ob_end_flush", "(", ")", ";", "exit", "(", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "obj", "->", "prescript", ")", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "obj", "->", "prescript", ")", ")", "{", "unset", "(", "$", "this", "->", "obj", "->", "prescript", ")", ";", "}", "else", "if", "(", "!", "BBN_IS_DEV", ")", "{", "try", "{", "$", "tmp", "=", "\\", "JShrink", "\\", "Minifier", "::", "minify", "(", "$", "this", "->", "obj", "->", "prescript", ")", ";", "}", "catch", "(", "\\", "RuntimeException", "$", "e", ")", "{", "\\", "bbn", "\\", "x", "::", "log", "(", "$", "this", "->", "obj", "->", "prescript", ",", "'js_shrink'", ")", ";", "}", "if", "(", "$", "tmp", ")", "{", "$", "this", "->", "obj", "->", "prescript", "=", "$", "tmp", ";", "}", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "obj", "->", "script", ")", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "obj", "->", "script", ")", ")", "{", "unset", "(", "$", "this", "->", "obj", "->", "script", ")", ";", "}", "else", "if", "(", "!", "BBN_IS_DEV", ")", "{", "try", "{", "$", "tmp", "=", "\\", "JShrink", "\\", "Minifier", "::", "minify", "(", "$", "this", "->", "obj", "->", "script", ")", ";", "}", "catch", "(", "\\", "RuntimeException", "$", "e", ")", "{", "\\", "bbn", "\\", "x", "::", "log", "(", "$", "this", "->", "obj", "->", "script", ",", "'js_shrink'", ")", ";", "}", "if", "(", "$", "tmp", ")", "{", "$", "this", "->", "obj", "->", "script", "=", "$", "tmp", ";", "}", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "obj", "->", "postscript", ")", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "obj", "->", "postscript", ")", ")", "{", "unset", "(", "$", "this", "->", "obj", "->", "postscript", ")", ";", "}", "else", "if", "(", "!", "BBN_IS_DEV", ")", "{", "try", "{", "$", "tmp", "=", "\\", "JShrink", "\\", "Minifier", "::", "minify", "(", "$", "this", "->", "obj", "->", "postscript", ")", ";", "}", "catch", "(", "\\", "RuntimeException", "$", "e", ")", "{", "\\", "bbn", "\\", "x", "::", "log", "(", "$", "this", "->", "obj", "->", "postscript", ",", "'js_shrink'", ")", ";", "}", "if", "(", "$", "tmp", ")", "{", "$", "this", "->", "obj", "->", "postscript", "=", "$", "tmp", ";", "}", "}", "}", "if", "(", "empty", "(", "$", "this", "->", "obj", "->", "content", ")", "||", "(", "(", "$", "this", "->", "mode", "===", "'file'", ")", "||", "(", "$", "this", "->", "mode", "===", "'image'", ")", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "obj", "->", "file", ")", ")", "{", "if", "(", "\\", "is_string", "(", "$", "this", "->", "obj", "->", "file", ")", "&&", "is_file", "(", "$", "this", "->", "obj", "->", "file", ")", ")", "{", "$", "this", "->", "obj", "->", "file", "=", "new", "bbn", "\\", "file", "(", "$", "this", "->", "obj", "->", "file", ")", ";", "}", "if", "(", "\\", "is_object", "(", "$", "this", "->", "obj", "->", "file", ")", "&&", "method_exists", "(", "$", "this", "->", "obj", "->", "file", ",", "'download'", ")", "&&", "method_exists", "(", "$", "this", "->", "obj", "->", "file", ",", "'test'", ")", "&&", "$", "this", "->", "obj", "->", "file", "->", "test", "(", ")", ")", "{", "$", "this", "->", "mode", "=", "'file'", ";", "}", "}", "else", "if", "(", "!", "empty", "(", "$", "this", "->", "obj", "->", "img", ")", ")", "{", "if", "(", "\\", "is_string", "(", "$", "this", "->", "obj", "->", "img", ")", "&&", "is_file", "(", "$", "this", "->", "obj", "->", "img", ")", ")", "{", "$", "this", "->", "obj", "->", "img", "=", "new", "bbn", "\\", "file", "\\", "image", "(", "$", "this", "->", "obj", "->", "img", ")", ";", "}", "if", "(", "\\", "is_object", "(", "$", "this", "->", "obj", "->", "img", ")", "&&", "method_exists", "(", "$", "this", "->", "obj", "->", "img", ",", "'display'", ")", "&&", "method_exists", "(", "$", "this", "->", "obj", "->", "img", ",", "'test'", ")", "&&", "$", "this", "->", "obj", "->", "img", "->", "test", "(", ")", ")", "{", "$", "this", "->", "mode", "=", "'image'", ";", "}", "}", "}", "switch", "(", "$", "this", "->", "mode", ")", "{", "case", "'public'", ":", "case", "'json'", ":", "case", "'js'", ":", "case", "'css'", ":", "case", "'doc'", ":", "case", "'html'", ":", "if", "(", "!", "ob_start", "(", "\"ob_gzhandler\"", ")", ")", "{", "ob_start", "(", ")", ";", "}", "else", "{", "header", "(", "'Content-Encoding: gzip'", ")", ";", "}", "break", ";", "default", ":", "ob_start", "(", ")", ";", "}", "if", "(", "(", "empty", "(", "$", "this", "->", "obj", "->", "content", ")", "&&", "empty", "(", "$", "this", "->", "obj", "->", "file", ")", "&&", "empty", "(", "$", "this", "->", "obj", "->", "img", ")", "&&", "(", "$", "this", "->", "mode", "!==", "'public'", ")", ")", "||", "(", "(", "$", "this", "->", "mode", "===", "'public'", ")", "&&", "empty", "(", "$", "this", "->", "obj", ")", ")", ")", "{", "$", "this", "->", "mode", "=", "''", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "this", "->", "obj", "->", "content", ")", "&&", "!", "empty", "(", "$", "this", "->", "obj", "->", "help", ")", ")", "{", "$", "Parsedown", "=", "new", "\\", "Parsedown", "(", ")", ";", "$", "this", "->", "obj", "->", "help", "=", "$", "Parsedown", "->", "text", "(", "$", "this", "->", "obj", "->", "help", ")", ";", "}", "switch", "(", "$", "this", "->", "mode", ")", "{", "case", "'public'", ":", "header", "(", "'Content-type: application/json; charset=utf-8'", ")", ";", "echo", "json_encode", "(", "$", "this", "->", "obj", ")", ";", "break", ";", "case", "'js'", ":", "header", "(", "'Content-type: application/javascript; charset=utf-8'", ")", ";", "echo", "$", "this", "->", "obj", "->", "content", ";", "break", ";", "case", "'css'", ":", "header", "(", "'Content-type: text/css; charset=utf-8'", ")", ";", "echo", "$", "this", "->", "obj", "->", "content", ";", "break", ";", "case", "'text'", ":", "header", "(", "'Content-type: text/plain; charset=utf-8'", ")", ";", "echo", "$", "this", "->", "obj", "->", "content", ";", "break", ";", "case", "'xml'", ":", "header", "(", "'Content-type: text/xml; charset=utf-8'", ")", ";", "echo", "$", "this", "->", "obj", "->", "content", ";", "break", ";", "case", "'image'", ":", "if", "(", "isset", "(", "$", "this", "->", "obj", "->", "img", ")", "&&", "\\", "is_object", "(", "$", "this", "->", "obj", "->", "img", ")", ")", "{", "$", "this", "->", "obj", "->", "img", "->", "display", "(", ")", ";", "}", "else", "{", "$", "this", "->", "log", "(", "\"Impossible to display the following image: \"", ".", "$", "this", "->", "obj", "->", "img", "->", "name", ")", ";", "header", "(", "'HTTP/1.0 404 Not Found'", ")", ";", "}", "break", ";", "case", "'file'", ":", "if", "(", "isset", "(", "$", "this", "->", "obj", "->", "file", ")", "&&", "\\", "is_object", "(", "$", "this", "->", "obj", "->", "file", ")", "&&", "method_exists", "(", "$", "this", "->", "obj", "->", "file", ",", "'download'", ")", ")", "{", "$", "this", "->", "obj", "->", "file", "->", "download", "(", ")", ";", "}", "else", "{", "$", "this", "->", "log", "(", "\"Impossible to display the following controller\"", ",", "$", "this", ")", ";", "header", "(", "'HTTP/1.0 404 Not Found'", ")", ";", "exit", "(", ")", ";", "}", "break", ";", "default", ":", "header", "(", "'Content-type: text/html; charset=utf-8'", ")", ";", "echo", "isset", "(", "$", "this", "->", "obj", "->", "content", ")", "?", "$", "this", "->", "obj", "->", "content", ":", "''", ";", "}", "}" ]
Outputs the result. @return void
[ "Outputs", "the", "result", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/mvc/output.php#L26-L199
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionTemplatesInsert
public function sectionTemplatesInsert() { $filename = arg('name'); $filter = new Eresus_FS_NameFilter(); $filename = $filter->filter($filename); if ('' === $filename) { $filename = uniqid(); } if ($filename != arg('name')) { Eresus_Kernel::app()->getPage()->addErrorMessage( sprintf(ADM_THEMES_FILENAME_FILTERED, $filename)); } $templates = Templates::getInstance(); $templates->add($filename, '', arg('code'), arg('desc')); HTTP::redirect(arg('submitURL')); }
php
public function sectionTemplatesInsert() { $filename = arg('name'); $filter = new Eresus_FS_NameFilter(); $filename = $filter->filter($filename); if ('' === $filename) { $filename = uniqid(); } if ($filename != arg('name')) { Eresus_Kernel::app()->getPage()->addErrorMessage( sprintf(ADM_THEMES_FILENAME_FILTERED, $filename)); } $templates = Templates::getInstance(); $templates->add($filename, '', arg('code'), arg('desc')); HTTP::redirect(arg('submitURL')); }
[ "public", "function", "sectionTemplatesInsert", "(", ")", "{", "$", "filename", "=", "arg", "(", "'name'", ")", ";", "$", "filter", "=", "new", "Eresus_FS_NameFilter", "(", ")", ";", "$", "filename", "=", "$", "filter", "->", "filter", "(", "$", "filename", ")", ";", "if", "(", "''", "===", "$", "filename", ")", "{", "$", "filename", "=", "uniqid", "(", ")", ";", "}", "if", "(", "$", "filename", "!=", "arg", "(", "'name'", ")", ")", "{", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "addErrorMessage", "(", "sprintf", "(", "ADM_THEMES_FILENAME_FILTERED", ",", "$", "filename", ")", ")", ";", "}", "$", "templates", "=", "Templates", "::", "getInstance", "(", ")", ";", "$", "templates", "->", "add", "(", "$", "filename", ",", "''", ",", "arg", "(", "'code'", ")", ",", "arg", "(", "'desc'", ")", ")", ";", "HTTP", "::", "redirect", "(", "arg", "(", "'submitURL'", ")", ")", ";", "}" ]
??? @return void
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L94-L114
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionTemplatesUpdate
public function sectionTemplatesUpdate() { $templates = Templates::getInstance(); $templates->update(arg('name'), '', arg('code'), arg('desc')); HTTP::redirect(arg('submitURL')); }
php
public function sectionTemplatesUpdate() { $templates = Templates::getInstance(); $templates->update(arg('name'), '', arg('code'), arg('desc')); HTTP::redirect(arg('submitURL')); }
[ "public", "function", "sectionTemplatesUpdate", "(", ")", "{", "$", "templates", "=", "Templates", "::", "getInstance", "(", ")", ";", "$", "templates", "->", "update", "(", "arg", "(", "'name'", ")", ",", "''", ",", "arg", "(", "'code'", ")", ",", "arg", "(", "'desc'", ")", ")", ";", "HTTP", "::", "redirect", "(", "arg", "(", "'submitURL'", ")", ")", ";", "}" ]
??? @return void
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L120-L125
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionTemplatesDelete
public function sectionTemplatesDelete() { $templates = Templates::getInstance(); $templates->delete(arg('delete')); HTTP::redirect(Eresus_Kernel::app()->getPage()->url()); }
php
public function sectionTemplatesDelete() { $templates = Templates::getInstance(); $templates->delete(arg('delete')); HTTP::redirect(Eresus_Kernel::app()->getPage()->url()); }
[ "public", "function", "sectionTemplatesDelete", "(", ")", "{", "$", "templates", "=", "Templates", "::", "getInstance", "(", ")", ";", "$", "templates", "->", "delete", "(", "arg", "(", "'delete'", ")", ")", ";", "HTTP", "::", "redirect", "(", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "url", "(", ")", ")", ";", "}" ]
??? @return void
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L131-L136
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionTemplatesAdd
public function sectionTemplatesAdd() { $form = array( 'name' => 'addForm', 'caption' => Eresus_Kernel::app()->getPage()->title.ADM_T_DIV.ADM_ADD, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'action', 'value'=>'insert'), array('type'=>'hidden','name'=>'section', 'value'=>arg('section')), array('type'=>'edit','name'=>'name','label'=>ADM_THEMES_FILENAME_LABEL, 'width'=>'200px', 'comment'=>'.html'), array('type'=>'edit','name'=>'desc','label'=>ADM_THEMES_DESC_LABEL, 'width'=>'100%'), array('type'=>'memo','name'=>'code', 'height'=>'30', 'syntax' => 'html'), ), 'buttons' => array('ok','cancel'), ); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderForm($form); return $result; }
php
public function sectionTemplatesAdd() { $form = array( 'name' => 'addForm', 'caption' => Eresus_Kernel::app()->getPage()->title.ADM_T_DIV.ADM_ADD, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'action', 'value'=>'insert'), array('type'=>'hidden','name'=>'section', 'value'=>arg('section')), array('type'=>'edit','name'=>'name','label'=>ADM_THEMES_FILENAME_LABEL, 'width'=>'200px', 'comment'=>'.html'), array('type'=>'edit','name'=>'desc','label'=>ADM_THEMES_DESC_LABEL, 'width'=>'100%'), array('type'=>'memo','name'=>'code', 'height'=>'30', 'syntax' => 'html'), ), 'buttons' => array('ok','cancel'), ); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderForm($form); return $result; }
[ "public", "function", "sectionTemplatesAdd", "(", ")", "{", "$", "form", "=", "array", "(", "'name'", "=>", "'addForm'", ",", "'caption'", "=>", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "title", ".", "ADM_T_DIV", ".", "ADM_ADD", ",", "'width'", "=>", "'100%'", ",", "'fields'", "=>", "array", "(", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'action'", ",", "'value'", "=>", "'insert'", ")", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'section'", ",", "'value'", "=>", "arg", "(", "'section'", ")", ")", ",", "array", "(", "'type'", "=>", "'edit'", ",", "'name'", "=>", "'name'", ",", "'label'", "=>", "ADM_THEMES_FILENAME_LABEL", ",", "'width'", "=>", "'200px'", ",", "'comment'", "=>", "'.html'", ")", ",", "array", "(", "'type'", "=>", "'edit'", ",", "'name'", "=>", "'desc'", ",", "'label'", "=>", "ADM_THEMES_DESC_LABEL", ",", "'width'", "=>", "'100%'", ")", ",", "array", "(", "'type'", "=>", "'memo'", ",", "'name'", "=>", "'code'", ",", "'height'", "=>", "'30'", ",", "'syntax'", "=>", "'html'", ")", ",", ")", ",", "'buttons'", "=>", "array", "(", "'ok'", ",", "'cancel'", ")", ",", ")", ";", "/** @var TAdminUI $page */", "$", "page", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", ";", "$", "result", "=", "$", "page", "->", "renderForm", "(", "$", "form", ")", ";", "return", "$", "result", ";", "}" ]
??? @return string HTML
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L142-L162
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionTemplatesEdit
public function sectionTemplatesEdit() { $templates = Templates::getInstance(); $item = $templates->get(arg('id'), '', true); $form = array( 'name' => 'editForm', 'caption' => Eresus_Kernel::app()->getPage()->title.ADM_T_DIV.ADM_EDIT, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'action', 'value'=>'update'), array('type'=>'hidden','name'=>'section', 'value'=>arg('section')), array('type'=>'hidden','name'=>'name'), array('type' => 'edit', 'name' => 'filename', 'label' => ADM_THEMES_FILENAME_LABEL, 'width' => '200px', 'comment' => '.html', 'disabled' => true, 'value' => $item['name']), array('type'=>'edit','name'=>'desc','label'=>ADM_THEMES_DESC_LABEL, 'width'=>'100%'), array('type'=>'memo','name'=>'code', 'height'=>'30', 'syntax' => 'html'), ), 'buttons' => array('ok', 'apply', 'cancel'), ); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderForm($form, $item); return $result; }
php
public function sectionTemplatesEdit() { $templates = Templates::getInstance(); $item = $templates->get(arg('id'), '', true); $form = array( 'name' => 'editForm', 'caption' => Eresus_Kernel::app()->getPage()->title.ADM_T_DIV.ADM_EDIT, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'action', 'value'=>'update'), array('type'=>'hidden','name'=>'section', 'value'=>arg('section')), array('type'=>'hidden','name'=>'name'), array('type' => 'edit', 'name' => 'filename', 'label' => ADM_THEMES_FILENAME_LABEL, 'width' => '200px', 'comment' => '.html', 'disabled' => true, 'value' => $item['name']), array('type'=>'edit','name'=>'desc','label'=>ADM_THEMES_DESC_LABEL, 'width'=>'100%'), array('type'=>'memo','name'=>'code', 'height'=>'30', 'syntax' => 'html'), ), 'buttons' => array('ok', 'apply', 'cancel'), ); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderForm($form, $item); return $result; }
[ "public", "function", "sectionTemplatesEdit", "(", ")", "{", "$", "templates", "=", "Templates", "::", "getInstance", "(", ")", ";", "$", "item", "=", "$", "templates", "->", "get", "(", "arg", "(", "'id'", ")", ",", "''", ",", "true", ")", ";", "$", "form", "=", "array", "(", "'name'", "=>", "'editForm'", ",", "'caption'", "=>", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "title", ".", "ADM_T_DIV", ".", "ADM_EDIT", ",", "'width'", "=>", "'100%'", ",", "'fields'", "=>", "array", "(", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'action'", ",", "'value'", "=>", "'update'", ")", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'section'", ",", "'value'", "=>", "arg", "(", "'section'", ")", ")", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'name'", ")", ",", "array", "(", "'type'", "=>", "'edit'", ",", "'name'", "=>", "'filename'", ",", "'label'", "=>", "ADM_THEMES_FILENAME_LABEL", ",", "'width'", "=>", "'200px'", ",", "'comment'", "=>", "'.html'", ",", "'disabled'", "=>", "true", ",", "'value'", "=>", "$", "item", "[", "'name'", "]", ")", ",", "array", "(", "'type'", "=>", "'edit'", ",", "'name'", "=>", "'desc'", ",", "'label'", "=>", "ADM_THEMES_DESC_LABEL", ",", "'width'", "=>", "'100%'", ")", ",", "array", "(", "'type'", "=>", "'memo'", ",", "'name'", "=>", "'code'", ",", "'height'", "=>", "'30'", ",", "'syntax'", "=>", "'html'", ")", ",", ")", ",", "'buttons'", "=>", "array", "(", "'ok'", ",", "'apply'", ",", "'cancel'", ")", ",", ")", ";", "/** @var TAdminUI $page */", "$", "page", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", ";", "$", "result", "=", "$", "page", "->", "renderForm", "(", "$", "form", ",", "$", "item", ")", ";", "return", "$", "result", ";", "}" ]
??? @return string HTML
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L169-L192
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionTemplates
public function sectionTemplates() { Eresus_Kernel::app()->getPage()->title .= ADM_T_DIV.ADM_THEMES_TEMPLATES; $result = ''; switch (arg('action')) { case 'update': $this->sectionTemplatesUpdate(); break; case 'insert': $this->sectionTemplatesInsert(); break; case 'add': $result = $this->sectionTemplatesAdd(); break; default: if (arg('delete')) { $this->sectionTemplatesDelete(); } elseif (arg('id')) { $result = $this->sectionTemplatesEdit(); } else { $result = $this->sectionTemplatesList(); } } return $result; }
php
public function sectionTemplates() { Eresus_Kernel::app()->getPage()->title .= ADM_T_DIV.ADM_THEMES_TEMPLATES; $result = ''; switch (arg('action')) { case 'update': $this->sectionTemplatesUpdate(); break; case 'insert': $this->sectionTemplatesInsert(); break; case 'add': $result = $this->sectionTemplatesAdd(); break; default: if (arg('delete')) { $this->sectionTemplatesDelete(); } elseif (arg('id')) { $result = $this->sectionTemplatesEdit(); } else { $result = $this->sectionTemplatesList(); } } return $result; }
[ "public", "function", "sectionTemplates", "(", ")", "{", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "title", ".=", "ADM_T_DIV", ".", "ADM_THEMES_TEMPLATES", ";", "$", "result", "=", "''", ";", "switch", "(", "arg", "(", "'action'", ")", ")", "{", "case", "'update'", ":", "$", "this", "->", "sectionTemplatesUpdate", "(", ")", ";", "break", ";", "case", "'insert'", ":", "$", "this", "->", "sectionTemplatesInsert", "(", ")", ";", "break", ";", "case", "'add'", ":", "$", "result", "=", "$", "this", "->", "sectionTemplatesAdd", "(", ")", ";", "break", ";", "default", ":", "if", "(", "arg", "(", "'delete'", ")", ")", "{", "$", "this", "->", "sectionTemplatesDelete", "(", ")", ";", "}", "elseif", "(", "arg", "(", "'id'", ")", ")", "{", "$", "result", "=", "$", "this", "->", "sectionTemplatesEdit", "(", ")", ";", "}", "else", "{", "$", "result", "=", "$", "this", "->", "sectionTemplatesList", "(", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
??? @return string
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L238-L269
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionStdInsert
public function sectionStdInsert() { $templates = Templates::getInstance(); $templates->add(arg('name'), 'std', arg('code'), $this->stdTemplates[arg('name')]['caption']); HTTP::redirect(arg('submitURL')); }
php
public function sectionStdInsert() { $templates = Templates::getInstance(); $templates->add(arg('name'), 'std', arg('code'), $this->stdTemplates[arg('name')]['caption']); HTTP::redirect(arg('submitURL')); }
[ "public", "function", "sectionStdInsert", "(", ")", "{", "$", "templates", "=", "Templates", "::", "getInstance", "(", ")", ";", "$", "templates", "->", "add", "(", "arg", "(", "'name'", ")", ",", "'std'", ",", "arg", "(", "'code'", ")", ",", "$", "this", "->", "stdTemplates", "[", "arg", "(", "'name'", ")", "]", "[", "'caption'", "]", ")", ";", "HTTP", "::", "redirect", "(", "arg", "(", "'submitURL'", ")", ")", ";", "}" ]
??? @return void
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L276-L281
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionStdAdd
private function sectionStdAdd() { /* * Создаём список имеющихся шаблонов чтобы отфильтровать их из списка доступных. */ $templates = Templates::getInstance(); $list = array_keys($templates->enum('std')); $existed = array(); foreach ($list as $key) { $existed []= $key; } $values = array(); $items = array(); $jsArray = "var aTemplates = Array();\n"; foreach ($this->stdTemplates as $key => $item) { if (in_array($key, $existed)) { continue; } if (!isset($hint)) { $hint = isset($item['hint']) ? $item['hint'] : ''; } $values[] = $key; $items[] = $item['caption']; $jsArray .= "aTemplates['".$key."'] = '".(isset($item['hint'])?$item['hint']:'')."'\n"; } if (!isset($hint)) { $hint = ''; } Eresus_Kernel::app()->getPage()->addScripts($jsArray." function onTemplateNameChange() { document.getElementById('templateHint').innerHTML = aTemplates[document.addForm.elements.namedItem('name').value]; } "); $form = array( 'name' => 'addForm', 'caption' => Eresus_Kernel::app()->getPage()->title.ADM_T_DIV.ADM_ADD, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'action', 'value'=>'insert'), array('type'=>'hidden','name'=>'section', 'value'=>arg('section')), array('type'=>'select','name'=>'name','label'=>ADM_THEMES_TEMPLATE, 'values'=>$values, 'items'=>$items, 'extra' => 'onChange="onTemplateNameChange()"'), array('type'=>'text','name'=>'hint', 'value' => $hint, 'extra' => 'id="templateHint"'), array('type'=>'memo','name'=>'code', 'height'=>'30', 'syntax' => 'html'), ), 'buttons' => array('ok','cancel'), ); /* @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderForm($form); return $result; }
php
private function sectionStdAdd() { /* * Создаём список имеющихся шаблонов чтобы отфильтровать их из списка доступных. */ $templates = Templates::getInstance(); $list = array_keys($templates->enum('std')); $existed = array(); foreach ($list as $key) { $existed []= $key; } $values = array(); $items = array(); $jsArray = "var aTemplates = Array();\n"; foreach ($this->stdTemplates as $key => $item) { if (in_array($key, $existed)) { continue; } if (!isset($hint)) { $hint = isset($item['hint']) ? $item['hint'] : ''; } $values[] = $key; $items[] = $item['caption']; $jsArray .= "aTemplates['".$key."'] = '".(isset($item['hint'])?$item['hint']:'')."'\n"; } if (!isset($hint)) { $hint = ''; } Eresus_Kernel::app()->getPage()->addScripts($jsArray." function onTemplateNameChange() { document.getElementById('templateHint').innerHTML = aTemplates[document.addForm.elements.namedItem('name').value]; } "); $form = array( 'name' => 'addForm', 'caption' => Eresus_Kernel::app()->getPage()->title.ADM_T_DIV.ADM_ADD, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'action', 'value'=>'insert'), array('type'=>'hidden','name'=>'section', 'value'=>arg('section')), array('type'=>'select','name'=>'name','label'=>ADM_THEMES_TEMPLATE, 'values'=>$values, 'items'=>$items, 'extra' => 'onChange="onTemplateNameChange()"'), array('type'=>'text','name'=>'hint', 'value' => $hint, 'extra' => 'id="templateHint"'), array('type'=>'memo','name'=>'code', 'height'=>'30', 'syntax' => 'html'), ), 'buttons' => array('ok','cancel'), ); /* @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderForm($form); return $result; }
[ "private", "function", "sectionStdAdd", "(", ")", "{", "/*\n\t\t * Создаём список имеющихся шаблонов чтобы отфильтровать их из списка доступных.\n\t\t */", "$", "templates", "=", "Templates", "::", "getInstance", "(", ")", ";", "$", "list", "=", "array_keys", "(", "$", "templates", "->", "enum", "(", "'std'", ")", ")", ";", "$", "existed", "=", "array", "(", ")", ";", "foreach", "(", "$", "list", "as", "$", "key", ")", "{", "$", "existed", "[", "]", "=", "$", "key", ";", "}", "$", "values", "=", "array", "(", ")", ";", "$", "items", "=", "array", "(", ")", ";", "$", "jsArray", "=", "\"var aTemplates = Array();\\n\"", ";", "foreach", "(", "$", "this", "->", "stdTemplates", "as", "$", "key", "=>", "$", "item", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "$", "existed", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "isset", "(", "$", "hint", ")", ")", "{", "$", "hint", "=", "isset", "(", "$", "item", "[", "'hint'", "]", ")", "?", "$", "item", "[", "'hint'", "]", ":", "''", ";", "}", "$", "values", "[", "]", "=", "$", "key", ";", "$", "items", "[", "]", "=", "$", "item", "[", "'caption'", "]", ";", "$", "jsArray", ".=", "\"aTemplates['\"", ".", "$", "key", ".", "\"'] = '\"", ".", "(", "isset", "(", "$", "item", "[", "'hint'", "]", ")", "?", "$", "item", "[", "'hint'", "]", ":", "''", ")", ".", "\"'\\n\"", ";", "}", "if", "(", "!", "isset", "(", "$", "hint", ")", ")", "{", "$", "hint", "=", "''", ";", "}", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "addScripts", "(", "$", "jsArray", ".", "\"\n\t\t\tfunction onTemplateNameChange()\n\t\t\t{\n\t\t\t\tdocument.getElementById('templateHint').innerHTML =\n\t\t\t\t\taTemplates[document.addForm.elements.namedItem('name').value];\n\t\t\t}\n\t\t\"", ")", ";", "$", "form", "=", "array", "(", "'name'", "=>", "'addForm'", ",", "'caption'", "=>", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "title", ".", "ADM_T_DIV", ".", "ADM_ADD", ",", "'width'", "=>", "'100%'", ",", "'fields'", "=>", "array", "(", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'action'", ",", "'value'", "=>", "'insert'", ")", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'section'", ",", "'value'", "=>", "arg", "(", "'section'", ")", ")", ",", "array", "(", "'type'", "=>", "'select'", ",", "'name'", "=>", "'name'", ",", "'label'", "=>", "ADM_THEMES_TEMPLATE", ",", "'values'", "=>", "$", "values", ",", "'items'", "=>", "$", "items", ",", "'extra'", "=>", "'onChange=\"onTemplateNameChange()\"'", ")", ",", "array", "(", "'type'", "=>", "'text'", ",", "'name'", "=>", "'hint'", ",", "'value'", "=>", "$", "hint", ",", "'extra'", "=>", "'id=\"templateHint\"'", ")", ",", "array", "(", "'type'", "=>", "'memo'", ",", "'name'", "=>", "'code'", ",", "'height'", "=>", "'30'", ",", "'syntax'", "=>", "'html'", ")", ",", ")", ",", "'buttons'", "=>", "array", "(", "'ok'", ",", "'cancel'", ")", ",", ")", ";", "/* @var TAdminUI $page */", "$", "page", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", ";", "$", "result", "=", "$", "page", "->", "renderForm", "(", "$", "form", ")", ";", "return", "$", "result", ";", "}" ]
Диалог добавления стандартного шаблона @return string
[ "Диалог", "добавления", "стандартного", "шаблона" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L309-L370
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionStdEdit
public function sectionStdEdit() { $templates = Templates::getInstance(); $item = $templates->get(arg('id'), 'std', true); $form = array( 'name' => 'editForm', 'caption' => Eresus_Kernel::app()->getPage()->title . ADM_T_DIV . ADM_EDIT, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'action', 'value'=>'update'), array('type'=>'hidden','name'=>'section', 'value'=>arg('section')), array('type'=>'hidden','name'=>'name'), array('type'=>'edit','name'=>'_name','label' => ADM_THEMES_FILENAME_LABEL, 'width' => '200px', 'comment' => '.tmpl (' . $this->stdTemplates[$item['name']]['caption'].')', 'disabled' => true, 'value'=>$item['name']), array('type'=>'text','name'=>'hint', 'value' => isset($this->stdTemplates[$item['name']]['hint']) ? $this->stdTemplates[$item['name']]['hint']:'', 'extra' => 'id="templateHint"'), array('type'=>'memo','name'=>'code', 'height'=>'30', 'syntax' => 'html'), ), 'buttons' => array('ok', 'apply', 'cancel'), ); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderForm($form, $item); return $result; }
php
public function sectionStdEdit() { $templates = Templates::getInstance(); $item = $templates->get(arg('id'), 'std', true); $form = array( 'name' => 'editForm', 'caption' => Eresus_Kernel::app()->getPage()->title . ADM_T_DIV . ADM_EDIT, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'action', 'value'=>'update'), array('type'=>'hidden','name'=>'section', 'value'=>arg('section')), array('type'=>'hidden','name'=>'name'), array('type'=>'edit','name'=>'_name','label' => ADM_THEMES_FILENAME_LABEL, 'width' => '200px', 'comment' => '.tmpl (' . $this->stdTemplates[$item['name']]['caption'].')', 'disabled' => true, 'value'=>$item['name']), array('type'=>'text','name'=>'hint', 'value' => isset($this->stdTemplates[$item['name']]['hint']) ? $this->stdTemplates[$item['name']]['hint']:'', 'extra' => 'id="templateHint"'), array('type'=>'memo','name'=>'code', 'height'=>'30', 'syntax' => 'html'), ), 'buttons' => array('ok', 'apply', 'cancel'), ); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderForm($form, $item); return $result; }
[ "public", "function", "sectionStdEdit", "(", ")", "{", "$", "templates", "=", "Templates", "::", "getInstance", "(", ")", ";", "$", "item", "=", "$", "templates", "->", "get", "(", "arg", "(", "'id'", ")", ",", "'std'", ",", "true", ")", ";", "$", "form", "=", "array", "(", "'name'", "=>", "'editForm'", ",", "'caption'", "=>", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "title", ".", "ADM_T_DIV", ".", "ADM_EDIT", ",", "'width'", "=>", "'100%'", ",", "'fields'", "=>", "array", "(", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'action'", ",", "'value'", "=>", "'update'", ")", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'section'", ",", "'value'", "=>", "arg", "(", "'section'", ")", ")", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'name'", ")", ",", "array", "(", "'type'", "=>", "'edit'", ",", "'name'", "=>", "'_name'", ",", "'label'", "=>", "ADM_THEMES_FILENAME_LABEL", ",", "'width'", "=>", "'200px'", ",", "'comment'", "=>", "'.tmpl ('", ".", "$", "this", "->", "stdTemplates", "[", "$", "item", "[", "'name'", "]", "]", "[", "'caption'", "]", ".", "')'", ",", "'disabled'", "=>", "true", ",", "'value'", "=>", "$", "item", "[", "'name'", "]", ")", ",", "array", "(", "'type'", "=>", "'text'", ",", "'name'", "=>", "'hint'", ",", "'value'", "=>", "isset", "(", "$", "this", "->", "stdTemplates", "[", "$", "item", "[", "'name'", "]", "]", "[", "'hint'", "]", ")", "?", "$", "this", "->", "stdTemplates", "[", "$", "item", "[", "'name'", "]", "]", "[", "'hint'", "]", ":", "''", ",", "'extra'", "=>", "'id=\"templateHint\"'", ")", ",", "array", "(", "'type'", "=>", "'memo'", ",", "'name'", "=>", "'code'", ",", "'height'", "=>", "'30'", ",", "'syntax'", "=>", "'html'", ")", ",", ")", ",", "'buttons'", "=>", "array", "(", "'ok'", ",", "'apply'", ",", "'cancel'", ")", ",", ")", ";", "/** @var TAdminUI $page */", "$", "page", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", ";", "$", "result", "=", "$", "page", "->", "renderForm", "(", "$", "form", ",", "$", "item", ")", ";", "return", "$", "result", ";", "}" ]
??? @return string
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L377-L404
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionStdList
public function sectionStdList() { $table = array( 'name' => 'templates', 'key'=> 'filename', 'sortMode' => 'filename', 'sortDesc' => false, 'columns' => array( array('name' => 'description', 'caption' => 'Описание'), #array('name' => 'filename', 'caption' => 'Имя файла'), ), 'controls' => array ( 'delete' => '', 'edit' => '', ), 'tabs' => array( 'width'=>'120px', 'items'=>array( array('caption'=>ADM_ADD, 'name'=>'action', 'value'=>'add'), ) ), ); $templates = Templates::getInstance(); $list = $templates->enum('std'); $items = array(); foreach ($list as $key=>$value) { $items[] = array('filename' => $key, 'description' => $value); } /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderTable($table, $items); return $result; }
php
public function sectionStdList() { $table = array( 'name' => 'templates', 'key'=> 'filename', 'sortMode' => 'filename', 'sortDesc' => false, 'columns' => array( array('name' => 'description', 'caption' => 'Описание'), #array('name' => 'filename', 'caption' => 'Имя файла'), ), 'controls' => array ( 'delete' => '', 'edit' => '', ), 'tabs' => array( 'width'=>'120px', 'items'=>array( array('caption'=>ADM_ADD, 'name'=>'action', 'value'=>'add'), ) ), ); $templates = Templates::getInstance(); $list = $templates->enum('std'); $items = array(); foreach ($list as $key=>$value) { $items[] = array('filename' => $key, 'description' => $value); } /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderTable($table, $items); return $result; }
[ "public", "function", "sectionStdList", "(", ")", "{", "$", "table", "=", "array", "(", "'name'", "=>", "'templates'", ",", "'key'", "=>", "'filename'", ",", "'sortMode'", "=>", "'filename'", ",", "'sortDesc'", "=>", "false", ",", "'columns'", "=>", "array", "(", "array", "(", "'name'", "=>", "'description'", ",", "'caption'", "=>", "'Описание'),", "", "", "#array('name' => 'filename', 'caption' => 'Имя файла'),", ")", ",", "'controls'", "=>", "array", "(", "'delete'", "=>", "''", ",", "'edit'", "=>", "''", ",", ")", ",", "'tabs'", "=>", "array", "(", "'width'", "=>", "'120px'", ",", "'items'", "=>", "array", "(", "array", "(", "'caption'", "=>", "ADM_ADD", ",", "'name'", "=>", "'action'", ",", "'value'", "=>", "'add'", ")", ",", ")", ")", ",", ")", ";", "$", "templates", "=", "Templates", "::", "getInstance", "(", ")", ";", "$", "list", "=", "$", "templates", "->", "enum", "(", "'std'", ")", ";", "$", "items", "=", "array", "(", ")", ";", "foreach", "(", "$", "list", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "items", "[", "]", "=", "array", "(", "'filename'", "=>", "$", "key", ",", "'description'", "=>", "$", "value", ")", ";", "}", "/** @var TAdminUI $page */", "$", "page", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", ";", "$", "result", "=", "$", "page", "->", "renderTable", "(", "$", "table", ",", "$", "items", ")", ";", "return", "$", "result", ";", "}" ]
??? @return string HTML
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L411-L444
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionStd
public function sectionStd() { Eresus_Kernel::app()->getPage()->title .= ADM_T_DIV.ADM_THEMES_STANDARD; $result = ''; switch (arg('action')) { case 'update': $this->sectionStdUpdate(); break; case 'insert': $this->sectionStdInsert(); break; case 'add': $result = $this->sectionStdAdd(); break; default: if (arg('delete')) { $this->sectionStdDelete(); } if (arg('id')) { $result = $this->sectionStdEdit(); } else { $result = $this->sectionStdList(); } } return $result; }
php
public function sectionStd() { Eresus_Kernel::app()->getPage()->title .= ADM_T_DIV.ADM_THEMES_STANDARD; $result = ''; switch (arg('action')) { case 'update': $this->sectionStdUpdate(); break; case 'insert': $this->sectionStdInsert(); break; case 'add': $result = $this->sectionStdAdd(); break; default: if (arg('delete')) { $this->sectionStdDelete(); } if (arg('id')) { $result = $this->sectionStdEdit(); } else { $result = $this->sectionStdList(); } } return $result; }
[ "public", "function", "sectionStd", "(", ")", "{", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "title", ".=", "ADM_T_DIV", ".", "ADM_THEMES_STANDARD", ";", "$", "result", "=", "''", ";", "switch", "(", "arg", "(", "'action'", ")", ")", "{", "case", "'update'", ":", "$", "this", "->", "sectionStdUpdate", "(", ")", ";", "break", ";", "case", "'insert'", ":", "$", "this", "->", "sectionStdInsert", "(", ")", ";", "break", ";", "case", "'add'", ":", "$", "result", "=", "$", "this", "->", "sectionStdAdd", "(", ")", ";", "break", ";", "default", ":", "if", "(", "arg", "(", "'delete'", ")", ")", "{", "$", "this", "->", "sectionStdDelete", "(", ")", ";", "}", "if", "(", "arg", "(", "'id'", ")", ")", "{", "$", "result", "=", "$", "this", "->", "sectionStdEdit", "(", ")", ";", "}", "else", "{", "$", "result", "=", "$", "this", "->", "sectionStdList", "(", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
??? @return string HTML
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L450-L481
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionStylesInsert
public function sectionStylesInsert() { $filename = arg('filename'); $filter = new Eresus_FS_NameFilter(); $filename = $filter->filter($filename); if ('' === $filename) { $filename = uniqid(); } if ($filename != arg('filename')) { Eresus_Kernel::app()->getPage()->addErrorMessage( sprintf(ADM_THEMES_FILENAME_FILTERED, $filename)); } $contents = "/* ".arg('description')." */\r\n\r\n".arg('html'); file_put_contents(Eresus_CMS::getLegacyKernel()->froot . 'style/' . $filename . '.css', $contents); HTTP::redirect(arg('submitURL')); }
php
public function sectionStylesInsert() { $filename = arg('filename'); $filter = new Eresus_FS_NameFilter(); $filename = $filter->filter($filename); if ('' === $filename) { $filename = uniqid(); } if ($filename != arg('filename')) { Eresus_Kernel::app()->getPage()->addErrorMessage( sprintf(ADM_THEMES_FILENAME_FILTERED, $filename)); } $contents = "/* ".arg('description')." */\r\n\r\n".arg('html'); file_put_contents(Eresus_CMS::getLegacyKernel()->froot . 'style/' . $filename . '.css', $contents); HTTP::redirect(arg('submitURL')); }
[ "public", "function", "sectionStylesInsert", "(", ")", "{", "$", "filename", "=", "arg", "(", "'filename'", ")", ";", "$", "filter", "=", "new", "Eresus_FS_NameFilter", "(", ")", ";", "$", "filename", "=", "$", "filter", "->", "filter", "(", "$", "filename", ")", ";", "if", "(", "''", "===", "$", "filename", ")", "{", "$", "filename", "=", "uniqid", "(", ")", ";", "}", "if", "(", "$", "filename", "!=", "arg", "(", "'filename'", ")", ")", "{", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "addErrorMessage", "(", "sprintf", "(", "ADM_THEMES_FILENAME_FILTERED", ",", "$", "filename", ")", ")", ";", "}", "$", "contents", "=", "\"/* \"", ".", "arg", "(", "'description'", ")", ".", "\" */\\r\\n\\r\\n\"", ".", "arg", "(", "'html'", ")", ";", "file_put_contents", "(", "Eresus_CMS", "::", "getLegacyKernel", "(", ")", "->", "froot", ".", "'style/'", ".", "$", "filename", ".", "'.css'", ",", "$", "contents", ")", ";", "HTTP", "::", "redirect", "(", "arg", "(", "'submitURL'", ")", ")", ";", "}" ]
Создаёт новый файл стилей @return void
[ "Создаёт", "новый", "файл", "стилей" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L489-L510
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionStylesDelete
public function sectionStylesDelete() { $filename = Eresus_CMS::getLegacyKernel()->froot . 'style/'.arg('delete'); if (file_exists($filename)) { unlink($filename); } HTTP::redirect(Eresus_Kernel::app()->getPage()->url()); }
php
public function sectionStylesDelete() { $filename = Eresus_CMS::getLegacyKernel()->froot . 'style/'.arg('delete'); if (file_exists($filename)) { unlink($filename); } HTTP::redirect(Eresus_Kernel::app()->getPage()->url()); }
[ "public", "function", "sectionStylesDelete", "(", ")", "{", "$", "filename", "=", "Eresus_CMS", "::", "getLegacyKernel", "(", ")", "->", "froot", ".", "'style/'", ".", "arg", "(", "'delete'", ")", ";", "if", "(", "file_exists", "(", "$", "filename", ")", ")", "{", "unlink", "(", "$", "filename", ")", ";", "}", "HTTP", "::", "redirect", "(", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "url", "(", ")", ")", ";", "}" ]
??? @return void
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L524-L532
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionStylesEdit
public function sectionStylesEdit() { $item['filename'] = arg('id'); $item['html'] = trim(file_get_contents(Eresus_CMS::getLegacyKernel()->froot . 'style/' . $item['filename'])); preg_match('|/\*(.*?)\*/|', $item['html'], $item['description']); $item['description'] = trim($item['description'][1]); $item['filename'] = substr($item['filename'], 0, strrpos($item['filename'], '.')); $item['html'] = trim(mb_substr($item['html'], mb_strpos($item['html'], "\n"))); $form = array( 'name' => 'editForm', 'caption' => Eresus_Kernel::app()->getPage()->title.ADM_T_DIV.ADM_EDIT, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'action', 'value'=>'update'), array('type'=>'hidden','name'=>'section', 'value'=>arg('section')), array('type'=>'hidden','name'=>'filename'), array('type' => 'edit', 'name' => '_filename', 'label' => ADM_THEMES_FILENAME_LABEL, 'width'=>'200px', 'comment'=>'.css', 'disabled' => true, 'value' => $item['filename']), array('type'=>'edit','name'=>'description','label'=>ADM_THEMES_DESC_LABEL, 'width'=>'100%'), array('type'=>'memo','name'=>'html', 'height'=>'30', 'syntax' => 'css'), ), 'buttons' => array('ok', 'apply', 'cancel'), ); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderForm($form, $item); return $result; }
php
public function sectionStylesEdit() { $item['filename'] = arg('id'); $item['html'] = trim(file_get_contents(Eresus_CMS::getLegacyKernel()->froot . 'style/' . $item['filename'])); preg_match('|/\*(.*?)\*/|', $item['html'], $item['description']); $item['description'] = trim($item['description'][1]); $item['filename'] = substr($item['filename'], 0, strrpos($item['filename'], '.')); $item['html'] = trim(mb_substr($item['html'], mb_strpos($item['html'], "\n"))); $form = array( 'name' => 'editForm', 'caption' => Eresus_Kernel::app()->getPage()->title.ADM_T_DIV.ADM_EDIT, 'width' => '100%', 'fields' => array ( array('type'=>'hidden','name'=>'action', 'value'=>'update'), array('type'=>'hidden','name'=>'section', 'value'=>arg('section')), array('type'=>'hidden','name'=>'filename'), array('type' => 'edit', 'name' => '_filename', 'label' => ADM_THEMES_FILENAME_LABEL, 'width'=>'200px', 'comment'=>'.css', 'disabled' => true, 'value' => $item['filename']), array('type'=>'edit','name'=>'description','label'=>ADM_THEMES_DESC_LABEL, 'width'=>'100%'), array('type'=>'memo','name'=>'html', 'height'=>'30', 'syntax' => 'css'), ), 'buttons' => array('ok', 'apply', 'cancel'), ); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderForm($form, $item); return $result; }
[ "public", "function", "sectionStylesEdit", "(", ")", "{", "$", "item", "[", "'filename'", "]", "=", "arg", "(", "'id'", ")", ";", "$", "item", "[", "'html'", "]", "=", "trim", "(", "file_get_contents", "(", "Eresus_CMS", "::", "getLegacyKernel", "(", ")", "->", "froot", ".", "'style/'", ".", "$", "item", "[", "'filename'", "]", ")", ")", ";", "preg_match", "(", "'|/\\*(.*?)\\*/|'", ",", "$", "item", "[", "'html'", "]", ",", "$", "item", "[", "'description'", "]", ")", ";", "$", "item", "[", "'description'", "]", "=", "trim", "(", "$", "item", "[", "'description'", "]", "[", "1", "]", ")", ";", "$", "item", "[", "'filename'", "]", "=", "substr", "(", "$", "item", "[", "'filename'", "]", ",", "0", ",", "strrpos", "(", "$", "item", "[", "'filename'", "]", ",", "'.'", ")", ")", ";", "$", "item", "[", "'html'", "]", "=", "trim", "(", "mb_substr", "(", "$", "item", "[", "'html'", "]", ",", "mb_strpos", "(", "$", "item", "[", "'html'", "]", ",", "\"\\n\"", ")", ")", ")", ";", "$", "form", "=", "array", "(", "'name'", "=>", "'editForm'", ",", "'caption'", "=>", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "title", ".", "ADM_T_DIV", ".", "ADM_EDIT", ",", "'width'", "=>", "'100%'", ",", "'fields'", "=>", "array", "(", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'action'", ",", "'value'", "=>", "'update'", ")", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'section'", ",", "'value'", "=>", "arg", "(", "'section'", ")", ")", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'filename'", ")", ",", "array", "(", "'type'", "=>", "'edit'", ",", "'name'", "=>", "'_filename'", ",", "'label'", "=>", "ADM_THEMES_FILENAME_LABEL", ",", "'width'", "=>", "'200px'", ",", "'comment'", "=>", "'.css'", ",", "'disabled'", "=>", "true", ",", "'value'", "=>", "$", "item", "[", "'filename'", "]", ")", ",", "array", "(", "'type'", "=>", "'edit'", ",", "'name'", "=>", "'description'", ",", "'label'", "=>", "ADM_THEMES_DESC_LABEL", ",", "'width'", "=>", "'100%'", ")", ",", "array", "(", "'type'", "=>", "'memo'", ",", "'name'", "=>", "'html'", ",", "'height'", "=>", "'30'", ",", "'syntax'", "=>", "'css'", ")", ",", ")", ",", "'buttons'", "=>", "array", "(", "'ok'", ",", "'apply'", ",", "'cancel'", ")", ",", ")", ";", "/** @var TAdminUI $page */", "$", "page", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", ";", "$", "result", "=", "$", "page", "->", "renderForm", "(", "$", "form", ",", "$", "item", ")", ";", "return", "$", "result", ";", "}" ]
??? @return string HTML
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L567-L596
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionStylesList
public function sectionStylesList() { $table = array( 'name' => 'Styles', 'key'=> 'filename', 'sortMode' => 'filename', 'sortDesc' => false, 'columns' => array( array('name' => 'description', 'caption' => 'Описание'), array('name' => 'filename', 'caption' => 'Имя файла'), ), 'controls' => array ( 'delete' => '', 'edit' => '', ), 'tabs' => array( 'width'=>'120px', 'items'=>array( array('caption'=>ADM_ADD, 'name'=>'action', 'value'=>'add'), ) ), ); # Загружаем список шаблонов $dir = Eresus_CMS::getLegacyKernel()->froot . 'style/'; $hnd = opendir($dir); $items = array(); while (($filename = readdir($hnd))!==false) { if (preg_match('/.*\.css$/', $filename)) { $description = file_get_contents($dir.$filename); preg_match('|/\*(.*?)\*/|', $description, $description); $description = trim($description[1]); $items[] = array( 'filename' => $filename, 'description' => $description, ); } } closedir($hnd); /* @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderTable($table, $items); return $result; }
php
public function sectionStylesList() { $table = array( 'name' => 'Styles', 'key'=> 'filename', 'sortMode' => 'filename', 'sortDesc' => false, 'columns' => array( array('name' => 'description', 'caption' => 'Описание'), array('name' => 'filename', 'caption' => 'Имя файла'), ), 'controls' => array ( 'delete' => '', 'edit' => '', ), 'tabs' => array( 'width'=>'120px', 'items'=>array( array('caption'=>ADM_ADD, 'name'=>'action', 'value'=>'add'), ) ), ); # Загружаем список шаблонов $dir = Eresus_CMS::getLegacyKernel()->froot . 'style/'; $hnd = opendir($dir); $items = array(); while (($filename = readdir($hnd))!==false) { if (preg_match('/.*\.css$/', $filename)) { $description = file_get_contents($dir.$filename); preg_match('|/\*(.*?)\*/|', $description, $description); $description = trim($description[1]); $items[] = array( 'filename' => $filename, 'description' => $description, ); } } closedir($hnd); /* @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result = $page->renderTable($table, $items); return $result; }
[ "public", "function", "sectionStylesList", "(", ")", "{", "$", "table", "=", "array", "(", "'name'", "=>", "'Styles'", ",", "'key'", "=>", "'filename'", ",", "'sortMode'", "=>", "'filename'", ",", "'sortDesc'", "=>", "false", ",", "'columns'", "=>", "array", "(", "array", "(", "'name'", "=>", "'description'", ",", "'caption'", "=>", "'Описание'),", "", "", "array", "(", "'name'", "=>", "'filename'", ",", "'caption'", "=>", "'Имя файла'),", "", "", ")", ",", "'controls'", "=>", "array", "(", "'delete'", "=>", "''", ",", "'edit'", "=>", "''", ",", ")", ",", "'tabs'", "=>", "array", "(", "'width'", "=>", "'120px'", ",", "'items'", "=>", "array", "(", "array", "(", "'caption'", "=>", "ADM_ADD", ",", "'name'", "=>", "'action'", ",", "'value'", "=>", "'add'", ")", ",", ")", ")", ",", ")", ";", "# Загружаем список шаблонов", "$", "dir", "=", "Eresus_CMS", "::", "getLegacyKernel", "(", ")", "->", "froot", ".", "'style/'", ";", "$", "hnd", "=", "opendir", "(", "$", "dir", ")", ";", "$", "items", "=", "array", "(", ")", ";", "while", "(", "(", "$", "filename", "=", "readdir", "(", "$", "hnd", ")", ")", "!==", "false", ")", "{", "if", "(", "preg_match", "(", "'/.*\\.css$/'", ",", "$", "filename", ")", ")", "{", "$", "description", "=", "file_get_contents", "(", "$", "dir", ".", "$", "filename", ")", ";", "preg_match", "(", "'|/\\*(.*?)\\*/|'", ",", "$", "description", ",", "$", "description", ")", ";", "$", "description", "=", "trim", "(", "$", "description", "[", "1", "]", ")", ";", "$", "items", "[", "]", "=", "array", "(", "'filename'", "=>", "$", "filename", ",", "'description'", "=>", "$", "description", ",", ")", ";", "}", "}", "closedir", "(", "$", "hnd", ")", ";", "/* @var TAdminUI $page */", "$", "page", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", ";", "$", "result", "=", "$", "page", "->", "renderTable", "(", "$", "table", ",", "$", "items", ")", ";", "return", "$", "result", ";", "}" ]
??? @return string
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L603-L647
Eresus/EresusCMS
src/core/themes.php
TThemes.sectionStyles
public function sectionStyles() { $result = ''; Eresus_Kernel::app()->getPage()->title .= ADM_T_DIV.ADM_THEMES_STYLES; switch (arg('action')) { case 'update': $this->sectionStylesUpdate(); break; case 'insert': $this->sectionStylesInsert(); break; case 'add': $result = $this->sectionStylesAdd(); break; default: if (arg('delete')) { $this->sectionStylesDelete(); } elseif (arg('id')) { $result = $this->sectionStylesEdit(); } else { $result = $this->sectionStylesList(); } } return $result; }
php
public function sectionStyles() { $result = ''; Eresus_Kernel::app()->getPage()->title .= ADM_T_DIV.ADM_THEMES_STYLES; switch (arg('action')) { case 'update': $this->sectionStylesUpdate(); break; case 'insert': $this->sectionStylesInsert(); break; case 'add': $result = $this->sectionStylesAdd(); break; default: if (arg('delete')) { $this->sectionStylesDelete(); } elseif (arg('id')) { $result = $this->sectionStylesEdit(); } else { $result = $this->sectionStylesList(); } } return $result; }
[ "public", "function", "sectionStyles", "(", ")", "{", "$", "result", "=", "''", ";", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "title", ".=", "ADM_T_DIV", ".", "ADM_THEMES_STYLES", ";", "switch", "(", "arg", "(", "'action'", ")", ")", "{", "case", "'update'", ":", "$", "this", "->", "sectionStylesUpdate", "(", ")", ";", "break", ";", "case", "'insert'", ":", "$", "this", "->", "sectionStylesInsert", "(", ")", ";", "break", ";", "case", "'add'", ":", "$", "result", "=", "$", "this", "->", "sectionStylesAdd", "(", ")", ";", "break", ";", "default", ":", "if", "(", "arg", "(", "'delete'", ")", ")", "{", "$", "this", "->", "sectionStylesDelete", "(", ")", ";", "}", "elseif", "(", "arg", "(", "'id'", ")", ")", "{", "$", "result", "=", "$", "this", "->", "sectionStylesEdit", "(", ")", ";", "}", "else", "{", "$", "result", "=", "$", "this", "->", "sectionStylesList", "(", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
??? @return string
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L654-L687
Eresus/EresusCMS
src/core/themes.php
TThemes.adminRender
public function adminRender() { $result = ''; if (UserRights($this->access)) { #FIXME: Временное решение #0000163 $this->tabs['items'][0]['url'] = Eresus_Kernel::app()->getPage()->url(array('id' => '', 'section' => 'templates')); $this->tabs['items'][1]['url'] = Eresus_Kernel::app()->getPage()->url(array('id' => '', 'section' => 'std')); $this->tabs['items'][2]['url'] = Eresus_Kernel::app()->getPage()->url(array('id' => '', 'section' => 'css')); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result .= $page->renderTabs($this->tabs); switch (arg('section')) { case 'css': $result .= $this->sectionStyles(); break; case 'std': $result .= $this->sectionStd(); break; case 'themes': default: $result .= $this->sectionTemplates(); break; } } return $result; }
php
public function adminRender() { $result = ''; if (UserRights($this->access)) { #FIXME: Временное решение #0000163 $this->tabs['items'][0]['url'] = Eresus_Kernel::app()->getPage()->url(array('id' => '', 'section' => 'templates')); $this->tabs['items'][1]['url'] = Eresus_Kernel::app()->getPage()->url(array('id' => '', 'section' => 'std')); $this->tabs['items'][2]['url'] = Eresus_Kernel::app()->getPage()->url(array('id' => '', 'section' => 'css')); /** @var TAdminUI $page */ $page = Eresus_Kernel::app()->getPage(); $result .= $page->renderTabs($this->tabs); switch (arg('section')) { case 'css': $result .= $this->sectionStyles(); break; case 'std': $result .= $this->sectionStd(); break; case 'themes': default: $result .= $this->sectionTemplates(); break; } } return $result; }
[ "public", "function", "adminRender", "(", ")", "{", "$", "result", "=", "''", ";", "if", "(", "UserRights", "(", "$", "this", "->", "access", ")", ")", "{", "#FIXME: Временное решение #0000163", "$", "this", "->", "tabs", "[", "'items'", "]", "[", "0", "]", "[", "'url'", "]", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "url", "(", "array", "(", "'id'", "=>", "''", ",", "'section'", "=>", "'templates'", ")", ")", ";", "$", "this", "->", "tabs", "[", "'items'", "]", "[", "1", "]", "[", "'url'", "]", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "url", "(", "array", "(", "'id'", "=>", "''", ",", "'section'", "=>", "'std'", ")", ")", ";", "$", "this", "->", "tabs", "[", "'items'", "]", "[", "2", "]", "[", "'url'", "]", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", "->", "url", "(", "array", "(", "'id'", "=>", "''", ",", "'section'", "=>", "'css'", ")", ")", ";", "/** @var TAdminUI $page */", "$", "page", "=", "Eresus_Kernel", "::", "app", "(", ")", "->", "getPage", "(", ")", ";", "$", "result", ".=", "$", "page", "->", "renderTabs", "(", "$", "this", "->", "tabs", ")", ";", "switch", "(", "arg", "(", "'section'", ")", ")", "{", "case", "'css'", ":", "$", "result", ".=", "$", "this", "->", "sectionStyles", "(", ")", ";", "break", ";", "case", "'std'", ":", "$", "result", ".=", "$", "this", "->", "sectionStd", "(", ")", ";", "break", ";", "case", "'themes'", ":", "default", ":", "$", "result", ".=", "$", "this", "->", "sectionTemplates", "(", ")", ";", "break", ";", "}", "}", "return", "$", "result", ";", "}" ]
??? @return string
[ "???" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/themes.php#L694-L724
netzmacht/contao-leaflet-geocode-widget
src/EventListener/RadiusWizardCallbackListener.php
RadiusWizardCallbackListener.generateWizard
public function generateWizard($dataContainer) { if (!isset($GLOBALS['TL_DCA'][$dataContainer->table]['fields'][$dataContainer->field]['eval']['coordinates'])) { return ''; } return sprintf( '<a href="#" onclick="$(\'ctrl_%s_toggle\').click();return false;"><img src="%s"></a>', $GLOBALS['TL_DCA'][$dataContainer->table]['fields'][$dataContainer->field]['eval']['coordinates'], 'bundles/leafletgeocodewidget/img/map.png' ); }
php
public function generateWizard($dataContainer) { if (!isset($GLOBALS['TL_DCA'][$dataContainer->table]['fields'][$dataContainer->field]['eval']['coordinates'])) { return ''; } return sprintf( '<a href="#" onclick="$(\'ctrl_%s_toggle\').click();return false;"><img src="%s"></a>', $GLOBALS['TL_DCA'][$dataContainer->table]['fields'][$dataContainer->field]['eval']['coordinates'], 'bundles/leafletgeocodewidget/img/map.png' ); }
[ "public", "function", "generateWizard", "(", "$", "dataContainer", ")", "{", "if", "(", "!", "isset", "(", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "$", "dataContainer", "->", "table", "]", "[", "'fields'", "]", "[", "$", "dataContainer", "->", "field", "]", "[", "'eval'", "]", "[", "'coordinates'", "]", ")", ")", "{", "return", "''", ";", "}", "return", "sprintf", "(", "'<a href=\"#\" onclick=\"$(\\'ctrl_%s_toggle\\').click();return false;\"><img src=\"%s\"></a>'", ",", "$", "GLOBALS", "[", "'TL_DCA'", "]", "[", "$", "dataContainer", "->", "table", "]", "[", "'fields'", "]", "[", "$", "dataContainer", "->", "field", "]", "[", "'eval'", "]", "[", "'coordinates'", "]", ",", "'bundles/leafletgeocodewidget/img/map.png'", ")", ";", "}" ]
Generate the wizard for the radius widget. @param DataContainer $dataContainer Data container driver. @return string @SuppressWarnings(PHPMD.Superglobals)
[ "Generate", "the", "wizard", "for", "the", "radius", "widget", "." ]
train
https://github.com/netzmacht/contao-leaflet-geocode-widget/blob/08acfbc473696f385d7c6aed6148e51c91443e12/src/EventListener/RadiusWizardCallbackListener.php#L33-L44
wenbinye/PhalconX
src/Helper/ArrayHelper.php
ArrayHelper.pull
public static function pull($arr, $name, $type = null) { $ret = []; if ($type == self::GETTER) { $method = 'get' . $name; foreach ($arr as $elem) { $ret[] = $elem->$method(); } } elseif ($type == self::OBJ) { foreach ($arr as $elem) { $ret[] = $elem->$name; } } else { foreach ($arr as $elem) { $ret[] = $elem[$name]; } } return $ret; }
php
public static function pull($arr, $name, $type = null) { $ret = []; if ($type == self::GETTER) { $method = 'get' . $name; foreach ($arr as $elem) { $ret[] = $elem->$method(); } } elseif ($type == self::OBJ) { foreach ($arr as $elem) { $ret[] = $elem->$name; } } else { foreach ($arr as $elem) { $ret[] = $elem[$name]; } } return $ret; }
[ "public", "static", "function", "pull", "(", "$", "arr", ",", "$", "name", ",", "$", "type", "=", "null", ")", "{", "$", "ret", "=", "[", "]", ";", "if", "(", "$", "type", "==", "self", "::", "GETTER", ")", "{", "$", "method", "=", "'get'", ".", "$", "name", ";", "foreach", "(", "$", "arr", "as", "$", "elem", ")", "{", "$", "ret", "[", "]", "=", "$", "elem", "->", "$", "method", "(", ")", ";", "}", "}", "elseif", "(", "$", "type", "==", "self", "::", "OBJ", ")", "{", "foreach", "(", "$", "arr", "as", "$", "elem", ")", "{", "$", "ret", "[", "]", "=", "$", "elem", "->", "$", "name", ";", "}", "}", "else", "{", "foreach", "(", "$", "arr", "as", "$", "elem", ")", "{", "$", "ret", "[", "]", "=", "$", "elem", "[", "$", "name", "]", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Collects value from array @param array $array @param string $name @param string $type @return array
[ "Collects", "value", "from", "array" ]
train
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Helper/ArrayHelper.php#L37-L55
wenbinye/PhalconX
src/Helper/ArrayHelper.php
ArrayHelper.assoc
public static function assoc($arr, $name, $type = null) { $ret = []; if (empty($arr)) { return $ret; } if ($type == self::GETTER) { $method = 'get' . $name; foreach ($arr as $elem) { $ret[$elem->$method()] = $elem; } } elseif ($type == self::OBJ) { foreach ($arr as $elem) { $ret[$elem->$name] = $elem; } } else { foreach ($arr as $elem) { $ret[$elem[$name]] = $elem; } } return $ret; }
php
public static function assoc($arr, $name, $type = null) { $ret = []; if (empty($arr)) { return $ret; } if ($type == self::GETTER) { $method = 'get' . $name; foreach ($arr as $elem) { $ret[$elem->$method()] = $elem; } } elseif ($type == self::OBJ) { foreach ($arr as $elem) { $ret[$elem->$name] = $elem; } } else { foreach ($arr as $elem) { $ret[$elem[$name]] = $elem; } } return $ret; }
[ "public", "static", "function", "assoc", "(", "$", "arr", ",", "$", "name", ",", "$", "type", "=", "null", ")", "{", "$", "ret", "=", "[", "]", ";", "if", "(", "empty", "(", "$", "arr", ")", ")", "{", "return", "$", "ret", ";", "}", "if", "(", "$", "type", "==", "self", "::", "GETTER", ")", "{", "$", "method", "=", "'get'", ".", "$", "name", ";", "foreach", "(", "$", "arr", "as", "$", "elem", ")", "{", "$", "ret", "[", "$", "elem", "->", "$", "method", "(", ")", "]", "=", "$", "elem", ";", "}", "}", "elseif", "(", "$", "type", "==", "self", "::", "OBJ", ")", "{", "foreach", "(", "$", "arr", "as", "$", "elem", ")", "{", "$", "ret", "[", "$", "elem", "->", "$", "name", "]", "=", "$", "elem", ";", "}", "}", "else", "{", "foreach", "(", "$", "arr", "as", "$", "elem", ")", "{", "$", "ret", "[", "$", "elem", "[", "$", "name", "]", "]", "=", "$", "elem", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Creates associated array @param array $array @param string $name @param string $type @return array
[ "Creates", "associated", "array" ]
train
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Helper/ArrayHelper.php#L65-L86
wenbinye/PhalconX
src/Helper/ArrayHelper.php
ArrayHelper.select
public static function select($arr, $includedKeys) { $ret = []; foreach ($includedKeys as $key) { if (array_key_exists($key, $arr)) { $ret[$key] = $arr[$key]; } } return $ret; }
php
public static function select($arr, $includedKeys) { $ret = []; foreach ($includedKeys as $key) { if (array_key_exists($key, $arr)) { $ret[$key] = $arr[$key]; } } return $ret; }
[ "public", "static", "function", "select", "(", "$", "arr", ",", "$", "includedKeys", ")", "{", "$", "ret", "=", "[", "]", ";", "foreach", "(", "$", "includedKeys", "as", "$", "key", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "arr", ")", ")", "{", "$", "ret", "[", "$", "key", "]", "=", "$", "arr", "[", "$", "key", "]", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Create array with given keys @param array $array @param array $includedKeys @return array
[ "Create", "array", "with", "given", "keys" ]
train
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Helper/ArrayHelper.php#L107-L116
wenbinye/PhalconX
src/Helper/ArrayHelper.php
ArrayHelper.sorter
public static function sorter($name, $func = null, $type = null) { if (!isset($func)) { $func = function ($a, $b) { if ($a == $b) { return 0; } return $a < $b ? -1 : 1; }; } if ($type == self::GETTER) { $method = 'get' . $name; return function ($a, $b) use ($method, $func) { return call_user_func($func, $a->$method(), $b->$method()); }; } elseif ($type == self::OBJ) { return function ($a, $b) use ($name, $func) { return call_user_func($func, $a->$name, $b->$name); }; } else { return function ($a, $b) use ($name, $func) { return call_user_func($func, $a[$name], $b[$name]); }; } }
php
public static function sorter($name, $func = null, $type = null) { if (!isset($func)) { $func = function ($a, $b) { if ($a == $b) { return 0; } return $a < $b ? -1 : 1; }; } if ($type == self::GETTER) { $method = 'get' . $name; return function ($a, $b) use ($method, $func) { return call_user_func($func, $a->$method(), $b->$method()); }; } elseif ($type == self::OBJ) { return function ($a, $b) use ($name, $func) { return call_user_func($func, $a->$name, $b->$name); }; } else { return function ($a, $b) use ($name, $func) { return call_user_func($func, $a[$name], $b[$name]); }; } }
[ "public", "static", "function", "sorter", "(", "$", "name", ",", "$", "func", "=", "null", ",", "$", "type", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "func", ")", ")", "{", "$", "func", "=", "function", "(", "$", "a", ",", "$", "b", ")", "{", "if", "(", "$", "a", "==", "$", "b", ")", "{", "return", "0", ";", "}", "return", "$", "a", "<", "$", "b", "?", "-", "1", ":", "1", ";", "}", ";", "}", "if", "(", "$", "type", "==", "self", "::", "GETTER", ")", "{", "$", "method", "=", "'get'", ".", "$", "name", ";", "return", "function", "(", "$", "a", ",", "$", "b", ")", "use", "(", "$", "method", ",", "$", "func", ")", "{", "return", "call_user_func", "(", "$", "func", ",", "$", "a", "->", "$", "method", "(", ")", ",", "$", "b", "->", "$", "method", "(", ")", ")", ";", "}", ";", "}", "elseif", "(", "$", "type", "==", "self", "::", "OBJ", ")", "{", "return", "function", "(", "$", "a", ",", "$", "b", ")", "use", "(", "$", "name", ",", "$", "func", ")", "{", "return", "call_user_func", "(", "$", "func", ",", "$", "a", "->", "$", "name", ",", "$", "b", "->", "$", "name", ")", ";", "}", ";", "}", "else", "{", "return", "function", "(", "$", "a", ",", "$", "b", ")", "use", "(", "$", "name", ",", "$", "func", ")", "{", "return", "call_user_func", "(", "$", "func", ",", "$", "a", "[", "$", "name", "]", ",", "$", "b", "[", "$", "name", "]", ")", ";", "}", ";", "}", "}" ]
create sorter @param string $name @param closure $func @param string $type @return closure
[ "create", "sorter" ]
train
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Helper/ArrayHelper.php#L139-L164
ajgarlag/AjglCsv
src/Reader/NativePhpReader.php
NativePhpReader.doRead
protected function doRead() { $row = fgetcsv($this->getHandler(), 0, $this->getDelimiter()); return ($row !== false) ? $row : null; }
php
protected function doRead() { $row = fgetcsv($this->getHandler(), 0, $this->getDelimiter()); return ($row !== false) ? $row : null; }
[ "protected", "function", "doRead", "(", ")", "{", "$", "row", "=", "fgetcsv", "(", "$", "this", "->", "getHandler", "(", ")", ",", "0", ",", "$", "this", "->", "getDelimiter", "(", ")", ")", ";", "return", "(", "$", "row", "!==", "false", ")", "?", "$", "row", ":", "null", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/ajgarlag/AjglCsv/blob/28872f58b9ef864893cac6faddfcb1229c2c2047/src/Reader/NativePhpReader.php#L22-L27
i-lateral/silverstripe-deferedimages
src/DeferedImageExtension.php
DeferedImage.MicroImage
public function MicroImage() { $pixel = $this->config()->pixelate; $blur = $this->config()->blur; $quality = $this->config()->quality; $scale = $this->config()->scale; $variant = $this->owner->variantName(__FUNCTION__, $pixel, $blur, $quality, $scale); return $this->owner->manipulateImage( $variant, function (Image_Backend $backend) use ($pixel, $blur, $quality, $scale) { $clone = clone $backend; $resource = clone $backend->getImageResource(); $resource->pixelate($pixel)->blur($blur)->encode('jpg', $quality); if ($scale != 100) { $width = $backend->getWidth() * ($scale/100); $height = $backend->getHeight() * ($scale/100); $resource->resize($width, $height); } $clone->setImageResource($resource); return $clone; } ); }
php
public function MicroImage() { $pixel = $this->config()->pixelate; $blur = $this->config()->blur; $quality = $this->config()->quality; $scale = $this->config()->scale; $variant = $this->owner->variantName(__FUNCTION__, $pixel, $blur, $quality, $scale); return $this->owner->manipulateImage( $variant, function (Image_Backend $backend) use ($pixel, $blur, $quality, $scale) { $clone = clone $backend; $resource = clone $backend->getImageResource(); $resource->pixelate($pixel)->blur($blur)->encode('jpg', $quality); if ($scale != 100) { $width = $backend->getWidth() * ($scale/100); $height = $backend->getHeight() * ($scale/100); $resource->resize($width, $height); } $clone->setImageResource($resource); return $clone; } ); }
[ "public", "function", "MicroImage", "(", ")", "{", "$", "pixel", "=", "$", "this", "->", "config", "(", ")", "->", "pixelate", ";", "$", "blur", "=", "$", "this", "->", "config", "(", ")", "->", "blur", ";", "$", "quality", "=", "$", "this", "->", "config", "(", ")", "->", "quality", ";", "$", "scale", "=", "$", "this", "->", "config", "(", ")", "->", "scale", ";", "$", "variant", "=", "$", "this", "->", "owner", "->", "variantName", "(", "__FUNCTION__", ",", "$", "pixel", ",", "$", "blur", ",", "$", "quality", ",", "$", "scale", ")", ";", "return", "$", "this", "->", "owner", "->", "manipulateImage", "(", "$", "variant", ",", "function", "(", "Image_Backend", "$", "backend", ")", "use", "(", "$", "pixel", ",", "$", "blur", ",", "$", "quality", ",", "$", "scale", ")", "{", "$", "clone", "=", "clone", "$", "backend", ";", "$", "resource", "=", "clone", "$", "backend", "->", "getImageResource", "(", ")", ";", "$", "resource", "->", "pixelate", "(", "$", "pixel", ")", "->", "blur", "(", "$", "blur", ")", "->", "encode", "(", "'jpg'", ",", "$", "quality", ")", ";", "if", "(", "$", "scale", "!=", "100", ")", "{", "$", "width", "=", "$", "backend", "->", "getWidth", "(", ")", "*", "(", "$", "scale", "/", "100", ")", ";", "$", "height", "=", "$", "backend", "->", "getHeight", "(", ")", "*", "(", "$", "scale", "/", "100", ")", ";", "$", "resource", "->", "resize", "(", "$", "width", ",", "$", "height", ")", ";", "}", "$", "clone", "->", "setImageResource", "(", "$", "resource", ")", ";", "return", "$", "clone", ";", "}", ")", ";", "}" ]
Generates a reduced quality version of the current image @config @return void
[ "Generates", "a", "reduced", "quality", "version", "of", "the", "current", "image" ]
train
https://github.com/i-lateral/silverstripe-deferedimages/blob/6095e2404bbc5e33a8d996909f34111d4f751026/src/DeferedImageExtension.php#L50-L73
thelia-modules/CustomerGroup
Model/Map/CustomerGroupTableMap.php
CustomerGroupTableMap.getPrimaryKeyFromRow
public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) { return (int) $row[ $indexType == TableMap::TYPE_NUM ? 2 + $offset : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) ]; }
php
public static function getPrimaryKeyFromRow($row, $offset = 0, $indexType = TableMap::TYPE_NUM) { return (int) $row[ $indexType == TableMap::TYPE_NUM ? 2 + $offset : self::translateFieldName('Id', TableMap::TYPE_PHPNAME, $indexType) ]; }
[ "public", "static", "function", "getPrimaryKeyFromRow", "(", "$", "row", ",", "$", "offset", "=", "0", ",", "$", "indexType", "=", "TableMap", "::", "TYPE_NUM", ")", "{", "return", "(", "int", ")", "$", "row", "[", "$", "indexType", "==", "TableMap", "::", "TYPE_NUM", "?", "2", "+", "$", "offset", ":", "self", "::", "translateFieldName", "(", "'Id'", ",", "TableMap", "::", "TYPE_PHPNAME", ",", "$", "indexType", ")", "]", ";", "}" ]
Retrieves the primary key from the DB resultset row For tables with a single-column primary key, that simple pkey value will be returned. For tables with a multi-column primary key, an array of the primary key columns will be returned. @param array $row resultset row. @param int $offset The 0-based offset for reading from the resultset row. @param string $indexType One of the class type constants TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM @return mixed The primary key of the row
[ "Retrieves", "the", "primary", "key", "from", "the", "DB", "resultset", "row", "For", "tables", "with", "a", "single", "-", "column", "primary", "key", "that", "simple", "pkey", "value", "will", "be", "returned", ".", "For", "tables", "with", "a", "multi", "-", "column", "primary", "key", "an", "array", "of", "the", "primary", "key", "columns", "will", "be", "returned", "." ]
train
https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Model/Map/CustomerGroupTableMap.php#L247-L255
thelia-modules/CustomerGroup
Model/Map/CustomerGroupTableMap.php
CustomerGroupTableMap.addSelectColumns
public static function addSelectColumns(Criteria $criteria, $alias = null) { if (null === $alias) { $criteria->addSelectColumn(CustomerGroupTableMap::CODE); $criteria->addSelectColumn(CustomerGroupTableMap::IS_DEFAULT); $criteria->addSelectColumn(CustomerGroupTableMap::ID); $criteria->addSelectColumn(CustomerGroupTableMap::CREATED_AT); $criteria->addSelectColumn(CustomerGroupTableMap::UPDATED_AT); $criteria->addSelectColumn(CustomerGroupTableMap::POSITION); } else { $criteria->addSelectColumn($alias . '.CODE'); $criteria->addSelectColumn($alias . '.IS_DEFAULT'); $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); $criteria->addSelectColumn($alias . '.POSITION'); } }
php
public static function addSelectColumns(Criteria $criteria, $alias = null) { if (null === $alias) { $criteria->addSelectColumn(CustomerGroupTableMap::CODE); $criteria->addSelectColumn(CustomerGroupTableMap::IS_DEFAULT); $criteria->addSelectColumn(CustomerGroupTableMap::ID); $criteria->addSelectColumn(CustomerGroupTableMap::CREATED_AT); $criteria->addSelectColumn(CustomerGroupTableMap::UPDATED_AT); $criteria->addSelectColumn(CustomerGroupTableMap::POSITION); } else { $criteria->addSelectColumn($alias . '.CODE'); $criteria->addSelectColumn($alias . '.IS_DEFAULT'); $criteria->addSelectColumn($alias . '.ID'); $criteria->addSelectColumn($alias . '.CREATED_AT'); $criteria->addSelectColumn($alias . '.UPDATED_AT'); $criteria->addSelectColumn($alias . '.POSITION'); } }
[ "public", "static", "function", "addSelectColumns", "(", "Criteria", "$", "criteria", ",", "$", "alias", "=", "null", ")", "{", "if", "(", "null", "===", "$", "alias", ")", "{", "$", "criteria", "->", "addSelectColumn", "(", "CustomerGroupTableMap", "::", "CODE", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "CustomerGroupTableMap", "::", "IS_DEFAULT", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "CustomerGroupTableMap", "::", "ID", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "CustomerGroupTableMap", "::", "CREATED_AT", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "CustomerGroupTableMap", "::", "UPDATED_AT", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "CustomerGroupTableMap", "::", "POSITION", ")", ";", "}", "else", "{", "$", "criteria", "->", "addSelectColumn", "(", "$", "alias", ".", "'.CODE'", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "$", "alias", ".", "'.IS_DEFAULT'", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "$", "alias", ".", "'.ID'", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "$", "alias", ".", "'.CREATED_AT'", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "$", "alias", ".", "'.UPDATED_AT'", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "$", "alias", ".", "'.POSITION'", ")", ";", "}", "}" ]
Add all the columns needed to create a new object. Note: any columns that were marked with lazyLoad="true" in the XML schema will not be added to the select list and only loaded on demand. @param Criteria $criteria object containing the columns to add. @param string $alias optional table alias @throws PropelException Any exceptions caught during processing will be rethrown wrapped into a PropelException.
[ "Add", "all", "the", "columns", "needed", "to", "create", "a", "new", "object", "." ]
train
https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Model/Map/CustomerGroupTableMap.php#L349-L366
thelia-modules/CustomerGroup
Model/Map/CustomerGroupTableMap.php
CustomerGroupTableMap.buildTableMap
public static function buildTableMap() { $dbMap = Propel::getServiceContainer()->getDatabaseMap(CustomerGroupTableMap::DATABASE_NAME); if (!$dbMap->hasTable(CustomerGroupTableMap::TABLE_NAME)) { $dbMap->addTableObject(new CustomerGroupTableMap()); } }
php
public static function buildTableMap() { $dbMap = Propel::getServiceContainer()->getDatabaseMap(CustomerGroupTableMap::DATABASE_NAME); if (!$dbMap->hasTable(CustomerGroupTableMap::TABLE_NAME)) { $dbMap->addTableObject(new CustomerGroupTableMap()); } }
[ "public", "static", "function", "buildTableMap", "(", ")", "{", "$", "dbMap", "=", "Propel", "::", "getServiceContainer", "(", ")", "->", "getDatabaseMap", "(", "CustomerGroupTableMap", "::", "DATABASE_NAME", ")", ";", "if", "(", "!", "$", "dbMap", "->", "hasTable", "(", "CustomerGroupTableMap", "::", "TABLE_NAME", ")", ")", "{", "$", "dbMap", "->", "addTableObject", "(", "new", "CustomerGroupTableMap", "(", ")", ")", ";", "}", "}" ]
Add a TableMap instance to the database for this tableMap class.
[ "Add", "a", "TableMap", "instance", "to", "the", "database", "for", "this", "tableMap", "class", "." ]
train
https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Model/Map/CustomerGroupTableMap.php#L383-L389
songshenzong/log
src/DataCollector/PDO/TracedStatement.php
TracedStatement.getSqlWithParams
public function getSqlWithParams($quotationChar = '<>') { if (($l = strlen($quotationChar)) > 1) { $quoteLeft = substr($quotationChar, 0, $l / 2); $quoteRight = substr($quotationChar, $l / 2); } else { $quoteLeft = $quoteRight = $quotationChar; } $sql = $this->sql; foreach ($this->parameters as $k => $v) { $v = "$quoteLeft$v$quoteRight"; if (!is_numeric($k)) { $sql = str_replace($k, $v, $sql); } else { $p = strpos($sql, '?'); $sql = substr($sql, 0, $p) . $v . substr($sql, $p + 1); } } return $sql; }
php
public function getSqlWithParams($quotationChar = '<>') { if (($l = strlen($quotationChar)) > 1) { $quoteLeft = substr($quotationChar, 0, $l / 2); $quoteRight = substr($quotationChar, $l / 2); } else { $quoteLeft = $quoteRight = $quotationChar; } $sql = $this->sql; foreach ($this->parameters as $k => $v) { $v = "$quoteLeft$v$quoteRight"; if (!is_numeric($k)) { $sql = str_replace($k, $v, $sql); } else { $p = strpos($sql, '?'); $sql = substr($sql, 0, $p) . $v . substr($sql, $p + 1); } } return $sql; }
[ "public", "function", "getSqlWithParams", "(", "$", "quotationChar", "=", "'<>'", ")", "{", "if", "(", "(", "$", "l", "=", "strlen", "(", "$", "quotationChar", ")", ")", ">", "1", ")", "{", "$", "quoteLeft", "=", "substr", "(", "$", "quotationChar", ",", "0", ",", "$", "l", "/", "2", ")", ";", "$", "quoteRight", "=", "substr", "(", "$", "quotationChar", ",", "$", "l", "/", "2", ")", ";", "}", "else", "{", "$", "quoteLeft", "=", "$", "quoteRight", "=", "$", "quotationChar", ";", "}", "$", "sql", "=", "$", "this", "->", "sql", ";", "foreach", "(", "$", "this", "->", "parameters", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "v", "=", "\"$quoteLeft$v$quoteRight\"", ";", "if", "(", "!", "is_numeric", "(", "$", "k", ")", ")", "{", "$", "sql", "=", "str_replace", "(", "$", "k", ",", "$", "v", ",", "$", "sql", ")", ";", "}", "else", "{", "$", "p", "=", "strpos", "(", "$", "sql", ",", "'?'", ")", ";", "$", "sql", "=", "substr", "(", "$", "sql", ",", "0", ",", "$", "p", ")", ".", "$", "v", ".", "substr", "(", "$", "sql", ",", "$", "p", "+", "1", ")", ";", "}", "}", "return", "$", "sql", ";", "}" ]
Returns the SQL string with any parameters used embedded @param string $quotationChar @return string
[ "Returns", "the", "SQL", "string", "with", "any", "parameters", "used", "embedded" ]
train
https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/DataCollector/PDO/TracedStatement.php#L132-L152
traderinteractive/image-util-php
src/Image.php
Image.resize
public static function resize(\Imagick $source, int $boxWidth, int $boxHeight, array $options = []) : \Imagick { $results = self::resizeMulti($source, [['width' => $boxWidth, 'height' => $boxHeight]], $options); return $results[0]; }
php
public static function resize(\Imagick $source, int $boxWidth, int $boxHeight, array $options = []) : \Imagick { $results = self::resizeMulti($source, [['width' => $boxWidth, 'height' => $boxHeight]], $options); return $results[0]; }
[ "public", "static", "function", "resize", "(", "\\", "Imagick", "$", "source", ",", "int", "$", "boxWidth", ",", "int", "$", "boxHeight", ",", "array", "$", "options", "=", "[", "]", ")", ":", "\\", "Imagick", "{", "$", "results", "=", "self", "::", "resizeMulti", "(", "$", "source", ",", "[", "[", "'width'", "=>", "$", "boxWidth", ",", "'height'", "=>", "$", "boxHeight", "]", "]", ",", "$", "options", ")", ";", "return", "$", "results", "[", "0", "]", ";", "}" ]
Calls @see resizeMulti() with $boxWidth and $boxHeight as a single element in $boxSizes
[ "Calls" ]
train
https://github.com/traderinteractive/image-util-php/blob/60595257ff8cb704e9a39384a0fc1232159d16dc/src/Image.php#L10-L14
traderinteractive/image-util-php
src/Image.php
Image.resizeMulti
public static function resizeMulti(\Imagick $source, array $boxSizes, array $options = []) : array { //algorithm inspired from http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html //use of 2x2 binning is arguably the best quality one will get downsizing and is what lots of hardware does in //the photography field, while being reasonably fast. Upsizing is more subjective but you can't get much //better than bicubic which is what is used here. $color = 'white'; if (isset($options['color'])) { $color = $options['color']; if (!is_string($color)) { throw new \InvalidArgumentException('$options["color"] was not a string'); } } $upsize = false; if (isset($options['upsize'])) { $upsize = $options['upsize']; if ($upsize !== true && $upsize !== false) { throw new \InvalidArgumentException('$options["upsize"] was not a bool'); } } $maxWidth = 10000; if (isset($options['maxWidth'])) { $maxWidth = $options['maxWidth']; if (!is_int($maxWidth)) { throw new \InvalidArgumentException('$options["maxWidth"] was not an int'); } } $maxHeight = 10000; if (isset($options['maxHeight'])) { $maxHeight = $options['maxHeight']; if (!is_int($maxHeight)) { throw new \InvalidArgumentException('$options["maxHeight"] was not an int'); } } foreach ($boxSizes as $boxSizeKey => $boxSize) { if (!isset($boxSize['width']) || !is_int($boxSize['width'])) { throw new \InvalidArgumentException('a width in a $boxSizes value was not an int'); } if (!isset($boxSize['height']) || !is_int($boxSize['height'])) { throw new \InvalidArgumentException('a height in a $boxSizes value was not an int'); } if ($boxSize['width'] > $maxWidth || $boxSize['width'] <= 0) { throw new \InvalidArgumentException('a $boxSizes width was not between 0 and $options["maxWidth"]'); } if ($boxSize['height'] > $maxHeight || $boxSize['height'] <= 0) { throw new \InvalidArgumentException('a $boxSizes height was not between 0 and $options["maxHeight"]'); } } $results = []; $cloneCache = []; foreach ($boxSizes as $boxSizeKey => $boxSize) { $boxWidth = $boxSize['width']; $boxHeight = $boxSize['height']; $clone = clone $source; $orientation = $clone->getImageOrientation(); switch ($orientation) { case \Imagick::ORIENTATION_BOTTOMRIGHT: $clone->rotateimage('#fff', 180); $clone->stripImage(); break; case \Imagick::ORIENTATION_RIGHTTOP: $clone->rotateimage('#fff', 90); $clone->stripImage(); break; case \Imagick::ORIENTATION_LEFTBOTTOM: $clone->rotateimage('#fff', -90); $clone->stripImage(); break; } $width = $clone->getImageWidth(); $height = $clone->getImageHeight(); //ratio over 1 is horizontal, under 1 is vertical $boxRatio = $boxWidth / $boxHeight; //height should be positive since I didnt find a way you could get zero into imagick $originalRatio = $width / $height; $targetWidth = null; $targetHeight = null; $targetX = null; $targetY = null; if ($width < $boxWidth && $height < $boxHeight && !$upsize) { $targetWidth = $width; $targetHeight = $height; $targetX = ($boxWidth - $width) / 2; $targetY = ($boxHeight - $height) / 2; } else { //if box is more vertical than original if ($boxRatio < $originalRatio) { $targetWidth = $boxWidth; $targetHeight = (int)((double)$boxWidth / $originalRatio); $targetX = 0; $targetY = ($boxHeight - $targetHeight) / 2; } else { $targetWidth = (int)((double)$boxHeight * $originalRatio); $targetHeight = $boxHeight; $targetX = ($boxWidth - $targetWidth) / 2; $targetY = 0; } } //do iterative downsize by halfs (2x2 binning is a common name) on dimensions that are bigger than target //width and height while (true) { $widthReduced = false; $widthIsHalf = false; if ($width > $targetWidth) { $width = (int)($width / 2); $widthReduced = true; $widthIsHalf = true; if ($width < $targetWidth) { $width = $targetWidth; $widthIsHalf = false; } } $heightReduced = false; $heightIsHalf = false; if ($height > $targetHeight) { $height = (int)($height / 2); $heightReduced = true; $heightIsHalf = true; if ($height < $targetHeight) { $height = $targetHeight; $heightIsHalf = false; } } if (!$widthReduced && !$heightReduced) { break; } $cacheKey = "{$width}x{$height}"; if (isset($cloneCache[$cacheKey])) { $clone = clone $cloneCache[$cacheKey]; continue; } if ($clone->resizeImage($width, $height, \Imagick::FILTER_BOX, 1.0) !== true) { //cumbersome to test throw new \Exception('Imagick::resizeImage() did not return true');//@codeCoverageIgnore } if ($widthIsHalf && $heightIsHalf) { $cloneCache[$cacheKey] = clone $clone; } } if ($upsize && ($width < $targetWidth || $height < $targetHeight)) { if ($clone->resizeImage($targetWidth, $targetHeight, \Imagick::FILTER_CUBIC, 1.0) !== true) { //cumbersome to test throw new \Exception('Imagick::resizeImage() did not return true');//@codeCoverageIgnore } } //put image in box $canvas = new \Imagick(); if ($canvas->newImage($boxWidth, $boxHeight, $color) !== true) { //cumbersome to test throw new \Exception('Imagick::newImage() did not return true');//@codeCoverageIgnore } if ($canvas->compositeImage($clone, \Imagick::COMPOSITE_ATOP, $targetX, $targetY) !== true) { //cumbersome to test throw new \Exception('Imagick::compositeImage() did not return true');//@codeCoverageIgnore } //reason we are not supporting the options in self::write() here is because format, and strip headers are //only relevant once written Imagick::stripImage() doesnt even have an effect until written //also the user can just call that function with the resultant $canvas $results[$boxSizeKey] = $canvas; } return $results; }
php
public static function resizeMulti(\Imagick $source, array $boxSizes, array $options = []) : array { //algorithm inspired from http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html //use of 2x2 binning is arguably the best quality one will get downsizing and is what lots of hardware does in //the photography field, while being reasonably fast. Upsizing is more subjective but you can't get much //better than bicubic which is what is used here. $color = 'white'; if (isset($options['color'])) { $color = $options['color']; if (!is_string($color)) { throw new \InvalidArgumentException('$options["color"] was not a string'); } } $upsize = false; if (isset($options['upsize'])) { $upsize = $options['upsize']; if ($upsize !== true && $upsize !== false) { throw new \InvalidArgumentException('$options["upsize"] was not a bool'); } } $maxWidth = 10000; if (isset($options['maxWidth'])) { $maxWidth = $options['maxWidth']; if (!is_int($maxWidth)) { throw new \InvalidArgumentException('$options["maxWidth"] was not an int'); } } $maxHeight = 10000; if (isset($options['maxHeight'])) { $maxHeight = $options['maxHeight']; if (!is_int($maxHeight)) { throw new \InvalidArgumentException('$options["maxHeight"] was not an int'); } } foreach ($boxSizes as $boxSizeKey => $boxSize) { if (!isset($boxSize['width']) || !is_int($boxSize['width'])) { throw new \InvalidArgumentException('a width in a $boxSizes value was not an int'); } if (!isset($boxSize['height']) || !is_int($boxSize['height'])) { throw new \InvalidArgumentException('a height in a $boxSizes value was not an int'); } if ($boxSize['width'] > $maxWidth || $boxSize['width'] <= 0) { throw new \InvalidArgumentException('a $boxSizes width was not between 0 and $options["maxWidth"]'); } if ($boxSize['height'] > $maxHeight || $boxSize['height'] <= 0) { throw new \InvalidArgumentException('a $boxSizes height was not between 0 and $options["maxHeight"]'); } } $results = []; $cloneCache = []; foreach ($boxSizes as $boxSizeKey => $boxSize) { $boxWidth = $boxSize['width']; $boxHeight = $boxSize['height']; $clone = clone $source; $orientation = $clone->getImageOrientation(); switch ($orientation) { case \Imagick::ORIENTATION_BOTTOMRIGHT: $clone->rotateimage('#fff', 180); $clone->stripImage(); break; case \Imagick::ORIENTATION_RIGHTTOP: $clone->rotateimage('#fff', 90); $clone->stripImage(); break; case \Imagick::ORIENTATION_LEFTBOTTOM: $clone->rotateimage('#fff', -90); $clone->stripImage(); break; } $width = $clone->getImageWidth(); $height = $clone->getImageHeight(); //ratio over 1 is horizontal, under 1 is vertical $boxRatio = $boxWidth / $boxHeight; //height should be positive since I didnt find a way you could get zero into imagick $originalRatio = $width / $height; $targetWidth = null; $targetHeight = null; $targetX = null; $targetY = null; if ($width < $boxWidth && $height < $boxHeight && !$upsize) { $targetWidth = $width; $targetHeight = $height; $targetX = ($boxWidth - $width) / 2; $targetY = ($boxHeight - $height) / 2; } else { //if box is more vertical than original if ($boxRatio < $originalRatio) { $targetWidth = $boxWidth; $targetHeight = (int)((double)$boxWidth / $originalRatio); $targetX = 0; $targetY = ($boxHeight - $targetHeight) / 2; } else { $targetWidth = (int)((double)$boxHeight * $originalRatio); $targetHeight = $boxHeight; $targetX = ($boxWidth - $targetWidth) / 2; $targetY = 0; } } //do iterative downsize by halfs (2x2 binning is a common name) on dimensions that are bigger than target //width and height while (true) { $widthReduced = false; $widthIsHalf = false; if ($width > $targetWidth) { $width = (int)($width / 2); $widthReduced = true; $widthIsHalf = true; if ($width < $targetWidth) { $width = $targetWidth; $widthIsHalf = false; } } $heightReduced = false; $heightIsHalf = false; if ($height > $targetHeight) { $height = (int)($height / 2); $heightReduced = true; $heightIsHalf = true; if ($height < $targetHeight) { $height = $targetHeight; $heightIsHalf = false; } } if (!$widthReduced && !$heightReduced) { break; } $cacheKey = "{$width}x{$height}"; if (isset($cloneCache[$cacheKey])) { $clone = clone $cloneCache[$cacheKey]; continue; } if ($clone->resizeImage($width, $height, \Imagick::FILTER_BOX, 1.0) !== true) { //cumbersome to test throw new \Exception('Imagick::resizeImage() did not return true');//@codeCoverageIgnore } if ($widthIsHalf && $heightIsHalf) { $cloneCache[$cacheKey] = clone $clone; } } if ($upsize && ($width < $targetWidth || $height < $targetHeight)) { if ($clone->resizeImage($targetWidth, $targetHeight, \Imagick::FILTER_CUBIC, 1.0) !== true) { //cumbersome to test throw new \Exception('Imagick::resizeImage() did not return true');//@codeCoverageIgnore } } //put image in box $canvas = new \Imagick(); if ($canvas->newImage($boxWidth, $boxHeight, $color) !== true) { //cumbersome to test throw new \Exception('Imagick::newImage() did not return true');//@codeCoverageIgnore } if ($canvas->compositeImage($clone, \Imagick::COMPOSITE_ATOP, $targetX, $targetY) !== true) { //cumbersome to test throw new \Exception('Imagick::compositeImage() did not return true');//@codeCoverageIgnore } //reason we are not supporting the options in self::write() here is because format, and strip headers are //only relevant once written Imagick::stripImage() doesnt even have an effect until written //also the user can just call that function with the resultant $canvas $results[$boxSizeKey] = $canvas; } return $results; }
[ "public", "static", "function", "resizeMulti", "(", "\\", "Imagick", "$", "source", ",", "array", "$", "boxSizes", ",", "array", "$", "options", "=", "[", "]", ")", ":", "array", "{", "//algorithm inspired from http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html", "//use of 2x2 binning is arguably the best quality one will get downsizing and is what lots of hardware does in", "//the photography field, while being reasonably fast. Upsizing is more subjective but you can't get much", "//better than bicubic which is what is used here.", "$", "color", "=", "'white'", ";", "if", "(", "isset", "(", "$", "options", "[", "'color'", "]", ")", ")", "{", "$", "color", "=", "$", "options", "[", "'color'", "]", ";", "if", "(", "!", "is_string", "(", "$", "color", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$options[\"color\"] was not a string'", ")", ";", "}", "}", "$", "upsize", "=", "false", ";", "if", "(", "isset", "(", "$", "options", "[", "'upsize'", "]", ")", ")", "{", "$", "upsize", "=", "$", "options", "[", "'upsize'", "]", ";", "if", "(", "$", "upsize", "!==", "true", "&&", "$", "upsize", "!==", "false", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$options[\"upsize\"] was not a bool'", ")", ";", "}", "}", "$", "maxWidth", "=", "10000", ";", "if", "(", "isset", "(", "$", "options", "[", "'maxWidth'", "]", ")", ")", "{", "$", "maxWidth", "=", "$", "options", "[", "'maxWidth'", "]", ";", "if", "(", "!", "is_int", "(", "$", "maxWidth", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$options[\"maxWidth\"] was not an int'", ")", ";", "}", "}", "$", "maxHeight", "=", "10000", ";", "if", "(", "isset", "(", "$", "options", "[", "'maxHeight'", "]", ")", ")", "{", "$", "maxHeight", "=", "$", "options", "[", "'maxHeight'", "]", ";", "if", "(", "!", "is_int", "(", "$", "maxHeight", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$options[\"maxHeight\"] was not an int'", ")", ";", "}", "}", "foreach", "(", "$", "boxSizes", "as", "$", "boxSizeKey", "=>", "$", "boxSize", ")", "{", "if", "(", "!", "isset", "(", "$", "boxSize", "[", "'width'", "]", ")", "||", "!", "is_int", "(", "$", "boxSize", "[", "'width'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'a width in a $boxSizes value was not an int'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "boxSize", "[", "'height'", "]", ")", "||", "!", "is_int", "(", "$", "boxSize", "[", "'height'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'a height in a $boxSizes value was not an int'", ")", ";", "}", "if", "(", "$", "boxSize", "[", "'width'", "]", ">", "$", "maxWidth", "||", "$", "boxSize", "[", "'width'", "]", "<=", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'a $boxSizes width was not between 0 and $options[\"maxWidth\"]'", ")", ";", "}", "if", "(", "$", "boxSize", "[", "'height'", "]", ">", "$", "maxHeight", "||", "$", "boxSize", "[", "'height'", "]", "<=", "0", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'a $boxSizes height was not between 0 and $options[\"maxHeight\"]'", ")", ";", "}", "}", "$", "results", "=", "[", "]", ";", "$", "cloneCache", "=", "[", "]", ";", "foreach", "(", "$", "boxSizes", "as", "$", "boxSizeKey", "=>", "$", "boxSize", ")", "{", "$", "boxWidth", "=", "$", "boxSize", "[", "'width'", "]", ";", "$", "boxHeight", "=", "$", "boxSize", "[", "'height'", "]", ";", "$", "clone", "=", "clone", "$", "source", ";", "$", "orientation", "=", "$", "clone", "->", "getImageOrientation", "(", ")", ";", "switch", "(", "$", "orientation", ")", "{", "case", "\\", "Imagick", "::", "ORIENTATION_BOTTOMRIGHT", ":", "$", "clone", "->", "rotateimage", "(", "'#fff'", ",", "180", ")", ";", "$", "clone", "->", "stripImage", "(", ")", ";", "break", ";", "case", "\\", "Imagick", "::", "ORIENTATION_RIGHTTOP", ":", "$", "clone", "->", "rotateimage", "(", "'#fff'", ",", "90", ")", ";", "$", "clone", "->", "stripImage", "(", ")", ";", "break", ";", "case", "\\", "Imagick", "::", "ORIENTATION_LEFTBOTTOM", ":", "$", "clone", "->", "rotateimage", "(", "'#fff'", ",", "-", "90", ")", ";", "$", "clone", "->", "stripImage", "(", ")", ";", "break", ";", "}", "$", "width", "=", "$", "clone", "->", "getImageWidth", "(", ")", ";", "$", "height", "=", "$", "clone", "->", "getImageHeight", "(", ")", ";", "//ratio over 1 is horizontal, under 1 is vertical", "$", "boxRatio", "=", "$", "boxWidth", "/", "$", "boxHeight", ";", "//height should be positive since I didnt find a way you could get zero into imagick", "$", "originalRatio", "=", "$", "width", "/", "$", "height", ";", "$", "targetWidth", "=", "null", ";", "$", "targetHeight", "=", "null", ";", "$", "targetX", "=", "null", ";", "$", "targetY", "=", "null", ";", "if", "(", "$", "width", "<", "$", "boxWidth", "&&", "$", "height", "<", "$", "boxHeight", "&&", "!", "$", "upsize", ")", "{", "$", "targetWidth", "=", "$", "width", ";", "$", "targetHeight", "=", "$", "height", ";", "$", "targetX", "=", "(", "$", "boxWidth", "-", "$", "width", ")", "/", "2", ";", "$", "targetY", "=", "(", "$", "boxHeight", "-", "$", "height", ")", "/", "2", ";", "}", "else", "{", "//if box is more vertical than original", "if", "(", "$", "boxRatio", "<", "$", "originalRatio", ")", "{", "$", "targetWidth", "=", "$", "boxWidth", ";", "$", "targetHeight", "=", "(", "int", ")", "(", "(", "double", ")", "$", "boxWidth", "/", "$", "originalRatio", ")", ";", "$", "targetX", "=", "0", ";", "$", "targetY", "=", "(", "$", "boxHeight", "-", "$", "targetHeight", ")", "/", "2", ";", "}", "else", "{", "$", "targetWidth", "=", "(", "int", ")", "(", "(", "double", ")", "$", "boxHeight", "*", "$", "originalRatio", ")", ";", "$", "targetHeight", "=", "$", "boxHeight", ";", "$", "targetX", "=", "(", "$", "boxWidth", "-", "$", "targetWidth", ")", "/", "2", ";", "$", "targetY", "=", "0", ";", "}", "}", "//do iterative downsize by halfs (2x2 binning is a common name) on dimensions that are bigger than target", "//width and height", "while", "(", "true", ")", "{", "$", "widthReduced", "=", "false", ";", "$", "widthIsHalf", "=", "false", ";", "if", "(", "$", "width", ">", "$", "targetWidth", ")", "{", "$", "width", "=", "(", "int", ")", "(", "$", "width", "/", "2", ")", ";", "$", "widthReduced", "=", "true", ";", "$", "widthIsHalf", "=", "true", ";", "if", "(", "$", "width", "<", "$", "targetWidth", ")", "{", "$", "width", "=", "$", "targetWidth", ";", "$", "widthIsHalf", "=", "false", ";", "}", "}", "$", "heightReduced", "=", "false", ";", "$", "heightIsHalf", "=", "false", ";", "if", "(", "$", "height", ">", "$", "targetHeight", ")", "{", "$", "height", "=", "(", "int", ")", "(", "$", "height", "/", "2", ")", ";", "$", "heightReduced", "=", "true", ";", "$", "heightIsHalf", "=", "true", ";", "if", "(", "$", "height", "<", "$", "targetHeight", ")", "{", "$", "height", "=", "$", "targetHeight", ";", "$", "heightIsHalf", "=", "false", ";", "}", "}", "if", "(", "!", "$", "widthReduced", "&&", "!", "$", "heightReduced", ")", "{", "break", ";", "}", "$", "cacheKey", "=", "\"{$width}x{$height}\"", ";", "if", "(", "isset", "(", "$", "cloneCache", "[", "$", "cacheKey", "]", ")", ")", "{", "$", "clone", "=", "clone", "$", "cloneCache", "[", "$", "cacheKey", "]", ";", "continue", ";", "}", "if", "(", "$", "clone", "->", "resizeImage", "(", "$", "width", ",", "$", "height", ",", "\\", "Imagick", "::", "FILTER_BOX", ",", "1.0", ")", "!==", "true", ")", "{", "//cumbersome to test", "throw", "new", "\\", "Exception", "(", "'Imagick::resizeImage() did not return true'", ")", ";", "//@codeCoverageIgnore", "}", "if", "(", "$", "widthIsHalf", "&&", "$", "heightIsHalf", ")", "{", "$", "cloneCache", "[", "$", "cacheKey", "]", "=", "clone", "$", "clone", ";", "}", "}", "if", "(", "$", "upsize", "&&", "(", "$", "width", "<", "$", "targetWidth", "||", "$", "height", "<", "$", "targetHeight", ")", ")", "{", "if", "(", "$", "clone", "->", "resizeImage", "(", "$", "targetWidth", ",", "$", "targetHeight", ",", "\\", "Imagick", "::", "FILTER_CUBIC", ",", "1.0", ")", "!==", "true", ")", "{", "//cumbersome to test", "throw", "new", "\\", "Exception", "(", "'Imagick::resizeImage() did not return true'", ")", ";", "//@codeCoverageIgnore", "}", "}", "//put image in box", "$", "canvas", "=", "new", "\\", "Imagick", "(", ")", ";", "if", "(", "$", "canvas", "->", "newImage", "(", "$", "boxWidth", ",", "$", "boxHeight", ",", "$", "color", ")", "!==", "true", ")", "{", "//cumbersome to test", "throw", "new", "\\", "Exception", "(", "'Imagick::newImage() did not return true'", ")", ";", "//@codeCoverageIgnore", "}", "if", "(", "$", "canvas", "->", "compositeImage", "(", "$", "clone", ",", "\\", "Imagick", "::", "COMPOSITE_ATOP", ",", "$", "targetX", ",", "$", "targetY", ")", "!==", "true", ")", "{", "//cumbersome to test", "throw", "new", "\\", "Exception", "(", "'Imagick::compositeImage() did not return true'", ")", ";", "//@codeCoverageIgnore", "}", "//reason we are not supporting the options in self::write() here is because format, and strip headers are", "//only relevant once written Imagick::stripImage() doesnt even have an effect until written", "//also the user can just call that function with the resultant $canvas", "$", "results", "[", "$", "boxSizeKey", "]", "=", "$", "canvas", ";", "}", "return", "$", "results", ";", "}" ]
resizes images into a bounding box. Maintains aspect ratio, extra space filled with given color. @param \Imagick $source source image to resize. Will not modify @param array $boxSizes resulting bounding boxes. Each value should be an array with width and height, both integers @param array $options options string color (default white) background color. Any supported from http://www.imagemagick.org/script/color.php#color_names bool upsize (default false) true to upsize the original image or false to upsize just the bounding box int maxWidth (default 10000) max width allowed for $boxWidth int maxHeight (default 10000) max height allowed for $boxHeight @return array array of \Imagick objects resized. Keys maintained from $boxSizes @throws \InvalidArgumentException if $options["color"] was not a string @throws \InvalidArgumentException if $options["upsize"] was not a bool @throws \InvalidArgumentException if $options["maxWidth"] was not an int @throws \InvalidArgumentException if $options["maxHeight"] was not an int @throws \InvalidArgumentException if a width in a $boxSizes value was not an int @throws \InvalidArgumentException if a height in a $boxSizes value was not an int @throws \InvalidArgumentException if a $boxSizes width was not between 0 and $options["maxWidth"] @throws \InvalidArgumentException if a $boxSizes height was not between 0 and $options["maxHeight"] @throws \Exception
[ "resizes", "images", "into", "a", "bounding", "box", ".", "Maintains", "aspect", "ratio", "extra", "space", "filled", "with", "given", "color", "." ]
train
https://github.com/traderinteractive/image-util-php/blob/60595257ff8cb704e9a39384a0fc1232159d16dc/src/Image.php#L41-L226
traderinteractive/image-util-php
src/Image.php
Image.write
public static function write(\Imagick $source, string $destPath, array $options = []) { $format = 'jpeg'; if (array_key_exists('format', $options)) { $format = $options['format']; if (!is_string($format)) { throw new \InvalidArgumentException('$options["format"] was not a string'); } } $directoryMode = 0777; if (array_key_exists('directoryMode', $options)) { $directoryMode = $options['directoryMode']; if (!is_int($directoryMode)) { throw new \InvalidArgumentException('$options["directoryMode"] was not an int'); } } $fileMode = 0777; if (array_key_exists('fileMode', $options)) { $fileMode = $options['fileMode']; if (!is_int($fileMode)) { throw new \InvalidArgumentException('$options["fileMode"] was not an int'); } } $stripHeaders = true; if (array_key_exists('stripHeaders', $options)) { $stripHeaders = $options['stripHeaders']; if ($stripHeaders !== false && $stripHeaders !== true) { throw new \InvalidArgumentException('$options["stripHeaders"] was not a bool'); } } $destDir = dirname($destPath); if (!is_dir($destDir)) { $oldUmask = umask(0); if (!mkdir($destDir, $directoryMode, true)) { //cumbersome to test throw new \Exception('mkdir() returned false');//@codeCoverageIgnore } umask($oldUmask); } $clone = clone $source; if ($clone->setImageFormat($format) !== true) { //cumbersome to test throw new \Exception('Imagick::setImageFormat() did not return true');//@codeCoverageIgnore } if ($stripHeaders && $clone->stripImage() !== true) { //cumbersome to test throw new \Exception('Imagick::stripImage() did not return true');//@codeCoverageIgnore } if ($clone->writeImage($destPath) !== true) { //cumbersome to test throw new \Exception('Imagick::writeImage() did not return true');//@codeCoverageIgnore } if (!chmod($destPath, $fileMode)) { //cumbersome to test throw new \Exception('chmod() returned false');//@codeCoverageIgnore } }
php
public static function write(\Imagick $source, string $destPath, array $options = []) { $format = 'jpeg'; if (array_key_exists('format', $options)) { $format = $options['format']; if (!is_string($format)) { throw new \InvalidArgumentException('$options["format"] was not a string'); } } $directoryMode = 0777; if (array_key_exists('directoryMode', $options)) { $directoryMode = $options['directoryMode']; if (!is_int($directoryMode)) { throw new \InvalidArgumentException('$options["directoryMode"] was not an int'); } } $fileMode = 0777; if (array_key_exists('fileMode', $options)) { $fileMode = $options['fileMode']; if (!is_int($fileMode)) { throw new \InvalidArgumentException('$options["fileMode"] was not an int'); } } $stripHeaders = true; if (array_key_exists('stripHeaders', $options)) { $stripHeaders = $options['stripHeaders']; if ($stripHeaders !== false && $stripHeaders !== true) { throw new \InvalidArgumentException('$options["stripHeaders"] was not a bool'); } } $destDir = dirname($destPath); if (!is_dir($destDir)) { $oldUmask = umask(0); if (!mkdir($destDir, $directoryMode, true)) { //cumbersome to test throw new \Exception('mkdir() returned false');//@codeCoverageIgnore } umask($oldUmask); } $clone = clone $source; if ($clone->setImageFormat($format) !== true) { //cumbersome to test throw new \Exception('Imagick::setImageFormat() did not return true');//@codeCoverageIgnore } if ($stripHeaders && $clone->stripImage() !== true) { //cumbersome to test throw new \Exception('Imagick::stripImage() did not return true');//@codeCoverageIgnore } if ($clone->writeImage($destPath) !== true) { //cumbersome to test throw new \Exception('Imagick::writeImage() did not return true');//@codeCoverageIgnore } if (!chmod($destPath, $fileMode)) { //cumbersome to test throw new \Exception('chmod() returned false');//@codeCoverageIgnore } }
[ "public", "static", "function", "write", "(", "\\", "Imagick", "$", "source", ",", "string", "$", "destPath", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "format", "=", "'jpeg'", ";", "if", "(", "array_key_exists", "(", "'format'", ",", "$", "options", ")", ")", "{", "$", "format", "=", "$", "options", "[", "'format'", "]", ";", "if", "(", "!", "is_string", "(", "$", "format", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$options[\"format\"] was not a string'", ")", ";", "}", "}", "$", "directoryMode", "=", "0777", ";", "if", "(", "array_key_exists", "(", "'directoryMode'", ",", "$", "options", ")", ")", "{", "$", "directoryMode", "=", "$", "options", "[", "'directoryMode'", "]", ";", "if", "(", "!", "is_int", "(", "$", "directoryMode", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$options[\"directoryMode\"] was not an int'", ")", ";", "}", "}", "$", "fileMode", "=", "0777", ";", "if", "(", "array_key_exists", "(", "'fileMode'", ",", "$", "options", ")", ")", "{", "$", "fileMode", "=", "$", "options", "[", "'fileMode'", "]", ";", "if", "(", "!", "is_int", "(", "$", "fileMode", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$options[\"fileMode\"] was not an int'", ")", ";", "}", "}", "$", "stripHeaders", "=", "true", ";", "if", "(", "array_key_exists", "(", "'stripHeaders'", ",", "$", "options", ")", ")", "{", "$", "stripHeaders", "=", "$", "options", "[", "'stripHeaders'", "]", ";", "if", "(", "$", "stripHeaders", "!==", "false", "&&", "$", "stripHeaders", "!==", "true", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$options[\"stripHeaders\"] was not a bool'", ")", ";", "}", "}", "$", "destDir", "=", "dirname", "(", "$", "destPath", ")", ";", "if", "(", "!", "is_dir", "(", "$", "destDir", ")", ")", "{", "$", "oldUmask", "=", "umask", "(", "0", ")", ";", "if", "(", "!", "mkdir", "(", "$", "destDir", ",", "$", "directoryMode", ",", "true", ")", ")", "{", "//cumbersome to test", "throw", "new", "\\", "Exception", "(", "'mkdir() returned false'", ")", ";", "//@codeCoverageIgnore", "}", "umask", "(", "$", "oldUmask", ")", ";", "}", "$", "clone", "=", "clone", "$", "source", ";", "if", "(", "$", "clone", "->", "setImageFormat", "(", "$", "format", ")", "!==", "true", ")", "{", "//cumbersome to test", "throw", "new", "\\", "Exception", "(", "'Imagick::setImageFormat() did not return true'", ")", ";", "//@codeCoverageIgnore", "}", "if", "(", "$", "stripHeaders", "&&", "$", "clone", "->", "stripImage", "(", ")", "!==", "true", ")", "{", "//cumbersome to test", "throw", "new", "\\", "Exception", "(", "'Imagick::stripImage() did not return true'", ")", ";", "//@codeCoverageIgnore", "}", "if", "(", "$", "clone", "->", "writeImage", "(", "$", "destPath", ")", "!==", "true", ")", "{", "//cumbersome to test", "throw", "new", "\\", "Exception", "(", "'Imagick::writeImage() did not return true'", ")", ";", "//@codeCoverageIgnore", "}", "if", "(", "!", "chmod", "(", "$", "destPath", ",", "$", "fileMode", ")", ")", "{", "//cumbersome to test", "throw", "new", "\\", "Exception", "(", "'chmod() returned false'", ")", ";", "//@codeCoverageIgnore", "}", "}" ]
write $source to $destPath with $options applied @param \Imagick $source source image. Will not modify @param string $destPath destination image path @param array $options options string format (default jpeg) Any from http://www.imagemagick.org/script/formats.php#supported int directoryMode (default 0777) chmod mode for any parent directories created int fileMode (default 0777) chmod mode for the resized image file bool stripHeaders (default true) whether to strip headers (exif, etc). Is only reflected in $destPath, not returned clone @return void @throws \InvalidArgumentException if $destPath was not a string @throws \InvalidArgumentException if $options["format"] was not a string @throws \InvalidArgumentException if $options["directoryMode"] was not an int @throws \InvalidArgumentException if $options["fileMode"] was not an int @throws \InvalidArgumentException if $options["stripHeaders"] was not a bool @throws \Exception
[ "write", "$source", "to", "$destPath", "with", "$options", "applied" ]
train
https://github.com/traderinteractive/image-util-php/blob/60595257ff8cb704e9a39384a0fc1232159d16dc/src/Image.php#L249-L315
traderinteractive/image-util-php
src/Image.php
Image.stripHeaders
public static function stripHeaders(string $path) { $imagick = new \Imagick($path); if ($imagick->stripImage() !== true) { //cumbersome to test throw new \Exception('Imagick::stripImage() did not return true');//@codeCoverageIgnore } if ($imagick->writeImage($path) !== true) { //cumbersome to test throw new \Exception('Imagick::writeImage() did not return true');//@codeCoverageIgnore } }
php
public static function stripHeaders(string $path) { $imagick = new \Imagick($path); if ($imagick->stripImage() !== true) { //cumbersome to test throw new \Exception('Imagick::stripImage() did not return true');//@codeCoverageIgnore } if ($imagick->writeImage($path) !== true) { //cumbersome to test throw new \Exception('Imagick::writeImage() did not return true');//@codeCoverageIgnore } }
[ "public", "static", "function", "stripHeaders", "(", "string", "$", "path", ")", "{", "$", "imagick", "=", "new", "\\", "Imagick", "(", "$", "path", ")", ";", "if", "(", "$", "imagick", "->", "stripImage", "(", ")", "!==", "true", ")", "{", "//cumbersome to test", "throw", "new", "\\", "Exception", "(", "'Imagick::stripImage() did not return true'", ")", ";", "//@codeCoverageIgnore", "}", "if", "(", "$", "imagick", "->", "writeImage", "(", "$", "path", ")", "!==", "true", ")", "{", "//cumbersome to test", "throw", "new", "\\", "Exception", "(", "'Imagick::writeImage() did not return true'", ")", ";", "//@codeCoverageIgnore", "}", "}" ]
Strips the headers (exif, etc) from an image at the given path. @param string $path The image path. @return void @throws \InvalidArgumentException if $path is not a string @throws \Exception if there is a failure stripping the headers @throws \Exception if there is a failure writing the image back to path
[ "Strips", "the", "headers", "(", "exif", "etc", ")", "from", "an", "image", "at", "the", "given", "path", "." ]
train
https://github.com/traderinteractive/image-util-php/blob/60595257ff8cb704e9a39384a0fc1232159d16dc/src/Image.php#L326-L338
contao-community-alliance/url-builder
src/Contao/BackendUrlBuilder.php
BackendUrlBuilder.getQueryString
public function getQueryString() { $query = parent::getQueryString(); if ($query) { $query .= '&'; } if (!defined('REQUEST_TOKEN')) { throw new \RuntimeException('Request token not defined - can not append to query string.'); } $query .= 'rt=' . REQUEST_TOKEN; return $query; }
php
public function getQueryString() { $query = parent::getQueryString(); if ($query) { $query .= '&'; } if (!defined('REQUEST_TOKEN')) { throw new \RuntimeException('Request token not defined - can not append to query string.'); } $query .= 'rt=' . REQUEST_TOKEN; return $query; }
[ "public", "function", "getQueryString", "(", ")", "{", "$", "query", "=", "parent", "::", "getQueryString", "(", ")", ";", "if", "(", "$", "query", ")", "{", "$", "query", ".=", "'&'", ";", "}", "if", "(", "!", "defined", "(", "'REQUEST_TOKEN'", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Request token not defined - can not append to query string.'", ")", ";", "}", "$", "query", ".=", "'rt='", ".", "REQUEST_TOKEN", ";", "return", "$", "query", ";", "}" ]
Retrieve the serialized query string. @return string @throws \RuntimeException If no REQUEST_TOKEN constant exists.
[ "Retrieve", "the", "serialized", "query", "string", "." ]
train
https://github.com/contao-community-alliance/url-builder/blob/2d730649058f3d3af41175358ee92f0659de08a1/src/Contao/BackendUrlBuilder.php#L42-L56
Eresus/EresusCMS
src/core/FS/Tool.php
Eresus_FS_Tool.normalize
public static function normalize($path) { $path = self::expandParentLinks($path); $path = self::tidy($path); return $path; }
php
public static function normalize($path) { $path = self::expandParentLinks($path); $path = self::tidy($path); return $path; }
[ "public", "static", "function", "normalize", "(", "$", "path", ")", "{", "$", "path", "=", "self", "::", "expandParentLinks", "(", "$", "path", ")", ";", "$", "path", "=", "self", "::", "tidy", "(", "$", "path", ")", ";", "return", "$", "path", ";", "}" ]
Нормализует имя файла Вызывает последовательно {@link expandParentLinks()} и {@link tidy()}. @param string $path путь @return string @since 3.01
[ "Нормализует", "имя", "файла" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/FS/Tool.php#L48-L53
Eresus/EresusCMS
src/core/FS/Tool.php
Eresus_FS_Tool.expandParentLinks
public static function expandParentLinks($path) { if (strpos($path, '..') === false) { return $path; } if ($path) { $parts = explode('/', $path); for ($i = 0; $i < count($parts); $i++) { if ($parts[$i] == '..') { if ($i > 1) { array_splice($parts, $i-1, 2); $i -= 2; } else { array_splice($parts, $i, 1); $i -= 1; } } } $path = implode('/', $parts); } return $path; }
php
public static function expandParentLinks($path) { if (strpos($path, '..') === false) { return $path; } if ($path) { $parts = explode('/', $path); for ($i = 0; $i < count($parts); $i++) { if ($parts[$i] == '..') { if ($i > 1) { array_splice($parts, $i-1, 2); $i -= 2; } else { array_splice($parts, $i, 1); $i -= 1; } } } $path = implode('/', $parts); } return $path; }
[ "public", "static", "function", "expandParentLinks", "(", "$", "path", ")", "{", "if", "(", "strpos", "(", "$", "path", ",", "'..'", ")", "===", "false", ")", "{", "return", "$", "path", ";", "}", "if", "(", "$", "path", ")", "{", "$", "parts", "=", "explode", "(", "'/'", ",", "$", "path", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "parts", ")", ";", "$", "i", "++", ")", "{", "if", "(", "$", "parts", "[", "$", "i", "]", "==", "'..'", ")", "{", "if", "(", "$", "i", ">", "1", ")", "{", "array_splice", "(", "$", "parts", ",", "$", "i", "-", "1", ",", "2", ")", ";", "$", "i", "-=", "2", ";", "}", "else", "{", "array_splice", "(", "$", "parts", ",", "$", "i", ",", "1", ")", ";", "$", "i", "-=", "1", ";", "}", "}", "}", "$", "path", "=", "implode", "(", "'/'", ",", "$", "parts", ")", ";", "}", "return", "$", "path", ";", "}" ]
Раскрывает ссылки на родительские папки ('..') @param string $path @return string @since 3.01
[ "Раскрывает", "ссылки", "на", "родительские", "папки", "(", "..", ")" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/FS/Tool.php#L62-L91
Eresus/EresusCMS
src/core/FS/Tool.php
Eresus_FS_Tool.tidy
public static function tidy($path) { $path = preg_replace('~/{2,}~', '/', $path); $path = str_replace('/./', '/', $path); $path = preg_replace('~^./~', '', $path); $path = rtrim($path, '/'); return $path; }
php
public static function tidy($path) { $path = preg_replace('~/{2,}~', '/', $path); $path = str_replace('/./', '/', $path); $path = preg_replace('~^./~', '', $path); $path = rtrim($path, '/'); return $path; }
[ "public", "static", "function", "tidy", "(", "$", "path", ")", "{", "$", "path", "=", "preg_replace", "(", "'~/{2,}~'", ",", "'/'", ",", "$", "path", ")", ";", "$", "path", "=", "str_replace", "(", "'/./'", ",", "'/'", ",", "$", "path", ")", ";", "$", "path", "=", "preg_replace", "(", "'~^./~'", ",", "''", ",", "$", "path", ")", ";", "$", "path", "=", "rtrim", "(", "$", "path", ",", "'/'", ")", ";", "return", "$", "path", ";", "}" ]
Исправляет некоторые ошибки в пути 1. Заменяет несколько идущих подряд слэшей одним 2. Заменяет "/./" на "/" 3. Удаляет финальный слэш "/" @param string $path @return string @since 3.01
[ "Исправляет", "некоторые", "ошибки", "в", "пути" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/FS/Tool.php#L104-L111
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_delete.php
ezcQueryDelete.deleteFrom
public function deleteFrom( $table ) { $table = $this->getPrefixedTableNames($table); $this->table = $table; return $this; }
php
public function deleteFrom( $table ) { $table = $this->getPrefixedTableNames($table); $this->table = $table; return $this; }
[ "public", "function", "deleteFrom", "(", "$", "table", ")", "{", "$", "table", "=", "$", "this", "->", "getPrefixedTableNames", "(", "$", "table", ")", ";", "$", "this", "->", "table", "=", "$", "table", ";", "return", "$", "this", ";", "}" ]
Opens the query and sets the target table to $table. deleteFrom() returns a pointer to $this. @param string $table @return ezcQueryDelete
[ "Opens", "the", "query", "and", "sets", "the", "target", "table", "to", "$table", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_delete.php#L76-L81
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_delete.php
ezcQueryDelete.where
public function where() { if ( $this->whereString == null ) { $this->whereString = 'WHERE '; } $args = func_get_args(); $expressions = self::arrayFlatten( $args ); if ( count( $expressions ) < 1 ) { throw new ezcQueryVariableParameterException( 'where', count( $args ), 1 ); } // glue string should be inserted each time but not before first entry if ( $this->whereString != 'WHERE ' ) { $this->whereString .= ' AND '; } $this->whereString .= join( ' AND ', $expressions ); return $this; }
php
public function where() { if ( $this->whereString == null ) { $this->whereString = 'WHERE '; } $args = func_get_args(); $expressions = self::arrayFlatten( $args ); if ( count( $expressions ) < 1 ) { throw new ezcQueryVariableParameterException( 'where', count( $args ), 1 ); } // glue string should be inserted each time but not before first entry if ( $this->whereString != 'WHERE ' ) { $this->whereString .= ' AND '; } $this->whereString .= join( ' AND ', $expressions ); return $this; }
[ "public", "function", "where", "(", ")", "{", "if", "(", "$", "this", "->", "whereString", "==", "null", ")", "{", "$", "this", "->", "whereString", "=", "'WHERE '", ";", "}", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "expressions", "=", "self", "::", "arrayFlatten", "(", "$", "args", ")", ";", "if", "(", "count", "(", "$", "expressions", ")", "<", "1", ")", "{", "throw", "new", "ezcQueryVariableParameterException", "(", "'where'", ",", "count", "(", "$", "args", ")", ",", "1", ")", ";", "}", "// glue string should be inserted each time but not before first entry", "if", "(", "$", "this", "->", "whereString", "!=", "'WHERE '", ")", "{", "$", "this", "->", "whereString", ".=", "' AND '", ";", "}", "$", "this", "->", "whereString", ".=", "join", "(", "' AND '", ",", "$", "expressions", ")", ";", "return", "$", "this", ";", "}" ]
Adds a where clause with logical expressions to the query. where() accepts an arbitrary number of parameters. Each parameter must contain a logical expression or an array with logical expressions. where() could be invoked several times. All provided arguments added to the end of $whereString and form final WHERE clause of the query. If you specify multiple logical expression they are connected using a logical and. Example: <code> $q->deleteFrom( 'MyTable' )->where( $q->eq( 'id', 1 ) ); </code> @throws ezcQueryVaraibleParameterException if called with no parameters. @param string|array(string) $... Either a string with a logical expression name or an array with logical expressions. @return ezcQueryDelete
[ "Adds", "a", "where", "clause", "with", "logical", "expressions", "to", "the", "query", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_delete.php#L103-L125
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_delete.php
ezcQueryDelete.getQuery
public function getQuery() { if ( $this->table == null ) { throw new ezcQueryInvalidException( "DELETE", "deleteFrom() was not called before getQuery()." ); } $query = "DELETE FROM {$this->table}"; // append where part. if ( $this->whereString !== null ) { $query .= " {$this->whereString}"; } return $query; }
php
public function getQuery() { if ( $this->table == null ) { throw new ezcQueryInvalidException( "DELETE", "deleteFrom() was not called before getQuery()." ); } $query = "DELETE FROM {$this->table}"; // append where part. if ( $this->whereString !== null ) { $query .= " {$this->whereString}"; } return $query; }
[ "public", "function", "getQuery", "(", ")", "{", "if", "(", "$", "this", "->", "table", "==", "null", ")", "{", "throw", "new", "ezcQueryInvalidException", "(", "\"DELETE\"", ",", "\"deleteFrom() was not called before getQuery().\"", ")", ";", "}", "$", "query", "=", "\"DELETE FROM {$this->table}\"", ";", "// append where part.", "if", "(", "$", "this", "->", "whereString", "!==", "null", ")", "{", "$", "query", ".=", "\" {$this->whereString}\"", ";", "}", "return", "$", "query", ";", "}" ]
Returns the query string for this query object. @todo wrong exception @throws ezcQueryInvalidException if no table or no values have been set. @return string
[ "Returns", "the", "query", "string", "for", "this", "query", "object", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_delete.php#L135-L150
jnaxo/country-codes
database/seeds/WorldZonesSeeder.php
WorldZonesSeeder.run
public function run() { DB::table('ctrystore_zones')->delete(); $today = date('Y-m-d H:i:s'); $zones = [ 1 => 'europe', 2 => 'near east', 3 => 'caribbean', 4 => 'sub-saharan africa', 5 => 'antartica', 6 => 'latam', 7 => 'oceania', 8 => 'south asia', 9 => 'far east', 10 => 'atlantic ocean', 11 => 'north america', 12 => 'maghreb', 13 => 'greenland', 14 => 'indian ocean', 15 => 'southeast asia', 16 => 'north africa' ]; foreach ($zones as $i => $zone ) { DB::table('ctrystore_zones')->insert([ 'id' => $i, 'name' => $zone, 'created_at' => $today, 'updated_at' => $today, ]); } }
php
public function run() { DB::table('ctrystore_zones')->delete(); $today = date('Y-m-d H:i:s'); $zones = [ 1 => 'europe', 2 => 'near east', 3 => 'caribbean', 4 => 'sub-saharan africa', 5 => 'antartica', 6 => 'latam', 7 => 'oceania', 8 => 'south asia', 9 => 'far east', 10 => 'atlantic ocean', 11 => 'north america', 12 => 'maghreb', 13 => 'greenland', 14 => 'indian ocean', 15 => 'southeast asia', 16 => 'north africa' ]; foreach ($zones as $i => $zone ) { DB::table('ctrystore_zones')->insert([ 'id' => $i, 'name' => $zone, 'created_at' => $today, 'updated_at' => $today, ]); } }
[ "public", "function", "run", "(", ")", "{", "DB", "::", "table", "(", "'ctrystore_zones'", ")", "->", "delete", "(", ")", ";", "$", "today", "=", "date", "(", "'Y-m-d H:i:s'", ")", ";", "$", "zones", "=", "[", "1", "=>", "'europe'", ",", "2", "=>", "'near east'", ",", "3", "=>", "'caribbean'", ",", "4", "=>", "'sub-saharan africa'", ",", "5", "=>", "'antartica'", ",", "6", "=>", "'latam'", ",", "7", "=>", "'oceania'", ",", "8", "=>", "'south asia'", ",", "9", "=>", "'far east'", ",", "10", "=>", "'atlantic ocean'", ",", "11", "=>", "'north america'", ",", "12", "=>", "'maghreb'", ",", "13", "=>", "'greenland'", ",", "14", "=>", "'indian ocean'", ",", "15", "=>", "'southeast asia'", ",", "16", "=>", "'north africa'", "]", ";", "foreach", "(", "$", "zones", "as", "$", "i", "=>", "$", "zone", ")", "{", "DB", "::", "table", "(", "'ctrystore_zones'", ")", "->", "insert", "(", "[", "'id'", "=>", "$", "i", ",", "'name'", "=>", "$", "zone", ",", "'created_at'", "=>", "$", "today", ",", "'updated_at'", "=>", "$", "today", ",", "]", ")", ";", "}", "}" ]
Run the database seeds. @return void
[ "Run", "the", "database", "seeds", "." ]
train
https://github.com/jnaxo/country-codes/blob/ab1f24886e1b49eef5fd4b4eb4fb37aa7faeacd9/database/seeds/WorldZonesSeeder.php#L12-L45
zicht/z
src/Zicht/Tool/Container/Traverser.php
Traverser.addVisitor
public function addVisitor($callable, $condition, $when = self::BEFORE) { $this->visitors[] = array($when, $condition, $callable); return $this; }
php
public function addVisitor($callable, $condition, $when = self::BEFORE) { $this->visitors[] = array($when, $condition, $callable); return $this; }
[ "public", "function", "addVisitor", "(", "$", "callable", ",", "$", "condition", ",", "$", "when", "=", "self", "::", "BEFORE", ")", "{", "$", "this", "->", "visitors", "[", "]", "=", "array", "(", "$", "when", ",", "$", "condition", ",", "$", "callable", ")", ";", "return", "$", "this", ";", "}" ]
Add a visitor to the traverser. The node being visited is passed to the second callback to determine whether the first callback should be called with the node. The arguments passed to both callbacks are the current node and the path to the node. The result of the first callback is used to replace the node in the tree. Example: <code> $traverser->addVisitor( function($path, $node) { $node['i was visited'] = true; return $node; }, function($path, $node) { return count($path) == 3 && $path[0] == 'foo' && $path[2] == 'bar'; } ); $traverser->traverse( array( 'foo' => array( array( 'bar' => array('i should be visited' => true), 'baz' => array('i should not be visited' => true) ) ) ) ); </code> @param callable $callable @param callable $condition @param int $when @return self
[ "Add", "a", "visitor", "to", "the", "traverser", ".", "The", "node", "being", "visited", "is", "passed", "to", "the", "second", "callback", "to", "determine", "whether", "the", "first", "callback", "should", "be", "called", "with", "the", "node", ".", "The", "arguments", "passed", "to", "both", "callbacks", "are", "the", "current", "node", "and", "the", "path", "to", "the", "node", ".", "The", "result", "of", "the", "first", "callback", "is", "used", "to", "replace", "the", "node", "in", "the", "tree", "." ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/Traverser.php#L86-L91
zicht/z
src/Zicht/Tool/Container/Traverser.php
Traverser.doTraverse
private function doTraverse($node, $path = array()) { foreach ($node as $name => $value) { $path[] = $name; $value = $this->doVisit($path, $value, self::BEFORE); if (is_array($value)) { $value = $this->doTraverse($value, $path); } $value = $this->doVisit($path, $value, self::AFTER); $node[$name] = $value; array_pop($path); } return $node; }
php
private function doTraverse($node, $path = array()) { foreach ($node as $name => $value) { $path[] = $name; $value = $this->doVisit($path, $value, self::BEFORE); if (is_array($value)) { $value = $this->doTraverse($value, $path); } $value = $this->doVisit($path, $value, self::AFTER); $node[$name] = $value; array_pop($path); } return $node; }
[ "private", "function", "doTraverse", "(", "$", "node", ",", "$", "path", "=", "array", "(", ")", ")", "{", "foreach", "(", "$", "node", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "path", "[", "]", "=", "$", "name", ";", "$", "value", "=", "$", "this", "->", "doVisit", "(", "$", "path", ",", "$", "value", ",", "self", "::", "BEFORE", ")", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "$", "this", "->", "doTraverse", "(", "$", "value", ",", "$", "path", ")", ";", "}", "$", "value", "=", "$", "this", "->", "doVisit", "(", "$", "path", ",", "$", "value", ",", "self", "::", "AFTER", ")", ";", "$", "node", "[", "$", "name", "]", "=", "$", "value", ";", "array_pop", "(", "$", "path", ")", ";", "}", "return", "$", "node", ";", "}" ]
Recursive traversal implementation @param mixed $node @param array $path @return mixed
[ "Recursive", "traversal", "implementation" ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/Traverser.php#L112-L128
zicht/z
src/Zicht/Tool/Container/Traverser.php
Traverser.doVisit
private function doVisit($path, $value, $when) { foreach ($this->visitors as $visitor) { if ($visitor[0] === $when && call_user_func($visitor[1], $path, $value)) { try { $value = call_user_func($visitor[2], $path, $value); } catch (\Exception $e) { if ($path) { $path = join('.', $path); } $path = json_encode($path); $value = json_encode($value); throw new \RuntimeException("While visiting value '{$value}' at path {$path}", 0, $e); } } } return $value; }
php
private function doVisit($path, $value, $when) { foreach ($this->visitors as $visitor) { if ($visitor[0] === $when && call_user_func($visitor[1], $path, $value)) { try { $value = call_user_func($visitor[2], $path, $value); } catch (\Exception $e) { if ($path) { $path = join('.', $path); } $path = json_encode($path); $value = json_encode($value); throw new \RuntimeException("While visiting value '{$value}' at path {$path}", 0, $e); } } } return $value; }
[ "private", "function", "doVisit", "(", "$", "path", ",", "$", "value", ",", "$", "when", ")", "{", "foreach", "(", "$", "this", "->", "visitors", "as", "$", "visitor", ")", "{", "if", "(", "$", "visitor", "[", "0", "]", "===", "$", "when", "&&", "call_user_func", "(", "$", "visitor", "[", "1", "]", ",", "$", "path", ",", "$", "value", ")", ")", "{", "try", "{", "$", "value", "=", "call_user_func", "(", "$", "visitor", "[", "2", "]", ",", "$", "path", ",", "$", "value", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "$", "path", ")", "{", "$", "path", "=", "join", "(", "'.'", ",", "$", "path", ")", ";", "}", "$", "path", "=", "json_encode", "(", "$", "path", ")", ";", "$", "value", "=", "json_encode", "(", "$", "value", ")", ";", "throw", "new", "\\", "RuntimeException", "(", "\"While visiting value '{$value}' at path {$path}\"", ",", "0", ",", "$", "e", ")", ";", "}", "}", "}", "return", "$", "value", ";", "}" ]
Visits the node with all visitors at the specified time. @param array $path @param mixed $value @param int $when @return mixed @throws \RuntimeException
[ "Visits", "the", "node", "with", "all", "visitors", "at", "the", "specified", "time", "." ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Container/Traverser.php#L141-L158
thienhungho/yii2-product-management
src/modules/ProductManage/search/ProductSearch.php
ProductSearch.search
public function search($params) { $query = Product::find(); $this->load($params); $query->andFilterWhere([ 'id' => $this->id, 'author' => $this->author, 'quantity' => $this->quantity, 'promotional_price' => $this->promotional_price, 'price' => $this->price, 'product_parent' => $this->product_parent, 'assign_with' => $this->assign_with, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, ]); $query->andFilterWhere(['like', 'title', $this->title]) ->andFilterWhere(['like', 'slug', $this->slug]) ->andFilterWhere(['like', 'description', $this->description]) ->andFilterWhere(['like', 'content', $this->content]) ->andFilterWhere(['like', 'feature_img', $this->feature_img]) ->andFilterWhere(['like', 'sku', $this->sku]) ->andFilterWhere(['like', 'status', $this->status]) ->andFilterWhere(['like', 'comment_status', $this->comment_status]) ->andFilterWhere(['like', 'rating_status', $this->rating_status]) ->andFilterWhere(['like', 'unit', $this->unit]) ->andFilterWhere(['like', 'gallery', $this->gallery]) ->andFilterWhere(['like', 'product_type', $this->product_type]) ->andFilterWhere(['like', 'language', $this->language]); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); if (!$this->validate()) { return $dataProvider; } return $dataProvider; }
php
public function search($params) { $query = Product::find(); $this->load($params); $query->andFilterWhere([ 'id' => $this->id, 'author' => $this->author, 'quantity' => $this->quantity, 'promotional_price' => $this->promotional_price, 'price' => $this->price, 'product_parent' => $this->product_parent, 'assign_with' => $this->assign_with, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, ]); $query->andFilterWhere(['like', 'title', $this->title]) ->andFilterWhere(['like', 'slug', $this->slug]) ->andFilterWhere(['like', 'description', $this->description]) ->andFilterWhere(['like', 'content', $this->content]) ->andFilterWhere(['like', 'feature_img', $this->feature_img]) ->andFilterWhere(['like', 'sku', $this->sku]) ->andFilterWhere(['like', 'status', $this->status]) ->andFilterWhere(['like', 'comment_status', $this->comment_status]) ->andFilterWhere(['like', 'rating_status', $this->rating_status]) ->andFilterWhere(['like', 'unit', $this->unit]) ->andFilterWhere(['like', 'gallery', $this->gallery]) ->andFilterWhere(['like', 'product_type', $this->product_type]) ->andFilterWhere(['like', 'language', $this->language]); $dataProvider = new ActiveDataProvider([ 'query' => $query, ]); if (!$this->validate()) { return $dataProvider; } return $dataProvider; }
[ "public", "function", "search", "(", "$", "params", ")", "{", "$", "query", "=", "Product", "::", "find", "(", ")", ";", "$", "this", "->", "load", "(", "$", "params", ")", ";", "$", "query", "->", "andFilterWhere", "(", "[", "'id'", "=>", "$", "this", "->", "id", ",", "'author'", "=>", "$", "this", "->", "author", ",", "'quantity'", "=>", "$", "this", "->", "quantity", ",", "'promotional_price'", "=>", "$", "this", "->", "promotional_price", ",", "'price'", "=>", "$", "this", "->", "price", ",", "'product_parent'", "=>", "$", "this", "->", "product_parent", ",", "'assign_with'", "=>", "$", "this", "->", "assign_with", ",", "'created_at'", "=>", "$", "this", "->", "created_at", ",", "'updated_at'", "=>", "$", "this", "->", "updated_at", ",", "'created_by'", "=>", "$", "this", "->", "created_by", ",", "'updated_by'", "=>", "$", "this", "->", "updated_by", ",", "]", ")", ";", "$", "query", "->", "andFilterWhere", "(", "[", "'like'", ",", "'title'", ",", "$", "this", "->", "title", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'slug'", ",", "$", "this", "->", "slug", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'description'", ",", "$", "this", "->", "description", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'content'", ",", "$", "this", "->", "content", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'feature_img'", ",", "$", "this", "->", "feature_img", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'sku'", ",", "$", "this", "->", "sku", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'status'", ",", "$", "this", "->", "status", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'comment_status'", ",", "$", "this", "->", "comment_status", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'rating_status'", ",", "$", "this", "->", "rating_status", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'unit'", ",", "$", "this", "->", "unit", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'gallery'", ",", "$", "this", "->", "gallery", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'product_type'", ",", "$", "this", "->", "product_type", "]", ")", "->", "andFilterWhere", "(", "[", "'like'", ",", "'language'", ",", "$", "this", "->", "language", "]", ")", ";", "$", "dataProvider", "=", "new", "ActiveDataProvider", "(", "[", "'query'", "=>", "$", "query", ",", "]", ")", ";", "if", "(", "!", "$", "this", "->", "validate", "(", ")", ")", "{", "return", "$", "dataProvider", ";", "}", "return", "$", "dataProvider", ";", "}" ]
Creates data provider instance with search query applied @param array $params @return ActiveDataProvider
[ "Creates", "data", "provider", "instance", "with", "search", "query", "applied" ]
train
https://github.com/thienhungho/yii2-product-management/blob/72e1237bba123faf671e44491bd93077b50adde9/src/modules/ProductManage/search/ProductSearch.php#L38-L81
hametuha/wpametu
src/WPametu/API/Ajax/AjaxPostSearch.php
AjaxPostSearch.get_data
protected function get_data() { $post_type = $this->input->get('post_type'); if( !post_type_exists($post_type) ){ $this->error(sprintf($this->__('Post type %s does not exist.'), $post_type), 404); } if( !current_user_can('edit_posts') ){ $this->error($this->__('Sorry, but you have no permission.'), 403); } $paged = max(intval($this->input->get('paged')), 1) - 1; $args = [ 'post_type' => $post_type, 'suppress_filters' => false, 'orderby' => 'title', 'order' => 'ASC', 'offset' => $paged * get_option('posts_per_page'), 's' => $this->input->get('s'), ]; if( $this->is_public_search ){ // This is public search. $args = array_merge($args, [ 'post_status' => ['publish'] ]); }else{ // This is private search. $args = array_merge($args, [ 'post_status' => ['publish', 'draft', 'future'], ]); if( !current_user_can('edit_others_posts') ){ $args['author'] = get_current_user_id(); } } $data = []; foreach( get_posts($args) as $post){ $data[] = [ 'id' => $post->ID, 'name' => get_the_title($post), ]; } return $data; }
php
protected function get_data() { $post_type = $this->input->get('post_type'); if( !post_type_exists($post_type) ){ $this->error(sprintf($this->__('Post type %s does not exist.'), $post_type), 404); } if( !current_user_can('edit_posts') ){ $this->error($this->__('Sorry, but you have no permission.'), 403); } $paged = max(intval($this->input->get('paged')), 1) - 1; $args = [ 'post_type' => $post_type, 'suppress_filters' => false, 'orderby' => 'title', 'order' => 'ASC', 'offset' => $paged * get_option('posts_per_page'), 's' => $this->input->get('s'), ]; if( $this->is_public_search ){ // This is public search. $args = array_merge($args, [ 'post_status' => ['publish'] ]); }else{ // This is private search. $args = array_merge($args, [ 'post_status' => ['publish', 'draft', 'future'], ]); if( !current_user_can('edit_others_posts') ){ $args['author'] = get_current_user_id(); } } $data = []; foreach( get_posts($args) as $post){ $data[] = [ 'id' => $post->ID, 'name' => get_the_title($post), ]; } return $data; }
[ "protected", "function", "get_data", "(", ")", "{", "$", "post_type", "=", "$", "this", "->", "input", "->", "get", "(", "'post_type'", ")", ";", "if", "(", "!", "post_type_exists", "(", "$", "post_type", ")", ")", "{", "$", "this", "->", "error", "(", "sprintf", "(", "$", "this", "->", "__", "(", "'Post type %s does not exist.'", ")", ",", "$", "post_type", ")", ",", "404", ")", ";", "}", "if", "(", "!", "current_user_can", "(", "'edit_posts'", ")", ")", "{", "$", "this", "->", "error", "(", "$", "this", "->", "__", "(", "'Sorry, but you have no permission.'", ")", ",", "403", ")", ";", "}", "$", "paged", "=", "max", "(", "intval", "(", "$", "this", "->", "input", "->", "get", "(", "'paged'", ")", ")", ",", "1", ")", "-", "1", ";", "$", "args", "=", "[", "'post_type'", "=>", "$", "post_type", ",", "'suppress_filters'", "=>", "false", ",", "'orderby'", "=>", "'title'", ",", "'order'", "=>", "'ASC'", ",", "'offset'", "=>", "$", "paged", "*", "get_option", "(", "'posts_per_page'", ")", ",", "'s'", "=>", "$", "this", "->", "input", "->", "get", "(", "'s'", ")", ",", "]", ";", "if", "(", "$", "this", "->", "is_public_search", ")", "{", "// This is public search.", "$", "args", "=", "array_merge", "(", "$", "args", ",", "[", "'post_status'", "=>", "[", "'publish'", "]", "]", ")", ";", "}", "else", "{", "// This is private search.", "$", "args", "=", "array_merge", "(", "$", "args", ",", "[", "'post_status'", "=>", "[", "'publish'", ",", "'draft'", ",", "'future'", "]", ",", "]", ")", ";", "if", "(", "!", "current_user_can", "(", "'edit_others_posts'", ")", ")", "{", "$", "args", "[", "'author'", "]", "=", "get_current_user_id", "(", ")", ";", "}", "}", "$", "data", "=", "[", "]", ";", "foreach", "(", "get_posts", "(", "$", "args", ")", "as", "$", "post", ")", "{", "$", "data", "[", "]", "=", "[", "'id'", "=>", "$", "post", "->", "ID", ",", "'name'", "=>", "get_the_title", "(", "$", "post", ")", ",", "]", ";", "}", "return", "$", "data", ";", "}" ]
Returns data as array. @return array
[ "Returns", "data", "as", "array", "." ]
train
https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/API/Ajax/AjaxPostSearch.php#L29-L69
php-lug/lug
src/Bundle/GridBundle/Renderer/Renderer.php
Renderer.renderColumn
public function renderColumn(GridViewInterface $grid, ColumnInterface $column, $data) { return $this->doRender($grid, 'column', [ 'column' => $column, 'data' => $data, 'value' => $this->columnRenderer->render($grid, $column, $data), ]); }
php
public function renderColumn(GridViewInterface $grid, ColumnInterface $column, $data) { return $this->doRender($grid, 'column', [ 'column' => $column, 'data' => $data, 'value' => $this->columnRenderer->render($grid, $column, $data), ]); }
[ "public", "function", "renderColumn", "(", "GridViewInterface", "$", "grid", ",", "ColumnInterface", "$", "column", ",", "$", "data", ")", "{", "return", "$", "this", "->", "doRender", "(", "$", "grid", ",", "'column'", ",", "[", "'column'", "=>", "$", "column", ",", "'data'", "=>", "$", "data", ",", "'value'", "=>", "$", "this", "->", "columnRenderer", "->", "render", "(", "$", "grid", ",", "$", "column", ",", "$", "data", ")", ",", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Renderer/Renderer.php#L101-L108
php-lug/lug
src/Bundle/GridBundle/Renderer/Renderer.php
Renderer.renderColumnSorting
public function renderColumnSorting(GridViewInterface $grid, ColumnInterface $column, $sorting) { return $this->doRender($grid, 'column_sorting', [ 'column' => $column, 'sorting' => $sorting, 'label' => 'lug.sorting.'.strtolower($sorting), 'value' => $this->sorterRenderer->render($grid, $column, $sorting), ]); }
php
public function renderColumnSorting(GridViewInterface $grid, ColumnInterface $column, $sorting) { return $this->doRender($grid, 'column_sorting', [ 'column' => $column, 'sorting' => $sorting, 'label' => 'lug.sorting.'.strtolower($sorting), 'value' => $this->sorterRenderer->render($grid, $column, $sorting), ]); }
[ "public", "function", "renderColumnSorting", "(", "GridViewInterface", "$", "grid", ",", "ColumnInterface", "$", "column", ",", "$", "sorting", ")", "{", "return", "$", "this", "->", "doRender", "(", "$", "grid", ",", "'column_sorting'", ",", "[", "'column'", "=>", "$", "column", ",", "'sorting'", "=>", "$", "sorting", ",", "'label'", "=>", "'lug.sorting.'", ".", "strtolower", "(", "$", "sorting", ")", ",", "'value'", "=>", "$", "this", "->", "sorterRenderer", "->", "render", "(", "$", "grid", ",", "$", "column", ",", "$", "sorting", ")", ",", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Renderer/Renderer.php#L121-L129
php-lug/lug
src/Bundle/GridBundle/Renderer/Renderer.php
Renderer.renderColumnAction
public function renderColumnAction(GridViewInterface $grid, ActionInterface $action, $data) { return $this->doRender($grid, 'column_action', [ 'action' => $action, 'data' => $data, 'value' => $this->actionRenderer->render($grid, $action, $data), ]); }
php
public function renderColumnAction(GridViewInterface $grid, ActionInterface $action, $data) { return $this->doRender($grid, 'column_action', [ 'action' => $action, 'data' => $data, 'value' => $this->actionRenderer->render($grid, $action, $data), ]); }
[ "public", "function", "renderColumnAction", "(", "GridViewInterface", "$", "grid", ",", "ActionInterface", "$", "action", ",", "$", "data", ")", "{", "return", "$", "this", "->", "doRender", "(", "$", "grid", ",", "'column_action'", ",", "[", "'action'", "=>", "$", "action", ",", "'data'", "=>", "$", "data", ",", "'value'", "=>", "$", "this", "->", "actionRenderer", "->", "render", "(", "$", "grid", ",", "$", "action", ",", "$", "data", ")", ",", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Renderer/Renderer.php#L142-L149
php-lug/lug
src/Bundle/GridBundle/Renderer/Renderer.php
Renderer.renderGlobalAction
public function renderGlobalAction(GridViewInterface $grid, ActionInterface $action) { return $this->doRender($grid, 'global_action', [ 'action' => $action, 'value' => $this->actionRenderer->render($grid, $action, null), ]); }
php
public function renderGlobalAction(GridViewInterface $grid, ActionInterface $action) { return $this->doRender($grid, 'global_action', [ 'action' => $action, 'value' => $this->actionRenderer->render($grid, $action, null), ]); }
[ "public", "function", "renderGlobalAction", "(", "GridViewInterface", "$", "grid", ",", "ActionInterface", "$", "action", ")", "{", "return", "$", "this", "->", "doRender", "(", "$", "grid", ",", "'global_action'", ",", "[", "'action'", "=>", "$", "action", ",", "'value'", "=>", "$", "this", "->", "actionRenderer", "->", "render", "(", "$", "grid", ",", "$", "action", ",", "null", ")", ",", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Renderer/Renderer.php#L162-L168
php-lug/lug
src/Bundle/GridBundle/Renderer/Renderer.php
Renderer.doRender
private function doRender(GridViewInterface $grid, $template, array $context = []) { $context['grid'] = $grid; return $this->twig->render($this->resolveTemplate($grid->getDefinition(), $template), $context); }
php
private function doRender(GridViewInterface $grid, $template, array $context = []) { $context['grid'] = $grid; return $this->twig->render($this->resolveTemplate($grid->getDefinition(), $template), $context); }
[ "private", "function", "doRender", "(", "GridViewInterface", "$", "grid", ",", "$", "template", ",", "array", "$", "context", "=", "[", "]", ")", "{", "$", "context", "[", "'grid'", "]", "=", "$", "grid", ";", "return", "$", "this", "->", "twig", "->", "render", "(", "$", "this", "->", "resolveTemplate", "(", "$", "grid", "->", "getDefinition", "(", ")", ",", "$", "template", ")", ",", "$", "context", ")", ";", "}" ]
@param GridViewInterface $grid @param string $template @param mixed[] $context @return string
[ "@param", "GridViewInterface", "$grid", "@param", "string", "$template", "@param", "mixed", "[]", "$context" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Renderer/Renderer.php#L177-L182
php-lug/lug
src/Bundle/GridBundle/Renderer/Renderer.php
Renderer.resolveTemplate
private function resolveTemplate(GridInterface $grid, $template) { if ($grid->hasOption($option = $template.'_template')) { return $grid->getOption($option); } if (isset($this->templates[$template])) { return $this->templates[$template]; } return '@LugGrid/'.$template.'.html.twig'; }
php
private function resolveTemplate(GridInterface $grid, $template) { if ($grid->hasOption($option = $template.'_template')) { return $grid->getOption($option); } if (isset($this->templates[$template])) { return $this->templates[$template]; } return '@LugGrid/'.$template.'.html.twig'; }
[ "private", "function", "resolveTemplate", "(", "GridInterface", "$", "grid", ",", "$", "template", ")", "{", "if", "(", "$", "grid", "->", "hasOption", "(", "$", "option", "=", "$", "template", ".", "'_template'", ")", ")", "{", "return", "$", "grid", "->", "getOption", "(", "$", "option", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "templates", "[", "$", "template", "]", ")", ")", "{", "return", "$", "this", "->", "templates", "[", "$", "template", "]", ";", "}", "return", "'@LugGrid/'", ".", "$", "template", ".", "'.html.twig'", ";", "}" ]
@param GridInterface $grid @param string $template @return string
[ "@param", "GridInterface", "$grid", "@param", "string", "$template" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Renderer/Renderer.php#L190-L201
WellCommerce/AppBundle
Form/DataTransformer/MediaEntityToIdentifierTransformer.php
MediaEntityToIdentifierTransformer.reverseTransform
public function reverseTransform($modelData, PropertyPathInterface $propertyPath, $value) { $unmodified = intval($value['unmodified']); if ($unmodified === 1) { return; } $item = null; if (isset($value[0])) { $id = $value[0]; $item = $this->getRepository()->find($id); } $this->propertyAccessor->setValue($modelData, $propertyPath, $item); }
php
public function reverseTransform($modelData, PropertyPathInterface $propertyPath, $value) { $unmodified = intval($value['unmodified']); if ($unmodified === 1) { return; } $item = null; if (isset($value[0])) { $id = $value[0]; $item = $this->getRepository()->find($id); } $this->propertyAccessor->setValue($modelData, $propertyPath, $item); }
[ "public", "function", "reverseTransform", "(", "$", "modelData", ",", "PropertyPathInterface", "$", "propertyPath", ",", "$", "value", ")", "{", "$", "unmodified", "=", "intval", "(", "$", "value", "[", "'unmodified'", "]", ")", ";", "if", "(", "$", "unmodified", "===", "1", ")", "{", "return", ";", "}", "$", "item", "=", "null", ";", "if", "(", "isset", "(", "$", "value", "[", "0", "]", ")", ")", "{", "$", "id", "=", "$", "value", "[", "0", "]", ";", "$", "item", "=", "$", "this", "->", "getRepository", "(", ")", "->", "find", "(", "$", "id", ")", ";", "}", "$", "this", "->", "propertyAccessor", "->", "setValue", "(", "$", "modelData", ",", "$", "propertyPath", ",", "$", "item", ")", ";", "}" ]
Transforms identifier to entity @param object $modelData @param PropertyPathInterface $propertyPath @param mixed $value
[ "Transforms", "identifier", "to", "entity" ]
train
https://github.com/WellCommerce/AppBundle/blob/2add687d1c898dd0b24afd611d896e3811a0eac3/Form/DataTransformer/MediaEntityToIdentifierTransformer.php#L32-L46
traderinteractive/filter-dates-php
src/Filter/DateTime.php
DateTime.filter
public static function filter($value, bool $allowNull = false, DateTimeZoneStandard $timezone = null) { if (self::valueIsNullAndValid($allowNull, $value)) { return null; } if ($value instanceof DateTimeStandard) { return $value; } if (is_int($value) || ctype_digit($value)) { $value = "@{$value}"; } if (!is_string($value) || trim($value) == '') { throw new FilterException('$value is not a non-empty string'); } return new DateTimeStandard($value, $timezone); }
php
public static function filter($value, bool $allowNull = false, DateTimeZoneStandard $timezone = null) { if (self::valueIsNullAndValid($allowNull, $value)) { return null; } if ($value instanceof DateTimeStandard) { return $value; } if (is_int($value) || ctype_digit($value)) { $value = "@{$value}"; } if (!is_string($value) || trim($value) == '') { throw new FilterException('$value is not a non-empty string'); } return new DateTimeStandard($value, $timezone); }
[ "public", "static", "function", "filter", "(", "$", "value", ",", "bool", "$", "allowNull", "=", "false", ",", "DateTimeZoneStandard", "$", "timezone", "=", "null", ")", "{", "if", "(", "self", "::", "valueIsNullAndValid", "(", "$", "allowNull", ",", "$", "value", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "value", "instanceof", "DateTimeStandard", ")", "{", "return", "$", "value", ";", "}", "if", "(", "is_int", "(", "$", "value", ")", "||", "ctype_digit", "(", "$", "value", ")", ")", "{", "$", "value", "=", "\"@{$value}\"", ";", "}", "if", "(", "!", "is_string", "(", "$", "value", ")", "||", "trim", "(", "$", "value", ")", "==", "''", ")", "{", "throw", "new", "FilterException", "(", "'$value is not a non-empty string'", ")", ";", "}", "return", "new", "DateTimeStandard", "(", "$", "value", ",", "$", "timezone", ")", ";", "}" ]
Filters the given value into a \DateTime object. @param mixed $value The value to be filtered. @param boolean $allowNull True to allow nulls through, and false (default) if nulls should not be allowed. @param DateTimeZoneStandard $timezone A \DateTimeZone object representing the timezone of $value. If $timezone is omitted, the current timezone will be used. @return DateTimeStandard|null @throws FilterException if the value did not pass validation.
[ "Filters", "the", "given", "value", "into", "a", "\\", "DateTime", "object", "." ]
train
https://github.com/traderinteractive/filter-dates-php/blob/f9e60f139da3ebb565317c5d62a6fb0c347be4ee/src/Filter/DateTime.php#L28-L47
traderinteractive/filter-dates-php
src/Filter/DateTime.php
DateTime.format
public static function format(DateTimeInterface $dateTime, string $format = 'c') : string { if (empty(trim($format))) { throw new \InvalidArgumentException('$format is not a non-empty string'); } return $dateTime->format($format); }
php
public static function format(DateTimeInterface $dateTime, string $format = 'c') : string { if (empty(trim($format))) { throw new \InvalidArgumentException('$format is not a non-empty string'); } return $dateTime->format($format); }
[ "public", "static", "function", "format", "(", "DateTimeInterface", "$", "dateTime", ",", "string", "$", "format", "=", "'c'", ")", ":", "string", "{", "if", "(", "empty", "(", "trim", "(", "$", "format", ")", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'$format is not a non-empty string'", ")", ";", "}", "return", "$", "dateTime", "->", "format", "(", "$", "format", ")", ";", "}" ]
Filters the give \DateTime object to a formatted string. @param DateTimeInterface $dateTime The date to be formatted. @param string $format The format of the outputted date string. @return string @throws \InvalidArgumentException Thrown if $format is not a string
[ "Filters", "the", "give", "\\", "DateTime", "object", "to", "a", "formatted", "string", "." ]
train
https://github.com/traderinteractive/filter-dates-php/blob/f9e60f139da3ebb565317c5d62a6fb0c347be4ee/src/Filter/DateTime.php#L59-L66
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Transport/TCP.php
TCP.connect
public function connect() { if($this->stream !== null) return; $host = strval($this->config["host"]); $port = strval($this->config["port"]); $address = "tcp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port; $options = empty($this->config["tls"]) ? array() : array("ssl" => array("allow_self_signed" => TRUE, "verify_peer" => FALSE, "verify_peer_name" => FALSE)); $timeout = (int) $this->config["timeout"]; $this->stream = @stream_socket_client($address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options)); if($this->stream === FALSE) { throw new Exception(Str::factory($errstr)->toUtf8()->toString(), $errno); } if(!empty($this->config["tls"])) { stream_socket_enable_crypto($this->stream, TRUE, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); } @stream_set_timeout($this->stream, $timeout); @stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0); }
php
public function connect() { if($this->stream !== null) return; $host = strval($this->config["host"]); $port = strval($this->config["port"]); $address = "tcp://" . (strstr($host, ":") !== FALSE ? "[" . $host . "]" : $host) . ":" . $port; $options = empty($this->config["tls"]) ? array() : array("ssl" => array("allow_self_signed" => TRUE, "verify_peer" => FALSE, "verify_peer_name" => FALSE)); $timeout = (int) $this->config["timeout"]; $this->stream = @stream_socket_client($address, $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT, stream_context_create($options)); if($this->stream === FALSE) { throw new Exception(Str::factory($errstr)->toUtf8()->toString(), $errno); } if(!empty($this->config["tls"])) { stream_socket_enable_crypto($this->stream, TRUE, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); } @stream_set_timeout($this->stream, $timeout); @stream_set_blocking($this->stream, $this->config["blocking"] ? 1 : 0); }
[ "public", "function", "connect", "(", ")", "{", "if", "(", "$", "this", "->", "stream", "!==", "null", ")", "return", ";", "$", "host", "=", "strval", "(", "$", "this", "->", "config", "[", "\"host\"", "]", ")", ";", "$", "port", "=", "strval", "(", "$", "this", "->", "config", "[", "\"port\"", "]", ")", ";", "$", "address", "=", "\"tcp://\"", ".", "(", "strstr", "(", "$", "host", ",", "\":\"", ")", "!==", "FALSE", "?", "\"[\"", ".", "$", "host", ".", "\"]\"", ":", "$", "host", ")", ".", "\":\"", ".", "$", "port", ";", "$", "options", "=", "empty", "(", "$", "this", "->", "config", "[", "\"tls\"", "]", ")", "?", "array", "(", ")", ":", "array", "(", "\"ssl\"", "=>", "array", "(", "\"allow_self_signed\"", "=>", "TRUE", ",", "\"verify_peer\"", "=>", "FALSE", ",", "\"verify_peer_name\"", "=>", "FALSE", ")", ")", ";", "$", "timeout", "=", "(", "int", ")", "$", "this", "->", "config", "[", "\"timeout\"", "]", ";", "$", "this", "->", "stream", "=", "@", "stream_socket_client", "(", "$", "address", ",", "$", "errno", ",", "$", "errstr", ",", "$", "timeout", ",", "STREAM_CLIENT_CONNECT", ",", "stream_context_create", "(", "$", "options", ")", ")", ";", "if", "(", "$", "this", "->", "stream", "===", "FALSE", ")", "{", "throw", "new", "Exception", "(", "Str", "::", "factory", "(", "$", "errstr", ")", "->", "toUtf8", "(", ")", "->", "toString", "(", ")", ",", "$", "errno", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "[", "\"tls\"", "]", ")", ")", "{", "stream_socket_enable_crypto", "(", "$", "this", "->", "stream", ",", "TRUE", ",", "STREAM_CRYPTO_METHOD_SSLv23_CLIENT", ")", ";", "}", "@", "stream_set_timeout", "(", "$", "this", "->", "stream", ",", "$", "timeout", ")", ";", "@", "stream_set_blocking", "(", "$", "this", "->", "stream", ",", "$", "this", "->", "config", "[", "\"blocking\"", "]", "?", "1", ":", "0", ")", ";", "}" ]
Connects to a remote server. @throws Exception @return void
[ "Connects", "to", "a", "remote", "server", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Transport/TCP.php#L44-L69
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Transport/TCP.php
TCP.read
public function read($length = 4096) { $this->connect(); $this->waitForReadyRead(); $data = @stream_get_contents($this->stream, $length); Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data); if($data === FALSE) { throw new Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost"); } return new Str($data); }
php
public function read($length = 4096) { $this->connect(); $this->waitForReadyRead(); $data = @stream_get_contents($this->stream, $length); Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data); if($data === FALSE) { throw new Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost"); } return new Str($data); }
[ "public", "function", "read", "(", "$", "length", "=", "4096", ")", "{", "$", "this", "->", "connect", "(", ")", ";", "$", "this", "->", "waitForReadyRead", "(", ")", ";", "$", "data", "=", "@", "stream_get_contents", "(", "$", "this", "->", "stream", ",", "$", "length", ")", ";", "Signal", "::", "getInstance", "(", ")", "->", "emit", "(", "strtolower", "(", "$", "this", "->", "getAdapterType", "(", ")", ")", ".", "\"DataRead\"", ",", "$", "data", ")", ";", "if", "(", "$", "data", "===", "FALSE", ")", "{", "throw", "new", "Exception", "(", "\"connection to server '\"", ".", "$", "this", "->", "config", "[", "\"host\"", "]", ".", "\":\"", ".", "$", "this", "->", "config", "[", "\"port\"", "]", ".", "\"' lost\"", ")", ";", "}", "return", "new", "Str", "(", "$", "data", ")", ";", "}" ]
Reads data from the stream. @param integer $length @throws Exception @return Str
[ "Reads", "data", "from", "the", "stream", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Transport/TCP.php#L92-L107
lukasz-adamski/teamspeak3-framework
src/TeamSpeak3/Transport/TCP.php
TCP.readLine
public function readLine($token = "\n") { $this->connect(); $line = Str::factory(""); while(!$line->endsWith($token)) { $this->waitForReadyRead(); $data = @fgets($this->stream, 4096); Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data); if($data === FALSE) { if($line->count()) { $line->append($token); } else { throw new Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost"); } } else { $line->append($data); } } return $line->trim(); }
php
public function readLine($token = "\n") { $this->connect(); $line = Str::factory(""); while(!$line->endsWith($token)) { $this->waitForReadyRead(); $data = @fgets($this->stream, 4096); Signal::getInstance()->emit(strtolower($this->getAdapterType()) . "DataRead", $data); if($data === FALSE) { if($line->count()) { $line->append($token); } else { throw new Exception("connection to server '" . $this->config["host"] . ":" . $this->config["port"] . "' lost"); } } else { $line->append($data); } } return $line->trim(); }
[ "public", "function", "readLine", "(", "$", "token", "=", "\"\\n\"", ")", "{", "$", "this", "->", "connect", "(", ")", ";", "$", "line", "=", "Str", "::", "factory", "(", "\"\"", ")", ";", "while", "(", "!", "$", "line", "->", "endsWith", "(", "$", "token", ")", ")", "{", "$", "this", "->", "waitForReadyRead", "(", ")", ";", "$", "data", "=", "@", "fgets", "(", "$", "this", "->", "stream", ",", "4096", ")", ";", "Signal", "::", "getInstance", "(", ")", "->", "emit", "(", "strtolower", "(", "$", "this", "->", "getAdapterType", "(", ")", ")", ".", "\"DataRead\"", ",", "$", "data", ")", ";", "if", "(", "$", "data", "===", "FALSE", ")", "{", "if", "(", "$", "line", "->", "count", "(", ")", ")", "{", "$", "line", "->", "append", "(", "$", "token", ")", ";", "}", "else", "{", "throw", "new", "Exception", "(", "\"connection to server '\"", ".", "$", "this", "->", "config", "[", "\"host\"", "]", ".", "\":\"", ".", "$", "this", "->", "config", "[", "\"port\"", "]", ".", "\"' lost\"", ")", ";", "}", "}", "else", "{", "$", "line", "->", "append", "(", "$", "data", ")", ";", "}", "}", "return", "$", "line", "->", "trim", "(", ")", ";", "}" ]
Reads a single line of data from the stream. @param string $token @throws Exception @return Str
[ "Reads", "a", "single", "line", "of", "data", "from", "the", "stream", "." ]
train
https://github.com/lukasz-adamski/teamspeak3-framework/blob/39a56eca608da6b56b6aa386a7b5b31dc576c41a/src/TeamSpeak3/Transport/TCP.php#L116-L148
mainio/c5pkg_symfony_forms
src/Mainio/C5/Symfony/Form/Extension/Concrete5/Type/PageSelectorType.php
PageSelectorType.buildView
public function buildView(FormView $view, FormInterface $form, array $options) { $ph = \Core::make('helper/form/page_selector'); $view->vars = array_replace($view->vars, array( 'selector' => $ph->selectPage($view->vars["full_name"], $view->vars["value"]), )); }
php
public function buildView(FormView $view, FormInterface $form, array $options) { $ph = \Core::make('helper/form/page_selector'); $view->vars = array_replace($view->vars, array( 'selector' => $ph->selectPage($view->vars["full_name"], $view->vars["value"]), )); }
[ "public", "function", "buildView", "(", "FormView", "$", "view", ",", "FormInterface", "$", "form", ",", "array", "$", "options", ")", "{", "$", "ph", "=", "\\", "Core", "::", "make", "(", "'helper/form/page_selector'", ")", ";", "$", "view", "->", "vars", "=", "array_replace", "(", "$", "view", "->", "vars", ",", "array", "(", "'selector'", "=>", "$", "ph", "->", "selectPage", "(", "$", "view", "->", "vars", "[", "\"full_name\"", "]", ",", "$", "view", "->", "vars", "[", "\"value\"", "]", ")", ",", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/mainio/c5pkg_symfony_forms/blob/41a93c293d986574ec5cade8a7c8700e083dbaaa/src/Mainio/C5/Symfony/Form/Extension/Concrete5/Type/PageSelectorType.php#L34-L40
dstuecken/notify
src/Handler/MacOSHandler.php
MacOSHandler.handle
public function handle(NotificationInterface $notification, $level) { if ($notification instanceof TitleAwareInterface) { $command = $this->shellCommand . ' -e \'display notification "' . addslashes($notification->message()) . '" with title "' . addslashes($notification->title()) . '"\''; } else { $command = $this->shellCommand . ' -e \'display notification "' . addslashes($notification->message()) . '"\''; } exec($command . ' > /dev/null', $output, $code); return $code === 0; }
php
public function handle(NotificationInterface $notification, $level) { if ($notification instanceof TitleAwareInterface) { $command = $this->shellCommand . ' -e \'display notification "' . addslashes($notification->message()) . '" with title "' . addslashes($notification->title()) . '"\''; } else { $command = $this->shellCommand . ' -e \'display notification "' . addslashes($notification->message()) . '"\''; } exec($command . ' > /dev/null', $output, $code); return $code === 0; }
[ "public", "function", "handle", "(", "NotificationInterface", "$", "notification", ",", "$", "level", ")", "{", "if", "(", "$", "notification", "instanceof", "TitleAwareInterface", ")", "{", "$", "command", "=", "$", "this", "->", "shellCommand", ".", "' -e \\'display notification \"'", ".", "addslashes", "(", "$", "notification", "->", "message", "(", ")", ")", ".", "'\" with title \"'", ".", "addslashes", "(", "$", "notification", "->", "title", "(", ")", ")", ".", "'\"\\''", ";", "}", "else", "{", "$", "command", "=", "$", "this", "->", "shellCommand", ".", "' -e \\'display notification \"'", ".", "addslashes", "(", "$", "notification", "->", "message", "(", ")", ")", ".", "'\"\\''", ";", "}", "exec", "(", "$", "command", ".", "' > /dev/null'", ",", "$", "output", ",", "$", "code", ")", ";", "return", "$", "code", "===", "0", ";", "}" ]
Handle a notification @return bool
[ "Handle", "a", "notification" ]
train
https://github.com/dstuecken/notify/blob/abccf0a6a272caf66baea74323f18e2212c6e11e/src/Handler/MacOSHandler.php#L30-L44
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.disconnect
public function disconnect() { if ( $this->state !== self::STATE_NOT_CONNECTED && $this->connection->isConnected() === true ) { $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} LOGOUT" ); // discard the "bye bye" message ("{$tag} OK Logout completed.") $this->getResponse( $tag ); $this->state = self::STATE_LOGOUT; $this->selectedMailbox = null; $this->connection->close(); $this->connection = null; $this->state = self::STATE_NOT_CONNECTED; } }
php
public function disconnect() { if ( $this->state !== self::STATE_NOT_CONNECTED && $this->connection->isConnected() === true ) { $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} LOGOUT" ); // discard the "bye bye" message ("{$tag} OK Logout completed.") $this->getResponse( $tag ); $this->state = self::STATE_LOGOUT; $this->selectedMailbox = null; $this->connection->close(); $this->connection = null; $this->state = self::STATE_NOT_CONNECTED; } }
[ "public", "function", "disconnect", "(", ")", "{", "if", "(", "$", "this", "->", "state", "!==", "self", "::", "STATE_NOT_CONNECTED", "&&", "$", "this", "->", "connection", "->", "isConnected", "(", ")", "===", "true", ")", "{", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} LOGOUT\"", ")", ";", "// discard the \"bye bye\" message (\"{$tag} OK Logout completed.\")", "$", "this", "->", "getResponse", "(", "$", "tag", ")", ";", "$", "this", "->", "state", "=", "self", "::", "STATE_LOGOUT", ";", "$", "this", "->", "selectedMailbox", "=", "null", ";", "$", "this", "->", "connection", "->", "close", "(", ")", ";", "$", "this", "->", "connection", "=", "null", ";", "$", "this", "->", "state", "=", "self", "::", "STATE_NOT_CONNECTED", ";", "}", "}" ]
Disconnects the transport from the IMAP server.
[ "Disconnects", "the", "transport", "from", "the", "IMAP", "server", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L478-L494
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.authenticate
public function authenticate( $user, $password ) { if ( $this->state != self::STATE_NOT_AUTHENTICATED ) { throw new ezcMailTransportException( "Tried to authenticate when there was no connection or when already authenticated." ); } $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} LOGIN {$user} {$password}" ); $response = trim( $this->connection->getLine() ); // hack for gmail, to fix issue #15837: imap.google.com (google gmail) changed IMAP response if ( $this->serverType === self::SERVER_GIMAP && strpos( $response, "* CAPABILITY" ) === 0 ) { $response = trim( $this->connection->getLine() ); } if ( strpos( $response, '* OK' ) !== false ) { // the server is busy waiting for authentication process to // respond, so it is a good idea to just close the connection, // otherwise the application will be halted until the server // recovers $this->connection->close(); $this->connection = null; $this->state = self::STATE_NOT_CONNECTED; return false; } if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server did not accept the username and/or password: {$response}." ); } else { $this->state = self::STATE_AUTHENTICATED; $this->selectedMailbox = null; } return true; }
php
public function authenticate( $user, $password ) { if ( $this->state != self::STATE_NOT_AUTHENTICATED ) { throw new ezcMailTransportException( "Tried to authenticate when there was no connection or when already authenticated." ); } $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} LOGIN {$user} {$password}" ); $response = trim( $this->connection->getLine() ); // hack for gmail, to fix issue #15837: imap.google.com (google gmail) changed IMAP response if ( $this->serverType === self::SERVER_GIMAP && strpos( $response, "* CAPABILITY" ) === 0 ) { $response = trim( $this->connection->getLine() ); } if ( strpos( $response, '* OK' ) !== false ) { // the server is busy waiting for authentication process to // respond, so it is a good idea to just close the connection, // otherwise the application will be halted until the server // recovers $this->connection->close(); $this->connection = null; $this->state = self::STATE_NOT_CONNECTED; return false; } if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server did not accept the username and/or password: {$response}." ); } else { $this->state = self::STATE_AUTHENTICATED; $this->selectedMailbox = null; } return true; }
[ "public", "function", "authenticate", "(", "$", "user", ",", "$", "password", ")", "{", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_NOT_AUTHENTICATED", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Tried to authenticate when there was no connection or when already authenticated.\"", ")", ";", "}", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} LOGIN {$user} {$password}\"", ")", ";", "$", "response", "=", "trim", "(", "$", "this", "->", "connection", "->", "getLine", "(", ")", ")", ";", "// hack for gmail, to fix issue #15837: imap.google.com (google gmail) changed IMAP response", "if", "(", "$", "this", "->", "serverType", "===", "self", "::", "SERVER_GIMAP", "&&", "strpos", "(", "$", "response", ",", "\"* CAPABILITY\"", ")", "===", "0", ")", "{", "$", "response", "=", "trim", "(", "$", "this", "->", "connection", "->", "getLine", "(", ")", ")", ";", "}", "if", "(", "strpos", "(", "$", "response", ",", "'* OK'", ")", "!==", "false", ")", "{", "// the server is busy waiting for authentication process to", "// respond, so it is a good idea to just close the connection,", "// otherwise the application will be halted until the server", "// recovers", "$", "this", "->", "connection", "->", "close", "(", ")", ";", "$", "this", "->", "connection", "=", "null", ";", "$", "this", "->", "state", "=", "self", "::", "STATE_NOT_CONNECTED", ";", "return", "false", ";", "}", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "!=", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"The IMAP server did not accept the username and/or password: {$response}.\"", ")", ";", "}", "else", "{", "$", "this", "->", "state", "=", "self", "::", "STATE_AUTHENTICATED", ";", "$", "this", "->", "selectedMailbox", "=", "null", ";", "}", "return", "true", ";", "}" ]
Authenticates the user to the IMAP server with $user and $password. This method should be called directly after the construction of this object. If the server is waiting for the authentication process to respond, the connection with the IMAP server will be closed, and false is returned, and it is the application's task to reconnect and reauthenticate. Example of creating an IMAP transport and authenticating: <code> // replace with your IMAP server address $imap = new ezcMailImapTransport( 'imap.example.com' ); // replace the values with your username and password for the IMAP server $imap->authenticate( 'username', 'password' ); </code> @throws ezcMailTransportException if already authenticated or if the provided username/password combination did not work @param string $user @param string $password @return bool
[ "Authenticates", "the", "user", "to", "the", "IMAP", "server", "with", "$user", "and", "$password", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L522-L558
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.listMailboxes
public function listMailboxes( $reference = '', $mailbox = '*' ) { if ( $this->state != self::STATE_AUTHENTICATED && $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call listMailboxes() when not successfully logged in." ); } $result = array(); $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} LIST \"{$reference}\" \"{$mailbox}\"" ); $response = trim( $this->connection->getLine() ); while ( strpos( $response, '* LIST (' ) !== false ) { // only consider the selectable mailboxes if ( strpos( $response, "\\Noselect" ) === false ) { $response = substr( $response, strpos( $response, "\" " ) + 2 ); $response = trim( $response ); $response = trim( $response, "\"" ); $result[] = $response; } $response = $this->connection->getLine(); } $response = $this->getResponse( $tag, $response ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "Could not list mailboxes with the parameters '\"{$reference}\"' and '\"{$mailbox}\"': {$response}." ); } return $result; }
php
public function listMailboxes( $reference = '', $mailbox = '*' ) { if ( $this->state != self::STATE_AUTHENTICATED && $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call listMailboxes() when not successfully logged in." ); } $result = array(); $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} LIST \"{$reference}\" \"{$mailbox}\"" ); $response = trim( $this->connection->getLine() ); while ( strpos( $response, '* LIST (' ) !== false ) { // only consider the selectable mailboxes if ( strpos( $response, "\\Noselect" ) === false ) { $response = substr( $response, strpos( $response, "\" " ) + 2 ); $response = trim( $response ); $response = trim( $response, "\"" ); $result[] = $response; } $response = $this->connection->getLine(); } $response = $this->getResponse( $tag, $response ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "Could not list mailboxes with the parameters '\"{$reference}\"' and '\"{$mailbox}\"': {$response}." ); } return $result; }
[ "public", "function", "listMailboxes", "(", "$", "reference", "=", "''", ",", "$", "mailbox", "=", "'*'", ")", "{", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_AUTHENTICATED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED_READONLY", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Can't call listMailboxes() when not successfully logged in.\"", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} LIST \\\"{$reference}\\\" \\\"{$mailbox}\\\"\"", ")", ";", "$", "response", "=", "trim", "(", "$", "this", "->", "connection", "->", "getLine", "(", ")", ")", ";", "while", "(", "strpos", "(", "$", "response", ",", "'* LIST ('", ")", "!==", "false", ")", "{", "// only consider the selectable mailboxes", "if", "(", "strpos", "(", "$", "response", ",", "\"\\\\Noselect\"", ")", "===", "false", ")", "{", "$", "response", "=", "substr", "(", "$", "response", ",", "strpos", "(", "$", "response", ",", "\"\\\" \"", ")", "+", "2", ")", ";", "$", "response", "=", "trim", "(", "$", "response", ")", ";", "$", "response", "=", "trim", "(", "$", "response", ",", "\"\\\"\"", ")", ";", "$", "result", "[", "]", "=", "$", "response", ";", "}", "$", "response", "=", "$", "this", "->", "connection", "->", "getLine", "(", ")", ";", "}", "$", "response", "=", "$", "this", "->", "getResponse", "(", "$", "tag", ",", "$", "response", ")", ";", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "!=", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Could not list mailboxes with the parameters '\\\"{$reference}\\\"' and '\\\"{$mailbox}\\\"': {$response}.\"", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns an array with the names of the available mailboxes for the user currently authenticated on the IMAP server. Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully. For more information about $reference and $mailbox, consult the IMAP RFCs documents ({@link http://www.faqs.org/rfcs/rfc1730.html} or {@link http://www.faqs.org/rfcs/rfc2060.html}, section 7.2.2.). By default, $reference is "" and $mailbox is "*". The array returned contains the mailboxes available for the connected user on this IMAP server. Inbox is a special mailbox, and it can be specified upper-case or lower-case or mixed-case. The other mailboxes should be specified as they are (to the {@link selectMailbox()} method). Example of listing mailboxes: <code> $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $mailboxes = $imap->listMailboxes(); </code> @throws ezcMailMailTransportException if the current server state is not accepted or if the server sent a negative response @param string $reference @param string $mailbox @return array(string)
[ "Returns", "an", "array", "with", "the", "names", "of", "the", "available", "mailboxes", "for", "the", "user", "currently", "authenticated", "on", "the", "IMAP", "server", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L593-L626
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.getHierarchyDelimiter
public function getHierarchyDelimiter() { if ( $this->state != self::STATE_AUTHENTICATED && $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call getDelimiter() when not successfully logged in." ); } $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} LIST \"\" \"\"" ); // there should be only one * LIST response line from IMAP $response = trim( $this->getResponse( '* LIST' ) ); $parts = explode( '"', $response ); if ( count( $parts ) >= 2 ) { $result = $parts[1]; } else { throw new ezcMailTransportException( "Could not retrieve the hierarchy delimiter: {$response}." ); } $response = $this->getResponse( $tag, $response ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "Could not retrieve the hierarchy delimiter: {$response}." ); } return $result; }
php
public function getHierarchyDelimiter() { if ( $this->state != self::STATE_AUTHENTICATED && $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call getDelimiter() when not successfully logged in." ); } $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} LIST \"\" \"\"" ); // there should be only one * LIST response line from IMAP $response = trim( $this->getResponse( '* LIST' ) ); $parts = explode( '"', $response ); if ( count( $parts ) >= 2 ) { $result = $parts[1]; } else { throw new ezcMailTransportException( "Could not retrieve the hierarchy delimiter: {$response}." ); } $response = $this->getResponse( $tag, $response ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "Could not retrieve the hierarchy delimiter: {$response}." ); } return $result; }
[ "public", "function", "getHierarchyDelimiter", "(", ")", "{", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_AUTHENTICATED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED_READONLY", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Can't call getDelimiter() when not successfully logged in.\"", ")", ";", "}", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} LIST \\\"\\\" \\\"\\\"\"", ")", ";", "// there should be only one * LIST response line from IMAP", "$", "response", "=", "trim", "(", "$", "this", "->", "getResponse", "(", "'* LIST'", ")", ")", ";", "$", "parts", "=", "explode", "(", "'\"'", ",", "$", "response", ")", ";", "if", "(", "count", "(", "$", "parts", ")", ">=", "2", ")", "{", "$", "result", "=", "$", "parts", "[", "1", "]", ";", "}", "else", "{", "throw", "new", "ezcMailTransportException", "(", "\"Could not retrieve the hierarchy delimiter: {$response}.\"", ")", ";", "}", "$", "response", "=", "$", "this", "->", "getResponse", "(", "$", "tag", ",", "$", "response", ")", ";", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "!=", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Could not retrieve the hierarchy delimiter: {$response}.\"", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns the hierarchy delimiter of the IMAP server, useful for handling nested IMAP folders. For more information about the hierarchy delimiter, consult the IMAP RFCs {@link http://www.faqs.org/rfcs/rfc1730.html} or {@link http://www.faqs.org/rfcs/rfc2060.html}, section 6.3.8. Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully. Example of returning the hierarchy delimiter: <code> $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $delimiter = $imap->getDelimiter(); </code> After running the above code, $delimiter should be something like "/". @throws ezcMailMailTransportException if the current server state is not accepted or if the server sent a negative response @return string
[ "Returns", "the", "hierarchy", "delimiter", "of", "the", "IMAP", "server", "useful", "for", "handling", "nested", "IMAP", "folders", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L654-L685
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.selectMailbox
public function selectMailbox( $mailbox, $readOnly = false ) { if ( $this->state != self::STATE_AUTHENTICATED && $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call selectMailbox() when not successfully logged in." ); } $tag = $this->getNextTag(); // if the mailbox selection will be successful, $state will be STATE_SELECTED // or STATE_SELECTED_READONLY, depending on the $readOnly parameter if ( $readOnly !== true ) { $this->connection->sendData( "{$tag} SELECT \"{$mailbox}\"" ); $state = self::STATE_SELECTED; } else { $this->connection->sendData( "{$tag} EXAMINE \"{$mailbox}\"" ); $state = self::STATE_SELECTED_READONLY; } // if the selecting of the mailbox fails (with "NO" or "BAD" response // from the server), $state reverts to STATE_AUTHENTICATED $response = trim( $this->getResponse( $tag ) ); if ( $this->responseType( $response ) == self::RESPONSE_OK ) { $this->state = $state; $this->selectedMailbox = $mailbox; } else { $this->state = self::STATE_AUTHENTICATED; $this->selectedMailbox = null; throw new ezcMailTransportException( "Could not select mailbox '{$mailbox}': {$response}." ); } }
php
public function selectMailbox( $mailbox, $readOnly = false ) { if ( $this->state != self::STATE_AUTHENTICATED && $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call selectMailbox() when not successfully logged in." ); } $tag = $this->getNextTag(); // if the mailbox selection will be successful, $state will be STATE_SELECTED // or STATE_SELECTED_READONLY, depending on the $readOnly parameter if ( $readOnly !== true ) { $this->connection->sendData( "{$tag} SELECT \"{$mailbox}\"" ); $state = self::STATE_SELECTED; } else { $this->connection->sendData( "{$tag} EXAMINE \"{$mailbox}\"" ); $state = self::STATE_SELECTED_READONLY; } // if the selecting of the mailbox fails (with "NO" or "BAD" response // from the server), $state reverts to STATE_AUTHENTICATED $response = trim( $this->getResponse( $tag ) ); if ( $this->responseType( $response ) == self::RESPONSE_OK ) { $this->state = $state; $this->selectedMailbox = $mailbox; } else { $this->state = self::STATE_AUTHENTICATED; $this->selectedMailbox = null; throw new ezcMailTransportException( "Could not select mailbox '{$mailbox}': {$response}." ); } }
[ "public", "function", "selectMailbox", "(", "$", "mailbox", ",", "$", "readOnly", "=", "false", ")", "{", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_AUTHENTICATED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED_READONLY", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Can't call selectMailbox() when not successfully logged in.\"", ")", ";", "}", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "// if the mailbox selection will be successful, $state will be STATE_SELECTED", "// or STATE_SELECTED_READONLY, depending on the $readOnly parameter", "if", "(", "$", "readOnly", "!==", "true", ")", "{", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} SELECT \\\"{$mailbox}\\\"\"", ")", ";", "$", "state", "=", "self", "::", "STATE_SELECTED", ";", "}", "else", "{", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} EXAMINE \\\"{$mailbox}\\\"\"", ")", ";", "$", "state", "=", "self", "::", "STATE_SELECTED_READONLY", ";", "}", "// if the selecting of the mailbox fails (with \"NO\" or \"BAD\" response", "// from the server), $state reverts to STATE_AUTHENTICATED", "$", "response", "=", "trim", "(", "$", "this", "->", "getResponse", "(", "$", "tag", ")", ")", ";", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "==", "self", "::", "RESPONSE_OK", ")", "{", "$", "this", "->", "state", "=", "$", "state", ";", "$", "this", "->", "selectedMailbox", "=", "$", "mailbox", ";", "}", "else", "{", "$", "this", "->", "state", "=", "self", "::", "STATE_AUTHENTICATED", ";", "$", "this", "->", "selectedMailbox", "=", "null", ";", "throw", "new", "ezcMailTransportException", "(", "\"Could not select mailbox '{$mailbox}': {$response}.\"", ")", ";", "}", "}" ]
Selects the mailbox $mailbox, which will be the active mailbox for the subsequent commands until it is changed. Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully. Inbox is a special mailbox and can be specified with any case. This method should be called after authentication, and before fetching any messages. Example of selecting a mailbox: <code> $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $imap->selectMailbox( 'Reports 2006' ); </code> @throws ezcMailMailTransportException if the current server state is not accepted or if the server sent a negative response @param string $mailbox @param bool $readOnly
[ "Selects", "the", "mailbox", "$mailbox", "which", "will", "be", "the", "active", "mailbox", "for", "the", "subsequent", "commands", "until", "it", "is", "changed", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L713-L751
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.createMailbox
public function createMailbox( $mailbox ) { if ( $this->state != self::STATE_AUTHENTICATED && $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call createMailbox() when not successfully logged in." ); } $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} CREATE \"{$mailbox}\"" ); $response = trim( $this->getResponse( $tag ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not create mailbox '{$mailbox}': {$response}." ); } return true; }
php
public function createMailbox( $mailbox ) { if ( $this->state != self::STATE_AUTHENTICATED && $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call createMailbox() when not successfully logged in." ); } $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} CREATE \"{$mailbox}\"" ); $response = trim( $this->getResponse( $tag ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not create mailbox '{$mailbox}': {$response}." ); } return true; }
[ "public", "function", "createMailbox", "(", "$", "mailbox", ")", "{", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_AUTHENTICATED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED_READONLY", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Can't call createMailbox() when not successfully logged in.\"", ")", ";", "}", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} CREATE \\\"{$mailbox}\\\"\"", ")", ";", "$", "response", "=", "trim", "(", "$", "this", "->", "getResponse", "(", "$", "tag", ")", ")", ";", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "!=", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"The IMAP server could not create mailbox '{$mailbox}': {$response}.\"", ")", ";", "}", "return", "true", ";", "}" ]
Creates the mailbox $mailbox. Inbox cannot be created. Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully. @throws ezcMailTransportException if the current server state is not accepted or if the server sent a negative response @param string $mailbox @return bool
[ "Creates", "the", "mailbox", "$mailbox", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L767-L784
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.copyMessages
public function copyMessages( $messages, $destination ) { $uid = ( $this->options->uidReferencing ) ? self::UID : self::NO_UID; if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call copyMessages() on the IMAP transport when a mailbox is not selected." ); } $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} {$uid}COPY {$messages} \"{$destination}\"" ); $response = trim( $this->getResponse( $tag ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not copy '{$messages}' to '{$destination}': {$response}." ); } return true; }
php
public function copyMessages( $messages, $destination ) { $uid = ( $this->options->uidReferencing ) ? self::UID : self::NO_UID; if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call copyMessages() on the IMAP transport when a mailbox is not selected." ); } $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} {$uid}COPY {$messages} \"{$destination}\"" ); $response = trim( $this->getResponse( $tag ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not copy '{$messages}' to '{$destination}': {$response}." ); } return true; }
[ "public", "function", "copyMessages", "(", "$", "messages", ",", "$", "destination", ")", "{", "$", "uid", "=", "(", "$", "this", "->", "options", "->", "uidReferencing", ")", "?", "self", "::", "UID", ":", "self", "::", "NO_UID", ";", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED_READONLY", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Can't call copyMessages() on the IMAP transport when a mailbox is not selected.\"", ")", ";", "}", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} {$uid}COPY {$messages} \\\"{$destination}\\\"\"", ")", ";", "$", "response", "=", "trim", "(", "$", "this", "->", "getResponse", "(", "$", "tag", ")", ")", ";", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "!=", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"The IMAP server could not copy '{$messages}' to '{$destination}': {$response}.\"", ")", ";", "}", "return", "true", ";", "}" ]
Copies message(s) from the currently selected mailbox to mailbox $destination. This method supports unique IDs instead of message numbers. See {@link ezcMailImapTransportOptions} for how to enable unique IDs referencing. Warning! When using unique IDs referencing and trying to copy a message with an ID that does not exist, this method will not throw an exception. @todo Find out if it is possible to catch this IMAP bug. $messages can be: - a single message number (eg: '1') - a message range (eg. '1:4') - a message list (eg. '1,2,4') Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully, and a mailbox must be selected (the mailbox from which messages will be copied). Example of copying 3 messages to a mailbox: <code> $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $imap->selectMailbox( 'Inbox' ); $imap->copyMessages( '1,2,4', 'Reports 2006' ); </code> The above code will copy the messages with numbers 1, 2 and 4 from Inbox to Reports 2006. @throws ezcMailTransportException if the current server state is not accepted or if the server sent a negative response @param string $messages @param string $destination @return bool
[ "Copies", "message", "(", "s", ")", "from", "the", "currently", "selected", "mailbox", "to", "mailbox", "$destination", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L906-L925
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.listMessages
public function listMessages( $contentType = null ) { if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call listMessages() on the IMAP transport when a mailbox is not selected." ); } $messageList = array(); $messages = array(); // get the numbers of the existing messages $tag = $this->getNextTag(); $command = "{$tag} SEARCH UNDELETED"; if ( !is_null( $contentType ) ) { $command .= " HEADER \"Content-Type\" \"{$contentType}\""; } $this->connection->sendData( $command ); $response = trim( $this->getResponse( '* SEARCH' ) ); if ( strpos( $response, '* SEARCH' ) !== false ) { $ids = trim( substr( $response, 9 ) ); if ( $ids !== "" ) { $messageList = explode( ' ', $ids ); } } // skip the OK response ("{$tag} OK Search completed.") $response = trim( $this->getResponse( $tag, $response ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not list messages: {$response}." ); } if ( !empty( $messageList ) ) { // get the sizes of the messages $tag = $this->getNextTag(); $query = trim( implode( ',', $messageList ) ); $this->connection->sendData( "{$tag} FETCH {$query} RFC822.SIZE" ); $response = $this->getResponse( 'FETCH (' ); $currentMessage = trim( reset( $messageList ) ); while ( strpos( $response, 'FETCH (' ) !== false ) { $line = $response; $line = explode( ' ', $line ); $line = trim( $line[count( $line ) - 1] ); $line = substr( $line, 0, strlen( $line ) - 1 ); $messages[$currentMessage] = intval( $line ); $currentMessage = next( $messageList ); $response = $this->connection->getLine(); } // skip the OK response ("{$tag} OK Fetch completed.") $response = trim( $this->getResponse( $tag, $response ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not list messages: {$response}." ); } } return $messages; }
php
public function listMessages( $contentType = null ) { if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call listMessages() on the IMAP transport when a mailbox is not selected." ); } $messageList = array(); $messages = array(); // get the numbers of the existing messages $tag = $this->getNextTag(); $command = "{$tag} SEARCH UNDELETED"; if ( !is_null( $contentType ) ) { $command .= " HEADER \"Content-Type\" \"{$contentType}\""; } $this->connection->sendData( $command ); $response = trim( $this->getResponse( '* SEARCH' ) ); if ( strpos( $response, '* SEARCH' ) !== false ) { $ids = trim( substr( $response, 9 ) ); if ( $ids !== "" ) { $messageList = explode( ' ', $ids ); } } // skip the OK response ("{$tag} OK Search completed.") $response = trim( $this->getResponse( $tag, $response ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not list messages: {$response}." ); } if ( !empty( $messageList ) ) { // get the sizes of the messages $tag = $this->getNextTag(); $query = trim( implode( ',', $messageList ) ); $this->connection->sendData( "{$tag} FETCH {$query} RFC822.SIZE" ); $response = $this->getResponse( 'FETCH (' ); $currentMessage = trim( reset( $messageList ) ); while ( strpos( $response, 'FETCH (' ) !== false ) { $line = $response; $line = explode( ' ', $line ); $line = trim( $line[count( $line ) - 1] ); $line = substr( $line, 0, strlen( $line ) - 1 ); $messages[$currentMessage] = intval( $line ); $currentMessage = next( $messageList ); $response = $this->connection->getLine(); } // skip the OK response ("{$tag} OK Fetch completed.") $response = trim( $this->getResponse( $tag, $response ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not list messages: {$response}." ); } } return $messages; }
[ "public", "function", "listMessages", "(", "$", "contentType", "=", "null", ")", "{", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED_READONLY", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Can't call listMessages() on the IMAP transport when a mailbox is not selected.\"", ")", ";", "}", "$", "messageList", "=", "array", "(", ")", ";", "$", "messages", "=", "array", "(", ")", ";", "// get the numbers of the existing messages", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "command", "=", "\"{$tag} SEARCH UNDELETED\"", ";", "if", "(", "!", "is_null", "(", "$", "contentType", ")", ")", "{", "$", "command", ".=", "\" HEADER \\\"Content-Type\\\" \\\"{$contentType}\\\"\"", ";", "}", "$", "this", "->", "connection", "->", "sendData", "(", "$", "command", ")", ";", "$", "response", "=", "trim", "(", "$", "this", "->", "getResponse", "(", "'* SEARCH'", ")", ")", ";", "if", "(", "strpos", "(", "$", "response", ",", "'* SEARCH'", ")", "!==", "false", ")", "{", "$", "ids", "=", "trim", "(", "substr", "(", "$", "response", ",", "9", ")", ")", ";", "if", "(", "$", "ids", "!==", "\"\"", ")", "{", "$", "messageList", "=", "explode", "(", "' '", ",", "$", "ids", ")", ";", "}", "}", "// skip the OK response (\"{$tag} OK Search completed.\")", "$", "response", "=", "trim", "(", "$", "this", "->", "getResponse", "(", "$", "tag", ",", "$", "response", ")", ")", ";", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "!=", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"The IMAP server could not list messages: {$response}.\"", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "messageList", ")", ")", "{", "// get the sizes of the messages", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "query", "=", "trim", "(", "implode", "(", "','", ",", "$", "messageList", ")", ")", ";", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} FETCH {$query} RFC822.SIZE\"", ")", ";", "$", "response", "=", "$", "this", "->", "getResponse", "(", "'FETCH ('", ")", ";", "$", "currentMessage", "=", "trim", "(", "reset", "(", "$", "messageList", ")", ")", ";", "while", "(", "strpos", "(", "$", "response", ",", "'FETCH ('", ")", "!==", "false", ")", "{", "$", "line", "=", "$", "response", ";", "$", "line", "=", "explode", "(", "' '", ",", "$", "line", ")", ";", "$", "line", "=", "trim", "(", "$", "line", "[", "count", "(", "$", "line", ")", "-", "1", "]", ")", ";", "$", "line", "=", "substr", "(", "$", "line", ",", "0", ",", "strlen", "(", "$", "line", ")", "-", "1", ")", ";", "$", "messages", "[", "$", "currentMessage", "]", "=", "intval", "(", "$", "line", ")", ";", "$", "currentMessage", "=", "next", "(", "$", "messageList", ")", ";", "$", "response", "=", "$", "this", "->", "connection", "->", "getLine", "(", ")", ";", "}", "// skip the OK response (\"{$tag} OK Fetch completed.\")", "$", "response", "=", "trim", "(", "$", "this", "->", "getResponse", "(", "$", "tag", ",", "$", "response", ")", ")", ";", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "!=", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"The IMAP server could not list messages: {$response}.\"", ")", ";", "}", "}", "return", "$", "messages", ";", "}" ]
Returns a list of the not deleted messages in the current mailbox. It returns only the messages with the flag DELETED not set. Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully, and a mailbox must be selected. The format of the returned array is <code> array( message_id => size ); </code> Example: <code> array( 2 => 1700, 5 => 1450, 6 => 21043 ); </code> If $contentType is set, it returns only the messages with $contentType in the Content-Type header. For example $contentType can be "multipart/mixed" to return only the messages with attachments. @throws ezcMailTransportException if a mailbox is not selected or if the server sent a negative response @param string $contentType @return array(int)
[ "Returns", "a", "list", "of", "the", "not", "deleted", "messages", "in", "the", "current", "mailbox", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L958-L1019
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.fetchSizes
public function fetchSizes( $messages ) { $uid = ( $this->options->uidReferencing ) ? self::UID : self::NO_UID; if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call fetchSizes() on the IMAP transport when a mailbox is not selected." ); } $sizes = array(); $ids = implode( $messages, ',' ); $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} {$uid}FETCH {$ids} (RFC822.SIZE)" ); $response = trim( $this->connection->getLine() ); while ( strpos( $response, $tag ) === false ) { if ( strpos( $response, ' FETCH (' ) !== false ) { if ( $this->options->uidReferencing ) { preg_match( '/\*\s.*\sFETCH\s\(RFC822\.SIZE\s(.*)\sUID\s(.*)\)/U', $response, $matches ); $sizes[intval( $matches[2] )] = (int) $matches[1]; } else { preg_match( '/\*\s(.*)\sFETCH\s\(RFC822\.SIZE\s(.*)\)/U', $response, $matches ); $sizes[intval( $matches[1] )] = (int) $matches[2]; } } $response = trim( $this->connection->getLine() ); } if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not fetch flags for the messages '{$messages}': {$response}." ); } return $sizes; }
php
public function fetchSizes( $messages ) { $uid = ( $this->options->uidReferencing ) ? self::UID : self::NO_UID; if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call fetchSizes() on the IMAP transport when a mailbox is not selected." ); } $sizes = array(); $ids = implode( $messages, ',' ); $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} {$uid}FETCH {$ids} (RFC822.SIZE)" ); $response = trim( $this->connection->getLine() ); while ( strpos( $response, $tag ) === false ) { if ( strpos( $response, ' FETCH (' ) !== false ) { if ( $this->options->uidReferencing ) { preg_match( '/\*\s.*\sFETCH\s\(RFC822\.SIZE\s(.*)\sUID\s(.*)\)/U', $response, $matches ); $sizes[intval( $matches[2] )] = (int) $matches[1]; } else { preg_match( '/\*\s(.*)\sFETCH\s\(RFC822\.SIZE\s(.*)\)/U', $response, $matches ); $sizes[intval( $matches[1] )] = (int) $matches[2]; } } $response = trim( $this->connection->getLine() ); } if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not fetch flags for the messages '{$messages}': {$response}." ); } return $sizes; }
[ "public", "function", "fetchSizes", "(", "$", "messages", ")", "{", "$", "uid", "=", "(", "$", "this", "->", "options", "->", "uidReferencing", ")", "?", "self", "::", "UID", ":", "self", "::", "NO_UID", ";", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED_READONLY", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Can't call fetchSizes() on the IMAP transport when a mailbox is not selected.\"", ")", ";", "}", "$", "sizes", "=", "array", "(", ")", ";", "$", "ids", "=", "implode", "(", "$", "messages", ",", "','", ")", ";", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} {$uid}FETCH {$ids} (RFC822.SIZE)\"", ")", ";", "$", "response", "=", "trim", "(", "$", "this", "->", "connection", "->", "getLine", "(", ")", ")", ";", "while", "(", "strpos", "(", "$", "response", ",", "$", "tag", ")", "===", "false", ")", "{", "if", "(", "strpos", "(", "$", "response", ",", "' FETCH ('", ")", "!==", "false", ")", "{", "if", "(", "$", "this", "->", "options", "->", "uidReferencing", ")", "{", "preg_match", "(", "'/\\*\\s.*\\sFETCH\\s\\(RFC822\\.SIZE\\s(.*)\\sUID\\s(.*)\\)/U'", ",", "$", "response", ",", "$", "matches", ")", ";", "$", "sizes", "[", "intval", "(", "$", "matches", "[", "2", "]", ")", "]", "=", "(", "int", ")", "$", "matches", "[", "1", "]", ";", "}", "else", "{", "preg_match", "(", "'/\\*\\s(.*)\\sFETCH\\s\\(RFC822\\.SIZE\\s(.*)\\)/U'", ",", "$", "response", ",", "$", "matches", ")", ";", "$", "sizes", "[", "intval", "(", "$", "matches", "[", "1", "]", ")", "]", "=", "(", "int", ")", "$", "matches", "[", "2", "]", ";", "}", "}", "$", "response", "=", "trim", "(", "$", "this", "->", "connection", "->", "getLine", "(", ")", ")", ";", "}", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "!=", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"The IMAP server could not fetch flags for the messages '{$messages}': {$response}.\"", ")", ";", "}", "return", "$", "sizes", ";", "}" ]
Fetches the sizes in bytes for messages $messages. This method supports unique IDs instead of message numbers. See {@link ezcMailImapTransportOptions} for how to enable unique IDs referencing. $messages is an array of message numbers, for example: <code> array( 1, 2, 4 ); </code> The format of the returned array is: <code> array( message_number => size ) </code> Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully, and a mailbox must be selected. Example: <code> $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $imap->selectMailbox( 'mailbox' ); // Inbox or another mailbox $sizes = $imap->fetchSizes( array( 1, 2, 4 ) ); </code> The returned array $sizes will be something like: <code> array( 1 => 1043, 2 => 203901, 4 => 14277 ); </code> @throws ezcMailTransportException if a mailbox is not selected or if the server sent a negative response @param array $messages @return array(int)
[ "Fetches", "the", "sizes", "in", "bytes", "for", "messages", "$messages", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L1065-L1106
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.status
public function status( &$numMessages, &$sizeMessages, &$recent = 0, &$unseen = 0 ) { if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call status() on the IMAP transport when a mailbox is not selected." ); } $messages = $this->listMessages(); $numMessages = count( $messages ); $sizeMessages = array_sum( $messages ); $messages = array_keys( $messages ); $recentMessages = array_intersect( $this->searchByFlag( "RECENT" ), $messages ); $unseenMessages = array_intersect( $this->searchByFlag( "UNSEEN" ), $messages ); $recent = count( $recentMessages ); $unseen = count( $unseenMessages ); return true; }
php
public function status( &$numMessages, &$sizeMessages, &$recent = 0, &$unseen = 0 ) { if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call status() on the IMAP transport when a mailbox is not selected." ); } $messages = $this->listMessages(); $numMessages = count( $messages ); $sizeMessages = array_sum( $messages ); $messages = array_keys( $messages ); $recentMessages = array_intersect( $this->searchByFlag( "RECENT" ), $messages ); $unseenMessages = array_intersect( $this->searchByFlag( "UNSEEN" ), $messages ); $recent = count( $recentMessages ); $unseen = count( $unseenMessages ); return true; }
[ "public", "function", "status", "(", "&", "$", "numMessages", ",", "&", "$", "sizeMessages", ",", "&", "$", "recent", "=", "0", ",", "&", "$", "unseen", "=", "0", ")", "{", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED_READONLY", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Can't call status() on the IMAP transport when a mailbox is not selected.\"", ")", ";", "}", "$", "messages", "=", "$", "this", "->", "listMessages", "(", ")", ";", "$", "numMessages", "=", "count", "(", "$", "messages", ")", ";", "$", "sizeMessages", "=", "array_sum", "(", "$", "messages", ")", ";", "$", "messages", "=", "array_keys", "(", "$", "messages", ")", ";", "$", "recentMessages", "=", "array_intersect", "(", "$", "this", "->", "searchByFlag", "(", "\"RECENT\"", ")", ",", "$", "messages", ")", ";", "$", "unseenMessages", "=", "array_intersect", "(", "$", "this", "->", "searchByFlag", "(", "\"UNSEEN\"", ")", ",", "$", "messages", ")", ";", "$", "recent", "=", "count", "(", "$", "recentMessages", ")", ";", "$", "unseen", "=", "count", "(", "$", "unseenMessages", ")", ";", "return", "true", ";", "}" ]
Returns information about the messages in the current mailbox. The information returned through the parameters is: - $numMessages = number of not deleted messages in the selected mailbox - $sizeMessages = sum of the not deleted messages sizes - $recent = number of recent and not deleted messages - $unseen = number of unseen and not deleted messages Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully, and a mailbox must be selected. Example of returning the status of the currently selected mailbox: <code> $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $imap->selectMailbox( 'Inbox' ); $imap->status( $numMessages, $sizeMessages, $recent, $unseen ); </code> After running the above code, $numMessages, $sizeMessages, $recent and $unseen will be populated with values. @throws ezcMailTransportException if a mailbox is not selected or if the server sent a negative response @param int &$numMessages @param int &$sizeMessages @param int &$recent @param int &$unseen @return bool
[ "Returns", "information", "about", "the", "messages", "in", "the", "current", "mailbox", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L1142-L1158
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.delete
public function delete( $msgNum ) { $uid = ( $this->options->uidReferencing ) ? self::UID : self::NO_UID; if ( $this->state != self::STATE_SELECTED ) { throw new ezcMailTransportException( "Can't call delete() when a mailbox is not selected." ); } $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} {$uid}STORE {$msgNum} +FLAGS (\\Deleted)" ); // get the response (should be "{$tag} OK Store completed.") $response = trim( $this->getResponse( $tag ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not delete the message '{$msgNum}': {$response}." ); } return true; }
php
public function delete( $msgNum ) { $uid = ( $this->options->uidReferencing ) ? self::UID : self::NO_UID; if ( $this->state != self::STATE_SELECTED ) { throw new ezcMailTransportException( "Can't call delete() when a mailbox is not selected." ); } $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} {$uid}STORE {$msgNum} +FLAGS (\\Deleted)" ); // get the response (should be "{$tag} OK Store completed.") $response = trim( $this->getResponse( $tag ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not delete the message '{$msgNum}': {$response}." ); } return true; }
[ "public", "function", "delete", "(", "$", "msgNum", ")", "{", "$", "uid", "=", "(", "$", "this", "->", "options", "->", "uidReferencing", ")", "?", "self", "::", "UID", ":", "self", "::", "NO_UID", ";", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Can't call delete() when a mailbox is not selected.\"", ")", ";", "}", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} {$uid}STORE {$msgNum} +FLAGS (\\\\Deleted)\"", ")", ";", "// get the response (should be \"{$tag} OK Store completed.\")", "$", "response", "=", "trim", "(", "$", "this", "->", "getResponse", "(", "$", "tag", ")", ")", ";", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "!=", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"The IMAP server could not delete the message '{$msgNum}': {$response}.\"", ")", ";", "}", "return", "true", ";", "}" ]
Deletes the message with the message number $msgNum from the current mailbox. This method supports unique IDs instead of message numbers. See {@link ezcMailImapTransportOptions} for how to enable unique IDs referencing. The message number $msgNum must be a valid identifier fetched with e.g. {@link listMessages()}. The message is not physically deleted, but has its DELETED flag set, and can be later undeleted by clearing its DELETED flag with {@link clearFlag()}. Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully, and a mailbox must be selected. @throws ezcMailTransportException if a mailbox is not selected or if the server sent a negative response @param int $msgNum @return bool
[ "Deletes", "the", "message", "with", "the", "message", "number", "$msgNum", "from", "the", "current", "mailbox", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L1184-L1202
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.top
public function top( $msgNum, $chars = 0 ) { $uid = ( $this->options->uidReferencing ) ? self::UID : self::NO_UID; if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call top() on the IMAP transport when a mailbox is not selected." ); } $tag = $this->getNextTag(); if ( $chars === 0 ) { $command = "{$tag} {$uid}FETCH {$msgNum} (BODY.PEEK[HEADER] BODY.PEEK[TEXT])"; } else { $command = "{$tag} {$uid}FETCH {$msgNum} (BODY.PEEK[HEADER] BODY.PEEK[TEXT]<0.{$chars}>)"; } $this->connection->sendData( $command ); if ( $this->options->uidReferencing ) { // special case (BUG?) where "UID FETCH {$msgNum}" returns nothing $response = trim( $this->connection->getLine() ); if ( $this->responseType( $response ) === self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not fetch the message '{$msgNum}': {$response}." ); } } else { $response = $this->getResponse( 'FETCH (' ); } $message = ""; if ( strpos( $response, 'FETCH (' ) !== false ) { // Added hack for issue #14360: problems with $imap->top() command in gmail. if ( $this->serverType === self::SERVER_GIMAP ) { // Google IMAP servers return the body first, then the headers (!) $bytesToRead = $this->getMessageSectionSize( $response ); $response = ""; while ( $bytesToRead >= 0 ) { $data = $this->connection->getLine(); $lastResponse = $data; $bytesToRead -= strlen( $data ); // in case reading too much and the string "BODY[HEADER] {size}" // is at the end of the last line if ( $bytesToRead <= 0 ) { if ( $bytesToRead < 0 ) { $lastResponse = substr( $data, $bytesToRead ); $data = substr( $data, 0, strlen( $data ) + $bytesToRead ); } } $message .= $data; } // Read the headers $headers = ''; $response = $this->connection->getLine(); $bytesToRead = $this->getMessageSectionSize( $lastResponse ); $response = $this->connection->getLine(); while ( strpos( $response, $tag ) === false ) { $headers .= $response; $response = $this->connection->getLine(); } $headers = trim( $headers, ")\r\n" ); // Append the body AFTER the headers as it should be $message = $headers . "\r\n\r\n" . $message; } else { // Other IMAP servers return the headers first, then the body $response = ""; while ( strpos( $response, 'BODY[TEXT]' ) === false ) { $message .= $response; $response = $this->connection->getLine(); } $response = $this->connection->getLine(); while ( strpos( $response, $tag ) === false ) { $message .= $response; $response = $this->connection->getLine(); } } } // skip the OK response ("{$tag} OK Fetch completed.") $response = trim( $this->getResponse( $tag, $response ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not fetch the message '{$msgNum}': {$response}." ); } return $message; }
php
public function top( $msgNum, $chars = 0 ) { $uid = ( $this->options->uidReferencing ) ? self::UID : self::NO_UID; if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call top() on the IMAP transport when a mailbox is not selected." ); } $tag = $this->getNextTag(); if ( $chars === 0 ) { $command = "{$tag} {$uid}FETCH {$msgNum} (BODY.PEEK[HEADER] BODY.PEEK[TEXT])"; } else { $command = "{$tag} {$uid}FETCH {$msgNum} (BODY.PEEK[HEADER] BODY.PEEK[TEXT]<0.{$chars}>)"; } $this->connection->sendData( $command ); if ( $this->options->uidReferencing ) { // special case (BUG?) where "UID FETCH {$msgNum}" returns nothing $response = trim( $this->connection->getLine() ); if ( $this->responseType( $response ) === self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not fetch the message '{$msgNum}': {$response}." ); } } else { $response = $this->getResponse( 'FETCH (' ); } $message = ""; if ( strpos( $response, 'FETCH (' ) !== false ) { // Added hack for issue #14360: problems with $imap->top() command in gmail. if ( $this->serverType === self::SERVER_GIMAP ) { // Google IMAP servers return the body first, then the headers (!) $bytesToRead = $this->getMessageSectionSize( $response ); $response = ""; while ( $bytesToRead >= 0 ) { $data = $this->connection->getLine(); $lastResponse = $data; $bytesToRead -= strlen( $data ); // in case reading too much and the string "BODY[HEADER] {size}" // is at the end of the last line if ( $bytesToRead <= 0 ) { if ( $bytesToRead < 0 ) { $lastResponse = substr( $data, $bytesToRead ); $data = substr( $data, 0, strlen( $data ) + $bytesToRead ); } } $message .= $data; } // Read the headers $headers = ''; $response = $this->connection->getLine(); $bytesToRead = $this->getMessageSectionSize( $lastResponse ); $response = $this->connection->getLine(); while ( strpos( $response, $tag ) === false ) { $headers .= $response; $response = $this->connection->getLine(); } $headers = trim( $headers, ")\r\n" ); // Append the body AFTER the headers as it should be $message = $headers . "\r\n\r\n" . $message; } else { // Other IMAP servers return the headers first, then the body $response = ""; while ( strpos( $response, 'BODY[TEXT]' ) === false ) { $message .= $response; $response = $this->connection->getLine(); } $response = $this->connection->getLine(); while ( strpos( $response, $tag ) === false ) { $message .= $response; $response = $this->connection->getLine(); } } } // skip the OK response ("{$tag} OK Fetch completed.") $response = trim( $this->getResponse( $tag, $response ) ); if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not fetch the message '{$msgNum}': {$response}." ); } return $message; }
[ "public", "function", "top", "(", "$", "msgNum", ",", "$", "chars", "=", "0", ")", "{", "$", "uid", "=", "(", "$", "this", "->", "options", "->", "uidReferencing", ")", "?", "self", "::", "UID", ":", "self", "::", "NO_UID", ";", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED_READONLY", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Can't call top() on the IMAP transport when a mailbox is not selected.\"", ")", ";", "}", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "if", "(", "$", "chars", "===", "0", ")", "{", "$", "command", "=", "\"{$tag} {$uid}FETCH {$msgNum} (BODY.PEEK[HEADER] BODY.PEEK[TEXT])\"", ";", "}", "else", "{", "$", "command", "=", "\"{$tag} {$uid}FETCH {$msgNum} (BODY.PEEK[HEADER] BODY.PEEK[TEXT]<0.{$chars}>)\"", ";", "}", "$", "this", "->", "connection", "->", "sendData", "(", "$", "command", ")", ";", "if", "(", "$", "this", "->", "options", "->", "uidReferencing", ")", "{", "// special case (BUG?) where \"UID FETCH {$msgNum}\" returns nothing", "$", "response", "=", "trim", "(", "$", "this", "->", "connection", "->", "getLine", "(", ")", ")", ";", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "===", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"The IMAP server could not fetch the message '{$msgNum}': {$response}.\"", ")", ";", "}", "}", "else", "{", "$", "response", "=", "$", "this", "->", "getResponse", "(", "'FETCH ('", ")", ";", "}", "$", "message", "=", "\"\"", ";", "if", "(", "strpos", "(", "$", "response", ",", "'FETCH ('", ")", "!==", "false", ")", "{", "// Added hack for issue #14360: problems with $imap->top() command in gmail.", "if", "(", "$", "this", "->", "serverType", "===", "self", "::", "SERVER_GIMAP", ")", "{", "// Google IMAP servers return the body first, then the headers (!)", "$", "bytesToRead", "=", "$", "this", "->", "getMessageSectionSize", "(", "$", "response", ")", ";", "$", "response", "=", "\"\"", ";", "while", "(", "$", "bytesToRead", ">=", "0", ")", "{", "$", "data", "=", "$", "this", "->", "connection", "->", "getLine", "(", ")", ";", "$", "lastResponse", "=", "$", "data", ";", "$", "bytesToRead", "-=", "strlen", "(", "$", "data", ")", ";", "// in case reading too much and the string \"BODY[HEADER] {size}\"", "// is at the end of the last line", "if", "(", "$", "bytesToRead", "<=", "0", ")", "{", "if", "(", "$", "bytesToRead", "<", "0", ")", "{", "$", "lastResponse", "=", "substr", "(", "$", "data", ",", "$", "bytesToRead", ")", ";", "$", "data", "=", "substr", "(", "$", "data", ",", "0", ",", "strlen", "(", "$", "data", ")", "+", "$", "bytesToRead", ")", ";", "}", "}", "$", "message", ".=", "$", "data", ";", "}", "// Read the headers", "$", "headers", "=", "''", ";", "$", "response", "=", "$", "this", "->", "connection", "->", "getLine", "(", ")", ";", "$", "bytesToRead", "=", "$", "this", "->", "getMessageSectionSize", "(", "$", "lastResponse", ")", ";", "$", "response", "=", "$", "this", "->", "connection", "->", "getLine", "(", ")", ";", "while", "(", "strpos", "(", "$", "response", ",", "$", "tag", ")", "===", "false", ")", "{", "$", "headers", ".=", "$", "response", ";", "$", "response", "=", "$", "this", "->", "connection", "->", "getLine", "(", ")", ";", "}", "$", "headers", "=", "trim", "(", "$", "headers", ",", "\")\\r\\n\"", ")", ";", "// Append the body AFTER the headers as it should be", "$", "message", "=", "$", "headers", ".", "\"\\r\\n\\r\\n\"", ".", "$", "message", ";", "}", "else", "{", "// Other IMAP servers return the headers first, then the body", "$", "response", "=", "\"\"", ";", "while", "(", "strpos", "(", "$", "response", ",", "'BODY[TEXT]'", ")", "===", "false", ")", "{", "$", "message", ".=", "$", "response", ";", "$", "response", "=", "$", "this", "->", "connection", "->", "getLine", "(", ")", ";", "}", "$", "response", "=", "$", "this", "->", "connection", "->", "getLine", "(", ")", ";", "while", "(", "strpos", "(", "$", "response", ",", "$", "tag", ")", "===", "false", ")", "{", "$", "message", ".=", "$", "response", ";", "$", "response", "=", "$", "this", "->", "connection", "->", "getLine", "(", ")", ";", "}", "}", "}", "// skip the OK response (\"{$tag} OK Fetch completed.\")", "$", "response", "=", "trim", "(", "$", "this", "->", "getResponse", "(", "$", "tag", ",", "$", "response", ")", ")", ";", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "!=", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"The IMAP server could not fetch the message '{$msgNum}': {$response}.\"", ")", ";", "}", "return", "$", "message", ";", "}" ]
Returns the headers and the first characters from message $msgNum, without setting the SEEN flag. This method supports unique IDs instead of message numbers. See {@link ezcMailImapTransportOptions} for how to enable unique IDs referencing. If the command failed or if it was not supported by the server an empty string is returned. This method is useful for retrieving the headers of messages from the mailbox as strings, which can be later parsed with {@link ezcMailParser} and {@link ezcMailVariableSet}. In this way the retrieval of the full messages from the server is avoided when building a list of messages. Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully, and a mailbox must be selected. Example of listing the mail headers of all the messages in the current mailbox: <code> $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $imap->selectMailbox( 'Inbox' ); $parser = new ezcMailParser(); $messages = $imap->listMessages(); foreach ( $messages as $messageNr => $size ) { $set = new ezcMailVariableSet( $imap->top( $messageNr ) ); $mail = $parser->parseMail( $set ); $mail = $mail[0]; echo "From: {$mail->from}, Subject: {$mail->subject}, Size: {$size}\n"; } </code> For a more advanced example see the "Mail listing example" in the online documentation. @throws ezcMailTransportException if a mailbox is not selected or if the server sent a negative response @param int $msgNum @param int $chars @return string
[ "Returns", "the", "headers", "and", "the", "first", "characters", "from", "message", "$msgNum", "without", "setting", "the", "SEEN", "flag", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L1252-L1355
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.listUniqueIdentifiers
public function listUniqueIdentifiers( $msgNum = null ) { if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call listUniqueIdentifiers() on the IMAP transport when a mailbox is not selected." ); } $result = array(); if ( $msgNum !== null ) { $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} UID SEARCH {$msgNum}" ); $response = $this->getResponse( '* SEARCH' ); if ( strpos( $response, '* SEARCH' ) !== false ) { $result[(int)$msgNum] = trim( substr( $response, 9 ) ); } $response = trim( $this->getResponse( $tag, $response ) ); } else { $uids = array(); $messages = array_keys( $this->listMessages() ); $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} UID SEARCH UNDELETED" ); $response = $this->getResponse( '* SEARCH' ); if ( strpos( $response, '* SEARCH' ) !== false ) { $response = trim( substr( $response, 9 ) ); if ( $response !== "" ) { $uids = explode( ' ', $response ); } for ( $i = 0; $i < count( $messages ); $i++ ) { $result[trim( $messages[$i] )] = $uids[$i]; } } $response = trim( $this->getResponse( $tag ) ); } if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not fetch the unique identifiers: {$response}." ); } return $result; }
php
public function listUniqueIdentifiers( $msgNum = null ) { if ( $this->state != self::STATE_SELECTED && $this->state != self::STATE_SELECTED_READONLY ) { throw new ezcMailTransportException( "Can't call listUniqueIdentifiers() on the IMAP transport when a mailbox is not selected." ); } $result = array(); if ( $msgNum !== null ) { $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} UID SEARCH {$msgNum}" ); $response = $this->getResponse( '* SEARCH' ); if ( strpos( $response, '* SEARCH' ) !== false ) { $result[(int)$msgNum] = trim( substr( $response, 9 ) ); } $response = trim( $this->getResponse( $tag, $response ) ); } else { $uids = array(); $messages = array_keys( $this->listMessages() ); $tag = $this->getNextTag(); $this->connection->sendData( "{$tag} UID SEARCH UNDELETED" ); $response = $this->getResponse( '* SEARCH' ); if ( strpos( $response, '* SEARCH' ) !== false ) { $response = trim( substr( $response, 9 ) ); if ( $response !== "" ) { $uids = explode( ' ', $response ); } for ( $i = 0; $i < count( $messages ); $i++ ) { $result[trim( $messages[$i] )] = $uids[$i]; } } $response = trim( $this->getResponse( $tag ) ); } if ( $this->responseType( $response ) != self::RESPONSE_OK ) { throw new ezcMailTransportException( "The IMAP server could not fetch the unique identifiers: {$response}." ); } return $result; }
[ "public", "function", "listUniqueIdentifiers", "(", "$", "msgNum", "=", "null", ")", "{", "if", "(", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED", "&&", "$", "this", "->", "state", "!=", "self", "::", "STATE_SELECTED_READONLY", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"Can't call listUniqueIdentifiers() on the IMAP transport when a mailbox is not selected.\"", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "if", "(", "$", "msgNum", "!==", "null", ")", "{", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} UID SEARCH {$msgNum}\"", ")", ";", "$", "response", "=", "$", "this", "->", "getResponse", "(", "'* SEARCH'", ")", ";", "if", "(", "strpos", "(", "$", "response", ",", "'* SEARCH'", ")", "!==", "false", ")", "{", "$", "result", "[", "(", "int", ")", "$", "msgNum", "]", "=", "trim", "(", "substr", "(", "$", "response", ",", "9", ")", ")", ";", "}", "$", "response", "=", "trim", "(", "$", "this", "->", "getResponse", "(", "$", "tag", ",", "$", "response", ")", ")", ";", "}", "else", "{", "$", "uids", "=", "array", "(", ")", ";", "$", "messages", "=", "array_keys", "(", "$", "this", "->", "listMessages", "(", ")", ")", ";", "$", "tag", "=", "$", "this", "->", "getNextTag", "(", ")", ";", "$", "this", "->", "connection", "->", "sendData", "(", "\"{$tag} UID SEARCH UNDELETED\"", ")", ";", "$", "response", "=", "$", "this", "->", "getResponse", "(", "'* SEARCH'", ")", ";", "if", "(", "strpos", "(", "$", "response", ",", "'* SEARCH'", ")", "!==", "false", ")", "{", "$", "response", "=", "trim", "(", "substr", "(", "$", "response", ",", "9", ")", ")", ";", "if", "(", "$", "response", "!==", "\"\"", ")", "{", "$", "uids", "=", "explode", "(", "' '", ",", "$", "response", ")", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "messages", ")", ";", "$", "i", "++", ")", "{", "$", "result", "[", "trim", "(", "$", "messages", "[", "$", "i", "]", ")", "]", "=", "$", "uids", "[", "$", "i", "]", ";", "}", "}", "$", "response", "=", "trim", "(", "$", "this", "->", "getResponse", "(", "$", "tag", ")", ")", ";", "}", "if", "(", "$", "this", "->", "responseType", "(", "$", "response", ")", "!=", "self", "::", "RESPONSE_OK", ")", "{", "throw", "new", "ezcMailTransportException", "(", "\"The IMAP server could not fetch the unique identifiers: {$response}.\"", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns the unique identifiers for the messages from the current mailbox. You can fetch the unique identifier for a specific message by providing the $msgNum parameter. The unique identifier can be used to recognize mail from servers between requests. In contrast to the message numbers the unique numbers assigned to an email usually never changes. The format of the returned array is: <code> array( message_num => unique_id ); </code> Example: <code> array( 1 => 216, 2 => 217, 3 => 218, 4 => 219 ); </code> Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully, and a mailbox must be selected. @todo add UIVALIDITY value to UID (like in POP3) (if necessary). @throws ezcMailTransportException if a mailbox is not selected or if the server sent a negative response @param int $msgNum @return array(string)
[ "Returns", "the", "unique", "identifiers", "for", "the", "messages", "from", "the", "current", "mailbox", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L1389-L1435
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php
ezcMailImapTransport.fetchAll
public function fetchAll( $deleteFromServer = false ) { if ( $this->options->uidReferencing ) { $messages = array_values( $this->listUniqueIdentifiers() ); } else { $messages = array_keys( $this->listMessages() ); } return new ezcMailImapSet( $this->connection, $messages, $deleteFromServer, array( 'uidReferencing' => $this->options->uidReferencing ) ); }
php
public function fetchAll( $deleteFromServer = false ) { if ( $this->options->uidReferencing ) { $messages = array_values( $this->listUniqueIdentifiers() ); } else { $messages = array_keys( $this->listMessages() ); } return new ezcMailImapSet( $this->connection, $messages, $deleteFromServer, array( 'uidReferencing' => $this->options->uidReferencing ) ); }
[ "public", "function", "fetchAll", "(", "$", "deleteFromServer", "=", "false", ")", "{", "if", "(", "$", "this", "->", "options", "->", "uidReferencing", ")", "{", "$", "messages", "=", "array_values", "(", "$", "this", "->", "listUniqueIdentifiers", "(", ")", ")", ";", "}", "else", "{", "$", "messages", "=", "array_keys", "(", "$", "this", "->", "listMessages", "(", ")", ")", ";", "}", "return", "new", "ezcMailImapSet", "(", "$", "this", "->", "connection", ",", "$", "messages", ",", "$", "deleteFromServer", ",", "array", "(", "'uidReferencing'", "=>", "$", "this", "->", "options", "->", "uidReferencing", ")", ")", ";", "}" ]
Returns an {@link ezcMailImapSet} with all the messages from the current mailbox. This method supports unique IDs instead of message numbers. See {@link ezcMailImapTransportOptions} for how to enable unique IDs referencing. If $deleteFromServer is set to true the mail will be marked for deletion after retrieval. If not it will be left intact. The set returned can be parsed with {@link ezcMailParser}. Before calling this method, a connection to the IMAP server must be established and a user must be authenticated successfully, and a mailbox must be selected. Example: <code> $imap = new ezcMailImapTransport( 'imap.example.com' ); $imap->authenticate( 'username', 'password' ); $imap->selectMailbox( 'Inbox' ); $set = $imap->fetchAll(); // parse $set with ezcMailParser $parser = new ezcMailParser(); $mails = $parser->parseMail( $set ); foreach ( $mails as $mail ) { // process $mail which is an ezcMail object } </code> @throws ezcMailTransportException if a mailbox is not selected or if the server sent a negative response @param bool $deleteFromServer @return ezcMailParserSet
[ "Returns", "an", "{", "@link", "ezcMailImapSet", "}", "with", "all", "the", "messages", "from", "the", "current", "mailbox", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/imap/imap_transport.php#L1476-L1488