id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
237,400
aruberutochan/repository
src/Traits/RepositoryAncestorCriteriaTrait.php
RepositoryAncestorCriteriaTrait.getByAncestor
public function getByAncestor(AncestorCriteriaInterface $ancestor) { $this->model = $ancestor->apply($this->model, $this); $results = $this->model->get(); $this->resetModel(); return $this->parserResult($results); }
php
public function getByAncestor(AncestorCriteriaInterface $ancestor) { $this->model = $ancestor->apply($this->model, $this); $results = $this->model->get(); $this->resetModel(); return $this->parserResult($results); }
[ "public", "function", "getByAncestor", "(", "AncestorCriteriaInterface", "$", "ancestor", ")", "{", "$", "this", "->", "model", "=", "$", "ancestor", "->", "apply", "(", "$", "this", "->", "model", ",", "$", "this", ")", ";", "$", "results", "=", "$", "this", "->", "model", "->", "get", "(", ")", ";", "$", "this", "->", "resetModel", "(", ")", ";", "return", "$", "this", "->", "parserResult", "(", "$", "results", ")", ";", "}" ]
Find data by Ancestor @param AncestorCriteriaInterface $ancestor @return mixed
[ "Find", "data", "by", "Ancestor" ]
4ecc5eb37377af8f000af76c886c217479dcf454
https://github.com/aruberutochan/repository/blob/4ecc5eb37377af8f000af76c886c217479dcf454/src/Traits/RepositoryAncestorCriteriaTrait.php#L88-L95
237,401
gossi/trixionary
src/model/Base/Object.php
Object.getSport
public function getSport(ConnectionInterface $con = null) { if ($this->aSport === null && ($this->sport_id !== null)) { $this->aSport = ChildSportQuery::create()->findPk($this->sport_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aSport->addObjects($this); */ } return $this->aSport; }
php
public function getSport(ConnectionInterface $con = null) { if ($this->aSport === null && ($this->sport_id !== null)) { $this->aSport = ChildSportQuery::create()->findPk($this->sport_id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aSport->addObjects($this); */ } return $this->aSport; }
[ "public", "function", "getSport", "(", "ConnectionInterface", "$", "con", "=", "null", ")", "{", "if", "(", "$", "this", "->", "aSport", "===", "null", "&&", "(", "$", "this", "->", "sport_id", "!==", "null", ")", ")", "{", "$", "this", "->", "aSport", "=", "ChildSportQuery", "::", "create", "(", ")", "->", "findPk", "(", "$", "this", "->", "sport_id", ",", "$", "con", ")", ";", "/* The following can be used additionally to\n guarantee the related object contains a reference\n to this object. This level of coupling may, however, be\n undesirable since it could result in an only partially populated collection\n in the referenced object.\n $this->aSport->addObjects($this);\n */", "}", "return", "$", "this", "->", "aSport", ";", "}" ]
Get the associated ChildSport object @param ConnectionInterface $con Optional Connection object. @return ChildSport The associated ChildSport object. @throws PropelException
[ "Get", "the", "associated", "ChildSport", "object" ]
221a6c5322473d7d7f8e322958a3ee46d87da150
https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/model/Base/Object.php#L1442-L1456
237,402
gossi/trixionary
src/model/Base/Object.php
Object.initSkills
public function initSkills($overrideExisting = true) { if (null !== $this->collSkills && !$overrideExisting) { return; } $this->collSkills = new ObjectCollection(); $this->collSkills->setModel('\gossi\trixionary\model\Skill'); }
php
public function initSkills($overrideExisting = true) { if (null !== $this->collSkills && !$overrideExisting) { return; } $this->collSkills = new ObjectCollection(); $this->collSkills->setModel('\gossi\trixionary\model\Skill'); }
[ "public", "function", "initSkills", "(", "$", "overrideExisting", "=", "true", ")", "{", "if", "(", "null", "!==", "$", "this", "->", "collSkills", "&&", "!", "$", "overrideExisting", ")", "{", "return", ";", "}", "$", "this", "->", "collSkills", "=", "new", "ObjectCollection", "(", ")", ";", "$", "this", "->", "collSkills", "->", "setModel", "(", "'\\gossi\\trixionary\\model\\Skill'", ")", ";", "}" ]
Initializes the collSkills collection. By default this just sets the collSkills collection to an empty array (like clearcollSkills()); however, you may wish to override this method in your stub class to provide setting appropriate to your application -- for example, setting the initial array to the values stored in database. @param boolean $overrideExisting If set to true, the method call initializes the collection even if it is not empty @return void
[ "Initializes", "the", "collSkills", "collection", "." ]
221a6c5322473d7d7f8e322958a3ee46d87da150
https://github.com/gossi/trixionary/blob/221a6c5322473d7d7f8e322958a3ee46d87da150/src/model/Base/Object.php#L1508-L1515
237,403
etcinit/tutum-php
src/Chromabits/TutumClient/Entities/ContainerLink.php
ContainerLink.getEndpointAsUrl
public function getEndpointAsUrl($port, $protocol = 'tcp') { if (!$this->hasEndpoint($port, $protocol)) { throw new Exception('Endpoint is not available'); } $key = $port . '/' . $protocol; return Url::fromString($this->endpoints[$key]); }
php
public function getEndpointAsUrl($port, $protocol = 'tcp') { if (!$this->hasEndpoint($port, $protocol)) { throw new Exception('Endpoint is not available'); } $key = $port . '/' . $protocol; return Url::fromString($this->endpoints[$key]); }
[ "public", "function", "getEndpointAsUrl", "(", "$", "port", ",", "$", "protocol", "=", "'tcp'", ")", "{", "if", "(", "!", "$", "this", "->", "hasEndpoint", "(", "$", "port", ",", "$", "protocol", ")", ")", "{", "throw", "new", "Exception", "(", "'Endpoint is not available'", ")", ";", "}", "$", "key", "=", "$", "port", ".", "'/'", ".", "$", "protocol", ";", "return", "Url", "::", "fromString", "(", "$", "this", "->", "endpoints", "[", "$", "key", "]", ")", ";", "}" ]
Try to get a single endpoint as a Url @param $port @param string $protocol @return Url @throws Exception
[ "Try", "to", "get", "a", "single", "endpoint", "as", "a", "Url" ]
39fb3375e0d47109a5da70a0e441efb8fd4f4008
https://github.com/etcinit/tutum-php/blob/39fb3375e0d47109a5da70a0e441efb8fd4f4008/src/Chromabits/TutumClient/Entities/ContainerLink.php#L113-L122
237,404
etcinit/tutum-php
src/Chromabits/TutumClient/Entities/ContainerLink.php
ContainerLink.hasEndpoint
public function hasEndpoint($port, $protocol = 'tcp') { $key = $port . '/' . $protocol; return array_key_exists($key, $this->endpoints); }
php
public function hasEndpoint($port, $protocol = 'tcp') { $key = $port . '/' . $protocol; return array_key_exists($key, $this->endpoints); }
[ "public", "function", "hasEndpoint", "(", "$", "port", ",", "$", "protocol", "=", "'tcp'", ")", "{", "$", "key", "=", "$", "port", ".", "'/'", ".", "$", "protocol", ";", "return", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "endpoints", ")", ";", "}" ]
Return whether or not an endpoint exists @param $port @param string $protocol @return bool
[ "Return", "whether", "or", "not", "an", "endpoint", "exists" ]
39fb3375e0d47109a5da70a0e441efb8fd4f4008
https://github.com/etcinit/tutum-php/blob/39fb3375e0d47109a5da70a0e441efb8fd4f4008/src/Chromabits/TutumClient/Entities/ContainerLink.php#L132-L137
237,405
Briareos/mongodb-odm
lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php
CollectionPersister.getPathAndParent
private function getPathAndParent(PersistentCollection $coll) { $mapping = $coll->getMapping(); $fields = array(); $parent = $coll->getOwner(); while (null !== ($association = $this->uow->getParentAssociation($parent))) { list($m, $owner, $field) = $association; if (isset($m['reference'])) { break; } $parent = $owner; $fields[] = $field; } $propertyPath = implode('.', array_reverse($fields)); $path = $mapping['name']; if ($propertyPath) { $path = $propertyPath . '.' . $path; } return array($path, $parent); }
php
private function getPathAndParent(PersistentCollection $coll) { $mapping = $coll->getMapping(); $fields = array(); $parent = $coll->getOwner(); while (null !== ($association = $this->uow->getParentAssociation($parent))) { list($m, $owner, $field) = $association; if (isset($m['reference'])) { break; } $parent = $owner; $fields[] = $field; } $propertyPath = implode('.', array_reverse($fields)); $path = $mapping['name']; if ($propertyPath) { $path = $propertyPath . '.' . $path; } return array($path, $parent); }
[ "private", "function", "getPathAndParent", "(", "PersistentCollection", "$", "coll", ")", "{", "$", "mapping", "=", "$", "coll", "->", "getMapping", "(", ")", ";", "$", "fields", "=", "array", "(", ")", ";", "$", "parent", "=", "$", "coll", "->", "getOwner", "(", ")", ";", "while", "(", "null", "!==", "(", "$", "association", "=", "$", "this", "->", "uow", "->", "getParentAssociation", "(", "$", "parent", ")", ")", ")", "{", "list", "(", "$", "m", ",", "$", "owner", ",", "$", "field", ")", "=", "$", "association", ";", "if", "(", "isset", "(", "$", "m", "[", "'reference'", "]", ")", ")", "{", "break", ";", "}", "$", "parent", "=", "$", "owner", ";", "$", "fields", "[", "]", "=", "$", "field", ";", "}", "$", "propertyPath", "=", "implode", "(", "'.'", ",", "array_reverse", "(", "$", "fields", ")", ")", ";", "$", "path", "=", "$", "mapping", "[", "'name'", "]", ";", "if", "(", "$", "propertyPath", ")", "{", "$", "path", "=", "$", "propertyPath", ".", "'.'", ".", "$", "path", ";", "}", "return", "array", "(", "$", "path", ",", "$", "parent", ")", ";", "}" ]
Gets the parent information for a given PersistentCollection. It will retrieve the top-level persistent Document that the PersistentCollection lives in. We can use this to issue queries when updating a PersistentCollection that is multiple levels deep inside an embedded document. <code> list($path, $parent) = $this->getPathAndParent($coll) </code> @param PersistentCollection $coll @return array $pathAndParent
[ "Gets", "the", "parent", "information", "for", "a", "given", "PersistentCollection", ".", "It", "will", "retrieve", "the", "top", "-", "level", "persistent", "Document", "that", "the", "PersistentCollection", "lives", "in", ".", "We", "can", "use", "this", "to", "issue", "queries", "when", "updating", "a", "PersistentCollection", "that", "is", "multiple", "levels", "deep", "inside", "an", "embedded", "document", "." ]
29e28bed9a265efd7d05473b0a909fb7c83f76e0
https://github.com/Briareos/mongodb-odm/blob/29e28bed9a265efd7d05473b0a909fb7c83f76e0/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L258-L277
237,406
tofex/util
Helper/Arrays.php
Arrays.arrayFilterRecursive
public function arrayFilterRecursive(array $array) { foreach ($array as &$value) { if (is_array($value)) { /** @var $value array */ $value = count($value) === 1 && array_key_exists(0, $value) && is_string($value[ 0 ]) && $this->variable->isEmpty(trim($value[ 0 ])) ? $value[ 0 ] : $this->arrayFilterRecursive($value); } } return array_filter($array, function ($value) { return ! $this->variable->isEmpty($value) && ! (is_string($value) && $this->variable->isEmpty(trim($value))); }); }
php
public function arrayFilterRecursive(array $array) { foreach ($array as &$value) { if (is_array($value)) { /** @var $value array */ $value = count($value) === 1 && array_key_exists(0, $value) && is_string($value[ 0 ]) && $this->variable->isEmpty(trim($value[ 0 ])) ? $value[ 0 ] : $this->arrayFilterRecursive($value); } } return array_filter($array, function ($value) { return ! $this->variable->isEmpty($value) && ! (is_string($value) && $this->variable->isEmpty(trim($value))); }); }
[ "public", "function", "arrayFilterRecursive", "(", "array", "$", "array", ")", "{", "foreach", "(", "$", "array", "as", "&", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "/** @var $value array */", "$", "value", "=", "count", "(", "$", "value", ")", "===", "1", "&&", "array_key_exists", "(", "0", ",", "$", "value", ")", "&&", "is_string", "(", "$", "value", "[", "0", "]", ")", "&&", "$", "this", "->", "variable", "->", "isEmpty", "(", "trim", "(", "$", "value", "[", "0", "]", ")", ")", "?", "$", "value", "[", "0", "]", ":", "$", "this", "->", "arrayFilterRecursive", "(", "$", "value", ")", ";", "}", "}", "return", "array_filter", "(", "$", "array", ",", "function", "(", "$", "value", ")", "{", "return", "!", "$", "this", "->", "variable", "->", "isEmpty", "(", "$", "value", ")", "&&", "!", "(", "is_string", "(", "$", "value", ")", "&&", "$", "this", "->", "variable", "->", "isEmpty", "(", "trim", "(", "$", "value", ")", ")", ")", ";", "}", ")", ";", "}" ]
Method to filter empty elements from XML @param array $array @return array
[ "Method", "to", "filter", "empty", "elements", "from", "XML" ]
7b167c1094976732dc634367c3c6da37d586ddf2
https://github.com/tofex/util/blob/7b167c1094976732dc634367c3c6da37d586ddf2/Helper/Arrays.php#L446-L460
237,407
railken/laravel-application
src/AppServiceProvider.php
AppServiceProvider.makePath
public function makePath() { $path = base_path('src'); if (!File::exists($path)) { File::makeDirectory($path, 0775, true); } }
php
public function makePath() { $path = base_path('src'); if (!File::exists($path)) { File::makeDirectory($path, 0775, true); } }
[ "public", "function", "makePath", "(", ")", "{", "$", "path", "=", "base_path", "(", "'src'", ")", ";", "if", "(", "!", "File", "::", "exists", "(", "$", "path", ")", ")", "{", "File", "::", "makeDirectory", "(", "$", "path", ",", "0775", ",", "true", ")", ";", "}", "}" ]
Create basic path if doesn't exists @return void
[ "Create", "basic", "path", "if", "doesn", "t", "exists" ]
51b6f5063551e7b2e2302ac096e78b69fbad68de
https://github.com/railken/laravel-application/blob/51b6f5063551e7b2e2302ac096e78b69fbad68de/src/AppServiceProvider.php#L88-L95
237,408
phlexible/phlexible
src/Phlexible/Component/Util/StringUtil.php
StringUtil.truncatePreservingTags
public function truncatePreservingTags($str, $textMaxLength, $postString = '...', $encoding = 'UTF-8') { // complete string length with tags $htmlLength = mb_strlen($str, $encoding); // cursor position $htmlPos = 0; // extracted text length without tags $textLength = 0; // tags that need to closed $closeTag = array(); if ($htmlLength <= $textMaxLength) { return $str; } $inEntity = false; // loop through str, start at cursor position for ($i = $htmlPos; $i < $htmlLength; ++$i) { // extract multibyte encoded char on cursor position $char = mb_substr($str, $i, 1, $encoding); if ($char === '&') { if (!$inEntity) { $inEntity = true; } } elseif ($char === ';') { if ($inEntity) { $inEntity = false; } } // check on an angle bracket assuming text following is a tag elseif ($char === '<') { // sub cursor position inside the tag (after the first angle bracket) $tagPos = $i + 1; // remember first position inside the tag $tagFirst = $tagPos; // size of tag (including angle brackets <1234>) $tagSize = 1; // tag name $tagName = ''; // tag is valid ( <tag> OR </tag> ) $isTag = true; // tag is a closing tag </tag> $isClosingTag = false; // loop through text inside the tag until it is closed for ($j = $tagPos; $j < $htmlLength; ++$j) { // extract multibyte encoded char on sub cursor position $charTag = mb_substr($str, $j, 1, $encoding); // another opening angle bracket = first angle bracket serves as "smaller as" // not a valid tag, set mark and break if ($charTag === '<') { $isTag = false; break; } // seems to be an '<>' entity // not a valid tag, set mark and break elseif ($tagFirst === $j && $charTag === '>' ) { $isTag = false; break; } // closing tag, set mark elseif ($tagFirst === $j && $charTag === '/' ) { $isClosingTag = true; } // tag has ended, break elseif ($charTag === '>') { break; } // remember char as tag name else { $tagName .= $charTag; } ++$tagSize; } // valid tag if (!empty($isTag)) { // closing tag </tag> if (!empty($isClosingTag)) { // remove it from closing array array_pop($closeTag); } // not a closing tag else { // remember to close it $closeTag[] = $tagName; } // set cursor position, continue with next char after the tag $i = $i + $tagSize; } // not a valid tag else { // set assumed tag size as additional textLength, because it is text $textLength = $textLength + $tagSize; // set cursor position and reset the last < or > char to start a new check $i = $i + $tagSize - 1; } } // normal char, increase textLength else { ++$textLength; } // if maximum length reached break if (!$inEntity && $textLength >= $textMaxLength) { break; } } // set cursor to new position $htmlPos = $i + 1; // extract preview text from 0 to current cursor position $ret = mb_substr($str, 0, $htmlPos, $encoding); // if necessary set placeholder string (before tags get closed) if ($textLength >= $textMaxLength) { $ret .= $postString; } // if we are between tags, close them correctly if (count($closeTag)) { foreach (array_reverse($closeTag) as $tag) { $tokens = explode(' ', $tag); $ret .= '</'.$tokens[0].'>'; } } return $ret; }
php
public function truncatePreservingTags($str, $textMaxLength, $postString = '...', $encoding = 'UTF-8') { // complete string length with tags $htmlLength = mb_strlen($str, $encoding); // cursor position $htmlPos = 0; // extracted text length without tags $textLength = 0; // tags that need to closed $closeTag = array(); if ($htmlLength <= $textMaxLength) { return $str; } $inEntity = false; // loop through str, start at cursor position for ($i = $htmlPos; $i < $htmlLength; ++$i) { // extract multibyte encoded char on cursor position $char = mb_substr($str, $i, 1, $encoding); if ($char === '&') { if (!$inEntity) { $inEntity = true; } } elseif ($char === ';') { if ($inEntity) { $inEntity = false; } } // check on an angle bracket assuming text following is a tag elseif ($char === '<') { // sub cursor position inside the tag (after the first angle bracket) $tagPos = $i + 1; // remember first position inside the tag $tagFirst = $tagPos; // size of tag (including angle brackets <1234>) $tagSize = 1; // tag name $tagName = ''; // tag is valid ( <tag> OR </tag> ) $isTag = true; // tag is a closing tag </tag> $isClosingTag = false; // loop through text inside the tag until it is closed for ($j = $tagPos; $j < $htmlLength; ++$j) { // extract multibyte encoded char on sub cursor position $charTag = mb_substr($str, $j, 1, $encoding); // another opening angle bracket = first angle bracket serves as "smaller as" // not a valid tag, set mark and break if ($charTag === '<') { $isTag = false; break; } // seems to be an '<>' entity // not a valid tag, set mark and break elseif ($tagFirst === $j && $charTag === '>' ) { $isTag = false; break; } // closing tag, set mark elseif ($tagFirst === $j && $charTag === '/' ) { $isClosingTag = true; } // tag has ended, break elseif ($charTag === '>') { break; } // remember char as tag name else { $tagName .= $charTag; } ++$tagSize; } // valid tag if (!empty($isTag)) { // closing tag </tag> if (!empty($isClosingTag)) { // remove it from closing array array_pop($closeTag); } // not a closing tag else { // remember to close it $closeTag[] = $tagName; } // set cursor position, continue with next char after the tag $i = $i + $tagSize; } // not a valid tag else { // set assumed tag size as additional textLength, because it is text $textLength = $textLength + $tagSize; // set cursor position and reset the last < or > char to start a new check $i = $i + $tagSize - 1; } } // normal char, increase textLength else { ++$textLength; } // if maximum length reached break if (!$inEntity && $textLength >= $textMaxLength) { break; } } // set cursor to new position $htmlPos = $i + 1; // extract preview text from 0 to current cursor position $ret = mb_substr($str, 0, $htmlPos, $encoding); // if necessary set placeholder string (before tags get closed) if ($textLength >= $textMaxLength) { $ret .= $postString; } // if we are between tags, close them correctly if (count($closeTag)) { foreach (array_reverse($closeTag) as $tag) { $tokens = explode(' ', $tag); $ret .= '</'.$tokens[0].'>'; } } return $ret; }
[ "public", "function", "truncatePreservingTags", "(", "$", "str", ",", "$", "textMaxLength", ",", "$", "postString", "=", "'...'", ",", "$", "encoding", "=", "'UTF-8'", ")", "{", "// complete string length with tags", "$", "htmlLength", "=", "mb_strlen", "(", "$", "str", ",", "$", "encoding", ")", ";", "// cursor position", "$", "htmlPos", "=", "0", ";", "// extracted text length without tags", "$", "textLength", "=", "0", ";", "// tags that need to closed", "$", "closeTag", "=", "array", "(", ")", ";", "if", "(", "$", "htmlLength", "<=", "$", "textMaxLength", ")", "{", "return", "$", "str", ";", "}", "$", "inEntity", "=", "false", ";", "// loop through str, start at cursor position", "for", "(", "$", "i", "=", "$", "htmlPos", ";", "$", "i", "<", "$", "htmlLength", ";", "++", "$", "i", ")", "{", "// extract multibyte encoded char on cursor position", "$", "char", "=", "mb_substr", "(", "$", "str", ",", "$", "i", ",", "1", ",", "$", "encoding", ")", ";", "if", "(", "$", "char", "===", "'&'", ")", "{", "if", "(", "!", "$", "inEntity", ")", "{", "$", "inEntity", "=", "true", ";", "}", "}", "elseif", "(", "$", "char", "===", "';'", ")", "{", "if", "(", "$", "inEntity", ")", "{", "$", "inEntity", "=", "false", ";", "}", "}", "// check on an angle bracket assuming text following is a tag", "elseif", "(", "$", "char", "===", "'<'", ")", "{", "// sub cursor position inside the tag (after the first angle bracket)", "$", "tagPos", "=", "$", "i", "+", "1", ";", "// remember first position inside the tag", "$", "tagFirst", "=", "$", "tagPos", ";", "// size of tag (including angle brackets <1234>)", "$", "tagSize", "=", "1", ";", "// tag name", "$", "tagName", "=", "''", ";", "// tag is valid ( <tag> OR </tag> )", "$", "isTag", "=", "true", ";", "// tag is a closing tag </tag>", "$", "isClosingTag", "=", "false", ";", "// loop through text inside the tag until it is closed", "for", "(", "$", "j", "=", "$", "tagPos", ";", "$", "j", "<", "$", "htmlLength", ";", "++", "$", "j", ")", "{", "// extract multibyte encoded char on sub cursor position", "$", "charTag", "=", "mb_substr", "(", "$", "str", ",", "$", "j", ",", "1", ",", "$", "encoding", ")", ";", "// another opening angle bracket = first angle bracket serves as \"smaller as\"", "// not a valid tag, set mark and break", "if", "(", "$", "charTag", "===", "'<'", ")", "{", "$", "isTag", "=", "false", ";", "break", ";", "}", "// seems to be an '<>' entity", "// not a valid tag, set mark and break", "elseif", "(", "$", "tagFirst", "===", "$", "j", "&&", "$", "charTag", "===", "'>'", ")", "{", "$", "isTag", "=", "false", ";", "break", ";", "}", "// closing tag, set mark", "elseif", "(", "$", "tagFirst", "===", "$", "j", "&&", "$", "charTag", "===", "'/'", ")", "{", "$", "isClosingTag", "=", "true", ";", "}", "// tag has ended, break", "elseif", "(", "$", "charTag", "===", "'>'", ")", "{", "break", ";", "}", "// remember char as tag name", "else", "{", "$", "tagName", ".=", "$", "charTag", ";", "}", "++", "$", "tagSize", ";", "}", "// valid tag", "if", "(", "!", "empty", "(", "$", "isTag", ")", ")", "{", "// closing tag </tag>", "if", "(", "!", "empty", "(", "$", "isClosingTag", ")", ")", "{", "// remove it from closing array", "array_pop", "(", "$", "closeTag", ")", ";", "}", "// not a closing tag", "else", "{", "// remember to close it", "$", "closeTag", "[", "]", "=", "$", "tagName", ";", "}", "// set cursor position, continue with next char after the tag", "$", "i", "=", "$", "i", "+", "$", "tagSize", ";", "}", "// not a valid tag", "else", "{", "// set assumed tag size as additional textLength, because it is text", "$", "textLength", "=", "$", "textLength", "+", "$", "tagSize", ";", "// set cursor position and reset the last < or > char to start a new check", "$", "i", "=", "$", "i", "+", "$", "tagSize", "-", "1", ";", "}", "}", "// normal char, increase textLength", "else", "{", "++", "$", "textLength", ";", "}", "// if maximum length reached break", "if", "(", "!", "$", "inEntity", "&&", "$", "textLength", ">=", "$", "textMaxLength", ")", "{", "break", ";", "}", "}", "// set cursor to new position", "$", "htmlPos", "=", "$", "i", "+", "1", ";", "// extract preview text from 0 to current cursor position", "$", "ret", "=", "mb_substr", "(", "$", "str", ",", "0", ",", "$", "htmlPos", ",", "$", "encoding", ")", ";", "// if necessary set placeholder string (before tags get closed)", "if", "(", "$", "textLength", ">=", "$", "textMaxLength", ")", "{", "$", "ret", ".=", "$", "postString", ";", "}", "// if we are between tags, close them correctly", "if", "(", "count", "(", "$", "closeTag", ")", ")", "{", "foreach", "(", "array_reverse", "(", "$", "closeTag", ")", "as", "$", "tag", ")", "{", "$", "tokens", "=", "explode", "(", "' '", ",", "$", "tag", ")", ";", "$", "ret", ".=", "'</'", ".", "$", "tokens", "[", "0", "]", ".", "'>'", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Function truncates a HTML string, preserving and closing all tags. @param string $str @param int $textMaxLength @param string $postString @param string $encoding @return string
[ "Function", "truncates", "a", "HTML", "string", "preserving", "and", "closing", "all", "tags", "." ]
132f24924c9bb0dbb6c1ea84db0a463f97fa3893
https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Component/Util/StringUtil.php#L32-L164
237,409
MarcusFulbright/represent
src/Represent/Factory/StreamingResponseFactory.php
StreamingResponseFactory.createStreamingResponse
public function createStreamingResponse($filePath, $fileName, $type = 'application/octet-stream') { $response = new StreamedResponse(); $this->setStreamCallBack($response, $filePath); $this->setStreamHeaders($response, $fileName, $type); return $response; }
php
public function createStreamingResponse($filePath, $fileName, $type = 'application/octet-stream') { $response = new StreamedResponse(); $this->setStreamCallBack($response, $filePath); $this->setStreamHeaders($response, $fileName, $type); return $response; }
[ "public", "function", "createStreamingResponse", "(", "$", "filePath", ",", "$", "fileName", ",", "$", "type", "=", "'application/octet-stream'", ")", "{", "$", "response", "=", "new", "StreamedResponse", "(", ")", ";", "$", "this", "->", "setStreamCallBack", "(", "$", "response", ",", "$", "filePath", ")", ";", "$", "this", "->", "setStreamHeaders", "(", "$", "response", ",", "$", "fileName", ",", "$", "type", ")", ";", "return", "$", "response", ";", "}" ]
Handles creating a streaming response for the given file path and uses the given file name @param $filePath @param $fileName @param string $type @return StreamedResponse
[ "Handles", "creating", "a", "streaming", "response", "for", "the", "given", "file", "path", "and", "uses", "the", "given", "file", "name" ]
f7b624f473a3247a29f05c4a694d04bba4038e59
https://github.com/MarcusFulbright/represent/blob/f7b624f473a3247a29f05c4a694d04bba4038e59/src/Represent/Factory/StreamingResponseFactory.php#L31-L38
237,410
beheh/sulphur
src/Parser.php
Parser.parse
public function parse($string) { $response = new Response(); // normalize line endings $filtered = preg_replace("/(\n|\r){2,}/", PHP_EOL, $string); $lines = explode(PHP_EOL, $filtered); foreach($lines as $line) { $matches = array(); if(preg_match('/^(\s*)\[(.*)\]$/', $line, $matches)) { // entering new section $depth = strlen($matches[1]); // merge all lower sections $this->completeSection($response, $depth); $this->stack[$depth] = new Section($matches[2]); } else if(preg_match('/^(\s*)(.*)=(.*)$/', $line, $matches)) { $depth = strlen($matches[1]); if(isset($this->stack[$depth])) { $section = $this->stack[$depth]; $section->__set($matches[2], self::cast($matches[3])); } } } // merge remaining children into parents $this->completeSection($response, 0); return $response; }
php
public function parse($string) { $response = new Response(); // normalize line endings $filtered = preg_replace("/(\n|\r){2,}/", PHP_EOL, $string); $lines = explode(PHP_EOL, $filtered); foreach($lines as $line) { $matches = array(); if(preg_match('/^(\s*)\[(.*)\]$/', $line, $matches)) { // entering new section $depth = strlen($matches[1]); // merge all lower sections $this->completeSection($response, $depth); $this->stack[$depth] = new Section($matches[2]); } else if(preg_match('/^(\s*)(.*)=(.*)$/', $line, $matches)) { $depth = strlen($matches[1]); if(isset($this->stack[$depth])) { $section = $this->stack[$depth]; $section->__set($matches[2], self::cast($matches[3])); } } } // merge remaining children into parents $this->completeSection($response, 0); return $response; }
[ "public", "function", "parse", "(", "$", "string", ")", "{", "$", "response", "=", "new", "Response", "(", ")", ";", "// normalize line endings", "$", "filtered", "=", "preg_replace", "(", "\"/(\\n|\\r){2,}/\"", ",", "PHP_EOL", ",", "$", "string", ")", ";", "$", "lines", "=", "explode", "(", "PHP_EOL", ",", "$", "filtered", ")", ";", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "$", "matches", "=", "array", "(", ")", ";", "if", "(", "preg_match", "(", "'/^(\\s*)\\[(.*)\\]$/'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "// entering new section", "$", "depth", "=", "strlen", "(", "$", "matches", "[", "1", "]", ")", ";", "// merge all lower sections", "$", "this", "->", "completeSection", "(", "$", "response", ",", "$", "depth", ")", ";", "$", "this", "->", "stack", "[", "$", "depth", "]", "=", "new", "Section", "(", "$", "matches", "[", "2", "]", ")", ";", "}", "else", "if", "(", "preg_match", "(", "'/^(\\s*)(.*)=(.*)$/'", ",", "$", "line", ",", "$", "matches", ")", ")", "{", "$", "depth", "=", "strlen", "(", "$", "matches", "[", "1", "]", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "stack", "[", "$", "depth", "]", ")", ")", "{", "$", "section", "=", "$", "this", "->", "stack", "[", "$", "depth", "]", ";", "$", "section", "->", "__set", "(", "$", "matches", "[", "2", "]", ",", "self", "::", "cast", "(", "$", "matches", "[", "3", "]", ")", ")", ";", "}", "}", "}", "// merge remaining children into parents", "$", "this", "->", "completeSection", "(", "$", "response", ",", "0", ")", ";", "return", "$", "response", ";", "}" ]
Parses the passed response and passes the key-value pairs to references. @param string $string the string to parse @return Response the response
[ "Parses", "the", "passed", "response", "and", "passes", "the", "key", "-", "value", "pairs", "to", "references", "." ]
d608b40d6cf26f12476d992276ee9a0aa455bd55
https://github.com/beheh/sulphur/blob/d608b40d6cf26f12476d992276ee9a0aa455bd55/src/Parser.php#L20-L49
237,411
beheh/sulphur
src/Parser.php
Parser.cast
public static function cast($value) { $matches = array(); if(strtolower($value) === 'true') { $value = (bool) true; } else if(strtolower($value) === 'false') { $value = (bool) false; } else if(is_numeric($value)) { $value = (int) $value; } else if(preg_match('/^"(.*)"$/', $value, $matches)) { $value = $matches[1]; } return $value; }
php
public static function cast($value) { $matches = array(); if(strtolower($value) === 'true') { $value = (bool) true; } else if(strtolower($value) === 'false') { $value = (bool) false; } else if(is_numeric($value)) { $value = (int) $value; } else if(preg_match('/^"(.*)"$/', $value, $matches)) { $value = $matches[1]; } return $value; }
[ "public", "static", "function", "cast", "(", "$", "value", ")", "{", "$", "matches", "=", "array", "(", ")", ";", "if", "(", "strtolower", "(", "$", "value", ")", "===", "'true'", ")", "{", "$", "value", "=", "(", "bool", ")", "true", ";", "}", "else", "if", "(", "strtolower", "(", "$", "value", ")", "===", "'false'", ")", "{", "$", "value", "=", "(", "bool", ")", "false", ";", "}", "else", "if", "(", "is_numeric", "(", "$", "value", ")", ")", "{", "$", "value", "=", "(", "int", ")", "$", "value", ";", "}", "else", "if", "(", "preg_match", "(", "'/^\"(.*)\"$/'", ",", "$", "value", ",", "$", "matches", ")", ")", "{", "$", "value", "=", "$", "matches", "[", "1", "]", ";", "}", "return", "$", "value", ";", "}" ]
Casts the value to the correct datatype. @param string $value the value to cast @return any
[ "Casts", "the", "value", "to", "the", "correct", "datatype", "." ]
d608b40d6cf26f12476d992276ee9a0aa455bd55
https://github.com/beheh/sulphur/blob/d608b40d6cf26f12476d992276ee9a0aa455bd55/src/Parser.php#L79-L91
237,412
stubbles/stubbles-sequence
src/main/php/Collector.php
Collector.forSum
public static function forSum(callable $num): self { return new self( function() { return 0; }, function(&$result, $element) use($num) { $result+= $num($element); } ); }
php
public static function forSum(callable $num): self { return new self( function() { return 0; }, function(&$result, $element) use($num) { $result+= $num($element); } ); }
[ "public", "static", "function", "forSum", "(", "callable", "$", "num", ")", ":", "self", "{", "return", "new", "self", "(", "function", "(", ")", "{", "return", "0", ";", "}", ",", "function", "(", "&", "$", "result", ",", "$", "element", ")", "use", "(", "$", "num", ")", "{", "$", "result", "+=", "$", "num", "(", "$", "element", ")", ";", "}", ")", ";", "}" ]
returns a collector to sum up elements @api @param callable $num callable which retrieves a number from a given element @return \stubbles\sequence\Collector
[ "returns", "a", "collector", "to", "sum", "up", "elements" ]
258d2247f1cdd826818348fe15829d5a98a9de70
https://github.com/stubbles/stubbles-sequence/blob/258d2247f1cdd826818348fe15829d5a98a9de70/src/main/php/Collector.php#L108-L113
237,413
stubbles/stubbles-sequence
src/main/php/Collector.php
Collector.forAverage
public static function forAverage(callable $num): self { return new self( function() { return [0, 0]; }, function(&$result, $arg) use($num) { $result[0] += $num($arg); $result[1]++; }, function($result) { return $result[0] / $result[1]; } ); }
php
public static function forAverage(callable $num): self { return new self( function() { return [0, 0]; }, function(&$result, $arg) use($num) { $result[0] += $num($arg); $result[1]++; }, function($result) { return $result[0] / $result[1]; } ); }
[ "public", "static", "function", "forAverage", "(", "callable", "$", "num", ")", ":", "self", "{", "return", "new", "self", "(", "function", "(", ")", "{", "return", "[", "0", ",", "0", "]", ";", "}", ",", "function", "(", "&", "$", "result", ",", "$", "arg", ")", "use", "(", "$", "num", ")", "{", "$", "result", "[", "0", "]", "+=", "$", "num", "(", "$", "arg", ")", ";", "$", "result", "[", "1", "]", "++", ";", "}", ",", "function", "(", "$", "result", ")", "{", "return", "$", "result", "[", "0", "]", "/", "$", "result", "[", "1", "]", ";", "}", ")", ";", "}" ]
returns a collector to calculate an average for all the given elements @api @param callable $num callable which retrieves a number from a given element @return \stubbles\sequence\Collector
[ "returns", "a", "collector", "to", "calculate", "an", "average", "for", "all", "the", "given", "elements" ]
258d2247f1cdd826818348fe15829d5a98a9de70
https://github.com/stubbles/stubbles-sequence/blob/258d2247f1cdd826818348fe15829d5a98a9de70/src/main/php/Collector.php#L122-L128
237,414
stubbles/stubbles-sequence
src/main/php/Collector.php
Collector.accumulate
public function accumulate($element, $key) { $accumulate = $this->accumulator; $accumulate($this->structure, $element, $key); }
php
public function accumulate($element, $key) { $accumulate = $this->accumulator; $accumulate($this->structure, $element, $key); }
[ "public", "function", "accumulate", "(", "$", "element", ",", "$", "key", ")", "{", "$", "accumulate", "=", "$", "this", "->", "accumulator", ";", "$", "accumulate", "(", "$", "this", "->", "structure", ",", "$", "element", ",", "$", "key", ")", ";", "}" ]
adds given element and key to result structure @param mixed $element @param mixed $key
[ "adds", "given", "element", "and", "key", "to", "result", "structure" ]
258d2247f1cdd826818348fe15829d5a98a9de70
https://github.com/stubbles/stubbles-sequence/blob/258d2247f1cdd826818348fe15829d5a98a9de70/src/main/php/Collector.php#L146-L150
237,415
stubbles/stubbles-sequence
src/main/php/Collector.php
Collector.finish
public function finish() { if (null === $this->finisher) { return $this->structure; } $finish = $this->finisher; return $finish($this->structure); }
php
public function finish() { if (null === $this->finisher) { return $this->structure; } $finish = $this->finisher; return $finish($this->structure); }
[ "public", "function", "finish", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "finisher", ")", "{", "return", "$", "this", "->", "structure", ";", "}", "$", "finish", "=", "$", "this", "->", "finisher", ";", "return", "$", "finish", "(", "$", "this", "->", "structure", ")", ";", "}" ]
finishes collection of result @param mixed $result @return mixed finished result
[ "finishes", "collection", "of", "result" ]
258d2247f1cdd826818348fe15829d5a98a9de70
https://github.com/stubbles/stubbles-sequence/blob/258d2247f1cdd826818348fe15829d5a98a9de70/src/main/php/Collector.php#L158-L166
237,416
jsiefer/class-mocker
src/Registry/FootprintRegistry.php
FootprintRegistry.import
public function import($file) { if (!file_exists($file)) { throw new \InvalidArgumentException("Footprint file '$file' does not exist"); } $content = file_get_contents($file); $this->importJson($content); }
php
public function import($file) { if (!file_exists($file)) { throw new \InvalidArgumentException("Footprint file '$file' does not exist"); } $content = file_get_contents($file); $this->importJson($content); }
[ "public", "function", "import", "(", "$", "file", ")", "{", "if", "(", "!", "file_exists", "(", "$", "file", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Footprint file '$file' does not exist\"", ")", ";", "}", "$", "content", "=", "file_get_contents", "(", "$", "file", ")", ";", "$", "this", "->", "importJson", "(", "$", "content", ")", ";", "}" ]
Import footprints from json file @param string $file @return void
[ "Import", "footprints", "from", "json", "file" ]
a355fc9bece8e6f27fbfd09b1631234f7d73a791
https://github.com/jsiefer/class-mocker/blob/a355fc9bece8e6f27fbfd09b1631234f7d73a791/src/Registry/FootprintRegistry.php#L47-L54
237,417
jsiefer/class-mocker
src/Registry/FootprintRegistry.php
FootprintRegistry.importJson
public function importJson($jsonData) { $json = json_decode($jsonData, true); if ($json === null) { throw new \InvalidArgumentException("Footprint json is not a valid"); } if (!is_array($json)) { throw new \InvalidArgumentException("Footprint json data is not a valid"); } $this->_data += $json; }
php
public function importJson($jsonData) { $json = json_decode($jsonData, true); if ($json === null) { throw new \InvalidArgumentException("Footprint json is not a valid"); } if (!is_array($json)) { throw new \InvalidArgumentException("Footprint json data is not a valid"); } $this->_data += $json; }
[ "public", "function", "importJson", "(", "$", "jsonData", ")", "{", "$", "json", "=", "json_decode", "(", "$", "jsonData", ",", "true", ")", ";", "if", "(", "$", "json", "===", "null", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Footprint json is not a valid\"", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "json", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Footprint json data is not a valid\"", ")", ";", "}", "$", "this", "->", "_data", "+=", "$", "json", ";", "}" ]
Import footprints from json string @param string $jsonData @return void
[ "Import", "footprints", "from", "json", "string" ]
a355fc9bece8e6f27fbfd09b1631234f7d73a791
https://github.com/jsiefer/class-mocker/blob/a355fc9bece8e6f27fbfd09b1631234f7d73a791/src/Registry/FootprintRegistry.php#L63-L76
237,418
jsiefer/class-mocker
src/Registry/FootprintRegistry.php
FootprintRegistry.get
public function get($className) { if (isset($this->_footprints[$className])) { return $this->_footprints[$className]; } if (isset($this->_data[$className])) { $data = $this->_data[$className]; $footprint = new ClassFootprint($data); } else { $footprint = new ClassFootprint(); if (preg_match($this->_interfaceRegex, $className)) { $footprint->setType(ClassFootprint::TYPE_INTERFACE); } } $this->addFootprint($className, $footprint); return $footprint; }
php
public function get($className) { if (isset($this->_footprints[$className])) { return $this->_footprints[$className]; } if (isset($this->_data[$className])) { $data = $this->_data[$className]; $footprint = new ClassFootprint($data); } else { $footprint = new ClassFootprint(); if (preg_match($this->_interfaceRegex, $className)) { $footprint->setType(ClassFootprint::TYPE_INTERFACE); } } $this->addFootprint($className, $footprint); return $footprint; }
[ "public", "function", "get", "(", "$", "className", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_footprints", "[", "$", "className", "]", ")", ")", "{", "return", "$", "this", "->", "_footprints", "[", "$", "className", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "_data", "[", "$", "className", "]", ")", ")", "{", "$", "data", "=", "$", "this", "->", "_data", "[", "$", "className", "]", ";", "$", "footprint", "=", "new", "ClassFootprint", "(", "$", "data", ")", ";", "}", "else", "{", "$", "footprint", "=", "new", "ClassFootprint", "(", ")", ";", "if", "(", "preg_match", "(", "$", "this", "->", "_interfaceRegex", ",", "$", "className", ")", ")", "{", "$", "footprint", "->", "setType", "(", "ClassFootprint", "::", "TYPE_INTERFACE", ")", ";", "}", "}", "$", "this", "->", "addFootprint", "(", "$", "className", ",", "$", "footprint", ")", ";", "return", "$", "footprint", ";", "}" ]
Retrieve class footprint @param string $className @return ClassFootprint
[ "Retrieve", "class", "footprint" ]
a355fc9bece8e6f27fbfd09b1631234f7d73a791
https://github.com/jsiefer/class-mocker/blob/a355fc9bece8e6f27fbfd09b1631234f7d73a791/src/Registry/FootprintRegistry.php#L98-L116
237,419
sbstjn/reng
src/lib/Component/Base.php
Base.validate
private function validate() { if (!stristr(self::CHARACTER_LIST, $this->value[0])) { throw new \Exception('Invalid first character: ' . $this->value[0]); } if (!in_array($this->value, self::listForCharacter($this->value[0]))) { throw new \Exception('Word not in known list of words: ' . $this->value); } }
php
private function validate() { if (!stristr(self::CHARACTER_LIST, $this->value[0])) { throw new \Exception('Invalid first character: ' . $this->value[0]); } if (!in_array($this->value, self::listForCharacter($this->value[0]))) { throw new \Exception('Word not in known list of words: ' . $this->value); } }
[ "private", "function", "validate", "(", ")", "{", "if", "(", "!", "stristr", "(", "self", "::", "CHARACTER_LIST", ",", "$", "this", "->", "value", "[", "0", "]", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Invalid first character: '", ".", "$", "this", "->", "value", "[", "0", "]", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "this", "->", "value", ",", "self", "::", "listForCharacter", "(", "$", "this", "->", "value", "[", "0", "]", ")", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Word not in known list of words: '", ".", "$", "this", "->", "value", ")", ";", "}", "}" ]
Validate word against list of allowed characters and words @throws \Exception
[ "Validate", "word", "against", "list", "of", "allowed", "characters", "and", "words" ]
d0da8ed3498a269e610226ceb4c690f4447bd6a4
https://github.com/sbstjn/reng/blob/d0da8ed3498a269e610226ceb4c690f4447bd6a4/src/lib/Component/Base.php#L36-L45
237,420
sbstjn/reng
src/lib/Component/Base.php
Base.randomFor
public static function randomFor($char) { $list = self::listForCharacter($char); $class = get_called_class(); return new $class($list[rand(0, count($list) - 1)]); }
php
public static function randomFor($char) { $list = self::listForCharacter($char); $class = get_called_class(); return new $class($list[rand(0, count($list) - 1)]); }
[ "public", "static", "function", "randomFor", "(", "$", "char", ")", "{", "$", "list", "=", "self", "::", "listForCharacter", "(", "$", "char", ")", ";", "$", "class", "=", "get_called_class", "(", ")", ";", "return", "new", "$", "class", "(", "$", "list", "[", "rand", "(", "0", ",", "count", "(", "$", "list", ")", "-", "1", ")", "]", ")", ";", "}" ]
Get random string startign with given character @param $char @return string
[ "Get", "random", "string", "startign", "with", "given", "character" ]
d0da8ed3498a269e610226ceb4c690f4447bd6a4
https://github.com/sbstjn/reng/blob/d0da8ed3498a269e610226ceb4c690f4447bd6a4/src/lib/Component/Base.php#L76-L83
237,421
sbstjn/reng
src/lib/Component/Base.php
Base.listForCharacter
public static function listForCharacter($char) { $file = self::getDataFolder() . '/' . $char; $data = strtolower(file_get_contents($file)); return explode("\n", $data); }
php
public static function listForCharacter($char) { $file = self::getDataFolder() . '/' . $char; $data = strtolower(file_get_contents($file)); return explode("\n", $data); }
[ "public", "static", "function", "listForCharacter", "(", "$", "char", ")", "{", "$", "file", "=", "self", "::", "getDataFolder", "(", ")", ".", "'/'", ".", "$", "char", ";", "$", "data", "=", "strtolower", "(", "file_get_contents", "(", "$", "file", ")", ")", ";", "return", "explode", "(", "\"\\n\"", ",", "$", "data", ")", ";", "}" ]
Get list of available words for given character @param $char Needed character @return array
[ "Get", "list", "of", "available", "words", "for", "given", "character" ]
d0da8ed3498a269e610226ceb4c690f4447bd6a4
https://github.com/sbstjn/reng/blob/d0da8ed3498a269e610226ceb4c690f4447bd6a4/src/lib/Component/Base.php#L91-L96
237,422
railsphp/framework
src/Rails/ActiveRecord/Relation.php
Relation.firstOrCreate
public function firstOrCreate(array $attributes = []) { $model = $this->first(); if (!$model) { $model = $this->create($attributes); } return $model; }
php
public function firstOrCreate(array $attributes = []) { $model = $this->first(); if (!$model) { $model = $this->create($attributes); } return $model; }
[ "public", "function", "firstOrCreate", "(", "array", "$", "attributes", "=", "[", "]", ")", "{", "$", "model", "=", "$", "this", "->", "first", "(", ")", ";", "if", "(", "!", "$", "model", ")", "{", "$", "model", "=", "$", "this", "->", "create", "(", "$", "attributes", ")", ";", "}", "return", "$", "model", ";", "}" ]
Find first or create record. @param array $attributes additional attributes to create the record with. @return object
[ "Find", "first", "or", "create", "record", "." ]
2ac9d3e493035dcc68f3c3812423327127327cd5
https://github.com/railsphp/framework/blob/2ac9d3e493035dcc68f3c3812423327127327cd5/src/Rails/ActiveRecord/Relation.php#L248-L255
237,423
mkjpryor/option
src/Result.php
Result.get
public function get() { if( $this->value !== null ) return $this->value; if( $this->error !== null ) throw $this->error; throw new \LogicException("Value and error cannot both be null"); }
php
public function get() { if( $this->value !== null ) return $this->value; if( $this->error !== null ) throw $this->error; throw new \LogicException("Value and error cannot both be null"); }
[ "public", "function", "get", "(", ")", "{", "if", "(", "$", "this", "->", "value", "!==", "null", ")", "return", "$", "this", "->", "value", ";", "if", "(", "$", "this", "->", "error", "!==", "null", ")", "throw", "$", "this", "->", "error", ";", "throw", "new", "\\", "LogicException", "(", "\"Value and error cannot both be null\"", ")", ";", "}" ]
Returns the value of the result if it is a success If it is an error, the exception it was created with is thrown
[ "Returns", "the", "value", "of", "the", "result", "if", "it", "is", "a", "success" ]
202af894c6fac89b4cb3769acfa4f81813167706
https://github.com/mkjpryor/option/blob/202af894c6fac89b4cb3769acfa4f81813167706/src/Result.php#L37-L41
237,424
mkjpryor/option
src/Result.php
Result._try
public static function _try(callable $f) { try { return Result::success($f()); } catch( \Exception $error ) { return Result::error($error); } }
php
public static function _try(callable $f) { try { return Result::success($f()); } catch( \Exception $error ) { return Result::error($error); } }
[ "public", "static", "function", "_try", "(", "callable", "$", "f", ")", "{", "try", "{", "return", "Result", "::", "success", "(", "$", "f", "(", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "error", ")", "{", "return", "Result", "::", "error", "(", "$", "error", ")", ";", "}", "}" ]
Tries to execute the given function and returns a result representing the outcome, i.e. if the function returns normally, a successful result is returned containing the return value and if the function throws an exception, an error result is returned containing the error $f should take no arguments and return a value that will be wrapped in a success if the computation completes successfully The _ is required if we want to use the word try since it is keyword
[ "Tries", "to", "execute", "the", "given", "function", "and", "returns", "a", "result", "representing", "the", "outcome", "i", ".", "e", ".", "if", "the", "function", "returns", "normally", "a", "successful", "result", "is", "returned", "containing", "the", "return", "value", "and", "if", "the", "function", "throws", "an", "exception", "an", "error", "result", "is", "returned", "containing", "the", "error" ]
202af894c6fac89b4cb3769acfa4f81813167706
https://github.com/mkjpryor/option/blob/202af894c6fac89b4cb3769acfa4f81813167706/src/Result.php#L166-L173
237,425
wasabi-cms/core
src/Controller/Component/GuardianComponent.php
GuardianComponent.addGuestActions
public function addGuestActions($guestActions) { if (!is_array($guestActions)) { $guestActions = [$guestActions]; } $this->_guestActions = Hash::merge($this->_guestActions, $guestActions); }
php
public function addGuestActions($guestActions) { if (!is_array($guestActions)) { $guestActions = [$guestActions]; } $this->_guestActions = Hash::merge($this->_guestActions, $guestActions); }
[ "public", "function", "addGuestActions", "(", "$", "guestActions", ")", "{", "if", "(", "!", "is_array", "(", "$", "guestActions", ")", ")", "{", "$", "guestActions", "=", "[", "$", "guestActions", "]", ";", "}", "$", "this", "->", "_guestActions", "=", "Hash", "::", "merge", "(", "$", "this", "->", "_guestActions", ",", "$", "guestActions", ")", ";", "}" ]
Add guest actions which don't require a logged in user. @param array|string $guestActions The guest action to add. @return void
[ "Add", "guest", "actions", "which", "don", "t", "require", "a", "logged", "in", "user", "." ]
0eadbb64d2fc201bacc63c93814adeca70e08f90
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Controller/Component/GuardianComponent.php#L146-L153
237,426
wasabi-cms/core
src/Controller/Component/GuardianComponent.php
GuardianComponent.hasAccess
public function hasAccess($url) { if ($this->isGuestAction($url)) { return true; } $path = $this->getPathFromUrl($url); $groupId = $this->Auth->user('group_id'); if ($groupId === null) { return false; } if (!is_array($groupId)) { $groupId = [$groupId]; } if (in_array(1, $groupId)) { return true; } $user = Wasabi::user(); if (empty($user->permissions)) { Wasabi::user()->permissions = $this->_getGroupPermissions()->findAllForGroup($groupId); } if (array_key_exists($path, Wasabi::user()->permissions)) { return true; } return false; }
php
public function hasAccess($url) { if ($this->isGuestAction($url)) { return true; } $path = $this->getPathFromUrl($url); $groupId = $this->Auth->user('group_id'); if ($groupId === null) { return false; } if (!is_array($groupId)) { $groupId = [$groupId]; } if (in_array(1, $groupId)) { return true; } $user = Wasabi::user(); if (empty($user->permissions)) { Wasabi::user()->permissions = $this->_getGroupPermissions()->findAllForGroup($groupId); } if (array_key_exists($path, Wasabi::user()->permissions)) { return true; } return false; }
[ "public", "function", "hasAccess", "(", "$", "url", ")", "{", "if", "(", "$", "this", "->", "isGuestAction", "(", "$", "url", ")", ")", "{", "return", "true", ";", "}", "$", "path", "=", "$", "this", "->", "getPathFromUrl", "(", "$", "url", ")", ";", "$", "groupId", "=", "$", "this", "->", "Auth", "->", "user", "(", "'group_id'", ")", ";", "if", "(", "$", "groupId", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "!", "is_array", "(", "$", "groupId", ")", ")", "{", "$", "groupId", "=", "[", "$", "groupId", "]", ";", "}", "if", "(", "in_array", "(", "1", ",", "$", "groupId", ")", ")", "{", "return", "true", ";", "}", "$", "user", "=", "Wasabi", "::", "user", "(", ")", ";", "if", "(", "empty", "(", "$", "user", "->", "permissions", ")", ")", "{", "Wasabi", "::", "user", "(", ")", "->", "permissions", "=", "$", "this", "->", "_getGroupPermissions", "(", ")", "->", "findAllForGroup", "(", "$", "groupId", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "path", ",", "Wasabi", "::", "user", "(", ")", "->", "permissions", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if the currently logged in user is authorized to access the given url. @param array $url The url parameters. @return bool
[ "Check", "if", "the", "currently", "logged", "in", "user", "is", "authorized", "to", "access", "the", "given", "url", "." ]
0eadbb64d2fc201bacc63c93814adeca70e08f90
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Controller/Component/GuardianComponent.php#L161-L193
237,427
wasabi-cms/core
src/Controller/Component/GuardianComponent.php
GuardianComponent.isGuestAction
public function isGuestAction($url) { $path = $this->getPathFromUrl($url); if (in_array($path, $this->_guestActions)) { return true; } return false; }
php
public function isGuestAction($url) { $path = $this->getPathFromUrl($url); if (in_array($path, $this->_guestActions)) { return true; } return false; }
[ "public", "function", "isGuestAction", "(", "$", "url", ")", "{", "$", "path", "=", "$", "this", "->", "getPathFromUrl", "(", "$", "url", ")", ";", "if", "(", "in_array", "(", "$", "path", ",", "$", "this", "->", "_guestActions", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if the requested action does not require an authenticated user. -> guest action @param array $url The url parameters. @return bool
[ "Check", "if", "the", "requested", "action", "does", "not", "require", "an", "authenticated", "user", ".", "-", ">", "guest", "action" ]
0eadbb64d2fc201bacc63c93814adeca70e08f90
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Controller/Component/GuardianComponent.php#L202-L211
237,428
wasabi-cms/core
src/Controller/Component/GuardianComponent.php
GuardianComponent.getPathFromUrl
public function getPathFromUrl($url) { $cacheKey = md5(serialize($url)); return Cache::remember($cacheKey, function () use ($url) { $plugin = 'App'; $action = 'index'; $parsedUrl = !is_array($url) ? Router::parse($url) : $url; if (isset($parsedUrl['plugin']) && !empty($parsedUrl['plugin'])) { $plugin = $parsedUrl['plugin']; } $controller = $parsedUrl['controller']; if (isset($parsedUrl['action']) && $parsedUrl['action'] !== '') { $action = $parsedUrl['action']; } return $plugin . '.' . $controller . '.' . $action; }, 'wasabi/core/guardian_paths'); }
php
public function getPathFromUrl($url) { $cacheKey = md5(serialize($url)); return Cache::remember($cacheKey, function () use ($url) { $plugin = 'App'; $action = 'index'; $parsedUrl = !is_array($url) ? Router::parse($url) : $url; if (isset($parsedUrl['plugin']) && !empty($parsedUrl['plugin'])) { $plugin = $parsedUrl['plugin']; } $controller = $parsedUrl['controller']; if (isset($parsedUrl['action']) && $parsedUrl['action'] !== '') { $action = $parsedUrl['action']; } return $plugin . '.' . $controller . '.' . $action; }, 'wasabi/core/guardian_paths'); }
[ "public", "function", "getPathFromUrl", "(", "$", "url", ")", "{", "$", "cacheKey", "=", "md5", "(", "serialize", "(", "$", "url", ")", ")", ";", "return", "Cache", "::", "remember", "(", "$", "cacheKey", ",", "function", "(", ")", "use", "(", "$", "url", ")", "{", "$", "plugin", "=", "'App'", ";", "$", "action", "=", "'index'", ";", "$", "parsedUrl", "=", "!", "is_array", "(", "$", "url", ")", "?", "Router", "::", "parse", "(", "$", "url", ")", ":", "$", "url", ";", "if", "(", "isset", "(", "$", "parsedUrl", "[", "'plugin'", "]", ")", "&&", "!", "empty", "(", "$", "parsedUrl", "[", "'plugin'", "]", ")", ")", "{", "$", "plugin", "=", "$", "parsedUrl", "[", "'plugin'", "]", ";", "}", "$", "controller", "=", "$", "parsedUrl", "[", "'controller'", "]", ";", "if", "(", "isset", "(", "$", "parsedUrl", "[", "'action'", "]", ")", "&&", "$", "parsedUrl", "[", "'action'", "]", "!==", "''", ")", "{", "$", "action", "=", "$", "parsedUrl", "[", "'action'", "]", ";", "}", "return", "$", "plugin", ".", "'.'", ".", "$", "controller", ".", "'.'", ".", "$", "action", ";", "}", ",", "'wasabi/core/guardian_paths'", ")", ";", "}" ]
Determine the path for a given url array. @param array $url The url parameters. @return string
[ "Determine", "the", "path", "for", "a", "given", "url", "array", "." ]
0eadbb64d2fc201bacc63c93814adeca70e08f90
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Controller/Component/GuardianComponent.php#L229-L249
237,429
wasabi-cms/core
src/Controller/Component/GuardianComponent.php
GuardianComponent.getActionMap
public function getActionMap() { $plugins = $this->getLoadedPluginPaths(); $actionMap = []; foreach ($plugins as $plugin => $path) { $controllers = $this->getControllersForPlugin($plugin, $path); foreach ($controllers as $controller) { $actions = $this->introspectController($controller['path']); if (empty($actions)) { continue; } foreach ($actions as $action) { $path = "{$plugin}.{$controller['name']}.{$action}"; if (in_array($path, $this->_guestActions)) { continue; } $actionMap[$path] = [ 'plugin' => $plugin, 'controller' => $controller['name'], 'action' => $action ]; } } } $appControllers = $this->getControllersForApp(); foreach ($appControllers as $controller) { $actions = $this->introspectController($controller['path']); if (empty($actions)) { continue; } foreach ($actions as $action) { if (strpos($controller['path'], ROOT . DS . 'src' . DS . 'Controller') === false) { $path = "App.{$controller['name']}.{$action}"; if (in_array($path, $this->_guestActions)) { continue; } $actionMap[$path] = [ 'plugin' => 'App', 'controller' => $controller['name'], 'action' => $action ]; } else { $namespaceParts = explode(DS, substr($controller['path'], strlen(ROOT . DS . 'src' . DS . 'Controller') + 1)); array_pop($namespaceParts); $namespace = join('/', $namespaceParts); if (!empty($namespace)) { $path = "App.{$namespace}/{$controller['name']}.{$action}"; } else { $path = "App.{$controller['name']}.{$action}"; } if (in_array($path, $this->_guestActions)) { continue; } $actionMap[$path] = [ 'plugin' => 'App', 'controller' => !empty($namespace) ? $namespace . '/' . $controller['name'] : $controller['name'], 'action' => $action ]; } } } return $actionMap; }
php
public function getActionMap() { $plugins = $this->getLoadedPluginPaths(); $actionMap = []; foreach ($plugins as $plugin => $path) { $controllers = $this->getControllersForPlugin($plugin, $path); foreach ($controllers as $controller) { $actions = $this->introspectController($controller['path']); if (empty($actions)) { continue; } foreach ($actions as $action) { $path = "{$plugin}.{$controller['name']}.{$action}"; if (in_array($path, $this->_guestActions)) { continue; } $actionMap[$path] = [ 'plugin' => $plugin, 'controller' => $controller['name'], 'action' => $action ]; } } } $appControllers = $this->getControllersForApp(); foreach ($appControllers as $controller) { $actions = $this->introspectController($controller['path']); if (empty($actions)) { continue; } foreach ($actions as $action) { if (strpos($controller['path'], ROOT . DS . 'src' . DS . 'Controller') === false) { $path = "App.{$controller['name']}.{$action}"; if (in_array($path, $this->_guestActions)) { continue; } $actionMap[$path] = [ 'plugin' => 'App', 'controller' => $controller['name'], 'action' => $action ]; } else { $namespaceParts = explode(DS, substr($controller['path'], strlen(ROOT . DS . 'src' . DS . 'Controller') + 1)); array_pop($namespaceParts); $namespace = join('/', $namespaceParts); if (!empty($namespace)) { $path = "App.{$namespace}/{$controller['name']}.{$action}"; } else { $path = "App.{$controller['name']}.{$action}"; } if (in_array($path, $this->_guestActions)) { continue; } $actionMap[$path] = [ 'plugin' => 'App', 'controller' => !empty($namespace) ? $namespace . '/' . $controller['name'] : $controller['name'], 'action' => $action ]; } } } return $actionMap; }
[ "public", "function", "getActionMap", "(", ")", "{", "$", "plugins", "=", "$", "this", "->", "getLoadedPluginPaths", "(", ")", ";", "$", "actionMap", "=", "[", "]", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", "=>", "$", "path", ")", "{", "$", "controllers", "=", "$", "this", "->", "getControllersForPlugin", "(", "$", "plugin", ",", "$", "path", ")", ";", "foreach", "(", "$", "controllers", "as", "$", "controller", ")", "{", "$", "actions", "=", "$", "this", "->", "introspectController", "(", "$", "controller", "[", "'path'", "]", ")", ";", "if", "(", "empty", "(", "$", "actions", ")", ")", "{", "continue", ";", "}", "foreach", "(", "$", "actions", "as", "$", "action", ")", "{", "$", "path", "=", "\"{$plugin}.{$controller['name']}.{$action}\"", ";", "if", "(", "in_array", "(", "$", "path", ",", "$", "this", "->", "_guestActions", ")", ")", "{", "continue", ";", "}", "$", "actionMap", "[", "$", "path", "]", "=", "[", "'plugin'", "=>", "$", "plugin", ",", "'controller'", "=>", "$", "controller", "[", "'name'", "]", ",", "'action'", "=>", "$", "action", "]", ";", "}", "}", "}", "$", "appControllers", "=", "$", "this", "->", "getControllersForApp", "(", ")", ";", "foreach", "(", "$", "appControllers", "as", "$", "controller", ")", "{", "$", "actions", "=", "$", "this", "->", "introspectController", "(", "$", "controller", "[", "'path'", "]", ")", ";", "if", "(", "empty", "(", "$", "actions", ")", ")", "{", "continue", ";", "}", "foreach", "(", "$", "actions", "as", "$", "action", ")", "{", "if", "(", "strpos", "(", "$", "controller", "[", "'path'", "]", ",", "ROOT", ".", "DS", ".", "'src'", ".", "DS", ".", "'Controller'", ")", "===", "false", ")", "{", "$", "path", "=", "\"App.{$controller['name']}.{$action}\"", ";", "if", "(", "in_array", "(", "$", "path", ",", "$", "this", "->", "_guestActions", ")", ")", "{", "continue", ";", "}", "$", "actionMap", "[", "$", "path", "]", "=", "[", "'plugin'", "=>", "'App'", ",", "'controller'", "=>", "$", "controller", "[", "'name'", "]", ",", "'action'", "=>", "$", "action", "]", ";", "}", "else", "{", "$", "namespaceParts", "=", "explode", "(", "DS", ",", "substr", "(", "$", "controller", "[", "'path'", "]", ",", "strlen", "(", "ROOT", ".", "DS", ".", "'src'", ".", "DS", ".", "'Controller'", ")", "+", "1", ")", ")", ";", "array_pop", "(", "$", "namespaceParts", ")", ";", "$", "namespace", "=", "join", "(", "'/'", ",", "$", "namespaceParts", ")", ";", "if", "(", "!", "empty", "(", "$", "namespace", ")", ")", "{", "$", "path", "=", "\"App.{$namespace}/{$controller['name']}.{$action}\"", ";", "}", "else", "{", "$", "path", "=", "\"App.{$controller['name']}.{$action}\"", ";", "}", "if", "(", "in_array", "(", "$", "path", ",", "$", "this", "->", "_guestActions", ")", ")", "{", "continue", ";", "}", "$", "actionMap", "[", "$", "path", "]", "=", "[", "'plugin'", "=>", "'App'", ",", "'controller'", "=>", "!", "empty", "(", "$", "namespace", ")", "?", "$", "namespace", ".", "'/'", ".", "$", "controller", "[", "'name'", "]", ":", "$", "controller", "[", "'name'", "]", ",", "'action'", "=>", "$", "action", "]", ";", "}", "}", "}", "return", "$", "actionMap", ";", "}" ]
Get a mapped array of all guardable controller actions excluding the provided guest actions. @return array
[ "Get", "a", "mapped", "array", "of", "all", "guardable", "controller", "actions", "excluding", "the", "provided", "guest", "actions", "." ]
0eadbb64d2fc201bacc63c93814adeca70e08f90
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Controller/Component/GuardianComponent.php#L257-L323
237,430
wasabi-cms/core
src/Controller/Component/GuardianComponent.php
GuardianComponent.getLoadedPluginPaths
public function getLoadedPluginPaths() { $pluginPaths = []; $plugins = Plugin::loaded() ?? []; foreach ($plugins as $p) { // @TODO load active plugins from plugin manager if (in_array($p, ['DebugKit', 'Migrations'])) { continue; } $pluginPaths[$p] = Plugin::path($p); } return $pluginPaths; }
php
public function getLoadedPluginPaths() { $pluginPaths = []; $plugins = Plugin::loaded() ?? []; foreach ($plugins as $p) { // @TODO load active plugins from plugin manager if (in_array($p, ['DebugKit', 'Migrations'])) { continue; } $pluginPaths[$p] = Plugin::path($p); } return $pluginPaths; }
[ "public", "function", "getLoadedPluginPaths", "(", ")", "{", "$", "pluginPaths", "=", "[", "]", ";", "$", "plugins", "=", "Plugin", "::", "loaded", "(", ")", "??", "[", "]", ";", "foreach", "(", "$", "plugins", "as", "$", "p", ")", "{", "// @TODO load active plugins from plugin manager", "if", "(", "in_array", "(", "$", "p", ",", "[", "'DebugKit'", ",", "'Migrations'", "]", ")", ")", "{", "continue", ";", "}", "$", "pluginPaths", "[", "$", "p", "]", "=", "Plugin", "::", "path", "(", "$", "p", ")", ";", "}", "return", "$", "pluginPaths", ";", "}" ]
Get the paths of all installed and active plugins. @return array
[ "Get", "the", "paths", "of", "all", "installed", "and", "active", "plugins", "." ]
0eadbb64d2fc201bacc63c93814adeca70e08f90
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Controller/Component/GuardianComponent.php#L330-L344
237,431
wasabi-cms/core
src/Controller/Component/GuardianComponent.php
GuardianComponent.getControllersForPlugin
public function getControllersForPlugin($plugin, $pluginPath) { $controllers = []; $Folder = new Folder(); $ctrlFolder = $Folder->cd($pluginPath . DS . 'src' . DS . 'Controller'); if (!empty($ctrlFolder)) { $files = $Folder->find('.*Controller\.php$'); $subLength = strlen('Controller.php'); foreach ($files as $f) { $filename = basename($f); if ($filename === $plugin . 'AppController.php') { continue; } $ctrlName = substr($filename, 0, strlen($filename) - $subLength); $controllers[] = [ 'name' => $ctrlName, 'path' => $Folder->path . DS . $f ]; } } return $controllers; }
php
public function getControllersForPlugin($plugin, $pluginPath) { $controllers = []; $Folder = new Folder(); $ctrlFolder = $Folder->cd($pluginPath . DS . 'src' . DS . 'Controller'); if (!empty($ctrlFolder)) { $files = $Folder->find('.*Controller\.php$'); $subLength = strlen('Controller.php'); foreach ($files as $f) { $filename = basename($f); if ($filename === $plugin . 'AppController.php') { continue; } $ctrlName = substr($filename, 0, strlen($filename) - $subLength); $controllers[] = [ 'name' => $ctrlName, 'path' => $Folder->path . DS . $f ]; } } return $controllers; }
[ "public", "function", "getControllersForPlugin", "(", "$", "plugin", ",", "$", "pluginPath", ")", "{", "$", "controllers", "=", "[", "]", ";", "$", "Folder", "=", "new", "Folder", "(", ")", ";", "$", "ctrlFolder", "=", "$", "Folder", "->", "cd", "(", "$", "pluginPath", ".", "DS", ".", "'src'", ".", "DS", ".", "'Controller'", ")", ";", "if", "(", "!", "empty", "(", "$", "ctrlFolder", ")", ")", "{", "$", "files", "=", "$", "Folder", "->", "find", "(", "'.*Controller\\.php$'", ")", ";", "$", "subLength", "=", "strlen", "(", "'Controller.php'", ")", ";", "foreach", "(", "$", "files", "as", "$", "f", ")", "{", "$", "filename", "=", "basename", "(", "$", "f", ")", ";", "if", "(", "$", "filename", "===", "$", "plugin", ".", "'AppController.php'", ")", "{", "continue", ";", "}", "$", "ctrlName", "=", "substr", "(", "$", "filename", ",", "0", ",", "strlen", "(", "$", "filename", ")", "-", "$", "subLength", ")", ";", "$", "controllers", "[", "]", "=", "[", "'name'", "=>", "$", "ctrlName", ",", "'path'", "=>", "$", "Folder", "->", "path", ".", "DS", ".", "$", "f", "]", ";", "}", "}", "return", "$", "controllers", ";", "}" ]
Retrieve all controller names + paths for a given plugin. @param string $plugin The name of the plugin. @param string $pluginPath The path of the plugin. @return array @todo: Refactor https://scrutinizer-ci.com/g/wasabi-cms/core/indices/834500/duplications/543470
[ "Retrieve", "all", "controller", "names", "+", "paths", "for", "a", "given", "plugin", "." ]
0eadbb64d2fc201bacc63c93814adeca70e08f90
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Controller/Component/GuardianComponent.php#L354-L378
237,432
wasabi-cms/core
src/Controller/Component/GuardianComponent.php
GuardianComponent.getControllersForApp
public function getControllersForApp() { $controllers = []; $ctrlFolder = new Folder(); /** @var Folder $ctrlFolder */ $ctrlFolder->cd(ROOT . DS . 'src' . DS . 'Controller'); if (!empty($ctrlFolder)) { $files = $ctrlFolder->find('.*Controller\.php$'); $subLength = strlen('Controller.php'); foreach ($files as $f) { $filename = basename($f); if ($filename === 'AppController.php') { continue; } $ctrlName = substr($filename, 0, strlen($filename) - $subLength); $controllers[] = [ 'name' => $ctrlName, 'path' => $ctrlFolder->path . DS . $f ]; } $subFolders = $ctrlFolder->read(true, false, true)[0]; foreach ($subFolders as $subFolder) { $ctrlFolder->cd($subFolder); $files = $ctrlFolder->find('.*Controller\.php$'); $subLength = strlen('Controller.php'); foreach ($files as $f) { $filename = basename($f); if ($filename === 'AppController.php') { continue; } $ctrlName = substr($filename, 0, strlen($filename) - $subLength); $controllers[] = [ 'name' => $ctrlName, 'path' => $ctrlFolder->path . DS . $f ]; } } } return $controllers; }
php
public function getControllersForApp() { $controllers = []; $ctrlFolder = new Folder(); /** @var Folder $ctrlFolder */ $ctrlFolder->cd(ROOT . DS . 'src' . DS . 'Controller'); if (!empty($ctrlFolder)) { $files = $ctrlFolder->find('.*Controller\.php$'); $subLength = strlen('Controller.php'); foreach ($files as $f) { $filename = basename($f); if ($filename === 'AppController.php') { continue; } $ctrlName = substr($filename, 0, strlen($filename) - $subLength); $controllers[] = [ 'name' => $ctrlName, 'path' => $ctrlFolder->path . DS . $f ]; } $subFolders = $ctrlFolder->read(true, false, true)[0]; foreach ($subFolders as $subFolder) { $ctrlFolder->cd($subFolder); $files = $ctrlFolder->find('.*Controller\.php$'); $subLength = strlen('Controller.php'); foreach ($files as $f) { $filename = basename($f); if ($filename === 'AppController.php') { continue; } $ctrlName = substr($filename, 0, strlen($filename) - $subLength); $controllers[] = [ 'name' => $ctrlName, 'path' => $ctrlFolder->path . DS . $f ]; } } } return $controllers; }
[ "public", "function", "getControllersForApp", "(", ")", "{", "$", "controllers", "=", "[", "]", ";", "$", "ctrlFolder", "=", "new", "Folder", "(", ")", ";", "/** @var Folder $ctrlFolder */", "$", "ctrlFolder", "->", "cd", "(", "ROOT", ".", "DS", ".", "'src'", ".", "DS", ".", "'Controller'", ")", ";", "if", "(", "!", "empty", "(", "$", "ctrlFolder", ")", ")", "{", "$", "files", "=", "$", "ctrlFolder", "->", "find", "(", "'.*Controller\\.php$'", ")", ";", "$", "subLength", "=", "strlen", "(", "'Controller.php'", ")", ";", "foreach", "(", "$", "files", "as", "$", "f", ")", "{", "$", "filename", "=", "basename", "(", "$", "f", ")", ";", "if", "(", "$", "filename", "===", "'AppController.php'", ")", "{", "continue", ";", "}", "$", "ctrlName", "=", "substr", "(", "$", "filename", ",", "0", ",", "strlen", "(", "$", "filename", ")", "-", "$", "subLength", ")", ";", "$", "controllers", "[", "]", "=", "[", "'name'", "=>", "$", "ctrlName", ",", "'path'", "=>", "$", "ctrlFolder", "->", "path", ".", "DS", ".", "$", "f", "]", ";", "}", "$", "subFolders", "=", "$", "ctrlFolder", "->", "read", "(", "true", ",", "false", ",", "true", ")", "[", "0", "]", ";", "foreach", "(", "$", "subFolders", "as", "$", "subFolder", ")", "{", "$", "ctrlFolder", "->", "cd", "(", "$", "subFolder", ")", ";", "$", "files", "=", "$", "ctrlFolder", "->", "find", "(", "'.*Controller\\.php$'", ")", ";", "$", "subLength", "=", "strlen", "(", "'Controller.php'", ")", ";", "foreach", "(", "$", "files", "as", "$", "f", ")", "{", "$", "filename", "=", "basename", "(", "$", "f", ")", ";", "if", "(", "$", "filename", "===", "'AppController.php'", ")", "{", "continue", ";", "}", "$", "ctrlName", "=", "substr", "(", "$", "filename", ",", "0", ",", "strlen", "(", "$", "filename", ")", "-", "$", "subLength", ")", ";", "$", "controllers", "[", "]", "=", "[", "'name'", "=>", "$", "ctrlName", ",", "'path'", "=>", "$", "ctrlFolder", "->", "path", ".", "DS", ".", "$", "f", "]", ";", "}", "}", "}", "return", "$", "controllers", ";", "}" ]
Retrieve all controller names + paths for the app src. @return array
[ "Retrieve", "all", "controller", "names", "+", "paths", "for", "the", "app", "src", "." ]
0eadbb64d2fc201bacc63c93814adeca70e08f90
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Controller/Component/GuardianComponent.php#L385-L427
237,433
wasabi-cms/core
src/Controller/Component/GuardianComponent.php
GuardianComponent.introspectController
public function introspectController($controllerPath) { $content = file_get_contents($controllerPath); preg_match_all('/public\s+function\s+\&?\s*([^(]+)/', $content, $methods); $guardableActions = []; foreach ($methods[1] as $m) { if (in_array($m, ['__construct', 'initialize', 'isAuthorized', 'setRequest', 'invokeAction', 'beforeFilter', 'beforeRender', 'beforeRedirect', 'afterFilter'])) { continue; } $guardableActions[] = $m; } return $guardableActions; }
php
public function introspectController($controllerPath) { $content = file_get_contents($controllerPath); preg_match_all('/public\s+function\s+\&?\s*([^(]+)/', $content, $methods); $guardableActions = []; foreach ($methods[1] as $m) { if (in_array($m, ['__construct', 'initialize', 'isAuthorized', 'setRequest', 'invokeAction', 'beforeFilter', 'beforeRender', 'beforeRedirect', 'afterFilter'])) { continue; } $guardableActions[] = $m; } return $guardableActions; }
[ "public", "function", "introspectController", "(", "$", "controllerPath", ")", "{", "$", "content", "=", "file_get_contents", "(", "$", "controllerPath", ")", ";", "preg_match_all", "(", "'/public\\s+function\\s+\\&?\\s*([^(]+)/'", ",", "$", "content", ",", "$", "methods", ")", ";", "$", "guardableActions", "=", "[", "]", ";", "foreach", "(", "$", "methods", "[", "1", "]", "as", "$", "m", ")", "{", "if", "(", "in_array", "(", "$", "m", ",", "[", "'__construct'", ",", "'initialize'", ",", "'isAuthorized'", ",", "'setRequest'", ",", "'invokeAction'", ",", "'beforeFilter'", ",", "'beforeRender'", ",", "'beforeRedirect'", ",", "'afterFilter'", "]", ")", ")", "{", "continue", ";", "}", "$", "guardableActions", "[", "]", "=", "$", "m", ";", "}", "return", "$", "guardableActions", ";", "}" ]
Retrieve all controller actions from a given controller. @param string $controllerPath The path of a specific controller. @return array
[ "Retrieve", "all", "controller", "actions", "from", "a", "given", "controller", "." ]
0eadbb64d2fc201bacc63c93814adeca70e08f90
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Controller/Component/GuardianComponent.php#L435-L449
237,434
wasabi-cms/core
src/Controller/Component/GuardianComponent.php
GuardianComponent._getGroupPermissions
protected function _getGroupPermissions() { if (get_class($this->GroupPermissions) === 'GroupPermission') { return $this->GroupPermissions; } return $this->GroupPermissions = TableRegistry::get('Wasabi/Core.GroupPermissions'); }
php
protected function _getGroupPermissions() { if (get_class($this->GroupPermissions) === 'GroupPermission') { return $this->GroupPermissions; } return $this->GroupPermissions = TableRegistry::get('Wasabi/Core.GroupPermissions'); }
[ "protected", "function", "_getGroupPermissions", "(", ")", "{", "if", "(", "get_class", "(", "$", "this", "->", "GroupPermissions", ")", "===", "'GroupPermission'", ")", "{", "return", "$", "this", "->", "GroupPermissions", ";", "}", "return", "$", "this", "->", "GroupPermissions", "=", "TableRegistry", "::", "get", "(", "'Wasabi/Core.GroupPermissions'", ")", ";", "}" ]
Get or initialize an instance of the GroupPermissionsTable. @return GroupPermissionsTable
[ "Get", "or", "initialize", "an", "instance", "of", "the", "GroupPermissionsTable", "." ]
0eadbb64d2fc201bacc63c93814adeca70e08f90
https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/Controller/Component/GuardianComponent.php#L456-L462
237,435
webriq/core
module/Core/src/Grid/Core/Model/Captcha.php
Captcha.isValid
public function isValid( $id, $value, $context = null ) { return $this->createRegeneratable( array( 'id' => $id ) ) ->isValid( $value, $context ); }
php
public function isValid( $id, $value, $context = null ) { return $this->createRegeneratable( array( 'id' => $id ) ) ->isValid( $value, $context ); }
[ "public", "function", "isValid", "(", "$", "id", ",", "$", "value", ",", "$", "context", "=", "null", ")", "{", "return", "$", "this", "->", "createRegeneratable", "(", "array", "(", "'id'", "=>", "$", "id", ")", ")", "->", "isValid", "(", "$", "value", ",", "$", "context", ")", ";", "}" ]
A captcha is valid by id @param string $id @param string $value @param array|object $context @return bool
[ "A", "captcha", "is", "valid", "by", "id" ]
cfeb6e8a4732561c2215ec94e736c07f9b8bc990
https://github.com/webriq/core/blob/cfeb6e8a4732561c2215ec94e736c07f9b8bc990/module/Core/src/Grid/Core/Model/Captcha.php#L50-L54
237,436
narrowspark/automatic-common
Traits/PhpFileMarkerTrait.php
PhpFileMarkerTrait.isFileMarked
protected function isFileMarked(string $packageName, string $file): bool { return \is_file($file) && \strpos(\file_get_contents($file), \sprintf('/** > %s **/', $packageName)) !== false; }
php
protected function isFileMarked(string $packageName, string $file): bool { return \is_file($file) && \strpos(\file_get_contents($file), \sprintf('/** > %s **/', $packageName)) !== false; }
[ "protected", "function", "isFileMarked", "(", "string", "$", "packageName", ",", "string", "$", "file", ")", ":", "bool", "{", "return", "\\", "is_file", "(", "$", "file", ")", "&&", "\\", "strpos", "(", "\\", "file_get_contents", "(", "$", "file", ")", ",", "\\", "sprintf", "(", "'/** > %s **/'", ",", "$", "packageName", ")", ")", "!==", "false", ";", "}" ]
Check if file is marked. @param string $packageName @param string $file @return bool
[ "Check", "if", "file", "is", "marked", "." ]
415f0d566932847c3ca799e06f27e588bd244881
https://github.com/narrowspark/automatic-common/blob/415f0d566932847c3ca799e06f27e588bd244881/Traits/PhpFileMarkerTrait.php#L15-L18
237,437
digipolisgent/openbib-id-api
src/Consumer/BibConsumer.php
BibConsumer.doRequest
protected function doRequest(Client $client, $url, $options = array()) { $options += array( 'urlParams' => array(), 'queryParams' => array(), 'method' => static::METHOD_GET, ); $token = $client->getToken(); // Replace parameters in the url. $urlReplacements = $this->getParameterReplacements($options['urlParams'], $token); $url = str_replace(array_keys($urlReplacements), array_values($urlReplacements), $url); // Replace query parameters. $queryReplacements = $this->getParameterReplacements($options['queryParams'], $token); $queryParams = array_merge($options['queryParams'], $queryReplacements); // Process query parameters. $queryParams = $this->processQueryParameters($queryParams); // Set the request uri. $client->setUri($this->credentials->getEnvironment()->getBaseUrl() . $url); // Set the parameters. switch ($options['method']) { case static::METHOD_POST: $client->setParameterPost($queryParams); break; case static::METHOD_GET: default: $client->setParameterGet($queryParams); break; } // Set the request method and send the request. $client->setMethod($options['method']); $response = $client->send(); // Below are all possible error codes as described bij de api // documentation. $statusCode = $response->getStatusCode(); switch ($statusCode) { // No content. case 204: return null; // Bad request. case 400: // Missing Authorization header. case 401: // Unauthorized. case 403: // Not found. case 404: // Misdirected request. case 421: // Any other undocumented error codes. case $statusCode >= 400: throw new BibException($response->getReasonPhrase(), $response->getStatusCode()); } $doc = new \DOMDocument(); $doc->loadXML($response->getBody()); return $doc; }
php
protected function doRequest(Client $client, $url, $options = array()) { $options += array( 'urlParams' => array(), 'queryParams' => array(), 'method' => static::METHOD_GET, ); $token = $client->getToken(); // Replace parameters in the url. $urlReplacements = $this->getParameterReplacements($options['urlParams'], $token); $url = str_replace(array_keys($urlReplacements), array_values($urlReplacements), $url); // Replace query parameters. $queryReplacements = $this->getParameterReplacements($options['queryParams'], $token); $queryParams = array_merge($options['queryParams'], $queryReplacements); // Process query parameters. $queryParams = $this->processQueryParameters($queryParams); // Set the request uri. $client->setUri($this->credentials->getEnvironment()->getBaseUrl() . $url); // Set the parameters. switch ($options['method']) { case static::METHOD_POST: $client->setParameterPost($queryParams); break; case static::METHOD_GET: default: $client->setParameterGet($queryParams); break; } // Set the request method and send the request. $client->setMethod($options['method']); $response = $client->send(); // Below are all possible error codes as described bij de api // documentation. $statusCode = $response->getStatusCode(); switch ($statusCode) { // No content. case 204: return null; // Bad request. case 400: // Missing Authorization header. case 401: // Unauthorized. case 403: // Not found. case 404: // Misdirected request. case 421: // Any other undocumented error codes. case $statusCode >= 400: throw new BibException($response->getReasonPhrase(), $response->getStatusCode()); } $doc = new \DOMDocument(); $doc->loadXML($response->getBody()); return $doc; }
[ "protected", "function", "doRequest", "(", "Client", "$", "client", ",", "$", "url", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "options", "+=", "array", "(", "'urlParams'", "=>", "array", "(", ")", ",", "'queryParams'", "=>", "array", "(", ")", ",", "'method'", "=>", "static", "::", "METHOD_GET", ",", ")", ";", "$", "token", "=", "$", "client", "->", "getToken", "(", ")", ";", "// Replace parameters in the url.", "$", "urlReplacements", "=", "$", "this", "->", "getParameterReplacements", "(", "$", "options", "[", "'urlParams'", "]", ",", "$", "token", ")", ";", "$", "url", "=", "str_replace", "(", "array_keys", "(", "$", "urlReplacements", ")", ",", "array_values", "(", "$", "urlReplacements", ")", ",", "$", "url", ")", ";", "// Replace query parameters.", "$", "queryReplacements", "=", "$", "this", "->", "getParameterReplacements", "(", "$", "options", "[", "'queryParams'", "]", ",", "$", "token", ")", ";", "$", "queryParams", "=", "array_merge", "(", "$", "options", "[", "'queryParams'", "]", ",", "$", "queryReplacements", ")", ";", "// Process query parameters.", "$", "queryParams", "=", "$", "this", "->", "processQueryParameters", "(", "$", "queryParams", ")", ";", "// Set the request uri.", "$", "client", "->", "setUri", "(", "$", "this", "->", "credentials", "->", "getEnvironment", "(", ")", "->", "getBaseUrl", "(", ")", ".", "$", "url", ")", ";", "// Set the parameters.", "switch", "(", "$", "options", "[", "'method'", "]", ")", "{", "case", "static", "::", "METHOD_POST", ":", "$", "client", "->", "setParameterPost", "(", "$", "queryParams", ")", ";", "break", ";", "case", "static", "::", "METHOD_GET", ":", "default", ":", "$", "client", "->", "setParameterGet", "(", "$", "queryParams", ")", ";", "break", ";", "}", "// Set the request method and send the request.", "$", "client", "->", "setMethod", "(", "$", "options", "[", "'method'", "]", ")", ";", "$", "response", "=", "$", "client", "->", "send", "(", ")", ";", "// Below are all possible error codes as described bij de api", "// documentation.", "$", "statusCode", "=", "$", "response", "->", "getStatusCode", "(", ")", ";", "switch", "(", "$", "statusCode", ")", "{", "// No content.", "case", "204", ":", "return", "null", ";", "// Bad request.", "case", "400", ":", "// Missing Authorization header.", "case", "401", ":", "// Unauthorized.", "case", "403", ":", "// Not found.", "case", "404", ":", "// Misdirected request.", "case", "421", ":", "// Any other undocumented error codes.", "case", "$", "statusCode", ">=", "400", ":", "throw", "new", "BibException", "(", "$", "response", "->", "getReasonPhrase", "(", ")", ",", "$", "response", "->", "getStatusCode", "(", ")", ")", ";", "}", "$", "doc", "=", "new", "\\", "DOMDocument", "(", ")", ";", "$", "doc", "->", "loadXML", "(", "$", "response", "->", "getBody", "(", ")", ")", ";", "return", "$", "doc", ";", "}" ]
Executes a request. @param \ZendOAuth\Client $client The client that will execute the request. @param string $url The URL to request. @param array $options An array of options: - urlParams: An array of replacements for the url: $url: 'https://mijn.bibliotheek.be/openbibid/rest/library/id/:id' urlParams: [':id' => 2199] Values between {} are taken from the access token: $url: 'https://mijn.bibliotheek.be/openbibid/rest/user/info/:userId' urlParams: [':userId' => '{userId}'] - queryParams: An array of query parameters for GET requests or POST data for POST requests. - method: One of the \Zend\Http\Request::METHOD_* constants. @return \DOMDocument|null A \DOMDocument containing the XML from the response, null if HTTP status code 204 (No content) was returned. @throws \OpenBibIdApi\Exception\BibException When any of the 400, 401, 403, 404 or 421 status codes were returned.
[ "Executes", "a", "request", "." ]
79f58dec53a91f44333d10fa4ef79f85f31fc2de
https://github.com/digipolisgent/openbib-id-api/blob/79f58dec53a91f44333d10fa4ef79f85f31fc2de/src/Consumer/BibConsumer.php#L227-L290
237,438
digipolisgent/openbib-id-api
src/Consumer/BibConsumer.php
BibConsumer.getParameterReplacements
protected function getParameterReplacements($parameters, TokenInterface $token) { $replacements = $parameters; foreach ($parameters as $key => $param) { if (strpos($param, '{') === 0 && strpos($param, '}') === strlen($param) - 1) { $replacements[$key] = $token->getParam(substr($param, 1, -1)); } } return $replacements; }
php
protected function getParameterReplacements($parameters, TokenInterface $token) { $replacements = $parameters; foreach ($parameters as $key => $param) { if (strpos($param, '{') === 0 && strpos($param, '}') === strlen($param) - 1) { $replacements[$key] = $token->getParam(substr($param, 1, -1)); } } return $replacements; }
[ "protected", "function", "getParameterReplacements", "(", "$", "parameters", ",", "TokenInterface", "$", "token", ")", "{", "$", "replacements", "=", "$", "parameters", ";", "foreach", "(", "$", "parameters", "as", "$", "key", "=>", "$", "param", ")", "{", "if", "(", "strpos", "(", "$", "param", ",", "'{'", ")", "===", "0", "&&", "strpos", "(", "$", "param", ",", "'}'", ")", "===", "strlen", "(", "$", "param", ")", "-", "1", ")", "{", "$", "replacements", "[", "$", "key", "]", "=", "$", "token", "->", "getParam", "(", "substr", "(", "$", "param", ",", "1", ",", "-", "1", ")", ")", ";", "}", "}", "return", "$", "replacements", ";", "}" ]
Replace values in an array with parameters from a token. @param array $parameters An array with parameters to replace. Values surrounded with {} will be replaced with their corresponding token parameter. @param \ZendOAuth\Token\TokenInterface $token The token with the parameters. @return array An array of replacements, keyed by the corresponding array key in $parameters.
[ "Replace", "values", "in", "an", "array", "with", "parameters", "from", "a", "token", "." ]
79f58dec53a91f44333d10fa4ef79f85f31fc2de
https://github.com/digipolisgent/openbib-id-api/blob/79f58dec53a91f44333d10fa4ef79f85f31fc2de/src/Consumer/BibConsumer.php#L305-L314
237,439
digipolisgent/openbib-id-api
src/Consumer/BibConsumer.php
BibConsumer.fetchRequestToken
protected function fetchRequestToken() { // Fetching a new request token. Remove any old access tokens. $this->storage->delete(static::BIB_ACCESS_TOKEN); // Fetch a request token. $token = $this->consumer->getRequestToken(); // Persist the token to storage. $this->storage->set(static::BIB_REQUEST_TOKEN, $token); return $this; }
php
protected function fetchRequestToken() { // Fetching a new request token. Remove any old access tokens. $this->storage->delete(static::BIB_ACCESS_TOKEN); // Fetch a request token. $token = $this->consumer->getRequestToken(); // Persist the token to storage. $this->storage->set(static::BIB_REQUEST_TOKEN, $token); return $this; }
[ "protected", "function", "fetchRequestToken", "(", ")", "{", "// Fetching a new request token. Remove any old access tokens.", "$", "this", "->", "storage", "->", "delete", "(", "static", "::", "BIB_ACCESS_TOKEN", ")", ";", "// Fetch a request token.", "$", "token", "=", "$", "this", "->", "consumer", "->", "getRequestToken", "(", ")", ";", "// Persist the token to storage.", "$", "this", "->", "storage", "->", "set", "(", "static", "::", "BIB_REQUEST_TOKEN", ",", "$", "token", ")", ";", "return", "$", "this", ";", "}" ]
Fetches the request token. @return $this
[ "Fetches", "the", "request", "token", "." ]
79f58dec53a91f44333d10fa4ef79f85f31fc2de
https://github.com/digipolisgent/openbib-id-api/blob/79f58dec53a91f44333d10fa4ef79f85f31fc2de/src/Consumer/BibConsumer.php#L321-L331
237,440
digipolisgent/openbib-id-api
src/Consumer/BibConsumer.php
BibConsumer.fetchAccessToken
protected function fetchAccessToken($queryData, $retry = true) { if (!$this->hasRequestToken()) { $this->consumer->setCallbackUrl($this->getCurrentUri()); $this->fetchRequestToken(); $this->consumer->redirect(array('hint' => $this->getHint())); } try { $token = $this->consumer->getAccessToken( $queryData, $this->getRequestToken() ); } catch (InvalidArgumentException $e) { if ($retry) { // We might have a corrupt/invalid request token. Delete it and // retry once. $this->storage->delete(static::BIB_REQUEST_TOKEN); $this->storage->delete(static::BIB_ACCESS_TOKEN); return $this->fetchAccessToken($queryData, false); } throw $e; } // We got a new access token, we can remove the request token now. $this->storage->delete(static::BIB_REQUEST_TOKEN); $this->storage->set(static::BIB_ACCESS_TOKEN, $token); return $this; }
php
protected function fetchAccessToken($queryData, $retry = true) { if (!$this->hasRequestToken()) { $this->consumer->setCallbackUrl($this->getCurrentUri()); $this->fetchRequestToken(); $this->consumer->redirect(array('hint' => $this->getHint())); } try { $token = $this->consumer->getAccessToken( $queryData, $this->getRequestToken() ); } catch (InvalidArgumentException $e) { if ($retry) { // We might have a corrupt/invalid request token. Delete it and // retry once. $this->storage->delete(static::BIB_REQUEST_TOKEN); $this->storage->delete(static::BIB_ACCESS_TOKEN); return $this->fetchAccessToken($queryData, false); } throw $e; } // We got a new access token, we can remove the request token now. $this->storage->delete(static::BIB_REQUEST_TOKEN); $this->storage->set(static::BIB_ACCESS_TOKEN, $token); return $this; }
[ "protected", "function", "fetchAccessToken", "(", "$", "queryData", ",", "$", "retry", "=", "true", ")", "{", "if", "(", "!", "$", "this", "->", "hasRequestToken", "(", ")", ")", "{", "$", "this", "->", "consumer", "->", "setCallbackUrl", "(", "$", "this", "->", "getCurrentUri", "(", ")", ")", ";", "$", "this", "->", "fetchRequestToken", "(", ")", ";", "$", "this", "->", "consumer", "->", "redirect", "(", "array", "(", "'hint'", "=>", "$", "this", "->", "getHint", "(", ")", ")", ")", ";", "}", "try", "{", "$", "token", "=", "$", "this", "->", "consumer", "->", "getAccessToken", "(", "$", "queryData", ",", "$", "this", "->", "getRequestToken", "(", ")", ")", ";", "}", "catch", "(", "InvalidArgumentException", "$", "e", ")", "{", "if", "(", "$", "retry", ")", "{", "// We might have a corrupt/invalid request token. Delete it and", "// retry once.", "$", "this", "->", "storage", "->", "delete", "(", "static", "::", "BIB_REQUEST_TOKEN", ")", ";", "$", "this", "->", "storage", "->", "delete", "(", "static", "::", "BIB_ACCESS_TOKEN", ")", ";", "return", "$", "this", "->", "fetchAccessToken", "(", "$", "queryData", ",", "false", ")", ";", "}", "throw", "$", "e", ";", "}", "// We got a new access token, we can remove the request token now.", "$", "this", "->", "storage", "->", "delete", "(", "static", "::", "BIB_REQUEST_TOKEN", ")", ";", "$", "this", "->", "storage", "->", "set", "(", "static", "::", "BIB_ACCESS_TOKEN", ",", "$", "token", ")", ";", "return", "$", "this", ";", "}" ]
Fetches the access token. @param array $queryData GET data returned in user's redirect from Provider. @param bool $retry Internal use only. @return $this @throws \ZendOAuth\Exception\InvalidArgumentException On invalid authorization token.
[ "Fetches", "the", "access", "token", "." ]
79f58dec53a91f44333d10fa4ef79f85f31fc2de
https://github.com/digipolisgent/openbib-id-api/blob/79f58dec53a91f44333d10fa4ef79f85f31fc2de/src/Consumer/BibConsumer.php#L346-L373
237,441
digipolisgent/openbib-id-api
src/Consumer/BibConsumer.php
BibConsumer.getCurrentUri
protected function getCurrentUri() { $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : false; if (!$uri) { $uri = $_SERVER['SCRIPT_NAME']; if (isset($_SERVER['argv']) || isset($_SERVER['QUERY_STRING'])) { $uri .= '?'; $uri .= isset($_SERVER['argv']) ? $_SERVER['argv'][0] : $_SERVER['QUERY_STRING']; } } return 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . '/' . ltrim($uri, '/'); }
php
protected function getCurrentUri() { $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : false; if (!$uri) { $uri = $_SERVER['SCRIPT_NAME']; if (isset($_SERVER['argv']) || isset($_SERVER['QUERY_STRING'])) { $uri .= '?'; $uri .= isset($_SERVER['argv']) ? $_SERVER['argv'][0] : $_SERVER['QUERY_STRING']; } } return 'http' . (isset($_SERVER['HTTPS']) ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . '/' . ltrim($uri, '/'); }
[ "protected", "function", "getCurrentUri", "(", ")", "{", "$", "uri", "=", "isset", "(", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", "?", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ":", "false", ";", "if", "(", "!", "$", "uri", ")", "{", "$", "uri", "=", "$", "_SERVER", "[", "'SCRIPT_NAME'", "]", ";", "if", "(", "isset", "(", "$", "_SERVER", "[", "'argv'", "]", ")", "||", "isset", "(", "$", "_SERVER", "[", "'QUERY_STRING'", "]", ")", ")", "{", "$", "uri", ".=", "'?'", ";", "$", "uri", ".=", "isset", "(", "$", "_SERVER", "[", "'argv'", "]", ")", "?", "$", "_SERVER", "[", "'argv'", "]", "[", "0", "]", ":", "$", "_SERVER", "[", "'QUERY_STRING'", "]", ";", "}", "}", "return", "'http'", ".", "(", "isset", "(", "$", "_SERVER", "[", "'HTTPS'", "]", ")", "?", "'s'", ":", "''", ")", ".", "'://'", ".", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ".", "'/'", ".", "ltrim", "(", "$", "uri", ",", "'/'", ")", ";", "}" ]
Gets the current uri. @return string The current uri.
[ "Gets", "the", "current", "uri", "." ]
79f58dec53a91f44333d10fa4ef79f85f31fc2de
https://github.com/digipolisgent/openbib-id-api/blob/79f58dec53a91f44333d10fa4ef79f85f31fc2de/src/Consumer/BibConsumer.php#L425-L445
237,442
digipolisgent/openbib-id-api
src/Consumer/BibConsumer.php
BibConsumer.processQueryParameters
protected function processQueryParameters($queryParams) { foreach ($queryParams as $name => $value) { if (is_bool($value)) { $queryParams[$name] = $value ? 'true' : 'false'; } } return $queryParams; }
php
protected function processQueryParameters($queryParams) { foreach ($queryParams as $name => $value) { if (is_bool($value)) { $queryParams[$name] = $value ? 'true' : 'false'; } } return $queryParams; }
[ "protected", "function", "processQueryParameters", "(", "$", "queryParams", ")", "{", "foreach", "(", "$", "queryParams", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "is_bool", "(", "$", "value", ")", ")", "{", "$", "queryParams", "[", "$", "name", "]", "=", "$", "value", "?", "'true'", ":", "'false'", ";", "}", "}", "return", "$", "queryParams", ";", "}" ]
Processes an array of query parameters to a readable format. @param array $queryParams The parameters to be processes. @return array The processed array of query parameters.
[ "Processes", "an", "array", "of", "query", "parameters", "to", "a", "readable", "format", "." ]
79f58dec53a91f44333d10fa4ef79f85f31fc2de
https://github.com/digipolisgent/openbib-id-api/blob/79f58dec53a91f44333d10fa4ef79f85f31fc2de/src/Consumer/BibConsumer.php#L456-L464
237,443
Zeeml/Dataset
src/DataSet.php
DataSet.prepare
public function prepare(Mapper $mapper) { if ($this->isPrepared()) { throw new DataSetPreparationException('DataSet is already prepared'); } //Split each row of the dataSet into inputs and outputs based on the mapper and the policies //Then re-parse the dataSet to fill in all the fields that used special policies (like Avg) and create the instances $this->map($mapper)->createInstances(); //mark the dataSet as prepared $this->isPrepared = true; }
php
public function prepare(Mapper $mapper) { if ($this->isPrepared()) { throw new DataSetPreparationException('DataSet is already prepared'); } //Split each row of the dataSet into inputs and outputs based on the mapper and the policies //Then re-parse the dataSet to fill in all the fields that used special policies (like Avg) and create the instances $this->map($mapper)->createInstances(); //mark the dataSet as prepared $this->isPrepared = true; }
[ "public", "function", "prepare", "(", "Mapper", "$", "mapper", ")", "{", "if", "(", "$", "this", "->", "isPrepared", "(", ")", ")", "{", "throw", "new", "DataSetPreparationException", "(", "'DataSet is already prepared'", ")", ";", "}", "//Split each row of the dataSet into inputs and outputs based on the mapper and the policies", "//Then re-parse the dataSet to fill in all the fields that used special policies (like Avg) and create the instances", "$", "this", "->", "map", "(", "$", "mapper", ")", "->", "createInstances", "(", ")", ";", "//mark the dataSet as prepared", "$", "this", "->", "isPrepared", "=", "true", ";", "}" ]
Prepare data to be trained. MUST be called prior to any call @param Mapper $mapper Data Mapper @throws DataSetPreparationException
[ "Prepare", "data", "to", "be", "trained", ".", "MUST", "be", "called", "prior", "to", "any", "call" ]
8809ba48c99bce1e9fe7e6431be7022e02ff027a
https://github.com/Zeeml/Dataset/blob/8809ba48c99bce1e9fe7e6431be7022e02ff027a/src/DataSet.php#L46-L57
237,444
Zeeml/Dataset
src/DataSet.php
DataSet.map
protected function map(Mapper $mapper): DataSet { $this->mapper = $mapper; $this->instances = $this->inputsMatrix = $this->outputsMatrix = []; foreach ($this->rawData as &$row) { //Split each row of the raw DataSet into inputs and outputs list($inputs, $outputs) = $this->mapper->map($row); //If the mapping was successfully made (the cleaners allowed the row to pass) if ($inputs && $outputs) { //Increment size $this->size++; //Save the inputs matrix $this->inputsMatrix[] = $inputs; $this->numberOfInputs = $this->numberOfInputs ?? count($inputs); //save the output matrix $this->outputsMatrix[] = $outputs; $this->numberOfOutputs = $this->numberOfOutputs ?? count($outputs); } foreach ($row as $key => $value) { //calculate the frequency at which each value occurs $this->frequency[$key][$value] = $this->frequency[$key][$value] ?? 0; $this->frequency[$key][$value]++; //calculate the rawAverage of each column of the raw DataSet, since cleaners might ignore a row $this->rawAverage[$key] = $this->rawAverage[$key] ?? 0; $this->rawAverage[$key] += floatval($value) / $this->rawSize; } } return $this; }
php
protected function map(Mapper $mapper): DataSet { $this->mapper = $mapper; $this->instances = $this->inputsMatrix = $this->outputsMatrix = []; foreach ($this->rawData as &$row) { //Split each row of the raw DataSet into inputs and outputs list($inputs, $outputs) = $this->mapper->map($row); //If the mapping was successfully made (the cleaners allowed the row to pass) if ($inputs && $outputs) { //Increment size $this->size++; //Save the inputs matrix $this->inputsMatrix[] = $inputs; $this->numberOfInputs = $this->numberOfInputs ?? count($inputs); //save the output matrix $this->outputsMatrix[] = $outputs; $this->numberOfOutputs = $this->numberOfOutputs ?? count($outputs); } foreach ($row as $key => $value) { //calculate the frequency at which each value occurs $this->frequency[$key][$value] = $this->frequency[$key][$value] ?? 0; $this->frequency[$key][$value]++; //calculate the rawAverage of each column of the raw DataSet, since cleaners might ignore a row $this->rawAverage[$key] = $this->rawAverage[$key] ?? 0; $this->rawAverage[$key] += floatval($value) / $this->rawSize; } } return $this; }
[ "protected", "function", "map", "(", "Mapper", "$", "mapper", ")", ":", "DataSet", "{", "$", "this", "->", "mapper", "=", "$", "mapper", ";", "$", "this", "->", "instances", "=", "$", "this", "->", "inputsMatrix", "=", "$", "this", "->", "outputsMatrix", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "rawData", "as", "&", "$", "row", ")", "{", "//Split each row of the raw DataSet into inputs and outputs", "list", "(", "$", "inputs", ",", "$", "outputs", ")", "=", "$", "this", "->", "mapper", "->", "map", "(", "$", "row", ")", ";", "//If the mapping was successfully made (the cleaners allowed the row to pass)", "if", "(", "$", "inputs", "&&", "$", "outputs", ")", "{", "//Increment size", "$", "this", "->", "size", "++", ";", "//Save the inputs matrix", "$", "this", "->", "inputsMatrix", "[", "]", "=", "$", "inputs", ";", "$", "this", "->", "numberOfInputs", "=", "$", "this", "->", "numberOfInputs", "??", "count", "(", "$", "inputs", ")", ";", "//save the output matrix", "$", "this", "->", "outputsMatrix", "[", "]", "=", "$", "outputs", ";", "$", "this", "->", "numberOfOutputs", "=", "$", "this", "->", "numberOfOutputs", "??", "count", "(", "$", "outputs", ")", ";", "}", "foreach", "(", "$", "row", "as", "$", "key", "=>", "$", "value", ")", "{", "//calculate the frequency at which each value occurs", "$", "this", "->", "frequency", "[", "$", "key", "]", "[", "$", "value", "]", "=", "$", "this", "->", "frequency", "[", "$", "key", "]", "[", "$", "value", "]", "??", "0", ";", "$", "this", "->", "frequency", "[", "$", "key", "]", "[", "$", "value", "]", "++", ";", "//calculate the rawAverage of each column of the raw DataSet, since cleaners might ignore a row", "$", "this", "->", "rawAverage", "[", "$", "key", "]", "=", "$", "this", "->", "rawAverage", "[", "$", "key", "]", "??", "0", ";", "$", "this", "->", "rawAverage", "[", "$", "key", "]", "+=", "floatval", "(", "$", "value", ")", "/", "$", "this", "->", "rawSize", ";", "}", "}", "return", "$", "this", ";", "}" ]
Is called by the prepare method, maps the data grabbed by the processor into instances objects @param Mapper $mapper @return DataSet
[ "Is", "called", "by", "the", "prepare", "method", "maps", "the", "data", "grabbed", "by", "the", "processor", "into", "instances", "objects" ]
8809ba48c99bce1e9fe7e6431be7022e02ff027a
https://github.com/Zeeml/Dataset/blob/8809ba48c99bce1e9fe7e6431be7022e02ff027a/src/DataSet.php#L64-L97
237,445
osflab/application
OsfApplication.php
OsfApplication.run
public function run() { $this->init(); try { $this->bootstrap(); $this->route(); $this->dispatch(); } catch (Exception $e) { if (APPLICATION_ENV == self::ENV_DEV) { var_dump($e); } else { throw $e; } } return $this; }
php
public function run() { $this->init(); try { $this->bootstrap(); $this->route(); $this->dispatch(); } catch (Exception $e) { if (APPLICATION_ENV == self::ENV_DEV) { var_dump($e); } else { throw $e; } } return $this; }
[ "public", "function", "run", "(", ")", "{", "$", "this", "->", "init", "(", ")", ";", "try", "{", "$", "this", "->", "bootstrap", "(", ")", ";", "$", "this", "->", "route", "(", ")", ";", "$", "this", "->", "dispatch", "(", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "if", "(", "APPLICATION_ENV", "==", "self", "::", "ENV_DEV", ")", "{", "var_dump", "(", "$", "e", ")", ";", "}", "else", "{", "throw", "$", "e", ";", "}", "}", "return", "$", "this", ";", "}" ]
bootstrap + route + dispatch @return $this @throws \Exception
[ "bootstrap", "+", "route", "+", "dispatch" ]
89386523f9749b6b455ecb0be853879b31b1bbf7
https://github.com/osflab/application/blob/89386523f9749b6b455ecb0be853879b31b1bbf7/OsfApplication.php#L56-L71
237,446
osflab/application
OsfApplication.php
OsfApplication.bootstrap
public function bootstrap() { $config = Container::getConfig(); $commonConfigFile = APPLICATION_PATH . '/App/' . Router::getDefaultControllerName(true) . '/Config/application.php'; $config->appendConfig(require $commonConfigFile); $bootstrapFile = APPLICATION_PATH . '/App/' . Router::getDefaultControllerName(true) . '/Bootstrap.php'; if (!file_exists($bootstrapFile)) { throw new ArchException('Bootstrap file ' . $bootstrapFile . ' is needed'); } //self::debug('Begin bootstrap'); Container::getBootstrap()->bootstrap(); //self::debug('End bootstrap'); return $this; }
php
public function bootstrap() { $config = Container::getConfig(); $commonConfigFile = APPLICATION_PATH . '/App/' . Router::getDefaultControllerName(true) . '/Config/application.php'; $config->appendConfig(require $commonConfigFile); $bootstrapFile = APPLICATION_PATH . '/App/' . Router::getDefaultControllerName(true) . '/Bootstrap.php'; if (!file_exists($bootstrapFile)) { throw new ArchException('Bootstrap file ' . $bootstrapFile . ' is needed'); } //self::debug('Begin bootstrap'); Container::getBootstrap()->bootstrap(); //self::debug('End bootstrap'); return $this; }
[ "public", "function", "bootstrap", "(", ")", "{", "$", "config", "=", "Container", "::", "getConfig", "(", ")", ";", "$", "commonConfigFile", "=", "APPLICATION_PATH", ".", "'/App/'", ".", "Router", "::", "getDefaultControllerName", "(", "true", ")", ".", "'/Config/application.php'", ";", "$", "config", "->", "appendConfig", "(", "require", "$", "commonConfigFile", ")", ";", "$", "bootstrapFile", "=", "APPLICATION_PATH", ".", "'/App/'", ".", "Router", "::", "getDefaultControllerName", "(", "true", ")", ".", "'/Bootstrap.php'", ";", "if", "(", "!", "file_exists", "(", "$", "bootstrapFile", ")", ")", "{", "throw", "new", "ArchException", "(", "'Bootstrap file '", ".", "$", "bootstrapFile", ".", "' is needed'", ")", ";", "}", "//self::debug('Begin bootstrap');", "Container", "::", "getBootstrap", "(", ")", "->", "bootstrap", "(", ")", ";", "//self::debug('End bootstrap');", "return", "$", "this", ";", "}" ]
Configuration + Bootstraping @return $this @throws ArchException
[ "Configuration", "+", "Bootstraping" ]
89386523f9749b6b455ecb0be853879b31b1bbf7
https://github.com/osflab/application/blob/89386523f9749b6b455ecb0be853879b31b1bbf7/OsfApplication.php#L101-L115
237,447
osflab/application
OsfApplication.php
OsfApplication.route
public function route() { PluginManager::handleApplicationPlugins(PluginManager::STEP_BEFORE_ROUTE); Container::getRouter()->route(); self::debug('Route: ' . Container::getRouter()->buildUri()); PluginManager::handleApplicationPlugins(PluginManager::STEP_AFTER_ROUTE); return $this; }
php
public function route() { PluginManager::handleApplicationPlugins(PluginManager::STEP_BEFORE_ROUTE); Container::getRouter()->route(); self::debug('Route: ' . Container::getRouter()->buildUri()); PluginManager::handleApplicationPlugins(PluginManager::STEP_AFTER_ROUTE); return $this; }
[ "public", "function", "route", "(", ")", "{", "PluginManager", "::", "handleApplicationPlugins", "(", "PluginManager", "::", "STEP_BEFORE_ROUTE", ")", ";", "Container", "::", "getRouter", "(", ")", "->", "route", "(", ")", ";", "self", "::", "debug", "(", "'Route: '", ".", "Container", "::", "getRouter", "(", ")", "->", "buildUri", "(", ")", ")", ";", "PluginManager", "::", "handleApplicationPlugins", "(", "PluginManager", "::", "STEP_AFTER_ROUTE", ")", ";", "return", "$", "this", ";", "}" ]
Call router before dispatching @return $this
[ "Call", "router", "before", "dispatching" ]
89386523f9749b6b455ecb0be853879b31b1bbf7
https://github.com/osflab/application/blob/89386523f9749b6b455ecb0be853879b31b1bbf7/OsfApplication.php#L121-L128
237,448
osflab/application
OsfApplication.php
OsfApplication.dispatch
public function dispatch() { $request = Container::getRequest(); $response = Container::getResponse(); PluginManager::handleApplicationPlugins(PluginManager::STEP_BEFORE_DISPATCH_LOOP); //self::debug('Begin dispatch loop...'); while (!$this->dispatched) { try { PluginManager::handleApplicationPlugins(PluginManager::STEP_BEFORE_ACTION); //self::debug('Begin dispatch ' . $request->getController() . '::' . $request->getAction() . ' [' . json_encode($request->getParams()) . ']'); $this->dispatchProcess($request, $response); //self::debug('End dispatch ' . $request->getController() . '::' . $request->getAction() . ' [' . json_encode($request->getParams()) . ']'); PluginManager::handleApplicationPlugins(PluginManager::STEP_AFTER_ACTION); } catch (Exception $e) { if ($request->getController(false) == 'event' && $request->getAction(false) == 'error') { throw $e; } Container::getView()->addValue('exception', $e); $this->renderView = true; $request->setController('event')->setAction('error'); $this->setDispatched(false); } } PluginManager::handleApplicationPlugins(PluginManager::STEP_AFTER_DISPATCH_LOOP); self::debug('End dispatch loop'); if ($this->dispatched && $this->renderLayout) { $layout = Container::getConfig()->getConfig('layout'); if ($layout !== null) { if (!file_exists($layout)) { throw new ArchException('Layout file ' . $layout . ' not found'); } $response->setBody(Container::getLayout(true)->render($layout)); } } if ($this->renderResponse) { $response->fixHeaders()->putTypeHeadersInResponse(); foreach ($response->getHeaders() as $header) { header($header); } $response->executeCallback(); if ($response->hasBody()) { echo $response->getBody(); } } return $this; }
php
public function dispatch() { $request = Container::getRequest(); $response = Container::getResponse(); PluginManager::handleApplicationPlugins(PluginManager::STEP_BEFORE_DISPATCH_LOOP); //self::debug('Begin dispatch loop...'); while (!$this->dispatched) { try { PluginManager::handleApplicationPlugins(PluginManager::STEP_BEFORE_ACTION); //self::debug('Begin dispatch ' . $request->getController() . '::' . $request->getAction() . ' [' . json_encode($request->getParams()) . ']'); $this->dispatchProcess($request, $response); //self::debug('End dispatch ' . $request->getController() . '::' . $request->getAction() . ' [' . json_encode($request->getParams()) . ']'); PluginManager::handleApplicationPlugins(PluginManager::STEP_AFTER_ACTION); } catch (Exception $e) { if ($request->getController(false) == 'event' && $request->getAction(false) == 'error') { throw $e; } Container::getView()->addValue('exception', $e); $this->renderView = true; $request->setController('event')->setAction('error'); $this->setDispatched(false); } } PluginManager::handleApplicationPlugins(PluginManager::STEP_AFTER_DISPATCH_LOOP); self::debug('End dispatch loop'); if ($this->dispatched && $this->renderLayout) { $layout = Container::getConfig()->getConfig('layout'); if ($layout !== null) { if (!file_exists($layout)) { throw new ArchException('Layout file ' . $layout . ' not found'); } $response->setBody(Container::getLayout(true)->render($layout)); } } if ($this->renderResponse) { $response->fixHeaders()->putTypeHeadersInResponse(); foreach ($response->getHeaders() as $header) { header($header); } $response->executeCallback(); if ($response->hasBody()) { echo $response->getBody(); } } return $this; }
[ "public", "function", "dispatch", "(", ")", "{", "$", "request", "=", "Container", "::", "getRequest", "(", ")", ";", "$", "response", "=", "Container", "::", "getResponse", "(", ")", ";", "PluginManager", "::", "handleApplicationPlugins", "(", "PluginManager", "::", "STEP_BEFORE_DISPATCH_LOOP", ")", ";", "//self::debug('Begin dispatch loop...');", "while", "(", "!", "$", "this", "->", "dispatched", ")", "{", "try", "{", "PluginManager", "::", "handleApplicationPlugins", "(", "PluginManager", "::", "STEP_BEFORE_ACTION", ")", ";", "//self::debug('Begin dispatch ' . $request->getController() . '::' . $request->getAction() . ' [' . json_encode($request->getParams()) . ']');", "$", "this", "->", "dispatchProcess", "(", "$", "request", ",", "$", "response", ")", ";", "//self::debug('End dispatch ' . $request->getController() . '::' . $request->getAction() . ' [' . json_encode($request->getParams()) . ']');", "PluginManager", "::", "handleApplicationPlugins", "(", "PluginManager", "::", "STEP_AFTER_ACTION", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "if", "(", "$", "request", "->", "getController", "(", "false", ")", "==", "'event'", "&&", "$", "request", "->", "getAction", "(", "false", ")", "==", "'error'", ")", "{", "throw", "$", "e", ";", "}", "Container", "::", "getView", "(", ")", "->", "addValue", "(", "'exception'", ",", "$", "e", ")", ";", "$", "this", "->", "renderView", "=", "true", ";", "$", "request", "->", "setController", "(", "'event'", ")", "->", "setAction", "(", "'error'", ")", ";", "$", "this", "->", "setDispatched", "(", "false", ")", ";", "}", "}", "PluginManager", "::", "handleApplicationPlugins", "(", "PluginManager", "::", "STEP_AFTER_DISPATCH_LOOP", ")", ";", "self", "::", "debug", "(", "'End dispatch loop'", ")", ";", "if", "(", "$", "this", "->", "dispatched", "&&", "$", "this", "->", "renderLayout", ")", "{", "$", "layout", "=", "Container", "::", "getConfig", "(", ")", "->", "getConfig", "(", "'layout'", ")", ";", "if", "(", "$", "layout", "!==", "null", ")", "{", "if", "(", "!", "file_exists", "(", "$", "layout", ")", ")", "{", "throw", "new", "ArchException", "(", "'Layout file '", ".", "$", "layout", ".", "' not found'", ")", ";", "}", "$", "response", "->", "setBody", "(", "Container", "::", "getLayout", "(", "true", ")", "->", "render", "(", "$", "layout", ")", ")", ";", "}", "}", "if", "(", "$", "this", "->", "renderResponse", ")", "{", "$", "response", "->", "fixHeaders", "(", ")", "->", "putTypeHeadersInResponse", "(", ")", ";", "foreach", "(", "$", "response", "->", "getHeaders", "(", ")", "as", "$", "header", ")", "{", "header", "(", "$", "header", ")", ";", "}", "$", "response", "->", "executeCallback", "(", ")", ";", "if", "(", "$", "response", "->", "hasBody", "(", ")", ")", "{", "echo", "$", "response", "->", "getBody", "(", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Launch the dispatch loop @throws \Exception @return $this
[ "Launch", "the", "dispatch", "loop" ]
89386523f9749b6b455ecb0be853879b31b1bbf7
https://github.com/osflab/application/blob/89386523f9749b6b455ecb0be853879b31b1bbf7/OsfApplication.php#L135-L184
237,449
99designs/ergo
classes/Ergo/Routing/FilteredController.php
FilteredController._applyFilter
private function _applyFilter($chain, $object) { foreach($chain as $filter) { if(!$object = call_user_func($filter, $object)) throw new Exception("Filter returned null"); } return $object; }
php
private function _applyFilter($chain, $object) { foreach($chain as $filter) { if(!$object = call_user_func($filter, $object)) throw new Exception("Filter returned null"); } return $object; }
[ "private", "function", "_applyFilter", "(", "$", "chain", ",", "$", "object", ")", "{", "foreach", "(", "$", "chain", "as", "$", "filter", ")", "{", "if", "(", "!", "$", "object", "=", "call_user_func", "(", "$", "filter", ",", "$", "object", ")", ")", "throw", "new", "Exception", "(", "\"Filter returned null\"", ")", ";", "}", "return", "$", "object", ";", "}" ]
Apply a chain of filters to an object @return object
[ "Apply", "a", "chain", "of", "filters", "to", "an", "object" ]
8fbcfe683a14572cbf26ff59c3537c2261a7a4eb
https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/FilteredController.php#L48-L57
237,450
99designs/ergo
classes/Ergo/Routing/FilteredController.php
FilteredController.filter
protected function filter($request) { return $this->_applyFilter($this->_responses, $this->_controller->execute( $this->_applyFilter($this->_requests, $request) )); }
php
protected function filter($request) { return $this->_applyFilter($this->_responses, $this->_controller->execute( $this->_applyFilter($this->_requests, $request) )); }
[ "protected", "function", "filter", "(", "$", "request", ")", "{", "return", "$", "this", "->", "_applyFilter", "(", "$", "this", "->", "_responses", ",", "$", "this", "->", "_controller", "->", "execute", "(", "$", "this", "->", "_applyFilter", "(", "$", "this", "->", "_requests", ",", "$", "request", ")", ")", ")", ";", "}" ]
Filter a request and response and return the response @return response
[ "Filter", "a", "request", "and", "response", "and", "return", "the", "response" ]
8fbcfe683a14572cbf26ff59c3537c2261a7a4eb
https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/FilteredController.php#L63-L69
237,451
koinephp/Http
lib/Koine/Http/Request.php
Request.getMethod
public function getMethod() { $fakeMethod = $this->params['_method']; if ($fakeMethod) { if (in_array($fakeMethod, $this->acceptedMethods)) { return $fakeMethod; } throw new Exceptions\InvalidRequestMethodException( "'$fakeMethod' is not a valid request method" ); } return $this->environment['REQUEST_METHOD']; }
php
public function getMethod() { $fakeMethod = $this->params['_method']; if ($fakeMethod) { if (in_array($fakeMethod, $this->acceptedMethods)) { return $fakeMethod; } throw new Exceptions\InvalidRequestMethodException( "'$fakeMethod' is not a valid request method" ); } return $this->environment['REQUEST_METHOD']; }
[ "public", "function", "getMethod", "(", ")", "{", "$", "fakeMethod", "=", "$", "this", "->", "params", "[", "'_method'", "]", ";", "if", "(", "$", "fakeMethod", ")", "{", "if", "(", "in_array", "(", "$", "fakeMethod", ",", "$", "this", "->", "acceptedMethods", ")", ")", "{", "return", "$", "fakeMethod", ";", "}", "throw", "new", "Exceptions", "\\", "InvalidRequestMethodException", "(", "\"'$fakeMethod' is not a valid request method\"", ")", ";", "}", "return", "$", "this", "->", "environment", "[", "'REQUEST_METHOD'", "]", ";", "}" ]
Get the request method @return string
[ "Get", "the", "request", "method" ]
90a777d779f326d691e1092de6e1936a94764691
https://github.com/koinephp/Http/blob/90a777d779f326d691e1092de6e1936a94764691/lib/Koine/Http/Request.php#L189-L204
237,452
kambo-1st/HttpMessage
src/Factories/String/UriFactory.php
UriFactory.create
public function create($uri) { list($scheme, $host, $port, $path, $query, $fragment, $user, $pass) = $this->parseUrl($uri); return new Uri($scheme, $host, $port, $path, $query, $fragment, $user, $pass); }
php
public function create($uri) { list($scheme, $host, $port, $path, $query, $fragment, $user, $pass) = $this->parseUrl($uri); return new Uri($scheme, $host, $port, $path, $query, $fragment, $user, $pass); }
[ "public", "function", "create", "(", "$", "uri", ")", "{", "list", "(", "$", "scheme", ",", "$", "host", ",", "$", "port", ",", "$", "path", ",", "$", "query", ",", "$", "fragment", ",", "$", "user", ",", "$", "pass", ")", "=", "$", "this", "->", "parseUrl", "(", "$", "uri", ")", ";", "return", "new", "Uri", "(", "$", "scheme", ",", "$", "host", ",", "$", "port", ",", "$", "path", ",", "$", "query", ",", "$", "fragment", ",", "$", "user", ",", "$", "pass", ")", ";", "}" ]
Create new Uri from provided string. @param string $uri uri that will be parsed into URI object @return Uri Instance of Uri based on provided string
[ "Create", "new", "Uri", "from", "provided", "string", "." ]
38877b9d895f279fdd5bdf957d8f23f9808a940a
https://github.com/kambo-1st/HttpMessage/blob/38877b9d895f279fdd5bdf957d8f23f9808a940a/src/Factories/String/UriFactory.php#L23-L28
237,453
kambo-1st/HttpMessage
src/Factories/String/UriFactory.php
UriFactory.parseUrl
protected function parseUrl($uri) { $parsedUrl = parse_url($uri); return [ isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] : '', isset($parsedUrl['host']) ? $parsedUrl['host'] : '', isset($parsedUrl['port']) ? $parsedUrl['port'] : null, isset($parsedUrl['path']) ? $parsedUrl['path'] : '/', isset($parsedUrl['query']) ? $parsedUrl['query'] : '', isset($parsedUrl['fragment']) ? $parsedUrl['fragment'] : '', isset($parsedUrl['user']) ? $parsedUrl['user'] : '', isset($parsedUrl['pass']) ? $parsedUrl['pass'] : '' ]; }
php
protected function parseUrl($uri) { $parsedUrl = parse_url($uri); return [ isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] : '', isset($parsedUrl['host']) ? $parsedUrl['host'] : '', isset($parsedUrl['port']) ? $parsedUrl['port'] : null, isset($parsedUrl['path']) ? $parsedUrl['path'] : '/', isset($parsedUrl['query']) ? $parsedUrl['query'] : '', isset($parsedUrl['fragment']) ? $parsedUrl['fragment'] : '', isset($parsedUrl['user']) ? $parsedUrl['user'] : '', isset($parsedUrl['pass']) ? $parsedUrl['pass'] : '' ]; }
[ "protected", "function", "parseUrl", "(", "$", "uri", ")", "{", "$", "parsedUrl", "=", "parse_url", "(", "$", "uri", ")", ";", "return", "[", "isset", "(", "$", "parsedUrl", "[", "'scheme'", "]", ")", "?", "$", "parsedUrl", "[", "'scheme'", "]", ":", "''", ",", "isset", "(", "$", "parsedUrl", "[", "'host'", "]", ")", "?", "$", "parsedUrl", "[", "'host'", "]", ":", "''", ",", "isset", "(", "$", "parsedUrl", "[", "'port'", "]", ")", "?", "$", "parsedUrl", "[", "'port'", "]", ":", "null", ",", "isset", "(", "$", "parsedUrl", "[", "'path'", "]", ")", "?", "$", "parsedUrl", "[", "'path'", "]", ":", "'/'", ",", "isset", "(", "$", "parsedUrl", "[", "'query'", "]", ")", "?", "$", "parsedUrl", "[", "'query'", "]", ":", "''", ",", "isset", "(", "$", "parsedUrl", "[", "'fragment'", "]", ")", "?", "$", "parsedUrl", "[", "'fragment'", "]", ":", "''", ",", "isset", "(", "$", "parsedUrl", "[", "'user'", "]", ")", "?", "$", "parsedUrl", "[", "'user'", "]", ":", "''", ",", "isset", "(", "$", "parsedUrl", "[", "'pass'", "]", ")", "?", "$", "parsedUrl", "[", "'pass'", "]", ":", "''", "]", ";", "}" ]
Parse uri to array with individual parts @param string $uri url that will be parsed into array with individual parts @return Array Individual parts of uri in array
[ "Parse", "uri", "to", "array", "with", "individual", "parts" ]
38877b9d895f279fdd5bdf957d8f23f9808a940a
https://github.com/kambo-1st/HttpMessage/blob/38877b9d895f279fdd5bdf957d8f23f9808a940a/src/Factories/String/UriFactory.php#L37-L51
237,454
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendTextMsgToXmlString
protected function sendTextMsgToXmlString(WxSendTextMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getContent() ); return $result; }
php
protected function sendTextMsgToXmlString(WxSendTextMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getContent() ); return $result; }
[ "protected", "function", "sendTextMsgToXmlString", "(", "WxSendTextMsg", "$", "msg", ")", "{", "$", "formatStr", "=", " <<<XML\n<xml>\n<ToUserName><![CDATA[%s]]></ToUserName>\n<FromUserName><![CDATA[%s]]></FromUserName>\n<CreateTime>%d</CreateTime>\n<MsgType><![CDATA[%s]]></MsgType>\n<Content><![CDATA[%s]]></Content>\n</xml>\nXML", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getFromUserName", "(", ")", ",", "strtotime", "(", "$", "msg", "->", "getCreateTime", "(", ")", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "msg", "->", "getContent", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendTextMsg to xml string @param WxSendTextMsg $msg @return string
[ "formatter", "WxSendTextMsg", "to", "xml", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L36-L56
237,455
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendImageMsgToXmlString
protected function sendImageMsgToXmlString(WxSendImageMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Image> <MediaId><![CDATA[%s]]></MediaId> </Image> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getMediaId() ); return $result; }
php
protected function sendImageMsgToXmlString(WxSendImageMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Image> <MediaId><![CDATA[%s]]></MediaId> </Image> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getMediaId() ); return $result; }
[ "protected", "function", "sendImageMsgToXmlString", "(", "WxSendImageMsg", "$", "msg", ")", "{", "$", "formatStr", "=", " <<<XML\n<xml>\n<ToUserName><![CDATA[%s]]></ToUserName>\n<FromUserName><![CDATA[%s]]></FromUserName>\n<CreateTime>%d</CreateTime>\n<MsgType><![CDATA[%s]]></MsgType>\n<Image>\n<MediaId><![CDATA[%s]]></MediaId>\n</Image>\n</xml>\nXML", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getFromUserName", "(", ")", ",", "strtotime", "(", "$", "msg", "->", "getCreateTime", "(", ")", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "msg", "->", "getMediaId", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendImageMsg to xml string @param WxSendImageMsg $msg @return string
[ "formatter", "WxSendImageMsg", "to", "xml", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L63-L85
237,456
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendVoiceMsgToXmlString
protected function sendVoiceMsgToXmlString(WxSendVoiceMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Voice> <MediaId><![CDATA[%s]]></MediaId> </Voice> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getMediaId() ); return $result; }
php
protected function sendVoiceMsgToXmlString(WxSendVoiceMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Voice> <MediaId><![CDATA[%s]]></MediaId> </Voice> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getMediaId() ); return $result; }
[ "protected", "function", "sendVoiceMsgToXmlString", "(", "WxSendVoiceMsg", "$", "msg", ")", "{", "$", "formatStr", "=", " <<<XML\n<xml>\n<ToUserName><![CDATA[%s]]></ToUserName>\n<FromUserName><![CDATA[%s]]></FromUserName>\n<CreateTime>%d</CreateTime>\n<MsgType><![CDATA[%s]]></MsgType>\n<Voice>\n<MediaId><![CDATA[%s]]></MediaId>\n</Voice>\n</xml>\nXML", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getFromUserName", "(", ")", ",", "strtotime", "(", "$", "msg", "->", "getCreateTime", "(", ")", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "msg", "->", "getMediaId", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendVoiceMsg to xml string @param WxSendVoiceMsg $msg @return string
[ "formatter", "WxSendVoiceMsg", "to", "xml", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L92-L114
237,457
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendVideoMsgToXmlString
protected function sendVideoMsgToXmlString(WxSendVideoMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Video> <MediaId><![CDATA[%s]]></MediaId> <Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Description> </Video> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getMediaId(), $msg->getTitle(), $msg->getDescription() ); return $result; }
php
protected function sendVideoMsgToXmlString(WxSendVideoMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Video> <MediaId><![CDATA[%s]]></MediaId> <Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Description> </Video> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getMediaId(), $msg->getTitle(), $msg->getDescription() ); return $result; }
[ "protected", "function", "sendVideoMsgToXmlString", "(", "WxSendVideoMsg", "$", "msg", ")", "{", "$", "formatStr", "=", " <<<XML\n<xml>\n<ToUserName><![CDATA[%s]]></ToUserName>\n<FromUserName><![CDATA[%s]]></FromUserName>\n<CreateTime>%d</CreateTime>\n<MsgType><![CDATA[%s]]></MsgType>\n<Video>\n<MediaId><![CDATA[%s]]></MediaId>\n<Title><![CDATA[%s]]></Title>\n<Description><![CDATA[%s]]></Description>\n</Video>\n</xml>\nXML", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getFromUserName", "(", ")", ",", "strtotime", "(", "$", "msg", "->", "getCreateTime", "(", ")", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "msg", "->", "getMediaId", "(", ")", ",", "$", "msg", "->", "getTitle", "(", ")", ",", "$", "msg", "->", "getDescription", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendVideoMsg to xml string @param WxSendVideoMsg $msg @return string
[ "formatter", "WxSendVideoMsg", "to", "xml", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L121-L146
237,458
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendMusicMsgToXmlString
protected function sendMusicMsgToXmlString(WxSendMusicMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Music> <Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Description> <MusicUrl><![CDATA[%s]]></MusicUrl> <HQMusicUrl><![CDATA[%s]]></HQMusicUrl> <ThumbMediaId><![CDATA[%s]]></ThumbMediaId> </Music> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getTitle(), $msg->getDescription(), $msg->getMusicUrl(), $msg->getHQMusicUrl(), $msg->getThumbMediaId() ); return $result; }
php
protected function sendMusicMsgToXmlString(WxSendMusicMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Music> <Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Description> <MusicUrl><![CDATA[%s]]></MusicUrl> <HQMusicUrl><![CDATA[%s]]></HQMusicUrl> <ThumbMediaId><![CDATA[%s]]></ThumbMediaId> </Music> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getTitle(), $msg->getDescription(), $msg->getMusicUrl(), $msg->getHQMusicUrl(), $msg->getThumbMediaId() ); return $result; }
[ "protected", "function", "sendMusicMsgToXmlString", "(", "WxSendMusicMsg", "$", "msg", ")", "{", "$", "formatStr", "=", " <<<XML\n<xml>\n<ToUserName><![CDATA[%s]]></ToUserName>\n<FromUserName><![CDATA[%s]]></FromUserName>\n<CreateTime>%d</CreateTime>\n<MsgType><![CDATA[%s]]></MsgType>\n<Music>\n<Title><![CDATA[%s]]></Title>\n<Description><![CDATA[%s]]></Description>\n<MusicUrl><![CDATA[%s]]></MusicUrl>\n<HQMusicUrl><![CDATA[%s]]></HQMusicUrl>\n<ThumbMediaId><![CDATA[%s]]></ThumbMediaId>\n</Music>\n</xml>\nXML", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getFromUserName", "(", ")", ",", "strtotime", "(", "$", "msg", "->", "getCreateTime", "(", ")", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "msg", "->", "getTitle", "(", ")", ",", "$", "msg", "->", "getDescription", "(", ")", ",", "$", "msg", "->", "getMusicUrl", "(", ")", ",", "$", "msg", "->", "getHQMusicUrl", "(", ")", ",", "$", "msg", "->", "getThumbMediaId", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendMusicMsg to xml string @param WxSendMusicMsg $msg @return string
[ "formatter", "WxSendMusicMsg", "to", "xml", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L153-L182
237,459
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendNewsMsgToXmlString
protected function sendNewsMsgToXmlString(WxSendNewsMsg $msg) { $itemArray = $msg->getAllArticleItems(); $itemStr = ''; foreach ($itemArray as $item) { $itemStr .= $this->sendNewsItemToXmlString($item); } $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <ArticleCount>%d</ArticleCount> <Articles> %s </Articles> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getArticleCount(), $itemStr ); return $result; }
php
protected function sendNewsMsgToXmlString(WxSendNewsMsg $msg) { $itemArray = $msg->getAllArticleItems(); $itemStr = ''; foreach ($itemArray as $item) { $itemStr .= $this->sendNewsItemToXmlString($item); } $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <ArticleCount>%d</ArticleCount> <Articles> %s </Articles> </xml> XML; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getFromUserName(), strtotime($msg->getCreateTime()), $msg->getMsgType(), $msg->getArticleCount(), $itemStr ); return $result; }
[ "protected", "function", "sendNewsMsgToXmlString", "(", "WxSendNewsMsg", "$", "msg", ")", "{", "$", "itemArray", "=", "$", "msg", "->", "getAllArticleItems", "(", ")", ";", "$", "itemStr", "=", "''", ";", "foreach", "(", "$", "itemArray", "as", "$", "item", ")", "{", "$", "itemStr", ".=", "$", "this", "->", "sendNewsItemToXmlString", "(", "$", "item", ")", ";", "}", "$", "formatStr", "=", " <<<XML\n<xml>\n<ToUserName><![CDATA[%s]]></ToUserName>\n<FromUserName><![CDATA[%s]]></FromUserName>\n<CreateTime>%d</CreateTime>\n<MsgType><![CDATA[%s]]></MsgType>\n<ArticleCount>%d</ArticleCount>\n<Articles>\n%s\n</Articles>\n</xml>\nXML", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getFromUserName", "(", ")", ",", "strtotime", "(", "$", "msg", "->", "getCreateTime", "(", ")", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "msg", "->", "getArticleCount", "(", ")", ",", "$", "itemStr", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendNewsMsg to xml string @param WxSendNewsMsg $msg @return string
[ "formatter", "WxSendNewsMsg", "to", "xml", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L189-L219
237,460
flavorzyb/wechat
src/Message/Formatter.php
Formatter.toJsonString
public function toJsonString(WxSendMsg $msg) { if ($msg instanceof WxSendTextMsg) { return $this->sendTextMsgToJsonString($msg); } elseif ($msg instanceof WxSendImageMsg) { return $this->sendImageMsgToJsonString($msg); } elseif ($msg instanceof WxSendVoiceMsg) { return $this->sendVoiceMsgToJsonString($msg); } elseif ($msg instanceof WxSendVideoMsg) { return $this->sendVideoMsgToJsonString($msg); } elseif ($msg instanceof WxSendMusicMsg) { return $this->sendMusicMsgToJsonString($msg); } elseif ($msg instanceof WxSendNewsMsg) { return $this->sendNewsMsgToJsonString($msg); } throw new \InvalidArgumentException("unknown wx send msg"); }
php
public function toJsonString(WxSendMsg $msg) { if ($msg instanceof WxSendTextMsg) { return $this->sendTextMsgToJsonString($msg); } elseif ($msg instanceof WxSendImageMsg) { return $this->sendImageMsgToJsonString($msg); } elseif ($msg instanceof WxSendVoiceMsg) { return $this->sendVoiceMsgToJsonString($msg); } elseif ($msg instanceof WxSendVideoMsg) { return $this->sendVideoMsgToJsonString($msg); } elseif ($msg instanceof WxSendMusicMsg) { return $this->sendMusicMsgToJsonString($msg); } elseif ($msg instanceof WxSendNewsMsg) { return $this->sendNewsMsgToJsonString($msg); } throw new \InvalidArgumentException("unknown wx send msg"); }
[ "public", "function", "toJsonString", "(", "WxSendMsg", "$", "msg", ")", "{", "if", "(", "$", "msg", "instanceof", "WxSendTextMsg", ")", "{", "return", "$", "this", "->", "sendTextMsgToJsonString", "(", "$", "msg", ")", ";", "}", "elseif", "(", "$", "msg", "instanceof", "WxSendImageMsg", ")", "{", "return", "$", "this", "->", "sendImageMsgToJsonString", "(", "$", "msg", ")", ";", "}", "elseif", "(", "$", "msg", "instanceof", "WxSendVoiceMsg", ")", "{", "return", "$", "this", "->", "sendVoiceMsgToJsonString", "(", "$", "msg", ")", ";", "}", "elseif", "(", "$", "msg", "instanceof", "WxSendVideoMsg", ")", "{", "return", "$", "this", "->", "sendVideoMsgToJsonString", "(", "$", "msg", ")", ";", "}", "elseif", "(", "$", "msg", "instanceof", "WxSendMusicMsg", ")", "{", "return", "$", "this", "->", "sendMusicMsgToJsonString", "(", "$", "msg", ")", ";", "}", "elseif", "(", "$", "msg", "instanceof", "WxSendNewsMsg", ")", "{", "return", "$", "this", "->", "sendNewsMsgToJsonString", "(", "$", "msg", ")", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "\"unknown wx send msg\"", ")", ";", "}" ]
formatter to json string @param WxSendMsg $msg @return string
[ "formatter", "to", "json", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L252-L269
237,461
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendTextMsgToJsonString
protected function sendTextMsgToJsonString(WxSendTextMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "text": { "content":"%s" } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $msg->getContent() ); return $result; }
php
protected function sendTextMsgToJsonString(WxSendTextMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "text": { "content":"%s" } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $msg->getContent() ); return $result; }
[ "protected", "function", "sendTextMsgToJsonString", "(", "WxSendTextMsg", "$", "msg", ")", "{", "$", "formatStr", "=", "'{\n \"touser\":\"%s\",\n \"msgtype\":\"%s\",\n \"text\":\n {\n \"content\":\"%s\"\n }\n }'", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "msg", "->", "getContent", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendTextMsg to Json string @param WxSendTextMsg $msg @return string
[ "formatter", "WxSendTextMsg", "to", "Json", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L276-L293
237,462
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendImageMsgToJsonString
protected function sendImageMsgToJsonString(WxSendImageMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "image": { "media_id":"%s" } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $msg->getMediaId() ); return $result; }
php
protected function sendImageMsgToJsonString(WxSendImageMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "image": { "media_id":"%s" } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $msg->getMediaId() ); return $result; }
[ "protected", "function", "sendImageMsgToJsonString", "(", "WxSendImageMsg", "$", "msg", ")", "{", "$", "formatStr", "=", "'{\n \"touser\":\"%s\",\n \"msgtype\":\"%s\",\n \"image\":\n {\n \"media_id\":\"%s\"\n }\n }'", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "msg", "->", "getMediaId", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendImageMsg to Json string @param WxSendImageMsg $msg @return string
[ "formatter", "WxSendImageMsg", "to", "Json", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L300-L317
237,463
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendVoiceMsgToJsonString
protected function sendVoiceMsgToJsonString(WxSendVoiceMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "voice": { "media_id":"%s" } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $msg->getMediaId() ); return $result; }
php
protected function sendVoiceMsgToJsonString(WxSendVoiceMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "voice": { "media_id":"%s" } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $msg->getMediaId() ); return $result; }
[ "protected", "function", "sendVoiceMsgToJsonString", "(", "WxSendVoiceMsg", "$", "msg", ")", "{", "$", "formatStr", "=", "'{\n \"touser\":\"%s\",\n \"msgtype\":\"%s\",\n \"voice\":\n {\n \"media_id\":\"%s\"\n }\n }'", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "msg", "->", "getMediaId", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendVoiceMsg to Json string @param WxSendVoiceMsg $msg @return string
[ "formatter", "WxSendVoiceMsg", "to", "Json", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L324-L341
237,464
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendVideoMsgToJsonString
protected function sendVideoMsgToJsonString(WxSendVideoMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "video": { "media_id":"%s", "thumb_media_id":"%s", "title":"%s", "description":"%s" } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $msg->getMediaId(), $msg->getThumbMediaId(), $msg->getTitle(), $msg->getDescription() ); return $result; }
php
protected function sendVideoMsgToJsonString(WxSendVideoMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "video": { "media_id":"%s", "thumb_media_id":"%s", "title":"%s", "description":"%s" } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $msg->getMediaId(), $msg->getThumbMediaId(), $msg->getTitle(), $msg->getDescription() ); return $result; }
[ "protected", "function", "sendVideoMsgToJsonString", "(", "WxSendVideoMsg", "$", "msg", ")", "{", "$", "formatStr", "=", "'{\n \"touser\":\"%s\",\n \"msgtype\":\"%s\",\n \"video\":\n {\n \"media_id\":\"%s\",\n \"thumb_media_id\":\"%s\",\n \"title\":\"%s\",\n \"description\":\"%s\"\n }\n }'", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "msg", "->", "getMediaId", "(", ")", ",", "$", "msg", "->", "getThumbMediaId", "(", ")", ",", "$", "msg", "->", "getTitle", "(", ")", ",", "$", "msg", "->", "getDescription", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendVideoMsg to Json string @param WxSendVideoMsg $msg @return string
[ "formatter", "WxSendVideoMsg", "to", "Json", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L348-L370
237,465
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendMusicMsgToJsonString
protected function sendMusicMsgToJsonString(WxSendMusicMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "music": { "title":"%s", "description":"%s", "musicurl":"%s", "hqmusicurl":"%s", "thumb_media_id":"%s" } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $msg->getTitle(), $msg->getDescription(), $msg->getMusicUrl(), $msg->getHQMusicUrl(), $msg->getThumbMediaId() ); return $result; }
php
protected function sendMusicMsgToJsonString(WxSendMusicMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "music": { "title":"%s", "description":"%s", "musicurl":"%s", "hqmusicurl":"%s", "thumb_media_id":"%s" } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $msg->getTitle(), $msg->getDescription(), $msg->getMusicUrl(), $msg->getHQMusicUrl(), $msg->getThumbMediaId() ); return $result; }
[ "protected", "function", "sendMusicMsgToJsonString", "(", "WxSendMusicMsg", "$", "msg", ")", "{", "$", "formatStr", "=", "'{\n \"touser\":\"%s\",\n \"msgtype\":\"%s\",\n \"music\":\n {\n \"title\":\"%s\",\n \"description\":\"%s\",\n \"musicurl\":\"%s\",\n \"hqmusicurl\":\"%s\",\n \"thumb_media_id\":\"%s\"\n }\n }'", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "msg", "->", "getTitle", "(", ")", ",", "$", "msg", "->", "getDescription", "(", ")", ",", "$", "msg", "->", "getMusicUrl", "(", ")", ",", "$", "msg", "->", "getHQMusicUrl", "(", ")", ",", "$", "msg", "->", "getThumbMediaId", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendMusicMsg to Json string @param WxSendMusicMsg $msg @return string
[ "formatter", "WxSendMusicMsg", "to", "Json", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L377-L401
237,466
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendNewsMsgToJsonString
protected function sendNewsMsgToJsonString(WxSendNewsMsg $msg) { $itemArray = $msg->getAllArticleItems(); $itemStr = ''; foreach ($itemArray as $item) { $itemStr .= $this->sendNewsItemToJsonString($item) . ','; } $itemStr = substr($itemStr, 0, -1); $formatStr = '{ "touser":"%s", "msgtype":"%s", "news":{ "articles": [ %s ] } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $itemStr ); return $result; }
php
protected function sendNewsMsgToJsonString(WxSendNewsMsg $msg) { $itemArray = $msg->getAllArticleItems(); $itemStr = ''; foreach ($itemArray as $item) { $itemStr .= $this->sendNewsItemToJsonString($item) . ','; } $itemStr = substr($itemStr, 0, -1); $formatStr = '{ "touser":"%s", "msgtype":"%s", "news":{ "articles": [ %s ] } }'; $result = sprintf($formatStr, $msg->getToUserName(), $msg->getMsgType(), $itemStr ); return $result; }
[ "protected", "function", "sendNewsMsgToJsonString", "(", "WxSendNewsMsg", "$", "msg", ")", "{", "$", "itemArray", "=", "$", "msg", "->", "getAllArticleItems", "(", ")", ";", "$", "itemStr", "=", "''", ";", "foreach", "(", "$", "itemArray", "as", "$", "item", ")", "{", "$", "itemStr", ".=", "$", "this", "->", "sendNewsItemToJsonString", "(", "$", "item", ")", ".", "','", ";", "}", "$", "itemStr", "=", "substr", "(", "$", "itemStr", ",", "0", ",", "-", "1", ")", ";", "$", "formatStr", "=", "'{\n \"touser\":\"%s\",\n \"msgtype\":\"%s\",\n \"news\":{\n \"articles\": [\n %s\n ]\n }\n }'", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "msg", "->", "getToUserName", "(", ")", ",", "$", "msg", "->", "getMsgType", "(", ")", ",", "$", "itemStr", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendNewsMsg to Json string @param WxSendNewsMsg $msg @return string
[ "formatter", "WxSendNewsMsg", "to", "Json", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L408-L434
237,467
flavorzyb/wechat
src/Message/Formatter.php
Formatter.sendNewsItemToJsonString
protected function sendNewsItemToJsonString(WxSendNewsMsgItem $item) { $formatStr = '{ "title":"%s", "description":"%s", "url":"%s", "picurl":"%s" }'; $result = sprintf($formatStr, $item->getTitle(), $item->getDescription(), $item->getPicUrl(), $item->getUrl() ); return $result; }
php
protected function sendNewsItemToJsonString(WxSendNewsMsgItem $item) { $formatStr = '{ "title":"%s", "description":"%s", "url":"%s", "picurl":"%s" }'; $result = sprintf($formatStr, $item->getTitle(), $item->getDescription(), $item->getPicUrl(), $item->getUrl() ); return $result; }
[ "protected", "function", "sendNewsItemToJsonString", "(", "WxSendNewsMsgItem", "$", "item", ")", "{", "$", "formatStr", "=", "'{\n \"title\":\"%s\",\n \"description\":\"%s\",\n \"url\":\"%s\",\n \"picurl\":\"%s\"\n }'", ";", "$", "result", "=", "sprintf", "(", "$", "formatStr", ",", "$", "item", "->", "getTitle", "(", ")", ",", "$", "item", "->", "getDescription", "(", ")", ",", "$", "item", "->", "getPicUrl", "(", ")", ",", "$", "item", "->", "getUrl", "(", ")", ")", ";", "return", "$", "result", ";", "}" ]
formatter WxSendNewsMsgItem to Json string @param WxSendNewsMsgItem $item @return string
[ "formatter", "WxSendNewsMsgItem", "to", "Json", "string" ]
e7854a193c4d23cc9b84afa465f4706c09e7e7c5
https://github.com/flavorzyb/wechat/blob/e7854a193c4d23cc9b84afa465f4706c09e7e7c5/src/Message/Formatter.php#L442-L457
237,468
Sowapps/orpheus-webtools
src/Config/AppConfig.php
AppConfig.load
public function load() { if( !$this->path ) { throw new \Exception('Unable to load AppConfig from undefined path'); } $this->data = json_decode(file_get_contents($this->path), true); }
php
public function load() { if( !$this->path ) { throw new \Exception('Unable to load AppConfig from undefined path'); } $this->data = json_decode(file_get_contents($this->path), true); }
[ "public", "function", "load", "(", ")", "{", "if", "(", "!", "$", "this", "->", "path", ")", "{", "throw", "new", "\\", "Exception", "(", "'Unable to load AppConfig from undefined path'", ")", ";", "}", "$", "this", "->", "data", "=", "json_decode", "(", "file_get_contents", "(", "$", "this", "->", "path", ")", ",", "true", ")", ";", "}" ]
Load config from filesystem @throws \Exception
[ "Load", "config", "from", "filesystem" ]
653682fcff6327a29c2b3ecbc796fae49e7c03ba
https://github.com/Sowapps/orpheus-webtools/blob/653682fcff6327a29c2b3ecbc796fae49e7c03ba/src/Config/AppConfig.php#L117-L122
237,469
FlexPress/component-templating
src/FlexPress/Components/Templating/Functions.php
Functions.getTwig
public function getTwig(\Twig_Environment $twig) { $this->functions->rewind(); while ($this->functions->valid()) { $function = $this->functions->current(); $twig->addFunction(new \Twig_SimpleFunction($function->getFunctionName(), array($function, 'getFunctionBody'))); $this->functions->next(); } return $twig; }
php
public function getTwig(\Twig_Environment $twig) { $this->functions->rewind(); while ($this->functions->valid()) { $function = $this->functions->current(); $twig->addFunction(new \Twig_SimpleFunction($function->getFunctionName(), array($function, 'getFunctionBody'))); $this->functions->next(); } return $twig; }
[ "public", "function", "getTwig", "(", "\\", "Twig_Environment", "$", "twig", ")", "{", "$", "this", "->", "functions", "->", "rewind", "(", ")", ";", "while", "(", "$", "this", "->", "functions", "->", "valid", "(", ")", ")", "{", "$", "function", "=", "$", "this", "->", "functions", "->", "current", "(", ")", ";", "$", "twig", "->", "addFunction", "(", "new", "\\", "Twig_SimpleFunction", "(", "$", "function", "->", "getFunctionName", "(", ")", ",", "array", "(", "$", "function", ",", "'getFunctionBody'", ")", ")", ")", ";", "$", "this", "->", "functions", "->", "next", "(", ")", ";", "}", "return", "$", "twig", ";", "}" ]
Adds all the functions into the twig environment @param \Twig_Environment $twig @return \Twig_Environment @author Tim Perry
[ "Adds", "all", "the", "functions", "into", "the", "twig", "environment" ]
58d1cdd3cae3bfff41d987f8c8a493e6a6efd9cb
https://github.com/FlexPress/component-templating/blob/58d1cdd3cae3bfff41d987f8c8a493e6a6efd9cb/src/FlexPress/Components/Templating/Functions.php#L53-L67
237,470
hanamura/wp-post-type
src/WPPostType/PostType.php
PostType.onMapMetaCap
public function onMapMetaCap($caps, $cap, $user_id, $args) { // post type object // ---------------- $post_type_object = get_post_type_object($this->name); if (is_null($post_type_object)) { return $caps; } if ( $post_type_object->capability_type === 'post' || $post_type_object->capability_type === 'page' ) { return $caps; } // meta caps // --------- $edit_post = $post_type_object->cap->edit_post; $delete_post = $post_type_object->cap->delete_post; $read_post = $post_type_object->cap->read_post; // receiving meta caps? // -------------------- if ( $cap === $edit_post || $cap === $delete_post || $cap === $read_post ) { $post = get_post($args[0]); // map meta caps // ------------- switch ($cap) { case $edit_post: return $this->onCheckedMapMetaCapEditPost($user_id, $post, $post_type_object); case $delete_post: return $this->onCheckedMapMetaCapDeletePost($user_id, $post, $post_type_object); case $read_post: return $this->onCheckedMapMetaCapReadPost($user_id, $post, $post_type_object); } } // default // ------- return $caps; }
php
public function onMapMetaCap($caps, $cap, $user_id, $args) { // post type object // ---------------- $post_type_object = get_post_type_object($this->name); if (is_null($post_type_object)) { return $caps; } if ( $post_type_object->capability_type === 'post' || $post_type_object->capability_type === 'page' ) { return $caps; } // meta caps // --------- $edit_post = $post_type_object->cap->edit_post; $delete_post = $post_type_object->cap->delete_post; $read_post = $post_type_object->cap->read_post; // receiving meta caps? // -------------------- if ( $cap === $edit_post || $cap === $delete_post || $cap === $read_post ) { $post = get_post($args[0]); // map meta caps // ------------- switch ($cap) { case $edit_post: return $this->onCheckedMapMetaCapEditPost($user_id, $post, $post_type_object); case $delete_post: return $this->onCheckedMapMetaCapDeletePost($user_id, $post, $post_type_object); case $read_post: return $this->onCheckedMapMetaCapReadPost($user_id, $post, $post_type_object); } } // default // ------- return $caps; }
[ "public", "function", "onMapMetaCap", "(", "$", "caps", ",", "$", "cap", ",", "$", "user_id", ",", "$", "args", ")", "{", "// post type object", "// ----------------", "$", "post_type_object", "=", "get_post_type_object", "(", "$", "this", "->", "name", ")", ";", "if", "(", "is_null", "(", "$", "post_type_object", ")", ")", "{", "return", "$", "caps", ";", "}", "if", "(", "$", "post_type_object", "->", "capability_type", "===", "'post'", "||", "$", "post_type_object", "->", "capability_type", "===", "'page'", ")", "{", "return", "$", "caps", ";", "}", "// meta caps", "// ---------", "$", "edit_post", "=", "$", "post_type_object", "->", "cap", "->", "edit_post", ";", "$", "delete_post", "=", "$", "post_type_object", "->", "cap", "->", "delete_post", ";", "$", "read_post", "=", "$", "post_type_object", "->", "cap", "->", "read_post", ";", "// receiving meta caps?", "// --------------------", "if", "(", "$", "cap", "===", "$", "edit_post", "||", "$", "cap", "===", "$", "delete_post", "||", "$", "cap", "===", "$", "read_post", ")", "{", "$", "post", "=", "get_post", "(", "$", "args", "[", "0", "]", ")", ";", "// map meta caps", "// -------------", "switch", "(", "$", "cap", ")", "{", "case", "$", "edit_post", ":", "return", "$", "this", "->", "onCheckedMapMetaCapEditPost", "(", "$", "user_id", ",", "$", "post", ",", "$", "post_type_object", ")", ";", "case", "$", "delete_post", ":", "return", "$", "this", "->", "onCheckedMapMetaCapDeletePost", "(", "$", "user_id", ",", "$", "post", ",", "$", "post_type_object", ")", ";", "case", "$", "read_post", ":", "return", "$", "this", "->", "onCheckedMapMetaCapReadPost", "(", "$", "user_id", ",", "$", "post", ",", "$", "post_type_object", ")", ";", "}", "}", "// default", "// -------", "return", "$", "caps", ";", "}" ]
map meta cap
[ "map", "meta", "cap" ]
c21a529a7c5c6291427707c007c245e89a659cfc
https://github.com/hanamura/wp-post-type/blob/c21a529a7c5c6291427707c007c245e89a659cfc/src/WPPostType/PostType.php#L263-L315
237,471
asbsoft/yii2module-users_0_170112
models/ProfileForm.php
ProfileForm.save
public function save($isNewRecord) { if ($this->validate()) { $user = $this->user; $data = []; $fn = $user->formName(); if ($isNewRecord) { $data[$fn]['username'] = $this->username; } $data[$fn]['email'] = $this->email; $data[$fn]['password'] = $this->password_new; $data[$fn]['change_auth_key'] = $this->change_auth_key; $loaded = $user->load($data); if ($isNewRecord) { $user->scenario = $user::SCENARIO_CREATE; $user->status = $user::STATUS_REGISTERED; $saved = $user->insert(); } else { $saved = $user->update(); } if ($loaded && $saved) { $this->auth_key = $user->auth_key; return $saved; } else { $this->addErrors($user->errors); } } return false; }
php
public function save($isNewRecord) { if ($this->validate()) { $user = $this->user; $data = []; $fn = $user->formName(); if ($isNewRecord) { $data[$fn]['username'] = $this->username; } $data[$fn]['email'] = $this->email; $data[$fn]['password'] = $this->password_new; $data[$fn]['change_auth_key'] = $this->change_auth_key; $loaded = $user->load($data); if ($isNewRecord) { $user->scenario = $user::SCENARIO_CREATE; $user->status = $user::STATUS_REGISTERED; $saved = $user->insert(); } else { $saved = $user->update(); } if ($loaded && $saved) { $this->auth_key = $user->auth_key; return $saved; } else { $this->addErrors($user->errors); } } return false; }
[ "public", "function", "save", "(", "$", "isNewRecord", ")", "{", "if", "(", "$", "this", "->", "validate", "(", ")", ")", "{", "$", "user", "=", "$", "this", "->", "user", ";", "$", "data", "=", "[", "]", ";", "$", "fn", "=", "$", "user", "->", "formName", "(", ")", ";", "if", "(", "$", "isNewRecord", ")", "{", "$", "data", "[", "$", "fn", "]", "[", "'username'", "]", "=", "$", "this", "->", "username", ";", "}", "$", "data", "[", "$", "fn", "]", "[", "'email'", "]", "=", "$", "this", "->", "email", ";", "$", "data", "[", "$", "fn", "]", "[", "'password'", "]", "=", "$", "this", "->", "password_new", ";", "$", "data", "[", "$", "fn", "]", "[", "'change_auth_key'", "]", "=", "$", "this", "->", "change_auth_key", ";", "$", "loaded", "=", "$", "user", "->", "load", "(", "$", "data", ")", ";", "if", "(", "$", "isNewRecord", ")", "{", "$", "user", "->", "scenario", "=", "$", "user", "::", "SCENARIO_CREATE", ";", "$", "user", "->", "status", "=", "$", "user", "::", "STATUS_REGISTERED", ";", "$", "saved", "=", "$", "user", "->", "insert", "(", ")", ";", "}", "else", "{", "$", "saved", "=", "$", "user", "->", "update", "(", ")", ";", "}", "if", "(", "$", "loaded", "&&", "$", "saved", ")", "{", "$", "this", "->", "auth_key", "=", "$", "user", "->", "auth_key", ";", "return", "$", "saved", ";", "}", "else", "{", "$", "this", "->", "addErrors", "(", "$", "user", "->", "errors", ")", ";", "}", "}", "return", "false", ";", "}" ]
Edit user's profile. @param boolean $isNewRecord @return integer|false the number of rows affected, or false if validation fails
[ "Edit", "user", "s", "profile", "." ]
3906fdde2d5fdd54637f2b5246d52fe91ec5f648
https://github.com/asbsoft/yii2module-users_0_170112/blob/3906fdde2d5fdd54637f2b5246d52fe91ec5f648/models/ProfileForm.php#L183-L212
237,472
projek-xyz/ci-common
src/Views.php
Views.addData
public function addData(array $data, $templates = null) { $this->engine->addData($data, $templates); return $this->engine; }
php
public function addData(array $data, $templates = null) { $this->engine->addData($data, $templates); return $this->engine; }
[ "public", "function", "addData", "(", "array", "$", "data", ",", "$", "templates", "=", "null", ")", "{", "$", "this", "->", "engine", "->", "addData", "(", "$", "data", ",", "$", "templates", ")", ";", "return", "$", "this", "->", "engine", ";", "}" ]
Add data to render. @param array $data Data @param string $templates Template @return League\Plates\Engine
[ "Add", "data", "to", "render", "." ]
2cd3f507f378e6a871fcaa87efa88c63ce1282c0
https://github.com/projek-xyz/ci-common/blob/2cd3f507f378e6a871fcaa87efa88c63ce1282c0/src/Views.php#L56-L61
237,473
bishopb/vanilla
library/core/class.upload.php
Gdn_Upload.CopyLocal
public function CopyLocal($Name) { $Parsed = self::Parse($Name); $LocalPath = ''; $this->EventArguments['Parsed'] = $Parsed; $this->EventArguments['Path'] =& $LocalPath; $this->FireAs('Gdn_Upload')->FireEvent('CopyLocal'); if (!$LocalPath) { $LocalPath = PATH_UPLOADS.'/'.$Parsed['Name']; } return $LocalPath; }
php
public function CopyLocal($Name) { $Parsed = self::Parse($Name); $LocalPath = ''; $this->EventArguments['Parsed'] = $Parsed; $this->EventArguments['Path'] =& $LocalPath; $this->FireAs('Gdn_Upload')->FireEvent('CopyLocal'); if (!$LocalPath) { $LocalPath = PATH_UPLOADS.'/'.$Parsed['Name']; } return $LocalPath; }
[ "public", "function", "CopyLocal", "(", "$", "Name", ")", "{", "$", "Parsed", "=", "self", "::", "Parse", "(", "$", "Name", ")", ";", "$", "LocalPath", "=", "''", ";", "$", "this", "->", "EventArguments", "[", "'Parsed'", "]", "=", "$", "Parsed", ";", "$", "this", "->", "EventArguments", "[", "'Path'", "]", "=", "&", "$", "LocalPath", ";", "$", "this", "->", "FireAs", "(", "'Gdn_Upload'", ")", "->", "FireEvent", "(", "'CopyLocal'", ")", ";", "if", "(", "!", "$", "LocalPath", ")", "{", "$", "LocalPath", "=", "PATH_UPLOADS", ".", "'/'", ".", "$", "Parsed", "[", "'Name'", "]", ";", "}", "return", "$", "LocalPath", ";", "}" ]
Copy an upload locally so that it can be operated on. @param string $Name
[ "Copy", "an", "upload", "locally", "so", "that", "it", "can", "be", "operated", "on", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.upload.php#L76-L88
237,474
bishopb/vanilla
library/core/class.upload.php
Gdn_Upload.Delete
public function Delete($Name) { $Parsed = $this->Parse($Name); // Throw an event so that plugins that have stored the file somewhere else can delete it. $this->EventArguments['Parsed'] =& $Parsed; $Handled = FALSE; $this->EventArguments['Handled'] =& $Handled; $this->FireAs('Gdn_Upload')->FireEvent('Delete'); if (!$Handled) { $Path = PATH_UPLOADS.'/'.ltrim($Name, '/'); @unlink($Path); } }
php
public function Delete($Name) { $Parsed = $this->Parse($Name); // Throw an event so that plugins that have stored the file somewhere else can delete it. $this->EventArguments['Parsed'] =& $Parsed; $Handled = FALSE; $this->EventArguments['Handled'] =& $Handled; $this->FireAs('Gdn_Upload')->FireEvent('Delete'); if (!$Handled) { $Path = PATH_UPLOADS.'/'.ltrim($Name, '/'); @unlink($Path); } }
[ "public", "function", "Delete", "(", "$", "Name", ")", "{", "$", "Parsed", "=", "$", "this", "->", "Parse", "(", "$", "Name", ")", ";", "// Throw an event so that plugins that have stored the file somewhere else can delete it.", "$", "this", "->", "EventArguments", "[", "'Parsed'", "]", "=", "&", "$", "Parsed", ";", "$", "Handled", "=", "FALSE", ";", "$", "this", "->", "EventArguments", "[", "'Handled'", "]", "=", "&", "$", "Handled", ";", "$", "this", "->", "FireAs", "(", "'Gdn_Upload'", ")", "->", "FireEvent", "(", "'Delete'", ")", ";", "if", "(", "!", "$", "Handled", ")", "{", "$", "Path", "=", "PATH_UPLOADS", ".", "'/'", ".", "ltrim", "(", "$", "Name", ",", "'/'", ")", ";", "@", "unlink", "(", "$", "Path", ")", ";", "}", "}" ]
Delete an uploaded file. @param string $Name The name of the upload as saved in the database.
[ "Delete", "an", "uploaded", "file", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.upload.php#L95-L108
237,475
bishopb/vanilla
library/core/class.upload.php
Gdn_Upload.FormatFileSize
public static function FormatFileSize($Bytes, $Precision = 1) { $Units = array('B', 'K', 'M', 'G', 'T'); $Bytes = max((int)$Bytes, 0); $Pow = floor(($Bytes ? log($Bytes) : 0) / log(1024)); $Pow = min($Pow, count($Units) - 1); $Bytes /= pow(1024, $Pow); $Result = round($Bytes, $Precision).$Units[$Pow]; return $Result; }
php
public static function FormatFileSize($Bytes, $Precision = 1) { $Units = array('B', 'K', 'M', 'G', 'T'); $Bytes = max((int)$Bytes, 0); $Pow = floor(($Bytes ? log($Bytes) : 0) / log(1024)); $Pow = min($Pow, count($Units) - 1); $Bytes /= pow(1024, $Pow); $Result = round($Bytes, $Precision).$Units[$Pow]; return $Result; }
[ "public", "static", "function", "FormatFileSize", "(", "$", "Bytes", ",", "$", "Precision", "=", "1", ")", "{", "$", "Units", "=", "array", "(", "'B'", ",", "'K'", ",", "'M'", ",", "'G'", ",", "'T'", ")", ";", "$", "Bytes", "=", "max", "(", "(", "int", ")", "$", "Bytes", ",", "0", ")", ";", "$", "Pow", "=", "floor", "(", "(", "$", "Bytes", "?", "log", "(", "$", "Bytes", ")", ":", "0", ")", "/", "log", "(", "1024", ")", ")", ";", "$", "Pow", "=", "min", "(", "$", "Pow", ",", "count", "(", "$", "Units", ")", "-", "1", ")", ";", "$", "Bytes", "/=", "pow", "(", "1024", ",", "$", "Pow", ")", ";", "$", "Result", "=", "round", "(", "$", "Bytes", ",", "$", "Precision", ")", ".", "$", "Units", "[", "$", "Pow", "]", ";", "return", "$", "Result", ";", "}" ]
Format a number of bytes with the largest unit. @param int $Bytes The number of bytes. @param int $Precision The number of decimal places in the formatted number. @return string the formatted filesize.
[ "Format", "a", "number", "of", "bytes", "with", "the", "largest", "unit", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.upload.php#L115-L126
237,476
bishopb/vanilla
library/core/class.upload.php
Gdn_Upload.UnformatFileSize
public static function UnformatFileSize($Formatted) { $Units = array('B' => 1, 'K' => 1024, 'M' => 1024 * 1024, 'G' => 1024 * 1024 * 1024, 'T' => 1024 * 1024 * 1024 * 1024); if(preg_match('/([0-9.]+)\s*([A-Z]*)/i', $Formatted, $Matches)) { $Number = floatval($Matches[1]); $Unit = strtoupper(substr($Matches[2], 0, 1)); $Mult = GetValue($Unit, $Units, 1); $Result = round($Number * $Mult, 0); return $Result; } else { return FALSE; } }
php
public static function UnformatFileSize($Formatted) { $Units = array('B' => 1, 'K' => 1024, 'M' => 1024 * 1024, 'G' => 1024 * 1024 * 1024, 'T' => 1024 * 1024 * 1024 * 1024); if(preg_match('/([0-9.]+)\s*([A-Z]*)/i', $Formatted, $Matches)) { $Number = floatval($Matches[1]); $Unit = strtoupper(substr($Matches[2], 0, 1)); $Mult = GetValue($Unit, $Units, 1); $Result = round($Number * $Mult, 0); return $Result; } else { return FALSE; } }
[ "public", "static", "function", "UnformatFileSize", "(", "$", "Formatted", ")", "{", "$", "Units", "=", "array", "(", "'B'", "=>", "1", ",", "'K'", "=>", "1024", ",", "'M'", "=>", "1024", "*", "1024", ",", "'G'", "=>", "1024", "*", "1024", "*", "1024", ",", "'T'", "=>", "1024", "*", "1024", "*", "1024", "*", "1024", ")", ";", "if", "(", "preg_match", "(", "'/([0-9.]+)\\s*([A-Z]*)/i'", ",", "$", "Formatted", ",", "$", "Matches", ")", ")", "{", "$", "Number", "=", "floatval", "(", "$", "Matches", "[", "1", "]", ")", ";", "$", "Unit", "=", "strtoupper", "(", "substr", "(", "$", "Matches", "[", "2", "]", ",", "0", ",", "1", ")", ")", ";", "$", "Mult", "=", "GetValue", "(", "$", "Unit", ",", "$", "Units", ",", "1", ")", ";", "$", "Result", "=", "round", "(", "$", "Number", "*", "$", "Mult", ",", "0", ")", ";", "return", "$", "Result", ";", "}", "else", "{", "return", "FALSE", ";", "}", "}" ]
Take a string formatted filesize and return the number of bytes. @param string $Formatted The formatted filesize. @return int The number of bytes in the string.
[ "Take", "a", "string", "formatted", "filesize", "and", "return", "the", "number", "of", "bytes", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.upload.php#L165-L178
237,477
bishopb/vanilla
library/core/class.upload.php
Gdn_Upload.Urls
public static function Urls($Type = NULL) { static $Urls = NULL; if ($Urls === NULL) { $Urls = array('' => Asset('/uploads', TRUE)); $Sender = new stdClass(); $Sender->Returns = array(); $Sender->EventArguments = array(); $Sender->EventArguments['Urls'] =& $Urls; Gdn::PluginManager()->CallEventHandlers($Sender, 'Gdn_Upload', 'GetUrls'); } if ($Type === NULL) return $Urls; if (isset($Urls[$Type])) return $Urls[$Type]; return FALSE; }
php
public static function Urls($Type = NULL) { static $Urls = NULL; if ($Urls === NULL) { $Urls = array('' => Asset('/uploads', TRUE)); $Sender = new stdClass(); $Sender->Returns = array(); $Sender->EventArguments = array(); $Sender->EventArguments['Urls'] =& $Urls; Gdn::PluginManager()->CallEventHandlers($Sender, 'Gdn_Upload', 'GetUrls'); } if ($Type === NULL) return $Urls; if (isset($Urls[$Type])) return $Urls[$Type]; return FALSE; }
[ "public", "static", "function", "Urls", "(", "$", "Type", "=", "NULL", ")", "{", "static", "$", "Urls", "=", "NULL", ";", "if", "(", "$", "Urls", "===", "NULL", ")", "{", "$", "Urls", "=", "array", "(", "''", "=>", "Asset", "(", "'/uploads'", ",", "TRUE", ")", ")", ";", "$", "Sender", "=", "new", "stdClass", "(", ")", ";", "$", "Sender", "->", "Returns", "=", "array", "(", ")", ";", "$", "Sender", "->", "EventArguments", "=", "array", "(", ")", ";", "$", "Sender", "->", "EventArguments", "[", "'Urls'", "]", "=", "&", "$", "Urls", ";", "Gdn", "::", "PluginManager", "(", ")", "->", "CallEventHandlers", "(", "$", "Sender", ",", "'Gdn_Upload'", ",", "'GetUrls'", ")", ";", "}", "if", "(", "$", "Type", "===", "NULL", ")", "return", "$", "Urls", ";", "if", "(", "isset", "(", "$", "Urls", "[", "$", "Type", "]", ")", ")", "return", "$", "Urls", "[", "$", "Type", "]", ";", "return", "FALSE", ";", "}" ]
Returns the url prefix for a given type. If there is a plugin that wants to store uploads at a different location or in a different way then they register themselves by subscribing to the Gdn_Upload_GetUrls_Handler event. After that they will be available here. @param string $Type The type of upload to get the prefix for. @return string The url prefix.
[ "Returns", "the", "url", "prefix", "for", "a", "given", "type", ".", "If", "there", "is", "a", "plugin", "that", "wants", "to", "store", "uploads", "at", "a", "different", "location", "or", "in", "a", "different", "way", "then", "they", "register", "themselves", "by", "subscribing", "to", "the", "Gdn_Upload_GetUrls_Handler", "event", ".", "After", "that", "they", "will", "be", "available", "here", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.upload.php#L243-L262
237,478
bishopb/vanilla
library/core/class.upload.php
Gdn_Upload.ValidateUpload
public function ValidateUpload($InputName, $ThrowException = TRUE) { $Ex = FALSE; if (!array_key_exists($InputName, $_FILES) || (!is_uploaded_file($_FILES[$InputName]['tmp_name']) && GetValue('error', $_FILES[$InputName], 0) == 0)) { // Check the content length to see if we exceeded the max post size. $ContentLength = Gdn::Request()->GetValueFrom('server', 'CONTENT_LENGTH'); $MaxPostSize = self::UnformatFileSize(ini_get('post_max_size')); if($ContentLength > $MaxPostSize) { $Ex = sprintf(T('Gdn_Upload.Error.MaxPostSize', 'The file is larger than the maximum post size. (%s)'), self::FormatFileSize($MaxPostSize)); } else { $Ex = T('The file failed to upload.'); } } else { switch ($_FILES[$InputName]['error']) { case 1: case 2: $MaxFileSize = self::UnformatFileSize(ini_get('upload_max_filesize')); $Ex = sprintf(T('Gdn_Upload.Error.PhpMaxFileSize', 'The file is larger than the server\'s maximum file size. (%s)'), self::FormatFileSize($MaxFileSize)); break; case 3: case 4: $Ex = T('The file failed to upload.'); break; case 6: $Ex = T('The temporary upload folder has not been configured.'); break; case 7: $Ex = T('Failed to write the file to disk.'); break; case 8: $Ex = T('The upload was stopped by extension.'); break; } } $Foo = self::FormatFileSize($this->_MaxFileSize); // Check the maxfilesize again just in case the value was spoofed in the form. if (!$Ex && $this->_MaxFileSize > 0 && filesize($_FILES[$InputName]['tmp_name']) > $this->_MaxFileSize) { $Ex = sprintf(T('Gdn_Upload.Error.MaxFileSize', 'The file is larger than the maximum file size. (%s)'), self::FormatFileSize($this->_MaxFileSize)); } elseif(!$Ex) { // Make sure that the file extension is allowed. $Extension = pathinfo($_FILES[$InputName]['name'], PATHINFO_EXTENSION); if (!InArrayI($Extension, $this->_AllowedFileExtensions)) $Ex = sprintf(T('You cannot upload files with this extension (%s). Allowed extension(s) are %s.'), $Extension, implode(', ', $this->_AllowedFileExtensions)); } if($Ex) { if($ThrowException) { throw new Gdn_UserException($Ex); } else { $this->Exception = $Ex; return FALSE; } } else { // If all validations were successful, return the tmp name/location of the file. $this->_UploadedFile = $_FILES[$InputName]; return $this->_UploadedFile['tmp_name']; } }
php
public function ValidateUpload($InputName, $ThrowException = TRUE) { $Ex = FALSE; if (!array_key_exists($InputName, $_FILES) || (!is_uploaded_file($_FILES[$InputName]['tmp_name']) && GetValue('error', $_FILES[$InputName], 0) == 0)) { // Check the content length to see if we exceeded the max post size. $ContentLength = Gdn::Request()->GetValueFrom('server', 'CONTENT_LENGTH'); $MaxPostSize = self::UnformatFileSize(ini_get('post_max_size')); if($ContentLength > $MaxPostSize) { $Ex = sprintf(T('Gdn_Upload.Error.MaxPostSize', 'The file is larger than the maximum post size. (%s)'), self::FormatFileSize($MaxPostSize)); } else { $Ex = T('The file failed to upload.'); } } else { switch ($_FILES[$InputName]['error']) { case 1: case 2: $MaxFileSize = self::UnformatFileSize(ini_get('upload_max_filesize')); $Ex = sprintf(T('Gdn_Upload.Error.PhpMaxFileSize', 'The file is larger than the server\'s maximum file size. (%s)'), self::FormatFileSize($MaxFileSize)); break; case 3: case 4: $Ex = T('The file failed to upload.'); break; case 6: $Ex = T('The temporary upload folder has not been configured.'); break; case 7: $Ex = T('Failed to write the file to disk.'); break; case 8: $Ex = T('The upload was stopped by extension.'); break; } } $Foo = self::FormatFileSize($this->_MaxFileSize); // Check the maxfilesize again just in case the value was spoofed in the form. if (!$Ex && $this->_MaxFileSize > 0 && filesize($_FILES[$InputName]['tmp_name']) > $this->_MaxFileSize) { $Ex = sprintf(T('Gdn_Upload.Error.MaxFileSize', 'The file is larger than the maximum file size. (%s)'), self::FormatFileSize($this->_MaxFileSize)); } elseif(!$Ex) { // Make sure that the file extension is allowed. $Extension = pathinfo($_FILES[$InputName]['name'], PATHINFO_EXTENSION); if (!InArrayI($Extension, $this->_AllowedFileExtensions)) $Ex = sprintf(T('You cannot upload files with this extension (%s). Allowed extension(s) are %s.'), $Extension, implode(', ', $this->_AllowedFileExtensions)); } if($Ex) { if($ThrowException) { throw new Gdn_UserException($Ex); } else { $this->Exception = $Ex; return FALSE; } } else { // If all validations were successful, return the tmp name/location of the file. $this->_UploadedFile = $_FILES[$InputName]; return $this->_UploadedFile['tmp_name']; } }
[ "public", "function", "ValidateUpload", "(", "$", "InputName", ",", "$", "ThrowException", "=", "TRUE", ")", "{", "$", "Ex", "=", "FALSE", ";", "if", "(", "!", "array_key_exists", "(", "$", "InputName", ",", "$", "_FILES", ")", "||", "(", "!", "is_uploaded_file", "(", "$", "_FILES", "[", "$", "InputName", "]", "[", "'tmp_name'", "]", ")", "&&", "GetValue", "(", "'error'", ",", "$", "_FILES", "[", "$", "InputName", "]", ",", "0", ")", "==", "0", ")", ")", "{", "// Check the content length to see if we exceeded the max post size.", "$", "ContentLength", "=", "Gdn", "::", "Request", "(", ")", "->", "GetValueFrom", "(", "'server'", ",", "'CONTENT_LENGTH'", ")", ";", "$", "MaxPostSize", "=", "self", "::", "UnformatFileSize", "(", "ini_get", "(", "'post_max_size'", ")", ")", ";", "if", "(", "$", "ContentLength", ">", "$", "MaxPostSize", ")", "{", "$", "Ex", "=", "sprintf", "(", "T", "(", "'Gdn_Upload.Error.MaxPostSize'", ",", "'The file is larger than the maximum post size. (%s)'", ")", ",", "self", "::", "FormatFileSize", "(", "$", "MaxPostSize", ")", ")", ";", "}", "else", "{", "$", "Ex", "=", "T", "(", "'The file failed to upload.'", ")", ";", "}", "}", "else", "{", "switch", "(", "$", "_FILES", "[", "$", "InputName", "]", "[", "'error'", "]", ")", "{", "case", "1", ":", "case", "2", ":", "$", "MaxFileSize", "=", "self", "::", "UnformatFileSize", "(", "ini_get", "(", "'upload_max_filesize'", ")", ")", ";", "$", "Ex", "=", "sprintf", "(", "T", "(", "'Gdn_Upload.Error.PhpMaxFileSize'", ",", "'The file is larger than the server\\'s maximum file size. (%s)'", ")", ",", "self", "::", "FormatFileSize", "(", "$", "MaxFileSize", ")", ")", ";", "break", ";", "case", "3", ":", "case", "4", ":", "$", "Ex", "=", "T", "(", "'The file failed to upload.'", ")", ";", "break", ";", "case", "6", ":", "$", "Ex", "=", "T", "(", "'The temporary upload folder has not been configured.'", ")", ";", "break", ";", "case", "7", ":", "$", "Ex", "=", "T", "(", "'Failed to write the file to disk.'", ")", ";", "break", ";", "case", "8", ":", "$", "Ex", "=", "T", "(", "'The upload was stopped by extension.'", ")", ";", "break", ";", "}", "}", "$", "Foo", "=", "self", "::", "FormatFileSize", "(", "$", "this", "->", "_MaxFileSize", ")", ";", "// Check the maxfilesize again just in case the value was spoofed in the form.", "if", "(", "!", "$", "Ex", "&&", "$", "this", "->", "_MaxFileSize", ">", "0", "&&", "filesize", "(", "$", "_FILES", "[", "$", "InputName", "]", "[", "'tmp_name'", "]", ")", ">", "$", "this", "->", "_MaxFileSize", ")", "{", "$", "Ex", "=", "sprintf", "(", "T", "(", "'Gdn_Upload.Error.MaxFileSize'", ",", "'The file is larger than the maximum file size. (%s)'", ")", ",", "self", "::", "FormatFileSize", "(", "$", "this", "->", "_MaxFileSize", ")", ")", ";", "}", "elseif", "(", "!", "$", "Ex", ")", "{", "// Make sure that the file extension is allowed.", "$", "Extension", "=", "pathinfo", "(", "$", "_FILES", "[", "$", "InputName", "]", "[", "'name'", "]", ",", "PATHINFO_EXTENSION", ")", ";", "if", "(", "!", "InArrayI", "(", "$", "Extension", ",", "$", "this", "->", "_AllowedFileExtensions", ")", ")", "$", "Ex", "=", "sprintf", "(", "T", "(", "'You cannot upload files with this extension (%s). Allowed extension(s) are %s.'", ")", ",", "$", "Extension", ",", "implode", "(", "', '", ",", "$", "this", "->", "_AllowedFileExtensions", ")", ")", ";", "}", "if", "(", "$", "Ex", ")", "{", "if", "(", "$", "ThrowException", ")", "{", "throw", "new", "Gdn_UserException", "(", "$", "Ex", ")", ";", "}", "else", "{", "$", "this", "->", "Exception", "=", "$", "Ex", ";", "return", "FALSE", ";", "}", "}", "else", "{", "// If all validations were successful, return the tmp name/location of the file.", "$", "this", "->", "_UploadedFile", "=", "$", "_FILES", "[", "$", "InputName", "]", ";", "return", "$", "this", "->", "_UploadedFile", "[", "'tmp_name'", "]", ";", "}", "}" ]
Validates the uploaded file. Returns the temporary name of the uploaded file.
[ "Validates", "the", "uploaded", "file", ".", "Returns", "the", "temporary", "name", "of", "the", "uploaded", "file", "." ]
8494eb4a4ad61603479015a8054d23ff488364e8
https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/library/core/class.upload.php#L267-L326
237,479
99designs/ergo
classes/Ergo/Routing/RoutedController.php
RoutedController._controllerFor
private function _controllerFor($name) { if(isset($this->_controllers[$name]) && is_string($this->_controllers[$name])) { return $this->_controllerFor($this->_controllers[$name]); } else if(isset($this->_controllers[$name]) && is_object($this->_controllers[$name])) { return $this->_controllers[$name]; } else if(isset($this->_controllerFactory)) { return $this->_controllerFactory->resolve($name); } else { throw new Exception("No controller found for $name"); } }
php
private function _controllerFor($name) { if(isset($this->_controllers[$name]) && is_string($this->_controllers[$name])) { return $this->_controllerFor($this->_controllers[$name]); } else if(isset($this->_controllers[$name]) && is_object($this->_controllers[$name])) { return $this->_controllers[$name]; } else if(isset($this->_controllerFactory)) { return $this->_controllerFactory->resolve($name); } else { throw new Exception("No controller found for $name"); } }
[ "private", "function", "_controllerFor", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_controllers", "[", "$", "name", "]", ")", "&&", "is_string", "(", "$", "this", "->", "_controllers", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "_controllerFor", "(", "$", "this", "->", "_controllers", "[", "$", "name", "]", ")", ";", "}", "else", "if", "(", "isset", "(", "$", "this", "->", "_controllers", "[", "$", "name", "]", ")", "&&", "is_object", "(", "$", "this", "->", "_controllers", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "_controllers", "[", "$", "name", "]", ";", "}", "else", "if", "(", "isset", "(", "$", "this", "->", "_controllerFactory", ")", ")", "{", "return", "$", "this", "->", "_controllerFactory", "->", "resolve", "(", "$", "name", ")", ";", "}", "else", "{", "throw", "new", "Exception", "(", "\"No controller found for $name\"", ")", ";", "}", "}" ]
Gets a controller for a path, either from a locally registered controller or one from a controller factory
[ "Gets", "a", "controller", "for", "a", "path", "either", "from", "a", "locally", "registered", "controller", "or", "one", "from", "a", "controller", "factory" ]
8fbcfe683a14572cbf26ff59c3537c2261a7a4eb
https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/RoutedController.php#L54-L72
237,480
99designs/ergo
classes/Ergo/Routing/RoutedController.php
RoutedController.connect
public function connect($url, $name, $controller=null) { $this->_router->connect($url, $name, $controller); // register the controller if one is provided if(!is_null($controller)) { $this->_controllers[$name] = $controller; } return $this; }
php
public function connect($url, $name, $controller=null) { $this->_router->connect($url, $name, $controller); // register the controller if one is provided if(!is_null($controller)) { $this->_controllers[$name] = $controller; } return $this; }
[ "public", "function", "connect", "(", "$", "url", ",", "$", "name", ",", "$", "controller", "=", "null", ")", "{", "$", "this", "->", "_router", "->", "connect", "(", "$", "url", ",", "$", "name", ",", "$", "controller", ")", ";", "// register the controller if one is provided", "if", "(", "!", "is_null", "(", "$", "controller", ")", ")", "{", "$", "this", "->", "_controllers", "[", "$", "name", "]", "=", "$", "controller", ";", "}", "return", "$", "this", ";", "}" ]
Defines a url, a route name and an optional controller @param $url string the url to connect the route to @param $name string an arbitrary controller name, must be unique @param $controller mixed either a controller class, or the name of another route
[ "Defines", "a", "url", "a", "route", "name", "and", "an", "optional", "controller" ]
8fbcfe683a14572cbf26ff59c3537c2261a7a4eb
https://github.com/99designs/ergo/blob/8fbcfe683a14572cbf26ff59c3537c2261a7a4eb/classes/Ergo/Routing/RoutedController.php#L95-L106
237,481
requtize/atline
src/Atline/Environment.php
Environment.fequiv_mb_ucfirst
protected function fequiv_mb_ucfirst($string, $encoding = 'utf8') { return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding).mb_substr($string, 1, mb_strlen($string, $encoding) - 1, $encoding); }
php
protected function fequiv_mb_ucfirst($string, $encoding = 'utf8') { return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding).mb_substr($string, 1, mb_strlen($string, $encoding) - 1, $encoding); }
[ "protected", "function", "fequiv_mb_ucfirst", "(", "$", "string", ",", "$", "encoding", "=", "'utf8'", ")", "{", "return", "mb_strtoupper", "(", "mb_substr", "(", "$", "string", ",", "0", ",", "1", ",", "$", "encoding", ")", ",", "$", "encoding", ")", ".", "mb_substr", "(", "$", "string", ",", "1", ",", "mb_strlen", "(", "$", "string", ",", "$", "encoding", ")", "-", "1", ",", "$", "encoding", ")", ";", "}" ]
Equivalent function to ucfirst with mbstring usage. @param string $string Input string. @param string $encoding Encoding. @return Transformed output string.
[ "Equivalent", "function", "to", "ucfirst", "with", "mbstring", "usage", "." ]
9a1b5fe70485f701b3d300fe41d81e6eccc0f27d
https://github.com/requtize/atline/blob/9a1b5fe70485f701b3d300fe41d81e6eccc0f27d/src/Atline/Environment.php#L100-L103
237,482
helloandre/pressing
src/Parser.php
Parser.parse
public static function parse($path) { if (!file_exists($path)) { throw new \Exception("$path not found"); } $src = file_get_contents($path); if (!$src) { throw new \Exception("could not read $path"); } // first of all do we have any frontmatter in there? preg_match(self::$frontmatter_regex, $src, $matches); if (!empty($matches)) { // if we have an empty frontmatter, this will fail // but we still want to act like there was something there if (!($frontmatter = json_decode(trim($matches[1]), true))) { $frontmatter = array(); } } else { $frontmatter = false; } // remove any frontmatter $plain_src = preg_replace(self::$frontmatter_regex, "", $src); return array( 'frontmatter' => $frontmatter, 'content' => $plain_src ); }
php
public static function parse($path) { if (!file_exists($path)) { throw new \Exception("$path not found"); } $src = file_get_contents($path); if (!$src) { throw new \Exception("could not read $path"); } // first of all do we have any frontmatter in there? preg_match(self::$frontmatter_regex, $src, $matches); if (!empty($matches)) { // if we have an empty frontmatter, this will fail // but we still want to act like there was something there if (!($frontmatter = json_decode(trim($matches[1]), true))) { $frontmatter = array(); } } else { $frontmatter = false; } // remove any frontmatter $plain_src = preg_replace(self::$frontmatter_regex, "", $src); return array( 'frontmatter' => $frontmatter, 'content' => $plain_src ); }
[ "public", "static", "function", "parse", "(", "$", "path", ")", "{", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "\"$path not found\"", ")", ";", "}", "$", "src", "=", "file_get_contents", "(", "$", "path", ")", ";", "if", "(", "!", "$", "src", ")", "{", "throw", "new", "\\", "Exception", "(", "\"could not read $path\"", ")", ";", "}", "// first of all do we have any frontmatter in there?", "preg_match", "(", "self", "::", "$", "frontmatter_regex", ",", "$", "src", ",", "$", "matches", ")", ";", "if", "(", "!", "empty", "(", "$", "matches", ")", ")", "{", "// if we have an empty frontmatter, this will fail ", "// but we still want to act like there was something there", "if", "(", "!", "(", "$", "frontmatter", "=", "json_decode", "(", "trim", "(", "$", "matches", "[", "1", "]", ")", ",", "true", ")", ")", ")", "{", "$", "frontmatter", "=", "array", "(", ")", ";", "}", "}", "else", "{", "$", "frontmatter", "=", "false", ";", "}", "// remove any frontmatter", "$", "plain_src", "=", "preg_replace", "(", "self", "::", "$", "frontmatter_regex", ",", "\"\"", ",", "$", "src", ")", ";", "return", "array", "(", "'frontmatter'", "=>", "$", "frontmatter", ",", "'content'", "=>", "$", "plain_src", ")", ";", "}" ]
parse out the frontmatter and content from the file @param String $path - absolute path @return Array - 'frontmatter' and 'content' values
[ "parse", "out", "the", "frontmatter", "and", "content", "from", "the", "file" ]
e4244c7bbe90c38fa7d45e3c2da5d4b9153a0f54
https://github.com/helloandre/pressing/blob/e4244c7bbe90c38fa7d45e3c2da5d4b9153a0f54/src/Parser.php#L27-L56
237,483
samurai-fw/samurai
src/Samurai/Component/Request/CliRequest.php
CliRequest.add
public function add($key, $value) { if (! isset($this->_params[$key])) { $this->_params[$key] = array(); } $this->_params[$key][] = $value; }
php
public function add($key, $value) { if (! isset($this->_params[$key])) { $this->_params[$key] = array(); } $this->_params[$key][] = $value; }
[ "public", "function", "add", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_params", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "_params", "[", "$", "key", "]", "=", "array", "(", ")", ";", "}", "$", "this", "->", "_params", "[", "$", "key", "]", "[", "]", "=", "$", "value", ";", "}" ]
add param. @access public @param string $key @param string $value
[ "add", "param", "." ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Request/CliRequest.php#L119-L125
237,484
samurai-fw/samurai
src/Samurai/Component/Request/CliRequest.php
CliRequest.getAsArray
public function getAsArray($key, array $default = array()) { $value = parent::get($key, $default); if (is_array($value) && !$value) $value = $default; return (array)$value; }
php
public function getAsArray($key, array $default = array()) { $value = parent::get($key, $default); if (is_array($value) && !$value) $value = $default; return (array)$value; }
[ "public", "function", "getAsArray", "(", "$", "key", ",", "array", "$", "default", "=", "array", "(", ")", ")", "{", "$", "value", "=", "parent", "::", "get", "(", "$", "key", ",", "$", "default", ")", ";", "if", "(", "is_array", "(", "$", "value", ")", "&&", "!", "$", "value", ")", "$", "value", "=", "$", "default", ";", "return", "(", "array", ")", "$", "value", ";", "}" ]
Get param as array. @access public @param string $key @param array $default @return array
[ "Get", "param", "as", "array", "." ]
7ca3847b13f86e2847a17ab5e8e4e20893021d5a
https://github.com/samurai-fw/samurai/blob/7ca3847b13f86e2847a17ab5e8e4e20893021d5a/src/Samurai/Component/Request/CliRequest.php#L154-L159
237,485
WasabiLib/wasabilib
src/WasabiLib/Ajax/Response.php
Response.add
public function add($object){ if(is_array($object)) { $this->responses = array_merge($this->responses, $object); } else { $implementedInterfaces = class_implements($object); if(array_key_exists("WasabiLib\Ajax\ResponseConfiguratorInterface", $implementedInterfaces)) { $object->configure(); // $this->responses = array_merge($this->responses, $object->getResponseTypes()); foreach($object->getResponseTypes() as $responseType){ $implementedInterfacesInResponseType = class_implements($responseType); if(array_key_exists("WasabiLib\Ajax\ResponseConfiguratorInterface", $implementedInterfacesInResponseType)) { $this->add($responseType); } else{ $this->responses[]=$responseType; } } } else if(array_key_exists("WasabiLib\Ajax\ResponseTypeInterface", $implementedInterfaces)) { $this->responses[] = $object; } else { throw new InvalidArgumentException("Invalid parameter type! Given value must be an array or implements the interfaces ResponseConfiguratorInterface or ResponseTypeInterface"); } } }
php
public function add($object){ if(is_array($object)) { $this->responses = array_merge($this->responses, $object); } else { $implementedInterfaces = class_implements($object); if(array_key_exists("WasabiLib\Ajax\ResponseConfiguratorInterface", $implementedInterfaces)) { $object->configure(); // $this->responses = array_merge($this->responses, $object->getResponseTypes()); foreach($object->getResponseTypes() as $responseType){ $implementedInterfacesInResponseType = class_implements($responseType); if(array_key_exists("WasabiLib\Ajax\ResponseConfiguratorInterface", $implementedInterfacesInResponseType)) { $this->add($responseType); } else{ $this->responses[]=$responseType; } } } else if(array_key_exists("WasabiLib\Ajax\ResponseTypeInterface", $implementedInterfaces)) { $this->responses[] = $object; } else { throw new InvalidArgumentException("Invalid parameter type! Given value must be an array or implements the interfaces ResponseConfiguratorInterface or ResponseTypeInterface"); } } }
[ "public", "function", "add", "(", "$", "object", ")", "{", "if", "(", "is_array", "(", "$", "object", ")", ")", "{", "$", "this", "->", "responses", "=", "array_merge", "(", "$", "this", "->", "responses", ",", "$", "object", ")", ";", "}", "else", "{", "$", "implementedInterfaces", "=", "class_implements", "(", "$", "object", ")", ";", "if", "(", "array_key_exists", "(", "\"WasabiLib\\Ajax\\ResponseConfiguratorInterface\"", ",", "$", "implementedInterfaces", ")", ")", "{", "$", "object", "->", "configure", "(", ")", ";", "// $this->responses = array_merge($this->responses, $object->getResponseTypes());", "foreach", "(", "$", "object", "->", "getResponseTypes", "(", ")", "as", "$", "responseType", ")", "{", "$", "implementedInterfacesInResponseType", "=", "class_implements", "(", "$", "responseType", ")", ";", "if", "(", "array_key_exists", "(", "\"WasabiLib\\Ajax\\ResponseConfiguratorInterface\"", ",", "$", "implementedInterfacesInResponseType", ")", ")", "{", "$", "this", "->", "add", "(", "$", "responseType", ")", ";", "}", "else", "{", "$", "this", "->", "responses", "[", "]", "=", "$", "responseType", ";", "}", "}", "}", "else", "if", "(", "array_key_exists", "(", "\"WasabiLib\\Ajax\\ResponseTypeInterface\"", ",", "$", "implementedInterfaces", ")", ")", "{", "$", "this", "->", "responses", "[", "]", "=", "$", "object", ";", "}", "else", "{", "throw", "new", "InvalidArgumentException", "(", "\"Invalid parameter type! Given value must be an array or implements the interfaces ResponseConfiguratorInterface or ResponseTypeInterface\"", ")", ";", "}", "}", "}" ]
Adds an object which implements the interfaces ResponseTypeInterface or ResponseConfiguratorInterface or an array of objects which implement the ResponseTypeInterface. @param $object array | ResponseConfiguratorInterface | ResponseTypeInterface @throws \Zend\Code\Exception\InvalidArgumentException
[ "Adds", "an", "object", "which", "implements", "the", "interfaces", "ResponseTypeInterface", "or", "ResponseConfiguratorInterface", "or", "an", "array", "of", "objects", "which", "implement", "the", "ResponseTypeInterface", "." ]
5a55bfbea6b6ee10222c521112d469015db170b7
https://github.com/WasabiLib/wasabilib/blob/5a55bfbea6b6ee10222c521112d469015db170b7/src/WasabiLib/Ajax/Response.php#L37-L63
237,486
phPoirot/Http
HttpMessage/Request/StreamBodyMultiPart.php
StreamBodyMultiPart.addElements
function addElements($multiPart) { if (! is_array($multiPart) ) throw new \InvalidArgumentException(sprintf( 'Accept array of Files; given: "%s".' , \Poirot\Std\flatten($multiPart) )); foreach($multiPart as $name => $element) $this->addElement($name, $element); $this->addElementDone(); return $this; }
php
function addElements($multiPart) { if (! is_array($multiPart) ) throw new \InvalidArgumentException(sprintf( 'Accept array of Files; given: "%s".' , \Poirot\Std\flatten($multiPart) )); foreach($multiPart as $name => $element) $this->addElement($name, $element); $this->addElementDone(); return $this; }
[ "function", "addElements", "(", "$", "multiPart", ")", "{", "if", "(", "!", "is_array", "(", "$", "multiPart", ")", ")", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Accept array of Files; given: \"%s\".'", ",", "\\", "Poirot", "\\", "Std", "\\", "flatten", "(", "$", "multiPart", ")", ")", ")", ";", "foreach", "(", "$", "multiPart", "as", "$", "name", "=>", "$", "element", ")", "$", "this", "->", "addElement", "(", "$", "name", ",", "$", "element", ")", ";", "$", "this", "->", "addElementDone", "(", ")", ";", "return", "$", "this", ";", "}" ]
Append Boundary Elements @param array|string $multiPart @return $this
[ "Append", "Boundary", "Elements" ]
3230b3555abf0e74c3d593fc49c8978758969736
https://github.com/phPoirot/Http/blob/3230b3555abf0e74c3d593fc49c8978758969736/HttpMessage/Request/StreamBodyMultiPart.php#L69-L84
237,487
phPoirot/Http
HttpMessage/Request/StreamBodyMultiPart.php
StreamBodyMultiPart.addElement
function addElement($fieldName, $element, $headers = null) { if ($this->_trailingBoundary) throw new \Exception('Trailing Boundary Is Added.'); if (! $headers instanceof iHeaders ) $headers = (! empty($headers) ) ? new CollectionHeader($headers) : new CollectionHeader; if ( $this->_addElement($fieldName, $element, $headers) ) $this->elementsAdded[$fieldName] = $element; return $this; }
php
function addElement($fieldName, $element, $headers = null) { if ($this->_trailingBoundary) throw new \Exception('Trailing Boundary Is Added.'); if (! $headers instanceof iHeaders ) $headers = (! empty($headers) ) ? new CollectionHeader($headers) : new CollectionHeader; if ( $this->_addElement($fieldName, $element, $headers) ) $this->elementsAdded[$fieldName] = $element; return $this; }
[ "function", "addElement", "(", "$", "fieldName", ",", "$", "element", ",", "$", "headers", "=", "null", ")", "{", "if", "(", "$", "this", "->", "_trailingBoundary", ")", "throw", "new", "\\", "Exception", "(", "'Trailing Boundary Is Added.'", ")", ";", "if", "(", "!", "$", "headers", "instanceof", "iHeaders", ")", "$", "headers", "=", "(", "!", "empty", "(", "$", "headers", ")", ")", "?", "new", "CollectionHeader", "(", "$", "headers", ")", ":", "new", "CollectionHeader", ";", "if", "(", "$", "this", "->", "_addElement", "(", "$", "fieldName", ",", "$", "element", ",", "$", "headers", ")", ")", "$", "this", "->", "elementsAdded", "[", "$", "fieldName", "]", "=", "$", "element", ";", "return", "$", "this", ";", "}" ]
Append Boundary Element @param string $fieldName Form Field Name @param UploadedFileInterface|string|StreamInterface $element @param null|array $headers Extra Headers To Be Added @return $this @throws \Exception
[ "Append", "Boundary", "Element" ]
3230b3555abf0e74c3d593fc49c8978758969736
https://github.com/phPoirot/Http/blob/3230b3555abf0e74c3d593fc49c8978758969736/HttpMessage/Request/StreamBodyMultiPart.php#L96-L109
237,488
phPoirot/Http
HttpMessage/Request/StreamBodyMultiPart.php
StreamBodyMultiPart.addElementDone
function addElementDone() { ## add trailing boundary as stream if not $this->_trailingBoundary = new STemporary("\r\n"."--{$this->_boundary}--"); $this->_t__wrap_stream->addStream($this->_trailingBoundary->rewind()); }
php
function addElementDone() { ## add trailing boundary as stream if not $this->_trailingBoundary = new STemporary("\r\n"."--{$this->_boundary}--"); $this->_t__wrap_stream->addStream($this->_trailingBoundary->rewind()); }
[ "function", "addElementDone", "(", ")", "{", "## add trailing boundary as stream if not", "$", "this", "->", "_trailingBoundary", "=", "new", "STemporary", "(", "\"\\r\\n\"", ".", "\"--{$this->_boundary}--\"", ")", ";", "$", "this", "->", "_t__wrap_stream", "->", "addStream", "(", "$", "this", "->", "_trailingBoundary", "->", "rewind", "(", ")", ")", ";", "}" ]
Add Trailing Boundary And Finish Data @return void
[ "Add", "Trailing", "Boundary", "And", "Finish", "Data" ]
3230b3555abf0e74c3d593fc49c8978758969736
https://github.com/phPoirot/Http/blob/3230b3555abf0e74c3d593fc49c8978758969736/HttpMessage/Request/StreamBodyMultiPart.php#L178-L183
237,489
znframework/package-generator
Project.php
Project.generate
public static function generate(String $name) : Bool { Post::project($name); $validation = Singleton::class('ZN\Validation\Data'); $validation->rules('project', ['alpha'], 'Project Name'); if( ! $error = $validation->error('string') ) { $source = EXTERNAL_FILES_DIR . 'DefaultProject.zip'; $target = PROJECTS_DIR . Post::project(); Forge::zipExtract($source, $target); return true; } return false; }
php
public static function generate(String $name) : Bool { Post::project($name); $validation = Singleton::class('ZN\Validation\Data'); $validation->rules('project', ['alpha'], 'Project Name'); if( ! $error = $validation->error('string') ) { $source = EXTERNAL_FILES_DIR . 'DefaultProject.zip'; $target = PROJECTS_DIR . Post::project(); Forge::zipExtract($source, $target); return true; } return false; }
[ "public", "static", "function", "generate", "(", "String", "$", "name", ")", ":", "Bool", "{", "Post", "::", "project", "(", "$", "name", ")", ";", "$", "validation", "=", "Singleton", "::", "class", "(", "'ZN\\Validation\\Data'", ")", ";", "$", "validation", "->", "rules", "(", "'project'", ",", "[", "'alpha'", "]", ",", "'Project Name'", ")", ";", "if", "(", "!", "$", "error", "=", "$", "validation", "->", "error", "(", "'string'", ")", ")", "{", "$", "source", "=", "EXTERNAL_FILES_DIR", ".", "'DefaultProject.zip'", ";", "$", "target", "=", "PROJECTS_DIR", ".", "Post", "::", "project", "(", ")", ";", "Forge", "::", "zipExtract", "(", "$", "source", ",", "$", "target", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Select project name @param string $name @return bool
[ "Select", "project", "name" ]
4524c28c607d8a5799b60bd39bee8be4fd1e7fba
https://github.com/znframework/package-generator/blob/4524c28c607d8a5799b60bd39bee8be4fd1e7fba/Project.php#L25-L44
237,490
atelierspierrot/library
src/Library/Helper/Number.php
Number.isPrime
public static function isPrime($val = null) { if (is_null($val)) { return null; } if ( ($val<=1) || ($val>2 && ($val%2)===0) ) { return false; } for ($i=2;$i<$val;$i++) { if (($val%$i)===0) { return false; } } return true; }
php
public static function isPrime($val = null) { if (is_null($val)) { return null; } if ( ($val<=1) || ($val>2 && ($val%2)===0) ) { return false; } for ($i=2;$i<$val;$i++) { if (($val%$i)===0) { return false; } } return true; }
[ "public", "static", "function", "isPrime", "(", "$", "val", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "val", ")", ")", "{", "return", "null", ";", "}", "if", "(", "(", "$", "val", "<=", "1", ")", "||", "(", "$", "val", ">", "2", "&&", "(", "$", "val", "%", "2", ")", "===", "0", ")", ")", "{", "return", "false", ";", "}", "for", "(", "$", "i", "=", "2", ";", "$", "i", "<", "$", "val", ";", "$", "i", "++", ")", "{", "if", "(", "(", "$", "val", "%", "$", "i", ")", "===", "0", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Test if an integer is a "prime number" @param int $val @return bool
[ "Test", "if", "an", "integer", "is", "a", "prime", "number" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Helper/Number.php#L74-L91
237,491
atelierspierrot/library
src/Library/Helper/Number.php
Number.isLuhn
public static function isLuhn($val = null) { if (is_null($val)) { return null; } $_num = substr($val, 0, strlen($val)-1); return (bool) (intval($val) == intval($_num.self::getLuhnKey($_num))); }
php
public static function isLuhn($val = null) { if (is_null($val)) { return null; } $_num = substr($val, 0, strlen($val)-1); return (bool) (intval($val) == intval($_num.self::getLuhnKey($_num))); }
[ "public", "static", "function", "isLuhn", "(", "$", "val", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "val", ")", ")", "{", "return", "null", ";", "}", "$", "_num", "=", "substr", "(", "$", "val", ",", "0", ",", "strlen", "(", "$", "val", ")", "-", "1", ")", ";", "return", "(", "bool", ")", "(", "intval", "(", "$", "val", ")", "==", "intval", "(", "$", "_num", ".", "self", "::", "getLuhnKey", "(", "$", "_num", ")", ")", ")", ";", "}" ]
Check that the last number in a suite is its Luhn key @param int $val The number to check INCLUDING Luhn's key at last @return bool
[ "Check", "that", "the", "last", "number", "in", "a", "suite", "is", "its", "Luhn", "key" ]
a2988a11370d13c7e0dc47f9d2d81c664c30b8dd
https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Helper/Number.php#L154-L161
237,492
matuck/TorFeed
TorFeed.php
TorFeed.getItems
public function getItems() { $namespaces = $this->xml->getDocNamespaces(); foreach($namespaces as $namespace => $url) { $this->xml->registerXPathNamespace($namespace, $url); } foreach ($this->xml->xpath($this->itemXpath) as $item) { $this->items[] = new Item ( $this->itemtitleXpath ? (string) $item->xpath($this->itemtitleXpath)[0] : NULL, $this->itemtorrenturlXpath ? (string) $item->xpath($this->itemtorrenturlXpath)[0] : NULL, $this->itemmagnetXpath ? (string) $item->xpath($this->itemmagnetXpath)[0] : NULL ); } return $this->items; }
php
public function getItems() { $namespaces = $this->xml->getDocNamespaces(); foreach($namespaces as $namespace => $url) { $this->xml->registerXPathNamespace($namespace, $url); } foreach ($this->xml->xpath($this->itemXpath) as $item) { $this->items[] = new Item ( $this->itemtitleXpath ? (string) $item->xpath($this->itemtitleXpath)[0] : NULL, $this->itemtorrenturlXpath ? (string) $item->xpath($this->itemtorrenturlXpath)[0] : NULL, $this->itemmagnetXpath ? (string) $item->xpath($this->itemmagnetXpath)[0] : NULL ); } return $this->items; }
[ "public", "function", "getItems", "(", ")", "{", "$", "namespaces", "=", "$", "this", "->", "xml", "->", "getDocNamespaces", "(", ")", ";", "foreach", "(", "$", "namespaces", "as", "$", "namespace", "=>", "$", "url", ")", "{", "$", "this", "->", "xml", "->", "registerXPathNamespace", "(", "$", "namespace", ",", "$", "url", ")", ";", "}", "foreach", "(", "$", "this", "->", "xml", "->", "xpath", "(", "$", "this", "->", "itemXpath", ")", "as", "$", "item", ")", "{", "$", "this", "->", "items", "[", "]", "=", "new", "Item", "(", "$", "this", "->", "itemtitleXpath", "?", "(", "string", ")", "$", "item", "->", "xpath", "(", "$", "this", "->", "itemtitleXpath", ")", "[", "0", "]", ":", "NULL", ",", "$", "this", "->", "itemtorrenturlXpath", "?", "(", "string", ")", "$", "item", "->", "xpath", "(", "$", "this", "->", "itemtorrenturlXpath", ")", "[", "0", "]", ":", "NULL", ",", "$", "this", "->", "itemmagnetXpath", "?", "(", "string", ")", "$", "item", "->", "xpath", "(", "$", "this", "->", "itemmagnetXpath", ")", "[", "0", "]", ":", "NULL", ")", ";", "}", "return", "$", "this", "->", "items", ";", "}" ]
Get Items from a feed. @return array Returns an array of Items
[ "Get", "Items", "from", "a", "feed", "." ]
278eeb43c0bde8d7bb3a00ef1efed14341788441
https://github.com/matuck/TorFeed/blob/278eeb43c0bde8d7bb3a00ef1efed14341788441/TorFeed.php#L114-L133
237,493
MehrAlsNix/Assumptions
src/Assume.php
Assume.assumeThat
public static function assumeThat($actual, Matcher $matcher, $message = ''): void { if (!$matcher->matches($actual)) { throw new AssumptionViolatedException($actual, $matcher, $message); } }
php
public static function assumeThat($actual, Matcher $matcher, $message = ''): void { if (!$matcher->matches($actual)) { throw new AssumptionViolatedException($actual, $matcher, $message); } }
[ "public", "static", "function", "assumeThat", "(", "$", "actual", ",", "Matcher", "$", "matcher", ",", "$", "message", "=", "''", ")", ":", "void", "{", "if", "(", "!", "$", "matcher", "->", "matches", "(", "$", "actual", ")", ")", "{", "throw", "new", "AssumptionViolatedException", "(", "$", "actual", ",", "$", "matcher", ",", "$", "message", ")", ";", "}", "}" ]
Assumes that a specific value matches a specific hamcrest matcher. @param mixed $actual @param Matcher $matcher @param string $message optional @return void @throws AssumptionViolatedException
[ "Assumes", "that", "a", "specific", "value", "matches", "a", "specific", "hamcrest", "matcher", "." ]
5d28349354bc80409beeac52df79e57d1d52bcf2
https://github.com/MehrAlsNix/Assumptions/blob/5d28349354bc80409beeac52df79e57d1d52bcf2/src/Assume.php#L77-L82
237,494
etd-framework/user
src/UserHelper.php
UserHelper.getUserGroups
public function getUserGroups() { $db = $this->db; $query = $db->getQuery(true) ->select('a.*, COUNT(DISTINCT b.id) AS level') ->from($db->quoteName('#__usergroups') . ' AS a') ->join('LEFT', $db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt') ->group('a.id, a.title, a.lft, a.rgt, a.parent_id') ->order('a.lft ASC'); return $db->setQuery($query) ->loadObjectList(); }
php
public function getUserGroups() { $db = $this->db; $query = $db->getQuery(true) ->select('a.*, COUNT(DISTINCT b.id) AS level') ->from($db->quoteName('#__usergroups') . ' AS a') ->join('LEFT', $db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt') ->group('a.id, a.title, a.lft, a.rgt, a.parent_id') ->order('a.lft ASC'); return $db->setQuery($query) ->loadObjectList(); }
[ "public", "function", "getUserGroups", "(", ")", "{", "$", "db", "=", "$", "this", "->", "db", ";", "$", "query", "=", "$", "db", "->", "getQuery", "(", "true", ")", "->", "select", "(", "'a.*, COUNT(DISTINCT b.id) AS level'", ")", "->", "from", "(", "$", "db", "->", "quoteName", "(", "'#__usergroups'", ")", ".", "' AS a'", ")", "->", "join", "(", "'LEFT'", ",", "$", "db", "->", "quoteName", "(", "'#__usergroups'", ")", ".", "' AS b ON a.lft > b.lft AND a.rgt < b.rgt'", ")", "->", "group", "(", "'a.id, a.title, a.lft, a.rgt, a.parent_id'", ")", "->", "order", "(", "'a.lft ASC'", ")", ";", "return", "$", "db", "->", "setQuery", "(", "$", "query", ")", "->", "loadObjectList", "(", ")", ";", "}" ]
Retourne les groupes utilisateurs. @return array Un tableau des groupes utilisateurs.
[ "Retourne", "les", "groupes", "utilisateurs", "." ]
2eb6e5b98ed724e590ec87d95e77ba4bd2b7a620
https://github.com/etd-framework/user/blob/2eb6e5b98ed724e590ec87d95e77ba4bd2b7a620/src/UserHelper.php#L41-L55
237,495
microffice/core
src/Microffice/Core/Traits/EloquentModelResourceTrait.php
EloquentModelResourceTrait.index
public function index() { $model = $this->modelFullName; $collection = $model::all(); if($collection->isEmpty()) throw new NotFoundException('There Are No Resources Named "' . $this->getResourceName() . '" Yet'); return $collection; }
php
public function index() { $model = $this->modelFullName; $collection = $model::all(); if($collection->isEmpty()) throw new NotFoundException('There Are No Resources Named "' . $this->getResourceName() . '" Yet'); return $collection; }
[ "public", "function", "index", "(", ")", "{", "$", "model", "=", "$", "this", "->", "modelFullName", ";", "$", "collection", "=", "$", "model", "::", "all", "(", ")", ";", "if", "(", "$", "collection", "->", "isEmpty", "(", ")", ")", "throw", "new", "NotFoundException", "(", "'There Are No Resources Named \"'", ".", "$", "this", "->", "getResourceName", "(", ")", ".", "'\" Yet'", ")", ";", "return", "$", "collection", ";", "}" ]
Return a listing of the resource. @return \Illuminate\Database\Eloquent\Collection
[ "Return", "a", "listing", "of", "the", "resource", "." ]
e98975bb6029c6a0c79d73bcabc5f067063ad9d9
https://github.com/microffice/core/blob/e98975bb6029c6a0c79d73bcabc5f067063ad9d9/src/Microffice/Core/Traits/EloquentModelResourceTrait.php#L28-L34
237,496
microffice/core
src/Microffice/Core/Traits/EloquentModelResourceTrait.php
EloquentModelResourceTrait.show
public function show($id) { $modelName = $this->modelFullName; $model = $modelName::find($id); if(!$model) throw new NotFoundException('There is no Resource with id = ' . $id . ' !'); return $model; }
php
public function show($id) { $modelName = $this->modelFullName; $model = $modelName::find($id); if(!$model) throw new NotFoundException('There is no Resource with id = ' . $id . ' !'); return $model; }
[ "public", "function", "show", "(", "$", "id", ")", "{", "$", "modelName", "=", "$", "this", "->", "modelFullName", ";", "$", "model", "=", "$", "modelName", "::", "find", "(", "$", "id", ")", ";", "if", "(", "!", "$", "model", ")", "throw", "new", "NotFoundException", "(", "'There is no Resource with id = '", ".", "$", "id", ".", "' !'", ")", ";", "return", "$", "model", ";", "}" ]
Return the specified resource. @param int $id @return \Illuminate\Database\Eloquent\Model|null
[ "Return", "the", "specified", "resource", "." ]
e98975bb6029c6a0c79d73bcabc5f067063ad9d9
https://github.com/microffice/core/blob/e98975bb6029c6a0c79d73bcabc5f067063ad9d9/src/Microffice/Core/Traits/EloquentModelResourceTrait.php#L58-L64
237,497
microffice/core
src/Microffice/Core/Traits/EloquentModelResourceTrait.php
EloquentModelResourceTrait.validate
protected function validate($data, $rules=false) { if(!$rules) { $modelName = $this->modelFullName; $rules = $modelName::$rules; } $validator = \Validator::make($data, $rules); if($validator->fails()) throw new ValidationException($validator); return true; }
php
protected function validate($data, $rules=false) { if(!$rules) { $modelName = $this->modelFullName; $rules = $modelName::$rules; } $validator = \Validator::make($data, $rules); if($validator->fails()) throw new ValidationException($validator); return true; }
[ "protected", "function", "validate", "(", "$", "data", ",", "$", "rules", "=", "false", ")", "{", "if", "(", "!", "$", "rules", ")", "{", "$", "modelName", "=", "$", "this", "->", "modelFullName", ";", "$", "rules", "=", "$", "modelName", "::", "$", "rules", ";", "}", "$", "validator", "=", "\\", "Validator", "::", "make", "(", "$", "data", ",", "$", "rules", ")", ";", "if", "(", "$", "validator", "->", "fails", "(", ")", ")", "throw", "new", "ValidationException", "(", "$", "validator", ")", ";", "return", "true", ";", "}" ]
Validate data for resource. @param array $data @param array $rules @return boolean
[ "Validate", "data", "for", "resource", "." ]
e98975bb6029c6a0c79d73bcabc5f067063ad9d9
https://github.com/microffice/core/blob/e98975bb6029c6a0c79d73bcabc5f067063ad9d9/src/Microffice/Core/Traits/EloquentModelResourceTrait.php#L106-L116
237,498
bugotech/io
src/Filesystem.php
Filesystem.force
public function force($path, $mode = 0777, $recursive = true) { if ($this->exists($path)) { return true; } return $this->makeDirectory($path, $mode, $recursive); }
php
public function force($path, $mode = 0777, $recursive = true) { if ($this->exists($path)) { return true; } return $this->makeDirectory($path, $mode, $recursive); }
[ "public", "function", "force", "(", "$", "path", ",", "$", "mode", "=", "0777", ",", "$", "recursive", "=", "true", ")", "{", "if", "(", "$", "this", "->", "exists", "(", "$", "path", ")", ")", "{", "return", "true", ";", "}", "return", "$", "this", "->", "makeDirectory", "(", "$", "path", ",", "$", "mode", ",", "$", "recursive", ")", ";", "}" ]
Alias of makeDirectory. @return bool
[ "Alias", "of", "makeDirectory", "." ]
3c7601af1839d1cdfa2ba5c43bf33d6d79117ae0
https://github.com/bugotech/io/blob/3c7601af1839d1cdfa2ba5c43bf33d6d79117ae0/src/Filesystem.php#L37-L44
237,499
bugotech/io
src/Filesystem.php
Filesystem.fileName
public function fileName($filename, $withExt = true) { return $withExt ? pathinfo($filename, PATHINFO_BASENAME) : pathinfo($filename, PATHINFO_FILENAME); }
php
public function fileName($filename, $withExt = true) { return $withExt ? pathinfo($filename, PATHINFO_BASENAME) : pathinfo($filename, PATHINFO_FILENAME); }
[ "public", "function", "fileName", "(", "$", "filename", ",", "$", "withExt", "=", "true", ")", "{", "return", "$", "withExt", "?", "pathinfo", "(", "$", "filename", ",", "PATHINFO_BASENAME", ")", ":", "pathinfo", "(", "$", "filename", ",", "PATHINFO_FILENAME", ")", ";", "}" ]
Get filename with or not extension. @return string
[ "Get", "filename", "with", "or", "not", "extension", "." ]
3c7601af1839d1cdfa2ba5c43bf33d6d79117ae0
https://github.com/bugotech/io/blob/3c7601af1839d1cdfa2ba5c43bf33d6d79117ae0/src/Filesystem.php#L63-L66