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
21,700
inhere/php-librarys
src/Traits/FixedEventTrait.php
FixedEventTrait.off
public function off(string $event) { if (false === ($key = array_search($event, $this->getSupportedEvents(), true))) { return null; } if (!isset($this->eventHandlers[$key]) || !($cb = $this->eventHandlers[$key])) { return null; } $this->eventHandlers[$key] = null; return $cb; }
php
public function off(string $event) { if (false === ($key = array_search($event, $this->getSupportedEvents(), true))) { return null; } if (!isset($this->eventHandlers[$key]) || !($cb = $this->eventHandlers[$key])) { return null; } $this->eventHandlers[$key] = null; return $cb; }
[ "public", "function", "off", "(", "string", "$", "event", ")", "{", "if", "(", "false", "===", "(", "$", "key", "=", "array_search", "(", "$", "event", ",", "$", "this", "->", "getSupportedEvents", "(", ")", ",", "true", ")", ")", ")", "{", "return", "null", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "eventHandlers", "[", "$", "key", "]", ")", "||", "!", "(", "$", "cb", "=", "$", "this", "->", "eventHandlers", "[", "$", "key", "]", ")", ")", "{", "return", "null", ";", "}", "$", "this", "->", "eventHandlers", "[", "$", "key", "]", "=", "null", ";", "return", "$", "cb", ";", "}" ]
remove event handler @param string $event @return bool
[ "remove", "event", "handler" ]
e6ca598685469794f310e3ab0e2bc19519cd0ae6
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/FixedEventTrait.php#L124-L137
21,701
oroinc/OroLayoutComponent
DeferredLayoutManipulator.php
DeferredLayoutManipulator.calculateActionCount
protected function calculateActionCount() { $counter = 0; foreach ($this->actions as $actions) { $counter += count($actions); } return $counter; }
php
protected function calculateActionCount() { $counter = 0; foreach ($this->actions as $actions) { $counter += count($actions); } return $counter; }
[ "protected", "function", "calculateActionCount", "(", ")", "{", "$", "counter", "=", "0", ";", "foreach", "(", "$", "this", "->", "actions", "as", "$", "actions", ")", "{", "$", "counter", "+=", "count", "(", "$", "actions", ")", ";", "}", "return", "$", "counter", ";", "}" ]
Returns the total number of actions in all groups @return int
[ "Returns", "the", "total", "number", "of", "actions", "in", "all", "groups" ]
682a96672393d81c63728e47c4a4c3618c515be0
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/DeferredLayoutManipulator.php#L378-L386
21,702
oroinc/OroLayoutComponent
DeferredLayoutManipulator.php
DeferredLayoutManipulator.removeNotImportantRemainingActions
protected function removeNotImportantRemainingActions() { // remove remaining 'move' actions if (!empty($this->actions[self::GROUP_ADD])) { foreach ($this->actions[self::GROUP_ADD] as $index => $action) { if ($action[0] === self::MOVE) { unset($this->actions[self::GROUP_ADD][$index]); } } } // remove remaining 'remove' actions if there are no any 'add' actions if (!empty($this->actions[self::GROUP_REMOVE]) && empty($this->actions[self::GROUP_ADD])) { unset($this->actions[self::GROUP_REMOVE]); } }
php
protected function removeNotImportantRemainingActions() { // remove remaining 'move' actions if (!empty($this->actions[self::GROUP_ADD])) { foreach ($this->actions[self::GROUP_ADD] as $index => $action) { if ($action[0] === self::MOVE) { unset($this->actions[self::GROUP_ADD][$index]); } } } // remove remaining 'remove' actions if there are no any 'add' actions if (!empty($this->actions[self::GROUP_REMOVE]) && empty($this->actions[self::GROUP_ADD])) { unset($this->actions[self::GROUP_REMOVE]); } }
[ "protected", "function", "removeNotImportantRemainingActions", "(", ")", "{", "// remove remaining 'move' actions", "if", "(", "!", "empty", "(", "$", "this", "->", "actions", "[", "self", "::", "GROUP_ADD", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "actions", "[", "self", "::", "GROUP_ADD", "]", "as", "$", "index", "=>", "$", "action", ")", "{", "if", "(", "$", "action", "[", "0", "]", "===", "self", "::", "MOVE", ")", "{", "unset", "(", "$", "this", "->", "actions", "[", "self", "::", "GROUP_ADD", "]", "[", "$", "index", "]", ")", ";", "}", "}", "}", "// remove remaining 'remove' actions if there are no any 'add' actions", "if", "(", "!", "empty", "(", "$", "this", "->", "actions", "[", "self", "::", "GROUP_REMOVE", "]", ")", "&&", "empty", "(", "$", "this", "->", "actions", "[", "self", "::", "GROUP_ADD", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "actions", "[", "self", "::", "GROUP_REMOVE", "]", ")", ";", "}", "}" ]
Checks if there are any not executed actions and remove actions which are not important
[ "Checks", "if", "there", "are", "any", "not", "executed", "actions", "and", "remove", "actions", "which", "are", "not", "important" ]
682a96672393d81c63728e47c4a4c3618c515be0
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/DeferredLayoutManipulator.php#L405-L419
21,703
oroinc/OroLayoutComponent
DeferredLayoutManipulator.php
DeferredLayoutManipulator.isActionReadyToExecute
protected function isActionReadyToExecute($key, $args) { switch ($key) { case self::ADD: $parentId = $args[1]; $siblingId = $args[4]; return !$parentId || ( $this->rawLayoutBuilder->has($parentId) && (!$siblingId || $this->rawLayoutBuilder->isParentFor($parentId, $siblingId)) ); case self::MOVE: list($id, $parentId, $siblingId) = $args; return (!$id || $this->rawLayoutBuilder->has($id)) && (!$parentId || $this->rawLayoutBuilder->has($parentId)) && ( !$siblingId || ($parentId && $this->rawLayoutBuilder->isParentFor($parentId, $siblingId)) || (!$parentId && $this->rawLayoutBuilder->has($siblingId)) ); case self::REMOVE: case self::SET_OPTION: case self::APPEND_OPTION: case self::SUBTRACT_OPTION: case self::REPLACE_OPTION: case self::REMOVE_OPTION: case self::CHANGE_BLOCK_TYPE: $id = $args[0]; return !$id || $this->rawLayoutBuilder->has($id); case self::SET_BLOCK_THEME: $id = $args[1]; return (!$id && !$this->rawLayoutBuilder->isEmpty()) || $this->rawLayoutBuilder->has($id); case self::ADD_ALIAS: $id = $args[1]; return !$id || $this->rawLayoutBuilder->has($id); case self::REMOVE_ALIAS: $alias = $args[0]; return !$alias || $this->rawLayoutBuilder->hasAlias($alias); } return true; }
php
protected function isActionReadyToExecute($key, $args) { switch ($key) { case self::ADD: $parentId = $args[1]; $siblingId = $args[4]; return !$parentId || ( $this->rawLayoutBuilder->has($parentId) && (!$siblingId || $this->rawLayoutBuilder->isParentFor($parentId, $siblingId)) ); case self::MOVE: list($id, $parentId, $siblingId) = $args; return (!$id || $this->rawLayoutBuilder->has($id)) && (!$parentId || $this->rawLayoutBuilder->has($parentId)) && ( !$siblingId || ($parentId && $this->rawLayoutBuilder->isParentFor($parentId, $siblingId)) || (!$parentId && $this->rawLayoutBuilder->has($siblingId)) ); case self::REMOVE: case self::SET_OPTION: case self::APPEND_OPTION: case self::SUBTRACT_OPTION: case self::REPLACE_OPTION: case self::REMOVE_OPTION: case self::CHANGE_BLOCK_TYPE: $id = $args[0]; return !$id || $this->rawLayoutBuilder->has($id); case self::SET_BLOCK_THEME: $id = $args[1]; return (!$id && !$this->rawLayoutBuilder->isEmpty()) || $this->rawLayoutBuilder->has($id); case self::ADD_ALIAS: $id = $args[1]; return !$id || $this->rawLayoutBuilder->has($id); case self::REMOVE_ALIAS: $alias = $args[0]; return !$alias || $this->rawLayoutBuilder->hasAlias($alias); } return true; }
[ "protected", "function", "isActionReadyToExecute", "(", "$", "key", ",", "$", "args", ")", "{", "switch", "(", "$", "key", ")", "{", "case", "self", "::", "ADD", ":", "$", "parentId", "=", "$", "args", "[", "1", "]", ";", "$", "siblingId", "=", "$", "args", "[", "4", "]", ";", "return", "!", "$", "parentId", "||", "(", "$", "this", "->", "rawLayoutBuilder", "->", "has", "(", "$", "parentId", ")", "&&", "(", "!", "$", "siblingId", "||", "$", "this", "->", "rawLayoutBuilder", "->", "isParentFor", "(", "$", "parentId", ",", "$", "siblingId", ")", ")", ")", ";", "case", "self", "::", "MOVE", ":", "list", "(", "$", "id", ",", "$", "parentId", ",", "$", "siblingId", ")", "=", "$", "args", ";", "return", "(", "!", "$", "id", "||", "$", "this", "->", "rawLayoutBuilder", "->", "has", "(", "$", "id", ")", ")", "&&", "(", "!", "$", "parentId", "||", "$", "this", "->", "rawLayoutBuilder", "->", "has", "(", "$", "parentId", ")", ")", "&&", "(", "!", "$", "siblingId", "||", "(", "$", "parentId", "&&", "$", "this", "->", "rawLayoutBuilder", "->", "isParentFor", "(", "$", "parentId", ",", "$", "siblingId", ")", ")", "||", "(", "!", "$", "parentId", "&&", "$", "this", "->", "rawLayoutBuilder", "->", "has", "(", "$", "siblingId", ")", ")", ")", ";", "case", "self", "::", "REMOVE", ":", "case", "self", "::", "SET_OPTION", ":", "case", "self", "::", "APPEND_OPTION", ":", "case", "self", "::", "SUBTRACT_OPTION", ":", "case", "self", "::", "REPLACE_OPTION", ":", "case", "self", "::", "REMOVE_OPTION", ":", "case", "self", "::", "CHANGE_BLOCK_TYPE", ":", "$", "id", "=", "$", "args", "[", "0", "]", ";", "return", "!", "$", "id", "||", "$", "this", "->", "rawLayoutBuilder", "->", "has", "(", "$", "id", ")", ";", "case", "self", "::", "SET_BLOCK_THEME", ":", "$", "id", "=", "$", "args", "[", "1", "]", ";", "return", "(", "!", "$", "id", "&&", "!", "$", "this", "->", "rawLayoutBuilder", "->", "isEmpty", "(", ")", ")", "||", "$", "this", "->", "rawLayoutBuilder", "->", "has", "(", "$", "id", ")", ";", "case", "self", "::", "ADD_ALIAS", ":", "$", "id", "=", "$", "args", "[", "1", "]", ";", "return", "!", "$", "id", "||", "$", "this", "->", "rawLayoutBuilder", "->", "has", "(", "$", "id", ")", ";", "case", "self", "::", "REMOVE_ALIAS", ":", "$", "alias", "=", "$", "args", "[", "0", "]", ";", "return", "!", "$", "alias", "||", "$", "this", "->", "rawLayoutBuilder", "->", "hasAlias", "(", "$", "alias", ")", ";", "}", "return", "true", ";", "}" ]
Checks whether an action is ready to execute @param string $key The action key @param array $args The action arguments @return bool @SuppressWarnings(PHPMD.CyclomaticComplexity)
[ "Checks", "whether", "an", "action", "is", "ready", "to", "execute" ]
682a96672393d81c63728e47c4a4c3618c515be0
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/DeferredLayoutManipulator.php#L510-L559
21,704
oroinc/OroLayoutComponent
DeferredLayoutManipulator.php
DeferredLayoutManipulator.executeActions
protected function executeActions($group) { $executedCount = 0; reset($this->actions[$group]); while (list($index, $action) = each($this->actions[$group])) { if ($this->isActionReadyToExecute($action[0], $action[2])) { $executedCount += $this->executeAction($index, $action); unset($this->actions[$group][$index]); } } return $executedCount; }
php
protected function executeActions($group) { $executedCount = 0; reset($this->actions[$group]); while (list($index, $action) = each($this->actions[$group])) { if ($this->isActionReadyToExecute($action[0], $action[2])) { $executedCount += $this->executeAction($index, $action); unset($this->actions[$group][$index]); } } return $executedCount; }
[ "protected", "function", "executeActions", "(", "$", "group", ")", "{", "$", "executedCount", "=", "0", ";", "reset", "(", "$", "this", "->", "actions", "[", "$", "group", "]", ")", ";", "while", "(", "list", "(", "$", "index", ",", "$", "action", ")", "=", "each", "(", "$", "this", "->", "actions", "[", "$", "group", "]", ")", ")", "{", "if", "(", "$", "this", "->", "isActionReadyToExecute", "(", "$", "action", "[", "0", "]", ",", "$", "action", "[", "2", "]", ")", ")", "{", "$", "executedCount", "+=", "$", "this", "->", "executeAction", "(", "$", "index", ",", "$", "action", ")", ";", "unset", "(", "$", "this", "->", "actions", "[", "$", "group", "]", "[", "$", "index", "]", ")", ";", "}", "}", "return", "$", "executedCount", ";", "}" ]
Executes actions from the given group Use this method if the group does not contain depended each other actions @param string $group @return int The number of executed actions
[ "Executes", "actions", "from", "the", "given", "group", "Use", "this", "method", "if", "the", "group", "does", "not", "contain", "depended", "each", "other", "actions" ]
682a96672393d81c63728e47c4a4c3618c515be0
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/DeferredLayoutManipulator.php#L569-L581
21,705
oroinc/OroLayoutComponent
DeferredLayoutManipulator.php
DeferredLayoutManipulator.executeDependedActions
protected function executeDependedActions($group) { $executedCount = 0; $continue = true; while ($continue) { $continue = false; $hasExecuted = false; $hasSkipped = false; reset($this->actions[$group]); while (list($index, $action) = each($this->actions[$group])) { if ($this->isActionReadyToExecute($action[0], $action[2])) { $executedCount += $this->executeAction($index, $action); unset($this->actions[$group][$index]); $hasExecuted = true; if ($hasSkipped) { // start execution from the begin $continue = true; break; } } else { $hasSkipped = true; if ($hasExecuted) { // start execution from the begin $continue = true; break; } } } } return $executedCount; }
php
protected function executeDependedActions($group) { $executedCount = 0; $continue = true; while ($continue) { $continue = false; $hasExecuted = false; $hasSkipped = false; reset($this->actions[$group]); while (list($index, $action) = each($this->actions[$group])) { if ($this->isActionReadyToExecute($action[0], $action[2])) { $executedCount += $this->executeAction($index, $action); unset($this->actions[$group][$index]); $hasExecuted = true; if ($hasSkipped) { // start execution from the begin $continue = true; break; } } else { $hasSkipped = true; if ($hasExecuted) { // start execution from the begin $continue = true; break; } } } } return $executedCount; }
[ "protected", "function", "executeDependedActions", "(", "$", "group", ")", "{", "$", "executedCount", "=", "0", ";", "$", "continue", "=", "true", ";", "while", "(", "$", "continue", ")", "{", "$", "continue", "=", "false", ";", "$", "hasExecuted", "=", "false", ";", "$", "hasSkipped", "=", "false", ";", "reset", "(", "$", "this", "->", "actions", "[", "$", "group", "]", ")", ";", "while", "(", "list", "(", "$", "index", ",", "$", "action", ")", "=", "each", "(", "$", "this", "->", "actions", "[", "$", "group", "]", ")", ")", "{", "if", "(", "$", "this", "->", "isActionReadyToExecute", "(", "$", "action", "[", "0", "]", ",", "$", "action", "[", "2", "]", ")", ")", "{", "$", "executedCount", "+=", "$", "this", "->", "executeAction", "(", "$", "index", ",", "$", "action", ")", ";", "unset", "(", "$", "this", "->", "actions", "[", "$", "group", "]", "[", "$", "index", "]", ")", ";", "$", "hasExecuted", "=", "true", ";", "if", "(", "$", "hasSkipped", ")", "{", "// start execution from the begin", "$", "continue", "=", "true", ";", "break", ";", "}", "}", "else", "{", "$", "hasSkipped", "=", "true", ";", "if", "(", "$", "hasExecuted", ")", "{", "// start execution from the begin", "$", "continue", "=", "true", ";", "break", ";", "}", "}", "}", "}", "return", "$", "executedCount", ";", "}" ]
Executes depended actions from the given group Use this method if the group can contain depended each other actions This method guarantee that all actions are executed in the order they are registered @param string $group @return int The number of executed actions
[ "Executes", "depended", "actions", "from", "the", "given", "group", "Use", "this", "method", "if", "the", "group", "can", "contain", "depended", "each", "other", "actions", "This", "method", "guarantee", "that", "all", "actions", "are", "executed", "in", "the", "order", "they", "are", "registered" ]
682a96672393d81c63728e47c4a4c3618c515be0
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/DeferredLayoutManipulator.php#L592-L623
21,706
spiral-modules/listing
source/Listing/Listing.php
Listing.setSelector
public function setSelector(PaginatorAwareInterface $selector) { $this->validateSelector($selector); $this->selector = $selector; return $this; }
php
public function setSelector(PaginatorAwareInterface $selector) { $this->validateSelector($selector); $this->selector = $selector; return $this; }
[ "public", "function", "setSelector", "(", "PaginatorAwareInterface", "$", "selector", ")", "{", "$", "this", "->", "validateSelector", "(", "$", "selector", ")", ";", "$", "this", "->", "selector", "=", "$", "selector", ";", "return", "$", "this", ";", "}" ]
Set active listing selector. @param RecordSelector|DocumentSelector|PaginatorAwareInterface $selector @return $this @throws InvalidSelectorException
[ "Set", "active", "listing", "selector", "." ]
89abe8939ce91cbf61b51b99e93ce1e57c8af83c
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/Listing.php#L93-L99
21,707
spiral-modules/listing
source/Listing/Listing.php
Listing.setLimits
public function setLimits(array $limits = []) { if (empty($limits)) { throw new ListingException("You must provide at least one limit option"); } $this->limits = array_values($limits); return $this; }
php
public function setLimits(array $limits = []) { if (empty($limits)) { throw new ListingException("You must provide at least one limit option"); } $this->limits = array_values($limits); return $this; }
[ "public", "function", "setLimits", "(", "array", "$", "limits", "=", "[", "]", ")", "{", "if", "(", "empty", "(", "$", "limits", ")", ")", "{", "throw", "new", "ListingException", "(", "\"You must provide at least one limit option\"", ")", ";", "}", "$", "this", "->", "limits", "=", "array_values", "(", "$", "limits", ")", ";", "return", "$", "this", ";", "}" ]
Set allowed pagination limits @param array $limits @return $this
[ "Set", "allowed", "pagination", "limits" ]
89abe8939ce91cbf61b51b99e93ce1e57c8af83c
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/Listing.php#L227-L236
21,708
spiral-modules/listing
source/Listing/Listing.php
Listing.createPaginator
protected function createPaginator() { $paginator = new Paginator($this->getLimit()); $paginator = $paginator->withPage($this->getPage()); return $paginator; }
php
protected function createPaginator() { $paginator = new Paginator($this->getLimit()); $paginator = $paginator->withPage($this->getPage()); return $paginator; }
[ "protected", "function", "createPaginator", "(", ")", "{", "$", "paginator", "=", "new", "Paginator", "(", "$", "this", "->", "getLimit", "(", ")", ")", ";", "$", "paginator", "=", "$", "paginator", "->", "withPage", "(", "$", "this", "->", "getPage", "(", ")", ")", ";", "return", "$", "paginator", ";", "}" ]
Get paginator associated with current listing @return Paginator
[ "Get", "paginator", "associated", "with", "current", "listing" ]
89abe8939ce91cbf61b51b99e93ce1e57c8af83c
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/Listing.php#L402-L408
21,709
spiral-modules/listing
source/Listing/Listing.php
Listing.getLimit
protected function getLimit() { $limit = $this->activeState()->getLimit(); if (!in_array($limit, $this->limits)) { //We are using lowest limit by default return $this->limits[0]; } return $limit; }
php
protected function getLimit() { $limit = $this->activeState()->getLimit(); if (!in_array($limit, $this->limits)) { //We are using lowest limit by default return $this->limits[0]; } return $limit; }
[ "protected", "function", "getLimit", "(", ")", "{", "$", "limit", "=", "$", "this", "->", "activeState", "(", ")", "->", "getLimit", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "limit", ",", "$", "this", "->", "limits", ")", ")", "{", "//We are using lowest limit by default", "return", "$", "this", "->", "limits", "[", "0", "]", ";", "}", "return", "$", "limit", ";", "}" ]
Get active pagination limit @return int
[ "Get", "active", "pagination", "limit" ]
89abe8939ce91cbf61b51b99e93ce1e57c8af83c
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/Listing.php#L415-L424
21,710
kouks/laravel-filters
src/Filters/Behavior/Searchable.php
Searchable.search
public function search($pattern = null) { if (! $pattern) { return; } foreach ($this->searchable as $column) { $this->resolveSearch($column, $pattern); } }
php
public function search($pattern = null) { if (! $pattern) { return; } foreach ($this->searchable as $column) { $this->resolveSearch($column, $pattern); } }
[ "public", "function", "search", "(", "$", "pattern", "=", "null", ")", "{", "if", "(", "!", "$", "pattern", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "searchable", "as", "$", "column", ")", "{", "$", "this", "->", "resolveSearch", "(", "$", "column", ",", "$", "pattern", ")", ";", "}", "}" ]
Searches given columns. @param string $pattern @return void
[ "Searches", "given", "columns", "." ]
c1a594fd40173dcbb454ea7ec59818a919fff6bd
https://github.com/kouks/laravel-filters/blob/c1a594fd40173dcbb454ea7ec59818a919fff6bd/src/Filters/Behavior/Searchable.php#L13-L22
21,711
kouks/laravel-filters
src/Filters/Behavior/Searchable.php
Searchable.resolveSearch
protected function resolveSearch($column, $key) { $this->resolve($column, $key, $this->getTableName(), function ($query, $pattern) { $this->builder->orWhere($query, 'LIKE', "%{$pattern}%"); }); }
php
protected function resolveSearch($column, $key) { $this->resolve($column, $key, $this->getTableName(), function ($query, $pattern) { $this->builder->orWhere($query, 'LIKE', "%{$pattern}%"); }); }
[ "protected", "function", "resolveSearch", "(", "$", "column", ",", "$", "key", ")", "{", "$", "this", "->", "resolve", "(", "$", "column", ",", "$", "key", ",", "$", "this", "->", "getTableName", "(", ")", ",", "function", "(", "$", "query", ",", "$", "pattern", ")", "{", "$", "this", "->", "builder", "->", "orWhere", "(", "$", "query", ",", "'LIKE'", ",", "\"%{$pattern}%\"", ")", ";", "}", ")", ";", "}" ]
Recursively build up the search query. @param string $column @param string $key @return void
[ "Recursively", "build", "up", "the", "search", "query", "." ]
c1a594fd40173dcbb454ea7ec59818a919fff6bd
https://github.com/kouks/laravel-filters/blob/c1a594fd40173dcbb454ea7ec59818a919fff6bd/src/Filters/Behavior/Searchable.php#L31-L36
21,712
willhoffmann/domuserp-php
src/Resources/People/Data/PersonData.php
PersonData.address
public function address(array $address) { if (! isset($this->data->addresses)) { $this->data->addresses = []; } return $this->data->addresses[] = (object) $address; }
php
public function address(array $address) { if (! isset($this->data->addresses)) { $this->data->addresses = []; } return $this->data->addresses[] = (object) $address; }
[ "public", "function", "address", "(", "array", "$", "address", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "data", "->", "addresses", ")", ")", "{", "$", "this", "->", "data", "->", "addresses", "=", "[", "]", ";", "}", "return", "$", "this", "->", "data", "->", "addresses", "[", "]", "=", "(", "object", ")", "$", "address", ";", "}" ]
Put a address on person data @param array $address @return object
[ "Put", "a", "address", "on", "person", "data" ]
44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6
https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/People/Data/PersonData.php#L15-L22
21,713
willhoffmann/domuserp-php
src/Resources/People/Data/PersonData.php
PersonData.contacts
public function contacts(array $contact) { if (! isset($this->data->contacts)) { $this->data->contacts = []; } return $this->data->contacts[] = (object) $contact; }
php
public function contacts(array $contact) { if (! isset($this->data->contacts)) { $this->data->contacts = []; } return $this->data->contacts[] = (object) $contact; }
[ "public", "function", "contacts", "(", "array", "$", "contact", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "data", "->", "contacts", ")", ")", "{", "$", "this", "->", "data", "->", "contacts", "=", "[", "]", ";", "}", "return", "$", "this", "->", "data", "->", "contacts", "[", "]", "=", "(", "object", ")", "$", "contact", ";", "}" ]
Put a contact on person data @param array $contact @return object
[ "Put", "a", "contact", "on", "person", "data" ]
44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6
https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/People/Data/PersonData.php#L30-L37
21,714
willhoffmann/domuserp-php
src/Resources/People/Data/PersonData.php
PersonData.references
public function references(array $reference = null) { if (! isset($this->data->references)) { $this->data->references = []; } return $this->data->contacts[] = (object) $reference; }
php
public function references(array $reference = null) { if (! isset($this->data->references)) { $this->data->references = []; } return $this->data->contacts[] = (object) $reference; }
[ "public", "function", "references", "(", "array", "$", "reference", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "data", "->", "references", ")", ")", "{", "$", "this", "->", "data", "->", "references", "=", "[", "]", ";", "}", "return", "$", "this", "->", "data", "->", "contacts", "[", "]", "=", "(", "object", ")", "$", "reference", ";", "}" ]
Put a commercial reference on person data @param array $reference @return object
[ "Put", "a", "commercial", "reference", "on", "person", "data" ]
44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6
https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/People/Data/PersonData.php#L45-L52
21,715
gedex/php-janrain-api
lib/Janrain/Api/Capture/Access.php
Access.getAuthorizationCode
public function getAuthorizationCode(array $params) { if (isset($params['transaction_state'])) { $params['transaction_state'] = json_encode($params['transaction_state']); } return $this->post('access/getAuthorizationCode', $params); }
php
public function getAuthorizationCode(array $params) { if (isset($params['transaction_state'])) { $params['transaction_state'] = json_encode($params['transaction_state']); } return $this->post('access/getAuthorizationCode', $params); }
[ "public", "function", "getAuthorizationCode", "(", "array", "$", "params", ")", "{", "if", "(", "isset", "(", "$", "params", "[", "'transaction_state'", "]", ")", ")", "{", "$", "params", "[", "'transaction_state'", "]", "=", "json_encode", "(", "$", "params", "[", "'transaction_state'", "]", ")", ";", "}", "return", "$", "this", "->", "post", "(", "'access/getAuthorizationCode'", ",", "$", "params", ")", ";", "}" ]
Get an authorization code that can be exchanged for an `access_token` and a `refresh_token`. @param array $params @link http://developers.janrain.com/documentation/api-methods/capture/access-codes-and-tokens/getauthorizationcode/
[ "Get", "an", "authorization", "code", "that", "can", "be", "exchanged", "for", "an", "access_token", "and", "a", "refresh_token", "." ]
6283f68454e0ad5211ac620f1d337df38cd49597
https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Access.php#L29-L36
21,716
zicht/z
src/Zicht/Tool/Command/TaskCommand.php
TaskCommand.addResolvableOption
public function addResolvableOption($name, $shortcut = null, $mode = null, $help = null, $default = null) { $this->opts[] = $name; return parent::addOption($name, $shortcut, $mode, $help, $default); }
php
public function addResolvableOption($name, $shortcut = null, $mode = null, $help = null, $default = null) { $this->opts[] = $name; return parent::addOption($name, $shortcut, $mode, $help, $default); }
[ "public", "function", "addResolvableOption", "(", "$", "name", ",", "$", "shortcut", "=", "null", ",", "$", "mode", "=", "null", ",", "$", "help", "=", "null", ",", "$", "default", "=", "null", ")", "{", "$", "this", "->", "opts", "[", "]", "=", "$", "name", ";", "return", "parent", "::", "addOption", "(", "$", "name", ",", "$", "shortcut", ",", "$", "mode", ",", "$", "help", ",", "$", "default", ")", ";", "}" ]
will add the given option the opt stack so it will resolved for the z plugin. @param string $name @param null $shortcut @param null $mode @param null $help @param null $default @return $this
[ "will", "add", "the", "given", "option", "the", "opt", "stack", "so", "it", "will", "resolved", "for", "the", "z", "plugin", "." ]
6a1731dad20b018555a96b726a61d4bf8ec8c886
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Command/TaskCommand.php#L126-L130
21,717
zicht/z
src/Zicht/Tool/Command/TaskCommand.php
TaskCommand.execute
protected function execute(InputInterface $input, Output\OutputInterface $output) { foreach ($this->getDefinition()->getArguments() as $arg) { if ($arg->getName() === 'command') { continue; } if ($input->getArgument($arg->getName())) { $this->getContainer()->set(explode('.', $this->nameToVar($arg->getName())), $input->getArgument($arg->getName())); } } foreach ($this->opts as $opt) { if ($value = $input->getOption($this->varToName($opt))) { $this->getContainer()->set(explode('.', $opt), $value); } } foreach ($this->flags as $name => $value) { $varName = explode('.', $name); $optName = $this->varToName($name); $this->getContainer()->set($varName, $value); if ($input->getOption('no-' . $optName) && $input->getOption($optName)) { throw new \InvalidArgumentException("Conflicting options --no-{$optName} and --{$optName} supplied. That confuses me."); } if ($input->getOption('no-' . $optName)) { $this->getContainer()->set($varName, false); } elseif ($input->getOption($optName)) { $this->getContainer()->set($varName, true); } } $callable = $this->getContainer()->get($this->getTaskReference()); call_user_func($callable, $this->getContainer()); }
php
protected function execute(InputInterface $input, Output\OutputInterface $output) { foreach ($this->getDefinition()->getArguments() as $arg) { if ($arg->getName() === 'command') { continue; } if ($input->getArgument($arg->getName())) { $this->getContainer()->set(explode('.', $this->nameToVar($arg->getName())), $input->getArgument($arg->getName())); } } foreach ($this->opts as $opt) { if ($value = $input->getOption($this->varToName($opt))) { $this->getContainer()->set(explode('.', $opt), $value); } } foreach ($this->flags as $name => $value) { $varName = explode('.', $name); $optName = $this->varToName($name); $this->getContainer()->set($varName, $value); if ($input->getOption('no-' . $optName) && $input->getOption($optName)) { throw new \InvalidArgumentException("Conflicting options --no-{$optName} and --{$optName} supplied. That confuses me."); } if ($input->getOption('no-' . $optName)) { $this->getContainer()->set($varName, false); } elseif ($input->getOption($optName)) { $this->getContainer()->set($varName, true); } } $callable = $this->getContainer()->get($this->getTaskReference()); call_user_func($callable, $this->getContainer()); }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "Output", "\\", "OutputInterface", "$", "output", ")", "{", "foreach", "(", "$", "this", "->", "getDefinition", "(", ")", "->", "getArguments", "(", ")", "as", "$", "arg", ")", "{", "if", "(", "$", "arg", "->", "getName", "(", ")", "===", "'command'", ")", "{", "continue", ";", "}", "if", "(", "$", "input", "->", "getArgument", "(", "$", "arg", "->", "getName", "(", ")", ")", ")", "{", "$", "this", "->", "getContainer", "(", ")", "->", "set", "(", "explode", "(", "'.'", ",", "$", "this", "->", "nameToVar", "(", "$", "arg", "->", "getName", "(", ")", ")", ")", ",", "$", "input", "->", "getArgument", "(", "$", "arg", "->", "getName", "(", ")", ")", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "opts", "as", "$", "opt", ")", "{", "if", "(", "$", "value", "=", "$", "input", "->", "getOption", "(", "$", "this", "->", "varToName", "(", "$", "opt", ")", ")", ")", "{", "$", "this", "->", "getContainer", "(", ")", "->", "set", "(", "explode", "(", "'.'", ",", "$", "opt", ")", ",", "$", "value", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "flags", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "varName", "=", "explode", "(", "'.'", ",", "$", "name", ")", ";", "$", "optName", "=", "$", "this", "->", "varToName", "(", "$", "name", ")", ";", "$", "this", "->", "getContainer", "(", ")", "->", "set", "(", "$", "varName", ",", "$", "value", ")", ";", "if", "(", "$", "input", "->", "getOption", "(", "'no-'", ".", "$", "optName", ")", "&&", "$", "input", "->", "getOption", "(", "$", "optName", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Conflicting options --no-{$optName} and --{$optName} supplied. That confuses me.\"", ")", ";", "}", "if", "(", "$", "input", "->", "getOption", "(", "'no-'", ".", "$", "optName", ")", ")", "{", "$", "this", "->", "getContainer", "(", ")", "->", "set", "(", "$", "varName", ",", "false", ")", ";", "}", "elseif", "(", "$", "input", "->", "getOption", "(", "$", "optName", ")", ")", "{", "$", "this", "->", "getContainer", "(", ")", "->", "set", "(", "$", "varName", ",", "true", ")", ";", "}", "}", "$", "callable", "=", "$", "this", "->", "getContainer", "(", ")", "->", "get", "(", "$", "this", "->", "getTaskReference", "(", ")", ")", ";", "call_user_func", "(", "$", "callable", ",", "$", "this", "->", "getContainer", "(", ")", ")", ";", "}" ]
Executes the specified task @param \Symfony\Component\Console\Input\InputInterface $input @param \Symfony\Component\Console\Output\OutputInterface $output @return mixed
[ "Executes", "the", "specified", "task" ]
6a1731dad20b018555a96b726a61d4bf8ec8c886
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Command/TaskCommand.php#L214-L248
21,718
raideer/twitch-api
src/Resources/Chat.php
Chat.getEmoticonImages
public function getEmoticonImages($params = []) { $defaults = [ 'emotesets' => null, ]; return $this->wrapper->request('GET', 'chat/emoticon_images', ['query' => $this->resolveOptions($params, $defaults)]); }
php
public function getEmoticonImages($params = []) { $defaults = [ 'emotesets' => null, ]; return $this->wrapper->request('GET', 'chat/emoticon_images', ['query' => $this->resolveOptions($params, $defaults)]); }
[ "public", "function", "getEmoticonImages", "(", "$", "params", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'emotesets'", "=>", "null", ",", "]", ";", "return", "$", "this", "->", "wrapper", "->", "request", "(", "'GET'", ",", "'chat/emoticon_images'", ",", "[", "'query'", "=>", "$", "this", "->", "resolveOptions", "(", "$", "params", ",", "$", "defaults", ")", "]", ")", ";", "}" ]
Returns a list of emoticons. Learn more: https://github.com/justintv/Twitch-API/blob/master/v3_resources/chat.md#get-chatemoticon_images @param array $params Optional parameters @return array
[ "Returns", "a", "list", "of", "emoticons", "." ]
27ebf1dcb0315206300d507600b6a82ebe33d57e
https://github.com/raideer/twitch-api/blob/27ebf1dcb0315206300d507600b6a82ebe33d57e/src/Resources/Chat.php#L58-L65
21,719
Erdiko/core
src/datasource/File.php
File.createDir
private function createDir($path) { if (!is_dir($path)) { $success = mkdir($path, 0775, true); if (!$success) { throw new \Exception("Cannot create folder {$path}. Check file system permissions."); } } }
php
private function createDir($path) { if (!is_dir($path)) { $success = mkdir($path, 0775, true); if (!$success) { throw new \Exception("Cannot create folder {$path}. Check file system permissions."); } } }
[ "private", "function", "createDir", "(", "$", "path", ")", "{", "if", "(", "!", "is_dir", "(", "$", "path", ")", ")", "{", "$", "success", "=", "mkdir", "(", "$", "path", ",", "0775", ",", "true", ")", ";", "if", "(", "!", "$", "success", ")", "{", "throw", "new", "\\", "Exception", "(", "\"Cannot create folder {$path}. Check file system permissions.\"", ")", ";", "}", "}", "}" ]
Create Directory If path doesn't exist, create it
[ "Create", "Directory", "If", "path", "doesn", "t", "exist", "create", "it" ]
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/datasource/File.php#L43-L51
21,720
Erdiko/core
src/datasource/File.php
File.read
public function read($filename, $pathToFile = null) { if(!$this->fileExists($filename, $pathToFile)) throw new \Exception("File, '{$filename}', does not exist."); if ($pathToFile==null) { return file_get_contents($this->_filePath."/".$filename); } else { return file_get_contents($pathToFile."/".$filename); } }
php
public function read($filename, $pathToFile = null) { if(!$this->fileExists($filename, $pathToFile)) throw new \Exception("File, '{$filename}', does not exist."); if ($pathToFile==null) { return file_get_contents($this->_filePath."/".$filename); } else { return file_get_contents($pathToFile."/".$filename); } }
[ "public", "function", "read", "(", "$", "filename", ",", "$", "pathToFile", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "fileExists", "(", "$", "filename", ",", "$", "pathToFile", ")", ")", "throw", "new", "\\", "Exception", "(", "\"File, '{$filename}', does not exist.\"", ")", ";", "if", "(", "$", "pathToFile", "==", "null", ")", "{", "return", "file_get_contents", "(", "$", "this", "->", "_filePath", ".", "\"/\"", ".", "$", "filename", ")", ";", "}", "else", "{", "return", "file_get_contents", "(", "$", "pathToFile", ".", "\"/\"", ".", "$", "filename", ")", ";", "}", "}" ]
Read string to file @param string $filename @param string $pathToFile @return string
[ "Read", "string", "to", "file" ]
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/datasource/File.php#L84-L94
21,721
Erdiko/core
src/datasource/File.php
File.move
public function move($filename, $pathTo, $pathFrom = null) { if ($pathFrom==null) { $pathFrom=$this->_filePath; } if (file_exists($pathFrom."/".$filename)) { $this->createDir($pathTo); return rename($pathFrom."/".$filename, $pathTo."/".$filename); } else { return null; } }
php
public function move($filename, $pathTo, $pathFrom = null) { if ($pathFrom==null) { $pathFrom=$this->_filePath; } if (file_exists($pathFrom."/".$filename)) { $this->createDir($pathTo); return rename($pathFrom."/".$filename, $pathTo."/".$filename); } else { return null; } }
[ "public", "function", "move", "(", "$", "filename", ",", "$", "pathTo", ",", "$", "pathFrom", "=", "null", ")", "{", "if", "(", "$", "pathFrom", "==", "null", ")", "{", "$", "pathFrom", "=", "$", "this", "->", "_filePath", ";", "}", "if", "(", "file_exists", "(", "$", "pathFrom", ".", "\"/\"", ".", "$", "filename", ")", ")", "{", "$", "this", "->", "createDir", "(", "$", "pathTo", ")", ";", "return", "rename", "(", "$", "pathFrom", ".", "\"/\"", ".", "$", "filename", ",", "$", "pathTo", ".", "\"/\"", ".", "$", "filename", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Move a file @param string $filename @param string $pathTo @param string $pathToFrom @return bool
[ "Move", "a", "file" ]
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/datasource/File.php#L123-L134
21,722
caffeinated/beverage
src/Traits/MultiSingleton.php
MultiSingleton.getInstance
public static function getInstance($name = 'default') { if (isset(static::$instances[$name])) { return static::$instances[$name]; } $instance = new static(); static::$instances[$name] = $instance; return $instance; }
php
public static function getInstance($name = 'default') { if (isset(static::$instances[$name])) { return static::$instances[$name]; } $instance = new static(); static::$instances[$name] = $instance; return $instance; }
[ "public", "static", "function", "getInstance", "(", "$", "name", "=", "'default'", ")", "{", "if", "(", "isset", "(", "static", "::", "$", "instances", "[", "$", "name", "]", ")", ")", "{", "return", "static", "::", "$", "instances", "[", "$", "name", "]", ";", "}", "$", "instance", "=", "new", "static", "(", ")", ";", "static", "::", "$", "instances", "[", "$", "name", "]", "=", "$", "instance", ";", "return", "$", "instance", ";", "}" ]
Get the current instance. @param string $name @return static
[ "Get", "the", "current", "instance", "." ]
c7d612a1d3bc1baddc97fec60ab17224550efaf3
https://github.com/caffeinated/beverage/blob/c7d612a1d3bc1baddc97fec60ab17224550efaf3/src/Traits/MultiSingleton.php#L49-L60
21,723
PeeHaa/AsyncTwitter
src/Api/Request/Search/Search.php
Search.geocode
public function geocode(string $latitude, string $longitude, string $radius): Search { $this->parameters['geocode'] = sprintf('%s %s %s', $latitude, $longitude, $radius); return $this; }
php
public function geocode(string $latitude, string $longitude, string $radius): Search { $this->parameters['geocode'] = sprintf('%s %s %s', $latitude, $longitude, $radius); return $this; }
[ "public", "function", "geocode", "(", "string", "$", "latitude", ",", "string", "$", "longitude", ",", "string", "$", "radius", ")", ":", "Search", "{", "$", "this", "->", "parameters", "[", "'geocode'", "]", "=", "sprintf", "(", "'%s %s %s'", ",", "$", "latitude", ",", "$", "longitude", ",", "$", "radius", ")", ";", "return", "$", "this", ";", "}" ]
use string instead of float
[ "use", "string", "instead", "of", "float" ]
a968909e7ed470bd87a0f25ef0c494338273c29c
https://github.com/PeeHaa/AsyncTwitter/blob/a968909e7ed470bd87a0f25ef0c494338273c29c/src/Api/Request/Search/Search.php#L25-L30
21,724
inhere/php-librarys
src/Helpers/DataHelper.php
DataHelper.toObject
public static function toObject($array, $class = \stdClass::class) { $object = new $class; foreach ($array as $name => $value) { $name = trim($name); if (!$name || is_numeric($name)) { continue; } $object->$name = \is_array($value) ? self::toObject($value) : $value; } return $object; }
php
public static function toObject($array, $class = \stdClass::class) { $object = new $class; foreach ($array as $name => $value) { $name = trim($name); if (!$name || is_numeric($name)) { continue; } $object->$name = \is_array($value) ? self::toObject($value) : $value; } return $object; }
[ "public", "static", "function", "toObject", "(", "$", "array", ",", "$", "class", "=", "\\", "stdClass", "::", "class", ")", "{", "$", "object", "=", "new", "$", "class", ";", "foreach", "(", "$", "array", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "name", "=", "trim", "(", "$", "name", ")", ";", "if", "(", "!", "$", "name", "||", "is_numeric", "(", "$", "name", ")", ")", "{", "continue", ";", "}", "$", "object", "->", "$", "name", "=", "\\", "is_array", "(", "$", "value", ")", "?", "self", "::", "toObject", "(", "$", "value", ")", ":", "$", "value", ";", "}", "return", "$", "object", ";", "}" ]
data to array @param array|\Traversable $array @param string $class @return mixed
[ "data", "to", "array" ]
e6ca598685469794f310e3ab0e2bc19519cd0ae6
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/DataHelper.php#L75-L90
21,725
inhere/php-librarys
src/Helpers/DataHelper.php
DataHelper.safeOutput
public static function safeOutput($string, $clearTag = false) { if (!$clearTag) { $string = strip_tags($string); } return @self::htmlentitiesUTF8($string); }
php
public static function safeOutput($string, $clearTag = false) { if (!$clearTag) { $string = strip_tags($string); } return @self::htmlentitiesUTF8($string); }
[ "public", "static", "function", "safeOutput", "(", "$", "string", ",", "$", "clearTag", "=", "false", ")", "{", "if", "(", "!", "$", "clearTag", ")", "{", "$", "string", "=", "strip_tags", "(", "$", "string", ")", ";", "}", "return", "@", "self", "::", "htmlentitiesUTF8", "(", "$", "string", ")", ";", "}" ]
Sanitize a string @param string $string String to sanitize @param bool $clearTag clear html tag @return string Sanitized string
[ "Sanitize", "a", "string" ]
e6ca598685469794f310e3ab0e2bc19519cd0ae6
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/DataHelper.php#L98-L105
21,726
gyselroth/micro-container
src/Config.php
Config.get
public function get(string $name): array { if (isset($this->compiled[$name])) { $config = $this->compiled[$name]; } else { $this->compiled[$name] = $this->createServiceConfig($name); $config = $this->compiled[$name]; } if (!isset($config['use'])) { $config['use'] = $name; } return $config; }
php
public function get(string $name): array { if (isset($this->compiled[$name])) { $config = $this->compiled[$name]; } else { $this->compiled[$name] = $this->createServiceConfig($name); $config = $this->compiled[$name]; } if (!isset($config['use'])) { $config['use'] = $name; } return $config; }
[ "public", "function", "get", "(", "string", "$", "name", ")", ":", "array", "{", "if", "(", "isset", "(", "$", "this", "->", "compiled", "[", "$", "name", "]", ")", ")", "{", "$", "config", "=", "$", "this", "->", "compiled", "[", "$", "name", "]", ";", "}", "else", "{", "$", "this", "->", "compiled", "[", "$", "name", "]", "=", "$", "this", "->", "createServiceConfig", "(", "$", "name", ")", ";", "$", "config", "=", "$", "this", "->", "compiled", "[", "$", "name", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "config", "[", "'use'", "]", ")", ")", "{", "$", "config", "[", "'use'", "]", "=", "$", "name", ";", "}", "return", "$", "config", ";", "}" ]
Get service configuration.
[ "Get", "service", "configuration", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/Config.php#L65-L79
21,727
gyselroth/micro-container
src/Config.php
Config.getEnv
public function getEnv(string $param): string { if (preg_match_all('#\{ENV\(([A-Za-z0-9_]+)(?:(,?)([^}]*))\)\}#', $param, $matches)) { if (4 !== count($matches)) { return $param; } for ($i = 0; $i < count($matches[0]); ++$i) { $param = $this->parseEnv($param, $matches, $i); } return $param; } return $param; }
php
public function getEnv(string $param): string { if (preg_match_all('#\{ENV\(([A-Za-z0-9_]+)(?:(,?)([^}]*))\)\}#', $param, $matches)) { if (4 !== count($matches)) { return $param; } for ($i = 0; $i < count($matches[0]); ++$i) { $param = $this->parseEnv($param, $matches, $i); } return $param; } return $param; }
[ "public", "function", "getEnv", "(", "string", "$", "param", ")", ":", "string", "{", "if", "(", "preg_match_all", "(", "'#\\{ENV\\(([A-Za-z0-9_]+)(?:(,?)([^}]*))\\)\\}#'", ",", "$", "param", ",", "$", "matches", ")", ")", "{", "if", "(", "4", "!==", "count", "(", "$", "matches", ")", ")", "{", "return", "$", "param", ";", "}", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "matches", "[", "0", "]", ")", ";", "++", "$", "i", ")", "{", "$", "param", "=", "$", "this", "->", "parseEnv", "(", "$", "param", ",", "$", "matches", ",", "$", "i", ")", ";", "}", "return", "$", "param", ";", "}", "return", "$", "param", ";", "}" ]
Parse env param.
[ "Parse", "env", "param", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/Config.php#L84-L99
21,728
gyselroth/micro-container
src/Config.php
Config.parseEnv
protected function parseEnv(string $param, array $variables, int $key): string { $env = getenv($variables[1][$key]); if (false === $env && !empty($variables[3][$key])) { return str_replace($variables[0][$key], $variables[3][$key], $param); } if (false === $env) { throw new Exception\EnvVariableNotFound('env variable '.$variables[1][$key].' required but it is neither set not a default value exists'); } return str_replace($variables[0][$key], $env, $param); }
php
protected function parseEnv(string $param, array $variables, int $key): string { $env = getenv($variables[1][$key]); if (false === $env && !empty($variables[3][$key])) { return str_replace($variables[0][$key], $variables[3][$key], $param); } if (false === $env) { throw new Exception\EnvVariableNotFound('env variable '.$variables[1][$key].' required but it is neither set not a default value exists'); } return str_replace($variables[0][$key], $env, $param); }
[ "protected", "function", "parseEnv", "(", "string", "$", "param", ",", "array", "$", "variables", ",", "int", "$", "key", ")", ":", "string", "{", "$", "env", "=", "getenv", "(", "$", "variables", "[", "1", "]", "[", "$", "key", "]", ")", ";", "if", "(", "false", "===", "$", "env", "&&", "!", "empty", "(", "$", "variables", "[", "3", "]", "[", "$", "key", "]", ")", ")", "{", "return", "str_replace", "(", "$", "variables", "[", "0", "]", "[", "$", "key", "]", ",", "$", "variables", "[", "3", "]", "[", "$", "key", "]", ",", "$", "param", ")", ";", "}", "if", "(", "false", "===", "$", "env", ")", "{", "throw", "new", "Exception", "\\", "EnvVariableNotFound", "(", "'env variable '", ".", "$", "variables", "[", "1", "]", "[", "$", "key", "]", ".", "' required but it is neither set not a default value exists'", ")", ";", "}", "return", "str_replace", "(", "$", "variables", "[", "0", "]", "[", "$", "key", "]", ",", "$", "env", ",", "$", "param", ")", ";", "}" ]
Parse env.
[ "Parse", "env", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/Config.php#L104-L115
21,729
gyselroth/micro-container
src/Config.php
Config.createServiceConfig
protected function createServiceConfig(string $name): array { $config = []; if ($this->has($name)) { $config = $this->config[$name]; } $class = $name; if (isset($config['use'])) { if (!is_string($config['use'])) { throw new Exception\InvalidConfiguration('use must be a string for service '.$name); } $class = $config['use'] = $this->getEnv($config['use']); } if (preg_match('#^\{([^{}]+)\}$#', $class)) { $config = array_merge($this->getServiceDefaults(), $config); return $config; } $config = $this->mergeServiceConfig($name, $class, $config); if (isset($config['use'])) { $class = $config['use'] = $this->getEnv($config['use']); } if (!class_exists($class)) { throw new Exception\InvalidConfiguration('class '.$class.' is either not a class or can not be found'); } return $config; }
php
protected function createServiceConfig(string $name): array { $config = []; if ($this->has($name)) { $config = $this->config[$name]; } $class = $name; if (isset($config['use'])) { if (!is_string($config['use'])) { throw new Exception\InvalidConfiguration('use must be a string for service '.$name); } $class = $config['use'] = $this->getEnv($config['use']); } if (preg_match('#^\{([^{}]+)\}$#', $class)) { $config = array_merge($this->getServiceDefaults(), $config); return $config; } $config = $this->mergeServiceConfig($name, $class, $config); if (isset($config['use'])) { $class = $config['use'] = $this->getEnv($config['use']); } if (!class_exists($class)) { throw new Exception\InvalidConfiguration('class '.$class.' is either not a class or can not be found'); } return $config; }
[ "protected", "function", "createServiceConfig", "(", "string", "$", "name", ")", ":", "array", "{", "$", "config", "=", "[", "]", ";", "if", "(", "$", "this", "->", "has", "(", "$", "name", ")", ")", "{", "$", "config", "=", "$", "this", "->", "config", "[", "$", "name", "]", ";", "}", "$", "class", "=", "$", "name", ";", "if", "(", "isset", "(", "$", "config", "[", "'use'", "]", ")", ")", "{", "if", "(", "!", "is_string", "(", "$", "config", "[", "'use'", "]", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidConfiguration", "(", "'use must be a string for service '", ".", "$", "name", ")", ";", "}", "$", "class", "=", "$", "config", "[", "'use'", "]", "=", "$", "this", "->", "getEnv", "(", "$", "config", "[", "'use'", "]", ")", ";", "}", "if", "(", "preg_match", "(", "'#^\\{([^{}]+)\\}$#'", ",", "$", "class", ")", ")", "{", "$", "config", "=", "array_merge", "(", "$", "this", "->", "getServiceDefaults", "(", ")", ",", "$", "config", ")", ";", "return", "$", "config", ";", "}", "$", "config", "=", "$", "this", "->", "mergeServiceConfig", "(", "$", "name", ",", "$", "class", ",", "$", "config", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'use'", "]", ")", ")", "{", "$", "class", "=", "$", "config", "[", "'use'", "]", "=", "$", "this", "->", "getEnv", "(", "$", "config", "[", "'use'", "]", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "Exception", "\\", "InvalidConfiguration", "(", "'class '", ".", "$", "class", ".", "' is either not a class or can not be found'", ")", ";", "}", "return", "$", "config", ";", "}" ]
Create service config.
[ "Create", "service", "config", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/Config.php#L120-L154
21,730
gyselroth/micro-container
src/Config.php
Config.mergeServiceConfig
protected function mergeServiceConfig(string $name, string $class, array $config): array { $config = array_merge($this->getServiceDefaults(), $config); if (!class_exists($class) && !interface_exists($class)) { return $config; } if (false === $config['merge']) { return $config; } $tree = $this->getConfigTree(); $parents = array_merge(class_implements($class), class_parents($class)); foreach ($tree as $parent_config) { foreach ($parents as $parent) { if (isset($parent_config[$parent])) { $config = array_replace_recursive($config, $parent_config[$parent]); } } if (isset($parent_config[$name])) { $config = array_replace_recursive($config, $parent_config[$name]); } } return $config; }
php
protected function mergeServiceConfig(string $name, string $class, array $config): array { $config = array_merge($this->getServiceDefaults(), $config); if (!class_exists($class) && !interface_exists($class)) { return $config; } if (false === $config['merge']) { return $config; } $tree = $this->getConfigTree(); $parents = array_merge(class_implements($class), class_parents($class)); foreach ($tree as $parent_config) { foreach ($parents as $parent) { if (isset($parent_config[$parent])) { $config = array_replace_recursive($config, $parent_config[$parent]); } } if (isset($parent_config[$name])) { $config = array_replace_recursive($config, $parent_config[$name]); } } return $config; }
[ "protected", "function", "mergeServiceConfig", "(", "string", "$", "name", ",", "string", "$", "class", ",", "array", "$", "config", ")", ":", "array", "{", "$", "config", "=", "array_merge", "(", "$", "this", "->", "getServiceDefaults", "(", ")", ",", "$", "config", ")", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", "&&", "!", "interface_exists", "(", "$", "class", ")", ")", "{", "return", "$", "config", ";", "}", "if", "(", "false", "===", "$", "config", "[", "'merge'", "]", ")", "{", "return", "$", "config", ";", "}", "$", "tree", "=", "$", "this", "->", "getConfigTree", "(", ")", ";", "$", "parents", "=", "array_merge", "(", "class_implements", "(", "$", "class", ")", ",", "class_parents", "(", "$", "class", ")", ")", ";", "foreach", "(", "$", "tree", "as", "$", "parent_config", ")", "{", "foreach", "(", "$", "parents", "as", "$", "parent", ")", "{", "if", "(", "isset", "(", "$", "parent_config", "[", "$", "parent", "]", ")", ")", "{", "$", "config", "=", "array_replace_recursive", "(", "$", "config", ",", "$", "parent_config", "[", "$", "parent", "]", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "parent_config", "[", "$", "name", "]", ")", ")", "{", "$", "config", "=", "array_replace_recursive", "(", "$", "config", ",", "$", "parent_config", "[", "$", "name", "]", ")", ";", "}", "}", "return", "$", "config", ";", "}" ]
Find parent classes or interfaces and merge service configurations.
[ "Find", "parent", "classes", "or", "interfaces", "and", "merge", "service", "configurations", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/Config.php#L174-L201
21,731
gyselroth/micro-container
src/Config.php
Config.getConfigTree
protected function getConfigTree(): array { $tree = [$this->getConfig()]; $parent = $this->container; while ($parent = $parent->getParent()) { $tree[] = $parent->getConfig()->getConfig(); } return $tree; }
php
protected function getConfigTree(): array { $tree = [$this->getConfig()]; $parent = $this->container; while ($parent = $parent->getParent()) { $tree[] = $parent->getConfig()->getConfig(); } return $tree; }
[ "protected", "function", "getConfigTree", "(", ")", ":", "array", "{", "$", "tree", "=", "[", "$", "this", "->", "getConfig", "(", ")", "]", ";", "$", "parent", "=", "$", "this", "->", "container", ";", "while", "(", "$", "parent", "=", "$", "parent", "->", "getParent", "(", ")", ")", "{", "$", "tree", "[", "]", "=", "$", "parent", "->", "getConfig", "(", ")", "->", "getConfig", "(", ")", ";", "}", "return", "$", "tree", ";", "}" ]
Get config tree.
[ "Get", "config", "tree", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/Config.php#L206-L215
21,732
m4grio/bangkok-insurance-php
src/Client/ParamsMapperTrait.php
ParamsMapperTrait.mergeParams
public function mergeParams($method, Array $params = []) { $result = parent::mergeParams($method, $params); foreach ($this->map as $oldKey => $newKey) { if (array_key_exists($oldKey, $result[$method])) { $result[$method][$newKey] = $result[$method][$oldKey]; $result[$method][$oldKey] = null; unset($result[$method][$oldKey]); } } return $result; }
php
public function mergeParams($method, Array $params = []) { $result = parent::mergeParams($method, $params); foreach ($this->map as $oldKey => $newKey) { if (array_key_exists($oldKey, $result[$method])) { $result[$method][$newKey] = $result[$method][$oldKey]; $result[$method][$oldKey] = null; unset($result[$method][$oldKey]); } } return $result; }
[ "public", "function", "mergeParams", "(", "$", "method", ",", "Array", "$", "params", "=", "[", "]", ")", "{", "$", "result", "=", "parent", "::", "mergeParams", "(", "$", "method", ",", "$", "params", ")", ";", "foreach", "(", "$", "this", "->", "map", "as", "$", "oldKey", "=>", "$", "newKey", ")", "{", "if", "(", "array_key_exists", "(", "$", "oldKey", ",", "$", "result", "[", "$", "method", "]", ")", ")", "{", "$", "result", "[", "$", "method", "]", "[", "$", "newKey", "]", "=", "$", "result", "[", "$", "method", "]", "[", "$", "oldKey", "]", ";", "$", "result", "[", "$", "method", "]", "[", "$", "oldKey", "]", "=", "null", ";", "unset", "(", "$", "result", "[", "$", "method", "]", "[", "$", "oldKey", "]", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Merge and remap params @param $method @param array $params @return mixed
[ "Merge", "and", "remap", "params" ]
400266d043abe6b7cacb9da36064cbb169149c2a
https://github.com/m4grio/bangkok-insurance-php/blob/400266d043abe6b7cacb9da36064cbb169149c2a/src/Client/ParamsMapperTrait.php#L27-L41
21,733
MASNathan/Parser
src/Type/Ini.php
Ini.encode
public static function encode($data) { $data = (array) $data; $resultString = self::loopEncode($data); return trim($resultString, PHP_EOL); }
php
public static function encode($data) { $data = (array) $data; $resultString = self::loopEncode($data); return trim($resultString, PHP_EOL); }
[ "public", "static", "function", "encode", "(", "$", "data", ")", "{", "$", "data", "=", "(", "array", ")", "$", "data", ";", "$", "resultString", "=", "self", "::", "loopEncode", "(", "$", "data", ")", ";", "return", "trim", "(", "$", "resultString", ",", "PHP_EOL", ")", ";", "}" ]
Encodes an array to ini strutcture @param array $data Data to encode @return string
[ "Encodes", "an", "array", "to", "ini", "strutcture" ]
0f55402b99b1e071bdcd6277b9268f783ca25e34
https://github.com/MASNathan/Parser/blob/0f55402b99b1e071bdcd6277b9268f783ca25e34/src/Type/Ini.php#L12-L19
21,734
MASNathan/Parser
src/Type/Ini.php
Ini.loopEncode
public static function loopEncode($data, array $parent = array()) { $resultString = ''; foreach ($data as $key => $value) { if (is_array($value)) { //subsection case //merge all the sections into one array... $sec = array_merge((array) $parent, (array) $key); //add section information to the output $resultString .= PHP_EOL . '[' . join('.', $sec) . ']' . PHP_EOL; //recursively traverse deeper $resultString .= self::loopEncode($value, $sec); } else { $resultString .= "$key = $value" . PHP_EOL; } } return $resultString; }
php
public static function loopEncode($data, array $parent = array()) { $resultString = ''; foreach ($data as $key => $value) { if (is_array($value)) { //subsection case //merge all the sections into one array... $sec = array_merge((array) $parent, (array) $key); //add section information to the output $resultString .= PHP_EOL . '[' . join('.', $sec) . ']' . PHP_EOL; //recursively traverse deeper $resultString .= self::loopEncode($value, $sec); } else { $resultString .= "$key = $value" . PHP_EOL; } } return $resultString; }
[ "public", "static", "function", "loopEncode", "(", "$", "data", ",", "array", "$", "parent", "=", "array", "(", ")", ")", "{", "$", "resultString", "=", "''", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "//subsection case", "//merge all the sections into one array...", "$", "sec", "=", "array_merge", "(", "(", "array", ")", "$", "parent", ",", "(", "array", ")", "$", "key", ")", ";", "//add section information to the output", "$", "resultString", ".=", "PHP_EOL", ".", "'['", ".", "join", "(", "'.'", ",", "$", "sec", ")", ".", "']'", ".", "PHP_EOL", ";", "//recursively traverse deeper", "$", "resultString", ".=", "self", "::", "loopEncode", "(", "$", "value", ",", "$", "sec", ")", ";", "}", "else", "{", "$", "resultString", ".=", "\"$key = $value\"", ".", "PHP_EOL", ";", "}", "}", "return", "$", "resultString", ";", "}" ]
Method to look the data and encode it to ini format @param array $data Data to encode @param array $parent Parent array, in case of recursive arrays @return string
[ "Method", "to", "look", "the", "data", "and", "encode", "it", "to", "ini", "format" ]
0f55402b99b1e071bdcd6277b9268f783ca25e34
https://github.com/MASNathan/Parser/blob/0f55402b99b1e071bdcd6277b9268f783ca25e34/src/Type/Ini.php#L27-L45
21,735
NuclearCMS/Hierarchy
src/Tags/Tag.php
Tag.firstByTitleOrCreate
public static function firstByTitleOrCreate($title, $locale = null) { $tag = Tag::whereTranslation('title', $title, $locale)->first(); if (is_null($tag)) { $attributes = compact('title'); if ($locale) { $attributes = [$locale => $attributes]; } $tag = Tag::create($attributes); } return $tag; }
php
public static function firstByTitleOrCreate($title, $locale = null) { $tag = Tag::whereTranslation('title', $title, $locale)->first(); if (is_null($tag)) { $attributes = compact('title'); if ($locale) { $attributes = [$locale => $attributes]; } $tag = Tag::create($attributes); } return $tag; }
[ "public", "static", "function", "firstByTitleOrCreate", "(", "$", "title", ",", "$", "locale", "=", "null", ")", "{", "$", "tag", "=", "Tag", "::", "whereTranslation", "(", "'title'", ",", "$", "title", ",", "$", "locale", ")", "->", "first", "(", ")", ";", "if", "(", "is_null", "(", "$", "tag", ")", ")", "{", "$", "attributes", "=", "compact", "(", "'title'", ")", ";", "if", "(", "$", "locale", ")", "{", "$", "attributes", "=", "[", "$", "locale", "=>", "$", "attributes", "]", ";", "}", "$", "tag", "=", "Tag", "::", "create", "(", "$", "attributes", ")", ";", "}", "return", "$", "tag", ";", "}" ]
Finds a tag by title or creates it @param string $title @param string $locale @return Tag
[ "Finds", "a", "tag", "by", "title", "or", "creates", "it" ]
535171c5e2db72265313fd2110aec8456e46f459
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Tags/Tag.php#L138-L155
21,736
codezero-be/laravel-localizer
src/LocalizerServiceProvider.php
LocalizerServiceProvider.registerLocalizer
protected function registerLocalizer() { $this->app->bind(Localizer::class, function ($app) { $locales = $app['config']->get("{$this->name}.supported-locales"); $detectors = $app['config']->get("{$this->name}.detectors"); $stores = $app['config']->get("{$this->name}.stores"); return new Localizer($locales, $detectors, $stores); }); }
php
protected function registerLocalizer() { $this->app->bind(Localizer::class, function ($app) { $locales = $app['config']->get("{$this->name}.supported-locales"); $detectors = $app['config']->get("{$this->name}.detectors"); $stores = $app['config']->get("{$this->name}.stores"); return new Localizer($locales, $detectors, $stores); }); }
[ "protected", "function", "registerLocalizer", "(", ")", "{", "$", "this", "->", "app", "->", "bind", "(", "Localizer", "::", "class", ",", "function", "(", "$", "app", ")", "{", "$", "locales", "=", "$", "app", "[", "'config'", "]", "->", "get", "(", "\"{$this->name}.supported-locales\"", ")", ";", "$", "detectors", "=", "$", "app", "[", "'config'", "]", "->", "get", "(", "\"{$this->name}.detectors\"", ")", ";", "$", "stores", "=", "$", "app", "[", "'config'", "]", "->", "get", "(", "\"{$this->name}.stores\"", ")", ";", "return", "new", "Localizer", "(", "$", "locales", ",", "$", "detectors", ",", "$", "stores", ")", ";", "}", ")", ";", "}" ]
Register Localizer. @return void
[ "Register", "Localizer", "." ]
812692796a73bd38fc205404d8ef90df5bfa0d83
https://github.com/codezero-be/laravel-localizer/blob/812692796a73bd38fc205404d8ef90df5bfa0d83/src/LocalizerServiceProvider.php#L65-L74
21,737
gyselroth/micro-container
src/RuntimeContainer.php
RuntimeContainer.resolve
public function resolve(string $name, ?array $parameters = null) { if (isset($this->service[$name])) { return $this->service[$name]; } if ($this->config->has($name)) { return $this->wrapService($name, $parameters); } if (null !== $this->parent_service) { $parents = array_merge([$name], class_implements($this->parent_service), class_parents($this->parent_service)); if (in_array($name, $parents, true) && $this->parent_service instanceof $name) { return $this->parent_service; } } if (null !== $this->parent) { return $this->parent->resolve($name, $parameters); } throw new Exception\ServiceNotFound("service $name was not found in service tree"); }
php
public function resolve(string $name, ?array $parameters = null) { if (isset($this->service[$name])) { return $this->service[$name]; } if ($this->config->has($name)) { return $this->wrapService($name, $parameters); } if (null !== $this->parent_service) { $parents = array_merge([$name], class_implements($this->parent_service), class_parents($this->parent_service)); if (in_array($name, $parents, true) && $this->parent_service instanceof $name) { return $this->parent_service; } } if (null !== $this->parent) { return $this->parent->resolve($name, $parameters); } throw new Exception\ServiceNotFound("service $name was not found in service tree"); }
[ "public", "function", "resolve", "(", "string", "$", "name", ",", "?", "array", "$", "parameters", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "service", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "service", "[", "$", "name", "]", ";", "}", "if", "(", "$", "this", "->", "config", "->", "has", "(", "$", "name", ")", ")", "{", "return", "$", "this", "->", "wrapService", "(", "$", "name", ",", "$", "parameters", ")", ";", "}", "if", "(", "null", "!==", "$", "this", "->", "parent_service", ")", "{", "$", "parents", "=", "array_merge", "(", "[", "$", "name", "]", ",", "class_implements", "(", "$", "this", "->", "parent_service", ")", ",", "class_parents", "(", "$", "this", "->", "parent_service", ")", ")", ";", "if", "(", "in_array", "(", "$", "name", ",", "$", "parents", ",", "true", ")", "&&", "$", "this", "->", "parent_service", "instanceof", "$", "name", ")", "{", "return", "$", "this", "->", "parent_service", ";", "}", "}", "if", "(", "null", "!==", "$", "this", "->", "parent", ")", "{", "return", "$", "this", "->", "parent", "->", "resolve", "(", "$", "name", ",", "$", "parameters", ")", ";", "}", "throw", "new", "Exception", "\\", "ServiceNotFound", "(", "\"service $name was not found in service tree\"", ")", ";", "}" ]
Resolve service.
[ "Resolve", "service", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L109-L132
21,738
gyselroth/micro-container
src/RuntimeContainer.php
RuntimeContainer.storeService
protected function storeService(string $name, array $config, $service) { if (false === $config['singleton']) { return $service; } $this->service[$name] = $service; if (isset($this->children[$name])) { $this->children[$name]->setParentService($service); } return $service; }
php
protected function storeService(string $name, array $config, $service) { if (false === $config['singleton']) { return $service; } $this->service[$name] = $service; if (isset($this->children[$name])) { $this->children[$name]->setParentService($service); } return $service; }
[ "protected", "function", "storeService", "(", "string", "$", "name", ",", "array", "$", "config", ",", "$", "service", ")", "{", "if", "(", "false", "===", "$", "config", "[", "'singleton'", "]", ")", "{", "return", "$", "service", ";", "}", "$", "this", "->", "service", "[", "$", "name", "]", "=", "$", "service", ";", "if", "(", "isset", "(", "$", "this", "->", "children", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "children", "[", "$", "name", "]", "->", "setParentService", "(", "$", "service", ")", ";", "}", "return", "$", "service", ";", "}" ]
Store service.
[ "Store", "service", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L137-L149
21,739
gyselroth/micro-container
src/RuntimeContainer.php
RuntimeContainer.wrapService
protected function wrapService(string $name, ?array $parameters = null) { $config = $this->config->get($name); if (true === $config['wrap']) { $that = $this; return function () use ($that, $name, $parameters) { return $that->autoWireClass($name, $parameters); }; } return $this->autoWireClass($name, $parameters); }
php
protected function wrapService(string $name, ?array $parameters = null) { $config = $this->config->get($name); if (true === $config['wrap']) { $that = $this; return function () use ($that, $name, $parameters) { return $that->autoWireClass($name, $parameters); }; } return $this->autoWireClass($name, $parameters); }
[ "protected", "function", "wrapService", "(", "string", "$", "name", ",", "?", "array", "$", "parameters", "=", "null", ")", "{", "$", "config", "=", "$", "this", "->", "config", "->", "get", "(", "$", "name", ")", ";", "if", "(", "true", "===", "$", "config", "[", "'wrap'", "]", ")", "{", "$", "that", "=", "$", "this", ";", "return", "function", "(", ")", "use", "(", "$", "that", ",", "$", "name", ",", "$", "parameters", ")", "{", "return", "$", "that", "->", "autoWireClass", "(", "$", "name", ",", "$", "parameters", ")", ";", "}", ";", "}", "return", "$", "this", "->", "autoWireClass", "(", "$", "name", ",", "$", "parameters", ")", ";", "}" ]
Wrap resolved service in callable if enabled.
[ "Wrap", "resolved", "service", "in", "callable", "if", "enabled", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L154-L166
21,740
gyselroth/micro-container
src/RuntimeContainer.php
RuntimeContainer.autoWireClass
protected function autoWireClass(string $name, ?array $parameters = null) { $config = $this->config->get($name); $class = $config['use']; if (null !== $parameters) { $config['singleton'] = false; } if (preg_match('#^\{([^{}]+)\}$#', $class, $match)) { return $this->wireReference($name, $match[1], $config); } $reflection = new ReflectionClass($class); if (isset($config['factory'])) { $factory = $reflection->getMethod($config['factory']); $args = $this->autoWireMethod($name, $factory, $config, $parameters); $instance = call_user_func_array([$class, $config['factory']], $args); return $this->prepareService($name, $instance, $reflection, $config); } $constructor = $reflection->getConstructor(); if (null === $constructor) { return $this->storeService($name, $config, new $class()); } $args = $this->autoWireMethod($name, $constructor, $config, $parameters); return $this->createInstance($name, $reflection, $args, $config); }
php
protected function autoWireClass(string $name, ?array $parameters = null) { $config = $this->config->get($name); $class = $config['use']; if (null !== $parameters) { $config['singleton'] = false; } if (preg_match('#^\{([^{}]+)\}$#', $class, $match)) { return $this->wireReference($name, $match[1], $config); } $reflection = new ReflectionClass($class); if (isset($config['factory'])) { $factory = $reflection->getMethod($config['factory']); $args = $this->autoWireMethod($name, $factory, $config, $parameters); $instance = call_user_func_array([$class, $config['factory']], $args); return $this->prepareService($name, $instance, $reflection, $config); } $constructor = $reflection->getConstructor(); if (null === $constructor) { return $this->storeService($name, $config, new $class()); } $args = $this->autoWireMethod($name, $constructor, $config, $parameters); return $this->createInstance($name, $reflection, $args, $config); }
[ "protected", "function", "autoWireClass", "(", "string", "$", "name", ",", "?", "array", "$", "parameters", "=", "null", ")", "{", "$", "config", "=", "$", "this", "->", "config", "->", "get", "(", "$", "name", ")", ";", "$", "class", "=", "$", "config", "[", "'use'", "]", ";", "if", "(", "null", "!==", "$", "parameters", ")", "{", "$", "config", "[", "'singleton'", "]", "=", "false", ";", "}", "if", "(", "preg_match", "(", "'#^\\{([^{}]+)\\}$#'", ",", "$", "class", ",", "$", "match", ")", ")", "{", "return", "$", "this", "->", "wireReference", "(", "$", "name", ",", "$", "match", "[", "1", "]", ",", "$", "config", ")", ";", "}", "$", "reflection", "=", "new", "ReflectionClass", "(", "$", "class", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'factory'", "]", ")", ")", "{", "$", "factory", "=", "$", "reflection", "->", "getMethod", "(", "$", "config", "[", "'factory'", "]", ")", ";", "$", "args", "=", "$", "this", "->", "autoWireMethod", "(", "$", "name", ",", "$", "factory", ",", "$", "config", ",", "$", "parameters", ")", ";", "$", "instance", "=", "call_user_func_array", "(", "[", "$", "class", ",", "$", "config", "[", "'factory'", "]", "]", ",", "$", "args", ")", ";", "return", "$", "this", "->", "prepareService", "(", "$", "name", ",", "$", "instance", ",", "$", "reflection", ",", "$", "config", ")", ";", "}", "$", "constructor", "=", "$", "reflection", "->", "getConstructor", "(", ")", ";", "if", "(", "null", "===", "$", "constructor", ")", "{", "return", "$", "this", "->", "storeService", "(", "$", "name", ",", "$", "config", ",", "new", "$", "class", "(", ")", ")", ";", "}", "$", "args", "=", "$", "this", "->", "autoWireMethod", "(", "$", "name", ",", "$", "constructor", ",", "$", "config", ",", "$", "parameters", ")", ";", "return", "$", "this", "->", "createInstance", "(", "$", "name", ",", "$", "reflection", ",", "$", "args", ",", "$", "config", ")", ";", "}" ]
Auto wire.
[ "Auto", "wire", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L171-L203
21,741
gyselroth/micro-container
src/RuntimeContainer.php
RuntimeContainer.wireReference
protected function wireReference(string $name, string $reference, array $config) { $service = $this->get($reference); $reflection = new ReflectionClass(get_class($service)); $config = $this->config->get($name); $service = $this->prepareService($name, $service, $reflection, $config); return $service; }
php
protected function wireReference(string $name, string $reference, array $config) { $service = $this->get($reference); $reflection = new ReflectionClass(get_class($service)); $config = $this->config->get($name); $service = $this->prepareService($name, $service, $reflection, $config); return $service; }
[ "protected", "function", "wireReference", "(", "string", "$", "name", ",", "string", "$", "reference", ",", "array", "$", "config", ")", "{", "$", "service", "=", "$", "this", "->", "get", "(", "$", "reference", ")", ";", "$", "reflection", "=", "new", "ReflectionClass", "(", "get_class", "(", "$", "service", ")", ")", ";", "$", "config", "=", "$", "this", "->", "config", "->", "get", "(", "$", "name", ")", ";", "$", "service", "=", "$", "this", "->", "prepareService", "(", "$", "name", ",", "$", "service", ",", "$", "reflection", ",", "$", "config", ")", ";", "return", "$", "service", ";", "}" ]
Wire named referenced service.
[ "Wire", "named", "referenced", "service", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L208-L216
21,742
gyselroth/micro-container
src/RuntimeContainer.php
RuntimeContainer.getProxyInstance
protected function getProxyInstance(string $name, ReflectionClass $class, array $arguments, array $config) { $factory = new LazyLoadingValueHolderFactory(); $that = $this; return $factory->createProxy( $class->getName(), function (&$wrappedObject, $proxy, $method, $parameters, &$initializer) use ($that, $name,$class,$arguments,$config) { $wrappedObject = $that->getRealInstance($name, $class, $arguments, $config); $initializer = null; } ); }
php
protected function getProxyInstance(string $name, ReflectionClass $class, array $arguments, array $config) { $factory = new LazyLoadingValueHolderFactory(); $that = $this; return $factory->createProxy( $class->getName(), function (&$wrappedObject, $proxy, $method, $parameters, &$initializer) use ($that, $name,$class,$arguments,$config) { $wrappedObject = $that->getRealInstance($name, $class, $arguments, $config); $initializer = null; } ); }
[ "protected", "function", "getProxyInstance", "(", "string", "$", "name", ",", "ReflectionClass", "$", "class", ",", "array", "$", "arguments", ",", "array", "$", "config", ")", "{", "$", "factory", "=", "new", "LazyLoadingValueHolderFactory", "(", ")", ";", "$", "that", "=", "$", "this", ";", "return", "$", "factory", "->", "createProxy", "(", "$", "class", "->", "getName", "(", ")", ",", "function", "(", "&", "$", "wrappedObject", ",", "$", "proxy", ",", "$", "method", ",", "$", "parameters", ",", "&", "$", "initializer", ")", "use", "(", "$", "that", ",", "$", "name", ",", "$", "class", ",", "$", "arguments", ",", "$", "config", ")", "{", "$", "wrappedObject", "=", "$", "that", "->", "getRealInstance", "(", "$", "name", ",", "$", "class", ",", "$", "arguments", ",", "$", "config", ")", ";", "$", "initializer", "=", "null", ";", "}", ")", ";", "}" ]
Create proxy instance.
[ "Create", "proxy", "instance", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L233-L245
21,743
gyselroth/micro-container
src/RuntimeContainer.php
RuntimeContainer.getRealInstance
protected function getRealInstance(string $name, ReflectionClass $class, array $arguments, array $config) { $instance = $class->newInstanceArgs($arguments); $instance = $this->prepareService($name, $instance, $class, $config); return $instance; }
php
protected function getRealInstance(string $name, ReflectionClass $class, array $arguments, array $config) { $instance = $class->newInstanceArgs($arguments); $instance = $this->prepareService($name, $instance, $class, $config); return $instance; }
[ "protected", "function", "getRealInstance", "(", "string", "$", "name", ",", "ReflectionClass", "$", "class", ",", "array", "$", "arguments", ",", "array", "$", "config", ")", "{", "$", "instance", "=", "$", "class", "->", "newInstanceArgs", "(", "$", "arguments", ")", ";", "$", "instance", "=", "$", "this", "->", "prepareService", "(", "$", "name", ",", "$", "instance", ",", "$", "class", ",", "$", "config", ")", ";", "return", "$", "instance", ";", "}" ]
Create real instance.
[ "Create", "real", "instance", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L250-L256
21,744
gyselroth/micro-container
src/RuntimeContainer.php
RuntimeContainer.autoWireMethod
protected function autoWireMethod(string $name, ReflectionMethod $method, array $config, ?array $parameters = null): array { $params = $method->getParameters(); $args = []; foreach ($params as $param) { $type = $param->getClass(); $param_name = $param->getName(); if (isset($parameters[$param_name])) { $args[$param_name] = $parameters[$param_name]; } elseif (isset($config['arguments'][$param_name])) { $args[$param_name] = $this->parseParam($config['arguments'][$param_name], $name); } elseif (null !== $type) { $args[$param_name] = $this->resolveServiceArgument($name, $type, $param); } elseif ($param->isDefaultValueAvailable()) { $args[$param_name] = $param->getDefaultValue(); } elseif ($param->allowsNull()) { $args[$param_name] = null; } else { throw new Exception\InvalidConfiguration('no value found for argument '.$param_name.' in method '.$method->getName().' for service '.$name); } if (!$param->canBePassedByValue()) { $value = &$args[$param_name]; $args[$param_name] = &$value; } } return $args; }
php
protected function autoWireMethod(string $name, ReflectionMethod $method, array $config, ?array $parameters = null): array { $params = $method->getParameters(); $args = []; foreach ($params as $param) { $type = $param->getClass(); $param_name = $param->getName(); if (isset($parameters[$param_name])) { $args[$param_name] = $parameters[$param_name]; } elseif (isset($config['arguments'][$param_name])) { $args[$param_name] = $this->parseParam($config['arguments'][$param_name], $name); } elseif (null !== $type) { $args[$param_name] = $this->resolveServiceArgument($name, $type, $param); } elseif ($param->isDefaultValueAvailable()) { $args[$param_name] = $param->getDefaultValue(); } elseif ($param->allowsNull()) { $args[$param_name] = null; } else { throw new Exception\InvalidConfiguration('no value found for argument '.$param_name.' in method '.$method->getName().' for service '.$name); } if (!$param->canBePassedByValue()) { $value = &$args[$param_name]; $args[$param_name] = &$value; } } return $args; }
[ "protected", "function", "autoWireMethod", "(", "string", "$", "name", ",", "ReflectionMethod", "$", "method", ",", "array", "$", "config", ",", "?", "array", "$", "parameters", "=", "null", ")", ":", "array", "{", "$", "params", "=", "$", "method", "->", "getParameters", "(", ")", ";", "$", "args", "=", "[", "]", ";", "foreach", "(", "$", "params", "as", "$", "param", ")", "{", "$", "type", "=", "$", "param", "->", "getClass", "(", ")", ";", "$", "param_name", "=", "$", "param", "->", "getName", "(", ")", ";", "if", "(", "isset", "(", "$", "parameters", "[", "$", "param_name", "]", ")", ")", "{", "$", "args", "[", "$", "param_name", "]", "=", "$", "parameters", "[", "$", "param_name", "]", ";", "}", "elseif", "(", "isset", "(", "$", "config", "[", "'arguments'", "]", "[", "$", "param_name", "]", ")", ")", "{", "$", "args", "[", "$", "param_name", "]", "=", "$", "this", "->", "parseParam", "(", "$", "config", "[", "'arguments'", "]", "[", "$", "param_name", "]", ",", "$", "name", ")", ";", "}", "elseif", "(", "null", "!==", "$", "type", ")", "{", "$", "args", "[", "$", "param_name", "]", "=", "$", "this", "->", "resolveServiceArgument", "(", "$", "name", ",", "$", "type", ",", "$", "param", ")", ";", "}", "elseif", "(", "$", "param", "->", "isDefaultValueAvailable", "(", ")", ")", "{", "$", "args", "[", "$", "param_name", "]", "=", "$", "param", "->", "getDefaultValue", "(", ")", ";", "}", "elseif", "(", "$", "param", "->", "allowsNull", "(", ")", ")", "{", "$", "args", "[", "$", "param_name", "]", "=", "null", ";", "}", "else", "{", "throw", "new", "Exception", "\\", "InvalidConfiguration", "(", "'no value found for argument '", ".", "$", "param_name", ".", "' in method '", ".", "$", "method", "->", "getName", "(", ")", ".", "' for service '", ".", "$", "name", ")", ";", "}", "if", "(", "!", "$", "param", "->", "canBePassedByValue", "(", ")", ")", "{", "$", "value", "=", "&", "$", "args", "[", "$", "param_name", "]", ";", "$", "args", "[", "$", "param_name", "]", "=", "&", "$", "value", ";", "}", "}", "return", "$", "args", ";", "}" ]
Autowire method.
[ "Autowire", "method", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L298-L328
21,745
gyselroth/micro-container
src/RuntimeContainer.php
RuntimeContainer.resolveServiceArgument
protected function resolveServiceArgument(string $name, ReflectionClass $type, ReflectionParameter $param) { $type_class = $type->getName(); if ($type_class === $name) { throw new RuntimeException('class '.$type_class.' can not depend on itself'); } try { return $this->traverseTree($name, $type_class); } catch (\Exception $e) { if ($param->isDefaultValueAvailable() && null === $param->getDefaultValue()) { return null; } throw $e; } }
php
protected function resolveServiceArgument(string $name, ReflectionClass $type, ReflectionParameter $param) { $type_class = $type->getName(); if ($type_class === $name) { throw new RuntimeException('class '.$type_class.' can not depend on itself'); } try { return $this->traverseTree($name, $type_class); } catch (\Exception $e) { if ($param->isDefaultValueAvailable() && null === $param->getDefaultValue()) { return null; } throw $e; } }
[ "protected", "function", "resolveServiceArgument", "(", "string", "$", "name", ",", "ReflectionClass", "$", "type", ",", "ReflectionParameter", "$", "param", ")", "{", "$", "type_class", "=", "$", "type", "->", "getName", "(", ")", ";", "if", "(", "$", "type_class", "===", "$", "name", ")", "{", "throw", "new", "RuntimeException", "(", "'class '", ".", "$", "type_class", ".", "' can not depend on itself'", ")", ";", "}", "try", "{", "return", "$", "this", "->", "traverseTree", "(", "$", "name", ",", "$", "type_class", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "$", "param", "->", "isDefaultValueAvailable", "(", ")", "&&", "null", "===", "$", "param", "->", "getDefaultValue", "(", ")", ")", "{", "return", "null", ";", "}", "throw", "$", "e", ";", "}", "}" ]
Resolve service argument.
[ "Resolve", "service", "argument", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L333-L350
21,746
gyselroth/micro-container
src/RuntimeContainer.php
RuntimeContainer.parseParam
protected function parseParam($param, string $name) { if (is_iterable($param)) { foreach ($param as $key => $value) { $param[$key] = $this->parseParam($value, $name); } return $param; } if (is_string($param)) { $param = $this->config->getEnv($param); if (preg_match('#^\{\{([^{}]+)\}\}$#', $param, $matches)) { return '{'.$matches[1].'}'; } if (preg_match('#^\{([^{}]+)\}$#', $param, $matches)) { return $this->traverseTree($name, $matches[1]); } return $param; } return $param; }
php
protected function parseParam($param, string $name) { if (is_iterable($param)) { foreach ($param as $key => $value) { $param[$key] = $this->parseParam($value, $name); } return $param; } if (is_string($param)) { $param = $this->config->getEnv($param); if (preg_match('#^\{\{([^{}]+)\}\}$#', $param, $matches)) { return '{'.$matches[1].'}'; } if (preg_match('#^\{([^{}]+)\}$#', $param, $matches)) { return $this->traverseTree($name, $matches[1]); } return $param; } return $param; }
[ "protected", "function", "parseParam", "(", "$", "param", ",", "string", "$", "name", ")", "{", "if", "(", "is_iterable", "(", "$", "param", ")", ")", "{", "foreach", "(", "$", "param", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "param", "[", "$", "key", "]", "=", "$", "this", "->", "parseParam", "(", "$", "value", ",", "$", "name", ")", ";", "}", "return", "$", "param", ";", "}", "if", "(", "is_string", "(", "$", "param", ")", ")", "{", "$", "param", "=", "$", "this", "->", "config", "->", "getEnv", "(", "$", "param", ")", ";", "if", "(", "preg_match", "(", "'#^\\{\\{([^{}]+)\\}\\}$#'", ",", "$", "param", ",", "$", "matches", ")", ")", "{", "return", "'{'", ".", "$", "matches", "[", "1", "]", ".", "'}'", ";", "}", "if", "(", "preg_match", "(", "'#^\\{([^{}]+)\\}$#'", ",", "$", "param", ",", "$", "matches", ")", ")", "{", "return", "$", "this", "->", "traverseTree", "(", "$", "name", ",", "$", "matches", "[", "1", "]", ")", ";", "}", "return", "$", "param", ";", "}", "return", "$", "param", ";", "}" ]
Parse param value.
[ "Parse", "param", "value", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L355-L379
21,747
gyselroth/micro-container
src/RuntimeContainer.php
RuntimeContainer.traverseTree
protected function traverseTree(string $current_service, string $service) { if (isset($this->children[$current_service])) { return $this->children[$current_service]->get($service); } $config = $this->config->get($current_service); if (isset($config['services'])) { $this->children[$current_service] = new self($config['services'], $this, $this->service[ContainerInterface::class]); return $this->children[$current_service]->get($service); } return $this->get($service); }
php
protected function traverseTree(string $current_service, string $service) { if (isset($this->children[$current_service])) { return $this->children[$current_service]->get($service); } $config = $this->config->get($current_service); if (isset($config['services'])) { $this->children[$current_service] = new self($config['services'], $this, $this->service[ContainerInterface::class]); return $this->children[$current_service]->get($service); } return $this->get($service); }
[ "protected", "function", "traverseTree", "(", "string", "$", "current_service", ",", "string", "$", "service", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "children", "[", "$", "current_service", "]", ")", ")", "{", "return", "$", "this", "->", "children", "[", "$", "current_service", "]", "->", "get", "(", "$", "service", ")", ";", "}", "$", "config", "=", "$", "this", "->", "config", "->", "get", "(", "$", "current_service", ")", ";", "if", "(", "isset", "(", "$", "config", "[", "'services'", "]", ")", ")", "{", "$", "this", "->", "children", "[", "$", "current_service", "]", "=", "new", "self", "(", "$", "config", "[", "'services'", "]", ",", "$", "this", ",", "$", "this", "->", "service", "[", "ContainerInterface", "::", "class", "]", ")", ";", "return", "$", "this", "->", "children", "[", "$", "current_service", "]", "->", "get", "(", "$", "service", ")", ";", "}", "return", "$", "this", "->", "get", "(", "$", "service", ")", ";", "}" ]
Locate service.
[ "Locate", "service", "." ]
728cf35af9645648392c50752b4b555d491bac4e
https://github.com/gyselroth/micro-container/blob/728cf35af9645648392c50752b4b555d491bac4e/src/RuntimeContainer.php#L384-L398
21,748
jarod2011/SimpleConcurrentRequestClient
src/SimpleConcurrent.php
RequestClient._getClient
private function _getClient(): ClientInterface { if (! $this->client instanceof ClientInterface) $this->client = new Client($this->clientConfig); return $this->client; }
php
private function _getClient(): ClientInterface { if (! $this->client instanceof ClientInterface) $this->client = new Client($this->clientConfig); return $this->client; }
[ "private", "function", "_getClient", "(", ")", ":", "ClientInterface", "{", "if", "(", "!", "$", "this", "->", "client", "instanceof", "ClientInterface", ")", "$", "this", "->", "client", "=", "new", "Client", "(", "$", "this", "->", "clientConfig", ")", ";", "return", "$", "this", "->", "client", ";", "}" ]
get a client implements \GuzzleHttp\ClientInterface @return ClientInterface
[ "get", "a", "client", "implements", "\\", "GuzzleHttp", "\\", "ClientInterface" ]
d9759e7978c0b8e4a3504f85db5983aa6146c91f
https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L434-L438
21,749
jarod2011/SimpleConcurrentRequestClient
src/SimpleConcurrent.php
RequestClient.addClientHeader
public function addClientHeader(string $headerName, $headerValue): self { $this->clientConfig['headers'][$headerName] = $headerValue; return $this; }
php
public function addClientHeader(string $headerName, $headerValue): self { $this->clientConfig['headers'][$headerName] = $headerValue; return $this; }
[ "public", "function", "addClientHeader", "(", "string", "$", "headerName", ",", "$", "headerValue", ")", ":", "self", "{", "$", "this", "->", "clientConfig", "[", "'headers'", "]", "[", "$", "headerName", "]", "=", "$", "headerValue", ";", "return", "$", "this", ";", "}" ]
add a client request header @param string $headerName @param mixed $headerValue @return self
[ "add", "a", "client", "request", "header" ]
d9759e7978c0b8e4a3504f85db5983aa6146c91f
https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L457-L461
21,750
jarod2011/SimpleConcurrentRequestClient
src/SimpleConcurrent.php
RequestClient._responseSuccessHandle
private function _responseSuccessHandle($response, $index) { try { if (! $response instanceof ResponseInterface) throw new UnknowResponseExpection($response); $result = $response->getBody()->getContents(); $cbk = $this->requestList[$index]->getSuccessCallbackList(); if (! empty($cbk)) { $result = array_reduce($cbk, function ($prev, $cb) { return $cb($prev); }, $result); } $response = new SimpleResponse(); $response->setResult($result); $this->requestList[$index]->setResponse($response); } catch (\Exception $e) { $this->_responseFailHandle($e, $index); } }
php
private function _responseSuccessHandle($response, $index) { try { if (! $response instanceof ResponseInterface) throw new UnknowResponseExpection($response); $result = $response->getBody()->getContents(); $cbk = $this->requestList[$index]->getSuccessCallbackList(); if (! empty($cbk)) { $result = array_reduce($cbk, function ($prev, $cb) { return $cb($prev); }, $result); } $response = new SimpleResponse(); $response->setResult($result); $this->requestList[$index]->setResponse($response); } catch (\Exception $e) { $this->_responseFailHandle($e, $index); } }
[ "private", "function", "_responseSuccessHandle", "(", "$", "response", ",", "$", "index", ")", "{", "try", "{", "if", "(", "!", "$", "response", "instanceof", "ResponseInterface", ")", "throw", "new", "UnknowResponseExpection", "(", "$", "response", ")", ";", "$", "result", "=", "$", "response", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ";", "$", "cbk", "=", "$", "this", "->", "requestList", "[", "$", "index", "]", "->", "getSuccessCallbackList", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "cbk", ")", ")", "{", "$", "result", "=", "array_reduce", "(", "$", "cbk", ",", "function", "(", "$", "prev", ",", "$", "cb", ")", "{", "return", "$", "cb", "(", "$", "prev", ")", ";", "}", ",", "$", "result", ")", ";", "}", "$", "response", "=", "new", "SimpleResponse", "(", ")", ";", "$", "response", "->", "setResult", "(", "$", "result", ")", ";", "$", "this", "->", "requestList", "[", "$", "index", "]", "->", "setResponse", "(", "$", "response", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "_responseFailHandle", "(", "$", "e", ",", "$", "index", ")", ";", "}", "}" ]
when request successed this method will be called @param mixed $response @param int $index @throws \Exception
[ "when", "request", "successed", "this", "method", "will", "be", "called" ]
d9759e7978c0b8e4a3504f85db5983aa6146c91f
https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L557-L574
21,751
jarod2011/SimpleConcurrentRequestClient
src/SimpleConcurrent.php
RequestClient._responseFailHandle
private function _responseFailHandle($error, $index) { $cbk = $this->requestList[$index]->getFailCallbackList(); if (! empty($cbk)) { $error = array_reduce($cbk, function ($prev, $cb) { return $cb($prev); }, $error); } $response = new SimpleResponse(); $response->setFail($error); $this->requestList[$index]->setResponse($response); }
php
private function _responseFailHandle($error, $index) { $cbk = $this->requestList[$index]->getFailCallbackList(); if (! empty($cbk)) { $error = array_reduce($cbk, function ($prev, $cb) { return $cb($prev); }, $error); } $response = new SimpleResponse(); $response->setFail($error); $this->requestList[$index]->setResponse($response); }
[ "private", "function", "_responseFailHandle", "(", "$", "error", ",", "$", "index", ")", "{", "$", "cbk", "=", "$", "this", "->", "requestList", "[", "$", "index", "]", "->", "getFailCallbackList", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "cbk", ")", ")", "{", "$", "error", "=", "array_reduce", "(", "$", "cbk", ",", "function", "(", "$", "prev", ",", "$", "cb", ")", "{", "return", "$", "cb", "(", "$", "prev", ")", ";", "}", ",", "$", "error", ")", ";", "}", "$", "response", "=", "new", "SimpleResponse", "(", ")", ";", "$", "response", "->", "setFail", "(", "$", "error", ")", ";", "$", "this", "->", "requestList", "[", "$", "index", "]", "->", "setResponse", "(", "$", "response", ")", ";", "}" ]
when request failed this method will be called @param mixed $error @param int $index
[ "when", "request", "failed", "this", "method", "will", "be", "called" ]
d9759e7978c0b8e4a3504f85db5983aa6146c91f
https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L581-L592
21,752
jarod2011/SimpleConcurrentRequestClient
src/SimpleConcurrent.php
RequestClient._getRequestPool
private function _getRequestPool(): Pool { return new Pool($this->_getClient(), $this->_getRequestPromise(), [ 'concurrency' => max(1, $this->configOfConcurrency), 'fulfilled' => function () { call_user_func_array([$this, '_responseSuccessHandle'], func_get_args()); }, 'rejected' => function () { call_user_func_array([$this, '_responseFailHandle'], func_get_args()); } ]); }
php
private function _getRequestPool(): Pool { return new Pool($this->_getClient(), $this->_getRequestPromise(), [ 'concurrency' => max(1, $this->configOfConcurrency), 'fulfilled' => function () { call_user_func_array([$this, '_responseSuccessHandle'], func_get_args()); }, 'rejected' => function () { call_user_func_array([$this, '_responseFailHandle'], func_get_args()); } ]); }
[ "private", "function", "_getRequestPool", "(", ")", ":", "Pool", "{", "return", "new", "Pool", "(", "$", "this", "->", "_getClient", "(", ")", ",", "$", "this", "->", "_getRequestPromise", "(", ")", ",", "[", "'concurrency'", "=>", "max", "(", "1", ",", "$", "this", "->", "configOfConcurrency", ")", ",", "'fulfilled'", "=>", "function", "(", ")", "{", "call_user_func_array", "(", "[", "$", "this", ",", "'_responseSuccessHandle'", "]", ",", "func_get_args", "(", ")", ")", ";", "}", ",", "'rejected'", "=>", "function", "(", ")", "{", "call_user_func_array", "(", "[", "$", "this", ",", "'_responseFailHandle'", "]", ",", "func_get_args", "(", ")", ")", ";", "}", "]", ")", ";", "}" ]
build a request pool implements \GuzzleHttp\Pool @return Pool
[ "build", "a", "request", "pool", "implements", "\\", "GuzzleHttp", "\\", "Pool" ]
d9759e7978c0b8e4a3504f85db5983aa6146c91f
https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L610-L621
21,753
jarod2011/SimpleConcurrentRequestClient
src/SimpleConcurrent.php
RequestClient.customSetting
public function customSetting(string $settingKey, $settingValue): self { $this->clientConfig[$settingKey] = $settingValue; return $this; }
php
public function customSetting(string $settingKey, $settingValue): self { $this->clientConfig[$settingKey] = $settingValue; return $this; }
[ "public", "function", "customSetting", "(", "string", "$", "settingKey", ",", "$", "settingValue", ")", ":", "self", "{", "$", "this", "->", "clientConfig", "[", "$", "settingKey", "]", "=", "$", "settingValue", ";", "return", "$", "this", ";", "}" ]
add or modify client config by custom @return self
[ "add", "or", "modify", "client", "config", "by", "custom" ]
d9759e7978c0b8e4a3504f85db5983aa6146c91f
https://github.com/jarod2011/SimpleConcurrentRequestClient/blob/d9759e7978c0b8e4a3504f85db5983aa6146c91f/src/SimpleConcurrent.php#L648-L652
21,754
alevilar/ristorantino-vendor
Risto/Controller/Component/Auth/PinAuthenticate.php
PinAuthenticate.authenticate
public function authenticate(CakeRequest $request, CakeResponse $response) { App::uses('MtSites', 'MtSites./Utility/MtSites'); // solo utilizar el logueo con PIN desde un Tenant if ( !MtSites::isTenant() ) { return false; } $userModel = $this->settings['userModel']; list(, $model) = pluginSplit($userModel); $fields = $this->settings['fields']; if (!$this->_checkFields($request, $model, $fields)) { return false; } return $this->_findUser($request->data[$model][$fields['pin']]); }
php
public function authenticate(CakeRequest $request, CakeResponse $response) { App::uses('MtSites', 'MtSites./Utility/MtSites'); // solo utilizar el logueo con PIN desde un Tenant if ( !MtSites::isTenant() ) { return false; } $userModel = $this->settings['userModel']; list(, $model) = pluginSplit($userModel); $fields = $this->settings['fields']; if (!$this->_checkFields($request, $model, $fields)) { return false; } return $this->_findUser($request->data[$model][$fields['pin']]); }
[ "public", "function", "authenticate", "(", "CakeRequest", "$", "request", ",", "CakeResponse", "$", "response", ")", "{", "App", "::", "uses", "(", "'MtSites'", ",", "'MtSites./Utility/MtSites'", ")", ";", "// solo utilizar el logueo con PIN desde un Tenant", "if", "(", "!", "MtSites", "::", "isTenant", "(", ")", ")", "{", "return", "false", ";", "}", "$", "userModel", "=", "$", "this", "->", "settings", "[", "'userModel'", "]", ";", "list", "(", ",", "$", "model", ")", "=", "pluginSplit", "(", "$", "userModel", ")", ";", "$", "fields", "=", "$", "this", "->", "settings", "[", "'fields'", "]", ";", "if", "(", "!", "$", "this", "->", "_checkFields", "(", "$", "request", ",", "$", "model", ",", "$", "fields", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "_findUser", "(", "$", "request", "->", "data", "[", "$", "model", "]", "[", "$", "fields", "[", "'pin'", "]", "]", ")", ";", "}" ]
Authenticates the identity contained in a request. Will use the `settings.userModel`, and `settings.fields` to find POST data that is used to find a matching record in the `settings.userModel`. Will return false if there is no post data, either username or pin is missing, or if the scope conditions have not been met. @param CakeRequest $request The request that contains login information. @param CakeResponse $response Unused response object. @return mixed False on login failure. An array of User data on success.
[ "Authenticates", "the", "identity", "contained", "in", "a", "request", ".", "Will", "use", "the", "settings", ".", "userModel", "and", "settings", ".", "fields", "to", "find", "POST", "data", "that", "is", "used", "to", "find", "a", "matching", "record", "in", "the", "settings", ".", "userModel", ".", "Will", "return", "false", "if", "there", "is", "no", "post", "data", "either", "username", "or", "pin", "is", "missing", "or", "if", "the", "scope", "conditions", "have", "not", "been", "met", "." ]
6b91a1e20cc0ba09a1968d77e3de6512cfa2d966
https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Controller/Component/Auth/PinAuthenticate.php#L81-L96
21,755
heidelpay/PhpDoc
src/phpDocumentor/Plugin/Scrybe/Converter/Metadata/Glossary.php
Glossary.addTerm
public function addTerm($term, $filename, $line_number) { if (!isset($this[$term])) { $this[$term] = array(); } if (!isset($this[$term][$filename])) { $this[$term][$filename] = array(); } $this[$term][$filename][] = $line_number; }
php
public function addTerm($term, $filename, $line_number) { if (!isset($this[$term])) { $this[$term] = array(); } if (!isset($this[$term][$filename])) { $this[$term][$filename] = array(); } $this[$term][$filename][] = $line_number; }
[ "public", "function", "addTerm", "(", "$", "term", ",", "$", "filename", ",", "$", "line_number", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "[", "$", "term", "]", ")", ")", "{", "$", "this", "[", "$", "term", "]", "=", "array", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "[", "$", "term", "]", "[", "$", "filename", "]", ")", ")", "{", "$", "this", "[", "$", "term", "]", "[", "$", "filename", "]", "=", "array", "(", ")", ";", "}", "$", "this", "[", "$", "term", "]", "[", "$", "filename", "]", "[", "]", "=", "$", "line_number", ";", "}" ]
Adds a glossary term to the collection. @param string $term @param string $filename @param int $line_number @return void
[ "Adds", "a", "glossary", "term", "to", "the", "collection", "." ]
5ac9e842cbd4cbb70900533b240c131f3515ee02
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Scrybe/Converter/Metadata/Glossary.php#L48-L58
21,756
wenbinye/PhalconX
src/Db/Schema/Column.php
Column.fromColumn
public static function fromColumn(Db\Column $column) { $data = $column->toArray(); if (isset($data['type']) && is_integer($data['type'])) { $data['type'] = self::getTypeName($data['type']); } if (isset($data['bindType']) && is_integer($data['bindType'])) { $data['bindType'] = self::getBindName($data['bindType']); } return new self($data); }
php
public static function fromColumn(Db\Column $column) { $data = $column->toArray(); if (isset($data['type']) && is_integer($data['type'])) { $data['type'] = self::getTypeName($data['type']); } if (isset($data['bindType']) && is_integer($data['bindType'])) { $data['bindType'] = self::getBindName($data['bindType']); } return new self($data); }
[ "public", "static", "function", "fromColumn", "(", "Db", "\\", "Column", "$", "column", ")", "{", "$", "data", "=", "$", "column", "->", "toArray", "(", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'type'", "]", ")", "&&", "is_integer", "(", "$", "data", "[", "'type'", "]", ")", ")", "{", "$", "data", "[", "'type'", "]", "=", "self", "::", "getTypeName", "(", "$", "data", "[", "'type'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "[", "'bindType'", "]", ")", "&&", "is_integer", "(", "$", "data", "[", "'bindType'", "]", ")", ")", "{", "$", "data", "[", "'bindType'", "]", "=", "self", "::", "getBindName", "(", "$", "data", "[", "'bindType'", "]", ")", ";", "}", "return", "new", "self", "(", "$", "data", ")", ";", "}" ]
create column object
[ "create", "column", "object" ]
0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Db/Schema/Column.php#L42-L53
21,757
surebert/surebert-framework
src/sb/JSON/RPC2/Client.php
Client.useEncryption
public function useEncryption($key) { $this->encryptor = new \sb\Encryption\ForTransmission($key); $this->encryption_key = $key; }
php
public function useEncryption($key) { $this->encryptor = new \sb\Encryption\ForTransmission($key); $this->encryption_key = $key; }
[ "public", "function", "useEncryption", "(", "$", "key", ")", "{", "$", "this", "->", "encryptor", "=", "new", "\\", "sb", "\\", "Encryption", "\\", "ForTransmission", "(", "$", "key", ")", ";", "$", "this", "->", "encryption_key", "=", "$", "key", ";", "}" ]
Sets the key that data is encrypted with and turns on encryption, the server must use the same key @param $key String
[ "Sets", "the", "key", "that", "data", "is", "encrypted", "with", "and", "turns", "on", "encryption", "the", "server", "must", "use", "the", "same", "key" ]
f2f32eb693bd39385ceb93355efb5b2a429f27ce
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/JSON/RPC2/Client.php#L114-L118
21,758
surebert/surebert-framework
src/sb/JSON/RPC2/Client.php
Client.addCookie
public function addCookie($cookie = Array()) { foreach ($cookie as $key => $val) { if (isset($this->encryption_key)) { $val = $this->encryptor->encrypt($val); } $this->cookies[$key] = $val; } }
php
public function addCookie($cookie = Array()) { foreach ($cookie as $key => $val) { if (isset($this->encryption_key)) { $val = $this->encryptor->encrypt($val); } $this->cookies[$key] = $val; } }
[ "public", "function", "addCookie", "(", "$", "cookie", "=", "Array", "(", ")", ")", "{", "foreach", "(", "$", "cookie", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "encryption_key", ")", ")", "{", "$", "val", "=", "$", "this", "->", "encryptor", "->", "encrypt", "(", "$", "val", ")", ";", "}", "$", "this", "->", "cookies", "[", "$", "key", "]", "=", "$", "val", ";", "}", "}" ]
Adds a cookie to send to the server @param $cookie Array('key' => 'val');
[ "Adds", "a", "cookie", "to", "send", "to", "the", "server" ]
f2f32eb693bd39385ceb93355efb5b2a429f27ce
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/JSON/RPC2/Client.php#L124-L133
21,759
surebert/surebert-framework
src/sb/JSON/RPC2/Client.php
Client.processResponse
protected function processResponse($str) { if (!empty($this->encryption_key)) { $str = $this->encryptor->decrypt($str); } $this->logResponse($str); //check if response body is serialized json_response object and just unserialize and return if it is if ($this->php_serialize_response && !empty($str)) { try { $serialized = \unserialize($str); if ($serialized !== false) { $response = $serialized; } } catch (\Exception $e) { if ($this->debug) { echo $body; } } } //Not sure about this? $str = \utf8_encode($str); if (!isset($response)) { $response = new \sb\JSON\RPC2\Response($str); } return $response; }
php
protected function processResponse($str) { if (!empty($this->encryption_key)) { $str = $this->encryptor->decrypt($str); } $this->logResponse($str); //check if response body is serialized json_response object and just unserialize and return if it is if ($this->php_serialize_response && !empty($str)) { try { $serialized = \unserialize($str); if ($serialized !== false) { $response = $serialized; } } catch (\Exception $e) { if ($this->debug) { echo $body; } } } //Not sure about this? $str = \utf8_encode($str); if (!isset($response)) { $response = new \sb\JSON\RPC2\Response($str); } return $response; }
[ "protected", "function", "processResponse", "(", "$", "str", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "encryption_key", ")", ")", "{", "$", "str", "=", "$", "this", "->", "encryptor", "->", "decrypt", "(", "$", "str", ")", ";", "}", "$", "this", "->", "logResponse", "(", "$", "str", ")", ";", "//check if response body is serialized json_response object and just unserialize and return if it is", "if", "(", "$", "this", "->", "php_serialize_response", "&&", "!", "empty", "(", "$", "str", ")", ")", "{", "try", "{", "$", "serialized", "=", "\\", "unserialize", "(", "$", "str", ")", ";", "if", "(", "$", "serialized", "!==", "false", ")", "{", "$", "response", "=", "$", "serialized", ";", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "if", "(", "$", "this", "->", "debug", ")", "{", "echo", "$", "body", ";", "}", "}", "}", "//Not sure about this?", "$", "str", "=", "\\", "utf8_encode", "(", "$", "str", ")", ";", "if", "(", "!", "isset", "(", "$", "response", ")", ")", "{", "$", "response", "=", "new", "\\", "sb", "\\", "JSON", "\\", "RPC2", "\\", "Response", "(", "$", "str", ")", ";", "}", "return", "$", "response", ";", "}" ]
Break down the received data into headers and response and then handle gz encoding, encryption, utf, etc @param $str The data returned from the socket connection @return string The body of the message
[ "Break", "down", "the", "received", "data", "into", "headers", "and", "response", "and", "then", "handle", "gz", "encoding", "encryption", "utf", "etc" ]
f2f32eb693bd39385ceb93355efb5b2a429f27ce
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/JSON/RPC2/Client.php#L234-L267
21,760
MASNathan/Parser
src/Parser.php
Parser.files
public static function files(array $listOfFiles) { $listOfContents = array(); foreach ($listOfFiles as $key => $filepath) { $listOfContents[$key] = self::file($filepath); } return $listOfContents; }
php
public static function files(array $listOfFiles) { $listOfContents = array(); foreach ($listOfFiles as $key => $filepath) { $listOfContents[$key] = self::file($filepath); } return $listOfContents; }
[ "public", "static", "function", "files", "(", "array", "$", "listOfFiles", ")", "{", "$", "listOfContents", "=", "array", "(", ")", ";", "foreach", "(", "$", "listOfFiles", "as", "$", "key", "=>", "$", "filepath", ")", "{", "$", "listOfContents", "[", "$", "key", "]", "=", "self", "::", "file", "(", "$", "filepath", ")", ";", "}", "return", "$", "listOfContents", ";", "}" ]
Creates an array of objects from multiple files @param array $listOfFiles List of file paths @return array
[ "Creates", "an", "array", "of", "objects", "from", "multiple", "files" ]
0f55402b99b1e071bdcd6277b9268f783ca25e34
https://github.com/MASNathan/Parser/blob/0f55402b99b1e071bdcd6277b9268f783ca25e34/src/Parser.php#L36-L43
21,761
ezsystems/ezcomments-ls-extension
datatypes/ezcomcomments/ezcomcommentstype.php
ezcomCommentsType.fetchObjectAttributeHTTPInput
function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) { $enabledName = $base . '_ezcomcomments_enabled_' . $contentObjectAttribute->attribute( 'id' ); $shownName = $base . '_ezcomcomments_shown_' . $contentObjectAttribute->attribute( 'id' ); $enabledValue = -1; $shownValue = -1; if ( $http->hasPostVariable( $enabledName ) ) { $enabledValue = 1; } if ( $http->hasPostVariable( $shownName ) ) { $shownValue = 1; } $contentObjectAttribute->setAttribute( 'data_float', $shownValue ); $contentObjectAttribute->setAttribute( 'data_int', $enabledValue ); return true; }
php
function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute ) { $enabledName = $base . '_ezcomcomments_enabled_' . $contentObjectAttribute->attribute( 'id' ); $shownName = $base . '_ezcomcomments_shown_' . $contentObjectAttribute->attribute( 'id' ); $enabledValue = -1; $shownValue = -1; if ( $http->hasPostVariable( $enabledName ) ) { $enabledValue = 1; } if ( $http->hasPostVariable( $shownName ) ) { $shownValue = 1; } $contentObjectAttribute->setAttribute( 'data_float', $shownValue ); $contentObjectAttribute->setAttribute( 'data_int', $enabledValue ); return true; }
[ "function", "fetchObjectAttributeHTTPInput", "(", "$", "http", ",", "$", "base", ",", "$", "contentObjectAttribute", ")", "{", "$", "enabledName", "=", "$", "base", ".", "'_ezcomcomments_enabled_'", ".", "$", "contentObjectAttribute", "->", "attribute", "(", "'id'", ")", ";", "$", "shownName", "=", "$", "base", ".", "'_ezcomcomments_shown_'", ".", "$", "contentObjectAttribute", "->", "attribute", "(", "'id'", ")", ";", "$", "enabledValue", "=", "-", "1", ";", "$", "shownValue", "=", "-", "1", ";", "if", "(", "$", "http", "->", "hasPostVariable", "(", "$", "enabledName", ")", ")", "{", "$", "enabledValue", "=", "1", ";", "}", "if", "(", "$", "http", "->", "hasPostVariable", "(", "$", "shownName", ")", ")", "{", "$", "shownValue", "=", "1", ";", "}", "$", "contentObjectAttribute", "->", "setAttribute", "(", "'data_float'", ",", "$", "shownValue", ")", ";", "$", "contentObjectAttribute", "->", "setAttribute", "(", "'data_int'", ",", "$", "enabledValue", ")", ";", "return", "true", ";", "}" ]
put the option enabled of ezcomcomment into data_int of contentobjectattribute @see kernel/classes/eZDataType#fetchObjectAttributeHTTPInput($http, $base, $objectAttribute)
[ "put", "the", "option", "enabled", "of", "ezcomcomment", "into", "data_int", "of", "contentobjectattribute" ]
2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5
https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/datatypes/ezcomcomments/ezcomcommentstype.php#L117-L134
21,762
ezsystems/ezcomments-ls-extension
datatypes/ezcomcomments/ezcomcommentstype.php
ezcomCommentsType.deleteStoredObjectAttribute
function deleteStoredObjectAttribute( $contentObjectAttribute, $version = null ) { $version = $contentObjectAttribute->objectVersion(); if ( !is_null( $version ) && $version->attribute( 'status' ) == eZContentObjectVersion::STATUS_PUBLISHED ) { $contentObjectID = $contentObjectAttribute->attribute( 'contentobject_id' ); $languageID = $contentObjectAttribute->attribute( 'language_id' ); eZPersistentObject::removeObject( ezcomComment::definition(), array( 'contentobject_id' => $contentObjectID, 'language_id' => $languageID ) ); } }
php
function deleteStoredObjectAttribute( $contentObjectAttribute, $version = null ) { $version = $contentObjectAttribute->objectVersion(); if ( !is_null( $version ) && $version->attribute( 'status' ) == eZContentObjectVersion::STATUS_PUBLISHED ) { $contentObjectID = $contentObjectAttribute->attribute( 'contentobject_id' ); $languageID = $contentObjectAttribute->attribute( 'language_id' ); eZPersistentObject::removeObject( ezcomComment::definition(), array( 'contentobject_id' => $contentObjectID, 'language_id' => $languageID ) ); } }
[ "function", "deleteStoredObjectAttribute", "(", "$", "contentObjectAttribute", ",", "$", "version", "=", "null", ")", "{", "$", "version", "=", "$", "contentObjectAttribute", "->", "objectVersion", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "version", ")", "&&", "$", "version", "->", "attribute", "(", "'status'", ")", "==", "eZContentObjectVersion", "::", "STATUS_PUBLISHED", ")", "{", "$", "contentObjectID", "=", "$", "contentObjectAttribute", "->", "attribute", "(", "'contentobject_id'", ")", ";", "$", "languageID", "=", "$", "contentObjectAttribute", "->", "attribute", "(", "'language_id'", ")", ";", "eZPersistentObject", "::", "removeObject", "(", "ezcomComment", "::", "definition", "(", ")", ",", "array", "(", "'contentobject_id'", "=>", "$", "contentObjectID", ",", "'language_id'", "=>", "$", "languageID", ")", ")", ";", "}", "}" ]
When deleting the content object, deleting all the comments. @see kernel/classes/eZDataType#deleteStoredObjectAttribute($objectAttribute, $version)
[ "When", "deleting", "the", "content", "object", "deleting", "all", "the", "comments", "." ]
2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5
https://github.com/ezsystems/ezcomments-ls-extension/blob/2b4cd8c34d4a77813e4d6a9c5a0d317a274c63c5/datatypes/ezcomcomments/ezcomcommentstype.php#L152-L164
21,763
snapwp/snap-blade
src/Blade_Service_Provider.php
Blade_Service_Provider.add_blade
public function add_blade() { $blade = new Snap_Blade( Theme_Utils::get_active_theme_path(Config::get('theme.templates_directory')), Theme_Utils::get_active_theme_path(\trailingslashit(Config::get('theme.cache_directory')) . 'templates'), Config::get('blade.development_mode') ? BladeOne::MODE_SLOW : BladeOne::MODE_FAST ); if (Config::get('blade.file_extension') !== $blade->getFileExtension()) { $blade->setFileExtension(Config::get('blade.file_extension')); } // Set the @inject directive to resolve from the service container. $blade->setInjectResolver( function ($namespace) { return Container::get($namespace); } ); $this->set_auth_callbacks($blade); $this->add_directives($blade); $this->add_wp_directives($blade); Container::add_instance($blade); Container::alias(Snap_Blade::class, 'blade'); }
php
public function add_blade() { $blade = new Snap_Blade( Theme_Utils::get_active_theme_path(Config::get('theme.templates_directory')), Theme_Utils::get_active_theme_path(\trailingslashit(Config::get('theme.cache_directory')) . 'templates'), Config::get('blade.development_mode') ? BladeOne::MODE_SLOW : BladeOne::MODE_FAST ); if (Config::get('blade.file_extension') !== $blade->getFileExtension()) { $blade->setFileExtension(Config::get('blade.file_extension')); } // Set the @inject directive to resolve from the service container. $blade->setInjectResolver( function ($namespace) { return Container::get($namespace); } ); $this->set_auth_callbacks($blade); $this->add_directives($blade); $this->add_wp_directives($blade); Container::add_instance($blade); Container::alias(Snap_Blade::class, 'blade'); }
[ "public", "function", "add_blade", "(", ")", "{", "$", "blade", "=", "new", "Snap_Blade", "(", "Theme_Utils", "::", "get_active_theme_path", "(", "Config", "::", "get", "(", "'theme.templates_directory'", ")", ")", ",", "Theme_Utils", "::", "get_active_theme_path", "(", "\\", "trailingslashit", "(", "Config", "::", "get", "(", "'theme.cache_directory'", ")", ")", ".", "'templates'", ")", ",", "Config", "::", "get", "(", "'blade.development_mode'", ")", "?", "BladeOne", "::", "MODE_SLOW", ":", "BladeOne", "::", "MODE_FAST", ")", ";", "if", "(", "Config", "::", "get", "(", "'blade.file_extension'", ")", "!==", "$", "blade", "->", "getFileExtension", "(", ")", ")", "{", "$", "blade", "->", "setFileExtension", "(", "Config", "::", "get", "(", "'blade.file_extension'", ")", ")", ";", "}", "// Set the @inject directive to resolve from the service container.", "$", "blade", "->", "setInjectResolver", "(", "function", "(", "$", "namespace", ")", "{", "return", "Container", "::", "get", "(", "$", "namespace", ")", ";", "}", ")", ";", "$", "this", "->", "set_auth_callbacks", "(", "$", "blade", ")", ";", "$", "this", "->", "add_directives", "(", "$", "blade", ")", ";", "$", "this", "->", "add_wp_directives", "(", "$", "blade", ")", ";", "Container", "::", "add_instance", "(", "$", "blade", ")", ";", "Container", "::", "alias", "(", "Snap_Blade", "::", "class", ",", "'blade'", ")", ";", "}" ]
Creates the Snap_blade instance, and adds to service container. @since 1.0.0
[ "Creates", "the", "Snap_blade", "instance", "and", "adds", "to", "service", "container", "." ]
41e004e93440f6b58638b64dc8d20cca4a0546fa
https://github.com/snapwp/snap-blade/blob/41e004e93440f6b58638b64dc8d20cca4a0546fa/src/Blade_Service_Provider.php#L58-L85
21,764
snapwp/snap-blade
src/Blade_Service_Provider.php
Blade_Service_Provider.add_directives
private function add_directives($blade) { $blade->directive( 'simplemenu', function ($expression) { \preg_match('/\( *(.*) * as *([^\)]*)/', $expression, $matches); $iteratee = \trim($matches[1]); $iteration = \trim($matches[2]); $init_loop = "\$__currentLoopData = \Snap\Utils\Menu_Utils::get_nav_menu($iteratee); \$this->addLoop(\$__currentLoopData);"; $iterate_loop = '$this->incrementLoopIndices(); $loop = $this->getFirstLoop();'; return "<?php {$init_loop} foreach(\$__currentLoopData as {$iteration}): {$iterate_loop} ?>"; } ); $blade->directive( 'endsimplemenu', function () { return '<?php endforeach; $this->popLoop(); $loop = $this->getFirstLoop(); ?>'; } ); $blade->directive( 'partial', function ($input) { $input = $this->trim_input($input); $input = \str_replace('partials.\'', 'partials.', '\'partials.' . $input); return '<?php echo $this->runChild('.$input.'); ?>'; } ); $blade->directive( 'posttypepartial', function () { return '<?php global $post; echo $this->runChild(\'partials.post-type.\' . \get_post_type(), [\'post\' => $post]); ?>'; } ); $blade->directive( 'paginate', function ($input = []) { $input = $input ?? '[]'; return ' <?php $pagination = \Snap\Services\Container::resolve( \Snap\Templating\Pagination::class, [ \'args\' => ' . $this->trim_input($input) .', ] ); echo $pagination->get(); ?>'; } ); $blade->directive( 'loop', function ($input) { $input = $this->trim_input($input); $init_loop = '$__loop_query = $wp_query;'; if (! empty($input)) { $init_loop = '$__loop_query = ' . $input . ';'; } $init_loop .= '$__currentLoopData = $__loop_query->posts; $this->addLoop($__currentLoopData); global $post;'; $iterate_loop = '$this->incrementLoopIndices(); $loop = $this->getFirstLoop();'; return "<?php {$init_loop} while (\$__loop_query->have_posts()): \$__loop_query->the_post(); {$iterate_loop} ?>"; } ); $blade->directive( 'endloop', function () { return '<?php endwhile; ?>'; } ); }
php
private function add_directives($blade) { $blade->directive( 'simplemenu', function ($expression) { \preg_match('/\( *(.*) * as *([^\)]*)/', $expression, $matches); $iteratee = \trim($matches[1]); $iteration = \trim($matches[2]); $init_loop = "\$__currentLoopData = \Snap\Utils\Menu_Utils::get_nav_menu($iteratee); \$this->addLoop(\$__currentLoopData);"; $iterate_loop = '$this->incrementLoopIndices(); $loop = $this->getFirstLoop();'; return "<?php {$init_loop} foreach(\$__currentLoopData as {$iteration}): {$iterate_loop} ?>"; } ); $blade->directive( 'endsimplemenu', function () { return '<?php endforeach; $this->popLoop(); $loop = $this->getFirstLoop(); ?>'; } ); $blade->directive( 'partial', function ($input) { $input = $this->trim_input($input); $input = \str_replace('partials.\'', 'partials.', '\'partials.' . $input); return '<?php echo $this->runChild('.$input.'); ?>'; } ); $blade->directive( 'posttypepartial', function () { return '<?php global $post; echo $this->runChild(\'partials.post-type.\' . \get_post_type(), [\'post\' => $post]); ?>'; } ); $blade->directive( 'paginate', function ($input = []) { $input = $input ?? '[]'; return ' <?php $pagination = \Snap\Services\Container::resolve( \Snap\Templating\Pagination::class, [ \'args\' => ' . $this->trim_input($input) .', ] ); echo $pagination->get(); ?>'; } ); $blade->directive( 'loop', function ($input) { $input = $this->trim_input($input); $init_loop = '$__loop_query = $wp_query;'; if (! empty($input)) { $init_loop = '$__loop_query = ' . $input . ';'; } $init_loop .= '$__currentLoopData = $__loop_query->posts; $this->addLoop($__currentLoopData); global $post;'; $iterate_loop = '$this->incrementLoopIndices(); $loop = $this->getFirstLoop();'; return "<?php {$init_loop} while (\$__loop_query->have_posts()): \$__loop_query->the_post(); {$iterate_loop} ?>"; } ); $blade->directive( 'endloop', function () { return '<?php endwhile; ?>'; } ); }
[ "private", "function", "add_directives", "(", "$", "blade", ")", "{", "$", "blade", "->", "directive", "(", "'simplemenu'", ",", "function", "(", "$", "expression", ")", "{", "\\", "preg_match", "(", "'/\\( *(.*) * as *([^\\)]*)/'", ",", "$", "expression", ",", "$", "matches", ")", ";", "$", "iteratee", "=", "\\", "trim", "(", "$", "matches", "[", "1", "]", ")", ";", "$", "iteration", "=", "\\", "trim", "(", "$", "matches", "[", "2", "]", ")", ";", "$", "init_loop", "=", "\"\\$__currentLoopData = \\Snap\\Utils\\Menu_Utils::get_nav_menu($iteratee); \n \\$this->addLoop(\\$__currentLoopData);\"", ";", "$", "iterate_loop", "=", "'$this->incrementLoopIndices(); \n $loop = $this->getFirstLoop();'", ";", "return", "\"<?php {$init_loop} foreach(\\$__currentLoopData as {$iteration}): {$iterate_loop} ?>\"", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'endsimplemenu'", ",", "function", "(", ")", "{", "return", "'<?php endforeach; $this->popLoop(); $loop = $this->getFirstLoop(); ?>'", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'partial'", ",", "function", "(", "$", "input", ")", "{", "$", "input", "=", "$", "this", "->", "trim_input", "(", "$", "input", ")", ";", "$", "input", "=", "\\", "str_replace", "(", "'partials.\\''", ",", "'partials.'", ",", "'\\'partials.'", ".", "$", "input", ")", ";", "return", "'<?php echo $this->runChild('", ".", "$", "input", ".", "'); ?>'", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'posttypepartial'", ",", "function", "(", ")", "{", "return", "'<?php global $post; echo $this->runChild(\\'partials.post-type.\\' . \\get_post_type(), [\\'post\\' => $post]); ?>'", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'paginate'", ",", "function", "(", "$", "input", "=", "[", "]", ")", "{", "$", "input", "=", "$", "input", "??", "'[]'", ";", "return", "'\n\t\t\t<?php\n\t\t\t$pagination = \\Snap\\Services\\Container::resolve(\n\t \\Snap\\Templating\\Pagination::class,\n\t [\n\t \\'args\\' => '", ".", "$", "this", "->", "trim_input", "(", "$", "input", ")", ".", "',\n\t ]\n\t );\n\n\t echo $pagination->get();\n\t ?>'", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'loop'", ",", "function", "(", "$", "input", ")", "{", "$", "input", "=", "$", "this", "->", "trim_input", "(", "$", "input", ")", ";", "$", "init_loop", "=", "'$__loop_query = $wp_query;'", ";", "if", "(", "!", "empty", "(", "$", "input", ")", ")", "{", "$", "init_loop", "=", "'$__loop_query = '", ".", "$", "input", ".", "';'", ";", "}", "$", "init_loop", ".=", "'$__currentLoopData = $__loop_query->posts; \n $this->addLoop($__currentLoopData); \n global $post;'", ";", "$", "iterate_loop", "=", "'$this->incrementLoopIndices(); $loop = $this->getFirstLoop();'", ";", "return", "\"<?php {$init_loop} while (\\$__loop_query->have_posts()): \n \\$__loop_query->the_post(); {$iterate_loop} ?>\"", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'endloop'", ",", "function", "(", ")", "{", "return", "'<?php endwhile; ?>'", ";", "}", ")", ";", "}" ]
Add custom directives to blade. @since 1.0.0 @param BladeOne $blade The BladeOne service.
[ "Add", "custom", "directives", "to", "blade", "." ]
41e004e93440f6b58638b64dc8d20cca4a0546fa
https://github.com/snapwp/snap-blade/blob/41e004e93440f6b58638b64dc8d20cca4a0546fa/src/Blade_Service_Provider.php#L134-L225
21,765
snapwp/snap-blade
src/Blade_Service_Provider.php
Blade_Service_Provider.add_wp_directives
private function add_wp_directives($blade) { $blade->directive( 'wphead', function () { return '<?php wp_head(); ?>'; } ); $blade->directive( 'wpfooter', function () { return '<?php wp_footer(); ?>'; } ); $blade->directive( 'sidebar', function ($input) { return "<?php dynamic_sidebar({$this->trim_input($input)}); ?>"; } ); $blade->directive( 'action', function ($input) { return "<?php do_action({$this->trim_input($input)}); ?>"; } ); $blade->directive( 'thecontent', function () { return "<?php the_content(); ?>"; } ); $blade->directive( 'theexcerpt', function () { return "<?php the_excerpt(); ?>"; } ); $blade->directive( 'navmenu', function ($input) { return "<?php wp_nav_menu({$this->trim_input($input)}); ?>"; } ); $blade->directive( 'searchform', function () { return "<?php get_search_form(); ?>"; } ); $blade->directive( 'setpostdata', function ($input) { return '<?php setup_postdata($GLOBALS[\'post\'] =& '. $this->trim_input($input) .'); ?>'; } ); $blade->directive( 'resetpostdata', function () { return '<?php wp_reset_postdata(); ?>'; } ); }
php
private function add_wp_directives($blade) { $blade->directive( 'wphead', function () { return '<?php wp_head(); ?>'; } ); $blade->directive( 'wpfooter', function () { return '<?php wp_footer(); ?>'; } ); $blade->directive( 'sidebar', function ($input) { return "<?php dynamic_sidebar({$this->trim_input($input)}); ?>"; } ); $blade->directive( 'action', function ($input) { return "<?php do_action({$this->trim_input($input)}); ?>"; } ); $blade->directive( 'thecontent', function () { return "<?php the_content(); ?>"; } ); $blade->directive( 'theexcerpt', function () { return "<?php the_excerpt(); ?>"; } ); $blade->directive( 'navmenu', function ($input) { return "<?php wp_nav_menu({$this->trim_input($input)}); ?>"; } ); $blade->directive( 'searchform', function () { return "<?php get_search_form(); ?>"; } ); $blade->directive( 'setpostdata', function ($input) { return '<?php setup_postdata($GLOBALS[\'post\'] =& '. $this->trim_input($input) .'); ?>'; } ); $blade->directive( 'resetpostdata', function () { return '<?php wp_reset_postdata(); ?>'; } ); }
[ "private", "function", "add_wp_directives", "(", "$", "blade", ")", "{", "$", "blade", "->", "directive", "(", "'wphead'", ",", "function", "(", ")", "{", "return", "'<?php wp_head(); ?>'", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'wpfooter'", ",", "function", "(", ")", "{", "return", "'<?php wp_footer(); ?>'", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'sidebar'", ",", "function", "(", "$", "input", ")", "{", "return", "\"<?php dynamic_sidebar({$this->trim_input($input)}); ?>\"", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'action'", ",", "function", "(", "$", "input", ")", "{", "return", "\"<?php do_action({$this->trim_input($input)}); ?>\"", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'thecontent'", ",", "function", "(", ")", "{", "return", "\"<?php the_content(); ?>\"", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'theexcerpt'", ",", "function", "(", ")", "{", "return", "\"<?php the_excerpt(); ?>\"", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'navmenu'", ",", "function", "(", "$", "input", ")", "{", "return", "\"<?php wp_nav_menu({$this->trim_input($input)}); ?>\"", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'searchform'", ",", "function", "(", ")", "{", "return", "\"<?php get_search_form(); ?>\"", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'setpostdata'", ",", "function", "(", "$", "input", ")", "{", "return", "'<?php setup_postdata($GLOBALS[\\'post\\'] =& '", ".", "$", "this", "->", "trim_input", "(", "$", "input", ")", ".", "'); ?>'", ";", "}", ")", ";", "$", "blade", "->", "directive", "(", "'resetpostdata'", ",", "function", "(", ")", "{", "return", "'<?php wp_reset_postdata(); ?>'", ";", "}", ")", ";", "}" ]
Add custom directives for WordPress functions to blade. @since 1.0.0 @param BladeOne $blade The BladeOne service.
[ "Add", "custom", "directives", "for", "WordPress", "functions", "to", "blade", "." ]
41e004e93440f6b58638b64dc8d20cca4a0546fa
https://github.com/snapwp/snap-blade/blob/41e004e93440f6b58638b64dc8d20cca4a0546fa/src/Blade_Service_Provider.php#L234-L305
21,766
NuclearCMS/Hierarchy
src/Repositories/NodeFieldRepository.php
NodeFieldRepository.create
public function create($id, array $attributes) { $typeModelName = $this->getTypeModelName(); $nodeType = $typeModelName::findOrFail($id); $nodeField = $nodeType->addField($attributes); $this->builderService->buildField( $nodeField->getName(), $nodeField->getType(), $nodeField->isIndexed(), $nodeType->getName(), $nodeType ); return $nodeField; }
php
public function create($id, array $attributes) { $typeModelName = $this->getTypeModelName(); $nodeType = $typeModelName::findOrFail($id); $nodeField = $nodeType->addField($attributes); $this->builderService->buildField( $nodeField->getName(), $nodeField->getType(), $nodeField->isIndexed(), $nodeType->getName(), $nodeType ); return $nodeField; }
[ "public", "function", "create", "(", "$", "id", ",", "array", "$", "attributes", ")", "{", "$", "typeModelName", "=", "$", "this", "->", "getTypeModelName", "(", ")", ";", "$", "nodeType", "=", "$", "typeModelName", "::", "findOrFail", "(", "$", "id", ")", ";", "$", "nodeField", "=", "$", "nodeType", "->", "addField", "(", "$", "attributes", ")", ";", "$", "this", "->", "builderService", "->", "buildField", "(", "$", "nodeField", "->", "getName", "(", ")", ",", "$", "nodeField", "->", "getType", "(", ")", ",", "$", "nodeField", "->", "isIndexed", "(", ")", ",", "$", "nodeType", "->", "getName", "(", ")", ",", "$", "nodeType", ")", ";", "return", "$", "nodeField", ";", "}" ]
Creates a node field @param int $id @param array $attributes @return NodeFieldContract
[ "Creates", "a", "node", "field" ]
535171c5e2db72265313fd2110aec8456e46f459
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Repositories/NodeFieldRepository.php#L15-L32
21,767
NuclearCMS/Hierarchy
src/Repositories/NodeFieldRepository.php
NodeFieldRepository.destroy
public function destroy($id) { $modelName = $this->getModelName(); $nodeField = $modelName::findOrFail($id); $nodeField->delete(); $this->builderService->destroyField( $nodeField->getName(), $nodeField->nodeType->getName(), $nodeField->nodeType ); return $nodeField; }
php
public function destroy($id) { $modelName = $this->getModelName(); $nodeField = $modelName::findOrFail($id); $nodeField->delete(); $this->builderService->destroyField( $nodeField->getName(), $nodeField->nodeType->getName(), $nodeField->nodeType ); return $nodeField; }
[ "public", "function", "destroy", "(", "$", "id", ")", "{", "$", "modelName", "=", "$", "this", "->", "getModelName", "(", ")", ";", "$", "nodeField", "=", "$", "modelName", "::", "findOrFail", "(", "$", "id", ")", ";", "$", "nodeField", "->", "delete", "(", ")", ";", "$", "this", "->", "builderService", "->", "destroyField", "(", "$", "nodeField", "->", "getName", "(", ")", ",", "$", "nodeField", "->", "nodeType", "->", "getName", "(", ")", ",", "$", "nodeField", "->", "nodeType", ")", ";", "return", "$", "nodeField", ";", "}" ]
Destroys a node field @param int $id @return NodeFieldContract
[ "Destroys", "a", "node", "field" ]
535171c5e2db72265313fd2110aec8456e46f459
https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Repositories/NodeFieldRepository.php#L40-L54
21,768
zicht/z
src/Zicht/Tool/Command/Descriptor/TextDescriptor.php
TextDescriptor.splitDefinition
public function splitDefinition(InputDefinition $definition) { /** @var InputDefinition[] $ret */ $ret = array( new InputDefinition(), new InputDefinition() ); foreach ($definition->getArguments() as $arg) { $ret[0]->addArgument($arg); $ret[1]->addArgument($arg); } foreach ($definition->getOptions() as $opt) { $ret[$this->isHiddenOption($opt) ? 1 : 0]->addOption($opt); } return $ret; }
php
public function splitDefinition(InputDefinition $definition) { /** @var InputDefinition[] $ret */ $ret = array( new InputDefinition(), new InputDefinition() ); foreach ($definition->getArguments() as $arg) { $ret[0]->addArgument($arg); $ret[1]->addArgument($arg); } foreach ($definition->getOptions() as $opt) { $ret[$this->isHiddenOption($opt) ? 1 : 0]->addOption($opt); } return $ret; }
[ "public", "function", "splitDefinition", "(", "InputDefinition", "$", "definition", ")", "{", "/** @var InputDefinition[] $ret */", "$", "ret", "=", "array", "(", "new", "InputDefinition", "(", ")", ",", "new", "InputDefinition", "(", ")", ")", ";", "foreach", "(", "$", "definition", "->", "getArguments", "(", ")", "as", "$", "arg", ")", "{", "$", "ret", "[", "0", "]", "->", "addArgument", "(", "$", "arg", ")", ";", "$", "ret", "[", "1", "]", "->", "addArgument", "(", "$", "arg", ")", ";", "}", "foreach", "(", "$", "definition", "->", "getOptions", "(", ")", "as", "$", "opt", ")", "{", "$", "ret", "[", "$", "this", "->", "isHiddenOption", "(", "$", "opt", ")", "?", "1", ":", "0", "]", "->", "addOption", "(", "$", "opt", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Splits the definition in an internal and public one, the latter representing whatever is shown to the user, the former representing the options that are hidden. @param \Symfony\Component\Console\Input\InputDefinition $definition @return InputDefinition[]
[ "Splits", "the", "definition", "in", "an", "internal", "and", "public", "one", "the", "latter", "representing", "whatever", "is", "shown", "to", "the", "user", "the", "former", "representing", "the", "options", "that", "are", "hidden", "." ]
6a1731dad20b018555a96b726a61d4bf8ec8c886
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Command/Descriptor/TextDescriptor.php#L74-L90
21,769
trunda/SmfMenu
src/Smf/Menu/Renderer/Manager.php
Manager.addRenderer
public function addRenderer($name, $renderer, $overwrite = false) { if (isset($this->renderers[$name]) && !$overwrite) { throw new InvalidArgumentException("Renderer with name '$name' is already registered."); } unset($this->renderers[$name]); // Is class? Exists? if (is_string($renderer) && !class_exists($renderer)) { throw new InvalidArgumentException("Renderer class '$renderer' doesn't exist."); } $this->renderers[$name] = $renderer; return $this; }
php
public function addRenderer($name, $renderer, $overwrite = false) { if (isset($this->renderers[$name]) && !$overwrite) { throw new InvalidArgumentException("Renderer with name '$name' is already registered."); } unset($this->renderers[$name]); // Is class? Exists? if (is_string($renderer) && !class_exists($renderer)) { throw new InvalidArgumentException("Renderer class '$renderer' doesn't exist."); } $this->renderers[$name] = $renderer; return $this; }
[ "public", "function", "addRenderer", "(", "$", "name", ",", "$", "renderer", ",", "$", "overwrite", "=", "false", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "renderers", "[", "$", "name", "]", ")", "&&", "!", "$", "overwrite", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Renderer with name '$name' is already registered.\"", ")", ";", "}", "unset", "(", "$", "this", "->", "renderers", "[", "$", "name", "]", ")", ";", "// Is class? Exists?", "if", "(", "is_string", "(", "$", "renderer", ")", "&&", "!", "class_exists", "(", "$", "renderer", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Renderer class '$renderer' doesn't exist.\"", ")", ";", "}", "$", "this", "->", "renderers", "[", "$", "name", "]", "=", "$", "renderer", ";", "return", "$", "this", ";", "}" ]
Ads renderer with given name @param string $name Name of the renderer @param string|IRenderer $renderer Renderer class name or instance @param bool $overwrite Should be overwritten renderer with this name if exists? @return IManager Fluent interface @throws InvalidArgumentException If the renderer with given name already exists and $overwrite is false
[ "Ads", "renderer", "with", "given", "name" ]
739e74fb664c1f018b4a74142bd28d20c004bac6
https://github.com/trunda/SmfMenu/blob/739e74fb664c1f018b4a74142bd28d20c004bac6/src/Smf/Menu/Renderer/Manager.php#L25-L37
21,770
trunda/SmfMenu
src/Smf/Menu/Renderer/Manager.php
Manager.getRenderer
public function getRenderer($name) { // default if ($name === null) { if ($this->defaultRenderer !== null) { $name = $this->defaultRenderer; } else if (count($this->renderers) > 0) { $name = key($this->renderers); } } if (!isset($this->renderers[$name])) { throw new InvalidArgumentException("Renderer with name '$name' doesn't exist."); } if (is_string($this->renderers[$name])) { $renderer = new $this->renderers[$name](); $reflection = ClassType::from($renderer); if (!$reflection->isSubclassOf('Smf\Menu\Renderer\IRenderer')) { throw new InvalidArgumentException("Renderer class '{$this->renderers[$name]}' is not subclass of Smf\\Menu\\Renderer\\IRenderer"); } $this->renderers[$name] = $renderer; } return $this->renderers[$name]; }
php
public function getRenderer($name) { // default if ($name === null) { if ($this->defaultRenderer !== null) { $name = $this->defaultRenderer; } else if (count($this->renderers) > 0) { $name = key($this->renderers); } } if (!isset($this->renderers[$name])) { throw new InvalidArgumentException("Renderer with name '$name' doesn't exist."); } if (is_string($this->renderers[$name])) { $renderer = new $this->renderers[$name](); $reflection = ClassType::from($renderer); if (!$reflection->isSubclassOf('Smf\Menu\Renderer\IRenderer')) { throw new InvalidArgumentException("Renderer class '{$this->renderers[$name]}' is not subclass of Smf\\Menu\\Renderer\\IRenderer"); } $this->renderers[$name] = $renderer; } return $this->renderers[$name]; }
[ "public", "function", "getRenderer", "(", "$", "name", ")", "{", "// default", "if", "(", "$", "name", "===", "null", ")", "{", "if", "(", "$", "this", "->", "defaultRenderer", "!==", "null", ")", "{", "$", "name", "=", "$", "this", "->", "defaultRenderer", ";", "}", "else", "if", "(", "count", "(", "$", "this", "->", "renderers", ")", ">", "0", ")", "{", "$", "name", "=", "key", "(", "$", "this", "->", "renderers", ")", ";", "}", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "renderers", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Renderer with name '$name' doesn't exist.\"", ")", ";", "}", "if", "(", "is_string", "(", "$", "this", "->", "renderers", "[", "$", "name", "]", ")", ")", "{", "$", "renderer", "=", "new", "$", "this", "->", "renderers", "[", "$", "name", "]", "(", ")", ";", "$", "reflection", "=", "ClassType", "::", "from", "(", "$", "renderer", ")", ";", "if", "(", "!", "$", "reflection", "->", "isSubclassOf", "(", "'Smf\\Menu\\Renderer\\IRenderer'", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Renderer class '{$this->renderers[$name]}' is not subclass of Smf\\\\Menu\\\\Renderer\\\\IRenderer\"", ")", ";", "}", "$", "this", "->", "renderers", "[", "$", "name", "]", "=", "$", "renderer", ";", "}", "return", "$", "this", "->", "renderers", "[", "$", "name", "]", ";", "}" ]
Returns instance of the renderer @param string $name Name of the renderer @return IRenderer Renderer instance @throws InvalidArgumentException If the renderer with given name does not exist
[ "Returns", "instance", "of", "the", "renderer" ]
739e74fb664c1f018b4a74142bd28d20c004bac6
https://github.com/trunda/SmfMenu/blob/739e74fb664c1f018b4a74142bd28d20c004bac6/src/Smf/Menu/Renderer/Manager.php#L59-L84
21,771
digipolisgent/robo-digipolis-package
src/PackageProject.php
PackageProject.getFiles
protected function getFiles() { $this->mirrorDir(); $this->prepareMirrorDir(); $this->printTaskInfo('Retrieving files to package.'); $mirrorFinder = new Finder(); $mirrorFinder->ignoreDotFiles(false); $add = []; $mirrorFinder ->in($this->tmpDir) ->depth(0); foreach ($mirrorFinder as $file) { $add[substr($file->getRealPath(), strlen(realpath($this->tmpDir)) + 1)] = $file->getRealPath(); } return $add; }
php
protected function getFiles() { $this->mirrorDir(); $this->prepareMirrorDir(); $this->printTaskInfo('Retrieving files to package.'); $mirrorFinder = new Finder(); $mirrorFinder->ignoreDotFiles(false); $add = []; $mirrorFinder ->in($this->tmpDir) ->depth(0); foreach ($mirrorFinder as $file) { $add[substr($file->getRealPath(), strlen(realpath($this->tmpDir)) + 1)] = $file->getRealPath(); } return $add; }
[ "protected", "function", "getFiles", "(", ")", "{", "$", "this", "->", "mirrorDir", "(", ")", ";", "$", "this", "->", "prepareMirrorDir", "(", ")", ";", "$", "this", "->", "printTaskInfo", "(", "'Retrieving files to package.'", ")", ";", "$", "mirrorFinder", "=", "new", "Finder", "(", ")", ";", "$", "mirrorFinder", "->", "ignoreDotFiles", "(", "false", ")", ";", "$", "add", "=", "[", "]", ";", "$", "mirrorFinder", "->", "in", "(", "$", "this", "->", "tmpDir", ")", "->", "depth", "(", "0", ")", ";", "foreach", "(", "$", "mirrorFinder", "as", "$", "file", ")", "{", "$", "add", "[", "substr", "(", "$", "file", "->", "getRealPath", "(", ")", ",", "strlen", "(", "realpath", "(", "$", "this", "->", "tmpDir", ")", ")", "+", "1", ")", "]", "=", "$", "file", "->", "getRealPath", "(", ")", ";", "}", "return", "$", "add", ";", "}" ]
Get the files and directories to package. @return array The list of files and directories to package.
[ "Get", "the", "files", "and", "directories", "to", "package", "." ]
6f206f32d910992d27b2a1b4dda1c5e7d8259b75
https://github.com/digipolisgent/robo-digipolis-package/blob/6f206f32d910992d27b2a1b4dda1c5e7d8259b75/src/PackageProject.php#L117-L132
21,772
digipolisgent/robo-digipolis-package
src/PackageProject.php
PackageProject.mirrorDir
protected function mirrorDir() { if (!$this->useTmpDir) { $this->tmpDir = $this->dir; return; } $this->tmpDir = md5(time()); if (file_exists($this->tmpDir)) { $this->fs->remove($this->tmpDir); } $this->printTaskInfo(sprintf( 'Creating temporary directory %s.', $this->tmpDir )); $this->fs->mkdir($this->tmpDir); $tmpRealPath = realpath($this->tmpDir); $directoryIterator = new \RecursiveDirectoryIterator($this->dir, \RecursiveDirectoryIterator::SKIP_DOTS); $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST); $filterIterator = new \CallbackFilterIterator( $recursiveIterator, function ($current) use ($tmpRealPath) { return strpos($current->getRealPath(), $tmpRealPath) !== 0; } ); $this->printTaskInfo(sprintf( 'Mirroring directory %s to temporary directory %s.', $this->dir, $tmpRealPath )); foreach ($filterIterator as $item) { if (strpos($item->getRealPath(), $tmpRealPath) === 0) { continue; } if (is_link($item)) { if ($item->getRealPath() !== false) { $this->fs->symlink( $item->getLinkTarget(), $this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName() ); } continue; } if ($item->isDir()) { $this->fs->mkdir($this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName()); continue; } $this->fs->copy($item, $this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName()); } }
php
protected function mirrorDir() { if (!$this->useTmpDir) { $this->tmpDir = $this->dir; return; } $this->tmpDir = md5(time()); if (file_exists($this->tmpDir)) { $this->fs->remove($this->tmpDir); } $this->printTaskInfo(sprintf( 'Creating temporary directory %s.', $this->tmpDir )); $this->fs->mkdir($this->tmpDir); $tmpRealPath = realpath($this->tmpDir); $directoryIterator = new \RecursiveDirectoryIterator($this->dir, \RecursiveDirectoryIterator::SKIP_DOTS); $recursiveIterator = new \RecursiveIteratorIterator($directoryIterator, \RecursiveIteratorIterator::SELF_FIRST); $filterIterator = new \CallbackFilterIterator( $recursiveIterator, function ($current) use ($tmpRealPath) { return strpos($current->getRealPath(), $tmpRealPath) !== 0; } ); $this->printTaskInfo(sprintf( 'Mirroring directory %s to temporary directory %s.', $this->dir, $tmpRealPath )); foreach ($filterIterator as $item) { if (strpos($item->getRealPath(), $tmpRealPath) === 0) { continue; } if (is_link($item)) { if ($item->getRealPath() !== false) { $this->fs->symlink( $item->getLinkTarget(), $this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName() ); } continue; } if ($item->isDir()) { $this->fs->mkdir($this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName()); continue; } $this->fs->copy($item, $this->tmpDir . DIRECTORY_SEPARATOR . $filterIterator->getSubPathName()); } }
[ "protected", "function", "mirrorDir", "(", ")", "{", "if", "(", "!", "$", "this", "->", "useTmpDir", ")", "{", "$", "this", "->", "tmpDir", "=", "$", "this", "->", "dir", ";", "return", ";", "}", "$", "this", "->", "tmpDir", "=", "md5", "(", "time", "(", ")", ")", ";", "if", "(", "file_exists", "(", "$", "this", "->", "tmpDir", ")", ")", "{", "$", "this", "->", "fs", "->", "remove", "(", "$", "this", "->", "tmpDir", ")", ";", "}", "$", "this", "->", "printTaskInfo", "(", "sprintf", "(", "'Creating temporary directory %s.'", ",", "$", "this", "->", "tmpDir", ")", ")", ";", "$", "this", "->", "fs", "->", "mkdir", "(", "$", "this", "->", "tmpDir", ")", ";", "$", "tmpRealPath", "=", "realpath", "(", "$", "this", "->", "tmpDir", ")", ";", "$", "directoryIterator", "=", "new", "\\", "RecursiveDirectoryIterator", "(", "$", "this", "->", "dir", ",", "\\", "RecursiveDirectoryIterator", "::", "SKIP_DOTS", ")", ";", "$", "recursiveIterator", "=", "new", "\\", "RecursiveIteratorIterator", "(", "$", "directoryIterator", ",", "\\", "RecursiveIteratorIterator", "::", "SELF_FIRST", ")", ";", "$", "filterIterator", "=", "new", "\\", "CallbackFilterIterator", "(", "$", "recursiveIterator", ",", "function", "(", "$", "current", ")", "use", "(", "$", "tmpRealPath", ")", "{", "return", "strpos", "(", "$", "current", "->", "getRealPath", "(", ")", ",", "$", "tmpRealPath", ")", "!==", "0", ";", "}", ")", ";", "$", "this", "->", "printTaskInfo", "(", "sprintf", "(", "'Mirroring directory %s to temporary directory %s.'", ",", "$", "this", "->", "dir", ",", "$", "tmpRealPath", ")", ")", ";", "foreach", "(", "$", "filterIterator", "as", "$", "item", ")", "{", "if", "(", "strpos", "(", "$", "item", "->", "getRealPath", "(", ")", ",", "$", "tmpRealPath", ")", "===", "0", ")", "{", "continue", ";", "}", "if", "(", "is_link", "(", "$", "item", ")", ")", "{", "if", "(", "$", "item", "->", "getRealPath", "(", ")", "!==", "false", ")", "{", "$", "this", "->", "fs", "->", "symlink", "(", "$", "item", "->", "getLinkTarget", "(", ")", ",", "$", "this", "->", "tmpDir", ".", "DIRECTORY_SEPARATOR", ".", "$", "filterIterator", "->", "getSubPathName", "(", ")", ")", ";", "}", "continue", ";", "}", "if", "(", "$", "item", "->", "isDir", "(", ")", ")", "{", "$", "this", "->", "fs", "->", "mkdir", "(", "$", "this", "->", "tmpDir", ".", "DIRECTORY_SEPARATOR", ".", "$", "filterIterator", "->", "getSubPathName", "(", ")", ")", ";", "continue", ";", "}", "$", "this", "->", "fs", "->", "copy", "(", "$", "item", ",", "$", "this", "->", "tmpDir", ".", "DIRECTORY_SEPARATOR", ".", "$", "filterIterator", "->", "getSubPathName", "(", ")", ")", ";", "}", "}" ]
Mirror the directory to a temp directory.
[ "Mirror", "the", "directory", "to", "a", "temp", "directory", "." ]
6f206f32d910992d27b2a1b4dda1c5e7d8259b75
https://github.com/digipolisgent/robo-digipolis-package/blob/6f206f32d910992d27b2a1b4dda1c5e7d8259b75/src/PackageProject.php#L137-L186
21,773
digipolisgent/robo-digipolis-package
src/PackageProject.php
PackageProject.prepareMirrorDir
protected function prepareMirrorDir() { $this->printTaskInfo(sprintf('Preparing directory %s.', $this->tmpDir)); if (empty($this->ignoreFileNames)) { return; } $files = new Finder(); $files->in($this->tmpDir); $files->ignoreDotFiles(false); $files->files(); // Ignore files defined by the dev. foreach ($this->ignoreFileNames as $fileName) { $files->name($fileName); } $this->fs->remove($files); }
php
protected function prepareMirrorDir() { $this->printTaskInfo(sprintf('Preparing directory %s.', $this->tmpDir)); if (empty($this->ignoreFileNames)) { return; } $files = new Finder(); $files->in($this->tmpDir); $files->ignoreDotFiles(false); $files->files(); // Ignore files defined by the dev. foreach ($this->ignoreFileNames as $fileName) { $files->name($fileName); } $this->fs->remove($files); }
[ "protected", "function", "prepareMirrorDir", "(", ")", "{", "$", "this", "->", "printTaskInfo", "(", "sprintf", "(", "'Preparing directory %s.'", ",", "$", "this", "->", "tmpDir", ")", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "ignoreFileNames", ")", ")", "{", "return", ";", "}", "$", "files", "=", "new", "Finder", "(", ")", ";", "$", "files", "->", "in", "(", "$", "this", "->", "tmpDir", ")", ";", "$", "files", "->", "ignoreDotFiles", "(", "false", ")", ";", "$", "files", "->", "files", "(", ")", ";", "// Ignore files defined by the dev.", "foreach", "(", "$", "this", "->", "ignoreFileNames", "as", "$", "fileName", ")", "{", "$", "files", "->", "name", "(", "$", "fileName", ")", ";", "}", "$", "this", "->", "fs", "->", "remove", "(", "$", "files", ")", ";", "}" ]
Removes files that should not be packaged from the mirrored directory.
[ "Removes", "files", "that", "should", "not", "be", "packaged", "from", "the", "mirrored", "directory", "." ]
6f206f32d910992d27b2a1b4dda1c5e7d8259b75
https://github.com/digipolisgent/robo-digipolis-package/blob/6f206f32d910992d27b2a1b4dda1c5e7d8259b75/src/PackageProject.php#L191-L207
21,774
inhere/php-librarys
src/Helpers/UtilHelper.php
UtilHelper.fd
public static function fd($object, $type = 'log') { $types = array('log', 'debug', 'info', 'warn', 'error', 'assert'); if (!\in_array($type, $types, true)) { $type = 'log'; } $data = json_encode($object); echo '<script type="text/javascript">console.' . $type . '(' . $data . ');</script>'; }
php
public static function fd($object, $type = 'log') { $types = array('log', 'debug', 'info', 'warn', 'error', 'assert'); if (!\in_array($type, $types, true)) { $type = 'log'; } $data = json_encode($object); echo '<script type="text/javascript">console.' . $type . '(' . $data . ');</script>'; }
[ "public", "static", "function", "fd", "(", "$", "object", ",", "$", "type", "=", "'log'", ")", "{", "$", "types", "=", "array", "(", "'log'", ",", "'debug'", ",", "'info'", ",", "'warn'", ",", "'error'", ",", "'assert'", ")", ";", "if", "(", "!", "\\", "in_array", "(", "$", "type", ",", "$", "types", ",", "true", ")", ")", "{", "$", "type", "=", "'log'", ";", "}", "$", "data", "=", "json_encode", "(", "$", "object", ")", ";", "echo", "'<script type=\"text/javascript\">console.'", ".", "$", "type", ".", "'('", ".", "$", "data", ".", "');</script>'", ";", "}" ]
Display a var dump in firebug console @param mixed $object Object to display @param string $type
[ "Display", "a", "var", "dump", "in", "firebug", "console" ]
e6ca598685469794f310e3ab0e2bc19519cd0ae6
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/UtilHelper.php#L16-L27
21,775
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.parse
public function parse() { $p = 0; do { $p = $this->scanner->position(); $this->consumeData(); // FIXME: Add infinite loop protection. } while ($this->carryOn); }
php
public function parse() { $p = 0; do { $p = $this->scanner->position(); $this->consumeData(); // FIXME: Add infinite loop protection. } while ($this->carryOn); }
[ "public", "function", "parse", "(", ")", "{", "$", "p", "=", "0", ";", "do", "{", "$", "p", "=", "$", "this", "->", "scanner", "->", "position", "(", ")", ";", "$", "this", "->", "consumeData", "(", ")", ";", "// FIXME: Add infinite loop protection.", "}", "while", "(", "$", "this", "->", "carryOn", ")", ";", "}" ]
Begin parsing. This will begin scanning the document, tokenizing as it goes. Tokens are emitted into the event handler. Tokenizing will continue until the document is completely read. Errors are emitted into the event handler, but the parser will attempt to continue parsing until the entire input stream is read.
[ "Begin", "parsing", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L154-L162
21,776
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.setTextMode
public function setTextMode($textmode, $untilTag = null) { $this->textMode = $textmode & (HTML5_Elements::TEXT_RAW | HTML5_Elements::TEXT_RCDATA); $this->untilTag = $untilTag; }
php
public function setTextMode($textmode, $untilTag = null) { $this->textMode = $textmode & (HTML5_Elements::TEXT_RAW | HTML5_Elements::TEXT_RCDATA); $this->untilTag = $untilTag; }
[ "public", "function", "setTextMode", "(", "$", "textmode", ",", "$", "untilTag", "=", "null", ")", "{", "$", "this", "->", "textMode", "=", "$", "textmode", "&", "(", "HTML5_Elements", "::", "TEXT_RAW", "|", "HTML5_Elements", "::", "TEXT_RCDATA", ")", ";", "$", "this", "->", "untilTag", "=", "$", "untilTag", ";", "}" ]
Set the text mode for the character data reader. HTML5 defines three different modes for reading text: - Normal: Read until a tag is encountered. - RCDATA: Read until a tag is encountered, but skip a few otherwise- special characters. - Raw: Read until a special closing tag is encountered (viz. pre, script) This allows those modes to be set. Normally, setting is done by the event handler via a special return code on startTag(), but it can also be set manually using this function. @param integer $textmode One of HTML5_Elements::TEXT_* @param string $untilTag The tag that should stop RAW or RCDATA mode. Normal mode does not use this indicator.
[ "Set", "the", "text", "mode", "for", "the", "character", "data", "reader", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L184-L187
21,777
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.consumeData
protected function consumeData() { // Character Ref /* * $this->characterReference() || $this->tagOpen() || $this->eof() || $this->characterData(); */ $this->characterReference(); $this->tagOpen(); $this->eof(); $this->characterData(); return $this->carryOn; }
php
protected function consumeData() { // Character Ref /* * $this->characterReference() || $this->tagOpen() || $this->eof() || $this->characterData(); */ $this->characterReference(); $this->tagOpen(); $this->eof(); $this->characterData(); return $this->carryOn; }
[ "protected", "function", "consumeData", "(", ")", "{", "// Character Ref", "/*\n * $this->characterReference() || $this->tagOpen() || $this->eof() || $this->characterData();\n */", "$", "this", "->", "characterReference", "(", ")", ";", "$", "this", "->", "tagOpen", "(", ")", ";", "$", "this", "->", "eof", "(", ")", ";", "$", "this", "->", "characterData", "(", ")", ";", "return", "$", "this", "->", "carryOn", ";", "}" ]
Consume a character and make a move. HTML5 8.2.4.1
[ "Consume", "a", "character", "and", "make", "a", "move", ".", "HTML5", "8", ".", "2", ".", "4", ".", "1" ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L193-L204
21,778
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.characterData
protected function characterData() { if ($this->scanner->current() === false) { return false; } switch ($this->textMode) { case HTML5_Elements::TEXT_RAW: return $this->rawText(); case HTML5_Elements::TEXT_RCDATA: return $this->rcdata(); default: $tok = $this->scanner->current(); if (strspn($tok, "<&")) { return false; } return $this->text(); } }
php
protected function characterData() { if ($this->scanner->current() === false) { return false; } switch ($this->textMode) { case HTML5_Elements::TEXT_RAW: return $this->rawText(); case HTML5_Elements::TEXT_RCDATA: return $this->rcdata(); default: $tok = $this->scanner->current(); if (strspn($tok, "<&")) { return false; } return $this->text(); } }
[ "protected", "function", "characterData", "(", ")", "{", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "===", "false", ")", "{", "return", "false", ";", "}", "switch", "(", "$", "this", "->", "textMode", ")", "{", "case", "HTML5_Elements", "::", "TEXT_RAW", ":", "return", "$", "this", "->", "rawText", "(", ")", ";", "case", "HTML5_Elements", "::", "TEXT_RCDATA", ":", "return", "$", "this", "->", "rcdata", "(", ")", ";", "default", ":", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "if", "(", "strspn", "(", "$", "tok", ",", "\"<&\"", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "text", "(", ")", ";", "}", "}" ]
Parse anything that looks like character data. Different rules apply based on the current text mode. @see HTML5_Elements::TEXT_RAW HTML5_Elements::TEXT_RCDATA.
[ "Parse", "anything", "that", "looks", "like", "character", "data", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L213-L229
21,779
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.text
protected function text() { $tok = $this->scanner->current(); // This should never happen... if ($tok === false) { return false; } // Null if ($tok === "\00") { $this->parseError("Received null character."); } // fprintf(STDOUT, "Writing '%s'", $tok); $this->buffer($tok); $this->scanner->next(); return true; }
php
protected function text() { $tok = $this->scanner->current(); // This should never happen... if ($tok === false) { return false; } // Null if ($tok === "\00") { $this->parseError("Received null character."); } // fprintf(STDOUT, "Writing '%s'", $tok); $this->buffer($tok); $this->scanner->next(); return true; }
[ "protected", "function", "text", "(", ")", "{", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "// This should never happen...", "if", "(", "$", "tok", "===", "false", ")", "{", "return", "false", ";", "}", "// Null", "if", "(", "$", "tok", "===", "\"\\00\"", ")", "{", "$", "this", "->", "parseError", "(", "\"Received null character.\"", ")", ";", "}", "// fprintf(STDOUT, \"Writing '%s'\", $tok);", "$", "this", "->", "buffer", "(", "$", "tok", ")", ";", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "return", "true", ";", "}" ]
This buffers the current token as character data.
[ "This", "buffers", "the", "current", "token", "as", "character", "data", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L234-L249
21,780
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.rawText
protected function rawText() { if (is_null($this->untilTag)) { return $this->text(); } $sequence = '</' . $this->untilTag . '>'; $txt = $this->readUntilSequence($sequence); $this->events->text($txt); $this->setTextMode(0); return $this->endTag(); }
php
protected function rawText() { if (is_null($this->untilTag)) { return $this->text(); } $sequence = '</' . $this->untilTag . '>'; $txt = $this->readUntilSequence($sequence); $this->events->text($txt); $this->setTextMode(0); return $this->endTag(); }
[ "protected", "function", "rawText", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "untilTag", ")", ")", "{", "return", "$", "this", "->", "text", "(", ")", ";", "}", "$", "sequence", "=", "'</'", ".", "$", "this", "->", "untilTag", ".", "'>'", ";", "$", "txt", "=", "$", "this", "->", "readUntilSequence", "(", "$", "sequence", ")", ";", "$", "this", "->", "events", "->", "text", "(", "$", "txt", ")", ";", "$", "this", "->", "setTextMode", "(", "0", ")", ";", "return", "$", "this", "->", "endTag", "(", ")", ";", "}" ]
Read text in RAW mode.
[ "Read", "text", "in", "RAW", "mode", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L254-L263
21,781
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.rcdata
protected function rcdata() { if (is_null($this->untilTag)) { return $this->text(); } $sequence = '</' . $this->untilTag . '>'; $txt = ''; $tok = $this->scanner->current(); while ($tok !== false && !($tok == '<' && ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))))) { if ($tok == '&') { $txt .= $this->decodeCharacterReference(); $tok = $this->scanner->current(); } else { $txt .= $tok; $tok = $this->scanner->next(); } } $this->events->text($txt); $this->setTextMode(0); return $this->endTag(); }
php
protected function rcdata() { if (is_null($this->untilTag)) { return $this->text(); } $sequence = '</' . $this->untilTag . '>'; $txt = ''; $tok = $this->scanner->current(); while ($tok !== false && !($tok == '<' && ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))))) { if ($tok == '&') { $txt .= $this->decodeCharacterReference(); $tok = $this->scanner->current(); } else { $txt .= $tok; $tok = $this->scanner->next(); } } $this->events->text($txt); $this->setTextMode(0); return $this->endTag(); }
[ "protected", "function", "rcdata", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "untilTag", ")", ")", "{", "return", "$", "this", "->", "text", "(", ")", ";", "}", "$", "sequence", "=", "'</'", ".", "$", "this", "->", "untilTag", ".", "'>'", ";", "$", "txt", "=", "''", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "while", "(", "$", "tok", "!==", "false", "&&", "!", "(", "$", "tok", "==", "'<'", "&&", "(", "$", "this", "->", "sequenceMatches", "(", "$", "sequence", ")", "||", "$", "this", "->", "sequenceMatches", "(", "strtoupper", "(", "$", "sequence", ")", ")", ")", ")", ")", "{", "if", "(", "$", "tok", "==", "'&'", ")", "{", "$", "txt", ".=", "$", "this", "->", "decodeCharacterReference", "(", ")", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "}", "else", "{", "$", "txt", ".=", "$", "tok", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "}", "}", "$", "this", "->", "events", "->", "text", "(", "$", "txt", ")", ";", "$", "this", "->", "setTextMode", "(", "0", ")", ";", "return", "$", "this", "->", "endTag", "(", ")", ";", "}" ]
Read text in RCDATA mode.
[ "Read", "text", "in", "RCDATA", "mode", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L268-L287
21,782
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.eof
protected function eof() { if ($this->scanner->current() === false) { // fprintf(STDOUT, "EOF"); $this->flushBuffer(); $this->events->eof(); $this->carryOn = false; return true; } return false; }
php
protected function eof() { if ($this->scanner->current() === false) { // fprintf(STDOUT, "EOF"); $this->flushBuffer(); $this->events->eof(); $this->carryOn = false; return true; } return false; }
[ "protected", "function", "eof", "(", ")", "{", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "===", "false", ")", "{", "// fprintf(STDOUT, \"EOF\");", "$", "this", "->", "flushBuffer", "(", ")", ";", "$", "this", "->", "events", "->", "eof", "(", ")", ";", "$", "this", "->", "carryOn", "=", "false", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
If the document is read, emit an EOF event.
[ "If", "the", "document", "is", "read", "emit", "an", "EOF", "event", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L292-L301
21,783
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.tagOpen
protected function tagOpen() { if ($this->scanner->current() != '<') { return false; } // Any buffered text data can go out now. $this->flushBuffer(); $this->scanner->next(); return $this->markupDeclaration() || $this->endTag() || $this->processingInstruction() || $this->tagName() || /* This always returns false. */ $this->parseError("Illegal tag opening") || $this->characterData(); }
php
protected function tagOpen() { if ($this->scanner->current() != '<') { return false; } // Any buffered text data can go out now. $this->flushBuffer(); $this->scanner->next(); return $this->markupDeclaration() || $this->endTag() || $this->processingInstruction() || $this->tagName() || /* This always returns false. */ $this->parseError("Illegal tag opening") || $this->characterData(); }
[ "protected", "function", "tagOpen", "(", ")", "{", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "!=", "'<'", ")", "{", "return", "false", ";", "}", "// Any buffered text data can go out now.", "$", "this", "->", "flushBuffer", "(", ")", ";", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "return", "$", "this", "->", "markupDeclaration", "(", ")", "||", "$", "this", "->", "endTag", "(", ")", "||", "$", "this", "->", "processingInstruction", "(", ")", "||", "$", "this", "->", "tagName", "(", ")", "||", "/* This always returns false. */", "$", "this", "->", "parseError", "(", "\"Illegal tag opening\"", ")", "||", "$", "this", "->", "characterData", "(", ")", ";", "}" ]
Emit a tagStart event on encountering a tag. 8.2.4.8
[ "Emit", "a", "tagStart", "event", "on", "encountering", "a", "tag", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L325-L338
21,784
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.markupDeclaration
protected function markupDeclaration() { if ($this->scanner->current() != '!') { return false; } $tok = $this->scanner->next(); // Comment: if ($tok == '-' && $this->scanner->peek() == '-') { $this->scanner->next(); // Consume the other '-' $this->scanner->next(); // Next char. return $this->comment(); } elseif ($tok == 'D' || $tok == 'd') { // Doctype return $this->doctype(''); } elseif ($tok == '[') { // CDATA section return $this->cdataSection(); } // FINISH $this->parseError("Expected <!--, <![CDATA[, or <!DOCTYPE. Got <!%s", $tok); $this->bogusComment('<!'); return true; }
php
protected function markupDeclaration() { if ($this->scanner->current() != '!') { return false; } $tok = $this->scanner->next(); // Comment: if ($tok == '-' && $this->scanner->peek() == '-') { $this->scanner->next(); // Consume the other '-' $this->scanner->next(); // Next char. return $this->comment(); } elseif ($tok == 'D' || $tok == 'd') { // Doctype return $this->doctype(''); } elseif ($tok == '[') { // CDATA section return $this->cdataSection(); } // FINISH $this->parseError("Expected <!--, <![CDATA[, or <!DOCTYPE. Got <!%s", $tok); $this->bogusComment('<!'); return true; }
[ "protected", "function", "markupDeclaration", "(", ")", "{", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "!=", "'!'", ")", "{", "return", "false", ";", "}", "$", "tok", "=", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "// Comment:", "if", "(", "$", "tok", "==", "'-'", "&&", "$", "this", "->", "scanner", "->", "peek", "(", ")", "==", "'-'", ")", "{", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "// Consume the other '-'", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "// Next char.", "return", "$", "this", "->", "comment", "(", ")", ";", "}", "elseif", "(", "$", "tok", "==", "'D'", "||", "$", "tok", "==", "'d'", ")", "{", "// Doctype", "return", "$", "this", "->", "doctype", "(", "''", ")", ";", "}", "elseif", "(", "$", "tok", "==", "'['", ")", "{", "// CDATA section", "return", "$", "this", "->", "cdataSection", "(", ")", ";", "}", "// FINISH", "$", "this", "->", "parseError", "(", "\"Expected <!--, <![CDATA[, or <!DOCTYPE. Got <!%s\"", ",", "$", "tok", ")", ";", "$", "this", "->", "bogusComment", "(", "'<!'", ")", ";", "return", "true", ";", "}" ]
Look for markup.
[ "Look", "for", "markup", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L343-L365
21,785
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.endTag
protected function endTag() { if ($this->scanner->current() != '/') { return false; } $tok = $this->scanner->next(); // a-zA-Z -> tagname // > -> parse error // EOF -> parse error // -> parse error if (!ctype_alpha($tok)) { $this->parseError("Expected tag name, got '%s'", $tok); if ($tok == "\0" || $tok === false) { return false; } return $this->bogusComment('</'); } $name = strtolower($this->scanner->charsUntil("\n\f \t>")); // Trash whitespace. $this->scanner->whitespace(); if ($this->scanner->current() != '>') { $this->parseError("Expected >, got '%s'", $this->scanner->current()); // We just trash stuff until we get to the next tag close. $this->scanner->charsUntil('>'); } $this->events->endTag($name); $this->scanner->next(); return true; }
php
protected function endTag() { if ($this->scanner->current() != '/') { return false; } $tok = $this->scanner->next(); // a-zA-Z -> tagname // > -> parse error // EOF -> parse error // -> parse error if (!ctype_alpha($tok)) { $this->parseError("Expected tag name, got '%s'", $tok); if ($tok == "\0" || $tok === false) { return false; } return $this->bogusComment('</'); } $name = strtolower($this->scanner->charsUntil("\n\f \t>")); // Trash whitespace. $this->scanner->whitespace(); if ($this->scanner->current() != '>') { $this->parseError("Expected >, got '%s'", $this->scanner->current()); // We just trash stuff until we get to the next tag close. $this->scanner->charsUntil('>'); } $this->events->endTag($name); $this->scanner->next(); return true; }
[ "protected", "function", "endTag", "(", ")", "{", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "!=", "'/'", ")", "{", "return", "false", ";", "}", "$", "tok", "=", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "// a-zA-Z -> tagname", "// > -> parse error", "// EOF -> parse error", "// -> parse error", "if", "(", "!", "ctype_alpha", "(", "$", "tok", ")", ")", "{", "$", "this", "->", "parseError", "(", "\"Expected tag name, got '%s'\"", ",", "$", "tok", ")", ";", "if", "(", "$", "tok", "==", "\"\\0\"", "||", "$", "tok", "===", "false", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "bogusComment", "(", "'</'", ")", ";", "}", "$", "name", "=", "strtolower", "(", "$", "this", "->", "scanner", "->", "charsUntil", "(", "\"\\n\\f \\t>\"", ")", ")", ";", "// Trash whitespace.", "$", "this", "->", "scanner", "->", "whitespace", "(", ")", ";", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "!=", "'>'", ")", "{", "$", "this", "->", "parseError", "(", "\"Expected >, got '%s'\"", ",", "$", "this", "->", "scanner", "->", "current", "(", ")", ")", ";", "// We just trash stuff until we get to the next tag close.", "$", "this", "->", "scanner", "->", "charsUntil", "(", "'>'", ")", ";", "}", "$", "this", "->", "events", "->", "endTag", "(", "$", "name", ")", ";", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "return", "true", ";", "}" ]
Consume an end tag. 8.2.4.9
[ "Consume", "an", "end", "tag", ".", "8", ".", "2", ".", "4", ".", "9" ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L371-L402
21,786
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.tagName
protected function tagName() { $tok = $this->scanner->current(); if (!ctype_alpha($tok)) { return false; } // We know this is at least one char. $name = strtolower($this->scanner->charsWhile(":_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); $attributes = array(); $selfClose = false; // Handle attribute parse exceptions here so that we can // react by trying to build a sensible parse tree. try { do { $this->scanner->whitespace(); $this->attribute($attributes); } while (!$this->isTagEnd($selfClose)); } catch (HTML5_Parser_Exception $e) { $selfClose = false; } $mode = $this->events->startTag($name, $attributes, $selfClose); // Should we do this? What does this buy that selfClose doesn't? if ($selfClose) { $this->events->endTag($name); } elseif (is_int($mode)) { // fprintf(STDOUT, "Event response says move into mode %d for tag %s", $mode, $name); $this->setTextMode($mode, $name); } $this->scanner->next(); return true; }
php
protected function tagName() { $tok = $this->scanner->current(); if (!ctype_alpha($tok)) { return false; } // We know this is at least one char. $name = strtolower($this->scanner->charsWhile(":_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")); $attributes = array(); $selfClose = false; // Handle attribute parse exceptions here so that we can // react by trying to build a sensible parse tree. try { do { $this->scanner->whitespace(); $this->attribute($attributes); } while (!$this->isTagEnd($selfClose)); } catch (HTML5_Parser_Exception $e) { $selfClose = false; } $mode = $this->events->startTag($name, $attributes, $selfClose); // Should we do this? What does this buy that selfClose doesn't? if ($selfClose) { $this->events->endTag($name); } elseif (is_int($mode)) { // fprintf(STDOUT, "Event response says move into mode %d for tag %s", $mode, $name); $this->setTextMode($mode, $name); } $this->scanner->next(); return true; }
[ "protected", "function", "tagName", "(", ")", "{", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "if", "(", "!", "ctype_alpha", "(", "$", "tok", ")", ")", "{", "return", "false", ";", "}", "// We know this is at least one char.", "$", "name", "=", "strtolower", "(", "$", "this", "->", "scanner", "->", "charsWhile", "(", "\":_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\"", ")", ")", ";", "$", "attributes", "=", "array", "(", ")", ";", "$", "selfClose", "=", "false", ";", "// Handle attribute parse exceptions here so that we can", "// react by trying to build a sensible parse tree.", "try", "{", "do", "{", "$", "this", "->", "scanner", "->", "whitespace", "(", ")", ";", "$", "this", "->", "attribute", "(", "$", "attributes", ")", ";", "}", "while", "(", "!", "$", "this", "->", "isTagEnd", "(", "$", "selfClose", ")", ")", ";", "}", "catch", "(", "HTML5_Parser_Exception", "$", "e", ")", "{", "$", "selfClose", "=", "false", ";", "}", "$", "mode", "=", "$", "this", "->", "events", "->", "startTag", "(", "$", "name", ",", "$", "attributes", ",", "$", "selfClose", ")", ";", "// Should we do this? What does this buy that selfClose doesn't?", "if", "(", "$", "selfClose", ")", "{", "$", "this", "->", "events", "->", "endTag", "(", "$", "name", ")", ";", "}", "elseif", "(", "is_int", "(", "$", "mode", ")", ")", "{", "// fprintf(STDOUT, \"Event response says move into mode %d for tag %s\", $mode, $name);", "$", "this", "->", "setTextMode", "(", "$", "mode", ",", "$", "name", ")", ";", "}", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "return", "true", ";", "}" ]
Consume a tag name and body. 8.2.4.10
[ "Consume", "a", "tag", "name", "and", "body", ".", "8", ".", "2", ".", "4", ".", "10" ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L408-L442
21,787
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.isTagEnd
protected function isTagEnd(&$selfClose) { $tok = $this->scanner->current(); if ($tok == '/') { $this->scanner->next(); $this->scanner->whitespace(); if ($this->scanner->current() == '>') { $selfClose = true; return true; } if ($this->scanner->current() === false) { $this->parseError("Unexpected EOF inside of tag."); return true; } // Basically, we skip the / token and go on. // See 8.2.4.43. $this->parseError("Unexpected '%s' inside of a tag.", $this->scanner->current()); return false; } if ($this->scanner->current() == '>') { return true; } if ($this->scanner->current() === false) { $this->parseError("Unexpected EOF inside of tag."); return true; } return false; }
php
protected function isTagEnd(&$selfClose) { $tok = $this->scanner->current(); if ($tok == '/') { $this->scanner->next(); $this->scanner->whitespace(); if ($this->scanner->current() == '>') { $selfClose = true; return true; } if ($this->scanner->current() === false) { $this->parseError("Unexpected EOF inside of tag."); return true; } // Basically, we skip the / token and go on. // See 8.2.4.43. $this->parseError("Unexpected '%s' inside of a tag.", $this->scanner->current()); return false; } if ($this->scanner->current() == '>') { return true; } if ($this->scanner->current() === false) { $this->parseError("Unexpected EOF inside of tag."); return true; } return false; }
[ "protected", "function", "isTagEnd", "(", "&", "$", "selfClose", ")", "{", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "if", "(", "$", "tok", "==", "'/'", ")", "{", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "$", "this", "->", "scanner", "->", "whitespace", "(", ")", ";", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "==", "'>'", ")", "{", "$", "selfClose", "=", "true", ";", "return", "true", ";", "}", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "===", "false", ")", "{", "$", "this", "->", "parseError", "(", "\"Unexpected EOF inside of tag.\"", ")", ";", "return", "true", ";", "}", "// Basically, we skip the / token and go on.", "// See 8.2.4.43.", "$", "this", "->", "parseError", "(", "\"Unexpected '%s' inside of a tag.\"", ",", "$", "this", "->", "scanner", "->", "current", "(", ")", ")", ";", "return", "false", ";", "}", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "==", "'>'", ")", "{", "return", "true", ";", "}", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "===", "false", ")", "{", "$", "this", "->", "parseError", "(", "\"Unexpected EOF inside of tag.\"", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if the scanner has reached the end of a tag.
[ "Check", "if", "the", "scanner", "has", "reached", "the", "end", "of", "a", "tag", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L447-L475
21,788
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.attribute
protected function attribute(&$attributes) { $tok = $this->scanner->current(); if ($tok == '/' || $tok == '>' || $tok === false) { return false; } if ($tok == '<') { $this->parseError("Unexepcted '<' inside of attributes list."); // Push the < back onto the stack. $this->scanner->unconsume(); // Let the caller figure out how to handle this. throw new HTML5_Parser_Exception("Start tag inside of attribute."); } $name = strtolower($this->scanner->charsUntil("/>=\n\f\t ")); if (strlen($name) == 0) { $this->parseError("Expected an attribute name, got %s.", $this->scanner->current()); // Really, only '=' can be the char here. Everything else gets absorbed // under one rule or another. $name = $this->scanner->current(); $this->scanner->next(); } $isValidAttribute = true; // Attribute names can contain most Unicode characters for HTML5. // But method "DOMElement::setAttribute" is throwing exception // because of it's own internal restriction so these have to be filtered. // see issue #23: https://github.com/Masterminds/html5-php/issues/23 // and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name if (preg_match("/[\x1-\x2C\\/\x3B-\x40\x5B-\x5E\x60\x7B-\x7F]/u", $name)) { $this->parseError("Unexpected characters in attribute name: %s", $name); $isValidAttribute = false; } // There is no limitation for 1st character in HTML5. // But method "DOMElement::setAttribute" is throwing exception for the // characters below so they have to be filtered. // see issue #23: https://github.com/Masterminds/html5-php/issues/23 // and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name else if (preg_match("/^[0-9.-]/u", $name)) { $this->parseError("Unexpected character at the begining of attribute name: %s", $name); $isValidAttribute = false; } // 8.1.2.3 $this->scanner->whitespace(); $val = $this->attributeValue(); if ($isValidAttribute) { $attributes[$name] = $val; } return true; }
php
protected function attribute(&$attributes) { $tok = $this->scanner->current(); if ($tok == '/' || $tok == '>' || $tok === false) { return false; } if ($tok == '<') { $this->parseError("Unexepcted '<' inside of attributes list."); // Push the < back onto the stack. $this->scanner->unconsume(); // Let the caller figure out how to handle this. throw new HTML5_Parser_Exception("Start tag inside of attribute."); } $name = strtolower($this->scanner->charsUntil("/>=\n\f\t ")); if (strlen($name) == 0) { $this->parseError("Expected an attribute name, got %s.", $this->scanner->current()); // Really, only '=' can be the char here. Everything else gets absorbed // under one rule or another. $name = $this->scanner->current(); $this->scanner->next(); } $isValidAttribute = true; // Attribute names can contain most Unicode characters for HTML5. // But method "DOMElement::setAttribute" is throwing exception // because of it's own internal restriction so these have to be filtered. // see issue #23: https://github.com/Masterminds/html5-php/issues/23 // and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name if (preg_match("/[\x1-\x2C\\/\x3B-\x40\x5B-\x5E\x60\x7B-\x7F]/u", $name)) { $this->parseError("Unexpected characters in attribute name: %s", $name); $isValidAttribute = false; } // There is no limitation for 1st character in HTML5. // But method "DOMElement::setAttribute" is throwing exception for the // characters below so they have to be filtered. // see issue #23: https://github.com/Masterminds/html5-php/issues/23 // and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name else if (preg_match("/^[0-9.-]/u", $name)) { $this->parseError("Unexpected character at the begining of attribute name: %s", $name); $isValidAttribute = false; } // 8.1.2.3 $this->scanner->whitespace(); $val = $this->attributeValue(); if ($isValidAttribute) { $attributes[$name] = $val; } return true; }
[ "protected", "function", "attribute", "(", "&", "$", "attributes", ")", "{", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "if", "(", "$", "tok", "==", "'/'", "||", "$", "tok", "==", "'>'", "||", "$", "tok", "===", "false", ")", "{", "return", "false", ";", "}", "if", "(", "$", "tok", "==", "'<'", ")", "{", "$", "this", "->", "parseError", "(", "\"Unexepcted '<' inside of attributes list.\"", ")", ";", "// Push the < back onto the stack.", "$", "this", "->", "scanner", "->", "unconsume", "(", ")", ";", "// Let the caller figure out how to handle this.", "throw", "new", "HTML5_Parser_Exception", "(", "\"Start tag inside of attribute.\"", ")", ";", "}", "$", "name", "=", "strtolower", "(", "$", "this", "->", "scanner", "->", "charsUntil", "(", "\"/>=\\n\\f\\t \"", ")", ")", ";", "if", "(", "strlen", "(", "$", "name", ")", "==", "0", ")", "{", "$", "this", "->", "parseError", "(", "\"Expected an attribute name, got %s.\"", ",", "$", "this", "->", "scanner", "->", "current", "(", ")", ")", ";", "// Really, only '=' can be the char here. Everything else gets absorbed", "// under one rule or another.", "$", "name", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "}", "$", "isValidAttribute", "=", "true", ";", "// Attribute names can contain most Unicode characters for HTML5.", "// But method \"DOMElement::setAttribute\" is throwing exception", "// because of it's own internal restriction so these have to be filtered.", "// see issue #23: https://github.com/Masterminds/html5-php/issues/23", "// and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name", "if", "(", "preg_match", "(", "\"/[\\x1-\\x2C\\\\/\\x3B-\\x40\\x5B-\\x5E\\x60\\x7B-\\x7F]/u\"", ",", "$", "name", ")", ")", "{", "$", "this", "->", "parseError", "(", "\"Unexpected characters in attribute name: %s\"", ",", "$", "name", ")", ";", "$", "isValidAttribute", "=", "false", ";", "}", "// There is no limitation for 1st character in HTML5.", "// But method \"DOMElement::setAttribute\" is throwing exception for the", "// characters below so they have to be filtered.", "// see issue #23: https://github.com/Masterminds/html5-php/issues/23", "// and http://www.w3.org/TR/2011/WD-html5-20110525/syntax.html#syntax-attribute-name", "else", "if", "(", "preg_match", "(", "\"/^[0-9.-]/u\"", ",", "$", "name", ")", ")", "{", "$", "this", "->", "parseError", "(", "\"Unexpected character at the begining of attribute name: %s\"", ",", "$", "name", ")", ";", "$", "isValidAttribute", "=", "false", ";", "}", "// 8.1.2.3", "$", "this", "->", "scanner", "->", "whitespace", "(", ")", ";", "$", "val", "=", "$", "this", "->", "attributeValue", "(", ")", ";", "if", "(", "$", "isValidAttribute", ")", "{", "$", "attributes", "[", "$", "name", "]", "=", "$", "val", ";", "}", "return", "true", ";", "}" ]
Parse attributes from inside of a tag.
[ "Parse", "attributes", "from", "inside", "of", "a", "tag", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L480-L531
21,789
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.attributeValue
protected function attributeValue() { if ($this->scanner->current() != '=') { return null; } $this->scanner->next(); // 8.1.2.3 $this->scanner->whitespace(); $tok = $this->scanner->current(); switch ($tok) { case "\n": case "\f": case " ": case "\t": // Whitespace here indicates an empty value. return null; case '"': case "'": $this->scanner->next(); return $this->quotedAttributeValue($tok); case '>': // case '/': // 8.2.4.37 seems to allow foo=/ as a valid attr. $this->parseError("Expected attribute value, got tag end."); return null; case '=': case '`': $this->parseError("Expecting quotes, got %s.", $tok); return $this->unquotedAttributeValue(); default: return $this->unquotedAttributeValue(); } }
php
protected function attributeValue() { if ($this->scanner->current() != '=') { return null; } $this->scanner->next(); // 8.1.2.3 $this->scanner->whitespace(); $tok = $this->scanner->current(); switch ($tok) { case "\n": case "\f": case " ": case "\t": // Whitespace here indicates an empty value. return null; case '"': case "'": $this->scanner->next(); return $this->quotedAttributeValue($tok); case '>': // case '/': // 8.2.4.37 seems to allow foo=/ as a valid attr. $this->parseError("Expected attribute value, got tag end."); return null; case '=': case '`': $this->parseError("Expecting quotes, got %s.", $tok); return $this->unquotedAttributeValue(); default: return $this->unquotedAttributeValue(); } }
[ "protected", "function", "attributeValue", "(", ")", "{", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "!=", "'='", ")", "{", "return", "null", ";", "}", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "// 8.1.2.3", "$", "this", "->", "scanner", "->", "whitespace", "(", ")", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "switch", "(", "$", "tok", ")", "{", "case", "\"\\n\"", ":", "case", "\"\\f\"", ":", "case", "\" \"", ":", "case", "\"\\t\"", ":", "// Whitespace here indicates an empty value.", "return", "null", ";", "case", "'\"'", ":", "case", "\"'\"", ":", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "return", "$", "this", "->", "quotedAttributeValue", "(", "$", "tok", ")", ";", "case", "'>'", ":", "// case '/': // 8.2.4.37 seems to allow foo=/ as a valid attr.", "$", "this", "->", "parseError", "(", "\"Expected attribute value, got tag end.\"", ")", ";", "return", "null", ";", "case", "'='", ":", "case", "'`'", ":", "$", "this", "->", "parseError", "(", "\"Expecting quotes, got %s.\"", ",", "$", "tok", ")", ";", "return", "$", "this", "->", "unquotedAttributeValue", "(", ")", ";", "default", ":", "return", "$", "this", "->", "unquotedAttributeValue", "(", ")", ";", "}", "}" ]
Consume an attribute value. 8.2.4.37 and after.
[ "Consume", "an", "attribute", "value", ".", "8", ".", "2", ".", "4", ".", "37", "and", "after", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L537-L568
21,790
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.quotedAttributeValue
protected function quotedAttributeValue($quote) { $stoplist = "\f" . $quote; $val = ''; $tok = $this->scanner->current(); while (strspn($tok, $stoplist) == 0 && $tok !== false) { if ($tok == '&') { $val .= $this->decodeCharacterReference(true); $tok = $this->scanner->current(); } else { $val .= $tok; $tok = $this->scanner->next(); } } $this->scanner->next(); return $val; }
php
protected function quotedAttributeValue($quote) { $stoplist = "\f" . $quote; $val = ''; $tok = $this->scanner->current(); while (strspn($tok, $stoplist) == 0 && $tok !== false) { if ($tok == '&') { $val .= $this->decodeCharacterReference(true); $tok = $this->scanner->current(); } else { $val .= $tok; $tok = $this->scanner->next(); } } $this->scanner->next(); return $val; }
[ "protected", "function", "quotedAttributeValue", "(", "$", "quote", ")", "{", "$", "stoplist", "=", "\"\\f\"", ".", "$", "quote", ";", "$", "val", "=", "''", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "while", "(", "strspn", "(", "$", "tok", ",", "$", "stoplist", ")", "==", "0", "&&", "$", "tok", "!==", "false", ")", "{", "if", "(", "$", "tok", "==", "'&'", ")", "{", "$", "val", ".=", "$", "this", "->", "decodeCharacterReference", "(", "true", ")", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "}", "else", "{", "$", "val", ".=", "$", "tok", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "}", "}", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "return", "$", "val", ";", "}" ]
Get an attribute value string. @param string $quote IMPORTANT: This is a series of chars! Any one of which will be considered termination of an attribute's value. E.g. "\"'" will stop at either ' or ". @return string The attribute value.
[ "Get", "an", "attribute", "value", "string", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L579-L594
21,791
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.bogusComment
protected function bogusComment($leading = '') { // TODO: This can be done more efficiently when the // scanner exposes a readUntil() method. $comment = $leading; $tok = $this->scanner->current(); do { $comment .= $tok; $tok = $this->scanner->next(); } while ($tok !== false && $tok != '>'); $this->flushBuffer(); $this->events->comment($comment . $tok); $this->scanner->next(); return true; }
php
protected function bogusComment($leading = '') { // TODO: This can be done more efficiently when the // scanner exposes a readUntil() method. $comment = $leading; $tok = $this->scanner->current(); do { $comment .= $tok; $tok = $this->scanner->next(); } while ($tok !== false && $tok != '>'); $this->flushBuffer(); $this->events->comment($comment . $tok); $this->scanner->next(); return true; }
[ "protected", "function", "bogusComment", "(", "$", "leading", "=", "''", ")", "{", "// TODO: This can be done more efficiently when the", "// scanner exposes a readUntil() method.", "$", "comment", "=", "$", "leading", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "do", "{", "$", "comment", ".=", "$", "tok", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "}", "while", "(", "$", "tok", "!==", "false", "&&", "$", "tok", "!=", "'>'", ")", ";", "$", "this", "->", "flushBuffer", "(", ")", ";", "$", "this", "->", "events", "->", "comment", "(", "$", "comment", ".", "$", "tok", ")", ";", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "return", "true", ";", "}" ]
Consume malformed markup as if it were a comment. 8.2.4.44 The spec requires that the ENTIRE tag-like thing be enclosed inside of the comment. So this will generate comments like: &lt;!--&lt/+foo&gt;--&gt; @param string $leading Prepend any leading characters. This essentially negates the need to backtrack, but it's sort of a hack.
[ "Consume", "malformed", "markup", "as", "if", "it", "were", "a", "comment", ".", "8", ".", "2", ".", "4", ".", "44" ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L629-L645
21,792
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.comment
protected function comment() { $tok = $this->scanner->current(); $comment = ''; // <!-->. Emit an empty comment because 8.2.4.46 says to. if ($tok == '>') { // Parse error. Emit the comment token. $this->parseError("Expected comment data, got '>'"); $this->events->comment(''); $this->scanner->next(); return true; } // Replace NULL with the replacement char. if ($tok == "\0") { $tok = HTML5_Parser_UTF8Utils::FFFD; } while (!$this->isCommentEnd()) { $comment .= $tok; $tok = $this->scanner->next(); } $this->events->comment($comment); $this->scanner->next(); return true; }
php
protected function comment() { $tok = $this->scanner->current(); $comment = ''; // <!-->. Emit an empty comment because 8.2.4.46 says to. if ($tok == '>') { // Parse error. Emit the comment token. $this->parseError("Expected comment data, got '>'"); $this->events->comment(''); $this->scanner->next(); return true; } // Replace NULL with the replacement char. if ($tok == "\0") { $tok = HTML5_Parser_UTF8Utils::FFFD; } while (!$this->isCommentEnd()) { $comment .= $tok; $tok = $this->scanner->next(); } $this->events->comment($comment); $this->scanner->next(); return true; }
[ "protected", "function", "comment", "(", ")", "{", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "$", "comment", "=", "''", ";", "// <!-->. Emit an empty comment because 8.2.4.46 says to.", "if", "(", "$", "tok", "==", "'>'", ")", "{", "// Parse error. Emit the comment token.", "$", "this", "->", "parseError", "(", "\"Expected comment data, got '>'\"", ")", ";", "$", "this", "->", "events", "->", "comment", "(", "''", ")", ";", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "return", "true", ";", "}", "// Replace NULL with the replacement char.", "if", "(", "$", "tok", "==", "\"\\0\"", ")", "{", "$", "tok", "=", "HTML5_Parser_UTF8Utils", "::", "FFFD", ";", "}", "while", "(", "!", "$", "this", "->", "isCommentEnd", "(", ")", ")", "{", "$", "comment", ".=", "$", "tok", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "}", "$", "this", "->", "events", "->", "comment", "(", "$", "comment", ")", ";", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "return", "true", ";", "}" ]
Read a comment. Expects the first tok to be inside of the comment.
[ "Read", "a", "comment", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L652-L677
21,793
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.isCommentEnd
protected function isCommentEnd() { // EOF if ($this->scanner->current() === false) { // Hit the end. $this->parseError("Unexpected EOF in a comment."); return true; } // If it doesn't start with -, not the end. if ($this->scanner->current() != '-') { return false; } // Advance one, and test for '->' if ($this->scanner->next() == '-' && $this->scanner->peek() == '>') { $this->scanner->next(); // Consume the last '>' return true; } // Unread '-'; $this->scanner->unconsume(1); return false; }
php
protected function isCommentEnd() { // EOF if ($this->scanner->current() === false) { // Hit the end. $this->parseError("Unexpected EOF in a comment."); return true; } // If it doesn't start with -, not the end. if ($this->scanner->current() != '-') { return false; } // Advance one, and test for '->' if ($this->scanner->next() == '-' && $this->scanner->peek() == '>') { $this->scanner->next(); // Consume the last '>' return true; } // Unread '-'; $this->scanner->unconsume(1); return false; }
[ "protected", "function", "isCommentEnd", "(", ")", "{", "// EOF", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "===", "false", ")", "{", "// Hit the end.", "$", "this", "->", "parseError", "(", "\"Unexpected EOF in a comment.\"", ")", ";", "return", "true", ";", "}", "// If it doesn't start with -, not the end.", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "!=", "'-'", ")", "{", "return", "false", ";", "}", "// Advance one, and test for '->'", "if", "(", "$", "this", "->", "scanner", "->", "next", "(", ")", "==", "'-'", "&&", "$", "this", "->", "scanner", "->", "peek", "(", ")", "==", "'>'", ")", "{", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "// Consume the last '>'", "return", "true", ";", "}", "// Unread '-';", "$", "this", "->", "scanner", "->", "unconsume", "(", "1", ")", ";", "return", "false", ";", "}" ]
Check if the scanner has reached the end of a comment.
[ "Check", "if", "the", "scanner", "has", "reached", "the", "end", "of", "a", "comment", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L682-L703
21,794
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.quotedString
protected function quotedString($stopchars) { $tok = $this->scanner->current(); if ($tok == '"' || $tok == "'") { $this->scanner->next(); $ret = $this->scanner->charsUntil($tok . $stopchars); if ($this->scanner->current() == $tok) { $this->scanner->next(); } else { // Parse error because no close quote. $this->parseError("Expected %s, got %s", $tok, $this->scanner->current()); } return $ret; } return false; }
php
protected function quotedString($stopchars) { $tok = $this->scanner->current(); if ($tok == '"' || $tok == "'") { $this->scanner->next(); $ret = $this->scanner->charsUntil($tok . $stopchars); if ($this->scanner->current() == $tok) { $this->scanner->next(); } else { // Parse error because no close quote. $this->parseError("Expected %s, got %s", $tok, $this->scanner->current()); } return $ret; } return false; }
[ "protected", "function", "quotedString", "(", "$", "stopchars", ")", "{", "$", "tok", "=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "if", "(", "$", "tok", "==", "'\"'", "||", "$", "tok", "==", "\"'\"", ")", "{", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "$", "ret", "=", "$", "this", "->", "scanner", "->", "charsUntil", "(", "$", "tok", ".", "$", "stopchars", ")", ";", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "==", "$", "tok", ")", "{", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "}", "else", "{", "// Parse error because no close quote.", "$", "this", "->", "parseError", "(", "\"Expected %s, got %s\"", ",", "$", "tok", ",", "$", "this", "->", "scanner", "->", "current", "(", ")", ")", ";", "}", "return", "$", "ret", ";", "}", "return", "false", ";", "}" ]
Utility for reading a quoted string. @param string $stopchars Characters (in addition to a close-quote) that should stop the string. E.g. sometimes '>' is higher precedence than '"' or "'". @return mixed String if one is found (quotations omitted)
[ "Utility", "for", "reading", "a", "quoted", "string", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L827-L841
21,795
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.cdataSection
protected function cdataSection() { if ($this->scanner->current() != '[') { return false; } $cdata = ''; $this->scanner->next(); $chars = $this->scanner->charsWhile('CDAT'); if ($chars != 'CDATA' || $this->scanner->current() != '[') { $this->parseError('Expected [CDATA[, got %s', $chars); return $this->bogusComment('<![' . $chars); } $tok = $this->scanner->next(); do { if ($tok === false) { $this->parseError('Unexpected EOF inside CDATA.'); $this->bogusComment('<![CDATA[' . $cdata); return true; } $cdata .= $tok; $tok = $this->scanner->next(); } while (!$this->sequenceMatches(']]>')); // Consume ]]> $this->scanner->consume(3); $this->events->cdata($cdata); return true; }
php
protected function cdataSection() { if ($this->scanner->current() != '[') { return false; } $cdata = ''; $this->scanner->next(); $chars = $this->scanner->charsWhile('CDAT'); if ($chars != 'CDATA' || $this->scanner->current() != '[') { $this->parseError('Expected [CDATA[, got %s', $chars); return $this->bogusComment('<![' . $chars); } $tok = $this->scanner->next(); do { if ($tok === false) { $this->parseError('Unexpected EOF inside CDATA.'); $this->bogusComment('<![CDATA[' . $cdata); return true; } $cdata .= $tok; $tok = $this->scanner->next(); } while (!$this->sequenceMatches(']]>')); // Consume ]]> $this->scanner->consume(3); $this->events->cdata($cdata); return true; }
[ "protected", "function", "cdataSection", "(", ")", "{", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "!=", "'['", ")", "{", "return", "false", ";", "}", "$", "cdata", "=", "''", ";", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "$", "chars", "=", "$", "this", "->", "scanner", "->", "charsWhile", "(", "'CDAT'", ")", ";", "if", "(", "$", "chars", "!=", "'CDATA'", "||", "$", "this", "->", "scanner", "->", "current", "(", ")", "!=", "'['", ")", "{", "$", "this", "->", "parseError", "(", "'Expected [CDATA[, got %s'", ",", "$", "chars", ")", ";", "return", "$", "this", "->", "bogusComment", "(", "'<!['", ".", "$", "chars", ")", ";", "}", "$", "tok", "=", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "do", "{", "if", "(", "$", "tok", "===", "false", ")", "{", "$", "this", "->", "parseError", "(", "'Unexpected EOF inside CDATA.'", ")", ";", "$", "this", "->", "bogusComment", "(", "'<![CDATA['", ".", "$", "cdata", ")", ";", "return", "true", ";", "}", "$", "cdata", ".=", "$", "tok", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "}", "while", "(", "!", "$", "this", "->", "sequenceMatches", "(", "']]>'", ")", ")", ";", "// Consume ]]>", "$", "this", "->", "scanner", "->", "consume", "(", "3", ")", ";", "$", "this", "->", "events", "->", "cdata", "(", "$", "cdata", ")", ";", "return", "true", ";", "}" ]
Handle a CDATA section.
[ "Handle", "a", "CDATA", "section", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L846-L875
21,796
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.processingInstruction
protected function processingInstruction() { if ($this->scanner->current() != '?') { return false; } $tok = $this->scanner->next(); $procName = $this->scanner->getAsciiAlpha(); $white = strlen($this->scanner->whitespace()); // If not a PI, send to bogusComment. if (strlen($procName) == 0 || $white == 0 || $this->scanner->current() == false) { $this->parseError("Expected processing instruction name, got $tok"); $this->bogusComment('<?' . $tok . $procName); return true; } $data = ''; // As long as it's not the case that the next two chars are ? and >. while (!($this->scanner->current() == '?' && $this->scanner->peek() == '>')) { $data .= $this->scanner->current(); $tok = $this->scanner->next(); if ($tok === false) { $this->parseError("Unexpected EOF in processing instruction."); $this->events->processingInstruction($procName, $data); return true; } } $this->scanner->next(); // > $this->scanner->next(); // Next token. $this->events->processingInstruction($procName, $data); return true; }
php
protected function processingInstruction() { if ($this->scanner->current() != '?') { return false; } $tok = $this->scanner->next(); $procName = $this->scanner->getAsciiAlpha(); $white = strlen($this->scanner->whitespace()); // If not a PI, send to bogusComment. if (strlen($procName) == 0 || $white == 0 || $this->scanner->current() == false) { $this->parseError("Expected processing instruction name, got $tok"); $this->bogusComment('<?' . $tok . $procName); return true; } $data = ''; // As long as it's not the case that the next two chars are ? and >. while (!($this->scanner->current() == '?' && $this->scanner->peek() == '>')) { $data .= $this->scanner->current(); $tok = $this->scanner->next(); if ($tok === false) { $this->parseError("Unexpected EOF in processing instruction."); $this->events->processingInstruction($procName, $data); return true; } } $this->scanner->next(); // > $this->scanner->next(); // Next token. $this->events->processingInstruction($procName, $data); return true; }
[ "protected", "function", "processingInstruction", "(", ")", "{", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "!=", "'?'", ")", "{", "return", "false", ";", "}", "$", "tok", "=", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "$", "procName", "=", "$", "this", "->", "scanner", "->", "getAsciiAlpha", "(", ")", ";", "$", "white", "=", "strlen", "(", "$", "this", "->", "scanner", "->", "whitespace", "(", ")", ")", ";", "// If not a PI, send to bogusComment.", "if", "(", "strlen", "(", "$", "procName", ")", "==", "0", "||", "$", "white", "==", "0", "||", "$", "this", "->", "scanner", "->", "current", "(", ")", "==", "false", ")", "{", "$", "this", "->", "parseError", "(", "\"Expected processing instruction name, got $tok\"", ")", ";", "$", "this", "->", "bogusComment", "(", "'<?'", ".", "$", "tok", ".", "$", "procName", ")", ";", "return", "true", ";", "}", "$", "data", "=", "''", ";", "// As long as it's not the case that the next two chars are ? and >.", "while", "(", "!", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "==", "'?'", "&&", "$", "this", "->", "scanner", "->", "peek", "(", ")", "==", "'>'", ")", ")", "{", "$", "data", ".=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "$", "tok", "=", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "if", "(", "$", "tok", "===", "false", ")", "{", "$", "this", "->", "parseError", "(", "\"Unexpected EOF in processing instruction.\"", ")", ";", "$", "this", "->", "events", "->", "processingInstruction", "(", "$", "procName", ",", "$", "data", ")", ";", "return", "true", ";", "}", "}", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "// >", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "// Next token.", "$", "this", "->", "events", "->", "processingInstruction", "(", "$", "procName", ",", "$", "data", ")", ";", "return", "true", ";", "}" ]
Handle a processing instruction. XML processing instructions are supposed to be ignored in HTML5, treated as "bogus comments". However, since we're not a user agent, we allow them. We consume until ?> and then issue a EventListener::processingInstruction() event.
[ "Handle", "a", "processing", "instruction", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L888-L921
21,797
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.readUntilSequence
protected function readUntilSequence($sequence) { $buffer = ''; // Optimization for reading larger blocks faster. $first = substr($sequence, 0, 1); while ($this->scanner->current() !== false) { $buffer .= $this->scanner->charsUntil($first); // Stop as soon as we hit the stopping condition. if ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))) { return $buffer; } $buffer .= $this->scanner->current(); $this->scanner->next(); } // If we get here, we hit the EOF. $this->parseError("Unexpected EOF during text read."); return $buffer; }
php
protected function readUntilSequence($sequence) { $buffer = ''; // Optimization for reading larger blocks faster. $first = substr($sequence, 0, 1); while ($this->scanner->current() !== false) { $buffer .= $this->scanner->charsUntil($first); // Stop as soon as we hit the stopping condition. if ($this->sequenceMatches($sequence) || $this->sequenceMatches(strtoupper($sequence))) { return $buffer; } $buffer .= $this->scanner->current(); $this->scanner->next(); } // If we get here, we hit the EOF. $this->parseError("Unexpected EOF during text read."); return $buffer; }
[ "protected", "function", "readUntilSequence", "(", "$", "sequence", ")", "{", "$", "buffer", "=", "''", ";", "// Optimization for reading larger blocks faster.", "$", "first", "=", "substr", "(", "$", "sequence", ",", "0", ",", "1", ")", ";", "while", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "!==", "false", ")", "{", "$", "buffer", ".=", "$", "this", "->", "scanner", "->", "charsUntil", "(", "$", "first", ")", ";", "// Stop as soon as we hit the stopping condition.", "if", "(", "$", "this", "->", "sequenceMatches", "(", "$", "sequence", ")", "||", "$", "this", "->", "sequenceMatches", "(", "strtoupper", "(", "$", "sequence", ")", ")", ")", "{", "return", "$", "buffer", ";", "}", "$", "buffer", ".=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "}", "// If we get here, we hit the EOF.", "$", "this", "->", "parseError", "(", "\"Unexpected EOF during text read.\"", ")", ";", "return", "$", "buffer", ";", "}" ]
Read from the input stream until we get to the desired sequene or hit the end of the input stream.
[ "Read", "from", "the", "input", "stream", "until", "we", "get", "to", "the", "desired", "sequene", "or", "hit", "the", "end", "of", "the", "input", "stream", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L931-L950
21,798
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.sequenceMatches
protected function sequenceMatches($sequence) { $len = strlen($sequence); $buffer = ''; for ($i = 0; $i < $len; ++$i) { $buffer .= $this->scanner->current(); // EOF. Rewind and let the caller handle it. if ($this->scanner->current() === false) { $this->scanner->unconsume($i); return false; } $this->scanner->next(); } $this->scanner->unconsume($len); return $buffer == $sequence; }
php
protected function sequenceMatches($sequence) { $len = strlen($sequence); $buffer = ''; for ($i = 0; $i < $len; ++$i) { $buffer .= $this->scanner->current(); // EOF. Rewind and let the caller handle it. if ($this->scanner->current() === false) { $this->scanner->unconsume($i); return false; } $this->scanner->next(); } $this->scanner->unconsume($len); return $buffer == $sequence; }
[ "protected", "function", "sequenceMatches", "(", "$", "sequence", ")", "{", "$", "len", "=", "strlen", "(", "$", "sequence", ")", ";", "$", "buffer", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "len", ";", "++", "$", "i", ")", "{", "$", "buffer", ".=", "$", "this", "->", "scanner", "->", "current", "(", ")", ";", "// EOF. Rewind and let the caller handle it.", "if", "(", "$", "this", "->", "scanner", "->", "current", "(", ")", "===", "false", ")", "{", "$", "this", "->", "scanner", "->", "unconsume", "(", "$", "i", ")", ";", "return", "false", ";", "}", "$", "this", "->", "scanner", "->", "next", "(", ")", ";", "}", "$", "this", "->", "scanner", "->", "unconsume", "(", "$", "len", ")", ";", "return", "$", "buffer", "==", "$", "sequence", ";", "}" ]
Check if upcomming chars match the given sequence. This will read the stream for the $sequence. If it's found, this will return true. If not, return false. Since this unconsumes any chars it reads, the caller will still need to read the next sequence, even if this returns true. Example: $this->sequenceMatches('</script>') will see if the input stream is at the start of a '</script>' string.
[ "Check", "if", "upcomming", "chars", "match", "the", "given", "sequence", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L965-L981
21,799
PHPPowertools/HTML5
src/PowerTools/HTML5/Parser/Tokenizer.php
HTML5_Parser_Tokenizer.flushBuffer
protected function flushBuffer() { if ($this->text === '') { return; } $this->events->text($this->text); $this->text = ''; }
php
protected function flushBuffer() { if ($this->text === '') { return; } $this->events->text($this->text); $this->text = ''; }
[ "protected", "function", "flushBuffer", "(", ")", "{", "if", "(", "$", "this", "->", "text", "===", "''", ")", "{", "return", ";", "}", "$", "this", "->", "events", "->", "text", "(", "$", "this", "->", "text", ")", ";", "$", "this", "->", "text", "=", "''", ";", "}" ]
Send a TEXT event with the contents of the text buffer. This emits an HTML5_Parser_EventHandler::text() event with the current contents of the temporary text buffer. (The buffer is used to group as much PCDATA as we can instead of emitting lots and lots of TEXT events.)
[ "Send", "a", "TEXT", "event", "with", "the", "contents", "of", "the", "text", "buffer", "." ]
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Parser/Tokenizer.php#L990-L996