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
fond-of/spryker-brand
src/FondOfSpryker/Zed/Brand/Business/Brand/Brand.php
Brand.update
public function update(BrandTransfer $brandTransfer): BrandResponseTransfer { $brandEntity = $this->getBrand($brandTransfer); $brandEntity->fromArray($brandTransfer->modifiedToArray()); $brandEntity->save(); $brandResponseTransfer = new BrandResponseTransfer(); $brandResponseTransfer->setIsSuccess(true); $brandResponseTransfer->setBrandTransfer($brandTransfer); return $brandResponseTransfer; }
php
public function update(BrandTransfer $brandTransfer): BrandResponseTransfer { $brandEntity = $this->getBrand($brandTransfer); $brandEntity->fromArray($brandTransfer->modifiedToArray()); $brandEntity->save(); $brandResponseTransfer = new BrandResponseTransfer(); $brandResponseTransfer->setIsSuccess(true); $brandResponseTransfer->setBrandTransfer($brandTransfer); return $brandResponseTransfer; }
[ "public", "function", "update", "(", "BrandTransfer", "$", "brandTransfer", ")", ":", "BrandResponseTransfer", "{", "$", "brandEntity", "=", "$", "this", "->", "getBrand", "(", "$", "brandTransfer", ")", ";", "$", "brandEntity", "->", "fromArray", "(", "$", "brandTransfer", "->", "modifiedToArray", "(", ")", ")", ";", "$", "brandEntity", "->", "save", "(", ")", ";", "$", "brandResponseTransfer", "=", "new", "BrandResponseTransfer", "(", ")", ";", "$", "brandResponseTransfer", "->", "setIsSuccess", "(", "true", ")", ";", "$", "brandResponseTransfer", "->", "setBrandTransfer", "(", "$", "brandTransfer", ")", ";", "return", "$", "brandResponseTransfer", ";", "}" ]
@param \Generated\Shared\Transfer\BrandTransfer $brandTransfer @return \Generated\Shared\Transfer\BrandResponseTransfer
[ "@param", "\\", "Generated", "\\", "Shared", "\\", "Transfer", "\\", "BrandTransfer", "$brandTransfer" ]
train
https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Zed/Brand/Business/Brand/Brand.php#L123-L133
fond-of/spryker-brand
src/FondOfSpryker/Zed/Brand/Business/Brand/Brand.php
Brand.findById
public function findById(BrandTransfer $brandTransfer): ?BrandTransfer { try { $brandTransfer->requireIdBrand(); return $this->get($brandTransfer); } catch (BrandNotFoundException $e) { return null; } }
php
public function findById(BrandTransfer $brandTransfer): ?BrandTransfer { try { $brandTransfer->requireIdBrand(); return $this->get($brandTransfer); } catch (BrandNotFoundException $e) { return null; } }
[ "public", "function", "findById", "(", "BrandTransfer", "$", "brandTransfer", ")", ":", "?", "BrandTransfer", "{", "try", "{", "$", "brandTransfer", "->", "requireIdBrand", "(", ")", ";", "return", "$", "this", "->", "get", "(", "$", "brandTransfer", ")", ";", "}", "catch", "(", "BrandNotFoundException", "$", "e", ")", "{", "return", "null", ";", "}", "}" ]
@param \Generated\Shared\Transfer\BrandTransfer $brandTransfer $brandTransfer @return \Generated\Shared\Transfer\BrandTransfer|null $brandTransfer|null
[ "@param", "\\", "Generated", "\\", "Shared", "\\", "Transfer", "\\", "BrandTransfer", "$brandTransfer", "$brandTransfer" ]
train
https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Zed/Brand/Business/Brand/Brand.php#L140-L148
fond-of/spryker-brand
src/FondOfSpryker/Zed/Brand/Business/Brand/Brand.php
Brand.findByName
public function findByName(BrandTransfer $brandTransfer): ?BrandTransfer { try { $brandTransfer->requireName(); return $this->get($brandTransfer); } catch (BrandNotFoundException $e) { return null; } }
php
public function findByName(BrandTransfer $brandTransfer): ?BrandTransfer { try { $brandTransfer->requireName(); return $this->get($brandTransfer); } catch (BrandNotFoundException $e) { return null; } }
[ "public", "function", "findByName", "(", "BrandTransfer", "$", "brandTransfer", ")", ":", "?", "BrandTransfer", "{", "try", "{", "$", "brandTransfer", "->", "requireName", "(", ")", ";", "return", "$", "this", "->", "get", "(", "$", "brandTransfer", ")", ";", "}", "catch", "(", "BrandNotFoundException", "$", "e", ")", "{", "return", "null", ";", "}", "}" ]
@param \Generated\Shared\Transfer\BrandTransfer $brandTransfer $brandTransfer @return \Generated\Shared\Transfer\BrandTransfer|null
[ "@param", "\\", "Generated", "\\", "Shared", "\\", "Transfer", "\\", "BrandTransfer", "$brandTransfer", "$brandTransfer" ]
train
https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Zed/Brand/Business/Brand/Brand.php#L155-L163
fond-of/spryker-brand
src/FondOfSpryker/Zed/Brand/Business/Brand/Brand.php
Brand.hasBrand
public function hasBrand(BrandTransfer $brandTransfer): bool { try { $this->getBrand($brandTransfer); return true; } catch (BrandNotFoundException $e) { return false; } }
php
public function hasBrand(BrandTransfer $brandTransfer): bool { try { $this->getBrand($brandTransfer); return true; } catch (BrandNotFoundException $e) { return false; } }
[ "public", "function", "hasBrand", "(", "BrandTransfer", "$", "brandTransfer", ")", ":", "bool", "{", "try", "{", "$", "this", "->", "getBrand", "(", "$", "brandTransfer", ")", ";", "return", "true", ";", "}", "catch", "(", "BrandNotFoundException", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
@param \Generated\Shared\Transfer\BrandTransfer $brandTransfer @return bool
[ "@param", "\\", "Generated", "\\", "Shared", "\\", "Transfer", "\\", "BrandTransfer", "$brandTransfer" ]
train
https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Zed/Brand/Business/Brand/Brand.php#L170-L178
fond-of/spryker-brand
src/FondOfSpryker/Zed/Brand/Business/Brand/Brand.php
Brand.getBrand
protected function getBrand(BrandTransfer $brandTransfer): FosBrand { $brandEntity = null; if ($brandTransfer->getIdBrand()) { $brandEntity = $this->queryContainer->queryBrandById($brandTransfer->getIdBrand()) ->findOne(); } elseif ($brandTransfer->getName()) { $brandEntity = $this->queryContainer->queryBrandByName($brandTransfer->getName()) ->findOne(); } if ($brandEntity !== null) { return $brandEntity; } throw new BrandNotFoundException(sprintf('Brand not found by either ID `%s` or name `%s`.', $brandTransfer->getIdBrand(), $brandTransfer->getName())); }
php
protected function getBrand(BrandTransfer $brandTransfer): FosBrand { $brandEntity = null; if ($brandTransfer->getIdBrand()) { $brandEntity = $this->queryContainer->queryBrandById($brandTransfer->getIdBrand()) ->findOne(); } elseif ($brandTransfer->getName()) { $brandEntity = $this->queryContainer->queryBrandByName($brandTransfer->getName()) ->findOne(); } if ($brandEntity !== null) { return $brandEntity; } throw new BrandNotFoundException(sprintf('Brand not found by either ID `%s` or name `%s`.', $brandTransfer->getIdBrand(), $brandTransfer->getName())); }
[ "protected", "function", "getBrand", "(", "BrandTransfer", "$", "brandTransfer", ")", ":", "FosBrand", "{", "$", "brandEntity", "=", "null", ";", "if", "(", "$", "brandTransfer", "->", "getIdBrand", "(", ")", ")", "{", "$", "brandEntity", "=", "$", "this", "->", "queryContainer", "->", "queryBrandById", "(", "$", "brandTransfer", "->", "getIdBrand", "(", ")", ")", "->", "findOne", "(", ")", ";", "}", "elseif", "(", "$", "brandTransfer", "->", "getName", "(", ")", ")", "{", "$", "brandEntity", "=", "$", "this", "->", "queryContainer", "->", "queryBrandByName", "(", "$", "brandTransfer", "->", "getName", "(", ")", ")", "->", "findOne", "(", ")", ";", "}", "if", "(", "$", "brandEntity", "!==", "null", ")", "{", "return", "$", "brandEntity", ";", "}", "throw", "new", "BrandNotFoundException", "(", "sprintf", "(", "'Brand not found by either ID `%s` or name `%s`.'", ",", "$", "brandTransfer", "->", "getIdBrand", "(", ")", ",", "$", "brandTransfer", "->", "getName", "(", ")", ")", ")", ";", "}" ]
@param \Generated\Shared\Transfer\BrandTransfer $brandTransfer @throws \FondOfSpryker\Zed\Brand\Business\Exception\BrandNotFoundException @return \Orm\Zed\Brand\Persistence\FosBrand
[ "@param", "\\", "Generated", "\\", "Shared", "\\", "Transfer", "\\", "BrandTransfer", "$brandTransfer" ]
train
https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Zed/Brand/Business/Brand/Brand.php#L187-L204
redaigbaria/oauth2
src/Entity/AccessTokenEntity.php
AccessTokenEntity.getSession
public function getSession() { if ($this->session instanceof SessionEntity) { return $this->session; } $this->session = $this->server->getSessionStorage()->getByAccessToken($this); return $this->session; }
php
public function getSession() { if ($this->session instanceof SessionEntity) { return $this->session; } $this->session = $this->server->getSessionStorage()->getByAccessToken($this); return $this->session; }
[ "public", "function", "getSession", "(", ")", "{", "if", "(", "$", "this", "->", "session", "instanceof", "SessionEntity", ")", "{", "return", "$", "this", "->", "session", ";", "}", "$", "this", "->", "session", "=", "$", "this", "->", "server", "->", "getSessionStorage", "(", ")", "->", "getByAccessToken", "(", "$", "this", ")", ";", "return", "$", "this", "->", "session", ";", "}" ]
Get session @return \League\OAuth2\Server\Entity\SessionEntity
[ "Get", "session" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Entity/AccessTokenEntity.php#L24-L33
redaigbaria/oauth2
src/Entity/AccessTokenEntity.php
AccessTokenEntity.getScopes
public function getScopes() { if ($this->scopes === null) { $this->scopes = $this->formatScopes( $this->server->getAccessTokenStorage()->getScopes($this) ); } return $this->scopes; }
php
public function getScopes() { if ($this->scopes === null) { $this->scopes = $this->formatScopes( $this->server->getAccessTokenStorage()->getScopes($this) ); } return $this->scopes; }
[ "public", "function", "getScopes", "(", ")", "{", "if", "(", "$", "this", "->", "scopes", "===", "null", ")", "{", "$", "this", "->", "scopes", "=", "$", "this", "->", "formatScopes", "(", "$", "this", "->", "server", "->", "getAccessTokenStorage", "(", ")", "->", "getScopes", "(", "$", "this", ")", ")", ";", "}", "return", "$", "this", "->", "scopes", ";", "}" ]
Return all scopes associated with the access token @return \League\OAuth2\Server\Entity\ScopeEntity[]
[ "Return", "all", "scopes", "associated", "with", "the", "access", "token" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Entity/AccessTokenEntity.php#L56-L65
redaigbaria/oauth2
src/Entity/AccessTokenEntity.php
AccessTokenEntity.save
public function save() { $this->server->getAccessTokenStorage()->create( $this->getId(), $this->getExpireTime(), $this->getSession()->getId() ); // Associate the scope with the token foreach ($this->getScopes() as $scope) { $this->server->getAccessTokenStorage()->associateScope($this, $scope); } return $this; }
php
public function save() { $this->server->getAccessTokenStorage()->create( $this->getId(), $this->getExpireTime(), $this->getSession()->getId() ); // Associate the scope with the token foreach ($this->getScopes() as $scope) { $this->server->getAccessTokenStorage()->associateScope($this, $scope); } return $this; }
[ "public", "function", "save", "(", ")", "{", "$", "this", "->", "server", "->", "getAccessTokenStorage", "(", ")", "->", "create", "(", "$", "this", "->", "getId", "(", ")", ",", "$", "this", "->", "getExpireTime", "(", ")", ",", "$", "this", "->", "getSession", "(", ")", "->", "getId", "(", ")", ")", ";", "// Associate the scope with the token", "foreach", "(", "$", "this", "->", "getScopes", "(", ")", "as", "$", "scope", ")", "{", "$", "this", "->", "server", "->", "getAccessTokenStorage", "(", ")", "->", "associateScope", "(", "$", "this", ",", "$", "scope", ")", ";", "}", "return", "$", "this", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Entity/AccessTokenEntity.php#L70-L84
rayrutjes/domain-foundation
src/UnitOfWork/Listener/UnitOfWorkListenerCollection.php
UnitOfWorkListenerCollection.onEventRegistration
public function onEventRegistration(UnitOfWork $unitOfWork, Event $event) { foreach ($this->listeners as $listener) { $event = $listener->onEventRegistration($unitOfWork, $event); } return $event; }
php
public function onEventRegistration(UnitOfWork $unitOfWork, Event $event) { foreach ($this->listeners as $listener) { $event = $listener->onEventRegistration($unitOfWork, $event); } return $event; }
[ "public", "function", "onEventRegistration", "(", "UnitOfWork", "$", "unitOfWork", ",", "Event", "$", "event", ")", "{", "foreach", "(", "$", "this", "->", "listeners", "as", "$", "listener", ")", "{", "$", "event", "=", "$", "listener", "->", "onEventRegistration", "(", "$", "unitOfWork", ",", "$", "event", ")", ";", "}", "return", "$", "event", ";", "}" ]
@param UnitOfWork $unitOfWork @param Event $event @return Event
[ "@param", "UnitOfWork", "$unitOfWork", "@param", "Event", "$event" ]
train
https://github.com/rayrutjes/domain-foundation/blob/2bce7cd6a6612f718e70e3176589c1abf39d1a3e/src/UnitOfWork/Listener/UnitOfWorkListenerCollection.php#L52-L59
CakeCMS/Core
src/View/Helper/NavHelper.php
NavHelper.render
public function render($key, array $items = [], array $options = [], $level = 1) { $i = 0; $output = []; $options = Hash::merge($this->_default, $options); $sorted = Hash::sort($items, '{s}.weight', 'ASC'); $itemCount = count($sorted); foreach ($sorted as $item) { $i++; $item = $this->_setFirstLast($i, $itemCount, $item); $children = false; if (count($item['children']) > 0) { $children = $this->render($key, $item['children'], $options, $level + 1); } $itemParams = [ 'options' => $options, 'item' => $item, 'count' => $i, 'children' => $children, 'level' => $level, ]; $this->_setItemParams($itemParams); if (isset($item['callable']) && is_callable($item['callable'])) { $output[] = call_user_func_array($item['callable'], array_merge(['view' => $this->_View], $itemParams)); } else { $output[] = $this->_View->element($options['itemElement'], $itemParams); } } $element = $this->_getCurrentMenuElement($options, $level); return $this->_View->element($element, [ 'content' => $output, 'options' => $options, ]); }
php
public function render($key, array $items = [], array $options = [], $level = 1) { $i = 0; $output = []; $options = Hash::merge($this->_default, $options); $sorted = Hash::sort($items, '{s}.weight', 'ASC'); $itemCount = count($sorted); foreach ($sorted as $item) { $i++; $item = $this->_setFirstLast($i, $itemCount, $item); $children = false; if (count($item['children']) > 0) { $children = $this->render($key, $item['children'], $options, $level + 1); } $itemParams = [ 'options' => $options, 'item' => $item, 'count' => $i, 'children' => $children, 'level' => $level, ]; $this->_setItemParams($itemParams); if (isset($item['callable']) && is_callable($item['callable'])) { $output[] = call_user_func_array($item['callable'], array_merge(['view' => $this->_View], $itemParams)); } else { $output[] = $this->_View->element($options['itemElement'], $itemParams); } } $element = $this->_getCurrentMenuElement($options, $level); return $this->_View->element($element, [ 'content' => $output, 'options' => $options, ]); }
[ "public", "function", "render", "(", "$", "key", ",", "array", "$", "items", "=", "[", "]", ",", "array", "$", "options", "=", "[", "]", ",", "$", "level", "=", "1", ")", "{", "$", "i", "=", "0", ";", "$", "output", "=", "[", "]", ";", "$", "options", "=", "Hash", "::", "merge", "(", "$", "this", "->", "_default", ",", "$", "options", ")", ";", "$", "sorted", "=", "Hash", "::", "sort", "(", "$", "items", ",", "'{s}.weight'", ",", "'ASC'", ")", ";", "$", "itemCount", "=", "count", "(", "$", "sorted", ")", ";", "foreach", "(", "$", "sorted", "as", "$", "item", ")", "{", "$", "i", "++", ";", "$", "item", "=", "$", "this", "->", "_setFirstLast", "(", "$", "i", ",", "$", "itemCount", ",", "$", "item", ")", ";", "$", "children", "=", "false", ";", "if", "(", "count", "(", "$", "item", "[", "'children'", "]", ")", ">", "0", ")", "{", "$", "children", "=", "$", "this", "->", "render", "(", "$", "key", ",", "$", "item", "[", "'children'", "]", ",", "$", "options", ",", "$", "level", "+", "1", ")", ";", "}", "$", "itemParams", "=", "[", "'options'", "=>", "$", "options", ",", "'item'", "=>", "$", "item", ",", "'count'", "=>", "$", "i", ",", "'children'", "=>", "$", "children", ",", "'level'", "=>", "$", "level", ",", "]", ";", "$", "this", "->", "_setItemParams", "(", "$", "itemParams", ")", ";", "if", "(", "isset", "(", "$", "item", "[", "'callable'", "]", ")", "&&", "is_callable", "(", "$", "item", "[", "'callable'", "]", ")", ")", "{", "$", "output", "[", "]", "=", "call_user_func_array", "(", "$", "item", "[", "'callable'", "]", ",", "array_merge", "(", "[", "'view'", "=>", "$", "this", "->", "_View", "]", ",", "$", "itemParams", ")", ")", ";", "}", "else", "{", "$", "output", "[", "]", "=", "$", "this", "->", "_View", "->", "element", "(", "$", "options", "[", "'itemElement'", "]", ",", "$", "itemParams", ")", ";", "}", "}", "$", "element", "=", "$", "this", "->", "_getCurrentMenuElement", "(", "$", "options", ",", "$", "level", ")", ";", "return", "$", "this", "->", "_View", "->", "element", "(", "$", "element", ",", "[", "'content'", "=>", "$", "output", ",", "'options'", "=>", "$", "options", ",", "]", ")", ";", "}" ]
Render menu. @param string $key @param array $items @param array $options @param int $level @return string @SuppressWarnings(PHPMD.ShortVariable)
[ "Render", "menu", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/NavHelper.php#L73-L113
CakeCMS/Core
src/View/Helper/NavHelper.php
NavHelper._getCurrentMenuElement
protected function _getCurrentMenuElement(array $options = [], $level = 1) { if ($level > 1) { $levelElement = $this->_getLevelElement($options, $level); if ($this->_View->elementExists($levelElement)) { return $levelElement; } return $options['childMenuAttr']['element']; } return $options['menuAttr']['element']; }
php
protected function _getCurrentMenuElement(array $options = [], $level = 1) { if ($level > 1) { $levelElement = $this->_getLevelElement($options, $level); if ($this->_View->elementExists($levelElement)) { return $levelElement; } return $options['childMenuAttr']['element']; } return $options['menuAttr']['element']; }
[ "protected", "function", "_getCurrentMenuElement", "(", "array", "$", "options", "=", "[", "]", ",", "$", "level", "=", "1", ")", "{", "if", "(", "$", "level", ">", "1", ")", "{", "$", "levelElement", "=", "$", "this", "->", "_getLevelElement", "(", "$", "options", ",", "$", "level", ")", ";", "if", "(", "$", "this", "->", "_View", "->", "elementExists", "(", "$", "levelElement", ")", ")", "{", "return", "$", "levelElement", ";", "}", "return", "$", "options", "[", "'childMenuAttr'", "]", "[", "'element'", "]", ";", "}", "return", "$", "options", "[", "'menuAttr'", "]", "[", "'element'", "]", ";", "}" ]
Get current menu element. @param array $options @param int $level @return string
[ "Get", "current", "menu", "element", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/NavHelper.php#L122-L134
CakeCMS/Core
src/View/Helper/NavHelper.php
NavHelper._getLevelElement
protected function _getLevelElement(array $options, $level) { $levelElement = 'menu_child_' . $level; $element = $options['childMenuAttr']['element']; list($plugin, $path) = $this->_View->pluginSplit($element); $path = FS::clean($path, '/'); $details = explode('/', $path); array_pop($details); $path = implode('/', $details); return $plugin . '.' . $path . '/' . $levelElement; }
php
protected function _getLevelElement(array $options, $level) { $levelElement = 'menu_child_' . $level; $element = $options['childMenuAttr']['element']; list($plugin, $path) = $this->_View->pluginSplit($element); $path = FS::clean($path, '/'); $details = explode('/', $path); array_pop($details); $path = implode('/', $details); return $plugin . '.' . $path . '/' . $levelElement; }
[ "protected", "function", "_getLevelElement", "(", "array", "$", "options", ",", "$", "level", ")", "{", "$", "levelElement", "=", "'menu_child_'", ".", "$", "level", ";", "$", "element", "=", "$", "options", "[", "'childMenuAttr'", "]", "[", "'element'", "]", ";", "list", "(", "$", "plugin", ",", "$", "path", ")", "=", "$", "this", "->", "_View", "->", "pluginSplit", "(", "$", "element", ")", ";", "$", "path", "=", "FS", "::", "clean", "(", "$", "path", ",", "'/'", ")", ";", "$", "details", "=", "explode", "(", "'/'", ",", "$", "path", ")", ";", "array_pop", "(", "$", "details", ")", ";", "$", "path", "=", "implode", "(", "'/'", ",", "$", "details", ")", ";", "return", "$", "plugin", ".", "'.'", ".", "$", "path", ".", "'/'", ".", "$", "levelElement", ";", "}" ]
Get current menu level element. @param array $options @param int $level @return string
[ "Get", "current", "menu", "level", "element", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/NavHelper.php#L143-L156
CakeCMS/Core
src/View/Helper/NavHelper.php
NavHelper._setFirstLast
protected function _setFirstLast($i, $itemCount, array $item = []) { $item = array_merge(['last' => false, 'first' => false], $item); if ($i == 1) { $item['first'] = true; } if ($i == $itemCount) { $item['last'] = true; } return $item; }
php
protected function _setFirstLast($i, $itemCount, array $item = []) { $item = array_merge(['last' => false, 'first' => false], $item); if ($i == 1) { $item['first'] = true; } if ($i == $itemCount) { $item['last'] = true; } return $item; }
[ "protected", "function", "_setFirstLast", "(", "$", "i", ",", "$", "itemCount", ",", "array", "$", "item", "=", "[", "]", ")", "{", "$", "item", "=", "array_merge", "(", "[", "'last'", "=>", "false", ",", "'first'", "=>", "false", "]", ",", "$", "item", ")", ";", "if", "(", "$", "i", "==", "1", ")", "{", "$", "item", "[", "'first'", "]", "=", "true", ";", "}", "if", "(", "$", "i", "==", "$", "itemCount", ")", "{", "$", "item", "[", "'last'", "]", "=", "true", ";", "}", "return", "$", "item", ";", "}" ]
Setup first last item params. @param int $i @param int $itemCount @param array $item @return array @SuppressWarnings(PHPMD.ShortVariable)
[ "Setup", "first", "last", "item", "params", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/NavHelper.php#L167-L179
CakeCMS/Core
src/View/Helper/NavHelper.php
NavHelper.getLiAttr
public function getLiAttr() { $params = self::$_itemParams; $attr = ['class' => 'li-item']; if (isset($params['item']['liClass'])) { $attr = $this->addClass($attr, $params['item']['liClass']); } if ($params['item']['last']) { $attr = $this->addClass($attr, 'last'); } if ($params['item']['first']) { $attr = $this->addClass($attr, 'first'); } return $this->_setActive($attr); }
php
public function getLiAttr() { $params = self::$_itemParams; $attr = ['class' => 'li-item']; if (isset($params['item']['liClass'])) { $attr = $this->addClass($attr, $params['item']['liClass']); } if ($params['item']['last']) { $attr = $this->addClass($attr, 'last'); } if ($params['item']['first']) { $attr = $this->addClass($attr, 'first'); } return $this->_setActive($attr); }
[ "public", "function", "getLiAttr", "(", ")", "{", "$", "params", "=", "self", "::", "$", "_itemParams", ";", "$", "attr", "=", "[", "'class'", "=>", "'li-item'", "]", ";", "if", "(", "isset", "(", "$", "params", "[", "'item'", "]", "[", "'liClass'", "]", ")", ")", "{", "$", "attr", "=", "$", "this", "->", "addClass", "(", "$", "attr", ",", "$", "params", "[", "'item'", "]", "[", "'liClass'", "]", ")", ";", "}", "if", "(", "$", "params", "[", "'item'", "]", "[", "'last'", "]", ")", "{", "$", "attr", "=", "$", "this", "->", "addClass", "(", "$", "attr", ",", "'last'", ")", ";", "}", "if", "(", "$", "params", "[", "'item'", "]", "[", "'first'", "]", ")", "{", "$", "attr", "=", "$", "this", "->", "addClass", "(", "$", "attr", ",", "'first'", ")", ";", "}", "return", "$", "this", "->", "_setActive", "(", "$", "attr", ")", ";", "}" ]
Get default li attributes. @return array
[ "Get", "default", "li", "attributes", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/NavHelper.php#L186-L204
CakeCMS/Core
src/View/Helper/NavHelper.php
NavHelper._setActive
protected function _setActive(array $attr = []) { if ($this->Url->build(self::$_itemParams['item']['url']) == env('REQUEST_URI')) { $attr = $this->addClass($attr, 'active'); } return $attr; }
php
protected function _setActive(array $attr = []) { if ($this->Url->build(self::$_itemParams['item']['url']) == env('REQUEST_URI')) { $attr = $this->addClass($attr, 'active'); } return $attr; }
[ "protected", "function", "_setActive", "(", "array", "$", "attr", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "Url", "->", "build", "(", "self", "::", "$", "_itemParams", "[", "'item'", "]", "[", "'url'", "]", ")", "==", "env", "(", "'REQUEST_URI'", ")", ")", "{", "$", "attr", "=", "$", "this", "->", "addClass", "(", "$", "attr", ",", "'active'", ")", ";", "}", "return", "$", "attr", ";", "}" ]
Set active item link. @param array $attr @return array
[ "Set", "active", "item", "link", "." ]
train
https://github.com/CakeCMS/Core/blob/f9cba7aa0043a10e5c35bd45fbad158688a09a96/src/View/Helper/NavHelper.php#L212-L219
yuncms/framework
src/behaviors/PolymorphicRelation.php
PolymorphicRelation.getPolymorphicRelation
public function getPolymorphicRelation() { if ($this->_cached !== null) { return $this->_cached; } $className = $this->owner->getAttribute($this->classAttribute); if ($className == "") { return null; } if (!class_exists($className)) { Yii::error("Underlying object class " . $className . " not found!"); return null; } $tableName = $className::tableName(); $object = $className::find()->where([$tableName . '.id' => $this->owner->getAttribute($this->pkAttribute)])->one(); if ($object !== null && $this->validateUnderlyingObjectType($object)) { $this->_cached = $object; return $object; } return null; }
php
public function getPolymorphicRelation() { if ($this->_cached !== null) { return $this->_cached; } $className = $this->owner->getAttribute($this->classAttribute); if ($className == "") { return null; } if (!class_exists($className)) { Yii::error("Underlying object class " . $className . " not found!"); return null; } $tableName = $className::tableName(); $object = $className::find()->where([$tableName . '.id' => $this->owner->getAttribute($this->pkAttribute)])->one(); if ($object !== null && $this->validateUnderlyingObjectType($object)) { $this->_cached = $object; return $object; } return null; }
[ "public", "function", "getPolymorphicRelation", "(", ")", "{", "if", "(", "$", "this", "->", "_cached", "!==", "null", ")", "{", "return", "$", "this", "->", "_cached", ";", "}", "$", "className", "=", "$", "this", "->", "owner", "->", "getAttribute", "(", "$", "this", "->", "classAttribute", ")", ";", "if", "(", "$", "className", "==", "\"\"", ")", "{", "return", "null", ";", "}", "if", "(", "!", "class_exists", "(", "$", "className", ")", ")", "{", "Yii", "::", "error", "(", "\"Underlying object class \"", ".", "$", "className", ".", "\" not found!\"", ")", ";", "return", "null", ";", "}", "$", "tableName", "=", "$", "className", "::", "tableName", "(", ")", ";", "$", "object", "=", "$", "className", "::", "find", "(", ")", "->", "where", "(", "[", "$", "tableName", ".", "'.id'", "=>", "$", "this", "->", "owner", "->", "getAttribute", "(", "$", "this", "->", "pkAttribute", ")", "]", ")", "->", "one", "(", ")", ";", "if", "(", "$", "object", "!==", "null", "&&", "$", "this", "->", "validateUnderlyingObjectType", "(", "$", "object", ")", ")", "{", "$", "this", "->", "_cached", "=", "$", "object", ";", "return", "$", "object", ";", "}", "return", "null", ";", "}" ]
Returns the Underlying Object @return mixed
[ "Returns", "the", "Underlying", "Object" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/behaviors/PolymorphicRelation.php#L50-L70
yuncms/framework
src/behaviors/PolymorphicRelation.php
PolymorphicRelation.validateUnderlyingObjectType
private function validateUnderlyingObjectType($object) { if (count($this->mustBeInstanceOf) == 0) { return true; } foreach ($this->mustBeInstanceOf as $instance) { if ($object instanceof $instance) { //|| $object->asa($instance) !== null return true; } } Yii::error('Got invalid underlying object type! (' . $object->className() . ')'); return false; }
php
private function validateUnderlyingObjectType($object) { if (count($this->mustBeInstanceOf) == 0) { return true; } foreach ($this->mustBeInstanceOf as $instance) { if ($object instanceof $instance) { //|| $object->asa($instance) !== null return true; } } Yii::error('Got invalid underlying object type! (' . $object->className() . ')'); return false; }
[ "private", "function", "validateUnderlyingObjectType", "(", "$", "object", ")", "{", "if", "(", "count", "(", "$", "this", "->", "mustBeInstanceOf", ")", "==", "0", ")", "{", "return", "true", ";", "}", "foreach", "(", "$", "this", "->", "mustBeInstanceOf", "as", "$", "instance", ")", "{", "if", "(", "$", "object", "instanceof", "$", "instance", ")", "{", "//|| $object->asa($instance) !== null", "return", "true", ";", "}", "}", "Yii", "::", "error", "(", "'Got invalid underlying object type! ('", ".", "$", "object", "->", "className", "(", ")", ".", "')'", ")", ";", "return", "false", ";", "}" ]
Validates if given object is of allowed type @param mixed $object @return boolean
[ "Validates", "if", "given", "object", "is", "of", "allowed", "type" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/behaviors/PolymorphicRelation.php#L98-L110
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Shared/String.php
PHPWord_Shared_String.getIsIconvEnabled
public static function getIsIconvEnabled() { if (isset(self::$_isIconvEnabled)) { return self::$_isIconvEnabled; } self::$_isIconvEnabled = function_exists('iconv') ? true : false; return self::$_isIconvEnabled; }
php
public static function getIsIconvEnabled() { if (isset(self::$_isIconvEnabled)) { return self::$_isIconvEnabled; } self::$_isIconvEnabled = function_exists('iconv') ? true : false; return self::$_isIconvEnabled; }
[ "public", "static", "function", "getIsIconvEnabled", "(", ")", "{", "if", "(", "isset", "(", "self", "::", "$", "_isIconvEnabled", ")", ")", "{", "return", "self", "::", "$", "_isIconvEnabled", ";", "}", "self", "::", "$", "_isIconvEnabled", "=", "function_exists", "(", "'iconv'", ")", "?", "true", ":", "false", ";", "return", "self", "::", "$", "_isIconvEnabled", ";", "}" ]
Get whether iconv extension is available @return boolean
[ "Get", "whether", "iconv", "extension", "is", "available" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Shared/String.php#L87-L97
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Shared/String.php
PHPWord_Shared_String.ControlCharacterOOXML2PHP
public static function ControlCharacterOOXML2PHP($value = '') { if(empty(self::$_controlCharacters)) { self::_buildControlCharacters(); } return str_replace( array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value ); }
php
public static function ControlCharacterOOXML2PHP($value = '') { if(empty(self::$_controlCharacters)) { self::_buildControlCharacters(); } return str_replace( array_keys(self::$_controlCharacters), array_values(self::$_controlCharacters), $value ); }
[ "public", "static", "function", "ControlCharacterOOXML2PHP", "(", "$", "value", "=", "''", ")", "{", "if", "(", "empty", "(", "self", "::", "$", "_controlCharacters", ")", ")", "{", "self", "::", "_buildControlCharacters", "(", ")", ";", "}", "return", "str_replace", "(", "array_keys", "(", "self", "::", "$", "_controlCharacters", ")", ",", "array_values", "(", "self", "::", "$", "_controlCharacters", ")", ",", "$", "value", ")", ";", "}" ]
Convert from OpenXML escaped control character to PHP control character Excel 2007 team: ---------------- That's correct, control characters are stored directly in the shared-strings table. We do encode characters that cannot be represented in XML using the following escape sequence: _xHHHH_ where H represents a hexadecimal character in the character's value... So you could end up with something like _x0008_ in a string (either in a cell value (<v>) element or in the shared string <t> element. @param string $value Value to unescape @return string
[ "Convert", "from", "OpenXML", "escaped", "control", "character", "to", "PHP", "control", "character" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Shared/String.php#L113-L119
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Shared/String.php
PHPWord_Shared_String.UTF8toBIFF8UnicodeLong
public static function UTF8toBIFF8UnicodeLong($value) { // character count $ln = self::CountCharacters($value, 'UTF-8'); // option flags $opt = (self::getIsMbstringEnabled() || self::getIsIconvEnabled()) ? 0x0001 : 0x0000; // characters $chars = self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8'); $data = pack('vC', $ln, $opt) . $chars; return $data; }
php
public static function UTF8toBIFF8UnicodeLong($value) { // character count $ln = self::CountCharacters($value, 'UTF-8'); // option flags $opt = (self::getIsMbstringEnabled() || self::getIsIconvEnabled()) ? 0x0001 : 0x0000; // characters $chars = self::ConvertEncoding($value, 'UTF-16LE', 'UTF-8'); $data = pack('vC', $ln, $opt) . $chars; return $data; }
[ "public", "static", "function", "UTF8toBIFF8UnicodeLong", "(", "$", "value", ")", "{", "// character count", "$", "ln", "=", "self", "::", "CountCharacters", "(", "$", "value", ",", "'UTF-8'", ")", ";", "// option flags", "$", "opt", "=", "(", "self", "::", "getIsMbstringEnabled", "(", ")", "||", "self", "::", "getIsIconvEnabled", "(", ")", ")", "?", "0x0001", ":", "0x0000", ";", "// characters", "$", "chars", "=", "self", "::", "ConvertEncoding", "(", "$", "value", ",", "'UTF-16LE'", ",", "'UTF-8'", ")", ";", "$", "data", "=", "pack", "(", "'vC'", ",", "$", "ln", ",", "$", "opt", ")", ".", "$", "chars", ";", "return", "$", "data", ";", "}" ]
Converts a UTF-8 string into BIFF8 Unicode string data (16-bit string length) Writes the string using uncompressed notation, no rich text, no Asian phonetics If mbstring extension is not available, ASCII is assumed, and compressed notation is used although this will give wrong results for non-ASCII strings see OpenOffice.org's Documentation of the Microsoft Excel File Format, sect. 2.5.3 @param string $value UTF-8 encoded string @return string
[ "Converts", "a", "UTF", "-", "8", "string", "into", "BIFF8", "Unicode", "string", "data", "(", "16", "-", "bit", "string", "length", ")", "Writes", "the", "string", "using", "uncompressed", "notation", "no", "rich", "text", "no", "Asian", "phonetics", "If", "mbstring", "extension", "is", "not", "available", "ASCII", "is", "assumed", "and", "compressed", "notation", "is", "used", "although", "this", "will", "give", "wrong", "results", "for", "non", "-", "ASCII", "strings", "see", "OpenOffice", ".", "org", "s", "Documentation", "of", "the", "Microsoft", "Excel", "File", "Format", "sect", ".", "2", ".", "5", ".", "3" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Shared/String.php#L199-L213
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Shared/String.php
PHPWord_Shared_String.ConvertEncoding
public static function ConvertEncoding($value, $to, $from) { if (self::getIsMbstringEnabled()) { $value = mb_convert_encoding($value, $to, $from); return $value; } if (self::getIsIconvEnabled()) { $value = iconv($from, $to, $value); return $value; } // else, no conversion return $value; }
php
public static function ConvertEncoding($value, $to, $from) { if (self::getIsMbstringEnabled()) { $value = mb_convert_encoding($value, $to, $from); return $value; } if (self::getIsIconvEnabled()) { $value = iconv($from, $to, $value); return $value; } // else, no conversion return $value; }
[ "public", "static", "function", "ConvertEncoding", "(", "$", "value", ",", "$", "to", ",", "$", "from", ")", "{", "if", "(", "self", "::", "getIsMbstringEnabled", "(", ")", ")", "{", "$", "value", "=", "mb_convert_encoding", "(", "$", "value", ",", "$", "to", ",", "$", "from", ")", ";", "return", "$", "value", ";", "}", "if", "(", "self", "::", "getIsIconvEnabled", "(", ")", ")", "{", "$", "value", "=", "iconv", "(", "$", "from", ",", "$", "to", ",", "$", "value", ")", ";", "return", "$", "value", ";", "}", "// else, no conversion", "return", "$", "value", ";", "}" ]
Convert string from one encoding to another. First try mbstring, then iconv, or no convertion @param string $value @param string $to Encoding to convert to, e.g. 'UTF-8' @param string $from Encoding to convert from, e.g. 'UTF-16LE' @return string
[ "Convert", "string", "from", "one", "encoding", "to", "another", ".", "First", "try", "mbstring", "then", "iconv", "or", "no", "convertion" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Shared/String.php#L223-L237
webforge-labs/psc-cms
lib/PHPWord/PHPWord/Shared/String.php
PHPWord_Shared_String.CountCharacters
public static function CountCharacters($value, $enc = 'UTF-8') { if (self::getIsMbstringEnabled()) { $count = mb_strlen($value, $enc); return $count; } if (self::getIsIconvEnabled()) { $count = iconv_strlen($value, $enc); return $count; } // else strlen $count = strlen($value); return $count; }
php
public static function CountCharacters($value, $enc = 'UTF-8') { if (self::getIsMbstringEnabled()) { $count = mb_strlen($value, $enc); return $count; } if (self::getIsIconvEnabled()) { $count = iconv_strlen($value, $enc); return $count; } // else strlen $count = strlen($value); return $count; }
[ "public", "static", "function", "CountCharacters", "(", "$", "value", ",", "$", "enc", "=", "'UTF-8'", ")", "{", "if", "(", "self", "::", "getIsMbstringEnabled", "(", ")", ")", "{", "$", "count", "=", "mb_strlen", "(", "$", "value", ",", "$", "enc", ")", ";", "return", "$", "count", ";", "}", "if", "(", "self", "::", "getIsIconvEnabled", "(", ")", ")", "{", "$", "count", "=", "iconv_strlen", "(", "$", "value", ",", "$", "enc", ")", ";", "return", "$", "count", ";", "}", "// else strlen", "$", "count", "=", "strlen", "(", "$", "value", ")", ";", "return", "$", "count", ";", "}" ]
Get character count. First try mbstring, then iconv, finally strlen @param string $value @param string $enc Encoding @return int Character count
[ "Get", "character", "count", ".", "First", "try", "mbstring", "then", "iconv", "finally", "strlen" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Shared/String.php#L246-L261
Craftsware/scissor
src/Lib/Database.php
Database.max
public function max($table, $inc = null) { return $this->select($table, ['MAX(id)'])[0]['MAX(id)'] + (isset($inc) ? $inc : 0); }
php
public function max($table, $inc = null) { return $this->select($table, ['MAX(id)'])[0]['MAX(id)'] + (isset($inc) ? $inc : 0); }
[ "public", "function", "max", "(", "$", "table", ",", "$", "inc", "=", "null", ")", "{", "return", "$", "this", "->", "select", "(", "$", "table", ",", "[", "'MAX(id)'", "]", ")", "[", "0", "]", "[", "'MAX(id)'", "]", "+", "(", "isset", "(", "$", "inc", ")", "?", "$", "inc", ":", "0", ")", ";", "}" ]
Get Maximum ID of a table @param $table String @param $add Int
[ "Get", "Maximum", "ID", "of", "a", "table" ]
train
https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Lib/Database.php#L53-L56
Craftsware/scissor
src/Lib/Database.php
Database.fetch
public function fetch($query) { $db = $this->connection(); if(method_exists($result = $db->query(rtrim(preg_replace('/\s\s/', ' ', $query), ' ')), 'rowCount')) { if($result->rowCount() && $result->setFetchMode($db::FETCH_ASSOC)) { return $result->fetchAll(); } return false; } }
php
public function fetch($query) { $db = $this->connection(); if(method_exists($result = $db->query(rtrim(preg_replace('/\s\s/', ' ', $query), ' ')), 'rowCount')) { if($result->rowCount() && $result->setFetchMode($db::FETCH_ASSOC)) { return $result->fetchAll(); } return false; } }
[ "public", "function", "fetch", "(", "$", "query", ")", "{", "$", "db", "=", "$", "this", "->", "connection", "(", ")", ";", "if", "(", "method_exists", "(", "$", "result", "=", "$", "db", "->", "query", "(", "rtrim", "(", "preg_replace", "(", "'/\\s\\s/'", ",", "' '", ",", "$", "query", ")", ",", "' '", ")", ")", ",", "'rowCount'", ")", ")", "{", "if", "(", "$", "result", "->", "rowCount", "(", ")", "&&", "$", "result", "->", "setFetchMode", "(", "$", "db", "::", "FETCH_ASSOC", ")", ")", "{", "return", "$", "result", "->", "fetchAll", "(", ")", ";", "}", "return", "false", ";", "}", "}" ]
Get Data from the table @param $query String
[ "Get", "Data", "from", "the", "table" ]
train
https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Lib/Database.php#L78-L91
Craftsware/scissor
src/Lib/Database.php
Database.migrate
public function migrate($dir) { $migrate = []; if(file_exists($directory = '../App/'. $dir)) { foreach(array_reverse(glob($directory .'/*.php')) as $path) { $namespace = str_replace('/', '\\', 'App'. explode('.php', explode('App', $path)[1])[0]); if(method_exists($object = (new $namespace), 'create')) { if($table = $object->create($this)) { $migrate['created'][] = basename($namespace); } else { $migrate['failed'][] = basename($namespace); } } else { $migrate['error'] = 'Method '. basename($namespace) . ':create() not exist.'; } } } else { $migrate['error'] = 'Directory ' . $dir .' not exist.'; } return $migrate; }
php
public function migrate($dir) { $migrate = []; if(file_exists($directory = '../App/'. $dir)) { foreach(array_reverse(glob($directory .'/*.php')) as $path) { $namespace = str_replace('/', '\\', 'App'. explode('.php', explode('App', $path)[1])[0]); if(method_exists($object = (new $namespace), 'create')) { if($table = $object->create($this)) { $migrate['created'][] = basename($namespace); } else { $migrate['failed'][] = basename($namespace); } } else { $migrate['error'] = 'Method '. basename($namespace) . ':create() not exist.'; } } } else { $migrate['error'] = 'Directory ' . $dir .' not exist.'; } return $migrate; }
[ "public", "function", "migrate", "(", "$", "dir", ")", "{", "$", "migrate", "=", "[", "]", ";", "if", "(", "file_exists", "(", "$", "directory", "=", "'../App/'", ".", "$", "dir", ")", ")", "{", "foreach", "(", "array_reverse", "(", "glob", "(", "$", "directory", ".", "'/*.php'", ")", ")", "as", "$", "path", ")", "{", "$", "namespace", "=", "str_replace", "(", "'/'", ",", "'\\\\'", ",", "'App'", ".", "explode", "(", "'.php'", ",", "explode", "(", "'App'", ",", "$", "path", ")", "[", "1", "]", ")", "[", "0", "]", ")", ";", "if", "(", "method_exists", "(", "$", "object", "=", "(", "new", "$", "namespace", ")", ",", "'create'", ")", ")", "{", "if", "(", "$", "table", "=", "$", "object", "->", "create", "(", "$", "this", ")", ")", "{", "$", "migrate", "[", "'created'", "]", "[", "]", "=", "basename", "(", "$", "namespace", ")", ";", "}", "else", "{", "$", "migrate", "[", "'failed'", "]", "[", "]", "=", "basename", "(", "$", "namespace", ")", ";", "}", "}", "else", "{", "$", "migrate", "[", "'error'", "]", "=", "'Method '", ".", "basename", "(", "$", "namespace", ")", ".", "':create() not exist.'", ";", "}", "}", "}", "else", "{", "$", "migrate", "[", "'error'", "]", "=", "'Directory '", ".", "$", "dir", ".", "' not exist.'", ";", "}", "return", "$", "migrate", ";", "}" ]
Migrate @param array $tables @return JSON $migrate
[ "Migrate" ]
train
https://github.com/Craftsware/scissor/blob/644e4a8ea9859fc30fee36705e54784acd8d43e2/src/Lib/Database.php#L169-L203
yuncms/framework
src/oauth2/actions/QRCode.php
QRCode.init
public function init() { $this->controller->enableCsrfValidation = false; Yii::$app->response->format = $this->format; }
php
public function init() { $this->controller->enableCsrfValidation = false; Yii::$app->response->format = $this->format; }
[ "public", "function", "init", "(", ")", "{", "$", "this", "->", "controller", "->", "enableCsrfValidation", "=", "false", ";", "Yii", "::", "$", "app", "->", "response", "->", "format", "=", "$", "this", "->", "format", ";", "}" ]
初始化
[ "初始化" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/oauth2/actions/QRCode.php#L40-L44
yuncms/framework
src/oauth2/actions/QRCode.php
QRCode.run
public function run($code = null) { if (empty($code)) { $code = Yii::$app->security->generateRandomString(40); } $attributes = Yii::$app->cache->getOrSet([self::CACHE_PREFIX, 'code' => $code], function ($cache) use ($code) { return [ 'code' => $code, 'msg' => Yii::t('yuncms', 'Please use App Scan QR code to login.'), ]; }, 120); Yii::$app->response->data = $attributes; }
php
public function run($code = null) { if (empty($code)) { $code = Yii::$app->security->generateRandomString(40); } $attributes = Yii::$app->cache->getOrSet([self::CACHE_PREFIX, 'code' => $code], function ($cache) use ($code) { return [ 'code' => $code, 'msg' => Yii::t('yuncms', 'Please use App Scan QR code to login.'), ]; }, 120); Yii::$app->response->data = $attributes; }
[ "public", "function", "run", "(", "$", "code", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "code", ")", ")", "{", "$", "code", "=", "Yii", "::", "$", "app", "->", "security", "->", "generateRandomString", "(", "40", ")", ";", "}", "$", "attributes", "=", "Yii", "::", "$", "app", "->", "cache", "->", "getOrSet", "(", "[", "self", "::", "CACHE_PREFIX", ",", "'code'", "=>", "$", "code", "]", ",", "function", "(", "$", "cache", ")", "use", "(", "$", "code", ")", "{", "return", "[", "'code'", "=>", "$", "code", ",", "'msg'", "=>", "Yii", "::", "t", "(", "'yuncms'", ",", "'Please use App Scan QR code to login.'", ")", ",", "]", ";", "}", ",", "120", ")", ";", "Yii", "::", "$", "app", "->", "response", "->", "data", "=", "$", "attributes", ";", "}" ]
run @param string $code @throws \yii\base\Exception
[ "run" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/oauth2/actions/QRCode.php#L51-L64
vorbind/influx-analytics
src/Connection.php
Connection.getDatabase
public function getDatabase($name) { try { if (!isset($name)) { throw InvalidArgumentException::invalidType('"db name" driver option', $name, 'string'); } if (null == $this->client) { $this->client = new \InfluxDB\Client($this->host, $this->port, $this->username, $this->password); } if (!isset($this->dbs[$name])) { $this->dbs[$name] = $this->client->selectDB($name); } return $this->dbs[$name]; } catch (Exception $e) { throw new AnalyticsException("Connecting influx db faild", 0, $e); } }
php
public function getDatabase($name) { try { if (!isset($name)) { throw InvalidArgumentException::invalidType('"db name" driver option', $name, 'string'); } if (null == $this->client) { $this->client = new \InfluxDB\Client($this->host, $this->port, $this->username, $this->password); } if (!isset($this->dbs[$name])) { $this->dbs[$name] = $this->client->selectDB($name); } return $this->dbs[$name]; } catch (Exception $e) { throw new AnalyticsException("Connecting influx db faild", 0, $e); } }
[ "public", "function", "getDatabase", "(", "$", "name", ")", "{", "try", "{", "if", "(", "!", "isset", "(", "$", "name", ")", ")", "{", "throw", "InvalidArgumentException", "::", "invalidType", "(", "'\"db name\" driver option'", ",", "$", "name", ",", "'string'", ")", ";", "}", "if", "(", "null", "==", "$", "this", "->", "client", ")", "{", "$", "this", "->", "client", "=", "new", "\\", "InfluxDB", "\\", "Client", "(", "$", "this", "->", "host", ",", "$", "this", "->", "port", ",", "$", "this", "->", "username", ",", "$", "this", "->", "password", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "dbs", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "dbs", "[", "$", "name", "]", "=", "$", "this", "->", "client", "->", "selectDB", "(", "$", "name", ")", ";", "}", "return", "$", "this", "->", "dbs", "[", "$", "name", "]", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "AnalyticsException", "(", "\"Connecting influx db faild\"", ",", "0", ",", "$", "e", ")", ";", "}", "}" ]
Get database @param string $name @return InfluxDB\Database $db @throws AnalyticsException
[ "Get", "database" ]
train
https://github.com/vorbind/influx-analytics/blob/8c0c150351f045ccd3d57063f2b3b50a2c926e3e/src/Connection.php#L53-L71
egeloen/IvorySerializerBundle
IvorySerializerBundle.php
IvorySerializerBundle.build
public function build(ContainerBuilder $container) { $container ->addCompilerPass(new RegisterCachePoolPass()) ->addCompilerPass(new RegisterClassMetadataLoaderPass()) ->addCompilerPass(new RegisterListenerPass()) ->addCompilerPass(new RegisterFOSServicePass()) ->addCompilerPass(new RegisterTypePass()) ->addCompilerPass(new RegisterVisitorPass()); }
php
public function build(ContainerBuilder $container) { $container ->addCompilerPass(new RegisterCachePoolPass()) ->addCompilerPass(new RegisterClassMetadataLoaderPass()) ->addCompilerPass(new RegisterListenerPass()) ->addCompilerPass(new RegisterFOSServicePass()) ->addCompilerPass(new RegisterTypePass()) ->addCompilerPass(new RegisterVisitorPass()); }
[ "public", "function", "build", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "container", "->", "addCompilerPass", "(", "new", "RegisterCachePoolPass", "(", ")", ")", "->", "addCompilerPass", "(", "new", "RegisterClassMetadataLoaderPass", "(", ")", ")", "->", "addCompilerPass", "(", "new", "RegisterListenerPass", "(", ")", ")", "->", "addCompilerPass", "(", "new", "RegisterFOSServicePass", "(", ")", ")", "->", "addCompilerPass", "(", "new", "RegisterTypePass", "(", ")", ")", "->", "addCompilerPass", "(", "new", "RegisterVisitorPass", "(", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/egeloen/IvorySerializerBundle/blob/a2bdd912bf715c61b823cf7257ee232d5c823dd3/IvorySerializerBundle.php#L31-L40
ClanCats/Core
src/classes/CCError/Trace.php
CCError_Trace.file
public function file( $cut = true ) { if ( empty( $this->file ) ) { return null; } if ( $cut ) { return str_replace( CCROOT, '', $this->file ); } return $this->file; }
php
public function file( $cut = true ) { if ( empty( $this->file ) ) { return null; } if ( $cut ) { return str_replace( CCROOT, '', $this->file ); } return $this->file; }
[ "public", "function", "file", "(", "$", "cut", "=", "true", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "file", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "cut", ")", "{", "return", "str_replace", "(", "CCROOT", ",", "''", ",", "$", "this", "->", "file", ")", ";", "}", "return", "$", "this", "->", "file", ";", "}" ]
get file path @param bool $cut Cut @return string
[ "get", "file", "path" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError/Trace.php#L90-L103
ClanCats/Core
src/classes/CCError/Trace.php
CCError_Trace.args_string
public function args_string() { if ( !isset( $this->args ) || !is_array( $this->args ) ) { return null; } $args = $this->args; foreach( $args as $key => $arg ) { if ( is_array( $arg ) ) { $args[$key] = 'Array'; } else { $args[$key] = var_export( $arg, true ); } } return implode( ', ', $args ); }
php
public function args_string() { if ( !isset( $this->args ) || !is_array( $this->args ) ) { return null; } $args = $this->args; foreach( $args as $key => $arg ) { if ( is_array( $arg ) ) { $args[$key] = 'Array'; } else { $args[$key] = var_export( $arg, true ); } } return implode( ', ', $args ); }
[ "public", "function", "args_string", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "args", ")", "||", "!", "is_array", "(", "$", "this", "->", "args", ")", ")", "{", "return", "null", ";", "}", "$", "args", "=", "$", "this", "->", "args", ";", "foreach", "(", "$", "args", "as", "$", "key", "=>", "$", "arg", ")", "{", "if", "(", "is_array", "(", "$", "arg", ")", ")", "{", "$", "args", "[", "$", "key", "]", "=", "'Array'", ";", "}", "else", "{", "$", "args", "[", "$", "key", "]", "=", "var_export", "(", "$", "arg", ",", "true", ")", ";", "}", "}", "return", "implode", "(", "', '", ",", "$", "args", ")", ";", "}" ]
create an argument string @return string
[ "create", "an", "argument", "string" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError/Trace.php#L160-L182
ClanCats/Core
src/classes/CCError/Trace.php
CCError_Trace.parse_source
private function parse_source() { if ( !$this->file() ) { return null; } // get the file $lines = file( $this->file ); /* * parse the relevant source */ $size = 10; $start = $this->line - ( $size / 2 ); $end = $this->line + ( $size / 2 ); // check if start is in the middle of a comment while( $start > 0 && substr( trim( $lines[$start-1] ), 0, 1 ) === '*' ) { $start--; } $source = array(); for ( $i=$start-1; $i<$end; $i++ ) { if ( array_key_exists( $i, $lines ) ) { $source[$i] = str_replace( "\t", ' ', $lines[$i] ); } } $this->source = $source; }
php
private function parse_source() { if ( !$this->file() ) { return null; } // get the file $lines = file( $this->file ); /* * parse the relevant source */ $size = 10; $start = $this->line - ( $size / 2 ); $end = $this->line + ( $size / 2 ); // check if start is in the middle of a comment while( $start > 0 && substr( trim( $lines[$start-1] ), 0, 1 ) === '*' ) { $start--; } $source = array(); for ( $i=$start-1; $i<$end; $i++ ) { if ( array_key_exists( $i, $lines ) ) { $source[$i] = str_replace( "\t", ' ', $lines[$i] ); } } $this->source = $source; }
[ "private", "function", "parse_source", "(", ")", "{", "if", "(", "!", "$", "this", "->", "file", "(", ")", ")", "{", "return", "null", ";", "}", "// get the file", "$", "lines", "=", "file", "(", "$", "this", "->", "file", ")", ";", "/*\n\t\t * parse the relevant source\n\t\t */", "$", "size", "=", "10", ";", "$", "start", "=", "$", "this", "->", "line", "-", "(", "$", "size", "/", "2", ")", ";", "$", "end", "=", "$", "this", "->", "line", "+", "(", "$", "size", "/", "2", ")", ";", "// check if start is in the middle of a comment", "while", "(", "$", "start", ">", "0", "&&", "substr", "(", "trim", "(", "$", "lines", "[", "$", "start", "-", "1", "]", ")", ",", "0", ",", "1", ")", "===", "'*'", ")", "{", "$", "start", "--", ";", "}", "$", "source", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "$", "start", "-", "1", ";", "$", "i", "<", "$", "end", ";", "$", "i", "++", ")", "{", "if", "(", "array_key_exists", "(", "$", "i", ",", "$", "lines", ")", ")", "{", "$", "source", "[", "$", "i", "]", "=", "str_replace", "(", "\"\\t\"", ",", "' '", ",", "$", "lines", "[", "$", "i", "]", ")", ";", "}", "}", "$", "this", "->", "source", "=", "$", "source", ";", "}" ]
parse the source file @return void
[ "parse", "the", "source", "file" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError/Trace.php#L189-L224
ClanCats/Core
src/classes/CCError/Trace.php
CCError_Trace.reflection_file
public function reflection_file() { if ( is_null( $this->reflection_file ) ) { if ( is_null( $reflection = $this->reflection() ) ) { return null; } $this->reflection_file = file( $reflection->getFileName() ); } return $this->reflection_file; }
php
public function reflection_file() { if ( is_null( $this->reflection_file ) ) { if ( is_null( $reflection = $this->reflection() ) ) { return null; } $this->reflection_file = file( $reflection->getFileName() ); } return $this->reflection_file; }
[ "public", "function", "reflection_file", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "reflection_file", ")", ")", "{", "if", "(", "is_null", "(", "$", "reflection", "=", "$", "this", "->", "reflection", "(", ")", ")", ")", "{", "return", "null", ";", "}", "$", "this", "->", "reflection_file", "=", "file", "(", "$", "reflection", "->", "getFileName", "(", ")", ")", ";", "}", "return", "$", "this", "->", "reflection_file", ";", "}" ]
get the source code of the reflected file @return string
[ "get", "the", "source", "code", "of", "the", "reflected", "file" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError/Trace.php#L261-L274
ClanCats/Core
src/classes/CCError/Trace.php
CCError_Trace.reflection_function_info
public function reflection_function_info( $function = null ) { if ( is_null( $lines = $this->reflection_file() ) ) { return null; } if ( is_null( $function ) ) { if ( is_null( $function = $this->function_name() ) ) { return null; } } $info = array( 'message' => '', ); foreach( $lines as $index => $line ) { // is this the function define if ( strpos( $line, 'function '.$function ) !== false ) { // do we have a comment on top if ( substr( trim( $lines[$index-1] ), 0, 1 ) === '*' ) { $start = $index-1; $comment = array(); // parse the comment while( $start > 0 && substr( trim( $lines[$start-1] ), 0, 1 ) === '*' ) { $start--; array_unshift( $comment, substr( trim( trim( $lines[$start] ), "*" ), 1 ) ); } // parse quotse $in_quote = false; // we got a comment foreach( $comment as $line ) { // add param if ( strpos( $line, '@' ) !== false ) { // replace double tabs $line = preg_replace( "!\t+!", "\t", $line ); // make tabs to spaces $line = str_replace( "\t", ' ', $line ); $info[trim(substr( $line, 1, strpos( $line, ' ' ) ))][] = trim( substr( $line, strpos( $line, ' ' ) ) ); } // add message else { $line = str_replace( "\t", ' ', $line ); if ( substr( $line, 0, 4 ) == ' ' && !$in_quote ) { $info['message'] .= "<pre>"; $in_quote = true; } elseif ( substr( $line, 0, 4 ) != ' ' && $in_quote ) { $info['message'] .= "</pre>"; $in_quote = false; } if ( $in_quote ) { $line = substr( $line, 4 ); } $info['message'] .= $line."\n"; } } // final trim $info['message'] = trim( $info['message'], "\n\r\t" ); // done; return $info; } continue; } } }
php
public function reflection_function_info( $function = null ) { if ( is_null( $lines = $this->reflection_file() ) ) { return null; } if ( is_null( $function ) ) { if ( is_null( $function = $this->function_name() ) ) { return null; } } $info = array( 'message' => '', ); foreach( $lines as $index => $line ) { // is this the function define if ( strpos( $line, 'function '.$function ) !== false ) { // do we have a comment on top if ( substr( trim( $lines[$index-1] ), 0, 1 ) === '*' ) { $start = $index-1; $comment = array(); // parse the comment while( $start > 0 && substr( trim( $lines[$start-1] ), 0, 1 ) === '*' ) { $start--; array_unshift( $comment, substr( trim( trim( $lines[$start] ), "*" ), 1 ) ); } // parse quotse $in_quote = false; // we got a comment foreach( $comment as $line ) { // add param if ( strpos( $line, '@' ) !== false ) { // replace double tabs $line = preg_replace( "!\t+!", "\t", $line ); // make tabs to spaces $line = str_replace( "\t", ' ', $line ); $info[trim(substr( $line, 1, strpos( $line, ' ' ) ))][] = trim( substr( $line, strpos( $line, ' ' ) ) ); } // add message else { $line = str_replace( "\t", ' ', $line ); if ( substr( $line, 0, 4 ) == ' ' && !$in_quote ) { $info['message'] .= "<pre>"; $in_quote = true; } elseif ( substr( $line, 0, 4 ) != ' ' && $in_quote ) { $info['message'] .= "</pre>"; $in_quote = false; } if ( $in_quote ) { $line = substr( $line, 4 ); } $info['message'] .= $line."\n"; } } // final trim $info['message'] = trim( $info['message'], "\n\r\t" ); // done; return $info; } continue; } } }
[ "public", "function", "reflection_function_info", "(", "$", "function", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "lines", "=", "$", "this", "->", "reflection_file", "(", ")", ")", ")", "{", "return", "null", ";", "}", "if", "(", "is_null", "(", "$", "function", ")", ")", "{", "if", "(", "is_null", "(", "$", "function", "=", "$", "this", "->", "function_name", "(", ")", ")", ")", "{", "return", "null", ";", "}", "}", "$", "info", "=", "array", "(", "'message'", "=>", "''", ",", ")", ";", "foreach", "(", "$", "lines", "as", "$", "index", "=>", "$", "line", ")", "{", "// is this the function define", "if", "(", "strpos", "(", "$", "line", ",", "'function '", ".", "$", "function", ")", "!==", "false", ")", "{", "// do we have a comment on top", "if", "(", "substr", "(", "trim", "(", "$", "lines", "[", "$", "index", "-", "1", "]", ")", ",", "0", ",", "1", ")", "===", "'*'", ")", "{", "$", "start", "=", "$", "index", "-", "1", ";", "$", "comment", "=", "array", "(", ")", ";", "// parse the comment", "while", "(", "$", "start", ">", "0", "&&", "substr", "(", "trim", "(", "$", "lines", "[", "$", "start", "-", "1", "]", ")", ",", "0", ",", "1", ")", "===", "'*'", ")", "{", "$", "start", "--", ";", "array_unshift", "(", "$", "comment", ",", "substr", "(", "trim", "(", "trim", "(", "$", "lines", "[", "$", "start", "]", ")", ",", "\"*\"", ")", ",", "1", ")", ")", ";", "}", "// parse quotse", "$", "in_quote", "=", "false", ";", "// we got a comment", "foreach", "(", "$", "comment", "as", "$", "line", ")", "{", "// add param", "if", "(", "strpos", "(", "$", "line", ",", "'@'", ")", "!==", "false", ")", "{", "// replace double tabs", "$", "line", "=", "preg_replace", "(", "\"!\\t+!\"", ",", "\"\\t\"", ",", "$", "line", ")", ";", "// make tabs to spaces", "$", "line", "=", "str_replace", "(", "\"\\t\"", ",", "' '", ",", "$", "line", ")", ";", "$", "info", "[", "trim", "(", "substr", "(", "$", "line", ",", "1", ",", "strpos", "(", "$", "line", ",", "' '", ")", ")", ")", "]", "[", "]", "=", "trim", "(", "substr", "(", "$", "line", ",", "strpos", "(", "$", "line", ",", "' '", ")", ")", ")", ";", "}", "// add message", "else", "{", "$", "line", "=", "str_replace", "(", "\"\\t\"", ",", "' '", ",", "$", "line", ")", ";", "if", "(", "substr", "(", "$", "line", ",", "0", ",", "4", ")", "==", "' '", "&&", "!", "$", "in_quote", ")", "{", "$", "info", "[", "'message'", "]", ".=", "\"<pre>\"", ";", "$", "in_quote", "=", "true", ";", "}", "elseif", "(", "substr", "(", "$", "line", ",", "0", ",", "4", ")", "!=", "' '", "&&", "$", "in_quote", ")", "{", "$", "info", "[", "'message'", "]", ".=", "\"</pre>\"", ";", "$", "in_quote", "=", "false", ";", "}", "if", "(", "$", "in_quote", ")", "{", "$", "line", "=", "substr", "(", "$", "line", ",", "4", ")", ";", "}", "$", "info", "[", "'message'", "]", ".=", "$", "line", ".", "\"\\n\"", ";", "}", "}", "// final trim", "$", "info", "[", "'message'", "]", "=", "trim", "(", "$", "info", "[", "'message'", "]", ",", "\"\\n\\r\\t\"", ")", ";", "// done;", "return", "$", "info", ";", "}", "continue", ";", "}", "}", "}" ]
get the source code where the trace happend @return string
[ "get", "the", "source", "code", "where", "the", "trace", "happend" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError/Trace.php#L281-L367
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed/Builder/Header.php
Zend_Feed_Builder_Header.setEmail
public function setEmail($email) { /** * @see Zend_Validate_EmailAddress */ require_once 'Zend/Validate/EmailAddress.php'; $validate = new Zend_Validate_EmailAddress(); if (!$validate->isValid($email)) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the email property"); } $this->offsetSet('email', $email); return $this; }
php
public function setEmail($email) { /** * @see Zend_Validate_EmailAddress */ require_once 'Zend/Validate/EmailAddress.php'; $validate = new Zend_Validate_EmailAddress(); if (!$validate->isValid($email)) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the email property"); } $this->offsetSet('email', $email); return $this; }
[ "public", "function", "setEmail", "(", "$", "email", ")", "{", "/**\n * @see Zend_Validate_EmailAddress\n */", "require_once", "'Zend/Validate/EmailAddress.php'", ";", "$", "validate", "=", "new", "Zend_Validate_EmailAddress", "(", ")", ";", "if", "(", "!", "$", "validate", "->", "isValid", "(", "$", "email", ")", ")", "{", "/**\n * @see Zend_Feed_Builder_Exception\n */", "require_once", "'Zend/Feed/Builder/Exception.php'", ";", "throw", "new", "Zend_Feed_Builder_Exception", "(", "\"you have to set a valid email address into the email property\"", ")", ";", "}", "$", "this", "->", "offsetSet", "(", "'email'", ",", "$", "email", ")", ";", "return", "$", "this", ";", "}" ]
Sets the author's email @param string $email @return Zend_Feed_Builder_Header @throws Zend_Feed_Builder_Exception
[ "Sets", "the", "author", "s", "email" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed/Builder/Header.php#L170-L186
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed/Builder/Header.php
Zend_Feed_Builder_Header.setWebmaster
public function setWebmaster($webmaster) { /** * @see Zend_Validate_EmailAddress */ require_once 'Zend/Validate/EmailAddress.php'; $validate = new Zend_Validate_EmailAddress(); if (!$validate->isValid($webmaster)) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the webmaster property"); } $this->offsetSet('webmaster', $webmaster); return $this; }
php
public function setWebmaster($webmaster) { /** * @see Zend_Validate_EmailAddress */ require_once 'Zend/Validate/EmailAddress.php'; $validate = new Zend_Validate_EmailAddress(); if (!$validate->isValid($webmaster)) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("you have to set a valid email address into the webmaster property"); } $this->offsetSet('webmaster', $webmaster); return $this; }
[ "public", "function", "setWebmaster", "(", "$", "webmaster", ")", "{", "/**\n * @see Zend_Validate_EmailAddress\n */", "require_once", "'Zend/Validate/EmailAddress.php'", ";", "$", "validate", "=", "new", "Zend_Validate_EmailAddress", "(", ")", ";", "if", "(", "!", "$", "validate", "->", "isValid", "(", "$", "webmaster", ")", ")", "{", "/**\n * @see Zend_Feed_Builder_Exception\n */", "require_once", "'Zend/Feed/Builder/Exception.php'", ";", "throw", "new", "Zend_Feed_Builder_Exception", "(", "\"you have to set a valid email address into the webmaster property\"", ")", ";", "}", "$", "this", "->", "offsetSet", "(", "'webmaster'", ",", "$", "webmaster", ")", ";", "return", "$", "this", ";", "}" ]
Email address for person responsible for technical issues Ignored if atom is used @param string $webmaster @return Zend_Feed_Builder_Header @throws Zend_Feed_Builder_Exception
[ "Email", "address", "for", "person", "responsible", "for", "technical", "issues", "Ignored", "if", "atom", "is", "used" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed/Builder/Header.php#L244-L260
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed/Builder/Header.php
Zend_Feed_Builder_Header.setTtl
public function setTtl($ttl) { /** * @see Zend_Validate_Int */ require_once 'Zend/Validate/Int.php'; $validate = new Zend_Validate_Int(); if (!$validate->isValid($ttl)) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("you have to set an integer value to the ttl property"); } $this->offsetSet('ttl', $ttl); return $this; }
php
public function setTtl($ttl) { /** * @see Zend_Validate_Int */ require_once 'Zend/Validate/Int.php'; $validate = new Zend_Validate_Int(); if (!$validate->isValid($ttl)) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("you have to set an integer value to the ttl property"); } $this->offsetSet('ttl', $ttl); return $this; }
[ "public", "function", "setTtl", "(", "$", "ttl", ")", "{", "/**\n * @see Zend_Validate_Int\n */", "require_once", "'Zend/Validate/Int.php'", ";", "$", "validate", "=", "new", "Zend_Validate_Int", "(", ")", ";", "if", "(", "!", "$", "validate", "->", "isValid", "(", "$", "ttl", ")", ")", "{", "/**\n * @see Zend_Feed_Builder_Exception\n */", "require_once", "'Zend/Feed/Builder/Exception.php'", ";", "throw", "new", "Zend_Feed_Builder_Exception", "(", "\"you have to set an integer value to the ttl property\"", ")", ";", "}", "$", "this", "->", "offsetSet", "(", "'ttl'", ",", "$", "ttl", ")", ";", "return", "$", "this", ";", "}" ]
How long in minutes a feed can be cached before refreshing Ignored if atom is used @param int $ttl @return Zend_Feed_Builder_Header @throws Zend_Feed_Builder_Exception
[ "How", "long", "in", "minutes", "a", "feed", "can", "be", "cached", "before", "refreshing", "Ignored", "if", "atom", "is", "used" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed/Builder/Header.php#L270-L286
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed/Builder/Header.php
Zend_Feed_Builder_Header.setCloud
public function setCloud($uri, $procedure, $protocol) { if (is_string($uri) && Zend_Uri_Http::check($uri)) { $uri = Zend_Uri::factory($uri); } if (!$uri instanceof Zend_Uri_Http) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception('Passed parameter is not a valid HTTP URI'); } if (!$uri->getPort()) { $uri->setPort(80); } $this->offsetSet('cloud', array('uri' => $uri, 'procedure' => $procedure, 'protocol' => $protocol)); return $this; }
php
public function setCloud($uri, $procedure, $protocol) { if (is_string($uri) && Zend_Uri_Http::check($uri)) { $uri = Zend_Uri::factory($uri); } if (!$uri instanceof Zend_Uri_Http) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception('Passed parameter is not a valid HTTP URI'); } if (!$uri->getPort()) { $uri->setPort(80); } $this->offsetSet('cloud', array('uri' => $uri, 'procedure' => $procedure, 'protocol' => $protocol)); return $this; }
[ "public", "function", "setCloud", "(", "$", "uri", ",", "$", "procedure", ",", "$", "protocol", ")", "{", "if", "(", "is_string", "(", "$", "uri", ")", "&&", "Zend_Uri_Http", "::", "check", "(", "$", "uri", ")", ")", "{", "$", "uri", "=", "Zend_Uri", "::", "factory", "(", "$", "uri", ")", ";", "}", "if", "(", "!", "$", "uri", "instanceof", "Zend_Uri_Http", ")", "{", "/**\n * @see Zend_Feed_Builder_Exception\n */", "require_once", "'Zend/Feed/Builder/Exception.php'", ";", "throw", "new", "Zend_Feed_Builder_Exception", "(", "'Passed parameter is not a valid HTTP URI'", ")", ";", "}", "if", "(", "!", "$", "uri", "->", "getPort", "(", ")", ")", "{", "$", "uri", "->", "setPort", "(", "80", ")", ";", "}", "$", "this", "->", "offsetSet", "(", "'cloud'", ",", "array", "(", "'uri'", "=>", "$", "uri", ",", "'procedure'", "=>", "$", "procedure", ",", "'protocol'", "=>", "$", "protocol", ")", ")", ";", "return", "$", "this", ";", "}" ]
Cloud to be notified of updates of the feed Ignored if atom is used @param string|Zend_Uri_Http $uri @param string $procedure procedure to call, e.g. myCloud.rssPleaseNotify @param string $protocol protocol to use, e.g. soap or xml-rpc @return Zend_Feed_Builder_Header @throws Zend_Feed_Builder_Exception
[ "Cloud", "to", "be", "notified", "of", "updates", "of", "the", "feed", "Ignored", "if", "atom", "is", "used" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed/Builder/Header.php#L311-L330
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed/Builder/Header.php
Zend_Feed_Builder_Header.setTextInput
public function setTextInput($title, $description, $name, $link) { $this->offsetSet('textInput', array('title' => $title, 'description' => $description, 'name' => $name, 'link' => $link)); return $this; }
php
public function setTextInput($title, $description, $name, $link) { $this->offsetSet('textInput', array('title' => $title, 'description' => $description, 'name' => $name, 'link' => $link)); return $this; }
[ "public", "function", "setTextInput", "(", "$", "title", ",", "$", "description", ",", "$", "name", ",", "$", "link", ")", "{", "$", "this", "->", "offsetSet", "(", "'textInput'", ",", "array", "(", "'title'", "=>", "$", "title", ",", "'description'", "=>", "$", "description", ",", "'name'", "=>", "$", "name", ",", "'link'", "=>", "$", "link", ")", ")", ";", "return", "$", "this", ";", "}" ]
A text input box that can be displayed with the feed Ignored if atom is used @param string $title the label of the Submit button in the text input area @param string $description explains the text input area @param string $name the name of the text object in the text input area @param string $link the URL of the CGI script that processes text input requests @return Zend_Feed_Builder_Header
[ "A", "text", "input", "box", "that", "can", "be", "displayed", "with", "the", "feed", "Ignored", "if", "atom", "is", "used" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed/Builder/Header.php#L342-L349
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed/Builder/Header.php
Zend_Feed_Builder_Header.setSkipHours
public function setSkipHours(array $hours) { if (count($hours) > 24) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("you can not have more than 24 rows in the skipHours property"); } foreach ($hours as $hour) { if ($hour < 0 || $hour > 23) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("$hour has te be between 0 and 23"); } } $this->offsetSet('skipHours', $hours); return $this; }
php
public function setSkipHours(array $hours) { if (count($hours) > 24) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("you can not have more than 24 rows in the skipHours property"); } foreach ($hours as $hour) { if ($hour < 0 || $hour > 23) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("$hour has te be between 0 and 23"); } } $this->offsetSet('skipHours', $hours); return $this; }
[ "public", "function", "setSkipHours", "(", "array", "$", "hours", ")", "{", "if", "(", "count", "(", "$", "hours", ")", ">", "24", ")", "{", "/**\n * @see Zend_Feed_Builder_Exception\n */", "require_once", "'Zend/Feed/Builder/Exception.php'", ";", "throw", "new", "Zend_Feed_Builder_Exception", "(", "\"you can not have more than 24 rows in the skipHours property\"", ")", ";", "}", "foreach", "(", "$", "hours", "as", "$", "hour", ")", "{", "if", "(", "$", "hour", "<", "0", "||", "$", "hour", ">", "23", ")", "{", "/**\n * @see Zend_Feed_Builder_Exception\n */", "require_once", "'Zend/Feed/Builder/Exception.php'", ";", "throw", "new", "Zend_Feed_Builder_Exception", "(", "\"$hour has te be between 0 and 23\"", ")", ";", "}", "}", "$", "this", "->", "offsetSet", "(", "'skipHours'", ",", "$", "hours", ")", ";", "return", "$", "this", ";", "}" ]
Hint telling aggregators which hours they can skip Ignored if atom is used @param array $hours list of hours in 24 format @return Zend_Feed_Builder_Header @throws Zend_Feed_Builder_Exception
[ "Hint", "telling", "aggregators", "which", "hours", "they", "can", "skip", "Ignored", "if", "atom", "is", "used" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed/Builder/Header.php#L359-L379
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed/Builder/Header.php
Zend_Feed_Builder_Header.setSkipDays
public function setSkipDays(array $days) { if (count($days) > 7) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("you can not have more than 7 days in the skipDays property"); } $valid = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'); foreach ($days as $day) { if (!in_array(strtolower($day), $valid)) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("$day is not a valid day"); } } $this->offsetSet('skipDays', $days); return $this; }
php
public function setSkipDays(array $days) { if (count($days) > 7) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("you can not have more than 7 days in the skipDays property"); } $valid = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday'); foreach ($days as $day) { if (!in_array(strtolower($day), $valid)) { /** * @see Zend_Feed_Builder_Exception */ require_once 'Zend/Feed/Builder/Exception.php'; throw new Zend_Feed_Builder_Exception("$day is not a valid day"); } } $this->offsetSet('skipDays', $days); return $this; }
[ "public", "function", "setSkipDays", "(", "array", "$", "days", ")", "{", "if", "(", "count", "(", "$", "days", ")", ">", "7", ")", "{", "/**\n * @see Zend_Feed_Builder_Exception\n */", "require_once", "'Zend/Feed/Builder/Exception.php'", ";", "throw", "new", "Zend_Feed_Builder_Exception", "(", "\"you can not have more than 7 days in the skipDays property\"", ")", ";", "}", "$", "valid", "=", "array", "(", "'monday'", ",", "'tuesday'", ",", "'wednesday'", ",", "'thursday'", ",", "'friday'", ",", "'saturday'", ",", "'sunday'", ")", ";", "foreach", "(", "$", "days", "as", "$", "day", ")", "{", "if", "(", "!", "in_array", "(", "strtolower", "(", "$", "day", ")", ",", "$", "valid", ")", ")", "{", "/**\n * @see Zend_Feed_Builder_Exception\n */", "require_once", "'Zend/Feed/Builder/Exception.php'", ";", "throw", "new", "Zend_Feed_Builder_Exception", "(", "\"$day is not a valid day\"", ")", ";", "}", "}", "$", "this", "->", "offsetSet", "(", "'skipDays'", ",", "$", "days", ")", ";", "return", "$", "this", ";", "}" ]
Hint telling aggregators which days they can skip Ignored if atom is used @param array $days list of days to skip, e.g. Monday @return Zend_Feed_Builder_Header @throws Zend_Feed_Builder_Exception
[ "Hint", "telling", "aggregators", "which", "days", "they", "can", "skip", "Ignored", "if", "atom", "is", "used" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed/Builder/Header.php#L389-L410
sebastiaanluca/laravel-unbreakable-migrations
src/Commands/GenerateMigration.php
GenerateMigration.handle
public function handle() : void { if ($module = $this->option('module')) { $this->input->setOption('path', 'modules/' . $module . '/database/migrations'); } parent::handle(); }
php
public function handle() : void { if ($module = $this->option('module')) { $this->input->setOption('path', 'modules/' . $module . '/database/migrations'); } parent::handle(); }
[ "public", "function", "handle", "(", ")", ":", "void", "{", "if", "(", "$", "module", "=", "$", "this", "->", "option", "(", "'module'", ")", ")", "{", "$", "this", "->", "input", "->", "setOption", "(", "'path'", ",", "'modules/'", ".", "$", "module", ".", "'/database/migrations'", ")", ";", "}", "parent", "::", "handle", "(", ")", ";", "}" ]
Execute the console command. @return void
[ "Execute", "the", "console", "command", "." ]
train
https://github.com/sebastiaanluca/laravel-unbreakable-migrations/blob/3c831b204770b80c97351c3b881dcbf924236a13/src/Commands/GenerateMigration.php#L46-L53
nyeholt/silverstripe-external-content
code/cache/CacheService.php
CacheService.store
public function store($key, $value, $expiry=0) { if ($expiry == 0) { $expiry = $this->expiry; } $entry = new CacheItem(); $entry->value = serialize($value); $entry->expireAt = time() + $expiry; $data = serialize($entry); $this->store->store($key, $data); $this->items[$key] = $entry; }
php
public function store($key, $value, $expiry=0) { if ($expiry == 0) { $expiry = $this->expiry; } $entry = new CacheItem(); $entry->value = serialize($value); $entry->expireAt = time() + $expiry; $data = serialize($entry); $this->store->store($key, $data); $this->items[$key] = $entry; }
[ "public", "function", "store", "(", "$", "key", ",", "$", "value", ",", "$", "expiry", "=", "0", ")", "{", "if", "(", "$", "expiry", "==", "0", ")", "{", "$", "expiry", "=", "$", "this", "->", "expiry", ";", "}", "$", "entry", "=", "new", "CacheItem", "(", ")", ";", "$", "entry", "->", "value", "=", "serialize", "(", "$", "value", ")", ";", "$", "entry", "->", "expireAt", "=", "time", "(", ")", "+", "$", "expiry", ";", "$", "data", "=", "serialize", "(", "$", "entry", ")", ";", "$", "this", "->", "store", "->", "store", "(", "$", "key", ",", "$", "data", ")", ";", "$", "this", "->", "items", "[", "$", "key", "]", "=", "$", "entry", ";", "}" ]
Cache an item @param string $key @param mixed $value @param int $expiry How many seconds to cache this object for (no value uses the configured default)
[ "Cache", "an", "item" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/code/cache/CacheService.php#L67-L80
nyeholt/silverstripe-external-content
code/cache/CacheService.php
CacheService.get
public function get($key) { $entry = null; if (isset($this->items[$key])) { $entry = $this->items[$key]; } else { $data = $this->store->get($key); if ($data) { $entry = unserialize($data); } } if (!$entry) { return $entry; } // if the expire time is in the future if ($entry->expireAt > time()) { return unserialize($entry->value); } // if we got to here, we need to expire the value $this->expire($key); return null; }
php
public function get($key) { $entry = null; if (isset($this->items[$key])) { $entry = $this->items[$key]; } else { $data = $this->store->get($key); if ($data) { $entry = unserialize($data); } } if (!$entry) { return $entry; } // if the expire time is in the future if ($entry->expireAt > time()) { return unserialize($entry->value); } // if we got to here, we need to expire the value $this->expire($key); return null; }
[ "public", "function", "get", "(", "$", "key", ")", "{", "$", "entry", "=", "null", ";", "if", "(", "isset", "(", "$", "this", "->", "items", "[", "$", "key", "]", ")", ")", "{", "$", "entry", "=", "$", "this", "->", "items", "[", "$", "key", "]", ";", "}", "else", "{", "$", "data", "=", "$", "this", "->", "store", "->", "get", "(", "$", "key", ")", ";", "if", "(", "$", "data", ")", "{", "$", "entry", "=", "unserialize", "(", "$", "data", ")", ";", "}", "}", "if", "(", "!", "$", "entry", ")", "{", "return", "$", "entry", ";", "}", "// if the expire time is in the future", "if", "(", "$", "entry", "->", "expireAt", ">", "time", "(", ")", ")", "{", "return", "unserialize", "(", "$", "entry", "->", "value", ")", ";", "}", "// if we got to here, we need to expire the value", "$", "this", "->", "expire", "(", "$", "key", ")", ";", "return", "null", ";", "}" ]
Gets a cached value for a given key @param String $key The key to retrieve data for
[ "Gets", "a", "cached", "value", "for", "a", "given", "key" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/code/cache/CacheService.php#L87-L113
Chill-project/Main
Export/Formatter/CSVListFormatter.php
CSVListFormatter.buildForm
public function buildForm( FormBuilderInterface $builder, $exportAlias, array $aggregatorAliases ){ $builder->add('numerotation', ChoiceType::class, array( 'choices' => array( 'yes' => true, 'no' => false ), 'expanded' => true, 'multiple' => false, 'label' => "Add a number on first column", 'choices_as_values' => true, 'data' => true )); }
php
public function buildForm( FormBuilderInterface $builder, $exportAlias, array $aggregatorAliases ){ $builder->add('numerotation', ChoiceType::class, array( 'choices' => array( 'yes' => true, 'no' => false ), 'expanded' => true, 'multiple' => false, 'label' => "Add a number on first column", 'choices_as_values' => true, 'data' => true )); }
[ "public", "function", "buildForm", "(", "FormBuilderInterface", "$", "builder", ",", "$", "exportAlias", ",", "array", "$", "aggregatorAliases", ")", "{", "$", "builder", "->", "add", "(", "'numerotation'", ",", "ChoiceType", "::", "class", ",", "array", "(", "'choices'", "=>", "array", "(", "'yes'", "=>", "true", ",", "'no'", "=>", "false", ")", ",", "'expanded'", "=>", "true", ",", "'multiple'", "=>", "false", ",", "'label'", "=>", "\"Add a number on first column\"", ",", "'choices_as_values'", "=>", "true", ",", "'data'", "=>", "true", ")", ")", ";", "}" ]
build a form, which will be used to collect data required for the execution of this formatter. @uses appendAggregatorForm @param FormBuilderInterface $builder @param type $exportAlias @param array $aggregatorAliases
[ "build", "a", "form", "which", "will", "be", "used", "to", "collect", "data", "required", "for", "the", "execution", "of", "this", "formatter", "." ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Export/Formatter/CSVListFormatter.php#L93-L109
Chill-project/Main
Export/Formatter/CSVListFormatter.php
CSVListFormatter.getResponse
public function getResponse( $result, $formatterData, $exportAlias, array $exportData, array $filtersData, array $aggregatorsData ) { $this->result = $result; $this->exportAlias = $exportAlias; $this->exportData = $exportData; $this->formatterData = $formatterData; $output = fopen('php://output', 'w'); $this->prepareHeaders($output); $i = 1; foreach ($result as $row) { $line = array(); if ($this->formatterData['numerotation'] === true) { $line[] = $i; } foreach ($row as $key => $value) { $line[] = $this->getLabel($key, $value); } fputcsv($output, $line); $i++; } $csvContent = stream_get_contents($output); fclose($output); $response = new Response(); $response->setStatusCode(200); $response->headers->set('Content-Type', 'text/csv; charset=utf-8'); //$response->headers->set('Content-Disposition','attachment; filename="export.csv"'); $response->setContent($csvContent); return $response; }
php
public function getResponse( $result, $formatterData, $exportAlias, array $exportData, array $filtersData, array $aggregatorsData ) { $this->result = $result; $this->exportAlias = $exportAlias; $this->exportData = $exportData; $this->formatterData = $formatterData; $output = fopen('php://output', 'w'); $this->prepareHeaders($output); $i = 1; foreach ($result as $row) { $line = array(); if ($this->formatterData['numerotation'] === true) { $line[] = $i; } foreach ($row as $key => $value) { $line[] = $this->getLabel($key, $value); } fputcsv($output, $line); $i++; } $csvContent = stream_get_contents($output); fclose($output); $response = new Response(); $response->setStatusCode(200); $response->headers->set('Content-Type', 'text/csv; charset=utf-8'); //$response->headers->set('Content-Disposition','attachment; filename="export.csv"'); $response->setContent($csvContent); return $response; }
[ "public", "function", "getResponse", "(", "$", "result", ",", "$", "formatterData", ",", "$", "exportAlias", ",", "array", "$", "exportData", ",", "array", "$", "filtersData", ",", "array", "$", "aggregatorsData", ")", "{", "$", "this", "->", "result", "=", "$", "result", ";", "$", "this", "->", "exportAlias", "=", "$", "exportAlias", ";", "$", "this", "->", "exportData", "=", "$", "exportData", ";", "$", "this", "->", "formatterData", "=", "$", "formatterData", ";", "$", "output", "=", "fopen", "(", "'php://output'", ",", "'w'", ")", ";", "$", "this", "->", "prepareHeaders", "(", "$", "output", ")", ";", "$", "i", "=", "1", ";", "foreach", "(", "$", "result", "as", "$", "row", ")", "{", "$", "line", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "formatterData", "[", "'numerotation'", "]", "===", "true", ")", "{", "$", "line", "[", "]", "=", "$", "i", ";", "}", "foreach", "(", "$", "row", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "line", "[", "]", "=", "$", "this", "->", "getLabel", "(", "$", "key", ",", "$", "value", ")", ";", "}", "fputcsv", "(", "$", "output", ",", "$", "line", ")", ";", "$", "i", "++", ";", "}", "$", "csvContent", "=", "stream_get_contents", "(", "$", "output", ")", ";", "fclose", "(", "$", "output", ")", ";", "$", "response", "=", "new", "Response", "(", ")", ";", "$", "response", "->", "setStatusCode", "(", "200", ")", ";", "$", "response", "->", "headers", "->", "set", "(", "'Content-Type'", ",", "'text/csv; charset=utf-8'", ")", ";", "//$response->headers->set('Content-Disposition','attachment; filename=\"export.csv\"');", "$", "response", "->", "setContent", "(", "$", "csvContent", ")", ";", "return", "$", "response", ";", "}" ]
Generate a response from the data collected on differents ExportElementInterface @param mixed[] $result The result, as given by the ExportInterface @param mixed[] $formatterData collected from the current form @param string $exportAlias the id of the current export @param array $filtersData an array containing the filters data. The key are the filters id, and the value are the data @param array $aggregatorsData an array containing the aggregators data. The key are the filters id, and the value are the data @return \Symfony\Component\HttpFoundation\Response The response to be shown
[ "Generate", "a", "response", "from", "the", "data", "collected", "on", "differents", "ExportElementInterface" ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Export/Formatter/CSVListFormatter.php#L121-L166
Chill-project/Main
Export/Formatter/CSVListFormatter.php
CSVListFormatter.prepareHeaders
protected function prepareHeaders($output) { $keys = $this->exportManager->getExport($this->exportAlias)->getQueryKeys($this->exportData); // we want to keep the order of the first row. So we will iterate on the first row of the results $first_row = count($this->result) > 0 ? $this->result[0] : array(); $header_line = array(); if ($this->formatterData['numerotation'] === true) { $header_line[] = $this->translator->trans('Number'); } foreach ($first_row as $key => $value) { $header_line[] = $this->getLabel($key, '_header'); } if (count($header_line) > 0) { fputcsv($output, $header_line); } }
php
protected function prepareHeaders($output) { $keys = $this->exportManager->getExport($this->exportAlias)->getQueryKeys($this->exportData); // we want to keep the order of the first row. So we will iterate on the first row of the results $first_row = count($this->result) > 0 ? $this->result[0] : array(); $header_line = array(); if ($this->formatterData['numerotation'] === true) { $header_line[] = $this->translator->trans('Number'); } foreach ($first_row as $key => $value) { $header_line[] = $this->getLabel($key, '_header'); } if (count($header_line) > 0) { fputcsv($output, $header_line); } }
[ "protected", "function", "prepareHeaders", "(", "$", "output", ")", "{", "$", "keys", "=", "$", "this", "->", "exportManager", "->", "getExport", "(", "$", "this", "->", "exportAlias", ")", "->", "getQueryKeys", "(", "$", "this", "->", "exportData", ")", ";", "// we want to keep the order of the first row. So we will iterate on the first row of the results", "$", "first_row", "=", "count", "(", "$", "this", "->", "result", ")", ">", "0", "?", "$", "this", "->", "result", "[", "0", "]", ":", "array", "(", ")", ";", "$", "header_line", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "formatterData", "[", "'numerotation'", "]", "===", "true", ")", "{", "$", "header_line", "[", "]", "=", "$", "this", "->", "translator", "->", "trans", "(", "'Number'", ")", ";", "}", "foreach", "(", "$", "first_row", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "header_line", "[", "]", "=", "$", "this", "->", "getLabel", "(", "$", "key", ",", "'_header'", ")", ";", "}", "if", "(", "count", "(", "$", "header_line", ")", ">", "0", ")", "{", "fputcsv", "(", "$", "output", ",", "$", "header_line", ")", ";", "}", "}" ]
add the headers to the csv file @param resource $output
[ "add", "the", "headers", "to", "the", "csv", "file" ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Export/Formatter/CSVListFormatter.php#L173-L191
Chill-project/Main
Export/Formatter/CSVListFormatter.php
CSVListFormatter.getLabel
protected function getLabel($key, $value) { if ($this->labelsCache === null) { $this->prepareCacheLabels(); } return $this->labelsCache[$key]($value); }
php
protected function getLabel($key, $value) { if ($this->labelsCache === null) { $this->prepareCacheLabels(); } return $this->labelsCache[$key]($value); }
[ "protected", "function", "getLabel", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "$", "this", "->", "labelsCache", "===", "null", ")", "{", "$", "this", "->", "prepareCacheLabels", "(", ")", ";", "}", "return", "$", "this", "->", "labelsCache", "[", "$", "key", "]", "(", "$", "value", ")", ";", "}" ]
Give the label corresponding to the given key and value. @param string $key @param string $value @return string @throws \LogicException if the label is not found
[ "Give", "the", "label", "corresponding", "to", "the", "given", "key", "and", "value", "." ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Export/Formatter/CSVListFormatter.php#L201-L209
Chill-project/Main
Export/Formatter/CSVListFormatter.php
CSVListFormatter.prepareCacheLabels
protected function prepareCacheLabels() { $export = $this->exportManager->getExport($this->exportAlias); $keys = $export->getQueryKeys($this->exportData); foreach($keys as $key) { // get an array with all values for this key if possible $values = \array_map(function ($v) use ($key) { return $v[$key]; }, $this->result); // store the label in the labelsCache property $this->labelsCache[$key] = $export->getLabels($key, $values, $this->exportData); } }
php
protected function prepareCacheLabels() { $export = $this->exportManager->getExport($this->exportAlias); $keys = $export->getQueryKeys($this->exportData); foreach($keys as $key) { // get an array with all values for this key if possible $values = \array_map(function ($v) use ($key) { return $v[$key]; }, $this->result); // store the label in the labelsCache property $this->labelsCache[$key] = $export->getLabels($key, $values, $this->exportData); } }
[ "protected", "function", "prepareCacheLabels", "(", ")", "{", "$", "export", "=", "$", "this", "->", "exportManager", "->", "getExport", "(", "$", "this", "->", "exportAlias", ")", ";", "$", "keys", "=", "$", "export", "->", "getQueryKeys", "(", "$", "this", "->", "exportData", ")", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "// get an array with all values for this key if possible", "$", "values", "=", "\\", "array_map", "(", "function", "(", "$", "v", ")", "use", "(", "$", "key", ")", "{", "return", "$", "v", "[", "$", "key", "]", ";", "}", ",", "$", "this", "->", "result", ")", ";", "// store the label in the labelsCache property", "$", "this", "->", "labelsCache", "[", "$", "key", "]", "=", "$", "export", "->", "getLabels", "(", "$", "key", ",", "$", "values", ",", "$", "this", "->", "exportData", ")", ";", "}", "}" ]
Prepare the label cache which will be used by getLabel. This function should be called only once in the generation lifecycle.
[ "Prepare", "the", "label", "cache", "which", "will", "be", "used", "by", "getLabel", ".", "This", "function", "should", "be", "called", "only", "once", "in", "the", "generation", "lifecycle", "." ]
train
https://github.com/Chill-project/Main/blob/384cb6c793072a4f1047dc5cafc2157ee2419f60/Export/Formatter/CSVListFormatter.php#L215-L226
hackzilla/ticket-message
Component/TicketFeatures.php
TicketFeatures.hasFeature
public function hasFeature($feature) { $feature = strtoupper($feature); if (!isset($this->features[$feature])) { return null; } return $this->features[$feature]; }
php
public function hasFeature($feature) { $feature = strtoupper($feature); if (!isset($this->features[$feature])) { return null; } return $this->features[$feature]; }
[ "public", "function", "hasFeature", "(", "$", "feature", ")", "{", "$", "feature", "=", "strtoupper", "(", "$", "feature", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "features", "[", "$", "feature", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "features", "[", "$", "feature", "]", ";", "}" ]
Check if feature exists and enabled. @param string $feature @return bool|null
[ "Check", "if", "feature", "exists", "and", "enabled", "." ]
train
https://github.com/hackzilla/ticket-message/blob/043950aa95f322cfaae145ce3c7781a4b0618a18/Component/TicketFeatures.php#L32-L41
webforge-labs/psc-cms
lib/Psc/URL/Service/Request.php
Request.infer
public static function infer($GET = NULL, $POST = NULL, $COOKIE = NULL, $SERVER = NULL) { $merged = array(); $merged['GET'] = $GET !== NULL ? $GET : $_GET; $merged['POST'] = $POST !== NULL ? $POST : $_POST; $merged['COOKIE']= $COOKIE !== NULL ? $COOKIE : $_COOKIE; $merged['SERVER'] = $SERVER !== NULL ? $SERVER : $_SERVER; $input = new \Psc\Form\DataInput($merged); $method = NULL; switch ($input->get(array('SERVER','REQUEST_METHOD'))) { case 'POST': $method = Request::POST; break; case 'PUT': $method = Request::PUT; break; case 'DELETE': $method = Request::DELETE; break; case 'GET': default: $method = Request::GET; break; } /* wir haben mit mod-rewrite $_GET['mod_rewrite_request'] gesetzt oder es übergeben */ if (($rewriteResource = $input->get('GET.mod_rewrite_request', NULL)) != '') { $request = new Request($method, $rewriteResource); } elseif(isset($_SERVER['REQUEST_URI'])) { $request = new Request($method, $_SERVER['REQUEST_URI']); } else { throw new Exception('Konnte keine vernünftige Resource inferren. (kann nur GET[mod_rewrite_request]'); } if ($request->getMethod() === REQUEST::POST) { $request->setBody($input->get(array('POST'),array())); } if ($request->getMethod() === REQUEST::PUT) { throw new Exception('Keine Ahnung, wie ich hier an den Body komme'); } return $request; }
php
public static function infer($GET = NULL, $POST = NULL, $COOKIE = NULL, $SERVER = NULL) { $merged = array(); $merged['GET'] = $GET !== NULL ? $GET : $_GET; $merged['POST'] = $POST !== NULL ? $POST : $_POST; $merged['COOKIE']= $COOKIE !== NULL ? $COOKIE : $_COOKIE; $merged['SERVER'] = $SERVER !== NULL ? $SERVER : $_SERVER; $input = new \Psc\Form\DataInput($merged); $method = NULL; switch ($input->get(array('SERVER','REQUEST_METHOD'))) { case 'POST': $method = Request::POST; break; case 'PUT': $method = Request::PUT; break; case 'DELETE': $method = Request::DELETE; break; case 'GET': default: $method = Request::GET; break; } /* wir haben mit mod-rewrite $_GET['mod_rewrite_request'] gesetzt oder es übergeben */ if (($rewriteResource = $input->get('GET.mod_rewrite_request', NULL)) != '') { $request = new Request($method, $rewriteResource); } elseif(isset($_SERVER['REQUEST_URI'])) { $request = new Request($method, $_SERVER['REQUEST_URI']); } else { throw new Exception('Konnte keine vernünftige Resource inferren. (kann nur GET[mod_rewrite_request]'); } if ($request->getMethod() === REQUEST::POST) { $request->setBody($input->get(array('POST'),array())); } if ($request->getMethod() === REQUEST::PUT) { throw new Exception('Keine Ahnung, wie ich hier an den Body komme'); } return $request; }
[ "public", "static", "function", "infer", "(", "$", "GET", "=", "NULL", ",", "$", "POST", "=", "NULL", ",", "$", "COOKIE", "=", "NULL", ",", "$", "SERVER", "=", "NULL", ")", "{", "$", "merged", "=", "array", "(", ")", ";", "$", "merged", "[", "'GET'", "]", "=", "$", "GET", "!==", "NULL", "?", "$", "GET", ":", "$", "_GET", ";", "$", "merged", "[", "'POST'", "]", "=", "$", "POST", "!==", "NULL", "?", "$", "POST", ":", "$", "_POST", ";", "$", "merged", "[", "'COOKIE'", "]", "=", "$", "COOKIE", "!==", "NULL", "?", "$", "COOKIE", ":", "$", "_COOKIE", ";", "$", "merged", "[", "'SERVER'", "]", "=", "$", "SERVER", "!==", "NULL", "?", "$", "SERVER", ":", "$", "_SERVER", ";", "$", "input", "=", "new", "\\", "Psc", "\\", "Form", "\\", "DataInput", "(", "$", "merged", ")", ";", "$", "method", "=", "NULL", ";", "switch", "(", "$", "input", "->", "get", "(", "array", "(", "'SERVER'", ",", "'REQUEST_METHOD'", ")", ")", ")", "{", "case", "'POST'", ":", "$", "method", "=", "Request", "::", "POST", ";", "break", ";", "case", "'PUT'", ":", "$", "method", "=", "Request", "::", "PUT", ";", "break", ";", "case", "'DELETE'", ":", "$", "method", "=", "Request", "::", "DELETE", ";", "break", ";", "case", "'GET'", ":", "default", ":", "$", "method", "=", "Request", "::", "GET", ";", "break", ";", "}", "/* wir haben mit mod-rewrite $_GET['mod_rewrite_request'] gesetzt oder es übergeben */", "if", "(", "(", "$", "rewriteResource", "=", "$", "input", "->", "get", "(", "'GET.mod_rewrite_request'", ",", "NULL", ")", ")", "!=", "''", ")", "{", "$", "request", "=", "new", "Request", "(", "$", "method", ",", "$", "rewriteResource", ")", ";", "}", "elseif", "(", "isset", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ")", "{", "$", "request", "=", "new", "Request", "(", "$", "method", ",", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ";", "}", "else", "{", "throw", "new", "Exception", "(", "'Konnte keine vernünftige Resource inferren. (kann nur GET[mod_rewrite_request]')", ";", "", "}", "if", "(", "$", "request", "->", "getMethod", "(", ")", "===", "REQUEST", "::", "POST", ")", "{", "$", "request", "->", "setBody", "(", "$", "input", "->", "get", "(", "array", "(", "'POST'", ")", ",", "array", "(", ")", ")", ")", ";", "}", "if", "(", "$", "request", "->", "getMethod", "(", ")", "===", "REQUEST", "::", "PUT", ")", "{", "throw", "new", "Exception", "(", "'Keine Ahnung, wie ich hier an den Body komme'", ")", ";", "}", "return", "$", "request", ";", "}" ]
Erstellt einen Request aus den Umgebungsvariablen wird eine Umgebungsvariable mit NULL übergeben (oder ausgelassen), wird die global Umgebungsvariable genommen infer() ist also äquivalent mit: infer($_GET, $_POST, $_COOKIE, $_SERVER) ist $_GET['mod_rewrite_request'] gesetzt wird dies als resource genommen
[ "Erstellt", "einen", "Request", "aus", "den", "Umgebungsvariablen" ]
train
https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/URL/Service/Request.php#L58-L106
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setEventEmitter
public function setEventEmitter($emitter = null) { if ($emitter === null) { $this->eventEmitter = new Emitter(); } else { $this->eventEmitter = $emitter; } }
php
public function setEventEmitter($emitter = null) { if ($emitter === null) { $this->eventEmitter = new Emitter(); } else { $this->eventEmitter = $emitter; } }
[ "public", "function", "setEventEmitter", "(", "$", "emitter", "=", "null", ")", "{", "if", "(", "$", "emitter", "===", "null", ")", "{", "$", "this", "->", "eventEmitter", "=", "new", "Emitter", "(", ")", ";", "}", "else", "{", "$", "this", "->", "eventEmitter", "=", "$", "emitter", ";", "}", "}" ]
Set an event emitter @param object $emitter Event emitter object
[ "Set", "an", "event", "emitter" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L111-L118
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.addEventListener
public function addEventListener($eventName, callable $listener, $priority = Emitter::P_NORMAL) { $this->eventEmitter->addListener($eventName, $listener, $priority); }
php
public function addEventListener($eventName, callable $listener, $priority = Emitter::P_NORMAL) { $this->eventEmitter->addListener($eventName, $listener, $priority); }
[ "public", "function", "addEventListener", "(", "$", "eventName", ",", "callable", "$", "listener", ",", "$", "priority", "=", "Emitter", "::", "P_NORMAL", ")", "{", "$", "this", "->", "eventEmitter", "->", "addListener", "(", "$", "eventName", ",", "$", "listener", ",", "$", "priority", ")", ";", "}" ]
Add an event listener to the event emitter @param string $eventName Event name @param callable $listener Callable function or method @param int $priority Priority of event listener
[ "Add", "an", "event", "listener", "to", "the", "event", "emitter" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L127-L130
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.getRequest
public function getRequest() { if ($this->request === null) { $this->request = Request::createFromGlobals(); } return $this->request; }
php
public function getRequest() { if ($this->request === null) { $this->request = Request::createFromGlobals(); } return $this->request; }
[ "public", "function", "getRequest", "(", ")", "{", "if", "(", "$", "this", "->", "request", "===", "null", ")", "{", "$", "this", "->", "request", "=", "Request", "::", "createFromGlobals", "(", ")", ";", "}", "return", "$", "this", "->", "request", ";", "}" ]
Gets the Request object. It will create one from the globals if one is not set. @return \Symfony\Component\HttpFoundation\Request
[ "Gets", "the", "Request", "object", ".", "It", "will", "create", "one", "from", "the", "globals", "if", "one", "is", "not", "set", "." ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L161-L168
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setClientStorage
public function setClientStorage(ClientInterface $storage) { $storage->setServer($this); $this->clientStorage = $storage; return $this; }
php
public function setClientStorage(ClientInterface $storage) { $storage->setServer($this); $this->clientStorage = $storage; return $this; }
[ "public", "function", "setClientStorage", "(", "ClientInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "clientStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the client storage @param \League\OAuth2\Server\Storage\ClientInterface $storage @return self
[ "Set", "the", "client", "storage" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L177-L183
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setSessionStorage
public function setSessionStorage(SessionInterface $storage) { $storage->setServer($this); $this->sessionStorage = $storage; return $this; }
php
public function setSessionStorage(SessionInterface $storage) { $storage->setServer($this); $this->sessionStorage = $storage; return $this; }
[ "public", "function", "setSessionStorage", "(", "SessionInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "sessionStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the session storage @param \League\OAuth2\Server\Storage\SessionInterface $storage @return self
[ "Set", "the", "session", "storage" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L192-L198
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setAccessTokenStorage
public function setAccessTokenStorage(AccessTokenInterface $storage) { $storage->setServer($this); $this->accessTokenStorage = $storage; return $this; }
php
public function setAccessTokenStorage(AccessTokenInterface $storage) { $storage->setServer($this); $this->accessTokenStorage = $storage; return $this; }
[ "public", "function", "setAccessTokenStorage", "(", "AccessTokenInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "accessTokenStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the access token storage @param \League\OAuth2\Server\Storage\AccessTokenInterface $storage @return self
[ "Set", "the", "access", "token", "storage" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L207-L213
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setRefreshTokenStorage
public function setRefreshTokenStorage(RefreshTokenInterface $storage) { $storage->setServer($this); $this->refreshTokenStorage = $storage; return $this; }
php
public function setRefreshTokenStorage(RefreshTokenInterface $storage) { $storage->setServer($this); $this->refreshTokenStorage = $storage; return $this; }
[ "public", "function", "setRefreshTokenStorage", "(", "RefreshTokenInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "refreshTokenStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the refresh token storage @param \League\OAuth2\Server\Storage\RefreshTokenInterface $storage @return self
[ "Set", "the", "refresh", "token", "storage" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L222-L228
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setAuthCodeStorage
public function setAuthCodeStorage(AuthCodeInterface $storage) { $storage->setServer($this); $this->authCodeStorage = $storage; return $this; }
php
public function setAuthCodeStorage(AuthCodeInterface $storage) { $storage->setServer($this); $this->authCodeStorage = $storage; return $this; }
[ "public", "function", "setAuthCodeStorage", "(", "AuthCodeInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "authCodeStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the auth code storage @param \League\OAuth2\Server\Storage\AuthCodeInterface $storage @return self
[ "Set", "the", "auth", "code", "storage" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L237-L243
redaigbaria/oauth2
src/AbstractServer.php
AbstractServer.setScopeStorage
public function setScopeStorage(ScopeInterface $storage) { $storage->setServer($this); $this->scopeStorage = $storage; return $this; }
php
public function setScopeStorage(ScopeInterface $storage) { $storage->setServer($this); $this->scopeStorage = $storage; return $this; }
[ "public", "function", "setScopeStorage", "(", "ScopeInterface", "$", "storage", ")", "{", "$", "storage", "->", "setServer", "(", "$", "this", ")", ";", "$", "this", "->", "scopeStorage", "=", "$", "storage", ";", "return", "$", "this", ";", "}" ]
Set the scope storage @param \League\OAuth2\Server\Storage\ScopeInterface $storage @return self
[ "Set", "the", "scope", "storage" ]
train
https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/AbstractServer.php#L252-L258
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php
BaseLicensePeer.getFieldNames
public static function getFieldNames($type = BasePeer::TYPE_PHPNAME) { if (!array_key_exists($type, LicensePeer::$fieldNames)) { throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.'); } return LicensePeer::$fieldNames[$type]; }
php
public static function getFieldNames($type = BasePeer::TYPE_PHPNAME) { if (!array_key_exists($type, LicensePeer::$fieldNames)) { throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.'); } return LicensePeer::$fieldNames[$type]; }
[ "public", "static", "function", "getFieldNames", "(", "$", "type", "=", "BasePeer", "::", "TYPE_PHPNAME", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "type", ",", "LicensePeer", "::", "$", "fieldNames", ")", ")", "{", "throw", "new", "PropelException", "(", "'Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. '", ".", "$", "type", ".", "' was given.'", ")", ";", "}", "return", "LicensePeer", "::", "$", "fieldNames", "[", "$", "type", "]", ";", "}" ]
Returns an array of field names. @param string $type The type of fieldnames to return: One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM @return array A list of field names @throws PropelException - if the type is not valid.
[ "Returns", "an", "array", "of", "field", "names", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php#L127-L134
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php
BaseLicensePeer.addSelectColumns
public static function addSelectColumns(Criteria $criteria, $alias = null) { if (null === $alias) { $criteria->addSelectColumn(LicensePeer::ID); $criteria->addSelectColumn(LicensePeer::MAX_CLIENTS); $criteria->addSelectColumn(LicensePeer::DOMAIN); $criteria->addSelectColumn(LicensePeer::VALID_UNTIL); $criteria->addSelectColumn(LicensePeer::SERIAL); } else { $criteria->addSelectColumn($alias . '.id'); $criteria->addSelectColumn($alias . '.max_clients'); $criteria->addSelectColumn($alias . '.domain'); $criteria->addSelectColumn($alias . '.valid_until'); $criteria->addSelectColumn($alias . '.serial'); } }
php
public static function addSelectColumns(Criteria $criteria, $alias = null) { if (null === $alias) { $criteria->addSelectColumn(LicensePeer::ID); $criteria->addSelectColumn(LicensePeer::MAX_CLIENTS); $criteria->addSelectColumn(LicensePeer::DOMAIN); $criteria->addSelectColumn(LicensePeer::VALID_UNTIL); $criteria->addSelectColumn(LicensePeer::SERIAL); } else { $criteria->addSelectColumn($alias . '.id'); $criteria->addSelectColumn($alias . '.max_clients'); $criteria->addSelectColumn($alias . '.domain'); $criteria->addSelectColumn($alias . '.valid_until'); $criteria->addSelectColumn($alias . '.serial'); } }
[ "public", "static", "function", "addSelectColumns", "(", "Criteria", "$", "criteria", ",", "$", "alias", "=", "null", ")", "{", "if", "(", "null", "===", "$", "alias", ")", "{", "$", "criteria", "->", "addSelectColumn", "(", "LicensePeer", "::", "ID", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "LicensePeer", "::", "MAX_CLIENTS", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "LicensePeer", "::", "DOMAIN", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "LicensePeer", "::", "VALID_UNTIL", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "LicensePeer", "::", "SERIAL", ")", ";", "}", "else", "{", "$", "criteria", "->", "addSelectColumn", "(", "$", "alias", ".", "'.id'", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "$", "alias", ".", "'.max_clients'", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "$", "alias", ".", "'.domain'", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "$", "alias", ".", "'.valid_until'", ")", ";", "$", "criteria", "->", "addSelectColumn", "(", "$", "alias", ".", "'.serial'", ")", ";", "}", "}" ]
Add all the columns needed to create a new object. Note: any columns that were marked with lazyLoad="true" in the XML schema will not be added to the select list and only loaded on demand. @param Criteria $criteria object containing the columns to add. @param string $alias optional table alias @throws PropelException Any exceptions caught during processing will be rethrown wrapped into a PropelException.
[ "Add", "all", "the", "columns", "needed", "to", "create", "a", "new", "object", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php#L165-L180
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php
BaseLicensePeer.doSelectStmt
public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(LicensePeer::DATABASE_NAME, Propel::CONNECTION_READ); } if (!$criteria->hasSelectClause()) { $criteria = clone $criteria; LicensePeer::addSelectColumns($criteria); } // Set the correct dbName $criteria->setDbName(LicensePeer::DATABASE_NAME); // BasePeer returns a PDOStatement return BasePeer::doSelect($criteria, $con); }
php
public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null) { if ($con === null) { $con = Propel::getConnection(LicensePeer::DATABASE_NAME, Propel::CONNECTION_READ); } if (!$criteria->hasSelectClause()) { $criteria = clone $criteria; LicensePeer::addSelectColumns($criteria); } // Set the correct dbName $criteria->setDbName(LicensePeer::DATABASE_NAME); // BasePeer returns a PDOStatement return BasePeer::doSelect($criteria, $con); }
[ "public", "static", "function", "doSelectStmt", "(", "Criteria", "$", "criteria", ",", "PropelPDO", "$", "con", "=", "null", ")", "{", "if", "(", "$", "con", "===", "null", ")", "{", "$", "con", "=", "Propel", "::", "getConnection", "(", "LicensePeer", "::", "DATABASE_NAME", ",", "Propel", "::", "CONNECTION_READ", ")", ";", "}", "if", "(", "!", "$", "criteria", "->", "hasSelectClause", "(", ")", ")", "{", "$", "criteria", "=", "clone", "$", "criteria", ";", "LicensePeer", "::", "addSelectColumns", "(", "$", "criteria", ")", ";", "}", "// Set the correct dbName", "$", "criteria", "->", "setDbName", "(", "LicensePeer", "::", "DATABASE_NAME", ")", ";", "// BasePeer returns a PDOStatement", "return", "BasePeer", "::", "doSelect", "(", "$", "criteria", ",", "$", "con", ")", ";", "}" ]
Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement. Use this method directly if you want to work with an executed statement directly (for example to perform your own object hydration). @param Criteria $criteria The Criteria object used to build the SELECT statement. @param PropelPDO $con The connection to use @throws PropelException Any exceptions caught during processing will be rethrown wrapped into a PropelException. @return PDOStatement The executed PDOStatement object. @see BasePeer::doSelect()
[ "Prepares", "the", "Criteria", "object", "and", "uses", "the", "parent", "doSelect", "()", "method", "to", "execute", "a", "PDOStatement", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php#L272-L288
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php
BaseLicensePeer.addInstanceToPool
public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null LicensePeer::$instances[$key] = $obj; } }
php
public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null LicensePeer::$instances[$key] = $obj; } }
[ "public", "static", "function", "addInstanceToPool", "(", "$", "obj", ",", "$", "key", "=", "null", ")", "{", "if", "(", "Propel", "::", "isInstancePoolingEnabled", "(", ")", ")", "{", "if", "(", "$", "key", "===", "null", ")", "{", "$", "key", "=", "(", "string", ")", "$", "obj", "->", "getId", "(", ")", ";", "}", "// if key === null", "LicensePeer", "::", "$", "instances", "[", "$", "key", "]", "=", "$", "obj", ";", "}", "}" ]
Adds an object to the instance pool. Propel keeps cached copies of objects in an instance pool when they are retrieved from the database. In some cases -- especially when you override doSelect*() methods in your stub classes -- you may need to explicitly add objects to the cache in order to ensure that the same objects are always returned by doSelect*() and retrieveByPK*() calls. @param License $obj A License object. @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
[ "Adds", "an", "object", "to", "the", "instance", "pool", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php#L301-L309
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php
BaseLicensePeer.getInstanceFromPool
public static function getInstanceFromPool($key) { if (Propel::isInstancePoolingEnabled()) { if (isset(LicensePeer::$instances[$key])) { return LicensePeer::$instances[$key]; } } return null; // just to be explicit }
php
public static function getInstanceFromPool($key) { if (Propel::isInstancePoolingEnabled()) { if (isset(LicensePeer::$instances[$key])) { return LicensePeer::$instances[$key]; } } return null; // just to be explicit }
[ "public", "static", "function", "getInstanceFromPool", "(", "$", "key", ")", "{", "if", "(", "Propel", "::", "isInstancePoolingEnabled", "(", ")", ")", "{", "if", "(", "isset", "(", "LicensePeer", "::", "$", "instances", "[", "$", "key", "]", ")", ")", "{", "return", "LicensePeer", "::", "$", "instances", "[", "$", "key", "]", ";", "}", "}", "return", "null", ";", "// just to be explicit", "}" ]
Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table. For tables with a single-column primary key, that simple pkey value will be returned. For tables with a multi-column primary key, a serialize()d version of the primary key will be returned. @param string $key The key (@see getPrimaryKeyHash()) for this instance. @return License Found object or null if 1) no instance exists for specified key or 2) instance pooling has been disabled. @see getPrimaryKeyHash()
[ "Retrieves", "a", "string", "version", "of", "the", "primary", "key", "from", "the", "DB", "resultset", "row", "that", "can", "be", "used", "to", "uniquely", "identify", "a", "row", "in", "this", "table", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php#L351-L360
slashworks/control-bundle
src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php
BaseLicensePeer.buildTableMap
public static function buildTableMap() { $dbMap = Propel::getDatabaseMap(BaseLicensePeer::DATABASE_NAME); if (!$dbMap->hasTable(BaseLicensePeer::TABLE_NAME)) { $dbMap->addTableObject(new \Slashworks\AppBundle\Model\map\LicenseTableMap()); } }
php
public static function buildTableMap() { $dbMap = Propel::getDatabaseMap(BaseLicensePeer::DATABASE_NAME); if (!$dbMap->hasTable(BaseLicensePeer::TABLE_NAME)) { $dbMap->addTableObject(new \Slashworks\AppBundle\Model\map\LicenseTableMap()); } }
[ "public", "static", "function", "buildTableMap", "(", ")", "{", "$", "dbMap", "=", "Propel", "::", "getDatabaseMap", "(", "BaseLicensePeer", "::", "DATABASE_NAME", ")", ";", "if", "(", "!", "$", "dbMap", "->", "hasTable", "(", "BaseLicensePeer", "::", "TABLE_NAME", ")", ")", "{", "$", "dbMap", "->", "addTableObject", "(", "new", "\\", "Slashworks", "\\", "AppBundle", "\\", "Model", "\\", "map", "\\", "LicenseTableMap", "(", ")", ")", ";", "}", "}" ]
Add a TableMap instance to the database for this peer class.
[ "Add", "a", "TableMap", "instance", "to", "the", "database", "for", "this", "peer", "class", "." ]
train
https://github.com/slashworks/control-bundle/blob/2ba86d96f1f41f9424e2229c4e2b13017e973f89/src/Slashworks/AppBundle/Model/om/BaseLicensePeer.php#L494-L500
yuncms/framework
src/admin/controllers/AdminController.php
AdminController.actionDelete
public function actionDelete($id) { if (Admin::find()->count() == 1) { Yii::$app->getSession()->setFlash('success', Yii::t('yuncms', 'This is the last administrator, delete can not manage the system, it can not be deleted!')); return $this->redirect(['index']); } $this->findModel($id)->delete(); Yii::$app->getSession()->setFlash('success', Yii::t('yuncms', 'Delete success.')); return $this->redirect(['index']); }
php
public function actionDelete($id) { if (Admin::find()->count() == 1) { Yii::$app->getSession()->setFlash('success', Yii::t('yuncms', 'This is the last administrator, delete can not manage the system, it can not be deleted!')); return $this->redirect(['index']); } $this->findModel($id)->delete(); Yii::$app->getSession()->setFlash('success', Yii::t('yuncms', 'Delete success.')); return $this->redirect(['index']); }
[ "public", "function", "actionDelete", "(", "$", "id", ")", "{", "if", "(", "Admin", "::", "find", "(", ")", "->", "count", "(", ")", "==", "1", ")", "{", "Yii", "::", "$", "app", "->", "getSession", "(", ")", "->", "setFlash", "(", "'success'", ",", "Yii", "::", "t", "(", "'yuncms'", ",", "'This is the last administrator, delete can not manage the system, it can not be deleted!'", ")", ")", ";", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}", "$", "this", "->", "findModel", "(", "$", "id", ")", "->", "delete", "(", ")", ";", "Yii", "::", "$", "app", "->", "getSession", "(", ")", "->", "setFlash", "(", "'success'", ",", "Yii", "::", "t", "(", "'yuncms'", ",", "'Delete success.'", ")", ")", ";", "return", "$", "this", "->", "redirect", "(", "[", "'index'", "]", ")", ";", "}" ]
Deletes an existing Admin model. If deletion is successful, the browser will be redirected to the 'index' page. @param integer $id @return mixed @throws NotFoundHttpException @throws \Exception @throws \Throwable @throws \yii\db\StaleObjectException
[ "Deletes", "an", "existing", "Admin", "model", ".", "If", "deletion", "is", "successful", "the", "browser", "will", "be", "redirected", "to", "the", "index", "page", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/admin/controllers/AdminController.php#L102-L111
okitcom/ok-lib-php
src/Model/Attributes.php
Attributes.init
public static function init(array $attributes) { $obj = new Attributes; foreach ($attributes as $attribute) { $obj->{$attribute->key} = $attribute; } return $obj; }
php
public static function init(array $attributes) { $obj = new Attributes; foreach ($attributes as $attribute) { $obj->{$attribute->key} = $attribute; } return $obj; }
[ "public", "static", "function", "init", "(", "array", "$", "attributes", ")", "{", "$", "obj", "=", "new", "Attributes", ";", "foreach", "(", "$", "attributes", "as", "$", "attribute", ")", "{", "$", "obj", "->", "{", "$", "attribute", "->", "key", "}", "=", "$", "attribute", ";", "}", "return", "$", "obj", ";", "}" ]
Initialize from list of attributes. @param Attribute[] $attributes @return Attributes
[ "Initialize", "from", "list", "of", "attributes", "." ]
train
https://github.com/okitcom/ok-lib-php/blob/1f441f3d216af7c952788e864bfe66bc4f089467/src/Model/Attributes.php#L62-L68
steeffeen/FancyManiaLinks
FML/Script/Features/ActionTrigger.php
ActionTrigger.getScriptText
protected function getScriptText() { $actionName = Builder::escapeText($this->actionName); if ($this->control) { // Control event $controlId = Builder::escapeText($this->control->getId()); $scriptText = " if (Event.Control.ControlId == {$controlId}) { TriggerPageAction({$actionName}); }"; } else { // Other $scriptText = " TriggerPageAction({$actionName});"; } return $scriptText; }
php
protected function getScriptText() { $actionName = Builder::escapeText($this->actionName); if ($this->control) { // Control event $controlId = Builder::escapeText($this->control->getId()); $scriptText = " if (Event.Control.ControlId == {$controlId}) { TriggerPageAction({$actionName}); }"; } else { // Other $scriptText = " TriggerPageAction({$actionName});"; } return $scriptText; }
[ "protected", "function", "getScriptText", "(", ")", "{", "$", "actionName", "=", "Builder", "::", "escapeText", "(", "$", "this", "->", "actionName", ")", ";", "if", "(", "$", "this", "->", "control", ")", "{", "// Control event", "$", "controlId", "=", "Builder", "::", "escapeText", "(", "$", "this", "->", "control", "->", "getId", "(", ")", ")", ";", "$", "scriptText", "=", "\"\nif (Event.Control.ControlId == {$controlId}) {\n\tTriggerPageAction({$actionName});\n}\"", ";", "}", "else", "{", "// Other", "$", "scriptText", "=", "\"\nTriggerPageAction({$actionName});\"", ";", "}", "return", "$", "scriptText", ";", "}" ]
Get the script text @return string
[ "Get", "the", "script", "text" ]
train
https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Script/Features/ActionTrigger.php#L149-L165
ClanCats/Core
src/bundles/Session/Manager/Database.php
Manager_Database.read
public function read( $id ) { $this->inital_session_id = $id; if ( $data = \DB::select( $this->table )->where( 'id', $id )->one( $this->database ) ) { $session_data = unserialize( $data->content ); foreach( $this->index_fields as $field ) { $session_data[$field] = $data->$field; } return $session_data; } return array(); }
php
public function read( $id ) { $this->inital_session_id = $id; if ( $data = \DB::select( $this->table )->where( 'id', $id )->one( $this->database ) ) { $session_data = unserialize( $data->content ); foreach( $this->index_fields as $field ) { $session_data[$field] = $data->$field; } return $session_data; } return array(); }
[ "public", "function", "read", "(", "$", "id", ")", "{", "$", "this", "->", "inital_session_id", "=", "$", "id", ";", "if", "(", "$", "data", "=", "\\", "DB", "::", "select", "(", "$", "this", "->", "table", ")", "->", "where", "(", "'id'", ",", "$", "id", ")", "->", "one", "(", "$", "this", "->", "database", ")", ")", "{", "$", "session_data", "=", "unserialize", "(", "$", "data", "->", "content", ")", ";", "foreach", "(", "$", "this", "->", "index_fields", "as", "$", "field", ")", "{", "$", "session_data", "[", "$", "field", "]", "=", "$", "data", "->", "$", "field", ";", "}", "return", "$", "session_data", ";", "}", "return", "array", "(", ")", ";", "}" ]
Read data from the session dirver @param string $id The session id key. @return array
[ "Read", "data", "from", "the", "session", "dirver" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Session/Manager/Database.php#L61-L78
ClanCats/Core
src/bundles/Session/Manager/Database.php
Manager_Database.has
public function has( $id ) { return \DB::select( $this->table ) ->where( 'id', $id ) ->column( 'id', $this->database ) == $id; }
php
public function has( $id ) { return \DB::select( $this->table ) ->where( 'id', $id ) ->column( 'id', $this->database ) == $id; }
[ "public", "function", "has", "(", "$", "id", ")", "{", "return", "\\", "DB", "::", "select", "(", "$", "this", "->", "table", ")", "->", "where", "(", "'id'", ",", "$", "id", ")", "->", "column", "(", "'id'", ",", "$", "this", "->", "database", ")", "==", "$", "id", ";", "}" ]
Check if a session with the given key already exists @param string $id The session id key. @return boool
[ "Check", "if", "a", "session", "with", "the", "given", "key", "already", "exists" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Session/Manager/Database.php#L86-L91
ClanCats/Core
src/bundles/Session/Manager/Database.php
Manager_Database.write
public function write( $id, $data ) { $columns = array(); foreach( $this->index_fields as $field ) { $columns[$field] = $data[$field]; unset( $data[$field] ); } $columns['content'] = serialize( $data ); // When the session id didnt change we will do an update if ( $id == $this->inital_session_id ) { // because the we might already be in the shutdown process we // have to forward sql error directly to CCError try { \DB::update( $this->table, $columns ) ->where( 'id', $id ) ->run( $this->database ); } catch ( \Exception $e ) { \CCError::exception( $e ); } } else // else insert a new one { // add the id to the columns $columns['id'] = $id; // because the we might already be in the shutdown process we // have to forward sql error directly to CCError try { \DB::insert( $this->table, $columns )->run( $this->database ); } catch ( \Exception $e ) { \CCError::exception( $e ); } } }
php
public function write( $id, $data ) { $columns = array(); foreach( $this->index_fields as $field ) { $columns[$field] = $data[$field]; unset( $data[$field] ); } $columns['content'] = serialize( $data ); // When the session id didnt change we will do an update if ( $id == $this->inital_session_id ) { // because the we might already be in the shutdown process we // have to forward sql error directly to CCError try { \DB::update( $this->table, $columns ) ->where( 'id', $id ) ->run( $this->database ); } catch ( \Exception $e ) { \CCError::exception( $e ); } } else // else insert a new one { // add the id to the columns $columns['id'] = $id; // because the we might already be in the shutdown process we // have to forward sql error directly to CCError try { \DB::insert( $this->table, $columns )->run( $this->database ); } catch ( \Exception $e ) { \CCError::exception( $e ); } } }
[ "public", "function", "write", "(", "$", "id", ",", "$", "data", ")", "{", "$", "columns", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "index_fields", "as", "$", "field", ")", "{", "$", "columns", "[", "$", "field", "]", "=", "$", "data", "[", "$", "field", "]", ";", "unset", "(", "$", "data", "[", "$", "field", "]", ")", ";", "}", "$", "columns", "[", "'content'", "]", "=", "serialize", "(", "$", "data", ")", ";", "// When the session id didnt change we will do an update", "if", "(", "$", "id", "==", "$", "this", "->", "inital_session_id", ")", "{", "// because the we might already be in the shutdown process we ", "// have to forward sql error directly to CCError", "try", "{", "\\", "DB", "::", "update", "(", "$", "this", "->", "table", ",", "$", "columns", ")", "->", "where", "(", "'id'", ",", "$", "id", ")", "->", "run", "(", "$", "this", "->", "database", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "\\", "CCError", "::", "exception", "(", "$", "e", ")", ";", "}", "}", "else", "// else insert a new one", "{", "// add the id to the columns", "$", "columns", "[", "'id'", "]", "=", "$", "id", ";", "// because the we might already be in the shutdown process we ", "// have to forward sql error directly to CCError", "try", "{", "\\", "DB", "::", "insert", "(", "$", "this", "->", "table", ",", "$", "columns", ")", "->", "run", "(", "$", "this", "->", "database", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "\\", "CCError", "::", "exception", "(", "$", "e", ")", ";", "}", "}", "}" ]
Check if a session with the given key already exists @param string $id The session id key. @param array $data @return bool
[ "Check", "if", "a", "session", "with", "the", "given", "key", "already", "exists" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Session/Manager/Database.php#L100-L140
ClanCats/Core
src/bundles/Session/Manager/Database.php
Manager_Database.gc
public function gc( $time ) { // if we don't have the last active key we cannot execute // the garbage collection if ( !in_array( 'last_active', $this->index_fields ) ) { return false; } \DB::delete( $this->table ) ->where( 'last_active', '<', time() - $time ) ->run( $this->database ); }
php
public function gc( $time ) { // if we don't have the last active key we cannot execute // the garbage collection if ( !in_array( 'last_active', $this->index_fields ) ) { return false; } \DB::delete( $this->table ) ->where( 'last_active', '<', time() - $time ) ->run( $this->database ); }
[ "public", "function", "gc", "(", "$", "time", ")", "{", "// if we don't have the last active key we cannot execute ", "// the garbage collection", "if", "(", "!", "in_array", "(", "'last_active'", ",", "$", "this", "->", "index_fields", ")", ")", "{", "return", "false", ";", "}", "\\", "DB", "::", "delete", "(", "$", "this", "->", "table", ")", "->", "where", "(", "'last_active'", ",", "'<'", ",", "time", "(", ")", "-", "$", "time", ")", "->", "run", "(", "$", "this", "->", "database", ")", ";", "}" ]
Delete session that are older than the given time in secounds @param int $time @return void
[ "Delete", "session", "that", "are", "older", "than", "the", "given", "time", "in", "secounds" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Session/Manager/Database.php#L148-L160
iocaste/microservice-foundation
src/Repository/Preloadable.php
Preloadable.getIncludes
protected function getIncludes($includes) { if ($includes === null) { return []; } $fractal = app(Manager::class); return $fractal->parseIncludes($includes)->getRequestedIncludes(); }
php
protected function getIncludes($includes) { if ($includes === null) { return []; } $fractal = app(Manager::class); return $fractal->parseIncludes($includes)->getRequestedIncludes(); }
[ "protected", "function", "getIncludes", "(", "$", "includes", ")", "{", "if", "(", "$", "includes", "===", "null", ")", "{", "return", "[", "]", ";", "}", "$", "fractal", "=", "app", "(", "Manager", "::", "class", ")", ";", "return", "$", "fractal", "->", "parseIncludes", "(", "$", "includes", ")", "->", "getRequestedIncludes", "(", ")", ";", "}" ]
@param $includes @return array|null
[ "@param", "$includes" ]
train
https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Repository/Preloadable.php#L69-L78
boekkooi/tactician-amqp
src/Exception/FailedToPublishException.php
FailedToPublishException.fromException
public static function fromException(Message $message, \AMQPException $exception) { $exception = new static('A AMQP exception occured while publishing the message', 0, $exception); $exception->tacticianMessage = $message; return $exception; }
php
public static function fromException(Message $message, \AMQPException $exception) { $exception = new static('A AMQP exception occured while publishing the message', 0, $exception); $exception->tacticianMessage = $message; return $exception; }
[ "public", "static", "function", "fromException", "(", "Message", "$", "message", ",", "\\", "AMQPException", "$", "exception", ")", "{", "$", "exception", "=", "new", "static", "(", "'A AMQP exception occured while publishing the message'", ",", "0", ",", "$", "exception", ")", ";", "$", "exception", "->", "tacticianMessage", "=", "$", "message", ";", "return", "$", "exception", ";", "}" ]
@param \AMQPException $exception @param Message $message @return static
[ "@param", "\\", "AMQPException", "$exception", "@param", "Message", "$message" ]
train
https://github.com/boekkooi/tactician-amqp/blob/55cbb8b9e20aab7891e6a6090b248377c599360e/src/Exception/FailedToPublishException.php#L40-L46
ClanCats/Core
src/bundles/Session/Manager/Json.php
Manager_Json.read
public function read( $id ) { if ( $this->has( $id ) ) { return \CCJson::read( $this->file_path( $id ) ); } return array(); }
php
public function read( $id ) { if ( $this->has( $id ) ) { return \CCJson::read( $this->file_path( $id ) ); } return array(); }
[ "public", "function", "read", "(", "$", "id", ")", "{", "if", "(", "$", "this", "->", "has", "(", "$", "id", ")", ")", "{", "return", "\\", "CCJson", "::", "read", "(", "$", "this", "->", "file_path", "(", "$", "id", ")", ")", ";", "}", "return", "array", "(", ")", ";", "}" ]
Read data from the session dirver @param string $id The session id key. @return array
[ "Read", "data", "from", "the", "session", "dirver" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Session/Manager/Json.php#L20-L28
ClanCats/Core
src/bundles/Session/Manager/Json.php
Manager_Json.write
public function write( $id, $data ) { \CCJson::write( $this->file_path( $id ), $data, true ); }
php
public function write( $id, $data ) { \CCJson::write( $this->file_path( $id ), $data, true ); }
[ "public", "function", "write", "(", "$", "id", ",", "$", "data", ")", "{", "\\", "CCJson", "::", "write", "(", "$", "this", "->", "file_path", "(", "$", "id", ")", ",", "$", "data", ",", "true", ")", ";", "}" ]
Check if a session with the given key already exists @param string $id The session id key. @param array $data @return bool
[ "Check", "if", "a", "session", "with", "the", "given", "key", "already", "exists" ]
train
https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Session/Manager/Json.php#L48-L51
loadsys/CakePHP-CreatorModifier
src/Model/Behavior/CreatorModifierBehavior.php
CreatorModifierBehavior.handleEvent
public function handleEvent(Event $event, Entity $entity) { $eventName = $event->name(); $events = $this->_config['events']; $new = $entity->isNew() !== false; foreach ($events[$eventName] as $field => $when) { if (!in_array($when, ['always', 'new', 'existing'])) { throw new UnexpectedValueException( sprintf('When should be one of "always", "new" or "existing". The passed value "%s" is invalid', $when) ); } if ($when === 'always' || ($when === 'new' && $new) || ($when === 'existing' && !$new) ) { $this->updateField($entity, $field); } } return true; }
php
public function handleEvent(Event $event, Entity $entity) { $eventName = $event->name(); $events = $this->_config['events']; $new = $entity->isNew() !== false; foreach ($events[$eventName] as $field => $when) { if (!in_array($when, ['always', 'new', 'existing'])) { throw new UnexpectedValueException( sprintf('When should be one of "always", "new" or "existing". The passed value "%s" is invalid', $when) ); } if ($when === 'always' || ($when === 'new' && $new) || ($when === 'existing' && !$new) ) { $this->updateField($entity, $field); } } return true; }
[ "public", "function", "handleEvent", "(", "Event", "$", "event", ",", "Entity", "$", "entity", ")", "{", "$", "eventName", "=", "$", "event", "->", "name", "(", ")", ";", "$", "events", "=", "$", "this", "->", "_config", "[", "'events'", "]", ";", "$", "new", "=", "$", "entity", "->", "isNew", "(", ")", "!==", "false", ";", "foreach", "(", "$", "events", "[", "$", "eventName", "]", "as", "$", "field", "=>", "$", "when", ")", "{", "if", "(", "!", "in_array", "(", "$", "when", ",", "[", "'always'", ",", "'new'", ",", "'existing'", "]", ")", ")", "{", "throw", "new", "UnexpectedValueException", "(", "sprintf", "(", "'When should be one of \"always\", \"new\" or \"existing\". The passed value \"%s\" is invalid'", ",", "$", "when", ")", ")", ";", "}", "if", "(", "$", "when", "===", "'always'", "||", "(", "$", "when", "===", "'new'", "&&", "$", "new", ")", "||", "(", "$", "when", "===", "'existing'", "&&", "!", "$", "new", ")", ")", "{", "$", "this", "->", "updateField", "(", "$", "entity", ",", "$", "field", ")", ";", "}", "}", "return", "true", ";", "}" ]
There is only one event handler, it can be configured to be called for any event @param \Cake\Event\Event $event Event instance. @param \Cake\ORM\Entity $entity Entity instance. @throws \UnexpectedValueException if a field's when value is misdefined @return true (irrespective of the behavior logic, the save will not be prevented) @throws \UnexpectedValueException When the value for an event is not 'always', 'new' or 'existing'
[ "There", "is", "only", "one", "event", "handler", "it", "can", "be", "configured", "to", "be", "called", "for", "any", "event" ]
train
https://github.com/loadsys/CakePHP-CreatorModifier/blob/42a87eda9413beff82b4eb9cab77d2d5bd5536a0/src/Model/Behavior/CreatorModifierBehavior.php#L78-L100
loadsys/CakePHP-CreatorModifier
src/Model/Behavior/CreatorModifierBehavior.php
CreatorModifierBehavior.createdOrModifed
public function createdOrModifed(Entity $entity, $eventName = 'Model.beforeSave') { $events = $this->_config['events']; if (empty($events[$eventName])) { return false; } $return = false; foreach ($events[$eventName] as $field => $when) { if (in_array($when, ['always', 'existing'])) { $return = true; $entity->dirty($field, false); $this->updateField($entity, $field); } } return $return; }
php
public function createdOrModifed(Entity $entity, $eventName = 'Model.beforeSave') { $events = $this->_config['events']; if (empty($events[$eventName])) { return false; } $return = false; foreach ($events[$eventName] as $field => $when) { if (in_array($when, ['always', 'existing'])) { $return = true; $entity->dirty($field, false); $this->updateField($entity, $field); } } return $return; }
[ "public", "function", "createdOrModifed", "(", "Entity", "$", "entity", ",", "$", "eventName", "=", "'Model.beforeSave'", ")", "{", "$", "events", "=", "$", "this", "->", "_config", "[", "'events'", "]", ";", "if", "(", "empty", "(", "$", "events", "[", "$", "eventName", "]", ")", ")", "{", "return", "false", ";", "}", "$", "return", "=", "false", ";", "foreach", "(", "$", "events", "[", "$", "eventName", "]", "as", "$", "field", "=>", "$", "when", ")", "{", "if", "(", "in_array", "(", "$", "when", ",", "[", "'always'", ",", "'existing'", "]", ")", ")", "{", "$", "return", "=", "true", ";", "$", "entity", "->", "dirty", "(", "$", "field", ",", "false", ")", ";", "$", "this", "->", "updateField", "(", "$", "entity", ",", "$", "field", ")", ";", "}", "}", "return", "$", "return", ";", "}" ]
Modifies the Creator/Modifier fields for the entity in the beforeSave callback. @param \Cake\ORM\Entity $entity Entity instance. @param string $eventName Event name. @return bool true if a field is updated, false if no action performed
[ "Modifies", "the", "Creator", "/", "Modifier", "fields", "for", "the", "entity", "in", "the", "beforeSave", "callback", "." ]
train
https://github.com/loadsys/CakePHP-CreatorModifier/blob/42a87eda9413beff82b4eb9cab77d2d5bd5536a0/src/Model/Behavior/CreatorModifierBehavior.php#L130-L147
loadsys/CakePHP-CreatorModifier
src/Model/Behavior/CreatorModifierBehavior.php
CreatorModifierBehavior.updateField
protected function updateField(Entity $entity, $field) { if ($entity->dirty($field)) { return; } $entity->set($field, $this->getUserId()); }
php
protected function updateField(Entity $entity, $field) { if ($entity->dirty($field)) { return; } $entity->set($field, $this->getUserId()); }
[ "protected", "function", "updateField", "(", "Entity", "$", "entity", ",", "$", "field", ")", "{", "if", "(", "$", "entity", "->", "dirty", "(", "$", "field", ")", ")", "{", "return", ";", "}", "$", "entity", "->", "set", "(", "$", "field", ",", "$", "this", "->", "getUserId", "(", ")", ")", ";", "}" ]
Update a field, if it hasn't been updated already @param \Cake\ORM\Entity $entity Entity instance. @param string $field Field name @return void
[ "Update", "a", "field", "if", "it", "hasn", "t", "been", "updated", "already" ]
train
https://github.com/loadsys/CakePHP-CreatorModifier/blob/42a87eda9413beff82b4eb9cab77d2d5bd5536a0/src/Model/Behavior/CreatorModifierBehavior.php#L156-L162
loadsys/CakePHP-CreatorModifier
src/Model/Behavior/CreatorModifierBehavior.php
CreatorModifierBehavior.sessionUserId
protected function sessionUserId() { $userId = null; $request = $this->newRequest(); if ($request->session()->started()) { $userId = $request->session()->read($this->_config['sessionUserIdKey']); } else { $this->log('The Session is not started. This typically means a User is not logged in. In this case there is no Session value for the currently active User and therefore we will set the `creator_id` and `modifier_id` to a null value. As a fallback, we are manually starting the session and reading the `$this->_config[sessionUserIdKey]` value, which is probably not correct.', 'debug'); try { $request->session()->start(); $userId = $request->session()->read($this->_config['sessionUserIdKey']); } catch (RuntimeException $e) { } } return $userId; }
php
protected function sessionUserId() { $userId = null; $request = $this->newRequest(); if ($request->session()->started()) { $userId = $request->session()->read($this->_config['sessionUserIdKey']); } else { $this->log('The Session is not started. This typically means a User is not logged in. In this case there is no Session value for the currently active User and therefore we will set the `creator_id` and `modifier_id` to a null value. As a fallback, we are manually starting the session and reading the `$this->_config[sessionUserIdKey]` value, which is probably not correct.', 'debug'); try { $request->session()->start(); $userId = $request->session()->read($this->_config['sessionUserIdKey']); } catch (RuntimeException $e) { } } return $userId; }
[ "protected", "function", "sessionUserId", "(", ")", "{", "$", "userId", "=", "null", ";", "$", "request", "=", "$", "this", "->", "newRequest", "(", ")", ";", "if", "(", "$", "request", "->", "session", "(", ")", "->", "started", "(", ")", ")", "{", "$", "userId", "=", "$", "request", "->", "session", "(", ")", "->", "read", "(", "$", "this", "->", "_config", "[", "'sessionUserIdKey'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "log", "(", "'The Session is not started. This typically means a User is not logged in. In this case there is no Session value for the currently active User and therefore we will set the `creator_id` and `modifier_id` to a null value. As a fallback, we are manually starting the session and reading the `$this->_config[sessionUserIdKey]` value, which is probably not correct.'", ",", "'debug'", ")", ";", "try", "{", "$", "request", "->", "session", "(", ")", "->", "start", "(", ")", ";", "$", "userId", "=", "$", "request", "->", "session", "(", ")", "->", "read", "(", "$", "this", "->", "_config", "[", "'sessionUserIdKey'", "]", ")", ";", "}", "catch", "(", "RuntimeException", "$", "e", ")", "{", "}", "}", "return", "$", "userId", ";", "}" ]
Return the User.id grabbed from the Session information. @return string The string representing the current logged in user.
[ "Return", "the", "User", ".", "id", "grabbed", "from", "the", "Session", "information", "." ]
train
https://github.com/loadsys/CakePHP-CreatorModifier/blob/42a87eda9413beff82b4eb9cab77d2d5bd5536a0/src/Model/Behavior/CreatorModifierBehavior.php#L169-L185
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed.php
Zend_Feed.lookupNamespace
public static function lookupNamespace($prefix) { return isset(self::$_namespaces[$prefix]) ? self::$_namespaces[$prefix] : $prefix; }
php
public static function lookupNamespace($prefix) { return isset(self::$_namespaces[$prefix]) ? self::$_namespaces[$prefix] : $prefix; }
[ "public", "static", "function", "lookupNamespace", "(", "$", "prefix", ")", "{", "return", "isset", "(", "self", "::", "$", "_namespaces", "[", "$", "prefix", "]", ")", "?", "self", "::", "$", "_namespaces", "[", "$", "prefix", "]", ":", "$", "prefix", ";", "}" ]
Get the full version of a namespace prefix Looks up a prefix (atom:, etc.) in the list of registered namespaces and returns the full namespace URI if available. Returns the prefix, unmodified, if it's not registered. @return string
[ "Get", "the", "full", "version", "of", "a", "namespace", "prefix" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed.php#L135-L140
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed.php
Zend_Feed.import
public static function import($uri) { $client = self::getHttpClient(); $client->setUri($uri); $response = $client->request('GET'); if ($response->getStatus() !== 200) { /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus()); } $feed = $response->getBody(); return self::importString($feed); }
php
public static function import($uri) { $client = self::getHttpClient(); $client->setUri($uri); $response = $client->request('GET'); if ($response->getStatus() !== 200) { /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception('Feed failed to load, got response code ' . $response->getStatus()); } $feed = $response->getBody(); return self::importString($feed); }
[ "public", "static", "function", "import", "(", "$", "uri", ")", "{", "$", "client", "=", "self", "::", "getHttpClient", "(", ")", ";", "$", "client", "->", "setUri", "(", "$", "uri", ")", ";", "$", "response", "=", "$", "client", "->", "request", "(", "'GET'", ")", ";", "if", "(", "$", "response", "->", "getStatus", "(", ")", "!==", "200", ")", "{", "/**\n * @see Zend_Feed_Exception\n */", "require_once", "'Zend/Feed/Exception.php'", ";", "throw", "new", "Zend_Feed_Exception", "(", "'Feed failed to load, got response code '", ".", "$", "response", "->", "getStatus", "(", ")", ")", ";", "}", "$", "feed", "=", "$", "response", "->", "getBody", "(", ")", ";", "return", "self", "::", "importString", "(", "$", "feed", ")", ";", "}" ]
Imports a feed located at $uri. @param string $uri @throws Zend_Feed_Exception @return Zend_Feed_Abstract
[ "Imports", "a", "feed", "located", "at", "$uri", "." ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed.php#L167-L181
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed.php
Zend_Feed.importString
public static function importString($string) { // Load the feed as an XML DOMDocument object @ini_set('track_errors', 1); $doc = new DOMDocument; $status = @$doc->loadXML($string); @ini_restore('track_errors'); if (!$status) { // prevent the class to generate an undefined variable notice (ZF-2590) if (!isset($php_errormsg)) { if (function_exists('xdebug_is_enabled')) { $php_errormsg = '(error message not available, when XDebug is running)'; } else { $php_errormsg = '(error message not available)'; } } /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg"); } // Try to find the base feed element or a single <entry> of an Atom feed if ($doc->getElementsByTagName('feed')->item(0) || $doc->getElementsByTagName('entry')->item(0)) { /** * @see Zend_Feed_Atom */ require_once 'Zend/Feed/Atom.php'; // return a newly created Zend_Feed_Atom object return new Zend_Feed_Atom(null, $string); } // Try to find the base feed element of an RSS feed if ($doc->getElementsByTagName('channel')->item(0)) { /** * @see Zend_Feed_Rss */ require_once 'Zend/Feed/Rss.php'; // return a newly created Zend_Feed_Rss object return new Zend_Feed_Rss(null, $string); } // $string does not appear to be a valid feed of the supported types /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception('Invalid or unsupported feed format'); }
php
public static function importString($string) { // Load the feed as an XML DOMDocument object @ini_set('track_errors', 1); $doc = new DOMDocument; $status = @$doc->loadXML($string); @ini_restore('track_errors'); if (!$status) { // prevent the class to generate an undefined variable notice (ZF-2590) if (!isset($php_errormsg)) { if (function_exists('xdebug_is_enabled')) { $php_errormsg = '(error message not available, when XDebug is running)'; } else { $php_errormsg = '(error message not available)'; } } /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception("DOMDocument cannot parse XML: $php_errormsg"); } // Try to find the base feed element or a single <entry> of an Atom feed if ($doc->getElementsByTagName('feed')->item(0) || $doc->getElementsByTagName('entry')->item(0)) { /** * @see Zend_Feed_Atom */ require_once 'Zend/Feed/Atom.php'; // return a newly created Zend_Feed_Atom object return new Zend_Feed_Atom(null, $string); } // Try to find the base feed element of an RSS feed if ($doc->getElementsByTagName('channel')->item(0)) { /** * @see Zend_Feed_Rss */ require_once 'Zend/Feed/Rss.php'; // return a newly created Zend_Feed_Rss object return new Zend_Feed_Rss(null, $string); } // $string does not appear to be a valid feed of the supported types /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception('Invalid or unsupported feed format'); }
[ "public", "static", "function", "importString", "(", "$", "string", ")", "{", "// Load the feed as an XML DOMDocument object", "@", "ini_set", "(", "'track_errors'", ",", "1", ")", ";", "$", "doc", "=", "new", "DOMDocument", ";", "$", "status", "=", "@", "$", "doc", "->", "loadXML", "(", "$", "string", ")", ";", "@", "ini_restore", "(", "'track_errors'", ")", ";", "if", "(", "!", "$", "status", ")", "{", "// prevent the class to generate an undefined variable notice (ZF-2590)", "if", "(", "!", "isset", "(", "$", "php_errormsg", ")", ")", "{", "if", "(", "function_exists", "(", "'xdebug_is_enabled'", ")", ")", "{", "$", "php_errormsg", "=", "'(error message not available, when XDebug is running)'", ";", "}", "else", "{", "$", "php_errormsg", "=", "'(error message not available)'", ";", "}", "}", "/**\n * @see Zend_Feed_Exception\n */", "require_once", "'Zend/Feed/Exception.php'", ";", "throw", "new", "Zend_Feed_Exception", "(", "\"DOMDocument cannot parse XML: $php_errormsg\"", ")", ";", "}", "// Try to find the base feed element or a single <entry> of an Atom feed", "if", "(", "$", "doc", "->", "getElementsByTagName", "(", "'feed'", ")", "->", "item", "(", "0", ")", "||", "$", "doc", "->", "getElementsByTagName", "(", "'entry'", ")", "->", "item", "(", "0", ")", ")", "{", "/**\n * @see Zend_Feed_Atom\n */", "require_once", "'Zend/Feed/Atom.php'", ";", "// return a newly created Zend_Feed_Atom object", "return", "new", "Zend_Feed_Atom", "(", "null", ",", "$", "string", ")", ";", "}", "// Try to find the base feed element of an RSS feed", "if", "(", "$", "doc", "->", "getElementsByTagName", "(", "'channel'", ")", "->", "item", "(", "0", ")", ")", "{", "/**\n * @see Zend_Feed_Rss\n */", "require_once", "'Zend/Feed/Rss.php'", ";", "// return a newly created Zend_Feed_Rss object", "return", "new", "Zend_Feed_Rss", "(", "null", ",", "$", "string", ")", ";", "}", "// $string does not appear to be a valid feed of the supported types", "/**\n * @see Zend_Feed_Exception\n */", "require_once", "'Zend/Feed/Exception.php'", ";", "throw", "new", "Zend_Feed_Exception", "(", "'Invalid or unsupported feed format'", ")", ";", "}" ]
Imports a feed represented by $string. @param string $string @throws Zend_Feed_Exception @return Zend_Feed_Abstract
[ "Imports", "a", "feed", "represented", "by", "$string", "." ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed.php#L191-L243
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed.php
Zend_Feed.importFile
public static function importFile($filename) { @ini_set('track_errors', 1); $feed = @file_get_contents($filename); @ini_restore('track_errors'); if ($feed === false) { /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception("File could not be loaded: $php_errormsg"); } return self::importString($feed); }
php
public static function importFile($filename) { @ini_set('track_errors', 1); $feed = @file_get_contents($filename); @ini_restore('track_errors'); if ($feed === false) { /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception("File could not be loaded: $php_errormsg"); } return self::importString($feed); }
[ "public", "static", "function", "importFile", "(", "$", "filename", ")", "{", "@", "ini_set", "(", "'track_errors'", ",", "1", ")", ";", "$", "feed", "=", "@", "file_get_contents", "(", "$", "filename", ")", ";", "@", "ini_restore", "(", "'track_errors'", ")", ";", "if", "(", "$", "feed", "===", "false", ")", "{", "/**\n * @see Zend_Feed_Exception\n */", "require_once", "'Zend/Feed/Exception.php'", ";", "throw", "new", "Zend_Feed_Exception", "(", "\"File could not be loaded: $php_errormsg\"", ")", ";", "}", "return", "self", "::", "importString", "(", "$", "feed", ")", ";", "}" ]
Imports a feed from a file located at $filename. @param string $filename @throws Zend_Feed_Exception @return Zend_Feed_Abstract
[ "Imports", "a", "feed", "from", "a", "file", "located", "at", "$filename", "." ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed.php#L253-L266
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed.php
Zend_Feed.findFeeds
public static function findFeeds($uri) { // Get the HTTP response from $uri and save the contents $client = self::getHttpClient(); $client->setUri($uri); $response = $client->request(); if ($response->getStatus() !== 200) { /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception("Failed to access $uri, got response code " . $response->getStatus()); } $contents = $response->getBody(); // Parse the contents for appropriate <link ... /> tags @ini_set('track_errors', 1); $pattern = '~(<link[^>]+)/?>~i'; $result = @preg_match_all($pattern, $contents, $matches); @ini_restore('track_errors'); if ($result === false) { /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception("Internal error: $php_errormsg"); } // Try to fetch a feed for each link tag that appears to refer to a feed $feeds = array(); if (isset($matches[1]) && count($matches[1]) > 0) { foreach ($matches[1] as $link) { // force string to be an utf-8 one if (!mb_check_encoding($link, 'UTF-8')) { $link = mb_convert_encoding($link, 'UTF-8'); } $xml = @simplexml_load_string(rtrim($link, ' /') . ' />'); if ($xml === false) { continue; } $attributes = $xml->attributes(); if (!isset($attributes['rel']) || !@preg_match('~^(?:alternate|service\.feed)~i', $attributes['rel'])) { continue; } if (!isset($attributes['type']) || !@preg_match('~^application/(?:atom|rss|rdf)\+xml~', $attributes['type'])) { continue; } if (!isset($attributes['href'])) { continue; } try { // checks if we need to canonize the given uri try { $uri = Zend_Uri::factory((string) $attributes['href']); } catch (Zend_Uri_Exception $e) { // canonize the uri $path = (string) $attributes['href']; $query = $fragment = ''; if (substr($path, 0, 1) != '/') { // add the current root path to this one $path = rtrim($client->getUri()->getPath(), '/') . '/' . $path; } if (strpos($path, '?') !== false) { list($path, $query) = explode('?', $path, 2); } if (strpos($query, '#') !== false) { list($query, $fragment) = explode('#', $query, 2); } $uri = Zend_Uri::factory($client->getUri(true)); $uri->setPath($path); $uri->setQuery($query); $uri->setFragment($fragment); } $feed = self::import($uri); } catch (Exception $e) { continue; } $feeds[] = $feed; } } // Return the fetched feeds return $feeds; }
php
public static function findFeeds($uri) { // Get the HTTP response from $uri and save the contents $client = self::getHttpClient(); $client->setUri($uri); $response = $client->request(); if ($response->getStatus() !== 200) { /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception("Failed to access $uri, got response code " . $response->getStatus()); } $contents = $response->getBody(); // Parse the contents for appropriate <link ... /> tags @ini_set('track_errors', 1); $pattern = '~(<link[^>]+)/?>~i'; $result = @preg_match_all($pattern, $contents, $matches); @ini_restore('track_errors'); if ($result === false) { /** * @see Zend_Feed_Exception */ require_once 'Zend/Feed/Exception.php'; throw new Zend_Feed_Exception("Internal error: $php_errormsg"); } // Try to fetch a feed for each link tag that appears to refer to a feed $feeds = array(); if (isset($matches[1]) && count($matches[1]) > 0) { foreach ($matches[1] as $link) { // force string to be an utf-8 one if (!mb_check_encoding($link, 'UTF-8')) { $link = mb_convert_encoding($link, 'UTF-8'); } $xml = @simplexml_load_string(rtrim($link, ' /') . ' />'); if ($xml === false) { continue; } $attributes = $xml->attributes(); if (!isset($attributes['rel']) || !@preg_match('~^(?:alternate|service\.feed)~i', $attributes['rel'])) { continue; } if (!isset($attributes['type']) || !@preg_match('~^application/(?:atom|rss|rdf)\+xml~', $attributes['type'])) { continue; } if (!isset($attributes['href'])) { continue; } try { // checks if we need to canonize the given uri try { $uri = Zend_Uri::factory((string) $attributes['href']); } catch (Zend_Uri_Exception $e) { // canonize the uri $path = (string) $attributes['href']; $query = $fragment = ''; if (substr($path, 0, 1) != '/') { // add the current root path to this one $path = rtrim($client->getUri()->getPath(), '/') . '/' . $path; } if (strpos($path, '?') !== false) { list($path, $query) = explode('?', $path, 2); } if (strpos($query, '#') !== false) { list($query, $fragment) = explode('#', $query, 2); } $uri = Zend_Uri::factory($client->getUri(true)); $uri->setPath($path); $uri->setQuery($query); $uri->setFragment($fragment); } $feed = self::import($uri); } catch (Exception $e) { continue; } $feeds[] = $feed; } } // Return the fetched feeds return $feeds; }
[ "public", "static", "function", "findFeeds", "(", "$", "uri", ")", "{", "// Get the HTTP response from $uri and save the contents", "$", "client", "=", "self", "::", "getHttpClient", "(", ")", ";", "$", "client", "->", "setUri", "(", "$", "uri", ")", ";", "$", "response", "=", "$", "client", "->", "request", "(", ")", ";", "if", "(", "$", "response", "->", "getStatus", "(", ")", "!==", "200", ")", "{", "/**\n * @see Zend_Feed_Exception\n */", "require_once", "'Zend/Feed/Exception.php'", ";", "throw", "new", "Zend_Feed_Exception", "(", "\"Failed to access $uri, got response code \"", ".", "$", "response", "->", "getStatus", "(", ")", ")", ";", "}", "$", "contents", "=", "$", "response", "->", "getBody", "(", ")", ";", "// Parse the contents for appropriate <link ... /> tags", "@", "ini_set", "(", "'track_errors'", ",", "1", ")", ";", "$", "pattern", "=", "'~(<link[^>]+)/?>~i'", ";", "$", "result", "=", "@", "preg_match_all", "(", "$", "pattern", ",", "$", "contents", ",", "$", "matches", ")", ";", "@", "ini_restore", "(", "'track_errors'", ")", ";", "if", "(", "$", "result", "===", "false", ")", "{", "/**\n * @see Zend_Feed_Exception\n */", "require_once", "'Zend/Feed/Exception.php'", ";", "throw", "new", "Zend_Feed_Exception", "(", "\"Internal error: $php_errormsg\"", ")", ";", "}", "// Try to fetch a feed for each link tag that appears to refer to a feed", "$", "feeds", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "matches", "[", "1", "]", ")", "&&", "count", "(", "$", "matches", "[", "1", "]", ")", ">", "0", ")", "{", "foreach", "(", "$", "matches", "[", "1", "]", "as", "$", "link", ")", "{", "// force string to be an utf-8 one", "if", "(", "!", "mb_check_encoding", "(", "$", "link", ",", "'UTF-8'", ")", ")", "{", "$", "link", "=", "mb_convert_encoding", "(", "$", "link", ",", "'UTF-8'", ")", ";", "}", "$", "xml", "=", "@", "simplexml_load_string", "(", "rtrim", "(", "$", "link", ",", "' /'", ")", ".", "' />'", ")", ";", "if", "(", "$", "xml", "===", "false", ")", "{", "continue", ";", "}", "$", "attributes", "=", "$", "xml", "->", "attributes", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "attributes", "[", "'rel'", "]", ")", "||", "!", "@", "preg_match", "(", "'~^(?:alternate|service\\.feed)~i'", ",", "$", "attributes", "[", "'rel'", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "isset", "(", "$", "attributes", "[", "'type'", "]", ")", "||", "!", "@", "preg_match", "(", "'~^application/(?:atom|rss|rdf)\\+xml~'", ",", "$", "attributes", "[", "'type'", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "isset", "(", "$", "attributes", "[", "'href'", "]", ")", ")", "{", "continue", ";", "}", "try", "{", "// checks if we need to canonize the given uri", "try", "{", "$", "uri", "=", "Zend_Uri", "::", "factory", "(", "(", "string", ")", "$", "attributes", "[", "'href'", "]", ")", ";", "}", "catch", "(", "Zend_Uri_Exception", "$", "e", ")", "{", "// canonize the uri", "$", "path", "=", "(", "string", ")", "$", "attributes", "[", "'href'", "]", ";", "$", "query", "=", "$", "fragment", "=", "''", ";", "if", "(", "substr", "(", "$", "path", ",", "0", ",", "1", ")", "!=", "'/'", ")", "{", "// add the current root path to this one", "$", "path", "=", "rtrim", "(", "$", "client", "->", "getUri", "(", ")", "->", "getPath", "(", ")", ",", "'/'", ")", ".", "'/'", ".", "$", "path", ";", "}", "if", "(", "strpos", "(", "$", "path", ",", "'?'", ")", "!==", "false", ")", "{", "list", "(", "$", "path", ",", "$", "query", ")", "=", "explode", "(", "'?'", ",", "$", "path", ",", "2", ")", ";", "}", "if", "(", "strpos", "(", "$", "query", ",", "'#'", ")", "!==", "false", ")", "{", "list", "(", "$", "query", ",", "$", "fragment", ")", "=", "explode", "(", "'#'", ",", "$", "query", ",", "2", ")", ";", "}", "$", "uri", "=", "Zend_Uri", "::", "factory", "(", "$", "client", "->", "getUri", "(", "true", ")", ")", ";", "$", "uri", "->", "setPath", "(", "$", "path", ")", ";", "$", "uri", "->", "setQuery", "(", "$", "query", ")", ";", "$", "uri", "->", "setFragment", "(", "$", "fragment", ")", ";", "}", "$", "feed", "=", "self", "::", "import", "(", "$", "uri", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "continue", ";", "}", "$", "feeds", "[", "]", "=", "$", "feed", ";", "}", "}", "// Return the fetched feeds", "return", "$", "feeds", ";", "}" ]
Attempts to find feeds at $uri referenced by <link ... /> tags. Returns an array of the feeds referenced at $uri. @todo Allow findFeeds() to follow one, but only one, code 302. @param string $uri @throws Zend_Feed_Exception @return array
[ "Attempts", "to", "find", "feeds", "at", "$uri", "referenced", "by", "<link", "...", "/", ">", "tags", ".", "Returns", "an", "array", "of", "the", "feeds", "referenced", "at", "$uri", "." ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed.php#L279-L364
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed.php
Zend_Feed.importArray
public static function importArray(array $data, $format = 'atom') { $obj = 'Zend_Feed_' . ucfirst(strtolower($format)); /** * @see Zend_Loader */ require_once 'Zend/Loader.php'; Zend_Loader::loadClass($obj); /** * @see Zend_Feed_Builder */ require_once 'Zend/Feed/Builder.php'; return new $obj(null, null, new Zend_Feed_Builder($data)); }
php
public static function importArray(array $data, $format = 'atom') { $obj = 'Zend_Feed_' . ucfirst(strtolower($format)); /** * @see Zend_Loader */ require_once 'Zend/Loader.php'; Zend_Loader::loadClass($obj); /** * @see Zend_Feed_Builder */ require_once 'Zend/Feed/Builder.php'; return new $obj(null, null, new Zend_Feed_Builder($data)); }
[ "public", "static", "function", "importArray", "(", "array", "$", "data", ",", "$", "format", "=", "'atom'", ")", "{", "$", "obj", "=", "'Zend_Feed_'", ".", "ucfirst", "(", "strtolower", "(", "$", "format", ")", ")", ";", "/**\n * @see Zend_Loader\n */", "require_once", "'Zend/Loader.php'", ";", "Zend_Loader", "::", "loadClass", "(", "$", "obj", ")", ";", "/**\n * @see Zend_Feed_Builder\n */", "require_once", "'Zend/Feed/Builder.php'", ";", "return", "new", "$", "obj", "(", "null", ",", "null", ",", "new", "Zend_Feed_Builder", "(", "$", "data", ")", ")", ";", "}" ]
Construct a new Zend_Feed_Abstract object from a custom array @param array $data @param string $format (rss|atom) the requested output format @return Zend_Feed_Abstract
[ "Construct", "a", "new", "Zend_Feed_Abstract", "object", "from", "a", "custom", "array" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed.php#L373-L386
nyeholt/silverstripe-external-content
thirdparty/Zend/Feed.php
Zend_Feed.importBuilder
public static function importBuilder(Zend_Feed_Builder_Interface $builder, $format = 'atom') { $obj = 'Zend_Feed_' . ucfirst(strtolower($format)); /** * @see Zend_Loader */ require_once 'Zend/Loader.php'; Zend_Loader::loadClass($obj); return new $obj(null, null, $builder); }
php
public static function importBuilder(Zend_Feed_Builder_Interface $builder, $format = 'atom') { $obj = 'Zend_Feed_' . ucfirst(strtolower($format)); /** * @see Zend_Loader */ require_once 'Zend/Loader.php'; Zend_Loader::loadClass($obj); return new $obj(null, null, $builder); }
[ "public", "static", "function", "importBuilder", "(", "Zend_Feed_Builder_Interface", "$", "builder", ",", "$", "format", "=", "'atom'", ")", "{", "$", "obj", "=", "'Zend_Feed_'", ".", "ucfirst", "(", "strtolower", "(", "$", "format", ")", ")", ";", "/**\n * @see Zend_Loader\n */", "require_once", "'Zend/Loader.php'", ";", "Zend_Loader", "::", "loadClass", "(", "$", "obj", ")", ";", "return", "new", "$", "obj", "(", "null", ",", "null", ",", "$", "builder", ")", ";", "}" ]
Construct a new Zend_Feed_Abstract object from a Zend_Feed_Builder_Interface data source @param Zend_Feed_Builder_Interface $builder this object will be used to extract the data of the feed @param string $format (rss|atom) the requested output format @return Zend_Feed_Abstract
[ "Construct", "a", "new", "Zend_Feed_Abstract", "object", "from", "a", "Zend_Feed_Builder_Interface", "data", "source" ]
train
https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Feed.php#L395-L405
inpsyde/inpsyde-filter
src/WordPress/NormalizeWhitespace.php
NormalizeWhitespace.filter
public function filter( $value ) { if ( ! is_string( $value ) || empty( $value ) ) { do_action( 'inpsyde.filter.error', 'The given value is not a string or empty.', [ 'method' => __METHOD__, 'value' => $value ] ); return $value; } return normalize_whitespace( $value ); }
php
public function filter( $value ) { if ( ! is_string( $value ) || empty( $value ) ) { do_action( 'inpsyde.filter.error', 'The given value is not a string or empty.', [ 'method' => __METHOD__, 'value' => $value ] ); return $value; } return normalize_whitespace( $value ); }
[ "public", "function", "filter", "(", "$", "value", ")", "{", "if", "(", "!", "is_string", "(", "$", "value", ")", "||", "empty", "(", "$", "value", ")", ")", "{", "do_action", "(", "'inpsyde.filter.error'", ",", "'The given value is not a string or empty.'", ",", "[", "'method'", "=>", "__METHOD__", ",", "'value'", "=>", "$", "value", "]", ")", ";", "return", "$", "value", ";", "}", "return", "normalize_whitespace", "(", "$", "value", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/inpsyde/inpsyde-filter/blob/777a6208ea4dfbeed89e6d0712a35dc25eab498b/src/WordPress/NormalizeWhitespace.php#L18-L27
zodream/thirdparty
src/Pay/AliPay.php
AliPay.encrypt
protected function encrypt($str){ //AES, 128 模式加密数据 CBC $screct_key = base64_decode($this->key); $str = trim($str); $str = $this->addPKCS7Padding($str); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), 1); $encrypt_str = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_CBC); return base64_encode($encrypt_str); }
php
protected function encrypt($str){ //AES, 128 模式加密数据 CBC $screct_key = base64_decode($this->key); $str = trim($str); $str = $this->addPKCS7Padding($str); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), 1); $encrypt_str = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_CBC); return base64_encode($encrypt_str); }
[ "protected", "function", "encrypt", "(", "$", "str", ")", "{", "//AES, 128 模式加密数据 CBC", "$", "screct_key", "=", "base64_decode", "(", "$", "this", "->", "key", ")", ";", "$", "str", "=", "trim", "(", "$", "str", ")", ";", "$", "str", "=", "$", "this", "->", "addPKCS7Padding", "(", "$", "str", ")", ";", "$", "iv", "=", "mcrypt_create_iv", "(", "mcrypt_get_iv_size", "(", "MCRYPT_RIJNDAEL_128", ",", "MCRYPT_MODE_CBC", ")", ",", "1", ")", ";", "$", "encrypt_str", "=", "mcrypt_encrypt", "(", "MCRYPT_RIJNDAEL_128", ",", "$", "screct_key", ",", "$", "str", ",", "MCRYPT_MODE_CBC", ")", ";", "return", "base64_encode", "(", "$", "encrypt_str", ")", ";", "}" ]
加密方法 @param string $str @return string
[ "加密方法" ]
train
https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/Pay/AliPay.php#L298-L306
zodream/thirdparty
src/Pay/AliPay.php
AliPay.decrypt
function decrypt($str){ //AES, 128 模式加密数据 CBC $str = base64_decode($str); $screct_key = base64_decode($this->key); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), 1); $encrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_CBC); $encrypt_str = trim($encrypt_str); $encrypt_str = stripPKSC7Padding($encrypt_str); return $encrypt_str; }
php
function decrypt($str){ //AES, 128 模式加密数据 CBC $str = base64_decode($str); $screct_key = base64_decode($this->key); $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), 1); $encrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_CBC); $encrypt_str = trim($encrypt_str); $encrypt_str = stripPKSC7Padding($encrypt_str); return $encrypt_str; }
[ "function", "decrypt", "(", "$", "str", ")", "{", "//AES, 128 模式加密数据 CBC", "$", "str", "=", "base64_decode", "(", "$", "str", ")", ";", "$", "screct_key", "=", "base64_decode", "(", "$", "this", "->", "key", ")", ";", "$", "iv", "=", "mcrypt_create_iv", "(", "mcrypt_get_iv_size", "(", "MCRYPT_RIJNDAEL_128", ",", "MCRYPT_MODE_CBC", ")", ",", "1", ")", ";", "$", "encrypt_str", "=", "mcrypt_decrypt", "(", "MCRYPT_RIJNDAEL_128", ",", "$", "screct_key", ",", "$", "str", ",", "MCRYPT_MODE_CBC", ")", ";", "$", "encrypt_str", "=", "trim", "(", "$", "encrypt_str", ")", ";", "$", "encrypt_str", "=", "stripPKSC7Padding", "(", "$", "encrypt_str", ")", ";", "return", "$", "encrypt_str", ";", "}" ]
解密方法 @param string $str @return string
[ "解密方法" ]
train
https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/Pay/AliPay.php#L313-L324
zodream/thirdparty
src/Pay/AliPay.php
AliPay.addPKCS7Padding
protected function addPKCS7Padding($source){ $source = trim($source); $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $pad = $block - (strlen($source) % $block); if ($pad <= $block) { $char = chr($pad); $source .= str_repeat($char, $pad); } return $source; }
php
protected function addPKCS7Padding($source){ $source = trim($source); $block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); $pad = $block - (strlen($source) % $block); if ($pad <= $block) { $char = chr($pad); $source .= str_repeat($char, $pad); } return $source; }
[ "protected", "function", "addPKCS7Padding", "(", "$", "source", ")", "{", "$", "source", "=", "trim", "(", "$", "source", ")", ";", "$", "block", "=", "mcrypt_get_block_size", "(", "MCRYPT_RIJNDAEL_128", ",", "MCRYPT_MODE_CBC", ")", ";", "$", "pad", "=", "$", "block", "-", "(", "strlen", "(", "$", "source", ")", "%", "$", "block", ")", ";", "if", "(", "$", "pad", "<=", "$", "block", ")", "{", "$", "char", "=", "chr", "(", "$", "pad", ")", ";", "$", "source", ".=", "str_repeat", "(", "$", "char", ",", "$", "pad", ")", ";", "}", "return", "$", "source", ";", "}" ]
填充算法 @param string $source @return string
[ "填充算法" ]
train
https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/Pay/AliPay.php#L331-L341
zodream/thirdparty
src/Pay/AliPay.php
AliPay.stripPKSC7Padding
protected function stripPKSC7Padding($source){ $source = trim($source); $char = substr($source, -1); $num = ord($char); if($num==62)return $source; $source = substr($source,0,-$num); return $source; }
php
protected function stripPKSC7Padding($source){ $source = trim($source); $char = substr($source, -1); $num = ord($char); if($num==62)return $source; $source = substr($source,0,-$num); return $source; }
[ "protected", "function", "stripPKSC7Padding", "(", "$", "source", ")", "{", "$", "source", "=", "trim", "(", "$", "source", ")", ";", "$", "char", "=", "substr", "(", "$", "source", ",", "-", "1", ")", ";", "$", "num", "=", "ord", "(", "$", "char", ")", ";", "if", "(", "$", "num", "==", "62", ")", "return", "$", "source", ";", "$", "source", "=", "substr", "(", "$", "source", ",", "0", ",", "-", "$", "num", ")", ";", "return", "$", "source", ";", "}" ]
移去填充算法 @param string $source @return string
[ "移去填充算法" ]
train
https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/Pay/AliPay.php#L347-L354
zodream/thirdparty
src/Pay/AliPay.php
AliPay.sign
public function sign($content) { if (is_array($content)) { $content = $this->getSignContent($content); } if ($this->signType == self::MD5 || empty($this->privateKeyFile)) { return md5($content.$this->key); } if ($this->signType != self::RSA && $this->signType != self::RSA2) { return null; } $res = $this->getPrivateKeyResource(); if (empty($res)) { throw new Exception('RSA私钥错误'); } openssl_sign($content, $sign, $res, $this->signType == self::RSA ? OPENSSL_ALGO_SHA1 : OPENSSL_ALGO_SHA256); if (is_resource($res)) { openssl_free_key($res); } //base64编码 return base64_encode($sign); }
php
public function sign($content) { if (is_array($content)) { $content = $this->getSignContent($content); } if ($this->signType == self::MD5 || empty($this->privateKeyFile)) { return md5($content.$this->key); } if ($this->signType != self::RSA && $this->signType != self::RSA2) { return null; } $res = $this->getPrivateKeyResource(); if (empty($res)) { throw new Exception('RSA私钥错误'); } openssl_sign($content, $sign, $res, $this->signType == self::RSA ? OPENSSL_ALGO_SHA1 : OPENSSL_ALGO_SHA256); if (is_resource($res)) { openssl_free_key($res); } //base64编码 return base64_encode($sign); }
[ "public", "function", "sign", "(", "$", "content", ")", "{", "if", "(", "is_array", "(", "$", "content", ")", ")", "{", "$", "content", "=", "$", "this", "->", "getSignContent", "(", "$", "content", ")", ";", "}", "if", "(", "$", "this", "->", "signType", "==", "self", "::", "MD5", "||", "empty", "(", "$", "this", "->", "privateKeyFile", ")", ")", "{", "return", "md5", "(", "$", "content", ".", "$", "this", "->", "key", ")", ";", "}", "if", "(", "$", "this", "->", "signType", "!=", "self", "::", "RSA", "&&", "$", "this", "->", "signType", "!=", "self", "::", "RSA2", ")", "{", "return", "null", ";", "}", "$", "res", "=", "$", "this", "->", "getPrivateKeyResource", "(", ")", ";", "if", "(", "empty", "(", "$", "res", ")", ")", "{", "throw", "new", "Exception", "(", "'RSA私钥错误');", "", "", "}", "openssl_sign", "(", "$", "content", ",", "$", "sign", ",", "$", "res", ",", "$", "this", "->", "signType", "==", "self", "::", "RSA", "?", "OPENSSL_ALGO_SHA1", ":", "OPENSSL_ALGO_SHA256", ")", ";", "if", "(", "is_resource", "(", "$", "res", ")", ")", "{", "openssl_free_key", "(", "$", "res", ")", ";", "}", "//base64编码", "return", "base64_encode", "(", "$", "sign", ")", ";", "}" ]
生成请求参数的签名 @param string|array $content @return string @throws Exception
[ "生成请求参数的签名" ]
train
https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/Pay/AliPay.php#L402-L425
zodream/thirdparty
src/Pay/AliPay.php
AliPay.queryOrder
public function queryOrder(array $args = array()) { $args = $this->getQuery()->parameters($this->merge($args))->json(); if (!array_key_exists('alipay_trade_query_response', $args)) { throw new \Exception('未知错误!'); } $args = $args['alipay_trade_query_response']; if ($args['code'] != 10000) { throw new \Exception($args['msg']); } if (!$this->verify($args)) { throw new \Exception('数据验签失败!'); } return $args; }
php
public function queryOrder(array $args = array()) { $args = $this->getQuery()->parameters($this->merge($args))->json(); if (!array_key_exists('alipay_trade_query_response', $args)) { throw new \Exception('未知错误!'); } $args = $args['alipay_trade_query_response']; if ($args['code'] != 10000) { throw new \Exception($args['msg']); } if (!$this->verify($args)) { throw new \Exception('数据验签失败!'); } return $args; }
[ "public", "function", "queryOrder", "(", "array", "$", "args", "=", "array", "(", ")", ")", "{", "$", "args", "=", "$", "this", "->", "getQuery", "(", ")", "->", "parameters", "(", "$", "this", "->", "merge", "(", "$", "args", ")", ")", "->", "json", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "'alipay_trade_query_response'", ",", "$", "args", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'未知错误!');", "", "", "}", "$", "args", "=", "$", "args", "[", "'alipay_trade_query_response'", "]", ";", "if", "(", "$", "args", "[", "'code'", "]", "!=", "10000", ")", "{", "throw", "new", "\\", "Exception", "(", "$", "args", "[", "'msg'", "]", ")", ";", "}", "if", "(", "!", "$", "this", "->", "verify", "(", "$", "args", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'数据验签失败!');", "", "", "}", "return", "$", "args", ";", "}" ]
查询接口 EXMAPLE: [ 'timestamp' => date('Y-m-d H:i:s'), 'out_trade_no' => '' ] @param array $args @return array|bool|mixed @throws \Exception
[ "查询接口", "EXMAPLE", ":", "[", "timestamp", "=", ">", "date", "(", "Y", "-", "m", "-", "d", "H", ":", "i", ":", "s", ")", "out_trade_no", "=", ">", "]" ]
train
https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/Pay/AliPay.php#L517-L530
zodream/thirdparty
src/Pay/AliPay.php
AliPay.encodeContent
protected function encodeContent(array $args) { $data = []; foreach ($args as $key => $item) { $data[] = sprintf('"%s"="%s"', $key, $item); } return '{'.implode(',', $data).'}'; }
php
protected function encodeContent(array $args) { $data = []; foreach ($args as $key => $item) { $data[] = sprintf('"%s"="%s"', $key, $item); } return '{'.implode(',', $data).'}'; }
[ "protected", "function", "encodeContent", "(", "array", "$", "args", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "args", "as", "$", "key", "=>", "$", "item", ")", "{", "$", "data", "[", "]", "=", "sprintf", "(", "'\"%s\"=\"%s\"'", ",", "$", "key", ",", "$", "item", ")", ";", "}", "return", "'{'", ".", "implode", "(", "','", ",", "$", "data", ")", ".", "'}'", ";", "}" ]
合并biz_content @param array $args @return string
[ "合并biz_content" ]
train
https://github.com/zodream/thirdparty/blob/b9d39087913850f1c5c7c9165105fec22a128f8f/src/Pay/AliPay.php#L546-L552
yuncms/framework
src/web/Controller.php
Controller.asJsonP
public function asJsonP($data): YiiResponse { $response = Yii::$app->getResponse(); $response->data = $data; $response->format = YiiResponse::FORMAT_JSONP; return $response; }
php
public function asJsonP($data): YiiResponse { $response = Yii::$app->getResponse(); $response->data = $data; $response->format = YiiResponse::FORMAT_JSONP; return $response; }
[ "public", "function", "asJsonP", "(", "$", "data", ")", ":", "YiiResponse", "{", "$", "response", "=", "Yii", "::", "$", "app", "->", "getResponse", "(", ")", ";", "$", "response", "->", "data", "=", "$", "data", ";", "$", "response", "->", "format", "=", "YiiResponse", "::", "FORMAT_JSONP", ";", "return", "$", "response", ";", "}" ]
Sets the response format of the given data as JSONP. @param mixed $data The data that should be formatted. @return Response A response that is configured to send `$data` formatted as JSON. @see YiiResponse::$format @see YiiResponse::FORMAT_JSONP @see JsonResponseFormatter
[ "Sets", "the", "response", "format", "of", "the", "given", "data", "as", "JSONP", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/Controller.php#L33-L39
yuncms/framework
src/web/Controller.php
Controller.asRaw
public function asRaw($data): YiiResponse { $response = Yii::$app->getResponse(); $response->data = $data; $response->format = YiiResponse::FORMAT_RAW; return $response; }
php
public function asRaw($data): YiiResponse { $response = Yii::$app->getResponse(); $response->data = $data; $response->format = YiiResponse::FORMAT_RAW; return $response; }
[ "public", "function", "asRaw", "(", "$", "data", ")", ":", "YiiResponse", "{", "$", "response", "=", "Yii", "::", "$", "app", "->", "getResponse", "(", ")", ";", "$", "response", "->", "data", "=", "$", "data", ";", "$", "response", "->", "format", "=", "YiiResponse", "::", "FORMAT_RAW", ";", "return", "$", "response", ";", "}" ]
Sets the response format of the given data as RAW. @param mixed $data The data that should *not* be formatted. @return YiiResponse A response that is configured to send `$data` without formatting. @see YiiResponse::$format @see YiiResponse::FORMAT_RAW
[ "Sets", "the", "response", "format", "of", "the", "given", "data", "as", "RAW", "." ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/Controller.php#L49-L55
yuncms/framework
src/web/Controller.php
Controller.asQrCode
public function asQrCode($data): YiiResponse { $response = Yii::$app->getResponse(); $response->format = YiiResponse::FORMAT_RAW; $headers = $response->getHeaders(); $qrCode = new QrCode($data); $headers->setDefault('Content-Type', $qrCode->getContentType()); $response->data = $qrCode->writeString(); return $response; }
php
public function asQrCode($data): YiiResponse { $response = Yii::$app->getResponse(); $response->format = YiiResponse::FORMAT_RAW; $headers = $response->getHeaders(); $qrCode = new QrCode($data); $headers->setDefault('Content-Type', $qrCode->getContentType()); $response->data = $qrCode->writeString(); return $response; }
[ "public", "function", "asQrCode", "(", "$", "data", ")", ":", "YiiResponse", "{", "$", "response", "=", "Yii", "::", "$", "app", "->", "getResponse", "(", ")", ";", "$", "response", "->", "format", "=", "YiiResponse", "::", "FORMAT_RAW", ";", "$", "headers", "=", "$", "response", "->", "getHeaders", "(", ")", ";", "$", "qrCode", "=", "new", "QrCode", "(", "$", "data", ")", ";", "$", "headers", "->", "setDefault", "(", "'Content-Type'", ",", "$", "qrCode", "->", "getContentType", "(", ")", ")", ";", "$", "response", "->", "data", "=", "$", "qrCode", "->", "writeString", "(", ")", ";", "return", "$", "response", ";", "}" ]
输出二维码 @param string $data @return YiiResponse @throws \Da\QrCode\Exception\UnknownWriterException
[ "输出二维码" ]
train
https://github.com/yuncms/framework/blob/af42e28ea4ae15ab8eead3f6d119f93863b94154/src/web/Controller.php#L63-L72
AndreyKluev/yii2-shop-basket
BasketComponent.php
BasketComponent.init
public function init() { // Если гость ... if (Yii::$app->getUser()->isGuest) { // ... то корзину храним в сессии $this->basket = new SessionBasket(); } else { // ... иначе в БД $this->basket = new DbBasket(); $this->basket->idUser = Yii::$app->user->identity->getId(); } $this->basket->owner = $this; // Если в сессии осталась корзина, а пользователь уже не гость => сливаем в БД if(!is_null(Yii::$app->session->get($this->storageName, null)) && !Yii::$app->getUser()->isGuest) { $this->basket->merge(); } // Кешируем товары // Это нужно, чтобы для проверки в корзине товар или нет, не делать запросы в БД для каждого товара $this->cache = $this->basket->getBasketProducts(); }
php
public function init() { // Если гость ... if (Yii::$app->getUser()->isGuest) { // ... то корзину храним в сессии $this->basket = new SessionBasket(); } else { // ... иначе в БД $this->basket = new DbBasket(); $this->basket->idUser = Yii::$app->user->identity->getId(); } $this->basket->owner = $this; // Если в сессии осталась корзина, а пользователь уже не гость => сливаем в БД if(!is_null(Yii::$app->session->get($this->storageName, null)) && !Yii::$app->getUser()->isGuest) { $this->basket->merge(); } // Кешируем товары // Это нужно, чтобы для проверки в корзине товар или нет, не делать запросы в БД для каждого товара $this->cache = $this->basket->getBasketProducts(); }
[ "public", "function", "init", "(", ")", "{", "// Если гость ...", "if", "(", "Yii", "::", "$", "app", "->", "getUser", "(", ")", "->", "isGuest", ")", "{", "// ... то корзину храним в сессии", "$", "this", "->", "basket", "=", "new", "SessionBasket", "(", ")", ";", "}", "else", "{", "// ... иначе в БД", "$", "this", "->", "basket", "=", "new", "DbBasket", "(", ")", ";", "$", "this", "->", "basket", "->", "idUser", "=", "Yii", "::", "$", "app", "->", "user", "->", "identity", "->", "getId", "(", ")", ";", "}", "$", "this", "->", "basket", "->", "owner", "=", "$", "this", ";", "// Если в сессии осталась корзина, а пользователь уже не гость => сливаем в БД", "if", "(", "!", "is_null", "(", "Yii", "::", "$", "app", "->", "session", "->", "get", "(", "$", "this", "->", "storageName", ",", "null", ")", ")", "&&", "!", "Yii", "::", "$", "app", "->", "getUser", "(", ")", "->", "isGuest", ")", "{", "$", "this", "->", "basket", "->", "merge", "(", ")", ";", "}", "// Кешируем товары", "// Это нужно, чтобы для проверки в корзине товар или нет, не делать запросы в БД для каждого товара", "$", "this", "->", "cache", "=", "$", "this", "->", "basket", "->", "getBasketProducts", "(", ")", ";", "}" ]
Инициализируем корзину
[ "Инициализируем", "корзину" ]
train
https://github.com/AndreyKluev/yii2-shop-basket/blob/3bc529fd576a18403096f911112d5337cb5b1069/BasketComponent.php#L52-L74