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
PayBreak/foundation
src/Decision/Condition/LessThanCondition.php
LessThanCondition.checkCondition
public function checkCondition(Value $value) { if ($this->compareType($value) === false) { return false; } if (!in_array($value->getType(), [Value::VALUE_INT, Value::VALUE_FLOAT])) { throw new ProcessingException('This condition can be performed only over int and float types.'); } if ($value->getValue() < $this->getValue()->getValue()) { return true; } return false; }
php
public function checkCondition(Value $value) { if ($this->compareType($value) === false) { return false; } if (!in_array($value->getType(), [Value::VALUE_INT, Value::VALUE_FLOAT])) { throw new ProcessingException('This condition can be performed only over int and float types.'); } if ($value->getValue() < $this->getValue()->getValue()) { return true; } return false; }
[ "public", "function", "checkCondition", "(", "Value", "$", "value", ")", "{", "if", "(", "$", "this", "->", "compareType", "(", "$", "value", ")", "===", "false", ")", "{", "return", "false", ";", "}", "if", "(", "!", "in_array", "(", "$", "value", "->", "getType", "(", ")", ",", "[", "Value", "::", "VALUE_INT", ",", "Value", "::", "VALUE_FLOAT", "]", ")", ")", "{", "throw", "new", "ProcessingException", "(", "'This condition can be performed only over int and float types.'", ")", ";", "}", "if", "(", "$", "value", "->", "getValue", "(", ")", "<", "$", "this", "->", "getValue", "(", ")", "->", "getValue", "(", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Test Value against Condition @param Value $value @return bool @throws ProcessingException
[ "Test", "Value", "against", "Condition" ]
train
https://github.com/PayBreak/foundation/blob/3dc5a5791e0c95abefa2a415a7f9fdb5abb62ca4/src/Decision/Condition/LessThanCondition.php#L39-L54
dstuecken/notify
src/Handler/HeaderHandler.php
HeaderHandler.handle
public function handle(NotificationInterface $notification, $level) { if (!headers_sent()) { if ($notification instanceof AttributeAwareInterface) { $options = $notification->attributes(); } else { $options = []; } if ($notification instanceof TitleAwareInterface) { $options['header'] = $notification->title(); } header( 'X-' . $this->identifier . '-Notification-' . self::$messageindex++ . ':' . json_encode( [ 'message' => $notification->message(), 'type' => isset($this->levelMapping[$level]) ? $this->levelMapping[$level] : self::STANDARD, 'options' => $options ] ) ); return true; } return true; }
php
public function handle(NotificationInterface $notification, $level) { if (!headers_sent()) { if ($notification instanceof AttributeAwareInterface) { $options = $notification->attributes(); } else { $options = []; } if ($notification instanceof TitleAwareInterface) { $options['header'] = $notification->title(); } header( 'X-' . $this->identifier . '-Notification-' . self::$messageindex++ . ':' . json_encode( [ 'message' => $notification->message(), 'type' => isset($this->levelMapping[$level]) ? $this->levelMapping[$level] : self::STANDARD, 'options' => $options ] ) ); return true; } return true; }
[ "public", "function", "handle", "(", "NotificationInterface", "$", "notification", ",", "$", "level", ")", "{", "if", "(", "!", "headers_sent", "(", ")", ")", "{", "if", "(", "$", "notification", "instanceof", "AttributeAwareInterface", ")", "{", "$", "options", "=", "$", "notification", "->", "attributes", "(", ")", ";", "}", "else", "{", "$", "options", "=", "[", "]", ";", "}", "if", "(", "$", "notification", "instanceof", "TitleAwareInterface", ")", "{", "$", "options", "[", "'header'", "]", "=", "$", "notification", "->", "title", "(", ")", ";", "}", "header", "(", "'X-'", ".", "$", "this", "->", "identifier", ".", "'-Notification-'", ".", "self", "::", "$", "messageindex", "++", ".", "':'", ".", "json_encode", "(", "[", "'message'", "=>", "$", "notification", "->", "message", "(", ")", ",", "'type'", "=>", "isset", "(", "$", "this", "->", "levelMapping", "[", "$", "level", "]", ")", "?", "$", "this", "->", "levelMapping", "[", "$", "level", "]", ":", "self", "::", "STANDARD", ",", "'options'", "=>", "$", "options", "]", ")", ")", ";", "return", "true", ";", "}", "return", "true", ";", "}" ]
Handle a notification @return bool
[ "Handle", "a", "notification" ]
train
https://github.com/dstuecken/notify/blob/abccf0a6a272caf66baea74323f18e2212c6e11e/src/Handler/HeaderHandler.php#L101-L134
dstuecken/notify
src/Handler/HeaderHandler.php
HeaderHandler.formatAttributes
public static function formatAttributes($destroy_callback = null, $create_callback = null, $sticky = null, $life = null, $classname = null, $width = null) { $options = []; if ($destroy_callback !== null) { $options['destroyed'] = $destroy_callback; } // if if ($create_callback !== null) { $options['created'] = $create_callback; } // if if ($sticky !== null) { $options['sticky'] = !!$sticky; } // if if ($life !== null) { $options['life'] = $life; } // if if ($classname !== null) { $options['className'] = $classname; } // if if ($width !== null) { $options['width'] = $width; } // if return $options; }
php
public static function formatAttributes($destroy_callback = null, $create_callback = null, $sticky = null, $life = null, $classname = null, $width = null) { $options = []; if ($destroy_callback !== null) { $options['destroyed'] = $destroy_callback; } // if if ($create_callback !== null) { $options['created'] = $create_callback; } // if if ($sticky !== null) { $options['sticky'] = !!$sticky; } // if if ($life !== null) { $options['life'] = $life; } // if if ($classname !== null) { $options['className'] = $classname; } // if if ($width !== null) { $options['width'] = $width; } // if return $options; }
[ "public", "static", "function", "formatAttributes", "(", "$", "destroy_callback", "=", "null", ",", "$", "create_callback", "=", "null", ",", "$", "sticky", "=", "null", ",", "$", "life", "=", "null", ",", "$", "classname", "=", "null", ",", "$", "width", "=", "null", ")", "{", "$", "options", "=", "[", "]", ";", "if", "(", "$", "destroy_callback", "!==", "null", ")", "{", "$", "options", "[", "'destroyed'", "]", "=", "$", "destroy_callback", ";", "}", "// if", "if", "(", "$", "create_callback", "!==", "null", ")", "{", "$", "options", "[", "'created'", "]", "=", "$", "create_callback", ";", "}", "// if", "if", "(", "$", "sticky", "!==", "null", ")", "{", "$", "options", "[", "'sticky'", "]", "=", "!", "!", "$", "sticky", ";", "}", "// if", "if", "(", "$", "life", "!==", "null", ")", "{", "$", "options", "[", "'life'", "]", "=", "$", "life", ";", "}", "// if", "if", "(", "$", "classname", "!==", "null", ")", "{", "$", "options", "[", "'className'", "]", "=", "$", "classname", ";", "}", "// if", "if", "(", "$", "width", "!==", "null", ")", "{", "$", "options", "[", "'width'", "]", "=", "$", "width", ";", "}", "// if", "return", "$", "options", ";", "}" ]
Static method for retrieving the options-array. @param string $destroy_callback @param string $create_callback @param boolean $sticky @param integer $life @param string $classname @param integer $width @return array
[ "Static", "method", "for", "retrieving", "the", "options", "-", "array", "." ]
train
https://github.com/dstuecken/notify/blob/abccf0a6a272caf66baea74323f18e2212c6e11e/src/Handler/HeaderHandler.php#L149-L184
welderlourenco/laravel-facebook
src/WelderLourenco/Facebook/Facebook.php
Facebook.getFacebookSession
private function getFacebookSession($accessToken) { $facebookSession = new FacebookSession($accessToken); try { $facebookSession->validate(); return $facebookSession; } catch (FacebookRequestException $ex) { throw new FacebookException($ex->getMessage()); } catch (\Exception $ex) { throw new FacebookException($ex->getMessage()); } }
php
private function getFacebookSession($accessToken) { $facebookSession = new FacebookSession($accessToken); try { $facebookSession->validate(); return $facebookSession; } catch (FacebookRequestException $ex) { throw new FacebookException($ex->getMessage()); } catch (\Exception $ex) { throw new FacebookException($ex->getMessage()); } }
[ "private", "function", "getFacebookSession", "(", "$", "accessToken", ")", "{", "$", "facebookSession", "=", "new", "FacebookSession", "(", "$", "accessToken", ")", ";", "try", "{", "$", "facebookSession", "->", "validate", "(", ")", ";", "return", "$", "facebookSession", ";", "}", "catch", "(", "FacebookRequestException", "$", "ex", ")", "{", "throw", "new", "FacebookException", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "throw", "new", "FacebookException", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Get the FacebookSession through an access_token. @param string $accessToken @return FacebookSession
[ "Get", "the", "FacebookSession", "through", "an", "access_token", "." ]
train
https://github.com/welderlourenco/laravel-facebook/blob/e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd/src/WelderLourenco/Facebook/Facebook.php#L74-L92
welderlourenco/laravel-facebook
src/WelderLourenco/Facebook/Facebook.php
Facebook.connect
public function connect($accessToken = null) { if (is_null($accessToken)) { return $this->getRedirectLoginHelper(); } else { return $this->getFacebookSession($accessToken); } }
php
public function connect($accessToken = null) { if (is_null($accessToken)) { return $this->getRedirectLoginHelper(); } else { return $this->getFacebookSession($accessToken); } }
[ "public", "function", "connect", "(", "$", "accessToken", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "accessToken", ")", ")", "{", "return", "$", "this", "->", "getRedirectLoginHelper", "(", ")", ";", "}", "else", "{", "return", "$", "this", "->", "getFacebookSession", "(", "$", "accessToken", ")", ";", "}", "}" ]
Trigger method that can get either a facebook session with access token or a redirect login helper. @param string $accessToken The facebook access token. @return mixed
[ "Trigger", "method", "that", "can", "get", "either", "a", "facebook", "session", "with", "access", "token", "or", "a", "redirect", "login", "helper", "." ]
train
https://github.com/welderlourenco/laravel-facebook/blob/e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd/src/WelderLourenco/Facebook/Facebook.php#L100-L110
welderlourenco/laravel-facebook
src/WelderLourenco/Facebook/Facebook.php
Facebook.process
public function process() { try { $redirectLoginHelper = $this->getRedirectLoginHelper(); return $this->connect($redirectLoginHelper->getSessionFromRedirect()->getToken()); } catch(FacebookRequestException $ex) { throw new FacebookException($ex->getMessage()); } catch(\Exception $ex) { throw new FacebookException($ex->getMessage()); } }
php
public function process() { try { $redirectLoginHelper = $this->getRedirectLoginHelper(); return $this->connect($redirectLoginHelper->getSessionFromRedirect()->getToken()); } catch(FacebookRequestException $ex) { throw new FacebookException($ex->getMessage()); } catch(\Exception $ex) { throw new FacebookException($ex->getMessage()); } }
[ "public", "function", "process", "(", ")", "{", "try", "{", "$", "redirectLoginHelper", "=", "$", "this", "->", "getRedirectLoginHelper", "(", ")", ";", "return", "$", "this", "->", "connect", "(", "$", "redirectLoginHelper", "->", "getSessionFromRedirect", "(", ")", "->", "getToken", "(", ")", ")", ";", "}", "catch", "(", "FacebookRequestException", "$", "ex", ")", "{", "throw", "new", "FacebookException", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "throw", "new", "FacebookException", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Get the redirect postback sent from facebook processed, ready to a facebook session. @return connect($accessToken)
[ "Get", "the", "redirect", "postback", "sent", "from", "facebook", "processed", "ready", "to", "a", "facebook", "session", "." ]
train
https://github.com/welderlourenco/laravel-facebook/blob/e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd/src/WelderLourenco/Facebook/Facebook.php#L117-L133
welderlourenco/laravel-facebook
src/WelderLourenco/Facebook/Facebook.php
Facebook.api
public function api(FacebookSession $fbsession, $method, $call) { try { $facebookResponse = (new FacebookRequest($fbsession, $method, $call))->execute(); return $graphObject = $facebookResponse->getGraphObject(); } catch (FacebookRequestException $ex) { throw new FacebookException($ex->getMessage()); } catch (\Exception $ex) { throw new FacebookException($ex->getMessage()); } }
php
public function api(FacebookSession $fbsession, $method, $call) { try { $facebookResponse = (new FacebookRequest($fbsession, $method, $call))->execute(); return $graphObject = $facebookResponse->getGraphObject(); } catch (FacebookRequestException $ex) { throw new FacebookException($ex->getMessage()); } catch (\Exception $ex) { throw new FacebookException($ex->getMessage()); } }
[ "public", "function", "api", "(", "FacebookSession", "$", "fbsession", ",", "$", "method", ",", "$", "call", ")", "{", "try", "{", "$", "facebookResponse", "=", "(", "new", "FacebookRequest", "(", "$", "fbsession", ",", "$", "method", ",", "$", "call", ")", ")", "->", "execute", "(", ")", ";", "return", "$", "graphObject", "=", "$", "facebookResponse", "->", "getGraphObject", "(", ")", ";", "}", "catch", "(", "FacebookRequestException", "$", "ex", ")", "{", "throw", "new", "FacebookException", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "ex", ")", "{", "throw", "new", "FacebookException", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Make a request into facebook api. @param FacebookSession $fbsession @param string $method @param string $call @return FacebookRequest
[ "Make", "a", "request", "into", "facebook", "api", "." ]
train
https://github.com/welderlourenco/laravel-facebook/blob/e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd/src/WelderLourenco/Facebook/Facebook.php#L143-L159
welderlourenco/laravel-facebook
src/WelderLourenco/Facebook/Facebook.php
Facebook.change
public function change($appId, $appSecret, $redirectUrl = null) { \Config::set('facebook::app.appId', $appId); \Config::set('facebook::app.appSecret', $appSecret); if (!is_null($redirectUrl)) \Config::set('facebook::app.redirectUrl', $redirectUrl); return $this; }
php
public function change($appId, $appSecret, $redirectUrl = null) { \Config::set('facebook::app.appId', $appId); \Config::set('facebook::app.appSecret', $appSecret); if (!is_null($redirectUrl)) \Config::set('facebook::app.redirectUrl', $redirectUrl); return $this; }
[ "public", "function", "change", "(", "$", "appId", ",", "$", "appSecret", ",", "$", "redirectUrl", "=", "null", ")", "{", "\\", "Config", "::", "set", "(", "'facebook::app.appId'", ",", "$", "appId", ")", ";", "\\", "Config", "::", "set", "(", "'facebook::app.appSecret'", ",", "$", "appSecret", ")", ";", "if", "(", "!", "is_null", "(", "$", "redirectUrl", ")", ")", "\\", "Config", "::", "set", "(", "'facebook::app.redirectUrl'", ",", "$", "redirectUrl", ")", ";", "return", "$", "this", ";", "}" ]
Change the appId, appSecret and redirectUrl before connecting. @param string $appId @param string $appSecret @param string $redireectUrl @return this
[ "Change", "the", "appId", "appSecret", "and", "redirectUrl", "before", "connecting", "." ]
train
https://github.com/welderlourenco/laravel-facebook/blob/e0c80ab5ff1c95b634da8c15a5fd3c00ded232dd/src/WelderLourenco/Facebook/Facebook.php#L169-L176
php-lug/lug
src/Component/Grid/Action/ActionRenderer.php
ActionRenderer.resolveTypes
private function resolveTypes($type) { $actionTypes = []; do { $actionTypes[] = $actionType = $this->actionRegistry[$type]; } while (($type = $actionType->getParent()) !== null); return $actionTypes; }
php
private function resolveTypes($type) { $actionTypes = []; do { $actionTypes[] = $actionType = $this->actionRegistry[$type]; } while (($type = $actionType->getParent()) !== null); return $actionTypes; }
[ "private", "function", "resolveTypes", "(", "$", "type", ")", "{", "$", "actionTypes", "=", "[", "]", ";", "do", "{", "$", "actionTypes", "[", "]", "=", "$", "actionType", "=", "$", "this", "->", "actionRegistry", "[", "$", "type", "]", ";", "}", "while", "(", "(", "$", "type", "=", "$", "actionType", "->", "getParent", "(", ")", ")", "!==", "null", ")", ";", "return", "$", "actionTypes", ";", "}" ]
@param string $type @return TypeInterface[]
[ "@param", "string", "$type" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Action/ActionRenderer.php#L71-L80
gyselroth/micro-container
src/Container.php
Container.has
public function has($name): bool { try { $this->container->get($name); return true; } catch (\Exception $e) { return false; } }
php
public function has($name): bool { try { $this->container->get($name); return true; } catch (\Exception $e) { return false; } }
[ "public", "function", "has", "(", "$", "name", ")", ":", "bool", "{", "try", "{", "$", "this", "->", "container", "->", "get", "(", "$", "name", ")", ";", "return", "true", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
Check if service is registered.
[ "Check", "if", "service", "is", "registered", "." ]
train
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/Container.php#L52-L61
php-lug/lug
src/Bundle/GridBundle/Model/Builder/GridBuilder.php
GridBuilder.buildColumn
protected function buildColumn(array $config, array $parentConfig) { return parent::buildColumn(array_merge( ['label' => $this->prepareLabel('column', $config, $parentConfig)], $config ), $parentConfig); }
php
protected function buildColumn(array $config, array $parentConfig) { return parent::buildColumn(array_merge( ['label' => $this->prepareLabel('column', $config, $parentConfig)], $config ), $parentConfig); }
[ "protected", "function", "buildColumn", "(", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "parent", "::", "buildColumn", "(", "array_merge", "(", "[", "'label'", "=>", "$", "this", "->", "prepareLabel", "(", "'column'", ",", "$", "config", ",", "$", "parentConfig", ")", "]", ",", "$", "config", ")", ",", "$", "parentConfig", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Model/Builder/GridBuilder.php#L24-L30
php-lug/lug
src/Bundle/GridBundle/Model/Builder/GridBuilder.php
GridBuilder.buildFilter
protected function buildFilter(array $config, array $parentConfig) { return parent::buildFilter(array_merge( ['label' => $this->prepareLabel('filter', $config, $parentConfig)], $config ), $parentConfig); }
php
protected function buildFilter(array $config, array $parentConfig) { return parent::buildFilter(array_merge( ['label' => $this->prepareLabel('filter', $config, $parentConfig)], $config ), $parentConfig); }
[ "protected", "function", "buildFilter", "(", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "parent", "::", "buildFilter", "(", "array_merge", "(", "[", "'label'", "=>", "$", "this", "->", "prepareLabel", "(", "'filter'", ",", "$", "config", ",", "$", "parentConfig", ")", "]", ",", "$", "config", ")", ",", "$", "parentConfig", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Model/Builder/GridBuilder.php#L35-L41
php-lug/lug
src/Bundle/GridBundle/Model/Builder/GridBuilder.php
GridBuilder.buildColumnAction
protected function buildColumnAction(array $config, array $parentConfig) { return parent::buildColumnAction(array_merge( ['label' => $this->prepareLabel('column_action', $config, $parentConfig)], $config ), $parentConfig); }
php
protected function buildColumnAction(array $config, array $parentConfig) { return parent::buildColumnAction(array_merge( ['label' => $this->prepareLabel('column_action', $config, $parentConfig)], $config ), $parentConfig); }
[ "protected", "function", "buildColumnAction", "(", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "parent", "::", "buildColumnAction", "(", "array_merge", "(", "[", "'label'", "=>", "$", "this", "->", "prepareLabel", "(", "'column_action'", ",", "$", "config", ",", "$", "parentConfig", ")", "]", ",", "$", "config", ")", ",", "$", "parentConfig", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Model/Builder/GridBuilder.php#L46-L52
php-lug/lug
src/Bundle/GridBundle/Model/Builder/GridBuilder.php
GridBuilder.buildGlobalAction
protected function buildGlobalAction(array $config, array $parentConfig) { return parent::buildGlobalAction(array_merge( ['label' => $this->prepareLabel('global_action', $config, $parentConfig)], $config ), $parentConfig); }
php
protected function buildGlobalAction(array $config, array $parentConfig) { return parent::buildGlobalAction(array_merge( ['label' => $this->prepareLabel('global_action', $config, $parentConfig)], $config ), $parentConfig); }
[ "protected", "function", "buildGlobalAction", "(", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "parent", "::", "buildGlobalAction", "(", "array_merge", "(", "[", "'label'", "=>", "$", "this", "->", "prepareLabel", "(", "'global_action'", ",", "$", "config", ",", "$", "parentConfig", ")", "]", ",", "$", "config", ")", ",", "$", "parentConfig", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Model/Builder/GridBuilder.php#L57-L63
php-lug/lug
src/Bundle/GridBundle/Model/Builder/GridBuilder.php
GridBuilder.buildBatch
protected function buildBatch(array $config, array $parentConfig) { return parent::buildBatch(array_merge( ['label' => $this->prepareLabel('batch', $config, $parentConfig)], $config ), $parentConfig); }
php
protected function buildBatch(array $config, array $parentConfig) { return parent::buildBatch(array_merge( ['label' => $this->prepareLabel('batch', $config, $parentConfig)], $config ), $parentConfig); }
[ "protected", "function", "buildBatch", "(", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "parent", "::", "buildBatch", "(", "array_merge", "(", "[", "'label'", "=>", "$", "this", "->", "prepareLabel", "(", "'batch'", ",", "$", "config", ",", "$", "parentConfig", ")", "]", ",", "$", "config", ")", ",", "$", "parentConfig", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Model/Builder/GridBuilder.php#L68-L74
php-lug/lug
src/Bundle/GridBundle/Model/Builder/GridBuilder.php
GridBuilder.prepareConfig
protected function prepareConfig(array $config, array $parentConfig = []) { $config['options'] = array_merge( $default = ['trans_domain' => 'grids'], isset($parentConfig['options']) ? array_intersect_key($parentConfig['options'], $default) : [], isset($config['options']) ? $config['options'] : [] ); return parent::prepareConfig($config, $parentConfig); }
php
protected function prepareConfig(array $config, array $parentConfig = []) { $config['options'] = array_merge( $default = ['trans_domain' => 'grids'], isset($parentConfig['options']) ? array_intersect_key($parentConfig['options'], $default) : [], isset($config['options']) ? $config['options'] : [] ); return parent::prepareConfig($config, $parentConfig); }
[ "protected", "function", "prepareConfig", "(", "array", "$", "config", ",", "array", "$", "parentConfig", "=", "[", "]", ")", "{", "$", "config", "[", "'options'", "]", "=", "array_merge", "(", "$", "default", "=", "[", "'trans_domain'", "=>", "'grids'", "]", ",", "isset", "(", "$", "parentConfig", "[", "'options'", "]", ")", "?", "array_intersect_key", "(", "$", "parentConfig", "[", "'options'", "]", ",", "$", "default", ")", ":", "[", "]", ",", "isset", "(", "$", "config", "[", "'options'", "]", ")", "?", "$", "config", "[", "'options'", "]", ":", "[", "]", ")", ";", "return", "parent", "::", "prepareConfig", "(", "$", "config", ",", "$", "parentConfig", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Model/Builder/GridBuilder.php#L79-L88
php-lug/lug
src/Bundle/GridBundle/Model/Builder/GridBuilder.php
GridBuilder.prepareLabel
protected function prepareLabel($type, array $config, array $parentConfig) { return $label = isset($config['label']) ? $config['label'] : 'lug.'.$this->buildResource($parentConfig)->getName().'.'.$type.'.'.$config['name']; }
php
protected function prepareLabel($type, array $config, array $parentConfig) { return $label = isset($config['label']) ? $config['label'] : 'lug.'.$this->buildResource($parentConfig)->getName().'.'.$type.'.'.$config['name']; }
[ "protected", "function", "prepareLabel", "(", "$", "type", ",", "array", "$", "config", ",", "array", "$", "parentConfig", ")", "{", "return", "$", "label", "=", "isset", "(", "$", "config", "[", "'label'", "]", ")", "?", "$", "config", "[", "'label'", "]", ":", "'lug.'", ".", "$", "this", "->", "buildResource", "(", "$", "parentConfig", ")", "->", "getName", "(", ")", ".", "'.'", ".", "$", "type", ".", "'.'", ".", "$", "config", "[", "'name'", "]", ";", "}" ]
@param string $type @param mixed[] $config @param mixed[] $parentConfig @return string
[ "@param", "string", "$type", "@param", "mixed", "[]", "$config", "@param", "mixed", "[]", "$parentConfig" ]
train
https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Model/Builder/GridBuilder.php#L97-L102
Danzabar/config-builder
src/Files/FileInfo.php
FileInfo.load
public function load($file) { $details = pathinfo($file); $this->filename = $details['basename']; $this->extension = $details['extension']; $this->directory = $details['dirname']; }
php
public function load($file) { $details = pathinfo($file); $this->filename = $details['basename']; $this->extension = $details['extension']; $this->directory = $details['dirname']; }
[ "public", "function", "load", "(", "$", "file", ")", "{", "$", "details", "=", "pathinfo", "(", "$", "file", ")", ";", "$", "this", "->", "filename", "=", "$", "details", "[", "'basename'", "]", ";", "$", "this", "->", "extension", "=", "$", "details", "[", "'extension'", "]", ";", "$", "this", "->", "directory", "=", "$", "details", "[", "'dirname'", "]", ";", "}" ]
Gather Details @param String $file @return void @author Dan Cox
[ "Gather", "Details" ]
train
https://github.com/Danzabar/config-builder/blob/3b237be578172c32498bbcdfb360e69a6243739d/src/Files/FileInfo.php#L40-L46
GrupaZero/api
src/Gzero/Api/Transformer/BlockTranslationTransformer.php
BlockTranslationTransformer.transform
public function transform($translation) { $translation = $this->entityToArray(BlockTranslation::class, $translation); return [ 'id' => (int) $translation['id'], 'langCode' => $translation['lang_code'], 'title' => $translation['title'], 'body' => $translation['body'], 'customFields' => $this->transformCustomFields($translation), 'isActive' => (bool) $translation['is_active'], 'createdAt' => $translation['created_at'], 'updatedAt' => $translation['updated_at'], ]; }
php
public function transform($translation) { $translation = $this->entityToArray(BlockTranslation::class, $translation); return [ 'id' => (int) $translation['id'], 'langCode' => $translation['lang_code'], 'title' => $translation['title'], 'body' => $translation['body'], 'customFields' => $this->transformCustomFields($translation), 'isActive' => (bool) $translation['is_active'], 'createdAt' => $translation['created_at'], 'updatedAt' => $translation['updated_at'], ]; }
[ "public", "function", "transform", "(", "$", "translation", ")", "{", "$", "translation", "=", "$", "this", "->", "entityToArray", "(", "BlockTranslation", "::", "class", ",", "$", "translation", ")", ";", "return", "[", "'id'", "=>", "(", "int", ")", "$", "translation", "[", "'id'", "]", ",", "'langCode'", "=>", "$", "translation", "[", "'lang_code'", "]", ",", "'title'", "=>", "$", "translation", "[", "'title'", "]", ",", "'body'", "=>", "$", "translation", "[", "'body'", "]", ",", "'customFields'", "=>", "$", "this", "->", "transformCustomFields", "(", "$", "translation", ")", ",", "'isActive'", "=>", "(", "bool", ")", "$", "translation", "[", "'is_active'", "]", ",", "'createdAt'", "=>", "$", "translation", "[", "'created_at'", "]", ",", "'updatedAt'", "=>", "$", "translation", "[", "'updated_at'", "]", ",", "]", ";", "}" ]
Transforms block translation entity @param BlockTranslation|array $translation BlockTranslation entity @return array
[ "Transforms", "block", "translation", "entity" ]
train
https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Transformer/BlockTranslationTransformer.php#L26-L39
JBZoo/Profiler
src/Profiler.php
Profiler.start
public function start($registerTick = true) { $this->_startTime = microtime(true); $this->_startMemory = memory_get_usage(false); if ($registerTick && Sys::isFunc('register_tick_function')) { register_tick_function(array($this, 'tick')); } }
php
public function start($registerTick = true) { $this->_startTime = microtime(true); $this->_startMemory = memory_get_usage(false); if ($registerTick && Sys::isFunc('register_tick_function')) { register_tick_function(array($this, 'tick')); } }
[ "public", "function", "start", "(", "$", "registerTick", "=", "true", ")", "{", "$", "this", "->", "_startTime", "=", "microtime", "(", "true", ")", ";", "$", "this", "->", "_startMemory", "=", "memory_get_usage", "(", "false", ")", ";", "if", "(", "$", "registerTick", "&&", "Sys", "::", "isFunc", "(", "'register_tick_function'", ")", ")", "{", "register_tick_function", "(", "array", "(", "$", "this", ",", "'tick'", ")", ")", ";", "}", "}" ]
Start profiler @param bool $registerTick
[ "Start", "profiler" ]
train
https://github.com/JBZoo/Profiler/blob/a4af3d2feb558ab9cd78012e0ca5c8dc7872fc69/src/Profiler.php#L52-L60
JBZoo/Profiler
src/Profiler.php
Profiler.stop
public function stop() { $this->_endTime = microtime(true); $this->tick(); if (Sys::isFunc('unregister_tick_function')) { unregister_tick_function(array($this, 'tick')); } }
php
public function stop() { $this->_endTime = microtime(true); $this->tick(); if (Sys::isFunc('unregister_tick_function')) { unregister_tick_function(array($this, 'tick')); } }
[ "public", "function", "stop", "(", ")", "{", "$", "this", "->", "_endTime", "=", "microtime", "(", "true", ")", ";", "$", "this", "->", "tick", "(", ")", ";", "if", "(", "Sys", "::", "isFunc", "(", "'unregister_tick_function'", ")", ")", "{", "unregister_tick_function", "(", "array", "(", "$", "this", ",", "'tick'", ")", ")", ";", "}", "}" ]
Stop profiler
[ "Stop", "profiler" ]
train
https://github.com/JBZoo/Profiler/blob/a4af3d2feb558ab9cd78012e0ca5c8dc7872fc69/src/Profiler.php#L73-L81
JBZoo/Profiler
src/Profiler.php
Profiler.resourceUsage
public static function resourceUsage($getPeakMemory = true, $isRealMemory = false) { if ($getPeakMemory) { $message = 'Time: %s, Peak memory: %s'; $memory = memory_get_peak_usage($isRealMemory); } else { $message = 'Time: %s, Memory: %s'; $memory = memory_get_usage($isRealMemory); } $memory = FS::format($memory, 2); $time = Timer::format(Timer::timeSinceStart()); return sprintf($message, $time, $memory); }
php
public static function resourceUsage($getPeakMemory = true, $isRealMemory = false) { if ($getPeakMemory) { $message = 'Time: %s, Peak memory: %s'; $memory = memory_get_peak_usage($isRealMemory); } else { $message = 'Time: %s, Memory: %s'; $memory = memory_get_usage($isRealMemory); } $memory = FS::format($memory, 2); $time = Timer::format(Timer::timeSinceStart()); return sprintf($message, $time, $memory); }
[ "public", "static", "function", "resourceUsage", "(", "$", "getPeakMemory", "=", "true", ",", "$", "isRealMemory", "=", "false", ")", "{", "if", "(", "$", "getPeakMemory", ")", "{", "$", "message", "=", "'Time: %s, Peak memory: %s'", ";", "$", "memory", "=", "memory_get_peak_usage", "(", "$", "isRealMemory", ")", ";", "}", "else", "{", "$", "message", "=", "'Time: %s, Memory: %s'", ";", "$", "memory", "=", "memory_get_usage", "(", "$", "isRealMemory", ")", ";", "}", "$", "memory", "=", "FS", "::", "format", "(", "$", "memory", ",", "2", ")", ";", "$", "time", "=", "Timer", "::", "format", "(", "Timer", "::", "timeSinceStart", "(", ")", ")", ";", "return", "sprintf", "(", "$", "message", ",", "$", "time", ",", "$", "memory", ")", ";", "}" ]
Returns the resources (time, memory) of the request as a string. @param bool $getPeakMemory @param bool $isRealMemory @return string
[ "Returns", "the", "resources", "(", "time", "memory", ")", "of", "the", "request", "as", "a", "string", "." ]
train
https://github.com/JBZoo/Profiler/blob/a4af3d2feb558ab9cd78012e0ca5c8dc7872fc69/src/Profiler.php#L118-L132
SporkCode/Spork
src/DateTime/DateInterval.php
DateInterval.toSeconds
public function toSeconds() { $seconds = $this->s; $seconds += $this->i * 60; $seconds += $this->h * 3600; if ($this->days) { $seconds += $this->days * 86400; } else { if ($this->d) { $seconds += $this->d * 86400; } if ($this->m) { trigger_error('Calculating seconds for interval with months property. Result may not be accurate.', E_USER_WARNING); $seconds += 2629800; } if ($this->y) { trigger_error('Calculating seconds for interval with years property. Result may not be accurate.', E_USER_WARNING); $seconds += $this->y * 31557600; } } return $seconds; }
php
public function toSeconds() { $seconds = $this->s; $seconds += $this->i * 60; $seconds += $this->h * 3600; if ($this->days) { $seconds += $this->days * 86400; } else { if ($this->d) { $seconds += $this->d * 86400; } if ($this->m) { trigger_error('Calculating seconds for interval with months property. Result may not be accurate.', E_USER_WARNING); $seconds += 2629800; } if ($this->y) { trigger_error('Calculating seconds for interval with years property. Result may not be accurate.', E_USER_WARNING); $seconds += $this->y * 31557600; } } return $seconds; }
[ "public", "function", "toSeconds", "(", ")", "{", "$", "seconds", "=", "$", "this", "->", "s", ";", "$", "seconds", "+=", "$", "this", "->", "i", "*", "60", ";", "$", "seconds", "+=", "$", "this", "->", "h", "*", "3600", ";", "if", "(", "$", "this", "->", "days", ")", "{", "$", "seconds", "+=", "$", "this", "->", "days", "*", "86400", ";", "}", "else", "{", "if", "(", "$", "this", "->", "d", ")", "{", "$", "seconds", "+=", "$", "this", "->", "d", "*", "86400", ";", "}", "if", "(", "$", "this", "->", "m", ")", "{", "trigger_error", "(", "'Calculating seconds for interval with months property. Result may not be accurate.'", ",", "E_USER_WARNING", ")", ";", "$", "seconds", "+=", "2629800", ";", "}", "if", "(", "$", "this", "->", "y", ")", "{", "trigger_error", "(", "'Calculating seconds for interval with years property. Result may not be accurate.'", ",", "E_USER_WARNING", ")", ";", "$", "seconds", "+=", "$", "this", "->", "y", "*", "31557600", ";", "}", "}", "return", "$", "seconds", ";", "}" ]
Convert interval to number of seconds @return integer
[ "Convert", "interval", "to", "number", "of", "seconds" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/DateTime/DateInterval.php#L47-L69
SporkCode/Spork
src/DateTime/DateInterval.php
DateInterval.isQuirkMode
protected static function isQuirkMode() { if (null === self::$quirkMode) { self::$quirkMode = version_compare(PHP_VERSION, '5.5.4', '<') && version_compare(PHP_VERSION, '5.5.0', '>') || version_compare(PHP_VERSION, '5.4.20', '<'); } return self::$quirkMode; }
php
protected static function isQuirkMode() { if (null === self::$quirkMode) { self::$quirkMode = version_compare(PHP_VERSION, '5.5.4', '<') && version_compare(PHP_VERSION, '5.5.0', '>') || version_compare(PHP_VERSION, '5.4.20', '<'); } return self::$quirkMode; }
[ "protected", "static", "function", "isQuirkMode", "(", ")", "{", "if", "(", "null", "===", "self", "::", "$", "quirkMode", ")", "{", "self", "::", "$", "quirkMode", "=", "version_compare", "(", "PHP_VERSION", ",", "'5.5.4'", ",", "'<'", ")", "&&", "version_compare", "(", "PHP_VERSION", ",", "'5.5.0'", ",", "'>'", ")", "||", "version_compare", "(", "PHP_VERSION", ",", "'5.4.20'", ",", "'<'", ")", ";", "}", "return", "self", "::", "$", "quirkMode", ";", "}" ]
Test if PHP version has quirks @return boolean
[ "Test", "if", "PHP", "version", "has", "quirks" ]
train
https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/DateTime/DateInterval.php#L75-L83
zicht/z
src/Zicht/Tool/Packager/Node/DynamicStub.php
DynamicStub.compileInitialization
protected function compileInitialization(Buffer $buffer) { $buffer->write('$app = new Zicht\Tool\Application(') ->asPhp($this->appName) ->raw(', Zicht\Version\Version::fromString(') ->asPhp($this->appVersion) ->raw(') ?: new Zicht\Version\Version(), Zicht\Tool\Configuration\ConfigurationLoader::fromEnv(')->asPhp($this->configFilename)->raw(')') ->raw(');') ->eol(); }
php
protected function compileInitialization(Buffer $buffer) { $buffer->write('$app = new Zicht\Tool\Application(') ->asPhp($this->appName) ->raw(', Zicht\Version\Version::fromString(') ->asPhp($this->appVersion) ->raw(') ?: new Zicht\Version\Version(), Zicht\Tool\Configuration\ConfigurationLoader::fromEnv(')->asPhp($this->configFilename)->raw(')') ->raw(');') ->eol(); }
[ "protected", "function", "compileInitialization", "(", "Buffer", "$", "buffer", ")", "{", "$", "buffer", "->", "write", "(", "'$app = new Zicht\\Tool\\Application('", ")", "->", "asPhp", "(", "$", "this", "->", "appName", ")", "->", "raw", "(", "', Zicht\\Version\\Version::fromString('", ")", "->", "asPhp", "(", "$", "this", "->", "appVersion", ")", "->", "raw", "(", "') ?: new Zicht\\Version\\Version(), Zicht\\Tool\\Configuration\\ConfigurationLoader::fromEnv('", ")", "->", "asPhp", "(", "$", "this", "->", "configFilename", ")", "->", "raw", "(", "')'", ")", "->", "raw", "(", "');'", ")", "->", "eol", "(", ")", ";", "}" ]
Writes the initialization code for a dynamic build @param \Zicht\Tool\Script\Buffer $buffer @return void
[ "Writes", "the", "initialization", "code", "for", "a", "dynamic", "build" ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Packager/Node/DynamicStub.php#L38-L47
zhouyl/mellivora
Mellivora/Application/Container.php
Container.make
public function make($abstract, array $parameters = []) { if ($this->offsetExists($abstract)) { return $this->offsetGet($abstract); } if (!class_exists($abstract)) { throw new RuntimeException("Can not make an undefined class [$abstract]"); } $reflector = new ReflectionClass($abstract); // 检测是否可实例化 if (!$reflector->isInstantiable()) { throw new RuntimeException("The class [$abstract] is not instantiable."); } $instance = $reflector->newInstanceArgs($parameters); $this->offsetSet($abstract, $instance); return $instance; }
php
public function make($abstract, array $parameters = []) { if ($this->offsetExists($abstract)) { return $this->offsetGet($abstract); } if (!class_exists($abstract)) { throw new RuntimeException("Can not make an undefined class [$abstract]"); } $reflector = new ReflectionClass($abstract); // 检测是否可实例化 if (!$reflector->isInstantiable()) { throw new RuntimeException("The class [$abstract] is not instantiable."); } $instance = $reflector->newInstanceArgs($parameters); $this->offsetSet($abstract, $instance); return $instance; }
[ "public", "function", "make", "(", "$", "abstract", ",", "array", "$", "parameters", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "offsetExists", "(", "$", "abstract", ")", ")", "{", "return", "$", "this", "->", "offsetGet", "(", "$", "abstract", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "abstract", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"Can not make an undefined class [$abstract]\"", ")", ";", "}", "$", "reflector", "=", "new", "ReflectionClass", "(", "$", "abstract", ")", ";", "// 检测是否可实例化", "if", "(", "!", "$", "reflector", "->", "isInstantiable", "(", ")", ")", "{", "throw", "new", "RuntimeException", "(", "\"The class [$abstract] is not instantiable.\"", ")", ";", "}", "$", "instance", "=", "$", "reflector", "->", "newInstanceArgs", "(", "$", "parameters", ")", ";", "$", "this", "->", "offsetSet", "(", "$", "abstract", ",", "$", "instance", ")", ";", "return", "$", "instance", ";", "}" ]
为兼容 laravel 组件而编写的方法 @param string $abstract @param array $parameters @throws \RuntimeException @return mixed
[ "为兼容", "laravel", "组件而编写的方法" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Application/Container.php#L78-L100
zhouyl/mellivora
Mellivora/Application/Container.php
Container.getAbstractId
protected function getAbstractId($id) { if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } return $id; }
php
protected function getAbstractId($id) { if (isset($this->aliases[$id])) { $id = $this->aliases[$id]; } return $id; }
[ "protected", "function", "getAbstractId", "(", "$", "id", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "aliases", "[", "$", "id", "]", ")", ")", "{", "$", "id", "=", "$", "this", "->", "aliases", "[", "$", "id", "]", ";", "}", "return", "$", "id", ";", "}" ]
将 class name 转换为 id @param string $id @return string
[ "将", "class", "name", "转换为", "id" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Application/Container.php#L123-L130
zhouyl/mellivora
Mellivora/Application/Container.php
Container.offsetSet
public function offsetSet($id, $value) { // Pimple/Container 不允许重写,这里重新处理 if (parent::offsetExists($id)) { parent::offsetUnset($id); } parent::offsetSet($id, $value); if (is_object($id)) { $this->aliases[get_class($id)] = $id; } else { // 重新注册时,需要删除旧的别名依赖 unset($this->aliases[$id]); } }
php
public function offsetSet($id, $value) { // Pimple/Container 不允许重写,这里重新处理 if (parent::offsetExists($id)) { parent::offsetUnset($id); } parent::offsetSet($id, $value); if (is_object($id)) { $this->aliases[get_class($id)] = $id; } else { // 重新注册时,需要删除旧的别名依赖 unset($this->aliases[$id]); } }
[ "public", "function", "offsetSet", "(", "$", "id", ",", "$", "value", ")", "{", "// Pimple/Container 不允许重写,这里重新处理", "if", "(", "parent", "::", "offsetExists", "(", "$", "id", ")", ")", "{", "parent", "::", "offsetUnset", "(", "$", "id", ")", ";", "}", "parent", "::", "offsetSet", "(", "$", "id", ",", "$", "value", ")", ";", "if", "(", "is_object", "(", "$", "id", ")", ")", "{", "$", "this", "->", "aliases", "[", "get_class", "(", "$", "id", ")", "]", "=", "$", "id", ";", "}", "else", "{", "// 重新注册时,需要删除旧的别名依赖", "unset", "(", "$", "this", "->", "aliases", "[", "$", "id", "]", ")", ";", "}", "}" ]
魔术方法重写或补充
[ "魔术方法重写或补充" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Application/Container.php#L134-L149
alevilar/ristorantino-vendor
Risto/Controller/ConfigsController.php
ConfigsController.add
public function add() { if ($this->request->is('post')) { $this->Config->create(); if ($this->Config->save($this->request->data)) { $this->Flash->success(__('The config has been saved.')); return $this->redirect(array('action' => 'index')); } else { $this->Flash->error(__('The config could not be saved. Please, try again.')); } } $configCategoryes = $this->Config->ConfigCategory->find('list'); $this->set(compact('configCategoryes')); }
php
public function add() { if ($this->request->is('post')) { $this->Config->create(); if ($this->Config->save($this->request->data)) { $this->Flash->success(__('The config has been saved.')); return $this->redirect(array('action' => 'index')); } else { $this->Flash->error(__('The config could not be saved. Please, try again.')); } } $configCategoryes = $this->Config->ConfigCategory->find('list'); $this->set(compact('configCategoryes')); }
[ "public", "function", "add", "(", ")", "{", "if", "(", "$", "this", "->", "request", "->", "is", "(", "'post'", ")", ")", "{", "$", "this", "->", "Config", "->", "create", "(", ")", ";", "if", "(", "$", "this", "->", "Config", "->", "save", "(", "$", "this", "->", "request", "->", "data", ")", ")", "{", "$", "this", "->", "Flash", "->", "success", "(", "__", "(", "'The config has been saved.'", ")", ")", ";", "return", "$", "this", "->", "redirect", "(", "array", "(", "'action'", "=>", "'index'", ")", ")", ";", "}", "else", "{", "$", "this", "->", "Flash", "->", "error", "(", "__", "(", "'The config could not be saved. Please, try again.'", ")", ")", ";", "}", "}", "$", "configCategoryes", "=", "$", "this", "->", "Config", "->", "ConfigCategory", "->", "find", "(", "'list'", ")", ";", "$", "this", "->", "set", "(", "compact", "(", "'configCategoryes'", ")", ")", ";", "}" ]
add method @return void
[ "add", "method" ]
train
https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Controller/ConfigsController.php#L48-L60
alevilar/ristorantino-vendor
Risto/Controller/ConfigsController.php
ConfigsController.edit
public function edit($id = null) { if (!$this->Config->exists($id)) { throw new NotFoundException(__('Invalid config')); } if ($this->request->is(array('post', 'put'))) { if ($this->Config->save($this->request->data)) { $this->Flash->success(__('The config has been saved.')); return $this->redirect(array('action' => 'index')); } else { $this->Flash->error(__('The config could not be saved. Please, try again.')); } } else { $options = array('conditions' => array('Config.' . $this->Config->primaryKey => $id)); $this->request->data = $this->Config->find('first', $options); } $configCategoryes = $this->Config->ConfigCategory->find('list'); $this->set(compact('configCategoryes')); }
php
public function edit($id = null) { if (!$this->Config->exists($id)) { throw new NotFoundException(__('Invalid config')); } if ($this->request->is(array('post', 'put'))) { if ($this->Config->save($this->request->data)) { $this->Flash->success(__('The config has been saved.')); return $this->redirect(array('action' => 'index')); } else { $this->Flash->error(__('The config could not be saved. Please, try again.')); } } else { $options = array('conditions' => array('Config.' . $this->Config->primaryKey => $id)); $this->request->data = $this->Config->find('first', $options); } $configCategoryes = $this->Config->ConfigCategory->find('list'); $this->set(compact('configCategoryes')); }
[ "public", "function", "edit", "(", "$", "id", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "Config", "->", "exists", "(", "$", "id", ")", ")", "{", "throw", "new", "NotFoundException", "(", "__", "(", "'Invalid config'", ")", ")", ";", "}", "if", "(", "$", "this", "->", "request", "->", "is", "(", "array", "(", "'post'", ",", "'put'", ")", ")", ")", "{", "if", "(", "$", "this", "->", "Config", "->", "save", "(", "$", "this", "->", "request", "->", "data", ")", ")", "{", "$", "this", "->", "Flash", "->", "success", "(", "__", "(", "'The config has been saved.'", ")", ")", ";", "return", "$", "this", "->", "redirect", "(", "array", "(", "'action'", "=>", "'index'", ")", ")", ";", "}", "else", "{", "$", "this", "->", "Flash", "->", "error", "(", "__", "(", "'The config could not be saved. Please, try again.'", ")", ")", ";", "}", "}", "else", "{", "$", "options", "=", "array", "(", "'conditions'", "=>", "array", "(", "'Config.'", ".", "$", "this", "->", "Config", "->", "primaryKey", "=>", "$", "id", ")", ")", ";", "$", "this", "->", "request", "->", "data", "=", "$", "this", "->", "Config", "->", "find", "(", "'first'", ",", "$", "options", ")", ";", "}", "$", "configCategoryes", "=", "$", "this", "->", "Config", "->", "ConfigCategory", "->", "find", "(", "'list'", ")", ";", "$", "this", "->", "set", "(", "compact", "(", "'configCategoryes'", ")", ")", ";", "}" ]
edit method @throws NotFoundException @param string $id @return void
[ "edit", "method" ]
train
https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Controller/ConfigsController.php#L69-L86
wplibs/rules
src/Operator/Is_Null.php
Is_Null.evaluate
public function evaluate( Context $context ) { /* @var \Ruler\Variable $left */ list( $left ) = $this->getOperands(); return null === $left->prepareValue( $context )->getValue(); }
php
public function evaluate( Context $context ) { /* @var \Ruler\Variable $left */ list( $left ) = $this->getOperands(); return null === $left->prepareValue( $context )->getValue(); }
[ "public", "function", "evaluate", "(", "Context", "$", "context", ")", "{", "/* @var \\Ruler\\Variable $left */", "list", "(", "$", "left", ")", "=", "$", "this", "->", "getOperands", "(", ")", ";", "return", "null", "===", "$", "left", "->", "prepareValue", "(", "$", "context", ")", "->", "getValue", "(", ")", ";", "}" ]
Evaluate the operands. @param Context $context Context with which to evaluate this Proposition. @return boolean
[ "Evaluate", "the", "operands", "." ]
train
https://github.com/wplibs/rules/blob/29b4495e2ae87349fd64fcd844f3ba96cc268e3d/src/Operator/Is_Null.php#L16-L21
nabab/bbn
src/bbn/html/builder.php
builder.reset
public function reset() { $this->_current_cfg = []; $this->_cfg = []; $this->_root_element = false; $this->_current_element = false; foreach ( $this->_defaults as $k => $v ){ $this->_current_cfg[$k] = $v; } return $this; }
php
public function reset() { $this->_current_cfg = []; $this->_cfg = []; $this->_root_element = false; $this->_current_element = false; foreach ( $this->_defaults as $k => $v ){ $this->_current_cfg[$k] = $v; } return $this; }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "_current_cfg", "=", "[", "]", ";", "$", "this", "->", "_cfg", "=", "[", "]", ";", "$", "this", "->", "_root_element", "=", "false", ";", "$", "this", "->", "_current_element", "=", "false", ";", "foreach", "(", "$", "this", "->", "_defaults", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "_current_cfg", "[", "$", "k", "]", "=", "$", "v", ";", "}", "return", "$", "this", ";", "}" ]
Sets the configuration back to its default value
[ "Sets", "the", "configuration", "back", "to", "its", "default", "value" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/builder.php#L133-L143
nabab/bbn
src/bbn/html/builder.php
builder.export_config
public function export_config() { if ( isset($this->_root_element) ){ return bbn\str::make_readable($this->_root_element->get_config()); } return bbn\str::make_readable($this->_cfg); }
php
public function export_config() { if ( isset($this->_root_element) ){ return bbn\str::make_readable($this->_root_element->get_config()); } return bbn\str::make_readable($this->_cfg); }
[ "public", "function", "export_config", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_root_element", ")", ")", "{", "return", "bbn", "\\", "str", "::", "make_readable", "(", "$", "this", "->", "_root_element", "->", "get_config", "(", ")", ")", ";", "}", "return", "bbn", "\\", "str", "::", "make_readable", "(", "$", "this", "->", "_cfg", ")", ";", "}" ]
Returns the current configuration @return array
[ "Returns", "the", "current", "configuration" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/builder.php#L162-L168
nabab/bbn
src/bbn/html/builder.php
builder.option
public function option($opt) { $args = \func_get_args(); if ( \is_array($opt) && isset($opt[0], $this->_defaults[$opt[0]]) ){ $this->_current_cfg[$opt[0]] = $opt[1]; } else if ( isset($args[0], $args[1], $this->_defaults[$args[0]]) ){ $this->_current_cfg[$args[0]] = $args[1]; } else{ throw new InvalidArgumentException('This configuration argument is imaginary... Sorry! :)'); } return $this; }
php
public function option($opt) { $args = \func_get_args(); if ( \is_array($opt) && isset($opt[0], $this->_defaults[$opt[0]]) ){ $this->_current_cfg[$opt[0]] = $opt[1]; } else if ( isset($args[0], $args[1], $this->_defaults[$args[0]]) ){ $this->_current_cfg[$args[0]] = $args[1]; } else{ throw new InvalidArgumentException('This configuration argument is imaginary... Sorry! :)'); } return $this; }
[ "public", "function", "option", "(", "$", "opt", ")", "{", "$", "args", "=", "\\", "func_get_args", "(", ")", ";", "if", "(", "\\", "is_array", "(", "$", "opt", ")", "&&", "isset", "(", "$", "opt", "[", "0", "]", ",", "$", "this", "->", "_defaults", "[", "$", "opt", "[", "0", "]", "]", ")", ")", "{", "$", "this", "->", "_current_cfg", "[", "$", "opt", "[", "0", "]", "]", "=", "$", "opt", "[", "1", "]", ";", "}", "else", "if", "(", "isset", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ",", "$", "this", "->", "_defaults", "[", "$", "args", "[", "0", "]", "]", ")", ")", "{", "$", "this", "->", "_current_cfg", "[", "$", "args", "[", "0", "]", "]", "=", "$", "args", "[", "1", "]", ";", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "'This configuration argument is imaginary... Sorry! :)'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Change an option in the current configuration - Chainable @param array|string $opt Either an array with the param name and value, or 2 strings in the same order @return bbn\html\builder
[ "Change", "an", "option", "in", "the", "current", "configuration", "-", "Chainable" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/builder.php#L207-L220
nabab/bbn
src/bbn/html/builder.php
builder.input
public function input($cfg=array()) { if ( \is_array($cfg) && isset($cfg['attr']['name']) ){ self::give_id($cfg); if ( isset($cfg['field']) ){ $cfg = bbn\x::merge_arrays(self::specs('fields', $cfg['field']), $cfg); } /* if ( !isset($cfg['tag']) ){ $cfg['tag'] = 'input'; } if ( !isset($cfg['attr']['type']) ){ $cfg['attr']['type'] = 'text'; } */ if ( isset($cfg['data']) ){ if ( isset($cfg['data']['sql'], $this->_current_cfg['data']['db']) ){ $db =& $this->_current_cfg['data']['db']; if ( !isset($cfg['widget']['options']['dataSource']) ){ $cfg['widget']['options']['dataSource'] = []; } $count = ( $r = $db->query($cfg['data']['sql']) ) ? $r->count() : 0; if ( $count <= self::max_values_at_once ){ if ( $ds = $db->get_irows($cfg['data']['sql']) ){ foreach ( $ds as $d ){ if ( \count($d) > 1 ){ array_push($cfg['widget']['options']['dataSource'], [ 'value' => $d[0], 'text' => $d[1] ]); } else{ array_push($cfg['widget']['options']['dataSource'], $d[0]); } } } } else{ $cfg['field'] = 'autocomplete'; } } else if ( \is_array($cfg['data']) && (\count($cfg['data']) > 0) ){ if ( isset($cfg['data'][0]) ){ $cfg['widget']['options']['dataSource'] = $cfg['data']; } else{ $cfg['widget']['options']['dataSource'] = []; foreach ( $cfg['data'] as $k => $v ){ array_push($cfg['widget']['options']['dataSource'], [ 'value' => $k, 'text' => $v ]); } } } if ( isset($cfg['widget']['options']['dataSource'][0]['text']) ){ $cfg['widget']['options']['dataTextField'] = 'text'; $cfg['widget']['options']['dataValueField'] = 'value'; } } if ( \is_array($cfg) ){ // Size calculation if ( isset($cfg['attr']['maxlength']) && !isset($cfg['attr']['size']) ){ if ( $cfg['attr']['maxlength'] <= 20 ){ $cfg['attr']['size'] = (int)$cfg['attr']['maxlength']; } } if ( isset($cfg['attr']['size'], $cfg['attr']['minlength']) && $cfg['attr']['size'] < $cfg['attr']['minlength']){ $cfg['attr']['size'] = (int)$cfg['attr']['minlength']; } $cfg = array_filter($cfg, function($a){ return !( \is_array($a) && \count($a) === 0 ); }); } if ( isset($cfg['null']) && $cfg['null'] ){ if ( empty($cfg['attr']['value']) ){ $cfg['attr']['value'] = null; $cfg['attr']['disabled'] = true; if ( isset($cfg['widget']) ){ if ( !isset($cfg['script']) ){ $cfg['script'] = ''; } /* $cfg['script'] .= 'if ( $("#'.$cfg['attr']['id'].'").data("'.$cfg['widget']['name'].'") ){ $("#'.$cfg['attr']['id'].'").data("'.$cfg['widget']['name'].'").enable(false); } else if ( $("#'.$cfg['attr']['id'].'").'.$cfg['widget']['name'].' ){ $("#'.$cfg['attr']['id'].'").'.$cfg['widget']['name'].'("enable", false); }'; * */ } } } $t = new input($cfg); return $t; } return false; }
php
public function input($cfg=array()) { if ( \is_array($cfg) && isset($cfg['attr']['name']) ){ self::give_id($cfg); if ( isset($cfg['field']) ){ $cfg = bbn\x::merge_arrays(self::specs('fields', $cfg['field']), $cfg); } /* if ( !isset($cfg['tag']) ){ $cfg['tag'] = 'input'; } if ( !isset($cfg['attr']['type']) ){ $cfg['attr']['type'] = 'text'; } */ if ( isset($cfg['data']) ){ if ( isset($cfg['data']['sql'], $this->_current_cfg['data']['db']) ){ $db =& $this->_current_cfg['data']['db']; if ( !isset($cfg['widget']['options']['dataSource']) ){ $cfg['widget']['options']['dataSource'] = []; } $count = ( $r = $db->query($cfg['data']['sql']) ) ? $r->count() : 0; if ( $count <= self::max_values_at_once ){ if ( $ds = $db->get_irows($cfg['data']['sql']) ){ foreach ( $ds as $d ){ if ( \count($d) > 1 ){ array_push($cfg['widget']['options']['dataSource'], [ 'value' => $d[0], 'text' => $d[1] ]); } else{ array_push($cfg['widget']['options']['dataSource'], $d[0]); } } } } else{ $cfg['field'] = 'autocomplete'; } } else if ( \is_array($cfg['data']) && (\count($cfg['data']) > 0) ){ if ( isset($cfg['data'][0]) ){ $cfg['widget']['options']['dataSource'] = $cfg['data']; } else{ $cfg['widget']['options']['dataSource'] = []; foreach ( $cfg['data'] as $k => $v ){ array_push($cfg['widget']['options']['dataSource'], [ 'value' => $k, 'text' => $v ]); } } } if ( isset($cfg['widget']['options']['dataSource'][0]['text']) ){ $cfg['widget']['options']['dataTextField'] = 'text'; $cfg['widget']['options']['dataValueField'] = 'value'; } } if ( \is_array($cfg) ){ // Size calculation if ( isset($cfg['attr']['maxlength']) && !isset($cfg['attr']['size']) ){ if ( $cfg['attr']['maxlength'] <= 20 ){ $cfg['attr']['size'] = (int)$cfg['attr']['maxlength']; } } if ( isset($cfg['attr']['size'], $cfg['attr']['minlength']) && $cfg['attr']['size'] < $cfg['attr']['minlength']){ $cfg['attr']['size'] = (int)$cfg['attr']['minlength']; } $cfg = array_filter($cfg, function($a){ return !( \is_array($a) && \count($a) === 0 ); }); } if ( isset($cfg['null']) && $cfg['null'] ){ if ( empty($cfg['attr']['value']) ){ $cfg['attr']['value'] = null; $cfg['attr']['disabled'] = true; if ( isset($cfg['widget']) ){ if ( !isset($cfg['script']) ){ $cfg['script'] = ''; } /* $cfg['script'] .= 'if ( $("#'.$cfg['attr']['id'].'").data("'.$cfg['widget']['name'].'") ){ $("#'.$cfg['attr']['id'].'").data("'.$cfg['widget']['name'].'").enable(false); } else if ( $("#'.$cfg['attr']['id'].'").'.$cfg['widget']['name'].' ){ $("#'.$cfg['attr']['id'].'").'.$cfg['widget']['name'].'("enable", false); }'; * */ } } } $t = new input($cfg); return $t; } return false; }
[ "public", "function", "input", "(", "$", "cfg", "=", "array", "(", ")", ")", "{", "if", "(", "\\", "is_array", "(", "$", "cfg", ")", "&&", "isset", "(", "$", "cfg", "[", "'attr'", "]", "[", "'name'", "]", ")", ")", "{", "self", "::", "give_id", "(", "$", "cfg", ")", ";", "if", "(", "isset", "(", "$", "cfg", "[", "'field'", "]", ")", ")", "{", "$", "cfg", "=", "bbn", "\\", "x", "::", "merge_arrays", "(", "self", "::", "specs", "(", "'fields'", ",", "$", "cfg", "[", "'field'", "]", ")", ",", "$", "cfg", ")", ";", "}", "/*\n if ( !isset($cfg['tag']) ){\n $cfg['tag'] = 'input';\n }\n if ( !isset($cfg['attr']['type']) ){\n $cfg['attr']['type'] = 'text';\n }\n */", "if", "(", "isset", "(", "$", "cfg", "[", "'data'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "cfg", "[", "'data'", "]", "[", "'sql'", "]", ",", "$", "this", "->", "_current_cfg", "[", "'data'", "]", "[", "'db'", "]", ")", ")", "{", "$", "db", "=", "&", "$", "this", "->", "_current_cfg", "[", "'data'", "]", "[", "'db'", "]", ";", "if", "(", "!", "isset", "(", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'dataSource'", "]", ")", ")", "{", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'dataSource'", "]", "=", "[", "]", ";", "}", "$", "count", "=", "(", "$", "r", "=", "$", "db", "->", "query", "(", "$", "cfg", "[", "'data'", "]", "[", "'sql'", "]", ")", ")", "?", "$", "r", "->", "count", "(", ")", ":", "0", ";", "if", "(", "$", "count", "<=", "self", "::", "max_values_at_once", ")", "{", "if", "(", "$", "ds", "=", "$", "db", "->", "get_irows", "(", "$", "cfg", "[", "'data'", "]", "[", "'sql'", "]", ")", ")", "{", "foreach", "(", "$", "ds", "as", "$", "d", ")", "{", "if", "(", "\\", "count", "(", "$", "d", ")", ">", "1", ")", "{", "array_push", "(", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'dataSource'", "]", ",", "[", "'value'", "=>", "$", "d", "[", "0", "]", ",", "'text'", "=>", "$", "d", "[", "1", "]", "]", ")", ";", "}", "else", "{", "array_push", "(", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'dataSource'", "]", ",", "$", "d", "[", "0", "]", ")", ";", "}", "}", "}", "}", "else", "{", "$", "cfg", "[", "'field'", "]", "=", "'autocomplete'", ";", "}", "}", "else", "if", "(", "\\", "is_array", "(", "$", "cfg", "[", "'data'", "]", ")", "&&", "(", "\\", "count", "(", "$", "cfg", "[", "'data'", "]", ")", ">", "0", ")", ")", "{", "if", "(", "isset", "(", "$", "cfg", "[", "'data'", "]", "[", "0", "]", ")", ")", "{", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'dataSource'", "]", "=", "$", "cfg", "[", "'data'", "]", ";", "}", "else", "{", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'dataSource'", "]", "=", "[", "]", ";", "foreach", "(", "$", "cfg", "[", "'data'", "]", "as", "$", "k", "=>", "$", "v", ")", "{", "array_push", "(", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'dataSource'", "]", ",", "[", "'value'", "=>", "$", "k", ",", "'text'", "=>", "$", "v", "]", ")", ";", "}", "}", "}", "if", "(", "isset", "(", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'dataSource'", "]", "[", "0", "]", "[", "'text'", "]", ")", ")", "{", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'dataTextField'", "]", "=", "'text'", ";", "$", "cfg", "[", "'widget'", "]", "[", "'options'", "]", "[", "'dataValueField'", "]", "=", "'value'", ";", "}", "}", "if", "(", "\\", "is_array", "(", "$", "cfg", ")", ")", "{", "// Size calculation", "if", "(", "isset", "(", "$", "cfg", "[", "'attr'", "]", "[", "'maxlength'", "]", ")", "&&", "!", "isset", "(", "$", "cfg", "[", "'attr'", "]", "[", "'size'", "]", ")", ")", "{", "if", "(", "$", "cfg", "[", "'attr'", "]", "[", "'maxlength'", "]", "<=", "20", ")", "{", "$", "cfg", "[", "'attr'", "]", "[", "'size'", "]", "=", "(", "int", ")", "$", "cfg", "[", "'attr'", "]", "[", "'maxlength'", "]", ";", "}", "}", "if", "(", "isset", "(", "$", "cfg", "[", "'attr'", "]", "[", "'size'", "]", ",", "$", "cfg", "[", "'attr'", "]", "[", "'minlength'", "]", ")", "&&", "$", "cfg", "[", "'attr'", "]", "[", "'size'", "]", "<", "$", "cfg", "[", "'attr'", "]", "[", "'minlength'", "]", ")", "{", "$", "cfg", "[", "'attr'", "]", "[", "'size'", "]", "=", "(", "int", ")", "$", "cfg", "[", "'attr'", "]", "[", "'minlength'", "]", ";", "}", "$", "cfg", "=", "array_filter", "(", "$", "cfg", ",", "function", "(", "$", "a", ")", "{", "return", "!", "(", "\\", "is_array", "(", "$", "a", ")", "&&", "\\", "count", "(", "$", "a", ")", "===", "0", ")", ";", "}", ")", ";", "}", "if", "(", "isset", "(", "$", "cfg", "[", "'null'", "]", ")", "&&", "$", "cfg", "[", "'null'", "]", ")", "{", "if", "(", "empty", "(", "$", "cfg", "[", "'attr'", "]", "[", "'value'", "]", ")", ")", "{", "$", "cfg", "[", "'attr'", "]", "[", "'value'", "]", "=", "null", ";", "$", "cfg", "[", "'attr'", "]", "[", "'disabled'", "]", "=", "true", ";", "if", "(", "isset", "(", "$", "cfg", "[", "'widget'", "]", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "cfg", "[", "'script'", "]", ")", ")", "{", "$", "cfg", "[", "'script'", "]", "=", "''", ";", "}", "/*\n $cfg['script'] .= 'if ( $(\"#'.$cfg['attr']['id'].'\").data(\"'.$cfg['widget']['name'].'\") ){\n $(\"#'.$cfg['attr']['id'].'\").data(\"'.$cfg['widget']['name'].'\").enable(false);\n }\n else if ( $(\"#'.$cfg['attr']['id'].'\").'.$cfg['widget']['name'].' ){\n $(\"#'.$cfg['attr']['id'].'\").'.$cfg['widget']['name'].'(\"enable\", false);\n }';\n * \n */", "}", "}", "}", "$", "t", "=", "new", "input", "(", "$", "cfg", ")", ";", "return", "$", "t", ";", "}", "return", "false", ";", "}" ]
Generates a whole input configuration array by combining the passed and default configurations @param array $cfg The input's config @return array
[ "Generates", "a", "whole", "input", "configuration", "array", "by", "combining", "the", "passed", "and", "default", "configurations" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/html/builder.php#L478-L586
mayconpaivac/l5-validation
src/Prettus/Validator/AbstractValidator.php
AbstractValidator.passesOrFail
public function passesOrFail($action = null) { if( !$this->passes($action) ){ throw new ValidatorException( $this->errorsBag() ); } return true; }
php
public function passesOrFail($action = null) { if( !$this->passes($action) ){ throw new ValidatorException( $this->errorsBag() ); } return true; }
[ "public", "function", "passesOrFail", "(", "$", "action", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "passes", "(", "$", "action", ")", ")", "{", "throw", "new", "ValidatorException", "(", "$", "this", "->", "errorsBag", "(", ")", ")", ";", "}", "return", "true", ";", "}" ]
Pass the data and the rules to the validator or throws ValidatorException @throws ValidatorException @param string $action @return boolean
[ "Pass", "the", "data", "and", "the", "rules", "to", "the", "validator", "or", "throws", "ValidatorException" ]
train
https://github.com/mayconpaivac/l5-validation/blob/0921391d7d9cf2853dd5667fb47c1450a251a0d8/src/Prettus/Validator/AbstractValidator.php#L110-L117
mayconpaivac/l5-validation
src/Prettus/Validator/AbstractValidator.php
AbstractValidator.getRules
public function getRules($action = null){ $rules = $this->rules; if( isset($this->rules[$action]) ){ $rules = $this->rules[$action]; } return $this->parserValidationRules($rules, $this->id); }
php
public function getRules($action = null){ $rules = $this->rules; if( isset($this->rules[$action]) ){ $rules = $this->rules[$action]; } return $this->parserValidationRules($rules, $this->id); }
[ "public", "function", "getRules", "(", "$", "action", "=", "null", ")", "{", "$", "rules", "=", "$", "this", "->", "rules", ";", "if", "(", "isset", "(", "$", "this", "->", "rules", "[", "$", "action", "]", ")", ")", "{", "$", "rules", "=", "$", "this", "->", "rules", "[", "$", "action", "]", ";", "}", "return", "$", "this", "->", "parserValidationRules", "(", "$", "rules", ",", "$", "this", "->", "id", ")", ";", "}" ]
Get rule for validation by action ValidatorInterface::RULE_CREATE or ValidatorInterface::RULE_UPDATE Default rule: ValidatorInterface::RULE_CREATE @param null $action @return array
[ "Get", "rule", "for", "validation", "by", "action", "ValidatorInterface", "::", "RULE_CREATE", "or", "ValidatorInterface", "::", "RULE_UPDATE" ]
train
https://github.com/mayconpaivac/l5-validation/blob/0921391d7d9cf2853dd5667fb47c1450a251a0d8/src/Prettus/Validator/AbstractValidator.php#L144-L153
mayconpaivac/l5-validation
src/Prettus/Validator/AbstractValidator.php
AbstractValidator.parserValidationRules
protected function parserValidationRules($rules, $id = null) { if($id === null) { return $rules; } array_walk($rules, function(&$rules, $field) use ($id) { if(!is_array($rules)) { $rules = explode("|", $rules); } foreach($rules as $ruleIdx => $rule) { // get name and parameters @list($name, $params) = array_pad(explode(":", $rule), 2, null); // only do someting for the unique rule if(strtolower($name) != "unique") { continue; // continue in foreach loop, nothing left to do here } $p = array_map("trim", explode(",", $params)); // set field name to rules key ($field) (laravel convention) if(!isset($p[1])) { $p[1] = $field; } // set 3rd parameter to id given to getValidationRules() $p[2] = $id; $params = implode(",", $p); $rules[$ruleIdx] = $name.":".$params; } }); return $rules; }
php
protected function parserValidationRules($rules, $id = null) { if($id === null) { return $rules; } array_walk($rules, function(&$rules, $field) use ($id) { if(!is_array($rules)) { $rules = explode("|", $rules); } foreach($rules as $ruleIdx => $rule) { // get name and parameters @list($name, $params) = array_pad(explode(":", $rule), 2, null); // only do someting for the unique rule if(strtolower($name) != "unique") { continue; // continue in foreach loop, nothing left to do here } $p = array_map("trim", explode(",", $params)); // set field name to rules key ($field) (laravel convention) if(!isset($p[1])) { $p[1] = $field; } // set 3rd parameter to id given to getValidationRules() $p[2] = $id; $params = implode(",", $p); $rules[$ruleIdx] = $name.":".$params; } }); return $rules; }
[ "protected", "function", "parserValidationRules", "(", "$", "rules", ",", "$", "id", "=", "null", ")", "{", "if", "(", "$", "id", "===", "null", ")", "{", "return", "$", "rules", ";", "}", "array_walk", "(", "$", "rules", ",", "function", "(", "&", "$", "rules", ",", "$", "field", ")", "use", "(", "$", "id", ")", "{", "if", "(", "!", "is_array", "(", "$", "rules", ")", ")", "{", "$", "rules", "=", "explode", "(", "\"|\"", ",", "$", "rules", ")", ";", "}", "foreach", "(", "$", "rules", "as", "$", "ruleIdx", "=>", "$", "rule", ")", "{", "// get name and parameters", "@", "list", "(", "$", "name", ",", "$", "params", ")", "=", "array_pad", "(", "explode", "(", "\":\"", ",", "$", "rule", ")", ",", "2", ",", "null", ")", ";", "// only do someting for the unique rule", "if", "(", "strtolower", "(", "$", "name", ")", "!=", "\"unique\"", ")", "{", "continue", ";", "// continue in foreach loop, nothing left to do here", "}", "$", "p", "=", "array_map", "(", "\"trim\"", ",", "explode", "(", "\",\"", ",", "$", "params", ")", ")", ";", "// set field name to rules key ($field) (laravel convention)", "if", "(", "!", "isset", "(", "$", "p", "[", "1", "]", ")", ")", "{", "$", "p", "[", "1", "]", "=", "$", "field", ";", "}", "// set 3rd parameter to id given to getValidationRules()", "$", "p", "[", "2", "]", "=", "$", "id", ";", "$", "params", "=", "implode", "(", "\",\"", ",", "$", "p", ")", ";", "$", "rules", "[", "$", "ruleIdx", "]", "=", "$", "name", ".", "\":\"", ".", "$", "params", ";", "}", "}", ")", ";", "return", "$", "rules", ";", "}" ]
Parser Validation Rules @param $rules @param null $id @return array
[ "Parser", "Validation", "Rules" ]
train
https://github.com/mayconpaivac/l5-validation/blob/0921391d7d9cf2853dd5667fb47c1450a251a0d8/src/Prettus/Validator/AbstractValidator.php#L174-L215
technote-space/wordpress-plugin-base
src/traits/singleton.php
Singleton.get_instance
public static function get_instance( \Technote $app ) { $class = get_called_class(); if ( false === $class ) { $class = get_class(); } try { $key = static::is_shared_class() ? '' : $app->plugin_name; if ( empty( self::$_instances[ $key ] ) || ! array_key_exists( $class, self::$_instances[ $key ] ) ) { $reflection = new \ReflectionClass( $class ); if ( $reflection->isAbstract() ) { self::$_instances[ $key ][ $class ] = null; } else { $instance = new static( $app, $reflection ); if ( $app->is_uninstall() && $instance instanceof \Technote\Interfaces\Uninstall ) { $app->uninstall->add_uninstall( [ $instance, 'uninstall' ], $instance->get_uninstall_priority() ); } self::$_instances[ $key ][ $class ] = $instance; $instance->set_allowed_access( true ); $instance->initialize(); $instance->set_allowed_access( false ); } } return self::$_instances[ $key ][ $class ]; } catch ( \Exception $e ) { } return null; }
php
public static function get_instance( \Technote $app ) { $class = get_called_class(); if ( false === $class ) { $class = get_class(); } try { $key = static::is_shared_class() ? '' : $app->plugin_name; if ( empty( self::$_instances[ $key ] ) || ! array_key_exists( $class, self::$_instances[ $key ] ) ) { $reflection = new \ReflectionClass( $class ); if ( $reflection->isAbstract() ) { self::$_instances[ $key ][ $class ] = null; } else { $instance = new static( $app, $reflection ); if ( $app->is_uninstall() && $instance instanceof \Technote\Interfaces\Uninstall ) { $app->uninstall->add_uninstall( [ $instance, 'uninstall' ], $instance->get_uninstall_priority() ); } self::$_instances[ $key ][ $class ] = $instance; $instance->set_allowed_access( true ); $instance->initialize(); $instance->set_allowed_access( false ); } } return self::$_instances[ $key ][ $class ]; } catch ( \Exception $e ) { } return null; }
[ "public", "static", "function", "get_instance", "(", "\\", "Technote", "$", "app", ")", "{", "$", "class", "=", "get_called_class", "(", ")", ";", "if", "(", "false", "===", "$", "class", ")", "{", "$", "class", "=", "get_class", "(", ")", ";", "}", "try", "{", "$", "key", "=", "static", "::", "is_shared_class", "(", ")", "?", "''", ":", "$", "app", "->", "plugin_name", ";", "if", "(", "empty", "(", "self", "::", "$", "_instances", "[", "$", "key", "]", ")", "||", "!", "array_key_exists", "(", "$", "class", ",", "self", "::", "$", "_instances", "[", "$", "key", "]", ")", ")", "{", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "if", "(", "$", "reflection", "->", "isAbstract", "(", ")", ")", "{", "self", "::", "$", "_instances", "[", "$", "key", "]", "[", "$", "class", "]", "=", "null", ";", "}", "else", "{", "$", "instance", "=", "new", "static", "(", "$", "app", ",", "$", "reflection", ")", ";", "if", "(", "$", "app", "->", "is_uninstall", "(", ")", "&&", "$", "instance", "instanceof", "\\", "Technote", "\\", "Interfaces", "\\", "Uninstall", ")", "{", "$", "app", "->", "uninstall", "->", "add_uninstall", "(", "[", "$", "instance", ",", "'uninstall'", "]", ",", "$", "instance", "->", "get_uninstall_priority", "(", ")", ")", ";", "}", "self", "::", "$", "_instances", "[", "$", "key", "]", "[", "$", "class", "]", "=", "$", "instance", ";", "$", "instance", "->", "set_allowed_access", "(", "true", ")", ";", "$", "instance", "->", "initialize", "(", ")", ";", "$", "instance", "->", "set_allowed_access", "(", "false", ")", ";", "}", "}", "return", "self", "::", "$", "_instances", "[", "$", "key", "]", "[", "$", "class", "]", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "}", "return", "null", ";", "}" ]
@since 2.0.2 Added: Uninstall priority @since 2.3.2 Fixed: ignore abstract class @since 2.10.0 Improved: performance @param \Technote $app @return \Technote\Traits\Singleton
[ "@since", "2", ".", "0", ".", "2", "Added", ":", "Uninstall", "priority", "@since", "2", ".", "3", ".", "2", "Fixed", ":", "ignore", "abstract", "class", "@since", "2", ".", "10", ".", "0", "Improved", ":", "performance" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/singleton.php#L71-L99
technote-space/wordpress-plugin-base
src/traits/singleton.php
Singleton.get_slug
public function get_slug( $config_name, $suffix = '-' ) { if ( ! isset( self::$_slugs[ $this->app->plugin_name ][ $config_name ] ) ) { $default = $this->app->slug_name . $suffix; $slug = $this->app->get_config( 'slug', $config_name, $default ); if ( empty( $slug ) ) { $slug = $default; } self::$_slugs[ $this->app->plugin_name ][ $config_name ] = $slug; } return self::$_slugs[ $this->app->plugin_name ][ $config_name ]; }
php
public function get_slug( $config_name, $suffix = '-' ) { if ( ! isset( self::$_slugs[ $this->app->plugin_name ][ $config_name ] ) ) { $default = $this->app->slug_name . $suffix; $slug = $this->app->get_config( 'slug', $config_name, $default ); if ( empty( $slug ) ) { $slug = $default; } self::$_slugs[ $this->app->plugin_name ][ $config_name ] = $slug; } return self::$_slugs[ $this->app->plugin_name ][ $config_name ]; }
[ "public", "function", "get_slug", "(", "$", "config_name", ",", "$", "suffix", "=", "'-'", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "_slugs", "[", "$", "this", "->", "app", "->", "plugin_name", "]", "[", "$", "config_name", "]", ")", ")", "{", "$", "default", "=", "$", "this", "->", "app", "->", "slug_name", ".", "$", "suffix", ";", "$", "slug", "=", "$", "this", "->", "app", "->", "get_config", "(", "'slug'", ",", "$", "config_name", ",", "$", "default", ")", ";", "if", "(", "empty", "(", "$", "slug", ")", ")", "{", "$", "slug", "=", "$", "default", ";", "}", "self", "::", "$", "_slugs", "[", "$", "this", "->", "app", "->", "plugin_name", "]", "[", "$", "config_name", "]", "=", "$", "slug", ";", "}", "return", "self", "::", "$", "_slugs", "[", "$", "this", "->", "app", "->", "plugin_name", "]", "[", "$", "config_name", "]", ";", "}" ]
@param string $config_name @param string $suffix @return string
[ "@param", "string", "$config_name", "@param", "string", "$suffix" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/singleton.php#L158-L169
technote-space/wordpress-plugin-base
src/traits/singleton.php
Singleton.lock_process
protected function lock_process( $name, $func ) { $name .= '__LOCK_PROCESS__'; $this->app->option->reload_options(); $check = $this->app->option->get( $name ); if ( ! empty( $check ) ) { return false; } $rand = md5( uniqid() ); $this->app->option->set( $name, $rand ); $this->app->option->reload_options(); if ( $this->app->option->get( $name ) != $rand ) { return false; } $func(); $this->app->option->delete( $name ); return true; }
php
protected function lock_process( $name, $func ) { $name .= '__LOCK_PROCESS__'; $this->app->option->reload_options(); $check = $this->app->option->get( $name ); if ( ! empty( $check ) ) { return false; } $rand = md5( uniqid() ); $this->app->option->set( $name, $rand ); $this->app->option->reload_options(); if ( $this->app->option->get( $name ) != $rand ) { return false; } $func(); $this->app->option->delete( $name ); return true; }
[ "protected", "function", "lock_process", "(", "$", "name", ",", "$", "func", ")", "{", "$", "name", ".=", "'__LOCK_PROCESS__'", ";", "$", "this", "->", "app", "->", "option", "->", "reload_options", "(", ")", ";", "$", "check", "=", "$", "this", "->", "app", "->", "option", "->", "get", "(", "$", "name", ")", ";", "if", "(", "!", "empty", "(", "$", "check", ")", ")", "{", "return", "false", ";", "}", "$", "rand", "=", "md5", "(", "uniqid", "(", ")", ")", ";", "$", "this", "->", "app", "->", "option", "->", "set", "(", "$", "name", ",", "$", "rand", ")", ";", "$", "this", "->", "app", "->", "option", "->", "reload_options", "(", ")", ";", "if", "(", "$", "this", "->", "app", "->", "option", "->", "get", "(", "$", "name", ")", "!=", "$", "rand", ")", "{", "return", "false", ";", "}", "$", "func", "(", ")", ";", "$", "this", "->", "app", "->", "option", "->", "delete", "(", "$", "name", ")", ";", "return", "true", ";", "}" ]
@param string $name @param callable $func @return bool
[ "@param", "string", "$name", "@param", "callable", "$func" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/singleton.php#L207-L224
InactiveProjects/limoncello-illuminate
app/Database/Seeds/SeedRoles.php
SeedRoles.run
public function run() { /** * @param string $roleName */ $createRole = function ($roleName) { (new Model([ Model::FIELD_ID => Model::getRoleId($roleName), Model::FIELD_NAME => $roleName, ]))->saveOrFail(); }; $createRole(Model::ENUM_ROLE_ADMIN); $createRole(Model::ENUM_ROLE_USER); }
php
public function run() { /** * @param string $roleName */ $createRole = function ($roleName) { (new Model([ Model::FIELD_ID => Model::getRoleId($roleName), Model::FIELD_NAME => $roleName, ]))->saveOrFail(); }; $createRole(Model::ENUM_ROLE_ADMIN); $createRole(Model::ENUM_ROLE_USER); }
[ "public", "function", "run", "(", ")", "{", "/**\n * @param string $roleName\n */", "$", "createRole", "=", "function", "(", "$", "roleName", ")", "{", "(", "new", "Model", "(", "[", "Model", "::", "FIELD_ID", "=>", "Model", "::", "getRoleId", "(", "$", "roleName", ")", ",", "Model", "::", "FIELD_NAME", "=>", "$", "roleName", ",", "]", ")", ")", "->", "saveOrFail", "(", ")", ";", "}", ";", "$", "createRole", "(", "Model", "::", "ENUM_ROLE_ADMIN", ")", ";", "$", "createRole", "(", "Model", "::", "ENUM_ROLE_USER", ")", ";", "}" ]
@inheritdoc @SuppressWarnings(PHPMD.StaticAccess)
[ "@inheritdoc" ]
train
https://github.com/InactiveProjects/limoncello-illuminate/blob/cae6fc26190efcf090495a5c3582c10fa2430897/app/Database/Seeds/SeedRoles.php#L15-L29
jasny/codeception-module
src/ResponseConvertor.php
ResponseConvertor.convert
public function convert(ResponseInterface $psrResponse) { return new BrowserKitResponse( (string)$psrResponse->getBody(), $psrResponse->getStatusCode() ?: 200, $this->flattenHeaders($psrResponse->getHeaders()) ); }
php
public function convert(ResponseInterface $psrResponse) { return new BrowserKitResponse( (string)$psrResponse->getBody(), $psrResponse->getStatusCode() ?: 200, $this->flattenHeaders($psrResponse->getHeaders()) ); }
[ "public", "function", "convert", "(", "ResponseInterface", "$", "psrResponse", ")", "{", "return", "new", "BrowserKitResponse", "(", "(", "string", ")", "$", "psrResponse", "->", "getBody", "(", ")", ",", "$", "psrResponse", "->", "getStatusCode", "(", ")", "?", ":", "200", ",", "$", "this", "->", "flattenHeaders", "(", "$", "psrResponse", "->", "getHeaders", "(", ")", ")", ")", ";", "}" ]
Convert a PSR-7 response to a codeception response @param ResponseInterface $psrResponse @return BrowserKitResponse
[ "Convert", "a", "PSR", "-", "7", "response", "to", "a", "codeception", "response" ]
train
https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/ResponseConvertor.php#L19-L26
jasny/codeception-module
src/ResponseConvertor.php
ResponseConvertor.flattenHeaders
protected function flattenHeaders(array $headers) { foreach ($headers as &$value) { $value = is_array($value) ? end($value) : $value; } return $headers; }
php
protected function flattenHeaders(array $headers) { foreach ($headers as &$value) { $value = is_array($value) ? end($value) : $value; } return $headers; }
[ "protected", "function", "flattenHeaders", "(", "array", "$", "headers", ")", "{", "foreach", "(", "$", "headers", "as", "&", "$", "value", ")", "{", "$", "value", "=", "is_array", "(", "$", "value", ")", "?", "end", "(", "$", "value", ")", ":", "$", "value", ";", "}", "return", "$", "headers", ";", "}" ]
Flatten headers @param array $headers @return array
[ "Flatten", "headers" ]
train
https://github.com/jasny/codeception-module/blob/5c2b12e4ab291f26424fda9fbf1618c818bc8d6e/src/ResponseConvertor.php#L34-L41
ekuiter/feature-php
FeaturePhp/Helper/Partition.php
Partition.fromObjects
public static function fromObjects($array, $key) { $elements = array(); foreach ($array as $element) { $result = call_user_func(array($element, $key)); $elements = array_merge($elements, is_array($result) ? $result : array($result)); } return new self($elements); }
php
public static function fromObjects($array, $key) { $elements = array(); foreach ($array as $element) { $result = call_user_func(array($element, $key)); $elements = array_merge($elements, is_array($result) ? $result : array($result)); } return new self($elements); }
[ "public", "static", "function", "fromObjects", "(", "$", "array", ",", "$", "key", ")", "{", "$", "elements", "=", "array", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "element", ")", "{", "$", "result", "=", "call_user_func", "(", "array", "(", "$", "element", ",", "$", "key", ")", ")", ";", "$", "elements", "=", "array_merge", "(", "$", "elements", ",", "is_array", "(", "$", "result", ")", "?", "$", "result", ":", "array", "(", "$", "result", ")", ")", ";", "}", "return", "new", "self", "(", "$", "elements", ")", ";", "}" ]
Creates a partition from a set of objects. @param array $array @param callable $key @return Partition
[ "Creates", "a", "partition", "from", "a", "set", "of", "objects", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Helper/Partition.php#L33-L40
ekuiter/feature-php
FeaturePhp/Helper/Partition.php
Partition.partitionBy
public function partitionBy($key) { $partition = array(); foreach ($this->elements as $element) { $newEquivalenceClass = true; for ($i = 0; $i < count($partition); $i++) // partition[$i] is an equivalence class // an equivalence class is guaranteed to be non-empty if (call_user_func(array($element, $key), $partition[$i][0])) { $partition[$i][] = $element; $newEquivalenceClass = false; } if ($newEquivalenceClass) $partition[] = array($element); } return $partition; }
php
public function partitionBy($key) { $partition = array(); foreach ($this->elements as $element) { $newEquivalenceClass = true; for ($i = 0; $i < count($partition); $i++) // partition[$i] is an equivalence class // an equivalence class is guaranteed to be non-empty if (call_user_func(array($element, $key), $partition[$i][0])) { $partition[$i][] = $element; $newEquivalenceClass = false; } if ($newEquivalenceClass) $partition[] = array($element); } return $partition; }
[ "public", "function", "partitionBy", "(", "$", "key", ")", "{", "$", "partition", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "elements", "as", "$", "element", ")", "{", "$", "newEquivalenceClass", "=", "true", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "partition", ")", ";", "$", "i", "++", ")", "// partition[$i] is an equivalence class", "// an equivalence class is guaranteed to be non-empty", "if", "(", "call_user_func", "(", "array", "(", "$", "element", ",", "$", "key", ")", ",", "$", "partition", "[", "$", "i", "]", "[", "0", "]", ")", ")", "{", "$", "partition", "[", "$", "i", "]", "[", "]", "=", "$", "element", ";", "$", "newEquivalenceClass", "=", "false", ";", "}", "if", "(", "$", "newEquivalenceClass", ")", "$", "partition", "[", "]", "=", "array", "(", "$", "element", ")", ";", "}", "return", "$", "partition", ";", "}" ]
Partitions the elements using an equivalence relation. @param callable $key a binary relation on the elements @return array[]
[ "Partitions", "the", "elements", "using", "an", "equivalence", "relation", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Helper/Partition.php#L47-L61
heidelpay/PhpDoc
src/phpDocumentor/Transformer/Router/StandardRouter.php
StandardRouter.configure
public function configure() { $projectDescriptorBuilder = $this->projectDescriptorBuilder; $fileGenerator = new UrlGenerator\Standard\FileDescriptor(); $namespaceGenerator = new UrlGenerator\Standard\NamespaceDescriptor(); $packageGenerator = new UrlGenerator\Standard\PackageDescriptor(); $classGenerator = new UrlGenerator\Standard\ClassDescriptor(); $methodGenerator = new UrlGenerator\Standard\MethodDescriptor(); $constantGenerator = new UrlGenerator\Standard\ConstantDescriptor(); $functionGenerator = new UrlGenerator\Standard\FunctionDescriptor(); $propertyGenerator = new UrlGenerator\Standard\PropertyDescriptor(); // Here we cheat! If a string element is passed to this rule then we try to transform it into a Descriptor // if the node is translated we do not let it match and instead fall through to one of the other rules. $stringRule = function (&$node) use ($projectDescriptorBuilder) { $elements = $projectDescriptorBuilder->getProjectDescriptor()->getIndexes()->get('elements'); if (is_string($node) && isset($elements[$node])) { $node = $elements[$node]; }; return false; }; // @codingStandardsIgnoreStart $this[] = new Rule($stringRule, function () { return false; }); $this[] = new Rule(function ($node) { return ($node instanceof FileDescriptor); }, $fileGenerator); $this[] = new Rule(function ($node) { return ($node instanceof PackageDescriptor); }, $packageGenerator); $this[] = new Rule(function ($node) { return ($node instanceof TraitDescriptor); }, $classGenerator); $this[] = new Rule(function ($node) { return ($node instanceof NamespaceDescriptor); }, $namespaceGenerator); $this[] = new Rule(function ($node) { return ($node instanceof InterfaceDescriptor); }, $classGenerator ); $this[] = new Rule(function ($node) { return ($node instanceof ClassDescriptor); }, $classGenerator); $this[] = new Rule(function ($node) { return ($node instanceof ConstantDescriptor); }, $constantGenerator); $this[] = new Rule(function ($node) { return ($node instanceof MethodDescriptor); }, $methodGenerator); $this[] = new Rule(function ($node) { return ($node instanceof FunctionDescriptor); }, $functionGenerator); $this[] = new Rule( function ($node) { return ($node instanceof PropertyDescriptor); }, $propertyGenerator); // if this is a link to an external page; return that URL $this[] = new Rule( function ($node) { return is_string($node) && (substr($node, 0, 7) == 'http://' || substr($node, 0, 7) == 'https://'); }, function ($node) { return $node; } ); // do not generate a file for every unknown type $this[] = new Rule(function () { return true; }, function () { return false; }); // @codingStandardsIgnoreEnd }
php
public function configure() { $projectDescriptorBuilder = $this->projectDescriptorBuilder; $fileGenerator = new UrlGenerator\Standard\FileDescriptor(); $namespaceGenerator = new UrlGenerator\Standard\NamespaceDescriptor(); $packageGenerator = new UrlGenerator\Standard\PackageDescriptor(); $classGenerator = new UrlGenerator\Standard\ClassDescriptor(); $methodGenerator = new UrlGenerator\Standard\MethodDescriptor(); $constantGenerator = new UrlGenerator\Standard\ConstantDescriptor(); $functionGenerator = new UrlGenerator\Standard\FunctionDescriptor(); $propertyGenerator = new UrlGenerator\Standard\PropertyDescriptor(); // Here we cheat! If a string element is passed to this rule then we try to transform it into a Descriptor // if the node is translated we do not let it match and instead fall through to one of the other rules. $stringRule = function (&$node) use ($projectDescriptorBuilder) { $elements = $projectDescriptorBuilder->getProjectDescriptor()->getIndexes()->get('elements'); if (is_string($node) && isset($elements[$node])) { $node = $elements[$node]; }; return false; }; // @codingStandardsIgnoreStart $this[] = new Rule($stringRule, function () { return false; }); $this[] = new Rule(function ($node) { return ($node instanceof FileDescriptor); }, $fileGenerator); $this[] = new Rule(function ($node) { return ($node instanceof PackageDescriptor); }, $packageGenerator); $this[] = new Rule(function ($node) { return ($node instanceof TraitDescriptor); }, $classGenerator); $this[] = new Rule(function ($node) { return ($node instanceof NamespaceDescriptor); }, $namespaceGenerator); $this[] = new Rule(function ($node) { return ($node instanceof InterfaceDescriptor); }, $classGenerator ); $this[] = new Rule(function ($node) { return ($node instanceof ClassDescriptor); }, $classGenerator); $this[] = new Rule(function ($node) { return ($node instanceof ConstantDescriptor); }, $constantGenerator); $this[] = new Rule(function ($node) { return ($node instanceof MethodDescriptor); }, $methodGenerator); $this[] = new Rule(function ($node) { return ($node instanceof FunctionDescriptor); }, $functionGenerator); $this[] = new Rule( function ($node) { return ($node instanceof PropertyDescriptor); }, $propertyGenerator); // if this is a link to an external page; return that URL $this[] = new Rule( function ($node) { return is_string($node) && (substr($node, 0, 7) == 'http://' || substr($node, 0, 7) == 'https://'); }, function ($node) { return $node; } ); // do not generate a file for every unknown type $this[] = new Rule(function () { return true; }, function () { return false; }); // @codingStandardsIgnoreEnd }
[ "public", "function", "configure", "(", ")", "{", "$", "projectDescriptorBuilder", "=", "$", "this", "->", "projectDescriptorBuilder", ";", "$", "fileGenerator", "=", "new", "UrlGenerator", "\\", "Standard", "\\", "FileDescriptor", "(", ")", ";", "$", "namespaceGenerator", "=", "new", "UrlGenerator", "\\", "Standard", "\\", "NamespaceDescriptor", "(", ")", ";", "$", "packageGenerator", "=", "new", "UrlGenerator", "\\", "Standard", "\\", "PackageDescriptor", "(", ")", ";", "$", "classGenerator", "=", "new", "UrlGenerator", "\\", "Standard", "\\", "ClassDescriptor", "(", ")", ";", "$", "methodGenerator", "=", "new", "UrlGenerator", "\\", "Standard", "\\", "MethodDescriptor", "(", ")", ";", "$", "constantGenerator", "=", "new", "UrlGenerator", "\\", "Standard", "\\", "ConstantDescriptor", "(", ")", ";", "$", "functionGenerator", "=", "new", "UrlGenerator", "\\", "Standard", "\\", "FunctionDescriptor", "(", ")", ";", "$", "propertyGenerator", "=", "new", "UrlGenerator", "\\", "Standard", "\\", "PropertyDescriptor", "(", ")", ";", "// Here we cheat! If a string element is passed to this rule then we try to transform it into a Descriptor", "// if the node is translated we do not let it match and instead fall through to one of the other rules.", "$", "stringRule", "=", "function", "(", "&", "$", "node", ")", "use", "(", "$", "projectDescriptorBuilder", ")", "{", "$", "elements", "=", "$", "projectDescriptorBuilder", "->", "getProjectDescriptor", "(", ")", "->", "getIndexes", "(", ")", "->", "get", "(", "'elements'", ")", ";", "if", "(", "is_string", "(", "$", "node", ")", "&&", "isset", "(", "$", "elements", "[", "$", "node", "]", ")", ")", "{", "$", "node", "=", "$", "elements", "[", "$", "node", "]", ";", "}", ";", "return", "false", ";", "}", ";", "// @codingStandardsIgnoreStart", "$", "this", "[", "]", "=", "new", "Rule", "(", "$", "stringRule", ",", "function", "(", ")", "{", "return", "false", ";", "}", ")", ";", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", "$", "node", ")", "{", "return", "(", "$", "node", "instanceof", "FileDescriptor", ")", ";", "}", ",", "$", "fileGenerator", ")", ";", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", "$", "node", ")", "{", "return", "(", "$", "node", "instanceof", "PackageDescriptor", ")", ";", "}", ",", "$", "packageGenerator", ")", ";", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", "$", "node", ")", "{", "return", "(", "$", "node", "instanceof", "TraitDescriptor", ")", ";", "}", ",", "$", "classGenerator", ")", ";", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", "$", "node", ")", "{", "return", "(", "$", "node", "instanceof", "NamespaceDescriptor", ")", ";", "}", ",", "$", "namespaceGenerator", ")", ";", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", "$", "node", ")", "{", "return", "(", "$", "node", "instanceof", "InterfaceDescriptor", ")", ";", "}", ",", "$", "classGenerator", ")", ";", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", "$", "node", ")", "{", "return", "(", "$", "node", "instanceof", "ClassDescriptor", ")", ";", "}", ",", "$", "classGenerator", ")", ";", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", "$", "node", ")", "{", "return", "(", "$", "node", "instanceof", "ConstantDescriptor", ")", ";", "}", ",", "$", "constantGenerator", ")", ";", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", "$", "node", ")", "{", "return", "(", "$", "node", "instanceof", "MethodDescriptor", ")", ";", "}", ",", "$", "methodGenerator", ")", ";", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", "$", "node", ")", "{", "return", "(", "$", "node", "instanceof", "FunctionDescriptor", ")", ";", "}", ",", "$", "functionGenerator", ")", ";", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", "$", "node", ")", "{", "return", "(", "$", "node", "instanceof", "PropertyDescriptor", ")", ";", "}", ",", "$", "propertyGenerator", ")", ";", "// if this is a link to an external page; return that URL", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", "$", "node", ")", "{", "return", "is_string", "(", "$", "node", ")", "&&", "(", "substr", "(", "$", "node", ",", "0", ",", "7", ")", "==", "'http://'", "||", "substr", "(", "$", "node", ",", "0", ",", "7", ")", "==", "'https://'", ")", ";", "}", ",", "function", "(", "$", "node", ")", "{", "return", "$", "node", ";", "}", ")", ";", "// do not generate a file for every unknown type", "$", "this", "[", "]", "=", "new", "Rule", "(", "function", "(", ")", "{", "return", "true", ";", "}", ",", "function", "(", ")", "{", "return", "false", ";", "}", ")", ";", "// @codingStandardsIgnoreEnd", "}" ]
Configuration function to add routing rules to a router. @return void
[ "Configuration", "function", "to", "add", "routing", "rules", "to", "a", "router", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Router/StandardRouter.php#L51-L99
Eresus/EresusCMS
src/core/HTTP/Request.php
Eresus_HTTP_Request.createFromGlobals
public static function createFromGlobals() { $request = new self(@$_SERVER['REQUEST_URI']); if (array_key_exists('REQUEST_METHOD', $_SERVER)) { $request->setMethod($_SERVER['REQUEST_METHOD']); } if ($request->getMethod() == 'POST') { $request->request->replace($_POST); } return $request; }
php
public static function createFromGlobals() { $request = new self(@$_SERVER['REQUEST_URI']); if (array_key_exists('REQUEST_METHOD', $_SERVER)) { $request->setMethod($_SERVER['REQUEST_METHOD']); } if ($request->getMethod() == 'POST') { $request->request->replace($_POST); } return $request; }
[ "public", "static", "function", "createFromGlobals", "(", ")", "{", "$", "request", "=", "new", "self", "(", "@", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ";", "if", "(", "array_key_exists", "(", "'REQUEST_METHOD'", ",", "$", "_SERVER", ")", ")", "{", "$", "request", "->", "setMethod", "(", "$", "_SERVER", "[", "'REQUEST_METHOD'", "]", ")", ";", "}", "if", "(", "$", "request", "->", "getMethod", "(", ")", "==", "'POST'", ")", "{", "$", "request", "->", "request", "->", "replace", "(", "$", "_POST", ")", ";", "}", "return", "$", "request", ";", "}" ]
Возвращает объект, созданный на основе глобальных переменных PHP @return Eresus_HTTP_Request @since 3.01
[ "Возвращает", "объект", "созданный", "на", "основе", "глобальных", "переменных", "PHP" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/HTTP/Request.php#L165-L177
Eresus/EresusCMS
src/core/HTTP/Request.php
Eresus_HTTP_Request.getDirectory
public function getDirectory() { return substr($this->getPath(), -1) == '/' ? substr($this->getPath(), 0, -1) : dirname($this->getPath()); }
php
public function getDirectory() { return substr($this->getPath(), -1) == '/' ? substr($this->getPath(), 0, -1) : dirname($this->getPath()); }
[ "public", "function", "getDirectory", "(", ")", "{", "return", "substr", "(", "$", "this", "->", "getPath", "(", ")", ",", "-", "1", ")", "==", "'/'", "?", "substr", "(", "$", "this", "->", "getPath", "(", ")", ",", "0", ",", "-", "1", ")", ":", "dirname", "(", "$", "this", "->", "getPath", "(", ")", ")", ";", "}" ]
Возвращает папку из запроса Возвращаемый путь не заканчивается слэшем. @return string
[ "Возвращает", "папку", "из", "запроса" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/HTTP/Request.php#L267-L272
Eresus/EresusCMS
src/core/HTTP/Request.php
Eresus_HTTP_Request.getQueryString
public function getQueryString() { $parameters = $this->query->all(); array_walk($parameters, function (&$value, $key) { $value = $key . '=' . $value; } ); return implode('&', $parameters); }
php
public function getQueryString() { $parameters = $this->query->all(); array_walk($parameters, function (&$value, $key) { $value = $key . '=' . $value; } ); return implode('&', $parameters); }
[ "public", "function", "getQueryString", "(", ")", "{", "$", "parameters", "=", "$", "this", "->", "query", "->", "all", "(", ")", ";", "array_walk", "(", "$", "parameters", ",", "function", "(", "&", "$", "value", ",", "$", "key", ")", "{", "$", "value", "=", "$", "key", ".", "'='", ".", "$", "value", ";", "}", ")", ";", "return", "implode", "(", "'&'", ",", "$", "parameters", ")", ";", "}" ]
Возвращает строку аргументов GET (часть URL после знака "?") @return string
[ "Возвращает", "строку", "аргументов", "GET", "(", "часть", "URL", "после", "знака", "?", ")" ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/HTTP/Request.php#L290-L300
surebert/surebert-framework
src/sb/String/HTML.php
HTML.escape
public static function escape($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8') { if (is_string($mixed)) { $mixed = htmlspecialchars($mixed, $quote_style, $charset); } elseif (is_object($mixed) || is_array($mixed)) { foreach ($mixed as $k => &$v) { if ($v) { if (is_object($mixed)) { $mixed->$k = self::escape($v, $quote_style, $charset); } else { $mixed[$k] = self::escape($v, $quote_style, $charset); } } } } return $mixed; }
php
public static function escape($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8') { if (is_string($mixed)) { $mixed = htmlspecialchars($mixed, $quote_style, $charset); } elseif (is_object($mixed) || is_array($mixed)) { foreach ($mixed as $k => &$v) { if ($v) { if (is_object($mixed)) { $mixed->$k = self::escape($v, $quote_style, $charset); } else { $mixed[$k] = self::escape($v, $quote_style, $charset); } } } } return $mixed; }
[ "public", "static", "function", "escape", "(", "$", "mixed", ",", "$", "quote_style", "=", "ENT_QUOTES", ",", "$", "charset", "=", "'UTF-8'", ")", "{", "if", "(", "is_string", "(", "$", "mixed", ")", ")", "{", "$", "mixed", "=", "htmlspecialchars", "(", "$", "mixed", ",", "$", "quote_style", ",", "$", "charset", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "mixed", ")", "||", "is_array", "(", "$", "mixed", ")", ")", "{", "foreach", "(", "$", "mixed", "as", "$", "k", "=>", "&", "$", "v", ")", "{", "if", "(", "$", "v", ")", "{", "if", "(", "is_object", "(", "$", "mixed", ")", ")", "{", "$", "mixed", "->", "$", "k", "=", "self", "::", "escape", "(", "$", "v", ",", "$", "quote_style", ",", "$", "charset", ")", ";", "}", "else", "{", "$", "mixed", "[", "$", "k", "]", "=", "self", "::", "escape", "(", "$", "v", ",", "$", "quote_style", ",", "$", "charset", ")", ";", "}", "}", "}", "}", "return", "$", "mixed", ";", "}" ]
Recursively htmlspecialchars string properties of objects and arrays @param mixed $mixed The object or array to convert @param int $quote_style ent quote style from htmlspecialchars @param string $charset The charset from htmlspecialchars @return type
[ "Recursively", "htmlspecialchars", "string", "properties", "of", "objects", "and", "arrays" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/String/HTML.php#L18-L36
surebert/surebert-framework
src/sb/String/HTML.php
HTML.unescape
public static function unescape($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8') { if (is_string($mixed)) { $mixed = str_replace('&amp;', '&', $mixed); $mixed = str_replace('&#039;', '\'', $mixed); $mixed = str_replace('&quot;', '"', $mixed); $mixed = str_replace('&lt;', '<', $mixed); $mixed = str_replace('&gt;', '>', $mixed); } elseif (is_object($mixed) || is_array($mixed)) { foreach ($mixed as $k => &$v) { if ($v) { if (is_object($mixed)) { $mixed->$k = self::unescape($v); } else { $mixed[$k] = self::unescape($v); } } } } return $mixed; }
php
public static function unescape($mixed, $quote_style = ENT_QUOTES, $charset = 'UTF-8') { if (is_string($mixed)) { $mixed = str_replace('&amp;', '&', $mixed); $mixed = str_replace('&#039;', '\'', $mixed); $mixed = str_replace('&quot;', '"', $mixed); $mixed = str_replace('&lt;', '<', $mixed); $mixed = str_replace('&gt;', '>', $mixed); } elseif (is_object($mixed) || is_array($mixed)) { foreach ($mixed as $k => &$v) { if ($v) { if (is_object($mixed)) { $mixed->$k = self::unescape($v); } else { $mixed[$k] = self::unescape($v); } } } } return $mixed; }
[ "public", "static", "function", "unescape", "(", "$", "mixed", ",", "$", "quote_style", "=", "ENT_QUOTES", ",", "$", "charset", "=", "'UTF-8'", ")", "{", "if", "(", "is_string", "(", "$", "mixed", ")", ")", "{", "$", "mixed", "=", "str_replace", "(", "'&amp;'", ",", "'&'", ",", "$", "mixed", ")", ";", "$", "mixed", "=", "str_replace", "(", "'&#039;'", ",", "'\\''", ",", "$", "mixed", ")", ";", "$", "mixed", "=", "str_replace", "(", "'&quot;'", ",", "'\"'", ",", "$", "mixed", ")", ";", "$", "mixed", "=", "str_replace", "(", "'&lt;'", ",", "'<'", ",", "$", "mixed", ")", ";", "$", "mixed", "=", "str_replace", "(", "'&gt;'", ",", "'>'", ",", "$", "mixed", ")", ";", "}", "elseif", "(", "is_object", "(", "$", "mixed", ")", "||", "is_array", "(", "$", "mixed", ")", ")", "{", "foreach", "(", "$", "mixed", "as", "$", "k", "=>", "&", "$", "v", ")", "{", "if", "(", "$", "v", ")", "{", "if", "(", "is_object", "(", "$", "mixed", ")", ")", "{", "$", "mixed", "->", "$", "k", "=", "self", "::", "unescape", "(", "$", "v", ")", ";", "}", "else", "{", "$", "mixed", "[", "$", "k", "]", "=", "self", "::", "unescape", "(", "$", "v", ")", ";", "}", "}", "}", "}", "return", "$", "mixed", ";", "}" ]
Recursively unhtmlspecialchars string properties of objects and arrays @param mixed $mixed The object or array to convert @param int $quote_style ent quote style from htmlspecialchars @param string $charset The charset from htmlspecialchars @return type
[ "Recursively", "unhtmlspecialchars", "string", "properties", "of", "objects", "and", "arrays" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/String/HTML.php#L45-L67
pvsaintpe/yii2-grid
controllers/ExportController.php
ExportController.actionDownload
public function actionDownload() { $request = Yii::$app->request; $type = $request->post('export_filetype', 'html'); $name = $request->post('export_filename', Yii::t('kvgrid', 'export')); $content = $request->post('export_content', Yii::t('kvgrid', 'No data found')); static::replaceDelimiters($content); $mime = $request->post('export_mime', 'text/plain'); $encoding = $request->post('export_encoding', 'utf-8'); $bom = $request->post('export_bom', true); $config = $request->post('export_config', '{}'); if ($type == GridView::PDF) { $config = Json::decode($config); $this->generatePDF($content, "{$name}.pdf", $config); /** @noinspection PhpInconsistentReturnPointsInspection */ return; } elseif ($type == GridView::HTML) { $content = HtmlPurifier::process($content); } elseif (($type == GridView::CSV || $type == GridView::TEXT) && $encoding == 'utf-8' && $bom) { $content = chr(239) . chr(187) . chr(191) . $content; // add BOM } $this->setHttpHeaders($type, $name, $mime, $encoding); return $content; }
php
public function actionDownload() { $request = Yii::$app->request; $type = $request->post('export_filetype', 'html'); $name = $request->post('export_filename', Yii::t('kvgrid', 'export')); $content = $request->post('export_content', Yii::t('kvgrid', 'No data found')); static::replaceDelimiters($content); $mime = $request->post('export_mime', 'text/plain'); $encoding = $request->post('export_encoding', 'utf-8'); $bom = $request->post('export_bom', true); $config = $request->post('export_config', '{}'); if ($type == GridView::PDF) { $config = Json::decode($config); $this->generatePDF($content, "{$name}.pdf", $config); /** @noinspection PhpInconsistentReturnPointsInspection */ return; } elseif ($type == GridView::HTML) { $content = HtmlPurifier::process($content); } elseif (($type == GridView::CSV || $type == GridView::TEXT) && $encoding == 'utf-8' && $bom) { $content = chr(239) . chr(187) . chr(191) . $content; // add BOM } $this->setHttpHeaders($type, $name, $mime, $encoding); return $content; }
[ "public", "function", "actionDownload", "(", ")", "{", "$", "request", "=", "Yii", "::", "$", "app", "->", "request", ";", "$", "type", "=", "$", "request", "->", "post", "(", "'export_filetype'", ",", "'html'", ")", ";", "$", "name", "=", "$", "request", "->", "post", "(", "'export_filename'", ",", "Yii", "::", "t", "(", "'kvgrid'", ",", "'export'", ")", ")", ";", "$", "content", "=", "$", "request", "->", "post", "(", "'export_content'", ",", "Yii", "::", "t", "(", "'kvgrid'", ",", "'No data found'", ")", ")", ";", "static", "::", "replaceDelimiters", "(", "$", "content", ")", ";", "$", "mime", "=", "$", "request", "->", "post", "(", "'export_mime'", ",", "'text/plain'", ")", ";", "$", "encoding", "=", "$", "request", "->", "post", "(", "'export_encoding'", ",", "'utf-8'", ")", ";", "$", "bom", "=", "$", "request", "->", "post", "(", "'export_bom'", ",", "true", ")", ";", "$", "config", "=", "$", "request", "->", "post", "(", "'export_config'", ",", "'{}'", ")", ";", "if", "(", "$", "type", "==", "GridView", "::", "PDF", ")", "{", "$", "config", "=", "Json", "::", "decode", "(", "$", "config", ")", ";", "$", "this", "->", "generatePDF", "(", "$", "content", ",", "\"{$name}.pdf\"", ",", "$", "config", ")", ";", "/** @noinspection PhpInconsistentReturnPointsInspection */", "return", ";", "}", "elseif", "(", "$", "type", "==", "GridView", "::", "HTML", ")", "{", "$", "content", "=", "HtmlPurifier", "::", "process", "(", "$", "content", ")", ";", "}", "elseif", "(", "(", "$", "type", "==", "GridView", "::", "CSV", "||", "$", "type", "==", "GridView", "::", "TEXT", ")", "&&", "$", "encoding", "==", "'utf-8'", "&&", "$", "bom", ")", "{", "$", "content", "=", "chr", "(", "239", ")", ".", "chr", "(", "187", ")", ".", "chr", "(", "191", ")", ".", "$", "content", ";", "// add BOM\r", "}", "$", "this", "->", "setHttpHeaders", "(", "$", "type", ",", "$", "name", ",", "$", "mime", ",", "$", "encoding", ")", ";", "return", "$", "content", ";", "}" ]
Download the exported file @return mixed
[ "Download", "the", "exported", "file" ]
train
https://github.com/pvsaintpe/yii2-grid/blob/8c91a1737412070775dc3fbee6a89384a67ca2cf/controllers/ExportController.php#L21-L46
HedronDev/hedron
src/GitPostReceiveHandler.php
GitPostReceiveHandler.doRun
public function doRun(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; $this->committedFiles = $this->extractCommittedFiles(); $this->allFiles = $this->extractTopLevelFiles(); $this->intersectFiles = array_intersect($this->allFiles, $this->committedFiles); if ($this->getConfiguration()->execute()) { $this->parseFiles(); } else { $this->destroy(); } }
php
public function doRun(InputInterface $input, OutputInterface $output) { $this->input = $input; $this->output = $output; $this->committedFiles = $this->extractCommittedFiles(); $this->allFiles = $this->extractTopLevelFiles(); $this->intersectFiles = array_intersect($this->allFiles, $this->committedFiles); if ($this->getConfiguration()->execute()) { $this->parseFiles(); } else { $this->destroy(); } }
[ "public", "function", "doRun", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", "{", "$", "this", "->", "input", "=", "$", "input", ";", "$", "this", "->", "output", "=", "$", "output", ";", "$", "this", "->", "committedFiles", "=", "$", "this", "->", "extractCommittedFiles", "(", ")", ";", "$", "this", "->", "allFiles", "=", "$", "this", "->", "extractTopLevelFiles", "(", ")", ";", "$", "this", "->", "intersectFiles", "=", "array_intersect", "(", "$", "this", "->", "allFiles", ",", "$", "this", "->", "committedFiles", ")", ";", "if", "(", "$", "this", "->", "getConfiguration", "(", ")", "->", "execute", "(", ")", ")", "{", "$", "this", "->", "parseFiles", "(", ")", ";", "}", "else", "{", "$", "this", "->", "destroy", "(", ")", ";", "}", "}" ]
{@inheritdoc}GitPostReceiveHandler
[ "{" ]
train
https://github.com/HedronDev/hedron/blob/3b4adec4912f2d7c0b7e7262dc36515fbc2e8e00/src/GitPostReceiveHandler.php#L55-L68
zhouyl/mellivora
Mellivora/Http/Response.php
Response.withJson
public function withJson($data, $status = null, $encodingOptions = JSON_ENCODE_OPTION) { return parent::withJson($data, $status, $encodingOptions); }
php
public function withJson($data, $status = null, $encodingOptions = JSON_ENCODE_OPTION) { return parent::withJson($data, $status, $encodingOptions); }
[ "public", "function", "withJson", "(", "$", "data", ",", "$", "status", "=", "null", ",", "$", "encodingOptions", "=", "JSON_ENCODE_OPTION", ")", "{", "return", "parent", "::", "withJson", "(", "$", "data", ",", "$", "status", ",", "$", "encodingOptions", ")", ";", "}" ]
默认使用定义的全局 json 格式化选项输出 {@inheritdoc}
[ "默认使用定义的全局", "json", "格式化选项输出" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Response.php#L17-L20
zhouyl/mellivora
Mellivora/Http/Response.php
Response.withHeaders
public function withHeaders(array $headers) { $clone = clone $this; foreach ($headers as $name => $value) { $clone->headers->set($name, $value); } return $clone; }
php
public function withHeaders(array $headers) { $clone = clone $this; foreach ($headers as $name => $value) { $clone->headers->set($name, $value); } return $clone; }
[ "public", "function", "withHeaders", "(", "array", "$", "headers", ")", "{", "$", "clone", "=", "clone", "$", "this", ";", "foreach", "(", "$", "headers", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "clone", "->", "headers", "->", "set", "(", "$", "name", ",", "$", "value", ")", ";", "}", "return", "$", "clone", ";", "}" ]
指定 headers 头部信息 @param array $headers @return static
[ "指定", "headers", "头部信息" ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Response.php#L29-L38
philiplb/Valdi
src/Valdi/Validator/Min.php
Min.isValidComparison
protected function isValidComparison($value, $parameters) { $isAllNumeric = $this->isAllNumeric($value, $parameters[0]); return $isAllNumeric && $value >= $parameters[0]; }
php
protected function isValidComparison($value, $parameters) { $isAllNumeric = $this->isAllNumeric($value, $parameters[0]); return $isAllNumeric && $value >= $parameters[0]; }
[ "protected", "function", "isValidComparison", "(", "$", "value", ",", "$", "parameters", ")", "{", "$", "isAllNumeric", "=", "$", "this", "->", "isAllNumeric", "(", "$", "value", ",", "$", "parameters", "[", "0", "]", ")", ";", "return", "$", "isAllNumeric", "&&", "$", "value", ">=", "$", "parameters", "[", "0", "]", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/philiplb/Valdi/blob/9927ec34a2cb00cec705e952d3c2374e2dc3c972/src/Valdi/Validator/Min.php#L27-L30
InactiveProjects/limoncello-illuminate
app/Http/Controllers/Web/HomeController.php
HomeController.authenticate
public function authenticate(Request $request) { $email = $request->input(self::AUTH_PARAM_EMAIL, null); $password = $request->input(self::AUTH_PARAM_PASSWORD, null); if ($email !== null && $password !== null && ($user = User::query()->where(User::FIELD_EMAIL, '=', strtolower($email))->first()) !== null ) { /** @var HasherInterface $hasher */ $hasher = app(HasherInterface::class); if ($hasher->check($password, $user->{User::FIELD_PASSWORD_HASH}) === true) { /** @var TokenCodecInterface $codec */ $codec = app(TokenCodecInterface::class); $token = $codec->encode($user); $this->getLogger()->debug( 'Account login success.', [User::FIELD_EMAIL => $email, User::FIELD_ID => $user->getKey()] ); return response($token); } } $this->getLogger()->debug('Account login failed.', [User::FIELD_EMAIL => $email]); return response(null, Response::HTTP_UNAUTHORIZED); }
php
public function authenticate(Request $request) { $email = $request->input(self::AUTH_PARAM_EMAIL, null); $password = $request->input(self::AUTH_PARAM_PASSWORD, null); if ($email !== null && $password !== null && ($user = User::query()->where(User::FIELD_EMAIL, '=', strtolower($email))->first()) !== null ) { /** @var HasherInterface $hasher */ $hasher = app(HasherInterface::class); if ($hasher->check($password, $user->{User::FIELD_PASSWORD_HASH}) === true) { /** @var TokenCodecInterface $codec */ $codec = app(TokenCodecInterface::class); $token = $codec->encode($user); $this->getLogger()->debug( 'Account login success.', [User::FIELD_EMAIL => $email, User::FIELD_ID => $user->getKey()] ); return response($token); } } $this->getLogger()->debug('Account login failed.', [User::FIELD_EMAIL => $email]); return response(null, Response::HTTP_UNAUTHORIZED); }
[ "public", "function", "authenticate", "(", "Request", "$", "request", ")", "{", "$", "email", "=", "$", "request", "->", "input", "(", "self", "::", "AUTH_PARAM_EMAIL", ",", "null", ")", ";", "$", "password", "=", "$", "request", "->", "input", "(", "self", "::", "AUTH_PARAM_PASSWORD", ",", "null", ")", ";", "if", "(", "$", "email", "!==", "null", "&&", "$", "password", "!==", "null", "&&", "(", "$", "user", "=", "User", "::", "query", "(", ")", "->", "where", "(", "User", "::", "FIELD_EMAIL", ",", "'='", ",", "strtolower", "(", "$", "email", ")", ")", "->", "first", "(", ")", ")", "!==", "null", ")", "{", "/** @var HasherInterface $hasher */", "$", "hasher", "=", "app", "(", "HasherInterface", "::", "class", ")", ";", "if", "(", "$", "hasher", "->", "check", "(", "$", "password", ",", "$", "user", "->", "{", "User", "::", "FIELD_PASSWORD_HASH", "}", ")", "===", "true", ")", "{", "/** @var TokenCodecInterface $codec */", "$", "codec", "=", "app", "(", "TokenCodecInterface", "::", "class", ")", ";", "$", "token", "=", "$", "codec", "->", "encode", "(", "$", "user", ")", ";", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "'Account login success.'", ",", "[", "User", "::", "FIELD_EMAIL", "=>", "$", "email", ",", "User", "::", "FIELD_ID", "=>", "$", "user", "->", "getKey", "(", ")", "]", ")", ";", "return", "response", "(", "$", "token", ")", ";", "}", "}", "$", "this", "->", "getLogger", "(", ")", "->", "debug", "(", "'Account login failed.'", ",", "[", "User", "::", "FIELD_EMAIL", "=>", "$", "email", "]", ")", ";", "return", "response", "(", "null", ",", "Response", "::", "HTTP_UNAUTHORIZED", ")", ";", "}" ]
Issue auth token. @param Request $request @return Response
[ "Issue", "auth", "token", "." ]
train
https://github.com/InactiveProjects/limoncello-illuminate/blob/cae6fc26190efcf090495a5c3582c10fa2430897/app/Http/Controllers/Web/HomeController.php#L39-L67
WellCommerce/StandardEditionBundle
DataFixtures/ORM/LoadShowcaseData.php
LoadShowcaseData.load
public function load(ObjectManager $manager) { if (!$this->isEnabled()) { return; } $this->createLayoutBoxes($manager, [ 'showcase' => [ 'type' => 'Showcase', 'name' => 'Showcase', 'settings' => [ 'status' => $this->getReference('product_status_featured')->getId(), 'limit' => 10, 'categories' => [], ], ], ]); $manager->flush(); }
php
public function load(ObjectManager $manager) { if (!$this->isEnabled()) { return; } $this->createLayoutBoxes($manager, [ 'showcase' => [ 'type' => 'Showcase', 'name' => 'Showcase', 'settings' => [ 'status' => $this->getReference('product_status_featured')->getId(), 'limit' => 10, 'categories' => [], ], ], ]); $manager->flush(); }
[ "public", "function", "load", "(", "ObjectManager", "$", "manager", ")", "{", "if", "(", "!", "$", "this", "->", "isEnabled", "(", ")", ")", "{", "return", ";", "}", "$", "this", "->", "createLayoutBoxes", "(", "$", "manager", ",", "[", "'showcase'", "=>", "[", "'type'", "=>", "'Showcase'", ",", "'name'", "=>", "'Showcase'", ",", "'settings'", "=>", "[", "'status'", "=>", "$", "this", "->", "getReference", "(", "'product_status_featured'", ")", "->", "getId", "(", ")", ",", "'limit'", "=>", "10", ",", "'categories'", "=>", "[", "]", ",", "]", ",", "]", ",", "]", ")", ";", "$", "manager", "->", "flush", "(", ")", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/WellCommerce/StandardEditionBundle/blob/6367bd20bbb6bde37c710a6ba87ae72b5f05f61e/DataFixtures/ORM/LoadShowcaseData.php#L28-L47
Eresus/EresusCMS
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mta/mta_transport.php
ezcMailMtaTransport.send
public function send( ezcMail $mail ) { $mail->appendExcludeHeaders( array( 'to', 'subject' ) ); $headers = rtrim( $mail->generateHeaders() ); // rtrim removes the linebreak at the end, mail doesn't want it. if ( ( count( $mail->to ) + count( $mail->cc ) + count( $mail->bcc ) ) < 1 ) { throw new ezcMailTransportException( 'No recipient addresses found in message header.' ); } $additionalParameters = ""; if ( isset( $mail->returnPath ) ) { $additionalParameters = "-f{$mail->returnPath->email}"; } $success = mail( ezcMailTools::composeEmailAddresses( $mail->to ), $mail->getHeader( 'Subject' ), $mail->generateBody(), $headers, $additionalParameters ); if ( $success === false ) { throw new ezcMailTransportException( 'The email could not be sent by sendmail' ); } }
php
public function send( ezcMail $mail ) { $mail->appendExcludeHeaders( array( 'to', 'subject' ) ); $headers = rtrim( $mail->generateHeaders() ); // rtrim removes the linebreak at the end, mail doesn't want it. if ( ( count( $mail->to ) + count( $mail->cc ) + count( $mail->bcc ) ) < 1 ) { throw new ezcMailTransportException( 'No recipient addresses found in message header.' ); } $additionalParameters = ""; if ( isset( $mail->returnPath ) ) { $additionalParameters = "-f{$mail->returnPath->email}"; } $success = mail( ezcMailTools::composeEmailAddresses( $mail->to ), $mail->getHeader( 'Subject' ), $mail->generateBody(), $headers, $additionalParameters ); if ( $success === false ) { throw new ezcMailTransportException( 'The email could not be sent by sendmail' ); } }
[ "public", "function", "send", "(", "ezcMail", "$", "mail", ")", "{", "$", "mail", "->", "appendExcludeHeaders", "(", "array", "(", "'to'", ",", "'subject'", ")", ")", ";", "$", "headers", "=", "rtrim", "(", "$", "mail", "->", "generateHeaders", "(", ")", ")", ";", "// rtrim removes the linebreak at the end, mail doesn't want it.", "if", "(", "(", "count", "(", "$", "mail", "->", "to", ")", "+", "count", "(", "$", "mail", "->", "cc", ")", "+", "count", "(", "$", "mail", "->", "bcc", ")", ")", "<", "1", ")", "{", "throw", "new", "ezcMailTransportException", "(", "'No recipient addresses found in message header.'", ")", ";", "}", "$", "additionalParameters", "=", "\"\"", ";", "if", "(", "isset", "(", "$", "mail", "->", "returnPath", ")", ")", "{", "$", "additionalParameters", "=", "\"-f{$mail->returnPath->email}\"", ";", "}", "$", "success", "=", "mail", "(", "ezcMailTools", "::", "composeEmailAddresses", "(", "$", "mail", "->", "to", ")", ",", "$", "mail", "->", "getHeader", "(", "'Subject'", ")", ",", "$", "mail", "->", "generateBody", "(", ")", ",", "$", "headers", ",", "$", "additionalParameters", ")", ";", "if", "(", "$", "success", "===", "false", ")", "{", "throw", "new", "ezcMailTransportException", "(", "'The email could not be sent by sendmail'", ")", ";", "}", "}" ]
Sends the mail $mail using the PHP mail method. Note that a message may not arrive at the destination even though it was accepted for delivery. @throws ezcMailTransportException if the mail was not accepted for delivery by the MTA. @param ezcMail $mail
[ "Sends", "the", "mail", "$mail", "using", "the", "PHP", "mail", "method", "." ]
train
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mta/mta_transport.php#L43-L63
Danack/GithubArtaxService
lib/GithubService/Operation/listForks.php
listForks.getFilteredParameter
public function getFilteredParameter($name) { if (array_key_exists($name, $this->parameters) == false) { throw new \Exception('Parameter '.$name.' does not exist.'); } $value = $this->parameters[$name]; return $value; }
php
public function getFilteredParameter($name) { if (array_key_exists($name, $this->parameters) == false) { throw new \Exception('Parameter '.$name.' does not exist.'); } $value = $this->parameters[$name]; return $value; }
[ "public", "function", "getFilteredParameter", "(", "$", "name", ")", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "parameters", ")", "==", "false", ")", "{", "throw", "new", "\\", "Exception", "(", "'Parameter '", ".", "$", "name", ".", "' does not exist.'", ")", ";", "}", "$", "value", "=", "$", "this", "->", "parameters", "[", "$", "name", "]", ";", "return", "$", "value", ";", "}" ]
Apply any filters necessary to the parameter @return mixed @param string $name The name of the parameter to get.
[ "Apply", "any", "filters", "necessary", "to", "the", "parameter" ]
train
https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/listForks.php#L71-L80
Danack/GithubArtaxService
lib/GithubService/Operation/listForks.php
listForks.createRequest
public function createRequest() { $request = new \Amp\Artax\Request(); $url = null; $request->setMethod(''); //Parameters are parsed and set, lets prepare the request if ($url == null) { $url = "https://api.github.com"; } $request->setUri($url); return $request; }
php
public function createRequest() { $request = new \Amp\Artax\Request(); $url = null; $request->setMethod(''); //Parameters are parsed and set, lets prepare the request if ($url == null) { $url = "https://api.github.com"; } $request->setUri($url); return $request; }
[ "public", "function", "createRequest", "(", ")", "{", "$", "request", "=", "new", "\\", "Amp", "\\", "Artax", "\\", "Request", "(", ")", ";", "$", "url", "=", "null", ";", "$", "request", "->", "setMethod", "(", "''", ")", ";", "//Parameters are parsed and set, lets prepare the request", "if", "(", "$", "url", "==", "null", ")", "{", "$", "url", "=", "\"https://api.github.com\"", ";", "}", "$", "request", "->", "setUri", "(", "$", "url", ")", ";", "return", "$", "request", ";", "}" ]
Create an Amp\Artax\Request object from the operation. @return \Amp\Artax\Request
[ "Create", "an", "Amp", "\\", "Artax", "\\", "Request", "object", "from", "the", "operation", "." ]
train
https://github.com/Danack/GithubArtaxService/blob/9f62b5be4f413207d4012e7fa084d0ae505680eb/lib/GithubService/Operation/listForks.php#L87-L101
djboris88/twig-commented-include
src/TokenParser/CommentedIncludeTokenParser.php
CommentedIncludeTokenParser.parse
public function parse(Twig_Token $token) { $expr = $this->parser->getExpressionParser()->parseExpression(); list($variables, $only, $ignoreMissing) = $this->parseArguments(); return new CommentedIncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); }
php
public function parse(Twig_Token $token) { $expr = $this->parser->getExpressionParser()->parseExpression(); list($variables, $only, $ignoreMissing) = $this->parseArguments(); return new CommentedIncludeNode($expr, $variables, $only, $ignoreMissing, $token->getLine(), $this->getTag()); }
[ "public", "function", "parse", "(", "Twig_Token", "$", "token", ")", "{", "$", "expr", "=", "$", "this", "->", "parser", "->", "getExpressionParser", "(", ")", "->", "parseExpression", "(", ")", ";", "list", "(", "$", "variables", ",", "$", "only", ",", "$", "ignoreMissing", ")", "=", "$", "this", "->", "parseArguments", "(", ")", ";", "return", "new", "CommentedIncludeNode", "(", "$", "expr", ",", "$", "variables", ",", "$", "only", ",", "$", "ignoreMissing", ",", "$", "token", "->", "getLine", "(", ")", ",", "$", "this", "->", "getTag", "(", ")", ")", ";", "}" ]
@param \Twig_Token $token @return \Djboris88\Twig\Node\CommentedIncludeNode
[ "@param", "\\", "Twig_Token", "$token" ]
train
https://github.com/djboris88/twig-commented-include/blob/424e0132e5416eadb3b02b7288b5a9d9df6b2475/src/TokenParser/CommentedIncludeTokenParser.php#L27-L34
nabab/bbn
src/bbn/file/image.php
image.remove_alpha_imagick
private static function remove_alpha_imagick(\Imagick $img){ if ( $img->getImageAlphaChannel() ){ $img->setImageBackgroundColor('#FFFFFF'); $img->setImageAlphaChannel(11); //$img->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN); //$img->transformImageColorspace(\Imagick::COLORSPACE_RGB); } return $img; }
php
private static function remove_alpha_imagick(\Imagick $img){ if ( $img->getImageAlphaChannel() ){ $img->setImageBackgroundColor('#FFFFFF'); $img->setImageAlphaChannel(11); //$img->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN); //$img->transformImageColorspace(\Imagick::COLORSPACE_RGB); } return $img; }
[ "private", "static", "function", "remove_alpha_imagick", "(", "\\", "Imagick", "$", "img", ")", "{", "if", "(", "$", "img", "->", "getImageAlphaChannel", "(", ")", ")", "{", "$", "img", "->", "setImageBackgroundColor", "(", "'#FFFFFF'", ")", ";", "$", "img", "->", "setImageAlphaChannel", "(", "11", ")", ";", "//$img->mergeImageLayers(\\Imagick::LAYERMETHOD_FLATTEN);", "//$img->transformImageColorspace(\\Imagick::COLORSPACE_RGB);", "}", "return", "$", "img", ";", "}" ]
Removes the alpha channel from an image (Imagick) @param \Imagick $img The Imagick object @return \Imagick
[ "Removes", "the", "alpha", "channel", "from", "an", "image", "(", "Imagick", ")" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L62-L70
nabab/bbn
src/bbn/file/image.php
image.jpg2pdf
public static function jpg2pdf($jpg, $pdf){ if ( class_exists('\\Imagick') ){ if ( \is_array($jpg) ){ $img = new \Imagick(); $img->setResolution(200, 200); if ( \count($jpg) === 1 ){ $img->readImage($jpg[0]); } else { $img->readImages($jpg); } $img->setImageFormat('pdf'); if ( \count($jpg) === 1 ){ $img->writeImage($pdf); } else { $img->writeImages($pdf, 1); } return $pdf; } } return false; }
php
public static function jpg2pdf($jpg, $pdf){ if ( class_exists('\\Imagick') ){ if ( \is_array($jpg) ){ $img = new \Imagick(); $img->setResolution(200, 200); if ( \count($jpg) === 1 ){ $img->readImage($jpg[0]); } else { $img->readImages($jpg); } $img->setImageFormat('pdf'); if ( \count($jpg) === 1 ){ $img->writeImage($pdf); } else { $img->writeImages($pdf, 1); } return $pdf; } } return false; }
[ "public", "static", "function", "jpg2pdf", "(", "$", "jpg", ",", "$", "pdf", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "if", "(", "\\", "is_array", "(", "$", "jpg", ")", ")", "{", "$", "img", "=", "new", "\\", "Imagick", "(", ")", ";", "$", "img", "->", "setResolution", "(", "200", ",", "200", ")", ";", "if", "(", "\\", "count", "(", "$", "jpg", ")", "===", "1", ")", "{", "$", "img", "->", "readImage", "(", "$", "jpg", "[", "0", "]", ")", ";", "}", "else", "{", "$", "img", "->", "readImages", "(", "$", "jpg", ")", ";", "}", "$", "img", "->", "setImageFormat", "(", "'pdf'", ")", ";", "if", "(", "\\", "count", "(", "$", "jpg", ")", "===", "1", ")", "{", "$", "img", "->", "writeImage", "(", "$", "pdf", ")", ";", "}", "else", "{", "$", "img", "->", "writeImages", "(", "$", "pdf", ",", "1", ")", ";", "}", "return", "$", "pdf", ";", "}", "}", "return", "false", ";", "}" ]
Converts one or more jpg image(s) to a pdf file. If the pdf file doesn't exist will be created. ```php bbn\x::dump(bbn\file\image::jpg2pdf(["/home/data/test/two.jpg","/home/data/test/one.jpeg"], "/home/data/test/doc.pdf")); // (string) "/home/data/test/doc.pdf" ``` @param array $jpg The path of jpg file(s) to convert @param string $pdf The path of the pdf file @return string|false
[ "Converts", "one", "or", "more", "jpg", "image", "(", "s", ")", "to", "a", "pdf", "file", ".", "If", "the", "pdf", "file", "doesn", "t", "exist", "will", "be", "created", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L84-L106
nabab/bbn
src/bbn/file/image.php
image.pdf2jpg
public static function pdf2jpg($pdf, $jpg='', $num=0){ if ( class_exists('\\Imagick') ){ $img = new \Imagick(); $img->setResolution(200, 200); $img->readImage($pdf); $img->setFormat('jpg'); if ( empty($jpg) ){ $dir = dirname($pdf); if ( !empty($dir) ){ $dir .= '/'; } $f = bbn\str::file_ext($pdf, 1); $jpg = $dir.$f[0].'.jpg'; } if ( $num !== 'all' ){ $img->setIteratorIndex($num); $img = self::remove_alpha_imagick($img); if ( $img->writeImage($jpg) ){ return $jpg; } } else { $pages_number = $img->getNumberImages(); $f = bbn\str::file_ext($jpg, 1); $dir = dirname($jpg); $r = []; if ( !empty($dir) ){ $dir .= '/'; } for ( $i = 0; $i < $pages_number; $i++ ){ $img->setIteratorIndex($i); $img = self::remove_alpha_imagick($img); $filename = $dir.$f[0]; if ( $pages_number > 1 ){ $l = \strlen((string)$i); if ( $l < $pages_number ){ $filename .= '-'.str_repeat('0', \strlen($pages_number) - $l).$i; } } $filename .= '.'.$f[1]; if ( $img->writeImage($filename) ){ array_push($r, $filename); } } if ( \count($r) === $pages_number ){ return $r; } } } return false; }
php
public static function pdf2jpg($pdf, $jpg='', $num=0){ if ( class_exists('\\Imagick') ){ $img = new \Imagick(); $img->setResolution(200, 200); $img->readImage($pdf); $img->setFormat('jpg'); if ( empty($jpg) ){ $dir = dirname($pdf); if ( !empty($dir) ){ $dir .= '/'; } $f = bbn\str::file_ext($pdf, 1); $jpg = $dir.$f[0].'.jpg'; } if ( $num !== 'all' ){ $img->setIteratorIndex($num); $img = self::remove_alpha_imagick($img); if ( $img->writeImage($jpg) ){ return $jpg; } } else { $pages_number = $img->getNumberImages(); $f = bbn\str::file_ext($jpg, 1); $dir = dirname($jpg); $r = []; if ( !empty($dir) ){ $dir .= '/'; } for ( $i = 0; $i < $pages_number; $i++ ){ $img->setIteratorIndex($i); $img = self::remove_alpha_imagick($img); $filename = $dir.$f[0]; if ( $pages_number > 1 ){ $l = \strlen((string)$i); if ( $l < $pages_number ){ $filename .= '-'.str_repeat('0', \strlen($pages_number) - $l).$i; } } $filename .= '.'.$f[1]; if ( $img->writeImage($filename) ){ array_push($r, $filename); } } if ( \count($r) === $pages_number ){ return $r; } } } return false; }
[ "public", "static", "function", "pdf2jpg", "(", "$", "pdf", ",", "$", "jpg", "=", "''", ",", "$", "num", "=", "0", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "$", "img", "=", "new", "\\", "Imagick", "(", ")", ";", "$", "img", "->", "setResolution", "(", "200", ",", "200", ")", ";", "$", "img", "->", "readImage", "(", "$", "pdf", ")", ";", "$", "img", "->", "setFormat", "(", "'jpg'", ")", ";", "if", "(", "empty", "(", "$", "jpg", ")", ")", "{", "$", "dir", "=", "dirname", "(", "$", "pdf", ")", ";", "if", "(", "!", "empty", "(", "$", "dir", ")", ")", "{", "$", "dir", ".=", "'/'", ";", "}", "$", "f", "=", "bbn", "\\", "str", "::", "file_ext", "(", "$", "pdf", ",", "1", ")", ";", "$", "jpg", "=", "$", "dir", ".", "$", "f", "[", "0", "]", ".", "'.jpg'", ";", "}", "if", "(", "$", "num", "!==", "'all'", ")", "{", "$", "img", "->", "setIteratorIndex", "(", "$", "num", ")", ";", "$", "img", "=", "self", "::", "remove_alpha_imagick", "(", "$", "img", ")", ";", "if", "(", "$", "img", "->", "writeImage", "(", "$", "jpg", ")", ")", "{", "return", "$", "jpg", ";", "}", "}", "else", "{", "$", "pages_number", "=", "$", "img", "->", "getNumberImages", "(", ")", ";", "$", "f", "=", "bbn", "\\", "str", "::", "file_ext", "(", "$", "jpg", ",", "1", ")", ";", "$", "dir", "=", "dirname", "(", "$", "jpg", ")", ";", "$", "r", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "dir", ")", ")", "{", "$", "dir", ".=", "'/'", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "pages_number", ";", "$", "i", "++", ")", "{", "$", "img", "->", "setIteratorIndex", "(", "$", "i", ")", ";", "$", "img", "=", "self", "::", "remove_alpha_imagick", "(", "$", "img", ")", ";", "$", "filename", "=", "$", "dir", ".", "$", "f", "[", "0", "]", ";", "if", "(", "$", "pages_number", ">", "1", ")", "{", "$", "l", "=", "\\", "strlen", "(", "(", "string", ")", "$", "i", ")", ";", "if", "(", "$", "l", "<", "$", "pages_number", ")", "{", "$", "filename", ".=", "'-'", ".", "str_repeat", "(", "'0'", ",", "\\", "strlen", "(", "$", "pages_number", ")", "-", "$", "l", ")", ".", "$", "i", ";", "}", "}", "$", "filename", ".=", "'.'", ".", "$", "f", "[", "1", "]", ";", "if", "(", "$", "img", "->", "writeImage", "(", "$", "filename", ")", ")", "{", "array_push", "(", "$", "r", ",", "$", "filename", ")", ";", "}", "}", "if", "(", "\\", "count", "(", "$", "r", ")", "===", "$", "pages_number", ")", "{", "return", "$", "r", ";", "}", "}", "}", "return", "false", ";", "}" ]
Converts pdf file to jpg image(s). ```php bbn\x::dump(bbn\file\image::pdf2jpg("/home/data/test/doc.pdf")); // (string) "/home/data/test/doc.jpg" bbn\x::dump(bbn\file\image::pdf2jpg("/home/data/test/doc.pdf",'', all)); // (array) ["/home/data/test/doc-0.jpg","/home/data/test/doc-1.jpg"] bbn\x::dump(bbn\file\image::pdf2jpg("/home/data/test/doc.pdf",'/home/data/test/Folder/image.jpg', all)); // (array) ["/home/data/test/Folder/image-0.jpg", "/home/data/test/Folder/image-1.jpg"], ``` @param string $pdf The path of pdf file to convert @param string $jpg The destination filename. If empty is used the same path of pdf. Default: empty. @param int $num The index page of pdf file to convert. If set 'all' all pages to convert. Default: 0(first page). @return string|array
[ "Converts", "pdf", "file", "to", "jpg", "image", "(", "s", ")", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L125-L175
nabab/bbn
src/bbn/file/image.php
image.get_extension
public function get_extension(){ parent::get_extension(); if ( !$this->ext2 && $this->file ){ if ( function_exists('exif_imagetype') ){ if ( $r = exif_imagetype($this->file) ){ if ( !array_key_exists($r, bbn\file\image::$allowed_extensions) ){ $this->ext = false; } } else{ $this->ext = false; } } if ( $this->ext ){ $this->ext2 = $this->ext; if ( $this->ext2 === 'jpg' ){ $this->ext2 = 'jpeg'; } } } return $this->ext; }
php
public function get_extension(){ parent::get_extension(); if ( !$this->ext2 && $this->file ){ if ( function_exists('exif_imagetype') ){ if ( $r = exif_imagetype($this->file) ){ if ( !array_key_exists($r, bbn\file\image::$allowed_extensions) ){ $this->ext = false; } } else{ $this->ext = false; } } if ( $this->ext ){ $this->ext2 = $this->ext; if ( $this->ext2 === 'jpg' ){ $this->ext2 = 'jpeg'; } } } return $this->ext; }
[ "public", "function", "get_extension", "(", ")", "{", "parent", "::", "get_extension", "(", ")", ";", "if", "(", "!", "$", "this", "->", "ext2", "&&", "$", "this", "->", "file", ")", "{", "if", "(", "function_exists", "(", "'exif_imagetype'", ")", ")", "{", "if", "(", "$", "r", "=", "exif_imagetype", "(", "$", "this", "->", "file", ")", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "r", ",", "bbn", "\\", "file", "\\", "image", "::", "$", "allowed_extensions", ")", ")", "{", "$", "this", "->", "ext", "=", "false", ";", "}", "}", "else", "{", "$", "this", "->", "ext", "=", "false", ";", "}", "}", "if", "(", "$", "this", "->", "ext", ")", "{", "$", "this", "->", "ext2", "=", "$", "this", "->", "ext", ";", "if", "(", "$", "this", "->", "ext2", "===", "'jpg'", ")", "{", "$", "this", "->", "ext2", "=", "'jpeg'", ";", "}", "}", "}", "return", "$", "this", "->", "ext", ";", "}" ]
Returns the extension of the image. If the file has jpg extension will return 'jpeg'. ```php $img = new bbn\file\image("/home/data/test/image.jpg"); bbn\x::dump($img->get_extension()); // (string) "jpeg" ``` @return string
[ "Returns", "the", "extension", "of", "the", "image", ".", "If", "the", "file", "has", "jpg", "extension", "will", "return", "jpeg", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L205-L226
nabab/bbn
src/bbn/file/image.php
image.display
public function display() { if ( $this->test() ){ if ( !headers_sent() ){ header('Content-Type: image/'.$this->ext2); } if ( class_exists('\\Imagick') ){ echo $this->img; $this->img->clear(); $this->img->destroy(); } else{ \call_user_func('image'.$this->ext2, $this->img); imagedestroy($this->img); } } return $this; }
php
public function display() { if ( $this->test() ){ if ( !headers_sent() ){ header('Content-Type: image/'.$this->ext2); } if ( class_exists('\\Imagick') ){ echo $this->img; $this->img->clear(); $this->img->destroy(); } else{ \call_user_func('image'.$this->ext2, $this->img); imagedestroy($this->img); } } return $this; }
[ "public", "function", "display", "(", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", ")", "{", "if", "(", "!", "headers_sent", "(", ")", ")", "{", "header", "(", "'Content-Type: image/'", ".", "$", "this", "->", "ext2", ")", ";", "}", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "echo", "$", "this", "->", "img", ";", "$", "this", "->", "img", "->", "clear", "(", ")", ";", "$", "this", "->", "img", "->", "destroy", "(", ")", ";", "}", "else", "{", "\\", "call_user_func", "(", "'image'", ".", "$", "this", "->", "ext2", ",", "$", "this", "->", "img", ")", ";", "imagedestroy", "(", "$", "this", "->", "img", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Sends the image with Content-Type. ```php $img = new bbn\file\image("/home/data/test/image.jpg"); $img->display(); ``` @return image
[ "Sends", "the", "image", "with", "Content", "-", "Type", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L338-L355
nabab/bbn
src/bbn/file/image.php
image.save
public function save($dest=false) { if ( $this->test() ){ if ( !$dest ){ $dest = $this->file; } if ( class_exists('\\Imagick') ){ try{ $this->img->writeImage($dest); } catch ( \Exception $e ){ die(var_dump($dest, $this->file)); $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( function_exists('image'.$this->ext2) ){ if ( !\call_user_func('image'.$this->ext2, $this->img, $dest) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
php
public function save($dest=false) { if ( $this->test() ){ if ( !$dest ){ $dest = $this->file; } if ( class_exists('\\Imagick') ){ try{ $this->img->writeImage($dest); } catch ( \Exception $e ){ die(var_dump($dest, $this->file)); $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( function_exists('image'.$this->ext2) ){ if ( !\call_user_func('image'.$this->ext2, $this->img, $dest) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
[ "public", "function", "save", "(", "$", "dest", "=", "false", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", ")", "{", "if", "(", "!", "$", "dest", ")", "{", "$", "dest", "=", "$", "this", "->", "file", ";", "}", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "try", "{", "$", "this", "->", "img", "->", "writeImage", "(", "$", "dest", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "die", "(", "var_dump", "(", "$", "dest", ",", "$", "this", "->", "file", ")", ")", ";", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "else", "if", "(", "function_exists", "(", "'image'", ".", "$", "this", "->", "ext2", ")", ")", "{", "if", "(", "!", "\\", "call_user_func", "(", "'image'", ".", "$", "this", "->", "ext2", ",", "$", "this", "->", "img", ",", "$", "dest", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Save the image in a new destination if given or overwrite the file (default). ```php $new_file="/home/data/test/Folder_test/image_test.jpeg"; $img2=new bbn\file\image($new_file); bbn\x::dump($img2->test()); // (bool) false bbn\x::dump($img->save($new_file)); bbn\x::dump($img2->test()); // (bool) true ``` @param string $dest The destination of the file to save. Default = false, the file will overwrited. @return image
[ "Save", "the", "image", "in", "a", "new", "destination", "if", "given", "or", "overwrite", "the", "file", "(", "default", ")", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L373-L397
nabab/bbn
src/bbn/file/image.php
image.resize
public function resize($w=false, $h=false, $crop=false, $max_w=false, $max_h=false) { $max_w = false; $max_h = false; if ( \is_array($w) ){ $max_w = isset($w['max_w']) ? $w['max_w'] : false; $max_h = isset($w['max_h']) ? $w['max_h'] : false; $crop = isset($w['crop']) ? $w['crop'] : false; $h = isset($w['h']) ? $w['h'] : false; $w = isset($w['w']) ? $w['w'] : false; } if ( ( $w || $h ) && $this->test() ){ if ( $w && $h ){ if ( $crop && ( ( $this->w / $this->h ) != ( $w / $h ) ) ){ if ( ( $this->w / $this->h ) < ( $w / $h ) ){ $w2 = $w; $h2 = floor(($w2*$this->h)/$this->w); $x = 0; $y = floor(($h2-$h)/2); } else if ( ( $this->w / $this->h ) > ( $w / $h ) ){ $h2 = $h; $w2 = floor(($h2*$this->w)/$this->h); $y = 0; $x = floor(($w2-$w)/2); } if ( class_exists('\\Imagick') ){ $res = $this->img->resizeImage($w2,$h2,\Imagick::FILTER_LANCZOS,1); } else{ $image = imagecreatetruecolor($w2,$h2); if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){ imageColorAllocateAlpha($image, 0, 0, 0, 127); imagealphablending($image, false); imagesavealpha($image, true); } $res = imagecopyresampled($image,$this->img,0,0,0,0,$w2,$h2,$this->w,$this->h); $this->img = $image; } if ( $res === true ){ $this->w = $w2; $this->h = $h2; if ( $this->crop($w,$h,$x,$y) ){ $this->w = $w; $this->h = $h; } } } else{ $w2 = $w; $h2 = $h; if ( class_exists('\\Imagick') ){ $res = $this->img->resizeImage($w2,$h2,\Imagick::FILTER_LANCZOS,1); } else{ $image = imagecreatetruecolor($w2,$h2); if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){ imageColorAllocateAlpha($image, 0, 0, 0, 127); imagealphablending($image, false); imagesavealpha($image, true); } $res = imagecopyresampled($image,$this->img,0,0,0,0,$w2,$h2,$this->w,$this->h); $this->img = $image; } } } else{ if ( $w > 0 ){ $w2 = $w; $h2 = floor(($w2*$this->h)/$this->w); } if ( $h > 0 ){ if ( isset($h2) ){ if ( $h2 > $h ){ $h2 = $h; $w2 = floor(($h2*$this->w)/$this->h); } } else{ $h2 = $h; $w2 = floor(($h2*$this->w)/$this->h); } } if ( isset($w2,$h2) ){ if ( class_exists('\\Imagick') ){ $res = $this->img->resizeImage($w2,$h2,\Imagick::FILTER_LANCZOS,1); } else{ $image = imagecreatetruecolor($w2,$h2); if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){ imageColorAllocateAlpha($image, 0, 0, 0, 127); imagealphablending($image, false); imagesavealpha($image, true); } $res = imagecopyresampled($image,$this->img,0,0,0,0,$w2,$h2,$this->w,$this->h); $this->img = $image; } if ( $res === true ){ $this->w = $w2; $this->h = $h2; } else{ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else{ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
php
public function resize($w=false, $h=false, $crop=false, $max_w=false, $max_h=false) { $max_w = false; $max_h = false; if ( \is_array($w) ){ $max_w = isset($w['max_w']) ? $w['max_w'] : false; $max_h = isset($w['max_h']) ? $w['max_h'] : false; $crop = isset($w['crop']) ? $w['crop'] : false; $h = isset($w['h']) ? $w['h'] : false; $w = isset($w['w']) ? $w['w'] : false; } if ( ( $w || $h ) && $this->test() ){ if ( $w && $h ){ if ( $crop && ( ( $this->w / $this->h ) != ( $w / $h ) ) ){ if ( ( $this->w / $this->h ) < ( $w / $h ) ){ $w2 = $w; $h2 = floor(($w2*$this->h)/$this->w); $x = 0; $y = floor(($h2-$h)/2); } else if ( ( $this->w / $this->h ) > ( $w / $h ) ){ $h2 = $h; $w2 = floor(($h2*$this->w)/$this->h); $y = 0; $x = floor(($w2-$w)/2); } if ( class_exists('\\Imagick') ){ $res = $this->img->resizeImage($w2,$h2,\Imagick::FILTER_LANCZOS,1); } else{ $image = imagecreatetruecolor($w2,$h2); if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){ imageColorAllocateAlpha($image, 0, 0, 0, 127); imagealphablending($image, false); imagesavealpha($image, true); } $res = imagecopyresampled($image,$this->img,0,0,0,0,$w2,$h2,$this->w,$this->h); $this->img = $image; } if ( $res === true ){ $this->w = $w2; $this->h = $h2; if ( $this->crop($w,$h,$x,$y) ){ $this->w = $w; $this->h = $h; } } } else{ $w2 = $w; $h2 = $h; if ( class_exists('\\Imagick') ){ $res = $this->img->resizeImage($w2,$h2,\Imagick::FILTER_LANCZOS,1); } else{ $image = imagecreatetruecolor($w2,$h2); if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){ imageColorAllocateAlpha($image, 0, 0, 0, 127); imagealphablending($image, false); imagesavealpha($image, true); } $res = imagecopyresampled($image,$this->img,0,0,0,0,$w2,$h2,$this->w,$this->h); $this->img = $image; } } } else{ if ( $w > 0 ){ $w2 = $w; $h2 = floor(($w2*$this->h)/$this->w); } if ( $h > 0 ){ if ( isset($h2) ){ if ( $h2 > $h ){ $h2 = $h; $w2 = floor(($h2*$this->w)/$this->h); } } else{ $h2 = $h; $w2 = floor(($h2*$this->w)/$this->h); } } if ( isset($w2,$h2) ){ if ( class_exists('\\Imagick') ){ $res = $this->img->resizeImage($w2,$h2,\Imagick::FILTER_LANCZOS,1); } else{ $image = imagecreatetruecolor($w2,$h2); if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){ imageColorAllocateAlpha($image, 0, 0, 0, 127); imagealphablending($image, false); imagesavealpha($image, true); } $res = imagecopyresampled($image,$this->img,0,0,0,0,$w2,$h2,$this->w,$this->h); $this->img = $image; } if ( $res === true ){ $this->w = $w2; $this->h = $h2; } else{ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else{ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
[ "public", "function", "resize", "(", "$", "w", "=", "false", ",", "$", "h", "=", "false", ",", "$", "crop", "=", "false", ",", "$", "max_w", "=", "false", ",", "$", "max_h", "=", "false", ")", "{", "$", "max_w", "=", "false", ";", "$", "max_h", "=", "false", ";", "if", "(", "\\", "is_array", "(", "$", "w", ")", ")", "{", "$", "max_w", "=", "isset", "(", "$", "w", "[", "'max_w'", "]", ")", "?", "$", "w", "[", "'max_w'", "]", ":", "false", ";", "$", "max_h", "=", "isset", "(", "$", "w", "[", "'max_h'", "]", ")", "?", "$", "w", "[", "'max_h'", "]", ":", "false", ";", "$", "crop", "=", "isset", "(", "$", "w", "[", "'crop'", "]", ")", "?", "$", "w", "[", "'crop'", "]", ":", "false", ";", "$", "h", "=", "isset", "(", "$", "w", "[", "'h'", "]", ")", "?", "$", "w", "[", "'h'", "]", ":", "false", ";", "$", "w", "=", "isset", "(", "$", "w", "[", "'w'", "]", ")", "?", "$", "w", "[", "'w'", "]", ":", "false", ";", "}", "if", "(", "(", "$", "w", "||", "$", "h", ")", "&&", "$", "this", "->", "test", "(", ")", ")", "{", "if", "(", "$", "w", "&&", "$", "h", ")", "{", "if", "(", "$", "crop", "&&", "(", "(", "$", "this", "->", "w", "/", "$", "this", "->", "h", ")", "!=", "(", "$", "w", "/", "$", "h", ")", ")", ")", "{", "if", "(", "(", "$", "this", "->", "w", "/", "$", "this", "->", "h", ")", "<", "(", "$", "w", "/", "$", "h", ")", ")", "{", "$", "w2", "=", "$", "w", ";", "$", "h2", "=", "floor", "(", "(", "$", "w2", "*", "$", "this", "->", "h", ")", "/", "$", "this", "->", "w", ")", ";", "$", "x", "=", "0", ";", "$", "y", "=", "floor", "(", "(", "$", "h2", "-", "$", "h", ")", "/", "2", ")", ";", "}", "else", "if", "(", "(", "$", "this", "->", "w", "/", "$", "this", "->", "h", ")", ">", "(", "$", "w", "/", "$", "h", ")", ")", "{", "$", "h2", "=", "$", "h", ";", "$", "w2", "=", "floor", "(", "(", "$", "h2", "*", "$", "this", "->", "w", ")", "/", "$", "this", "->", "h", ")", ";", "$", "y", "=", "0", ";", "$", "x", "=", "floor", "(", "(", "$", "w2", "-", "$", "w", ")", "/", "2", ")", ";", "}", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "$", "res", "=", "$", "this", "->", "img", "->", "resizeImage", "(", "$", "w2", ",", "$", "h2", ",", "\\", "Imagick", "::", "FILTER_LANCZOS", ",", "1", ")", ";", "}", "else", "{", "$", "image", "=", "imagecreatetruecolor", "(", "$", "w2", ",", "$", "h2", ")", ";", "if", "(", "$", "this", "->", "ext", "==", "'png'", "||", "$", "this", "->", "ext", "==", "'gif'", "||", "$", "this", "->", "ext", "==", "'svg'", ")", "{", "imageColorAllocateAlpha", "(", "$", "image", ",", "0", ",", "0", ",", "0", ",", "127", ")", ";", "imagealphablending", "(", "$", "image", ",", "false", ")", ";", "imagesavealpha", "(", "$", "image", ",", "true", ")", ";", "}", "$", "res", "=", "imagecopyresampled", "(", "$", "image", ",", "$", "this", "->", "img", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "w2", ",", "$", "h2", ",", "$", "this", "->", "w", ",", "$", "this", "->", "h", ")", ";", "$", "this", "->", "img", "=", "$", "image", ";", "}", "if", "(", "$", "res", "===", "true", ")", "{", "$", "this", "->", "w", "=", "$", "w2", ";", "$", "this", "->", "h", "=", "$", "h2", ";", "if", "(", "$", "this", "->", "crop", "(", "$", "w", ",", "$", "h", ",", "$", "x", ",", "$", "y", ")", ")", "{", "$", "this", "->", "w", "=", "$", "w", ";", "$", "this", "->", "h", "=", "$", "h", ";", "}", "}", "}", "else", "{", "$", "w2", "=", "$", "w", ";", "$", "h2", "=", "$", "h", ";", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "$", "res", "=", "$", "this", "->", "img", "->", "resizeImage", "(", "$", "w2", ",", "$", "h2", ",", "\\", "Imagick", "::", "FILTER_LANCZOS", ",", "1", ")", ";", "}", "else", "{", "$", "image", "=", "imagecreatetruecolor", "(", "$", "w2", ",", "$", "h2", ")", ";", "if", "(", "$", "this", "->", "ext", "==", "'png'", "||", "$", "this", "->", "ext", "==", "'gif'", "||", "$", "this", "->", "ext", "==", "'svg'", ")", "{", "imageColorAllocateAlpha", "(", "$", "image", ",", "0", ",", "0", ",", "0", ",", "127", ")", ";", "imagealphablending", "(", "$", "image", ",", "false", ")", ";", "imagesavealpha", "(", "$", "image", ",", "true", ")", ";", "}", "$", "res", "=", "imagecopyresampled", "(", "$", "image", ",", "$", "this", "->", "img", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "w2", ",", "$", "h2", ",", "$", "this", "->", "w", ",", "$", "this", "->", "h", ")", ";", "$", "this", "->", "img", "=", "$", "image", ";", "}", "}", "}", "else", "{", "if", "(", "$", "w", ">", "0", ")", "{", "$", "w2", "=", "$", "w", ";", "$", "h2", "=", "floor", "(", "(", "$", "w2", "*", "$", "this", "->", "h", ")", "/", "$", "this", "->", "w", ")", ";", "}", "if", "(", "$", "h", ">", "0", ")", "{", "if", "(", "isset", "(", "$", "h2", ")", ")", "{", "if", "(", "$", "h2", ">", "$", "h", ")", "{", "$", "h2", "=", "$", "h", ";", "$", "w2", "=", "floor", "(", "(", "$", "h2", "*", "$", "this", "->", "w", ")", "/", "$", "this", "->", "h", ")", ";", "}", "}", "else", "{", "$", "h2", "=", "$", "h", ";", "$", "w2", "=", "floor", "(", "(", "$", "h2", "*", "$", "this", "->", "w", ")", "/", "$", "this", "->", "h", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "w2", ",", "$", "h2", ")", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "$", "res", "=", "$", "this", "->", "img", "->", "resizeImage", "(", "$", "w2", ",", "$", "h2", ",", "\\", "Imagick", "::", "FILTER_LANCZOS", ",", "1", ")", ";", "}", "else", "{", "$", "image", "=", "imagecreatetruecolor", "(", "$", "w2", ",", "$", "h2", ")", ";", "if", "(", "$", "this", "->", "ext", "==", "'png'", "||", "$", "this", "->", "ext", "==", "'gif'", "||", "$", "this", "->", "ext", "==", "'svg'", ")", "{", "imageColorAllocateAlpha", "(", "$", "image", ",", "0", ",", "0", ",", "0", ",", "127", ")", ";", "imagealphablending", "(", "$", "image", ",", "false", ")", ";", "imagesavealpha", "(", "$", "image", ",", "true", ")", ";", "}", "$", "res", "=", "imagecopyresampled", "(", "$", "image", ",", "$", "this", "->", "img", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "w2", ",", "$", "h2", ",", "$", "this", "->", "w", ",", "$", "this", "->", "h", ")", ";", "$", "this", "->", "img", "=", "$", "image", ";", "}", "if", "(", "$", "res", "===", "true", ")", "{", "$", "this", "->", "w", "=", "$", "w2", ";", "$", "this", "->", "h", "=", "$", "h2", ";", "}", "else", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "else", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Resize the width and the height of the image. If is given only width or height the other dimension will be set on auto. @todo $max_h and $max_w doesn't work. ```php $img = new bbn\file\image("/home/data/test/image.jpg"); bbn\x::hdump($img->get_width(),$img->get_height()); // (int) 345 146 bbn\x::hdump($img->resize(200,"" )); bbn\x::hdump($img->get_width(),$img->get_height()); // (int) 200 84 bbn\x::hdump($img->get_width(),$img->get_height()); // (int) 345 146 bbn\x::dump($img->resize(205, 100, 1)); bbn\x::dump($img->get_width(),$img->get_height()); // (int) 205 100 ``` @param int|bool $w The new width. @param int|bool $h The new height. @param boolean $crop If cropping the image. Default = false. @param int|bool $max_w The maximum value for new width. @param int|bool $max_h The maximum valure for new height. @return image
[ "Resize", "the", "width", "and", "the", "height", "of", "the", "image", ".", "If", "is", "given", "only", "width", "or", "height", "the", "other", "dimension", "will", "be", "set", "on", "auto", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L467-L580
nabab/bbn
src/bbn/file/image.php
image.autoresize
public function autoresize($w=BBN_MAX_WIDTH, $h=BBN_MAX_HEIGHT) { if ( !$w ){ $w = \defined('BBN_MAX_WIDTH') ? BBN_MAX_WIDTH : self::$max_width; } if ( $this->test() && is_numeric($w) && is_numeric($h) ) { if ( $this->w > $w ){ $this->resize($w); } if ( $this->h > $h ){ $this->resize(false,$h); } } else{ $this->error = \defined('BBN_ARGUMENTS_MUST_BE_NUMERIC') ? BBN_ARGUMENTS_MUST_BE_NUMERIC : 'Arguments must be numeric'; } return $this; }
php
public function autoresize($w=BBN_MAX_WIDTH, $h=BBN_MAX_HEIGHT) { if ( !$w ){ $w = \defined('BBN_MAX_WIDTH') ? BBN_MAX_WIDTH : self::$max_width; } if ( $this->test() && is_numeric($w) && is_numeric($h) ) { if ( $this->w > $w ){ $this->resize($w); } if ( $this->h > $h ){ $this->resize(false,$h); } } else{ $this->error = \defined('BBN_ARGUMENTS_MUST_BE_NUMERIC') ? BBN_ARGUMENTS_MUST_BE_NUMERIC : 'Arguments must be numeric'; } return $this; }
[ "public", "function", "autoresize", "(", "$", "w", "=", "BBN_MAX_WIDTH", ",", "$", "h", "=", "BBN_MAX_HEIGHT", ")", "{", "if", "(", "!", "$", "w", ")", "{", "$", "w", "=", "\\", "defined", "(", "'BBN_MAX_WIDTH'", ")", "?", "BBN_MAX_WIDTH", ":", "self", "::", "$", "max_width", ";", "}", "if", "(", "$", "this", "->", "test", "(", ")", "&&", "is_numeric", "(", "$", "w", ")", "&&", "is_numeric", "(", "$", "h", ")", ")", "{", "if", "(", "$", "this", "->", "w", ">", "$", "w", ")", "{", "$", "this", "->", "resize", "(", "$", "w", ")", ";", "}", "if", "(", "$", "this", "->", "h", ">", "$", "h", ")", "{", "$", "this", "->", "resize", "(", "false", ",", "$", "h", ")", ";", "}", "}", "else", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_ARGUMENTS_MUST_BE_NUMERIC'", ")", "?", "BBN_ARGUMENTS_MUST_BE_NUMERIC", ":", "'Arguments must be numeric'", ";", "}", "return", "$", "this", ";", "}" ]
Resize the image with constant values, if the width is not given it will be set to auto. @todo BBN_MAX_WIDTH and BBN_MAX_HEIGHT ? ```php $img = new bbn\file\image("/home/data/test/image.jpg"); bbn\x::dump($img->get_width(),$img->get_height()); // (int) 345 146 $img->autoresize("", 100); bbn\x::dump($img->get_width(),$img->get_height()); // (int) 236 100 ``` @param integer $w default BBN_MAX_WIDTH @param integer $h default BBN_MAX_HEIGHT @return image
[ "Resize", "the", "image", "with", "constant", "values", "if", "the", "width", "is", "not", "given", "it", "will", "be", "set", "to", "auto", ".", "@todo", "BBN_MAX_WIDTH", "and", "BBN_MAX_HEIGHT", "?" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L599-L618
nabab/bbn
src/bbn/file/image.php
image.crop
public function crop($w, $h, $x, $y) { if ( $this->test() ){ $args = \func_get_args(); foreach ( $args as $arg ){ if ( !is_numeric($arg) ){ $this->error = \defined('BBN_ARGUMENTS_MUST_BE_NUMERIC') ? BBN_ARGUMENTS_MUST_BE_NUMERIC : 'Arguments must be numeric'; } } if ( $w + $x > $this->w ){ return false; } if ( $h + $y > $this->h ){ return false; } if ( class_exists('\\Imagick') ){ if ( !$this->img->cropImage($w,$h,$x,$y) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else { $img = imagecreatetruecolor($w,$h); if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){ imageColorAllocateAlpha($img, 0, 0, 0, 127); imagealphablending($img, false); imagesavealpha($img, true); } if ( imagecopyresampled($img,$this->img,0,0,$x,$y,$w,$h,$w,$h) ){ $this->img = $img; } else{ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
php
public function crop($w, $h, $x, $y) { if ( $this->test() ){ $args = \func_get_args(); foreach ( $args as $arg ){ if ( !is_numeric($arg) ){ $this->error = \defined('BBN_ARGUMENTS_MUST_BE_NUMERIC') ? BBN_ARGUMENTS_MUST_BE_NUMERIC : 'Arguments must be numeric'; } } if ( $w + $x > $this->w ){ return false; } if ( $h + $y > $this->h ){ return false; } if ( class_exists('\\Imagick') ){ if ( !$this->img->cropImage($w,$h,$x,$y) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else { $img = imagecreatetruecolor($w,$h); if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){ imageColorAllocateAlpha($img, 0, 0, 0, 127); imagealphablending($img, false); imagesavealpha($img, true); } if ( imagecopyresampled($img,$this->img,0,0,$x,$y,$w,$h,$w,$h) ){ $this->img = $img; } else{ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
[ "public", "function", "crop", "(", "$", "w", ",", "$", "h", ",", "$", "x", ",", "$", "y", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", ")", "{", "$", "args", "=", "\\", "func_get_args", "(", ")", ";", "foreach", "(", "$", "args", "as", "$", "arg", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "arg", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_ARGUMENTS_MUST_BE_NUMERIC'", ")", "?", "BBN_ARGUMENTS_MUST_BE_NUMERIC", ":", "'Arguments must be numeric'", ";", "}", "}", "if", "(", "$", "w", "+", "$", "x", ">", "$", "this", "->", "w", ")", "{", "return", "false", ";", "}", "if", "(", "$", "h", "+", "$", "y", ">", "$", "this", "->", "h", ")", "{", "return", "false", ";", "}", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "if", "(", "!", "$", "this", "->", "img", "->", "cropImage", "(", "$", "w", ",", "$", "h", ",", "$", "x", ",", "$", "y", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "else", "{", "$", "img", "=", "imagecreatetruecolor", "(", "$", "w", ",", "$", "h", ")", ";", "if", "(", "$", "this", "->", "ext", "==", "'png'", "||", "$", "this", "->", "ext", "==", "'gif'", "||", "$", "this", "->", "ext", "==", "'svg'", ")", "{", "imageColorAllocateAlpha", "(", "$", "img", ",", "0", ",", "0", ",", "0", ",", "127", ")", ";", "imagealphablending", "(", "$", "img", ",", "false", ")", ";", "imagesavealpha", "(", "$", "img", ",", "true", ")", ";", "}", "if", "(", "imagecopyresampled", "(", "$", "img", ",", "$", "this", "->", "img", ",", "0", ",", "0", ",", "$", "x", ",", "$", "y", ",", "$", "w", ",", "$", "h", ",", "$", "w", ",", "$", "h", ")", ")", "{", "$", "this", "->", "img", "=", "$", "img", ";", "}", "else", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Returns a crop of the image. ```php $img = new bbn\file\image("/home/data/test/image.jpg"); bbn\x::dump($img->get_width(),$img->get_height()); // (int) 345 146 $img->crop(10, 10, 30, 30)->save("/home/data/test/img2.jpeg"); $img2 = new \bbn\file\image("/home/data/test/img2.jpeg"); bbn\x::hdump($img2->get_width(),$img2->get_height()); // (int) 10 10 ``` @param integer $w the new width @param integer $h the new height @param integer $x X coordinate @param integer $y Y coordinate @return image|false
[ "Returns", "a", "crop", "of", "the", "image", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L639-L679
nabab/bbn
src/bbn/file/image.php
image.rotate
public function rotate($angle) { $ok = false; if ( $this->test() ){ if ( class_exists('\\Imagick') ){ if ( $this->img->rotateImage(new \ImagickPixel(),$angle) ){ $ok = 1; } } else if ( function_exists('imagerotate') ){ if ( $this->img = imagerotate($this->img, $angle, 0) ){ if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){ imageColorAllocateAlpha($this->img, 0, 0, 0, 127); imagealphablending($this->img, false); imagesavealpha($this->img, true); } $ok = 1; } } if ( $ok ){ if ( $angle == 90 || $angle == 270 ){ $h = $this->h; $this->h = $this->w; $this->w = $h; } } else{ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } return $this; }
php
public function rotate($angle) { $ok = false; if ( $this->test() ){ if ( class_exists('\\Imagick') ){ if ( $this->img->rotateImage(new \ImagickPixel(),$angle) ){ $ok = 1; } } else if ( function_exists('imagerotate') ){ if ( $this->img = imagerotate($this->img, $angle, 0) ){ if ( $this->ext == 'png' || $this->ext == 'gif' || $this->ext == 'svg' ){ imageColorAllocateAlpha($this->img, 0, 0, 0, 127); imagealphablending($this->img, false); imagesavealpha($this->img, true); } $ok = 1; } } if ( $ok ){ if ( $angle == 90 || $angle == 270 ){ $h = $this->h; $this->h = $this->w; $this->w = $h; } } else{ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } return $this; }
[ "public", "function", "rotate", "(", "$", "angle", ")", "{", "$", "ok", "=", "false", ";", "if", "(", "$", "this", "->", "test", "(", ")", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "if", "(", "$", "this", "->", "img", "->", "rotateImage", "(", "new", "\\", "ImagickPixel", "(", ")", ",", "$", "angle", ")", ")", "{", "$", "ok", "=", "1", ";", "}", "}", "else", "if", "(", "function_exists", "(", "'imagerotate'", ")", ")", "{", "if", "(", "$", "this", "->", "img", "=", "imagerotate", "(", "$", "this", "->", "img", ",", "$", "angle", ",", "0", ")", ")", "{", "if", "(", "$", "this", "->", "ext", "==", "'png'", "||", "$", "this", "->", "ext", "==", "'gif'", "||", "$", "this", "->", "ext", "==", "'svg'", ")", "{", "imageColorAllocateAlpha", "(", "$", "this", "->", "img", ",", "0", ",", "0", ",", "0", ",", "127", ")", ";", "imagealphablending", "(", "$", "this", "->", "img", ",", "false", ")", ";", "imagesavealpha", "(", "$", "this", "->", "img", ",", "true", ")", ";", "}", "$", "ok", "=", "1", ";", "}", "}", "if", "(", "$", "ok", ")", "{", "if", "(", "$", "angle", "==", "90", "||", "$", "angle", "==", "270", ")", "{", "$", "h", "=", "$", "this", "->", "h", ";", "$", "this", "->", "h", "=", "$", "this", "->", "w", ";", "$", "this", "->", "w", "=", "$", "h", ";", "}", "}", "else", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "return", "$", "this", ";", "}" ]
Rotates the image. _ ```php $img = new bbn\file\image("/home/data/test/image.jpg"); $img->rotate( 90 )->save(); ``` @param integer $angle The angle of rotation. @return image
[ "Rotates", "the", "image", ".", "_", "php", "$img", "=", "new", "bbn", "\\", "file", "\\", "image", "(", "/", "home", "/", "data", "/", "test", "/", "image", ".", "jpg", ")", ";", "$img", "-", ">", "rotate", "(", "90", ")", "-", ">", "save", "()", ";" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L692-L724
nabab/bbn
src/bbn/file/image.php
image.flip
public function flip($mode='v'){ if ( $this->test() ) { if ( class_exists('\\Imagick') ) { if ( $mode == 'v' ) { if ( !$this->img->flipImage() ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( !$this->img->flopImage() ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else { $w = imagesx($this->img); $h = imagesy($this->img); if ( $mode == 'v' ){ imageflip($this->img, IMG_FLIP_VERTICAL); } else{ imageflip($this->img, IMG_FLIP_HORIZONTAL); } } } return $this; }
php
public function flip($mode='v'){ if ( $this->test() ) { if ( class_exists('\\Imagick') ) { if ( $mode == 'v' ) { if ( !$this->img->flipImage() ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( !$this->img->flopImage() ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else { $w = imagesx($this->img); $h = imagesy($this->img); if ( $mode == 'v' ){ imageflip($this->img, IMG_FLIP_VERTICAL); } else{ imageflip($this->img, IMG_FLIP_HORIZONTAL); } } } return $this; }
[ "public", "function", "flip", "(", "$", "mode", "=", "'v'", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "if", "(", "$", "mode", "==", "'v'", ")", "{", "if", "(", "!", "$", "this", "->", "img", "->", "flipImage", "(", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "else", "if", "(", "!", "$", "this", "->", "img", "->", "flopImage", "(", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "else", "{", "$", "w", "=", "imagesx", "(", "$", "this", "->", "img", ")", ";", "$", "h", "=", "imagesy", "(", "$", "this", "->", "img", ")", ";", "if", "(", "$", "mode", "==", "'v'", ")", "{", "imageflip", "(", "$", "this", "->", "img", ",", "IMG_FLIP_VERTICAL", ")", ";", "}", "else", "{", "imageflip", "(", "$", "this", "->", "img", ",", "IMG_FLIP_HORIZONTAL", ")", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Flips the image. ```php $img = new bbn\file\image("/home/data/test/image.jpg"); $img->flip()->save(); $img->flip("h")->save(); $img->flip()->save(); ``` @param string $mode Vertical ("v") or Horizontal ("h") flip, default: "v". @return image
[ "Flips", "the", "image", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L739-L769
nabab/bbn
src/bbn/file/image.php
image.quality
public function quality(int $q = 80, int $comp = 8){ if ( $this->test() && ((strtolower($this->get_extension()) === 'jpg') || (strtolower($this->get_extension()) === 'jpeg')) ){ if ( class_exists('\\Imagick') ){ $this->img->setImageCompression($comp); $this->img->setImageCompressionQuality($q); $this->img->stripImage(); } } return $this; }
php
public function quality(int $q = 80, int $comp = 8){ if ( $this->test() && ((strtolower($this->get_extension()) === 'jpg') || (strtolower($this->get_extension()) === 'jpeg')) ){ if ( class_exists('\\Imagick') ){ $this->img->setImageCompression($comp); $this->img->setImageCompressionQuality($q); $this->img->stripImage(); } } return $this; }
[ "public", "function", "quality", "(", "int", "$", "q", "=", "80", ",", "int", "$", "comp", "=", "8", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", "&&", "(", "(", "strtolower", "(", "$", "this", "->", "get_extension", "(", ")", ")", "===", "'jpg'", ")", "||", "(", "strtolower", "(", "$", "this", "->", "get_extension", "(", ")", ")", "===", "'jpeg'", ")", ")", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "$", "this", "->", "img", "->", "setImageCompression", "(", "$", "comp", ")", ";", "$", "this", "->", "img", "->", "setImageCompressionQuality", "(", "$", "q", ")", ";", "$", "this", "->", "img", "->", "stripImage", "(", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Compresses and sets the image's quality (JPEG image only). ```php $img = new bbn\file\image("/home/data/test/image.jpg"); $img->quality(60, 6)->save(); ``` @param int $q The quality level (0-100) @param int $comp The compression type @return image
[ "Compresses", "and", "sets", "the", "image", "s", "quality", "(", "JPEG", "image", "only", ")", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L783-L795
nabab/bbn
src/bbn/file/image.php
image.brightness
public function brightness($val='+') { if ( $this->test() ) { if ( class_exists('\\Imagick') ) { $p = ( $val == '-' ) ? 90 : 110; if ( !$this->img->modulateImage($p,100,100) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( function_exists('imagefilter') ) { $p = ( $val == '-' ) ? -20 : 20; if ( !imagefilter($this->img,IMG_FILTER_BRIGHTNESS,-20) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
php
public function brightness($val='+') { if ( $this->test() ) { if ( class_exists('\\Imagick') ) { $p = ( $val == '-' ) ? 90 : 110; if ( !$this->img->modulateImage($p,100,100) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( function_exists('imagefilter') ) { $p = ( $val == '-' ) ? -20 : 20; if ( !imagefilter($this->img,IMG_FILTER_BRIGHTNESS,-20) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
[ "public", "function", "brightness", "(", "$", "val", "=", "'+'", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "$", "p", "=", "(", "$", "val", "==", "'-'", ")", "?", "90", ":", "110", ";", "if", "(", "!", "$", "this", "->", "img", "->", "modulateImage", "(", "$", "p", ",", "100", ",", "100", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "else", "if", "(", "function_exists", "(", "'imagefilter'", ")", ")", "{", "$", "p", "=", "(", "$", "val", "==", "'-'", ")", "?", "-", "20", ":", "20", ";", "if", "(", "!", "imagefilter", "(", "$", "this", "->", "img", ",", "IMG_FILTER_BRIGHTNESS", ",", "-", "20", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Adjusts the image's brightness. ```php $img = new bbn\file\image("/home/data/test/image.jpg"); $img->brightness(); $img->brightness("-"); ``` @param string $val The value "+" (default) increases the brightness, the value ("-") reduces it. @return image
[ "Adjusts", "the", "image", "s", "brightness", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L809-L831
nabab/bbn
src/bbn/file/image.php
image.contrast
public function contrast($val='+') { if ( $this->test() ) { if ( class_exists('\\Imagick') ) { $p = ( $val == '-' ) ? 0 : 1; if ( !$this->img->contrastImage($p) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( function_exists('imagefilter') ) { $p = ( $val == '-' ) ? -20 : 20; if ( !imagefilter($this->img,IMG_FILTER_CONTRAST,-20) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
php
public function contrast($val='+') { if ( $this->test() ) { if ( class_exists('\\Imagick') ) { $p = ( $val == '-' ) ? 0 : 1; if ( !$this->img->contrastImage($p) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( function_exists('imagefilter') ) { $p = ( $val == '-' ) ? -20 : 20; if ( !imagefilter($this->img,IMG_FILTER_CONTRAST,-20) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
[ "public", "function", "contrast", "(", "$", "val", "=", "'+'", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "$", "p", "=", "(", "$", "val", "==", "'-'", ")", "?", "0", ":", "1", ";", "if", "(", "!", "$", "this", "->", "img", "->", "contrastImage", "(", "$", "p", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "else", "if", "(", "function_exists", "(", "'imagefilter'", ")", ")", "{", "$", "p", "=", "(", "$", "val", "==", "'-'", ")", "?", "-", "20", ":", "20", ";", "if", "(", "!", "imagefilter", "(", "$", "this", "->", "img", ",", "IMG_FILTER_CONTRAST", ",", "-", "20", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Adjusts the image contrast. ```php $img = new bbn\file\image("/home/data/test/image.jpg"); $img->contrast("-"); $img->contrast(); ``` @param string $val The value "+" (default), increases the contrast, the value ("-") reduces it. @return image
[ "Adjusts", "the", "image", "contrast", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L845-L867
nabab/bbn
src/bbn/file/image.php
image.grayscale
public function grayscale() { if ( $this->test() ) { if ( class_exists('\\Imagick') ) { if ( !$this->img->modulateImage(100,0,100) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( function_exists('imagefilter') ) { if ( !imagefilter($this->img,IMG_FILTER_GRAYSCALE) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
php
public function grayscale() { if ( $this->test() ) { if ( class_exists('\\Imagick') ) { if ( !$this->img->modulateImage(100,0,100) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( function_exists('imagefilter') ) { if ( !imagefilter($this->img,IMG_FILTER_GRAYSCALE) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
[ "public", "function", "grayscale", "(", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "if", "(", "!", "$", "this", "->", "img", "->", "modulateImage", "(", "100", ",", "0", ",", "100", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "else", "if", "(", "function_exists", "(", "'imagefilter'", ")", ")", "{", "if", "(", "!", "imagefilter", "(", "$", "this", "->", "img", ",", "IMG_FILTER_GRAYSCALE", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Converts the image's color to grayscale. ```php $img = new bbn\file\image("/home/data/test/image.jpg"); $img->grayscale()->save(); ``` @return image
[ "Converts", "the", "image", "s", "color", "to", "grayscale", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L879-L899
nabab/bbn
src/bbn/file/image.php
image.negate
public function negate() { if ( $this->test() ) { if ( class_exists('\\Imagick') ) { if ( !$this->img->negateImage(false) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( function_exists('imagefilter') ) { if ( !imagefilter($this->img,IMG_FILTER_NEGATE) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
php
public function negate() { if ( $this->test() ) { if ( class_exists('\\Imagick') ) { if ( !$this->img->negateImage(false) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } else if ( function_exists('imagefilter') ) { if ( !imagefilter($this->img,IMG_FILTER_NEGATE) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
[ "public", "function", "negate", "(", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "if", "(", "!", "$", "this", "->", "img", "->", "negateImage", "(", "false", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "else", "if", "(", "function_exists", "(", "'imagefilter'", ")", ")", "{", "if", "(", "!", "imagefilter", "(", "$", "this", "->", "img", ",", "IMG_FILTER_NEGATE", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Converts the image's color to negative. ```php $img = new bbn\file\image("/home/data/test/image.jpg"); $img->negate(); ``` @return image
[ "Converts", "the", "image", "s", "color", "to", "negative", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L911-L931
nabab/bbn
src/bbn/file/image.php
image.polaroid
public function polaroid() { if ( $this->test() ){ if ( class_exists('\\Imagick') ){ if ( !$this->img->polaroidImage(new \ImagickDraw(), 0) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
php
public function polaroid() { if ( $this->test() ){ if ( class_exists('\\Imagick') ){ if ( !$this->img->polaroidImage(new \ImagickDraw(), 0) ){ $this->error = \defined('BBN_THERE_HAS_BEEN_A_PROBLEM') ? BBN_THERE_HAS_BEEN_A_PROBLEM : 'There has been a problem'; } } } return $this; }
[ "public", "function", "polaroid", "(", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "{", "if", "(", "!", "$", "this", "->", "img", "->", "polaroidImage", "(", "new", "\\", "ImagickDraw", "(", ")", ",", "0", ")", ")", "{", "$", "this", "->", "error", "=", "\\", "defined", "(", "'BBN_THERE_HAS_BEEN_A_PROBLEM'", ")", "?", "BBN_THERE_HAS_BEEN_A_PROBLEM", ":", "'There has been a problem'", ";", "}", "}", "}", "return", "$", "this", ";", "}" ]
Converts the image's color with polaroid filter. ```php $img = new bbn\file\image("/home/data/test/image.jpg"); $img->polaroid()->save(); ``` @return image @todo Transparency of png files.
[ "Converts", "the", "image", "s", "color", "with", "polaroid", "filter", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L944-L955
nabab/bbn
src/bbn/file/image.php
image.thumbs
public function thumbs($dest = '.', $sizes = [[false, 960], [false, 480], [false, 192], [false, 96], [false, 48]], $mask = '_%s', $crop = false, $bigger = false){ if ( $this->test() && is_dir($dest) ){ $this->get_extension(); $w = $this->get_width(); $h = $this->get_height(); $d = $w >= $h ? 'w' : 'h'; $res = []; if ( bbn\str::is_integer($sizes) ){ $sizes = [[$sizes, false]]; } if ( $$d / ($d === 'w' ? $h : $w) < 5 ){ $mask = ($dest === '.' ? '' : $dest.'/').$this->title.$mask.'.'.$this->ext; //die(var_dump($mask)); foreach ( $sizes as $s ){ if ( bbn\str::is_integer($s) ){ $s = [$s, false]; } if ( (!empty($s[0]) && ($w > $s[0])) || (!empty($s[1]) && ($h > $s[1])) || $bigger ){ $smask = (empty($s[0]) ? '' : 'w'.$s[0]).(empty($s[1]) ? '' : 'h'.$s[1]); $fn = sprintf($mask, $smask); if ( $s[0] && $s[1] ){ if ( $crop ){ $this->resize($s[0], $s[1], true); } else{ $this->resize($d === 'w' ? $s[0] : false, $d === 'h' ? $s[1] : false, false, $s[0], $s[1]); } } else{ $this->resize($s[0], $s[1], $crop); } $this->save($fn); $res[$smask] = $fn; } } return $res; } } return false; }
php
public function thumbs($dest = '.', $sizes = [[false, 960], [false, 480], [false, 192], [false, 96], [false, 48]], $mask = '_%s', $crop = false, $bigger = false){ if ( $this->test() && is_dir($dest) ){ $this->get_extension(); $w = $this->get_width(); $h = $this->get_height(); $d = $w >= $h ? 'w' : 'h'; $res = []; if ( bbn\str::is_integer($sizes) ){ $sizes = [[$sizes, false]]; } if ( $$d / ($d === 'w' ? $h : $w) < 5 ){ $mask = ($dest === '.' ? '' : $dest.'/').$this->title.$mask.'.'.$this->ext; //die(var_dump($mask)); foreach ( $sizes as $s ){ if ( bbn\str::is_integer($s) ){ $s = [$s, false]; } if ( (!empty($s[0]) && ($w > $s[0])) || (!empty($s[1]) && ($h > $s[1])) || $bigger ){ $smask = (empty($s[0]) ? '' : 'w'.$s[0]).(empty($s[1]) ? '' : 'h'.$s[1]); $fn = sprintf($mask, $smask); if ( $s[0] && $s[1] ){ if ( $crop ){ $this->resize($s[0], $s[1], true); } else{ $this->resize($d === 'w' ? $s[0] : false, $d === 'h' ? $s[1] : false, false, $s[0], $s[1]); } } else{ $this->resize($s[0], $s[1], $crop); } $this->save($fn); $res[$smask] = $fn; } } return $res; } } return false; }
[ "public", "function", "thumbs", "(", "$", "dest", "=", "'.'", ",", "$", "sizes", "=", "[", "[", "false", ",", "960", "]", ",", "[", "false", ",", "480", "]", ",", "[", "false", ",", "192", "]", ",", "[", "false", ",", "96", "]", ",", "[", "false", ",", "48", "]", "]", ",", "$", "mask", "=", "'_%s'", ",", "$", "crop", "=", "false", ",", "$", "bigger", "=", "false", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", "&&", "is_dir", "(", "$", "dest", ")", ")", "{", "$", "this", "->", "get_extension", "(", ")", ";", "$", "w", "=", "$", "this", "->", "get_width", "(", ")", ";", "$", "h", "=", "$", "this", "->", "get_height", "(", ")", ";", "$", "d", "=", "$", "w", ">=", "$", "h", "?", "'w'", ":", "'h'", ";", "$", "res", "=", "[", "]", ";", "if", "(", "bbn", "\\", "str", "::", "is_integer", "(", "$", "sizes", ")", ")", "{", "$", "sizes", "=", "[", "[", "$", "sizes", ",", "false", "]", "]", ";", "}", "if", "(", "$", "$", "d", "/", "(", "$", "d", "===", "'w'", "?", "$", "h", ":", "$", "w", ")", "<", "5", ")", "{", "$", "mask", "=", "(", "$", "dest", "===", "'.'", "?", "''", ":", "$", "dest", ".", "'/'", ")", ".", "$", "this", "->", "title", ".", "$", "mask", ".", "'.'", ".", "$", "this", "->", "ext", ";", "//die(var_dump($mask));", "foreach", "(", "$", "sizes", "as", "$", "s", ")", "{", "if", "(", "bbn", "\\", "str", "::", "is_integer", "(", "$", "s", ")", ")", "{", "$", "s", "=", "[", "$", "s", ",", "false", "]", ";", "}", "if", "(", "(", "!", "empty", "(", "$", "s", "[", "0", "]", ")", "&&", "(", "$", "w", ">", "$", "s", "[", "0", "]", ")", ")", "||", "(", "!", "empty", "(", "$", "s", "[", "1", "]", ")", "&&", "(", "$", "h", ">", "$", "s", "[", "1", "]", ")", ")", "||", "$", "bigger", ")", "{", "$", "smask", "=", "(", "empty", "(", "$", "s", "[", "0", "]", ")", "?", "''", ":", "'w'", ".", "$", "s", "[", "0", "]", ")", ".", "(", "empty", "(", "$", "s", "[", "1", "]", ")", "?", "''", ":", "'h'", ".", "$", "s", "[", "1", "]", ")", ";", "$", "fn", "=", "sprintf", "(", "$", "mask", ",", "$", "smask", ")", ";", "if", "(", "$", "s", "[", "0", "]", "&&", "$", "s", "[", "1", "]", ")", "{", "if", "(", "$", "crop", ")", "{", "$", "this", "->", "resize", "(", "$", "s", "[", "0", "]", ",", "$", "s", "[", "1", "]", ",", "true", ")", ";", "}", "else", "{", "$", "this", "->", "resize", "(", "$", "d", "===", "'w'", "?", "$", "s", "[", "0", "]", ":", "false", ",", "$", "d", "===", "'h'", "?", "$", "s", "[", "1", "]", ":", "false", ",", "false", ",", "$", "s", "[", "0", "]", ",", "$", "s", "[", "1", "]", ")", ";", "}", "}", "else", "{", "$", "this", "->", "resize", "(", "$", "s", "[", "0", "]", ",", "$", "s", "[", "1", "]", ",", "$", "crop", ")", ";", "}", "$", "this", "->", "save", "(", "$", "fn", ")", ";", "$", "res", "[", "$", "smask", "]", "=", "$", "fn", ";", "}", "}", "return", "$", "res", ";", "}", "}", "return", "false", ";", "}" ]
Creates miniature of the image ```php $img = new bbn\file\image("/home/data/test/image.jpg"); $img->thumbs()->save(/home/data/test/image_test.jpg"); ``` @return image|false
[ "Creates", "miniature", "of", "the", "image" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L967-L1010
nabab/bbn
src/bbn/file/image.php
image.toString
public function toString() { if ( $this->test() ) { if ( class_exists('\\Imagick') ) $m = $this->img; else { ob_start(); \call_user_func('image'.$this->ext2,$this->img); $m = ob_get_contents(); ob_end_clean(); } return 'data:image/'.$this->ext.';base64,'.base64_encode($m); } }
php
public function toString() { if ( $this->test() ) { if ( class_exists('\\Imagick') ) $m = $this->img; else { ob_start(); \call_user_func('image'.$this->ext2,$this->img); $m = ob_get_contents(); ob_end_clean(); } return 'data:image/'.$this->ext.';base64,'.base64_encode($m); } }
[ "public", "function", "toString", "(", ")", "{", "if", "(", "$", "this", "->", "test", "(", ")", ")", "{", "if", "(", "class_exists", "(", "'\\\\Imagick'", ")", ")", "$", "m", "=", "$", "this", "->", "img", ";", "else", "{", "ob_start", "(", ")", ";", "\\", "call_user_func", "(", "'image'", ".", "$", "this", "->", "ext2", ",", "$", "this", "->", "img", ")", ";", "$", "m", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "}", "return", "'data:image/'", ".", "$", "this", "->", "ext", ".", "';base64,'", ".", "base64_encode", "(", "$", "m", ")", ";", "}", "}" ]
Return the image as string. ```php $img = new bbn\file\image("/home/data/test/image.jpg"); bbn\x::hdump($img->toString()); // (string) ``` @return string
[ "Return", "the", "image", "as", "string", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file/image.php#L1023-L1038
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_not_empty
protected function validate_not_empty( $var ) { if ( is_string( $var ) ) { $var = trim( $var ); if ( ! empty( $var ) || '0' === $var ) { return true; } } elseif ( ! empty( $var ) ) { return true; } return new \WP_Error( 400, $this->app->translate( 'Value is required.' ) ); }
php
protected function validate_not_empty( $var ) { if ( is_string( $var ) ) { $var = trim( $var ); if ( ! empty( $var ) || '0' === $var ) { return true; } } elseif ( ! empty( $var ) ) { return true; } return new \WP_Error( 400, $this->app->translate( 'Value is required.' ) ); }
[ "protected", "function", "validate_not_empty", "(", "$", "var", ")", "{", "if", "(", "is_string", "(", "$", "var", ")", ")", "{", "$", "var", "=", "trim", "(", "$", "var", ")", ";", "if", "(", "!", "empty", "(", "$", "var", ")", "||", "'0'", "===", "$", "var", ")", "{", "return", "true", ";", "}", "}", "elseif", "(", "!", "empty", "(", "$", "var", ")", ")", "{", "return", "true", ";", "}", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'Value is required.'", ")", ")", ";", "}" ]
@param mixed $var @return bool|\WP_Error
[ "@param", "mixed", "$var" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L31-L42
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_positive
protected function validate_positive( $var, $include_zero = false ) { if ( ! is_numeric( $var ) ) { return new \WP_Error( 400, $this->app->translate( 'Invalid format.' ) ); } if ( ( ! $include_zero && $var <= 0 ) || ( $include_zero && $var < 0 ) ) { return new \WP_Error( 400, $this->app->translate( 'Outside the range of allowed values.' ) ); } return true; }
php
protected function validate_positive( $var, $include_zero = false ) { if ( ! is_numeric( $var ) ) { return new \WP_Error( 400, $this->app->translate( 'Invalid format.' ) ); } if ( ( ! $include_zero && $var <= 0 ) || ( $include_zero && $var < 0 ) ) { return new \WP_Error( 400, $this->app->translate( 'Outside the range of allowed values.' ) ); } return true; }
[ "protected", "function", "validate_positive", "(", "$", "var", ",", "$", "include_zero", "=", "false", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "var", ")", ")", "{", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'Invalid format.'", ")", ")", ";", "}", "if", "(", "(", "!", "$", "include_zero", "&&", "$", "var", "<=", "0", ")", "||", "(", "$", "include_zero", "&&", "$", "var", "<", "0", ")", ")", "{", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'Outside the range of allowed values.'", ")", ")", ";", "}", "return", "true", ";", "}" ]
@param mixed $var @param bool $include_zero @return bool|\WP_Error
[ "@param", "mixed", "$var", "@param", "bool", "$include_zero" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L115-L124
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_int
protected function validate_int( $var, $min = null, $max = null ) { if ( ! is_int( $var ) && ! is_string( $var ) && empty( $var ) ) { return new \WP_Error( 400, $this->app->translate( 'Value is required.' ) ); } if ( ! is_int( $var ) && ( ! is_string( $var ) || ! preg_match( '#\A-?\d+\z#', $var ) ) ) { return new \WP_Error( 400, $this->app->translate( 'Invalid format.' ) ); } if ( isset( $min ) && $var < $min ) { return new \WP_Error( 400, $this->app->translate( 'Outside the range of allowed values.' ) ); } if ( isset( $max ) && $var > $max ) { return new \WP_Error( 400, $this->app->translate( 'Outside the range of allowed values.' ) ); } return true; }
php
protected function validate_int( $var, $min = null, $max = null ) { if ( ! is_int( $var ) && ! is_string( $var ) && empty( $var ) ) { return new \WP_Error( 400, $this->app->translate( 'Value is required.' ) ); } if ( ! is_int( $var ) && ( ! is_string( $var ) || ! preg_match( '#\A-?\d+\z#', $var ) ) ) { return new \WP_Error( 400, $this->app->translate( 'Invalid format.' ) ); } if ( isset( $min ) && $var < $min ) { return new \WP_Error( 400, $this->app->translate( 'Outside the range of allowed values.' ) ); } if ( isset( $max ) && $var > $max ) { return new \WP_Error( 400, $this->app->translate( 'Outside the range of allowed values.' ) ); } return true; }
[ "protected", "function", "validate_int", "(", "$", "var", ",", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "if", "(", "!", "is_int", "(", "$", "var", ")", "&&", "!", "is_string", "(", "$", "var", ")", "&&", "empty", "(", "$", "var", ")", ")", "{", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'Value is required.'", ")", ")", ";", "}", "if", "(", "!", "is_int", "(", "$", "var", ")", "&&", "(", "!", "is_string", "(", "$", "var", ")", "||", "!", "preg_match", "(", "'#\\A-?\\d+\\z#'", ",", "$", "var", ")", ")", ")", "{", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'Invalid format.'", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "min", ")", "&&", "$", "var", "<", "$", "min", ")", "{", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'Outside the range of allowed values.'", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "max", ")", "&&", "$", "var", ">", "$", "max", ")", "{", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'Outside the range of allowed values.'", ")", ")", ";", "}", "return", "true", ";", "}" ]
@param mixed $var @param int|null $min @param int|null $max @return bool|\WP_Error
[ "@param", "mixed", "$var", "@param", "int|null", "$min", "@param", "int|null", "$max" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L150-L165
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_positive_int
protected function validate_positive_int( $var, $include_zero = false, $min = null, $max = null ) { $validate = $this->validate_int( $var, $min, $max ); if ( true === $validate ) { return $this->validate_positive( $var, $include_zero ); } return $validate; }
php
protected function validate_positive_int( $var, $include_zero = false, $min = null, $max = null ) { $validate = $this->validate_int( $var, $min, $max ); if ( true === $validate ) { return $this->validate_positive( $var, $include_zero ); } return $validate; }
[ "protected", "function", "validate_positive_int", "(", "$", "var", ",", "$", "include_zero", "=", "false", ",", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "$", "validate", "=", "$", "this", "->", "validate_int", "(", "$", "var", ",", "$", "min", ",", "$", "max", ")", ";", "if", "(", "true", "===", "$", "validate", ")", "{", "return", "$", "this", "->", "validate_positive", "(", "$", "var", ",", "$", "include_zero", ")", ";", "}", "return", "$", "validate", ";", "}" ]
@param mixed $var @param bool $include_zero @param int $min @param int $max @return bool|\WP_Error
[ "@param", "mixed", "$var", "@param", "bool", "$include_zero", "@param", "int", "$min", "@param", "int", "$max" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L199-L206
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_negative_int
protected function validate_negative_int( $var, $include_zero = false, $min = null, $max = null ) { $validate = $this->validate_int( $var, $min, $max ); if ( true === $validate ) { return $this->validate_negative( $var, $include_zero ); } return $validate; }
php
protected function validate_negative_int( $var, $include_zero = false, $min = null, $max = null ) { $validate = $this->validate_int( $var, $min, $max ); if ( true === $validate ) { return $this->validate_negative( $var, $include_zero ); } return $validate; }
[ "protected", "function", "validate_negative_int", "(", "$", "var", ",", "$", "include_zero", "=", "false", ",", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "$", "validate", "=", "$", "this", "->", "validate_int", "(", "$", "var", ",", "$", "min", ",", "$", "max", ")", ";", "if", "(", "true", "===", "$", "validate", ")", "{", "return", "$", "this", "->", "validate_negative", "(", "$", "var", ",", "$", "include_zero", ")", ";", "}", "return", "$", "validate", ";", "}" ]
@param mixed $var @param bool $include_zero @param int $min @param int $max @return bool|\WP_Error
[ "@param", "mixed", "$var", "@param", "bool", "$include_zero", "@param", "int", "$min", "@param", "int", "$max" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L216-L223
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_positive_float
protected function validate_positive_float( $var, $include_zero = false, $min = null, $max = null ) { $validate = $this->validate_float( $var, $min, $max ); if ( true === $validate ) { return $this->validate_positive( $var, $include_zero ); } return $validate; }
php
protected function validate_positive_float( $var, $include_zero = false, $min = null, $max = null ) { $validate = $this->validate_float( $var, $min, $max ); if ( true === $validate ) { return $this->validate_positive( $var, $include_zero ); } return $validate; }
[ "protected", "function", "validate_positive_float", "(", "$", "var", ",", "$", "include_zero", "=", "false", ",", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "$", "validate", "=", "$", "this", "->", "validate_float", "(", "$", "var", ",", "$", "min", ",", "$", "max", ")", ";", "if", "(", "true", "===", "$", "validate", ")", "{", "return", "$", "this", "->", "validate_positive", "(", "$", "var", ",", "$", "include_zero", ")", ";", "}", "return", "$", "validate", ";", "}" ]
@param mixed $var @param bool $include_zero @param int $min @param int $max @return bool|\WP_Error
[ "@param", "mixed", "$var", "@param", "bool", "$include_zero", "@param", "int", "$min", "@param", "int", "$max" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L233-L240
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_negative_float
protected function validate_negative_float( $var, $include_zero = false, $min = null, $max = null ) { $validate = $this->validate_float( $var, $min, $max ); if ( true === $validate ) { return $this->validate_negative( $var, $include_zero ); } return $validate; }
php
protected function validate_negative_float( $var, $include_zero = false, $min = null, $max = null ) { $validate = $this->validate_float( $var, $min, $max ); if ( true === $validate ) { return $this->validate_negative( $var, $include_zero ); } return $validate; }
[ "protected", "function", "validate_negative_float", "(", "$", "var", ",", "$", "include_zero", "=", "false", ",", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "$", "validate", "=", "$", "this", "->", "validate_float", "(", "$", "var", ",", "$", "min", ",", "$", "max", ")", ";", "if", "(", "true", "===", "$", "validate", ")", "{", "return", "$", "this", "->", "validate_negative", "(", "$", "var", ",", "$", "include_zero", ")", ";", "}", "return", "$", "validate", ";", "}" ]
@param mixed $var @param bool $include_zero @param int $min @param int $max @return bool|\WP_Error
[ "@param", "mixed", "$var", "@param", "bool", "$include_zero", "@param", "int", "$min", "@param", "int", "$max" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L250-L257
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_exists
protected function validate_exists( $var, $table, $id = 'id', $field = '*' ) { $validate = $this->validate_positive_int( $var ); if ( true === $validate ) { if ( $this->app->db->select_count( $table, $field, [ $id => $var, ] ) <= 0 ) { return new \WP_Error( 400, $this->app->translate( 'Data does not exist.' ) ); } } return $validate; }
php
protected function validate_exists( $var, $table, $id = 'id', $field = '*' ) { $validate = $this->validate_positive_int( $var ); if ( true === $validate ) { if ( $this->app->db->select_count( $table, $field, [ $id => $var, ] ) <= 0 ) { return new \WP_Error( 400, $this->app->translate( 'Data does not exist.' ) ); } } return $validate; }
[ "protected", "function", "validate_exists", "(", "$", "var", ",", "$", "table", ",", "$", "id", "=", "'id'", ",", "$", "field", "=", "'*'", ")", "{", "$", "validate", "=", "$", "this", "->", "validate_positive_int", "(", "$", "var", ")", ";", "if", "(", "true", "===", "$", "validate", ")", "{", "if", "(", "$", "this", "->", "app", "->", "db", "->", "select_count", "(", "$", "table", ",", "$", "field", ",", "[", "$", "id", "=>", "$", "var", ",", "]", ")", "<=", "0", ")", "{", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'Data does not exist.'", ")", ")", ";", "}", "}", "return", "$", "validate", ";", "}" ]
@param mixed $var @param string $table @param string $id @param string $field @return bool|\WP_Error
[ "@param", "mixed", "$var", "@param", "string", "$table", "@param", "string", "$id", "@param", "string", "$field" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L267-L278
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_authority
protected function validate_authority( $capability ) { if ( ! $this->app->user_can( $capability ) ) { return new \WP_Error( 400, $this->app->translate( 'You have no authority.' ) ); } return true; }
php
protected function validate_authority( $capability ) { if ( ! $this->app->user_can( $capability ) ) { return new \WP_Error( 400, $this->app->translate( 'You have no authority.' ) ); } return true; }
[ "protected", "function", "validate_authority", "(", "$", "capability", ")", "{", "if", "(", "!", "$", "this", "->", "app", "->", "user_can", "(", "$", "capability", ")", ")", "{", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'You have no authority.'", ")", ")", ";", "}", "return", "true", ";", "}" ]
@param string $capability @return bool|\WP_Error
[ "@param", "string", "$capability" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L285-L291
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_confirmation
protected function validate_confirmation( $var, $target, $request ) { $validate = $this->validate_not_empty( $var ); if ( true === $validate ) { $compare = $request->get_param( $target ); if ( $compare !== $var ) { return new \WP_Error( 400, $this->app->translate( 'The confirmation value does not match.' ) ); } } return $validate; }
php
protected function validate_confirmation( $var, $target, $request ) { $validate = $this->validate_not_empty( $var ); if ( true === $validate ) { $compare = $request->get_param( $target ); if ( $compare !== $var ) { return new \WP_Error( 400, $this->app->translate( 'The confirmation value does not match.' ) ); } } return $validate; }
[ "protected", "function", "validate_confirmation", "(", "$", "var", ",", "$", "target", ",", "$", "request", ")", "{", "$", "validate", "=", "$", "this", "->", "validate_not_empty", "(", "$", "var", ")", ";", "if", "(", "true", "===", "$", "validate", ")", "{", "$", "compare", "=", "$", "request", "->", "get_param", "(", "$", "target", ")", ";", "if", "(", "$", "compare", "!==", "$", "var", ")", "{", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'The confirmation value does not match.'", ")", ")", ";", "}", "}", "return", "$", "validate", ";", "}" ]
@param mixed $var @param string $target @param \WP_REST_Request $request @return bool|\WP_Error
[ "@param", "mixed", "$var", "@param", "string", "$target", "@param", "\\", "WP_REST_Request", "$request" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L300-L310
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_regex
protected function validate_regex( $var, $pattern ) { if ( is_string( $var ) && preg_match( $pattern, $var ) > 0 ) { return true; } return new \WP_Error( 400, $this->app->translate( 'Invalid format.' ) ); }
php
protected function validate_regex( $var, $pattern ) { if ( is_string( $var ) && preg_match( $pattern, $var ) > 0 ) { return true; } return new \WP_Error( 400, $this->app->translate( 'Invalid format.' ) ); }
[ "protected", "function", "validate_regex", "(", "$", "var", ",", "$", "pattern", ")", "{", "if", "(", "is_string", "(", "$", "var", ")", "&&", "preg_match", "(", "$", "pattern", ",", "$", "var", ")", ">", "0", ")", "{", "return", "true", ";", "}", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'Invalid format.'", ")", ")", ";", "}" ]
@param mixed $var @param string $pattern @return bool|\WP_Error
[ "@param", "mixed", "$var", "@param", "string", "$pattern" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L318-L324
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate_string_length
protected function validate_string_length( $var, $len ) { if ( ! is_string( $var ) ) { return new \WP_Error( 400, $this->app->translate( 'Invalid format.' ) ); } if ( strlen( $var ) > $len ) { return new \WP_Error( 400, $this->app->translate( 'Input value is too long.' ) ); } return true; }
php
protected function validate_string_length( $var, $len ) { if ( ! is_string( $var ) ) { return new \WP_Error( 400, $this->app->translate( 'Invalid format.' ) ); } if ( strlen( $var ) > $len ) { return new \WP_Error( 400, $this->app->translate( 'Input value is too long.' ) ); } return true; }
[ "protected", "function", "validate_string_length", "(", "$", "var", ",", "$", "len", ")", "{", "if", "(", "!", "is_string", "(", "$", "var", ")", ")", "{", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'Invalid format.'", ")", ")", ";", "}", "if", "(", "strlen", "(", "$", "var", ")", ">", "$", "len", ")", "{", "return", "new", "\\", "WP_Error", "(", "400", ",", "$", "this", "->", "app", "->", "translate", "(", "'Input value is too long.'", ")", ")", ";", "}", "return", "true", ";", "}" ]
@param mixed $var @param int $len @return bool|\WP_Error
[ "@param", "mixed", "$var", "@param", "int", "$len" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L332-L342
technote-space/wordpress-plugin-base
src/traits/helper/validate.php
Validate.validate
protected function validate( $var, $setting ) { $validate = $this->validate_not_empty( $var ); if ( $setting['required'] ) { if ( $validate instanceof \WP_Error ) { return $validate; } } else { if ( $validate instanceof \WP_Error ) { return true; } } switch ( $setting['type'] ) { case 'int': if ( ! empty( $setting['unsigned'] ) ) { return $this->validate_positive_int( $var, true ); } return $this->validate_int( $var ); case 'float': case 'number': if ( ! empty( $setting['unsigned'] ) ) { return $this->validate_positive_float( $var, true ); } return $this->validate_float( $var ); case 'bool': return true; case 'string': if ( ! empty( $setting['length'] ) ) { return $this->validate_string_length( $var, $setting['length'] ); } break; } return true; }
php
protected function validate( $var, $setting ) { $validate = $this->validate_not_empty( $var ); if ( $setting['required'] ) { if ( $validate instanceof \WP_Error ) { return $validate; } } else { if ( $validate instanceof \WP_Error ) { return true; } } switch ( $setting['type'] ) { case 'int': if ( ! empty( $setting['unsigned'] ) ) { return $this->validate_positive_int( $var, true ); } return $this->validate_int( $var ); case 'float': case 'number': if ( ! empty( $setting['unsigned'] ) ) { return $this->validate_positive_float( $var, true ); } return $this->validate_float( $var ); case 'bool': return true; case 'string': if ( ! empty( $setting['length'] ) ) { return $this->validate_string_length( $var, $setting['length'] ); } break; } return true; }
[ "protected", "function", "validate", "(", "$", "var", ",", "$", "setting", ")", "{", "$", "validate", "=", "$", "this", "->", "validate_not_empty", "(", "$", "var", ")", ";", "if", "(", "$", "setting", "[", "'required'", "]", ")", "{", "if", "(", "$", "validate", "instanceof", "\\", "WP_Error", ")", "{", "return", "$", "validate", ";", "}", "}", "else", "{", "if", "(", "$", "validate", "instanceof", "\\", "WP_Error", ")", "{", "return", "true", ";", "}", "}", "switch", "(", "$", "setting", "[", "'type'", "]", ")", "{", "case", "'int'", ":", "if", "(", "!", "empty", "(", "$", "setting", "[", "'unsigned'", "]", ")", ")", "{", "return", "$", "this", "->", "validate_positive_int", "(", "$", "var", ",", "true", ")", ";", "}", "return", "$", "this", "->", "validate_int", "(", "$", "var", ")", ";", "case", "'float'", ":", "case", "'number'", ":", "if", "(", "!", "empty", "(", "$", "setting", "[", "'unsigned'", "]", ")", ")", "{", "return", "$", "this", "->", "validate_positive_float", "(", "$", "var", ",", "true", ")", ";", "}", "return", "$", "this", "->", "validate_float", "(", "$", "var", ")", ";", "case", "'bool'", ":", "return", "true", ";", "case", "'string'", ":", "if", "(", "!", "empty", "(", "$", "setting", "[", "'length'", "]", ")", ")", "{", "return", "$", "this", "->", "validate_string_length", "(", "$", "var", ",", "$", "setting", "[", "'length'", "]", ")", ";", "}", "break", ";", "}", "return", "true", ";", "}" ]
@param mixed $var @param array $setting @return bool|\WP_Error
[ "@param", "mixed", "$var", "@param", "array", "$setting" ]
train
https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/traits/helper/validate.php#L350-L385
oroinc/OroLayoutComponent
Extension/Theme/PathProvider/ChainPathProvider.php
ChainPathProvider.addProvider
public function addProvider(PathProviderInterface $provider, $priority = 0) { $this->providers[$priority][] = $provider; $this->sorted = null; }
php
public function addProvider(PathProviderInterface $provider, $priority = 0) { $this->providers[$priority][] = $provider; $this->sorted = null; }
[ "public", "function", "addProvider", "(", "PathProviderInterface", "$", "provider", ",", "$", "priority", "=", "0", ")", "{", "$", "this", "->", "providers", "[", "$", "priority", "]", "[", "]", "=", "$", "provider", ";", "$", "this", "->", "sorted", "=", "null", ";", "}" ]
For automatically injecting provider should be registered as DI service with tag layout.resource.path_provider @param PathProviderInterface $provider @param int $priority
[ "For", "automatically", "injecting", "provider", "should", "be", "registered", "as", "DI", "service", "with", "tag", "layout", ".", "resource", ".", "path_provider" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/PathProvider/ChainPathProvider.php#L23-L27
oroinc/OroLayoutComponent
Extension/Theme/PathProvider/ChainPathProvider.php
ChainPathProvider.setContext
public function setContext(ContextInterface $context) { $providers = $this->getProviders(); foreach ($providers as $provider) { if ($provider instanceof ContextAwareInterface) { $provider->setContext($context); } } }
php
public function setContext(ContextInterface $context) { $providers = $this->getProviders(); foreach ($providers as $provider) { if ($provider instanceof ContextAwareInterface) { $provider->setContext($context); } } }
[ "public", "function", "setContext", "(", "ContextInterface", "$", "context", ")", "{", "$", "providers", "=", "$", "this", "->", "getProviders", "(", ")", ";", "foreach", "(", "$", "providers", "as", "$", "provider", ")", "{", "if", "(", "$", "provider", "instanceof", "ContextAwareInterface", ")", "{", "$", "provider", "->", "setContext", "(", "$", "context", ")", ";", "}", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/PathProvider/ChainPathProvider.php#L32-L40
oroinc/OroLayoutComponent
Extension/Theme/PathProvider/ChainPathProvider.php
ChainPathProvider.getPaths
public function getPaths(array $existingPaths) { $providers = $this->getProviders(); foreach ($providers as $provider) { $existingPaths = $provider->getPaths($existingPaths); } return array_unique($existingPaths, SORT_STRING); }
php
public function getPaths(array $existingPaths) { $providers = $this->getProviders(); foreach ($providers as $provider) { $existingPaths = $provider->getPaths($existingPaths); } return array_unique($existingPaths, SORT_STRING); }
[ "public", "function", "getPaths", "(", "array", "$", "existingPaths", ")", "{", "$", "providers", "=", "$", "this", "->", "getProviders", "(", ")", ";", "foreach", "(", "$", "providers", "as", "$", "provider", ")", "{", "$", "existingPaths", "=", "$", "provider", "->", "getPaths", "(", "$", "existingPaths", ")", ";", "}", "return", "array_unique", "(", "$", "existingPaths", ",", "SORT_STRING", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/PathProvider/ChainPathProvider.php#L45-L53
artscorestudio/document-bundle
Repository/PageRepository.php
PageRepository.getLastVersion
public function getLastVersion($page_id) { $qb = $this->createQueryBuilder('p'); $qb->where('p.original=:page_id') ->orderBy('p.createdAt', 'DESC') ->setParameter(':page_id', $page_id); $result = $qb->getQuery()->setMaxResults(1)->getResult(); if ( is_null($result) ) { $qb2 = $this->createQueryBuilder('p'); $qb2->where('p.id=:page_id')->setParameter(':page_id', $page_id); $result = $qb->getQuery()->getResult(); } return $result[0]; }
php
public function getLastVersion($page_id) { $qb = $this->createQueryBuilder('p'); $qb->where('p.original=:page_id') ->orderBy('p.createdAt', 'DESC') ->setParameter(':page_id', $page_id); $result = $qb->getQuery()->setMaxResults(1)->getResult(); if ( is_null($result) ) { $qb2 = $this->createQueryBuilder('p'); $qb2->where('p.id=:page_id')->setParameter(':page_id', $page_id); $result = $qb->getQuery()->getResult(); } return $result[0]; }
[ "public", "function", "getLastVersion", "(", "$", "page_id", ")", "{", "$", "qb", "=", "$", "this", "->", "createQueryBuilder", "(", "'p'", ")", ";", "$", "qb", "->", "where", "(", "'p.original=:page_id'", ")", "->", "orderBy", "(", "'p.createdAt'", ",", "'DESC'", ")", "->", "setParameter", "(", "':page_id'", ",", "$", "page_id", ")", ";", "$", "result", "=", "$", "qb", "->", "getQuery", "(", ")", "->", "setMaxResults", "(", "1", ")", "->", "getResult", "(", ")", ";", "if", "(", "is_null", "(", "$", "result", ")", ")", "{", "$", "qb2", "=", "$", "this", "->", "createQueryBuilder", "(", "'p'", ")", ";", "$", "qb2", "->", "where", "(", "'p.id=:page_id'", ")", "->", "setParameter", "(", "':page_id'", ",", "$", "page_id", ")", ";", "$", "result", "=", "$", "qb", "->", "getQuery", "(", ")", "->", "getResult", "(", ")", ";", "}", "return", "$", "result", "[", "0", "]", ";", "}" ]
Get last version for a page @param integer $id ASFDocumentBundle:Page ID
[ "Get", "last", "version", "for", "a", "page" ]
train
https://github.com/artscorestudio/document-bundle/blob/3aceab0f75de8f7dd0fad0d0db83d7940bf565c8/Repository/PageRepository.php#L30-L48
artscorestudio/document-bundle
Repository/PageRepository.php
PageRepository.findBySlug
public function findBySlug($path) { $qb = $this->createQueryBuilder('p'); $qb instanceof QueryBuilder; $qb->add('where', $qb->expr()->like('p.slug', $qb->expr()->lower(':searched_term'))) ->setParameter('searched_term', $path); return $qb->getQuery()->getResult(); }
php
public function findBySlug($path) { $qb = $this->createQueryBuilder('p'); $qb instanceof QueryBuilder; $qb->add('where', $qb->expr()->like('p.slug', $qb->expr()->lower(':searched_term'))) ->setParameter('searched_term', $path); return $qb->getQuery()->getResult(); }
[ "public", "function", "findBySlug", "(", "$", "path", ")", "{", "$", "qb", "=", "$", "this", "->", "createQueryBuilder", "(", "'p'", ")", ";", "$", "qb", "instanceof", "QueryBuilder", ";", "$", "qb", "->", "add", "(", "'where'", ",", "$", "qb", "->", "expr", "(", ")", "->", "like", "(", "'p.slug'", ",", "$", "qb", "->", "expr", "(", ")", "->", "lower", "(", "':searched_term'", ")", ")", ")", "->", "setParameter", "(", "'searched_term'", ",", "$", "path", ")", ";", "return", "$", "qb", "->", "getQuery", "(", ")", "->", "getResult", "(", ")", ";", "}" ]
Find page by slug @param string $path
[ "Find", "page", "by", "slug" ]
train
https://github.com/artscorestudio/document-bundle/blob/3aceab0f75de8f7dd0fad0d0db83d7940bf565c8/Repository/PageRepository.php#L72-L81