repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
graphp/graph
src/Edge/Base.php
Base.setWeight
public function setWeight($weight) { if ($weight !== NULL && !is_float($weight) && !is_int($weight)) { throw new InvalidArgumentException('Invalid weight given - must be numeric or NULL'); } $this->weight = $weight; return $this; }
php
public function setWeight($weight) { if ($weight !== NULL && !is_float($weight) && !is_int($weight)) { throw new InvalidArgumentException('Invalid weight given - must be numeric or NULL'); } $this->weight = $weight; return $this; }
[ "public", "function", "setWeight", "(", "$", "weight", ")", "{", "if", "(", "$", "weight", "!==", "NULL", "&&", "!", "is_float", "(", "$", "weight", ")", "&&", "!", "is_int", "(", "$", "weight", ")", ")", "{", "throw", "new", "InvalidArgumentException"...
set new weight for edge @param float|int|NULL $weight new numeric weight of edge or NULL=unset weight @return self $this (chainable) @throws InvalidArgumentException if given weight is not numeric
[ "set", "new", "weight", "for", "edge" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Edge/Base.php#L122-L130
graphp/graph
src/Edge/Base.php
Base.setCapacity
public function setCapacity($capacity) { if ($capacity !== NULL) { if (!is_float($capacity) && !is_int($capacity)) { throw new InvalidArgumentException('Invalid capacity given - must be numeric'); } if ($capacity < 0) { throw new InvalidArgumentException('Capacity must not be negative'); } if ($this->flow !== NULL && $this->flow > $capacity) { throw new RangeException('Current flow of ' . $this->flow . ' exceeds new capacity'); } } $this->capacity = $capacity; return $this; }
php
public function setCapacity($capacity) { if ($capacity !== NULL) { if (!is_float($capacity) && !is_int($capacity)) { throw new InvalidArgumentException('Invalid capacity given - must be numeric'); } if ($capacity < 0) { throw new InvalidArgumentException('Capacity must not be negative'); } if ($this->flow !== NULL && $this->flow > $capacity) { throw new RangeException('Current flow of ' . $this->flow . ' exceeds new capacity'); } } $this->capacity = $capacity; return $this; }
[ "public", "function", "setCapacity", "(", "$", "capacity", ")", "{", "if", "(", "$", "capacity", "!==", "NULL", ")", "{", "if", "(", "!", "is_float", "(", "$", "capacity", ")", "&&", "!", "is_int", "(", "$", "capacity", ")", ")", "{", "throw", "new...
set new total capacity of this edge @param float|int|NULL $capacity @return self $this (chainable) @throws InvalidArgumentException if $capacity is invalid (not numeric or negative) @throws RangeException if current flow exceeds new capacity
[ "set", "new", "total", "capacity", "of", "this", "edge" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Edge/Base.php#L164-L180
graphp/graph
src/Edge/Base.php
Base.setFlow
public function setFlow($flow) { if ($flow !== NULL) { if (!is_float($flow) && !is_int($flow)) { throw new InvalidArgumentException('Invalid flow given - must be numeric'); } if ($flow < 0) { throw new InvalidArgumentException('Flow must not be negative'); } if ($this->capacity !== NULL && $flow > $this->capacity) { throw new RangeException('New flow exceeds maximum capacity'); } } $this->flow = $flow; return $this; }
php
public function setFlow($flow) { if ($flow !== NULL) { if (!is_float($flow) && !is_int($flow)) { throw new InvalidArgumentException('Invalid flow given - must be numeric'); } if ($flow < 0) { throw new InvalidArgumentException('Flow must not be negative'); } if ($this->capacity !== NULL && $flow > $this->capacity) { throw new RangeException('New flow exceeds maximum capacity'); } } $this->flow = $flow; return $this; }
[ "public", "function", "setFlow", "(", "$", "flow", ")", "{", "if", "(", "$", "flow", "!==", "NULL", ")", "{", "if", "(", "!", "is_float", "(", "$", "flow", ")", "&&", "!", "is_int", "(", "$", "flow", ")", ")", "{", "throw", "new", "InvalidArgumen...
set new total flow (capacity currently in use) @param float|int|NULL $flow @return self $this (chainable) @throws InvalidArgumentException if $flow is invalid (not numeric or negative) @throws RangeException if flow exceeds current maximum capacity
[ "set", "new", "total", "flow", "(", "capacity", "currently", "in", "use", ")" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Edge/Base.php#L200-L216
graphp/graph
src/Edge/Base.php
Base.destroy
public function destroy() { $this->getGraph()->removeEdge($this); foreach ($this->getVertices() as $vertex) { $vertex->removeEdge($this); } }
php
public function destroy() { $this->getGraph()->removeEdge($this); foreach ($this->getVertices() as $vertex) { $vertex->removeEdge($this); } }
[ "public", "function", "destroy", "(", ")", "{", "$", "this", "->", "getGraph", "(", ")", "->", "removeEdge", "(", "$", "this", ")", ";", "foreach", "(", "$", "this", "->", "getVertices", "(", ")", "as", "$", "vertex", ")", "{", "$", "vertex", "->",...
destroy edge and remove reference from vertices and graph @uses Graph::removeEdge() @uses Vertex::removeEdge() @return void
[ "destroy", "edge", "and", "remove", "reference", "from", "vertices", "and", "graph" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Edge/Base.php#L252-L258
graphp/graph
src/Walk.php
Walk.factoryFromEdges
public static function factoryFromEdges($edges, Vertex $startVertex) { $vertices = array($startVertex); $vertexCurrent = $startVertex; foreach ($edges as $edge) { $vertexCurrent = $edge->getVertexToFrom($vertexCurrent); $vertices []= $vertexCurrent; } return new self($vertices, $edges); }
php
public static function factoryFromEdges($edges, Vertex $startVertex) { $vertices = array($startVertex); $vertexCurrent = $startVertex; foreach ($edges as $edge) { $vertexCurrent = $edge->getVertexToFrom($vertexCurrent); $vertices []= $vertexCurrent; } return new self($vertices, $edges); }
[ "public", "static", "function", "factoryFromEdges", "(", "$", "edges", ",", "Vertex", "$", "startVertex", ")", "{", "$", "vertices", "=", "array", "(", "$", "startVertex", ")", ";", "$", "vertexCurrent", "=", "$", "startVertex", ";", "foreach", "(", "$", ...
construct new walk from given start vertex and given array of edges @param Edges|Edge[] $edges @param Vertex $startVertex @return Walk
[ "construct", "new", "walk", "from", "given", "start", "vertex", "and", "given", "array", "of", "edges" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Walk.php#L31-L41
graphp/graph
src/Walk.php
Walk.factoryFromVertices
public static function factoryFromVertices($vertices, $by = null, $desc = false) { $edges = array(); $last = NULL; foreach ($vertices as $vertex) { // skip first vertex as last is unknown if ($last !== NULL) { // pick edge between last vertex and this vertex /* @var $last Vertex */ if ($by === null) { $edges []= $last->getEdgesTo($vertex)->getEdgeFirst(); } else { $edges []= $last->getEdgesTo($vertex)->getEdgeOrder($by, $desc); } } $last = $vertex; } if ($last === NULL) { throw new UnderflowException('No vertices given'); } return new self($vertices, $edges); }
php
public static function factoryFromVertices($vertices, $by = null, $desc = false) { $edges = array(); $last = NULL; foreach ($vertices as $vertex) { // skip first vertex as last is unknown if ($last !== NULL) { // pick edge between last vertex and this vertex /* @var $last Vertex */ if ($by === null) { $edges []= $last->getEdgesTo($vertex)->getEdgeFirst(); } else { $edges []= $last->getEdgesTo($vertex)->getEdgeOrder($by, $desc); } } $last = $vertex; } if ($last === NULL) { throw new UnderflowException('No vertices given'); } return new self($vertices, $edges); }
[ "public", "static", "function", "factoryFromVertices", "(", "$", "vertices", ",", "$", "by", "=", "null", ",", "$", "desc", "=", "false", ")", "{", "$", "edges", "=", "array", "(", ")", ";", "$", "last", "=", "NULL", ";", "foreach", "(", "$", "vert...
create new walk instance between given set of Vertices / array of Vertex instances @param Vertices|Vertex[] $vertices @param int|null $by @param boolean $desc @return Walk @throws UnderflowException if no vertices were given @see Edges::getEdgeOrder() for parameters $by and $desc
[ "create", "new", "walk", "instance", "between", "given", "set", "of", "Vertices", "/", "array", "of", "Vertex", "instances" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Walk.php#L53-L75
graphp/graph
src/Walk.php
Walk.factoryCycleFromPredecessorMap
public static function factoryCycleFromPredecessorMap(array $predecessors, Vertex $vertex, $by = null, $desc = false) { // find a vertex in the cycle $vid = $vertex->getId(); $startVertices = array(); do { if (!isset($predecessors[$vid])) { throw new InvalidArgumentException('Predecessor map is incomplete and does not form a cycle'); } $startVertices[$vid] = $vertex; $vertex = $predecessors[$vid]; $vid = $vertex->getId(); } while (!isset($startVertices[$vid])); // find negative cycle $vid = $vertex->getId(); // build array of vertices in cycle $vertices = array(); do { // add new vertex to cycle $vertices[$vid] = $vertex; // get predecessor of vertex $vertex = $predecessors[$vid]; $vid = $vertex->getId(); // continue until we find a vertex that's already in the circle (i.e. circle is closed) } while (!isset($vertices[$vid])); // reverse cycle, because cycle is actually built in opposite direction due to checking predecessors $vertices = array_reverse($vertices, true); // additional edge from last vertex to first vertex $vertices[] = reset($vertices); return self::factoryCycleFromVertices($vertices, $by, $desc); }
php
public static function factoryCycleFromPredecessorMap(array $predecessors, Vertex $vertex, $by = null, $desc = false) { // find a vertex in the cycle $vid = $vertex->getId(); $startVertices = array(); do { if (!isset($predecessors[$vid])) { throw new InvalidArgumentException('Predecessor map is incomplete and does not form a cycle'); } $startVertices[$vid] = $vertex; $vertex = $predecessors[$vid]; $vid = $vertex->getId(); } while (!isset($startVertices[$vid])); // find negative cycle $vid = $vertex->getId(); // build array of vertices in cycle $vertices = array(); do { // add new vertex to cycle $vertices[$vid] = $vertex; // get predecessor of vertex $vertex = $predecessors[$vid]; $vid = $vertex->getId(); // continue until we find a vertex that's already in the circle (i.e. circle is closed) } while (!isset($vertices[$vid])); // reverse cycle, because cycle is actually built in opposite direction due to checking predecessors $vertices = array_reverse($vertices, true); // additional edge from last vertex to first vertex $vertices[] = reset($vertices); return self::factoryCycleFromVertices($vertices, $by, $desc); }
[ "public", "static", "function", "factoryCycleFromPredecessorMap", "(", "array", "$", "predecessors", ",", "Vertex", "$", "vertex", ",", "$", "by", "=", "null", ",", "$", "desc", "=", "false", ")", "{", "// find a vertex in the cycle", "$", "vid", "=", "$", "...
create new cycle instance from given predecessor map @param Vertex[] $predecessors map of vid => predecessor vertex instance @param Vertex $vertex start vertex to search predecessors from @param int|null $by @param boolean $desc @return Walk @throws UnderflowException @see Edges::getEdgeOrder() for parameters $by and $desc @uses self::factoryFromVertices()
[ "create", "new", "cycle", "instance", "from", "given", "predecessor", "map" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Walk.php#L89-L126
graphp/graph
src/Walk.php
Walk.factoryCycleFromVertices
public static function factoryCycleFromVertices($vertices, $by = null, $desc = false) { $cycle = self::factoryFromVertices($vertices, $by, $desc); if ($cycle->getEdges()->isEmpty()) { throw new InvalidArgumentException('Cycle with no edges can not exist'); } if ($cycle->getVertices()->getVertexFirst() !== $cycle->getVertices()->getVertexLast()) { throw new InvalidArgumentException('Cycle has to start and end at the same vertex'); } return $cycle; }
php
public static function factoryCycleFromVertices($vertices, $by = null, $desc = false) { $cycle = self::factoryFromVertices($vertices, $by, $desc); if ($cycle->getEdges()->isEmpty()) { throw new InvalidArgumentException('Cycle with no edges can not exist'); } if ($cycle->getVertices()->getVertexFirst() !== $cycle->getVertices()->getVertexLast()) { throw new InvalidArgumentException('Cycle has to start and end at the same vertex'); } return $cycle; }
[ "public", "static", "function", "factoryCycleFromVertices", "(", "$", "vertices", ",", "$", "by", "=", "null", ",", "$", "desc", "=", "false", ")", "{", "$", "cycle", "=", "self", "::", "factoryFromVertices", "(", "$", "vertices", ",", "$", "by", ",", ...
create new cycle instance with edges between given vertices @param Vertex[]|Vertices $vertices @param int|null $by @param boolean $desc @return Walk @throws UnderflowException if no vertices were given @see Edges::getEdgeOrder() for parameters $by and $desc @uses self::factoryFromVertices()
[ "create", "new", "cycle", "instance", "with", "edges", "between", "given", "vertices" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Walk.php#L139-L152
graphp/graph
src/Walk.php
Walk.factoryCycleFromEdges
public static function factoryCycleFromEdges($edges, Vertex $startVertex) { $cycle = self::factoryFromEdges($edges, $startVertex); // ensure this walk is actually a cycle by checking start = end if ($cycle->getVertices()->getVertexLast() !== $startVertex) { throw new InvalidArgumentException('The given array of edges does not represent a cycle'); } return $cycle; }
php
public static function factoryCycleFromEdges($edges, Vertex $startVertex) { $cycle = self::factoryFromEdges($edges, $startVertex); // ensure this walk is actually a cycle by checking start = end if ($cycle->getVertices()->getVertexLast() !== $startVertex) { throw new InvalidArgumentException('The given array of edges does not represent a cycle'); } return $cycle; }
[ "public", "static", "function", "factoryCycleFromEdges", "(", "$", "edges", ",", "Vertex", "$", "startVertex", ")", "{", "$", "cycle", "=", "self", "::", "factoryFromEdges", "(", "$", "edges", ",", "$", "startVertex", ")", ";", "// ensure this walk is actually a...
create new cycle instance with vertices connected by given edges @param Edges|Edge[] $edges @param Vertex $startVertex @return Walk @throws InvalidArgumentException if the given array of edges does not represent a valid cycle @uses self::factoryFromEdges()
[ "create", "new", "cycle", "instance", "with", "vertices", "connected", "by", "given", "edges" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Walk.php#L163-L173
graphp/graph
src/Walk.php
Walk.createGraph
public function createGraph() { // create new graph clone with only edges of walk $graph = $this->getGraph()->createGraphCloneEdges($this->getEdges()); $vertices = $this->getVertices()->getMap(); // get all vertices foreach ($graph->getVertices()->getMap() as $vid => $vertex) { if (!isset($vertices[$vid])) { // remove those not present in the walk (isolated vertices, etc.) $vertex->destroy(); } } return $graph; }
php
public function createGraph() { // create new graph clone with only edges of walk $graph = $this->getGraph()->createGraphCloneEdges($this->getEdges()); $vertices = $this->getVertices()->getMap(); // get all vertices foreach ($graph->getVertices()->getMap() as $vid => $vertex) { if (!isset($vertices[$vid])) { // remove those not present in the walk (isolated vertices, etc.) $vertex->destroy(); } } return $graph; }
[ "public", "function", "createGraph", "(", ")", "{", "// create new graph clone with only edges of walk", "$", "graph", "=", "$", "this", "->", "getGraph", "(", ")", "->", "createGraphCloneEdges", "(", "$", "this", "->", "getEdges", "(", ")", ")", ";", "$", "ve...
create new graph clone with only vertices and edges actually in the walk do not add duplicate vertices and edges for loops and intersections, etc. @return Graph @uses Walk::getEdges() @uses Graph::createGraphCloneEdges()
[ "create", "new", "graph", "clone", "with", "only", "vertices", "and", "edges", "actually", "in", "the", "walk" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Walk.php#L215-L229
graphp/graph
src/Walk.php
Walk.getAlternatingSequence
public function getAlternatingSequence() { $edges = $this->edges->getVector(); $vertices = $this->vertices->getVector(); $ret = array(); for ($i = 0, $l = count($this->edges); $i < $l; ++$i) { $ret []= $vertices[$i]; $ret []= $edges[$i]; } $ret[] = $vertices[$i]; return $ret; }
php
public function getAlternatingSequence() { $edges = $this->edges->getVector(); $vertices = $this->vertices->getVector(); $ret = array(); for ($i = 0, $l = count($this->edges); $i < $l; ++$i) { $ret []= $vertices[$i]; $ret []= $edges[$i]; } $ret[] = $vertices[$i]; return $ret; }
[ "public", "function", "getAlternatingSequence", "(", ")", "{", "$", "edges", "=", "$", "this", "->", "edges", "->", "getVector", "(", ")", ";", "$", "vertices", "=", "$", "this", "->", "vertices", "->", "getVector", "(", ")", ";", "$", "ret", "=", "a...
get alternating sequence of vertex, edge, vertex, edge, ..., vertex @return array
[ "get", "alternating", "sequence", "of", "vertex", "edge", "vertex", "edge", "...", "vertex" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Walk.php#L268-L281
graphp/graph
src/Walk.php
Walk.isValid
public function isValid() { $vertices = $this->getGraph()->getVertices()->getMap(); // check source graph contains all vertices foreach ($this->getVertices()->getMap() as $vid => $vertex) { // make sure vertex ID exists and has not been replaced if (!isset($vertices[$vid]) || $vertices[$vid] !== $vertex) { return false; } } $edges = $this->getGraph()->getEdges()->getVector(); // check source graph contains all edges foreach ($this->edges as $edge) { if (!in_array($edge, $edges, true)) { return false; } } return true; }
php
public function isValid() { $vertices = $this->getGraph()->getVertices()->getMap(); // check source graph contains all vertices foreach ($this->getVertices()->getMap() as $vid => $vertex) { // make sure vertex ID exists and has not been replaced if (!isset($vertices[$vid]) || $vertices[$vid] !== $vertex) { return false; } } $edges = $this->getGraph()->getEdges()->getVector(); // check source graph contains all edges foreach ($this->edges as $edge) { if (!in_array($edge, $edges, true)) { return false; } } return true; }
[ "public", "function", "isValid", "(", ")", "{", "$", "vertices", "=", "$", "this", "->", "getGraph", "(", ")", "->", "getVertices", "(", ")", "->", "getMap", "(", ")", ";", "// check source graph contains all vertices", "foreach", "(", "$", "this", "->", "...
check to make sure this walk is still valid (i.e. source graph still contains all vertices and edges) @return boolean @uses Walk::getGraph() @uses Graph::getVertices() @uses Graph::getEdges()
[ "check", "to", "make", "sure", "this", "walk", "is", "still", "valid", "(", "i", ".", "e", ".", "source", "graph", "still", "contains", "all", "vertices", "and", "edges", ")" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Walk.php#L291-L310
graphp/graph
src/Attribute/AttributeBagNamespaced.php
AttributeBagNamespaced.setAttribute
public function setAttribute($name, $value) { $this->bag->setAttribute($this->prefix . $name, $value); }
php
public function setAttribute($name, $value) { $this->bag->setAttribute($this->prefix . $name, $value); }
[ "public", "function", "setAttribute", "(", "$", "name", ",", "$", "value", ")", "{", "$", "this", "->", "bag", "->", "setAttribute", "(", "$", "this", "->", "prefix", ".", "$", "name", ",", "$", "value", ")", ";", "}" ]
set a single attribute with the given $name to given $value This prefixes the attribute name before setting in the base bag. @param string $name @param mixed $value @return void
[ "set", "a", "single", "attribute", "with", "the", "given", "$name", "to", "given", "$value" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Attribute/AttributeBagNamespaced.php#L66-L69
graphp/graph
src/Attribute/AttributeBagNamespaced.php
AttributeBagNamespaced.getAttributes
public function getAttributes() { $attributes = array(); $len = strlen($this->prefix); foreach ($this->bag->getAttributes() as $name => $value) { if (strpos($name, $this->prefix) === 0) { $attributes[substr($name, $len)] = $value; } } return $attributes; }
php
public function getAttributes() { $attributes = array(); $len = strlen($this->prefix); foreach ($this->bag->getAttributes() as $name => $value) { if (strpos($name, $this->prefix) === 0) { $attributes[substr($name, $len)] = $value; } } return $attributes; }
[ "public", "function", "getAttributes", "(", ")", "{", "$", "attributes", "=", "array", "(", ")", ";", "$", "len", "=", "strlen", "(", "$", "this", "->", "prefix", ")", ";", "foreach", "(", "$", "this", "->", "bag", "->", "getAttributes", "(", ")", ...
get an array of all attributes The prefix will not be included in the returned attribute keys. @return array
[ "get", "an", "array", "of", "all", "attributes" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Attribute/AttributeBagNamespaced.php#L88-L100
graphp/graph
src/Attribute/AttributeBagNamespaced.php
AttributeBagNamespaced.setAttributes
public function setAttributes(array $attributes) { foreach ($attributes as $name => $value) { $this->bag->setAttribute($this->prefix . $name, $value); } }
php
public function setAttributes(array $attributes) { foreach ($attributes as $name => $value) { $this->bag->setAttribute($this->prefix . $name, $value); } }
[ "public", "function", "setAttributes", "(", "array", "$", "attributes", ")", "{", "foreach", "(", "$", "attributes", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "this", "->", "bag", "->", "setAttribute", "(", "$", "this", "->", "prefix", ".",...
set an array of additional attributes Each attribute is prefixed before setting in the base bag. @param array $attributes @return void
[ "set", "an", "array", "of", "additional", "attributes" ]
train
https://github.com/graphp/graph/blob/a5455eda4dc5fcecab6db13dbd24f8a8fa929d93/src/Attribute/AttributeBagNamespaced.php#L110-L115
oyejorge/less.php
lib/Less/Parser.php
Less_Parser.parseFile
public function parseFile( $filename, $uri_root = '', $returnRoot = false){ if( !file_exists($filename) ){ $this->Error(sprintf('File `%s` not found.', $filename)); } // fix uri_root? // Instead of The mixture of file path for the first argument and directory path for the second argument has bee if( !$returnRoot && !empty($uri_root) && basename($uri_root) == basename($filename) ){ $uri_root = dirname($uri_root); } $previousFileInfo = $this->env->currentFileInfo; if( $filename ){ $filename = self::AbsPath($filename, true); } $uri_root = self::WinPath($uri_root); $this->SetFileInfo($filename, $uri_root); self::AddParsedFile($filename); if( $returnRoot ){ $rules = $this->GetRules( $filename ); $return = new Less_Tree_Ruleset(array(), $rules ); }else{ $this->_parse( $filename ); $return = $this; } if( $previousFileInfo ){ $this->env->currentFileInfo = $previousFileInfo; } return $return; }
php
public function parseFile( $filename, $uri_root = '', $returnRoot = false){ if( !file_exists($filename) ){ $this->Error(sprintf('File `%s` not found.', $filename)); } // fix uri_root? // Instead of The mixture of file path for the first argument and directory path for the second argument has bee if( !$returnRoot && !empty($uri_root) && basename($uri_root) == basename($filename) ){ $uri_root = dirname($uri_root); } $previousFileInfo = $this->env->currentFileInfo; if( $filename ){ $filename = self::AbsPath($filename, true); } $uri_root = self::WinPath($uri_root); $this->SetFileInfo($filename, $uri_root); self::AddParsedFile($filename); if( $returnRoot ){ $rules = $this->GetRules( $filename ); $return = new Less_Tree_Ruleset(array(), $rules ); }else{ $this->_parse( $filename ); $return = $this; } if( $previousFileInfo ){ $this->env->currentFileInfo = $previousFileInfo; } return $return; }
[ "public", "function", "parseFile", "(", "$", "filename", ",", "$", "uri_root", "=", "''", ",", "$", "returnRoot", "=", "false", ")", "{", "if", "(", "!", "file_exists", "(", "$", "filename", ")", ")", "{", "$", "this", "->", "Error", "(", "sprintf", ...
Parse a Less string from a given file @throws Less_Exception_Parser @param string $filename The file to parse @param string $uri_root The url of the file @param bool $returnRoot Indicates whether the return value should be a css string a root node @return Less_Tree_Ruleset|Less_Parser
[ "Parse", "a", "Less", "string", "from", "a", "given", "file" ]
train
https://github.com/oyejorge/less.php/blob/42925c5a01a07d67ca7e82dfc8fb31814d557bc9/lib/Less/Parser.php#L468-L507
oyejorge/less.php
lib/Less/Parser.php
Less_Parser.MatchQuoted
private function MatchQuoted($quote_char, $i){ $matched = ''; while( $i < $this->input_len ){ $c = $this->input[$i]; //escaped character if( $c === '\\' ){ $matched .= $c . $this->input[$i+1]; $i += 2; continue; } if( $c === $quote_char ){ $this->pos = $i+1; $this->skipWhitespace(0); return $matched; } if( $c === "\r" || $c === "\n" ){ return false; } $i++; $matched .= $c; } return false; }
php
private function MatchQuoted($quote_char, $i){ $matched = ''; while( $i < $this->input_len ){ $c = $this->input[$i]; //escaped character if( $c === '\\' ){ $matched .= $c . $this->input[$i+1]; $i += 2; continue; } if( $c === $quote_char ){ $this->pos = $i+1; $this->skipWhitespace(0); return $matched; } if( $c === "\r" || $c === "\n" ){ return false; } $i++; $matched .= $c; } return false; }
[ "private", "function", "MatchQuoted", "(", "$", "quote_char", ",", "$", "i", ")", "{", "$", "matched", "=", "''", ";", "while", "(", "$", "i", "<", "$", "this", "->", "input_len", ")", "{", "$", "c", "=", "$", "this", "->", "input", "[", "$", "...
When PCRE JIT is enabled in php, regular expressions don't work for matching quoted strings $regex = '/\\G\'((?:[^\'\\\\\r\n]|\\\\.|\\\\\r\n|\\\\[\n\r\f])*)\'/'; $regex = '/\\G"((?:[^"\\\\\r\n]|\\\\.|\\\\\r\n|\\\\[\n\r\f])*)"/';
[ "When", "PCRE", "JIT", "is", "enabled", "in", "php", "regular", "expressions", "don", "t", "work", "for", "matching", "quoted", "strings" ]
train
https://github.com/oyejorge/less.php/blob/42925c5a01a07d67ca7e82dfc8fb31814d557bc9/lib/Less/Parser.php#L1107-L1135
oyejorge/less.php
lib/Less/Cache.php
Less_Cache.CleanCache
public static function CleanCache(){ static $clean = false; if( $clean || empty(Less_Cache::$cache_dir) ){ return; } $clean = true; // only remove files with extensions created by less.php // css files removed based on the list files $remove_types = array('lesscache'=>1,'list'=>1,'less'=>1,'map'=>1); $files = scandir(Less_Cache::$cache_dir); if( !$files ){ return; } $check_time = time() - self::$gc_lifetime; foreach($files as $file){ // don't delete if the file wasn't created with less.php if( strpos($file,Less_Cache::$prefix) !== 0 ){ continue; } $parts = explode('.',$file); $type = array_pop($parts); if( !isset($remove_types[$type]) ){ continue; } $full_path = Less_Cache::$cache_dir . $file; $mtime = filemtime($full_path); // don't delete if it's a relatively new file if( $mtime > $check_time ){ continue; } // delete the list file and associated css file if( $type === 'list' ){ self::ListFiles($full_path, $list, $css_file_name); if( $css_file_name ){ $css_file = Less_Cache::$cache_dir . $css_file_name; if( file_exists($css_file) ){ unlink($css_file); } } } unlink($full_path); } }
php
public static function CleanCache(){ static $clean = false; if( $clean || empty(Less_Cache::$cache_dir) ){ return; } $clean = true; // only remove files with extensions created by less.php // css files removed based on the list files $remove_types = array('lesscache'=>1,'list'=>1,'less'=>1,'map'=>1); $files = scandir(Less_Cache::$cache_dir); if( !$files ){ return; } $check_time = time() - self::$gc_lifetime; foreach($files as $file){ // don't delete if the file wasn't created with less.php if( strpos($file,Less_Cache::$prefix) !== 0 ){ continue; } $parts = explode('.',$file); $type = array_pop($parts); if( !isset($remove_types[$type]) ){ continue; } $full_path = Less_Cache::$cache_dir . $file; $mtime = filemtime($full_path); // don't delete if it's a relatively new file if( $mtime > $check_time ){ continue; } // delete the list file and associated css file if( $type === 'list' ){ self::ListFiles($full_path, $list, $css_file_name); if( $css_file_name ){ $css_file = Less_Cache::$cache_dir . $css_file_name; if( file_exists($css_file) ){ unlink($css_file); } } } unlink($full_path); } }
[ "public", "static", "function", "CleanCache", "(", ")", "{", "static", "$", "clean", "=", "false", ";", "if", "(", "$", "clean", "||", "empty", "(", "Less_Cache", "::", "$", "cache_dir", ")", ")", "{", "return", ";", "}", "$", "clean", "=", "true", ...
Delete unused less.php files
[ "Delete", "unused", "less", ".", "php", "files" ]
train
https://github.com/oyejorge/less.php/blob/42925c5a01a07d67ca7e82dfc8fb31814d557bc9/lib/Less/Cache.php#L238-L298
oyejorge/less.php
lib/Less/Tree/Import.php
Less_Tree_Import.PathAndUri
public function PathAndUri(){ $evald_path = $this->getPath(); if( $evald_path ){ $import_dirs = array(); if( Less_Environment::isPathRelative($evald_path) ){ //if the path is relative, the file should be in the current directory $import_dirs[ $this->currentFileInfo['currentDirectory'] ] = $this->currentFileInfo['uri_root']; }else{ //otherwise, the file should be relative to the server root $import_dirs[ $this->currentFileInfo['entryPath'] ] = $this->currentFileInfo['entryUri']; //if the user supplied entryPath isn't the actual root $import_dirs[ $_SERVER['DOCUMENT_ROOT'] ] = ''; } // always look in user supplied import directories $import_dirs = array_merge( $import_dirs, Less_Parser::$options['import_dirs'] ); foreach( $import_dirs as $rootpath => $rooturi){ if( is_callable($rooturi) ){ list($path, $uri) = call_user_func($rooturi, $evald_path); if( is_string($path) ){ $full_path = $path; return array( $full_path, $uri ); } }elseif( !empty($rootpath) ){ $path = rtrim($rootpath,'/\\').'/'.ltrim($evald_path,'/\\'); if( file_exists($path) ){ $full_path = Less_Environment::normalizePath($path); $uri = Less_Environment::normalizePath(dirname($rooturi.$evald_path)); return array( $full_path, $uri ); } elseif( file_exists($path.'.less') ){ $full_path = Less_Environment::normalizePath($path.'.less'); $uri = Less_Environment::normalizePath(dirname($rooturi.$evald_path.'.less')); return array( $full_path, $uri ); } } } } }
php
public function PathAndUri(){ $evald_path = $this->getPath(); if( $evald_path ){ $import_dirs = array(); if( Less_Environment::isPathRelative($evald_path) ){ //if the path is relative, the file should be in the current directory $import_dirs[ $this->currentFileInfo['currentDirectory'] ] = $this->currentFileInfo['uri_root']; }else{ //otherwise, the file should be relative to the server root $import_dirs[ $this->currentFileInfo['entryPath'] ] = $this->currentFileInfo['entryUri']; //if the user supplied entryPath isn't the actual root $import_dirs[ $_SERVER['DOCUMENT_ROOT'] ] = ''; } // always look in user supplied import directories $import_dirs = array_merge( $import_dirs, Less_Parser::$options['import_dirs'] ); foreach( $import_dirs as $rootpath => $rooturi){ if( is_callable($rooturi) ){ list($path, $uri) = call_user_func($rooturi, $evald_path); if( is_string($path) ){ $full_path = $path; return array( $full_path, $uri ); } }elseif( !empty($rootpath) ){ $path = rtrim($rootpath,'/\\').'/'.ltrim($evald_path,'/\\'); if( file_exists($path) ){ $full_path = Less_Environment::normalizePath($path); $uri = Less_Environment::normalizePath(dirname($rooturi.$evald_path)); return array( $full_path, $uri ); } elseif( file_exists($path.'.less') ){ $full_path = Less_Environment::normalizePath($path.'.less'); $uri = Less_Environment::normalizePath(dirname($rooturi.$evald_path.'.less')); return array( $full_path, $uri ); } } } } }
[ "public", "function", "PathAndUri", "(", ")", "{", "$", "evald_path", "=", "$", "this", "->", "getPath", "(", ")", ";", "if", "(", "$", "evald_path", ")", "{", "$", "import_dirs", "=", "array", "(", ")", ";", "if", "(", "Less_Environment", "::", "isP...
Using the import directories, get the full absolute path and uri of the import @param Less_Tree_Import $evald
[ "Using", "the", "import", "directories", "get", "the", "full", "absolute", "path", "and", "uri", "of", "the", "import" ]
train
https://github.com/oyejorge/less.php/blob/42925c5a01a07d67ca7e82dfc8fb31814d557bc9/lib/Less/Tree/Import.php#L207-L255
oyejorge/less.php
lib/Less/Tree/Import.php
Less_Tree_Import.Skip
private function Skip($path, $env){ $path = Less_Parser::AbsPath($path, true); if( $path && Less_Parser::FileParsed($path) ){ if( isset($this->currentFileInfo['reference']) ){ return true; } return !isset($this->options['multiple']) && !$env->importMultiple; } }
php
private function Skip($path, $env){ $path = Less_Parser::AbsPath($path, true); if( $path && Less_Parser::FileParsed($path) ){ if( isset($this->currentFileInfo['reference']) ){ return true; } return !isset($this->options['multiple']) && !$env->importMultiple; } }
[ "private", "function", "Skip", "(", "$", "path", ",", "$", "env", ")", "{", "$", "path", "=", "Less_Parser", "::", "AbsPath", "(", "$", "path", ",", "true", ")", ";", "if", "(", "$", "path", "&&", "Less_Parser", "::", "FileParsed", "(", "$", "path"...
Should the import be skipped? @return boolean|null
[ "Should", "the", "import", "be", "skipped?" ]
train
https://github.com/oyejorge/less.php/blob/42925c5a01a07d67ca7e82dfc8fb31814d557bc9/lib/Less/Tree/Import.php#L290-L303
tillkruss/redis-cache
includes/wp-cli-commands.php
RedisObjectCache_CLI_Commands.status
public function status() { $plugin = $GLOBALS[ 'redisObjectCache' ]; $status = $plugin->get_status(); $client = $plugin->get_redis_client_name(); switch ( $status ) { case __( 'Disabled', 'redis-cache' ): $status = WP_CLI::colorize( "%y{$status}%n" ); break; case __( 'Connected', 'redis-cache' ): $status = WP_CLI::colorize( "%g{$status}%n" ); break; case __( 'Not Connected', 'redis-cache' ): $status = WP_CLI::colorize( "%r{$status}%n" ); break; } WP_CLI::line( 'Status: ' . $status ); if ( ! is_null( $client ) ) { WP_CLI::line( 'Client: ' . $client ); } }
php
public function status() { $plugin = $GLOBALS[ 'redisObjectCache' ]; $status = $plugin->get_status(); $client = $plugin->get_redis_client_name(); switch ( $status ) { case __( 'Disabled', 'redis-cache' ): $status = WP_CLI::colorize( "%y{$status}%n" ); break; case __( 'Connected', 'redis-cache' ): $status = WP_CLI::colorize( "%g{$status}%n" ); break; case __( 'Not Connected', 'redis-cache' ): $status = WP_CLI::colorize( "%r{$status}%n" ); break; } WP_CLI::line( 'Status: ' . $status ); if ( ! is_null( $client ) ) { WP_CLI::line( 'Client: ' . $client ); } }
[ "public", "function", "status", "(", ")", "{", "$", "plugin", "=", "$", "GLOBALS", "[", "'redisObjectCache'", "]", ";", "$", "status", "=", "$", "plugin", "->", "get_status", "(", ")", ";", "$", "client", "=", "$", "plugin", "->", "get_redis_client_name"...
Show the Redis object cache status and (when possible) client. ## EXAMPLES wp redis status
[ "Show", "the", "Redis", "object", "cache", "status", "and", "(", "when", "possible", ")", "client", "." ]
train
https://github.com/tillkruss/redis-cache/blob/84c50fc15f21fec714f30b1202f0fc83e80184f0/includes/wp-cli-commands.php#L15-L40
tillkruss/redis-cache
includes/wp-cli-commands.php
RedisObjectCache_CLI_Commands.enable
public function enable() { global $wp_filesystem; $plugin = $GLOBALS[ 'redisObjectCache' ]; if ( $plugin->object_cache_dropin_exists() ) { if ( $plugin->validate_object_cache_dropin() ) { WP_CLI::line( __( 'Redis object cache already enabled.', 'redis-cache' ) ); } else { WP_CLI::error( __('An unknown object cache drop-in was found. To use Redis run: wp redis update-dropin.', 'redis-cache') ); } } else { WP_Filesystem(); if ( $wp_filesystem->copy( WP_PLUGIN_DIR . '/redis-cache/includes/object-cache.php', WP_CONTENT_DIR . '/object-cache.php', true ) ) { WP_CLI::success( __( 'Object cache enabled.', 'redis-cache' ) ); } else { WP_CLI::error( __( 'Object cache could not be enabled.', 'redis-cache' ) ); } } }
php
public function enable() { global $wp_filesystem; $plugin = $GLOBALS[ 'redisObjectCache' ]; if ( $plugin->object_cache_dropin_exists() ) { if ( $plugin->validate_object_cache_dropin() ) { WP_CLI::line( __( 'Redis object cache already enabled.', 'redis-cache' ) ); } else { WP_CLI::error( __('An unknown object cache drop-in was found. To use Redis run: wp redis update-dropin.', 'redis-cache') ); } } else { WP_Filesystem(); if ( $wp_filesystem->copy( WP_PLUGIN_DIR . '/redis-cache/includes/object-cache.php', WP_CONTENT_DIR . '/object-cache.php', true ) ) { WP_CLI::success( __( 'Object cache enabled.', 'redis-cache' ) ); } else { WP_CLI::error( __( 'Object cache could not be enabled.', 'redis-cache' ) ); } } }
[ "public", "function", "enable", "(", ")", "{", "global", "$", "wp_filesystem", ";", "$", "plugin", "=", "$", "GLOBALS", "[", "'redisObjectCache'", "]", ";", "if", "(", "$", "plugin", "->", "object_cache_dropin_exists", "(", ")", ")", "{", "if", "(", "$",...
Enables the Redis object cache. Default behavior is to create the object cache drop-in, unless an unknown object cache drop-in is present. ## EXAMPLES wp redis enable
[ "Enables", "the", "Redis", "object", "cache", "." ]
train
https://github.com/tillkruss/redis-cache/blob/84c50fc15f21fec714f30b1202f0fc83e80184f0/includes/wp-cli-commands.php#L53-L79
tillkruss/redis-cache
includes/wp-cli-commands.php
RedisObjectCache_CLI_Commands.disable
public function disable() { global $wp_filesystem; $plugin = $GLOBALS[ 'redisObjectCache' ]; if ( ! $plugin->object_cache_dropin_exists() ) { WP_CLI::error( __( 'No object cache drop-in found.', 'redis-cache' ) ); } else { if ( ! $plugin->validate_object_cache_dropin() ) { WP_CLI::error( __( 'An unknown object cache drop-in was found. To use Redis run: wp redis update-dropin.', 'redis-cache' ) ); } else { WP_Filesystem(); if ( $wp_filesystem->delete( WP_CONTENT_DIR . '/object-cache.php' ) ) { WP_CLI::success( __( 'Object cache disabled.', 'redis-cache' ) ); } else { WP_CLI::error( __( 'Object cache could not be disabled.', 'redis-cache' ) ); } } } }
php
public function disable() { global $wp_filesystem; $plugin = $GLOBALS[ 'redisObjectCache' ]; if ( ! $plugin->object_cache_dropin_exists() ) { WP_CLI::error( __( 'No object cache drop-in found.', 'redis-cache' ) ); } else { if ( ! $plugin->validate_object_cache_dropin() ) { WP_CLI::error( __( 'An unknown object cache drop-in was found. To use Redis run: wp redis update-dropin.', 'redis-cache' ) ); } else { WP_Filesystem(); if ( $wp_filesystem->delete( WP_CONTENT_DIR . '/object-cache.php' ) ) { WP_CLI::success( __( 'Object cache disabled.', 'redis-cache' ) ); } else { WP_CLI::error( __( 'Object cache could not be disabled.', 'redis-cache' ) ); } } } }
[ "public", "function", "disable", "(", ")", "{", "global", "$", "wp_filesystem", ";", "$", "plugin", "=", "$", "GLOBALS", "[", "'redisObjectCache'", "]", ";", "if", "(", "!", "$", "plugin", "->", "object_cache_dropin_exists", "(", ")", ")", "{", "WP_CLI", ...
Disables the Redis object cache. Default behavior is to delete the object cache drop-in, unless an unknown object cache drop-in is present. ## EXAMPLES wp redis disable
[ "Disables", "the", "Redis", "object", "cache", "." ]
train
https://github.com/tillkruss/redis-cache/blob/84c50fc15f21fec714f30b1202f0fc83e80184f0/includes/wp-cli-commands.php#L92-L122
tillkruss/redis-cache
includes/wp-cli-commands.php
RedisObjectCache_CLI_Commands.update_dropin
public function update_dropin() { global $wp_filesystem; WP_Filesystem(); if ( $wp_filesystem->copy( WP_PLUGIN_DIR . '/redis-cache/includes/object-cache.php', WP_CONTENT_DIR . '/object-cache.php', true )) { WP_CLI::success( __( 'Updated object cache drop-in and enabled Redis object cache.', 'redis-cache' ) ); } else { WP_CLI::error( __( 'Object cache drop-in could not be updated.', 'redis-cache' ) ); } }
php
public function update_dropin() { global $wp_filesystem; WP_Filesystem(); if ( $wp_filesystem->copy( WP_PLUGIN_DIR . '/redis-cache/includes/object-cache.php', WP_CONTENT_DIR . '/object-cache.php', true )) { WP_CLI::success( __( 'Updated object cache drop-in and enabled Redis object cache.', 'redis-cache' ) ); } else { WP_CLI::error( __( 'Object cache drop-in could not be updated.', 'redis-cache' ) ); } }
[ "public", "function", "update_dropin", "(", ")", "{", "global", "$", "wp_filesystem", ";", "WP_Filesystem", "(", ")", ";", "if", "(", "$", "wp_filesystem", "->", "copy", "(", "WP_PLUGIN_DIR", ".", "'/redis-cache/includes/object-cache.php'", ",", "WP_CONTENT_DIR", ...
Updates the Redis object cache drop-in. Default behavior is to overwrite any existing object cache drop-in. ## EXAMPLES wp redis update-dropin @subcommand update-dropin
[ "Updates", "the", "Redis", "object", "cache", "drop", "-", "in", "." ]
train
https://github.com/tillkruss/redis-cache/blob/84c50fc15f21fec714f30b1202f0fc83e80184f0/includes/wp-cli-commands.php#L135-L147
tillkruss/redis-cache
includes/predis/src/Collection/Iterator/HashKey.php
HashKey.extractNext
protected function extractNext() { if ($kv = each($this->elements)) { $this->position = $kv[0]; $this->current = $kv[1]; unset($this->elements[$this->position]); } }
php
protected function extractNext() { if ($kv = each($this->elements)) { $this->position = $kv[0]; $this->current = $kv[1]; unset($this->elements[$this->position]); } }
[ "protected", "function", "extractNext", "(", ")", "{", "if", "(", "$", "kv", "=", "each", "(", "$", "this", "->", "elements", ")", ")", "{", "$", "this", "->", "position", "=", "$", "kv", "[", "0", "]", ";", "$", "this", "->", "current", "=", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/tillkruss/redis-cache/blob/84c50fc15f21fec714f30b1202f0fc83e80184f0/includes/predis/src/Collection/Iterator/HashKey.php#L51-L59
tillkruss/redis-cache
includes/predis/src/Cluster/Hash/CRC16.php
CRC16.hash
public function hash($value) { // CRC-CCITT-16 algorithm $crc = 0; $CCITT_16 = self::$CCITT_16; $strlen = strlen($value); for ($i = 0; $i < $strlen; ++$i) { $crc = (($crc << 8) ^ $CCITT_16[($crc >> 8) ^ ord($value[$i])]) & 0xFFFF; } return $crc; }
php
public function hash($value) { // CRC-CCITT-16 algorithm $crc = 0; $CCITT_16 = self::$CCITT_16; $strlen = strlen($value); for ($i = 0; $i < $strlen; ++$i) { $crc = (($crc << 8) ^ $CCITT_16[($crc >> 8) ^ ord($value[$i])]) & 0xFFFF; } return $crc; }
[ "public", "function", "hash", "(", "$", "value", ")", "{", "// CRC-CCITT-16 algorithm", "$", "crc", "=", "0", ";", "$", "CCITT_16", "=", "self", "::", "$", "CCITT_16", ";", "$", "strlen", "=", "strlen", "(", "$", "value", ")", ";", "for", "(", "$", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/tillkruss/redis-cache/blob/84c50fc15f21fec714f30b1202f0fc83e80184f0/includes/predis/src/Cluster/Hash/CRC16.php#L59-L71
htmlburger/wpemerge
src/Routing/Conditions/ConditionFactory.php
ConditionFactory.make
public function make( $options ) { if ( is_string( $options ) ) { return $this->makeFromUrl( $options ); } if ( is_array( $options ) ) { return $this->makeFromArray( $options ); } if ( $options instanceof Closure ) { return $this->makeFromClosure( $options ); } throw new ConfigurationException( 'Invalid condition options supplied.' ); }
php
public function make( $options ) { if ( is_string( $options ) ) { return $this->makeFromUrl( $options ); } if ( is_array( $options ) ) { return $this->makeFromArray( $options ); } if ( $options instanceof Closure ) { return $this->makeFromClosure( $options ); } throw new ConfigurationException( 'Invalid condition options supplied.' ); }
[ "public", "function", "make", "(", "$", "options", ")", "{", "if", "(", "is_string", "(", "$", "options", ")", ")", "{", "return", "$", "this", "->", "makeFromUrl", "(", "$", "options", ")", ";", "}", "if", "(", "is_array", "(", "$", "options", ")"...
Create a new condition. @param string|array|Closure $options @return ConditionInterface
[ "Create", "a", "new", "condition", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/ConditionFactory.php#L46-L60
htmlburger/wpemerge
src/Routing/Conditions/ConditionFactory.php
ConditionFactory.getConditionTypeClass
protected function getConditionTypeClass( $condition_type ) { if ( ! isset( $this->condition_types[ $condition_type ] ) ) { return null; } return $this->condition_types[ $condition_type ]; }
php
protected function getConditionTypeClass( $condition_type ) { if ( ! isset( $this->condition_types[ $condition_type ] ) ) { return null; } return $this->condition_types[ $condition_type ]; }
[ "protected", "function", "getConditionTypeClass", "(", "$", "condition_type", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "condition_types", "[", "$", "condition_type", "]", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", ...
Get condition class for condition type. @param string $condition_type @return string|null
[ "Get", "condition", "class", "for", "condition", "type", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/ConditionFactory.php#L82-L88
htmlburger/wpemerge
src/Routing/Conditions/ConditionFactory.php
ConditionFactory.parseNegatedCondition
protected function parseNegatedCondition( $type, $arguments ) { $negated_type = substr( $type, strlen( static::NEGATE_CONDITION_PREFIX ) ); $arguments = array_merge( [ $negated_type ], $arguments ); $type = 'negate'; $condition = call_user_func( [$this, 'make'], $arguments ); return ['type' => $type, 'arguments' => [$condition]]; }
php
protected function parseNegatedCondition( $type, $arguments ) { $negated_type = substr( $type, strlen( static::NEGATE_CONDITION_PREFIX ) ); $arguments = array_merge( [ $negated_type ], $arguments ); $type = 'negate'; $condition = call_user_func( [$this, 'make'], $arguments ); return ['type' => $type, 'arguments' => [$condition]]; }
[ "protected", "function", "parseNegatedCondition", "(", "$", "type", ",", "$", "arguments", ")", "{", "$", "negated_type", "=", "substr", "(", "$", "type", ",", "strlen", "(", "static", "::", "NEGATE_CONDITION_PREFIX", ")", ")", ";", "$", "arguments", "=", ...
Parse a negated condition and its arguments. @param string $type @param array $arguments @return array
[ "Parse", "a", "negated", "condition", "and", "its", "arguments", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/ConditionFactory.php#L125-L133
htmlburger/wpemerge
src/Routing/Conditions/ConditionFactory.php
ConditionFactory.parseConditionOptions
protected function parseConditionOptions( $options ) { $type = $options[0]; $arguments = array_values( array_slice( $options, 1 ) ); if ( $this->isNegatedCondition( $type ) ) { return $this->parseNegatedCondition( $type, $arguments ); } if ( ! $this->conditionTypeRegistered( $type ) ) { if ( is_callable( $type ) ) { return ['type' => 'custom', 'arguments' => $options]; } throw new ConfigurationException( 'Unknown condition type specified: ' . $type ); } return ['type' => $type, 'arguments' => $arguments ]; }
php
protected function parseConditionOptions( $options ) { $type = $options[0]; $arguments = array_values( array_slice( $options, 1 ) ); if ( $this->isNegatedCondition( $type ) ) { return $this->parseNegatedCondition( $type, $arguments ); } if ( ! $this->conditionTypeRegistered( $type ) ) { if ( is_callable( $type ) ) { return ['type' => 'custom', 'arguments' => $options]; } throw new ConfigurationException( 'Unknown condition type specified: ' . $type ); } return ['type' => $type, 'arguments' => $arguments ]; }
[ "protected", "function", "parseConditionOptions", "(", "$", "options", ")", "{", "$", "type", "=", "$", "options", "[", "0", "]", ";", "$", "arguments", "=", "array_values", "(", "array_slice", "(", "$", "options", ",", "1", ")", ")", ";", "if", "(", ...
Parse the condition type and its arguments from an options array. @param array $options @return array
[ "Parse", "the", "condition", "type", "and", "its", "arguments", "from", "an", "options", "array", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/ConditionFactory.php#L141-L158
htmlburger/wpemerge
src/Routing/Conditions/ConditionFactory.php
ConditionFactory.makeFromArray
protected function makeFromArray( $options ) { if ( count( $options ) === 0 ) { throw new ConfigurationException( 'No condition type specified.' ); } if ( is_array( $options[0] ) ) { return $this->makeFromArrayOfConditions( $options ); } $condition_options = $this->parseConditionOptions( $options ); $condition_class = $this->getConditionTypeClass( $condition_options['type'] ); try { $reflection = new ReflectionClass( $condition_class ); /** @var $instance \WPEmerge\Routing\Conditions\ConditionInterface */ $instance = $reflection->newInstanceArgs( $condition_options['arguments'] ); return $instance; } catch ( ReflectionException $e ) { throw new ConfigurationException( 'Condition class "' . $condition_class . '" does not exist.' ); } }
php
protected function makeFromArray( $options ) { if ( count( $options ) === 0 ) { throw new ConfigurationException( 'No condition type specified.' ); } if ( is_array( $options[0] ) ) { return $this->makeFromArrayOfConditions( $options ); } $condition_options = $this->parseConditionOptions( $options ); $condition_class = $this->getConditionTypeClass( $condition_options['type'] ); try { $reflection = new ReflectionClass( $condition_class ); /** @var $instance \WPEmerge\Routing\Conditions\ConditionInterface */ $instance = $reflection->newInstanceArgs( $condition_options['arguments'] ); return $instance; } catch ( ReflectionException $e ) { throw new ConfigurationException( 'Condition class "' . $condition_class . '" does not exist.' ); } }
[ "protected", "function", "makeFromArray", "(", "$", "options", ")", "{", "if", "(", "count", "(", "$", "options", ")", "===", "0", ")", "{", "throw", "new", "ConfigurationException", "(", "'No condition type specified.'", ")", ";", "}", "if", "(", "is_array"...
Create a new condition from an array. @param array $options @return ConditionInterface
[ "Create", "a", "new", "condition", "from", "an", "array", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/ConditionFactory.php#L176-L196
htmlburger/wpemerge
src/Routing/Conditions/ConditionFactory.php
ConditionFactory.makeFromArrayOfConditions
protected function makeFromArrayOfConditions( $options ) { $conditions = array_map( function ( $condition ) { if ( $condition instanceof ConditionInterface ) { return $condition; } return $this->make( $condition ); }, $options ); return new MultipleCondition( $conditions ); }
php
protected function makeFromArrayOfConditions( $options ) { $conditions = array_map( function ( $condition ) { if ( $condition instanceof ConditionInterface ) { return $condition; } return $this->make( $condition ); }, $options ); return new MultipleCondition( $conditions ); }
[ "protected", "function", "makeFromArrayOfConditions", "(", "$", "options", ")", "{", "$", "conditions", "=", "array_map", "(", "function", "(", "$", "condition", ")", "{", "if", "(", "$", "condition", "instanceof", "ConditionInterface", ")", "{", "return", "$"...
Create a new condition from an array of conditions. @param array $options @return ConditionInterface
[ "Create", "a", "new", "condition", "from", "an", "array", "of", "conditions", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/ConditionFactory.php#L204-L213
htmlburger/wpemerge
src/Routing/Conditions/ConditionFactory.php
ConditionFactory.merge
public function merge( $old, $new ) { if ( empty( $old ) ) { if ( empty( $new ) ) { return null; } return $this->condition( $new ); } else if ( empty( $new ) ) { return $this->condition( $old ); } return $this->mergeConditions( $this->condition( $old ), $this->condition( $new ) ); }
php
public function merge( $old, $new ) { if ( empty( $old ) ) { if ( empty( $new ) ) { return null; } return $this->condition( $new ); } else if ( empty( $new ) ) { return $this->condition( $old ); } return $this->mergeConditions( $this->condition( $old ), $this->condition( $new ) ); }
[ "public", "function", "merge", "(", "$", "old", ",", "$", "new", ")", "{", "if", "(", "empty", "(", "$", "old", ")", ")", "{", "if", "(", "empty", "(", "$", "new", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "condi...
Merge group condition attribute. @param string|array|Closure|ConditionInterface|null $old @param string|array|Closure|ConditionInterface|null $new @return ConditionInterface|null
[ "Merge", "group", "condition", "attribute", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/ConditionFactory.php#L232-L243
htmlburger/wpemerge
src/Routing/Conditions/ConditionFactory.php
ConditionFactory.mergeConditions
public function mergeConditions( ConditionInterface $old, ConditionInterface $new ) { if ( $old instanceof UrlCondition && $new instanceof UrlCondition ) { return $old->concatenate( $new->getUrl(), $new->getUrlWhere() ); } return $this->makeFromArrayOfConditions( [$old, $new] ); }
php
public function mergeConditions( ConditionInterface $old, ConditionInterface $new ) { if ( $old instanceof UrlCondition && $new instanceof UrlCondition ) { return $old->concatenate( $new->getUrl(), $new->getUrlWhere() ); } return $this->makeFromArrayOfConditions( [$old, $new] ); }
[ "public", "function", "mergeConditions", "(", "ConditionInterface", "$", "old", ",", "ConditionInterface", "$", "new", ")", "{", "if", "(", "$", "old", "instanceof", "UrlCondition", "&&", "$", "new", "instanceof", "UrlCondition", ")", "{", "return", "$", "old"...
Merge condition instances. @param ConditionInterface $old @param ConditionInterface $new @return ConditionInterface
[ "Merge", "condition", "instances", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/ConditionFactory.php#L252-L258
htmlburger/wpemerge
src/Middleware/HasMiddlewareDefinitionsTrait.php
HasMiddlewareDefinitionsTrait.expandMiddleware
public function expandMiddleware( $middleware ) { $classes = []; foreach ( $middleware as $item ) { $classes = array_merge( $classes, $this->expandMiddlewareMolecule( $item ) ); } return $classes; }
php
public function expandMiddleware( $middleware ) { $classes = []; foreach ( $middleware as $item ) { $classes = array_merge( $classes, $this->expandMiddlewareMolecule( $item ) ); } return $classes; }
[ "public", "function", "expandMiddleware", "(", "$", "middleware", ")", "{", "$", "classes", "=", "[", "]", ";", "foreach", "(", "$", "middleware", "as", "$", "item", ")", "{", "$", "classes", "=", "array_merge", "(", "$", "classes", ",", "$", "this", ...
Expand array of middleware into an array of fully qualified class names. @param array<string> $middleware @return array<array>
[ "Expand", "array", "of", "middleware", "into", "an", "array", "of", "fully", "qualified", "class", "names", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Middleware/HasMiddlewareDefinitionsTrait.php#L81-L92
htmlburger/wpemerge
src/Middleware/HasMiddlewareDefinitionsTrait.php
HasMiddlewareDefinitionsTrait.expandMiddlewareGroup
public function expandMiddlewareGroup( $group ) { if ( ! isset( $this->middleware_groups[ $group ] ) ) { throw new ConfigurationException( 'Unknown middleware group "' . $group . '" used.' ); } $middleware = $this->middleware_groups[ $group ]; if ( in_array( $group, $this->middleware_groups_with_global, true ) ) { $middleware = array_merge( ['global'], $middleware ); } return $this->expandMiddleware( $middleware ); }
php
public function expandMiddlewareGroup( $group ) { if ( ! isset( $this->middleware_groups[ $group ] ) ) { throw new ConfigurationException( 'Unknown middleware group "' . $group . '" used.' ); } $middleware = $this->middleware_groups[ $group ]; if ( in_array( $group, $this->middleware_groups_with_global, true ) ) { $middleware = array_merge( ['global'], $middleware ); } return $this->expandMiddleware( $middleware ); }
[ "public", "function", "expandMiddlewareGroup", "(", "$", "group", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "middleware_groups", "[", "$", "group", "]", ")", ")", "{", "throw", "new", "ConfigurationException", "(", "'Unknown middleware group \...
Expand a middleware group into an array of fully qualified class names. @param string $group @return array<array>
[ "Expand", "a", "middleware", "group", "into", "an", "array", "of", "fully", "qualified", "class", "names", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Middleware/HasMiddlewareDefinitionsTrait.php#L100-L112
htmlburger/wpemerge
src/Middleware/HasMiddlewareDefinitionsTrait.php
HasMiddlewareDefinitionsTrait.expandMiddlewareMolecule
public function expandMiddlewareMolecule( $middleware ) { $pieces = explode( ':', $middleware, 2 ); if ( count( $pieces ) > 1 ) { return [array_merge( [$this->expandMiddlewareAtom( $pieces[0] )], explode( ',', $pieces[1] ) )]; } if ( isset( $this->middleware_groups[ $middleware ] ) ) { return $this->expandMiddlewareGroup( $middleware ); } return [[$this->expandMiddlewareAtom( $middleware )]]; }
php
public function expandMiddlewareMolecule( $middleware ) { $pieces = explode( ':', $middleware, 2 ); if ( count( $pieces ) > 1 ) { return [array_merge( [$this->expandMiddlewareAtom( $pieces[0] )], explode( ',', $pieces[1] ) )]; } if ( isset( $this->middleware_groups[ $middleware ] ) ) { return $this->expandMiddlewareGroup( $middleware ); } return [[$this->expandMiddlewareAtom( $middleware )]]; }
[ "public", "function", "expandMiddlewareMolecule", "(", "$", "middleware", ")", "{", "$", "pieces", "=", "explode", "(", "':'", ",", "$", "middleware", ",", "2", ")", ";", "if", "(", "count", "(", "$", "pieces", ")", ">", "1", ")", "{", "return", "[",...
Expand middleware into an array of fully qualified class names and any companion arguments. @param string $middleware @return array<array>
[ "Expand", "middleware", "into", "an", "array", "of", "fully", "qualified", "class", "names", "and", "any", "companion", "arguments", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Middleware/HasMiddlewareDefinitionsTrait.php#L120-L132
htmlburger/wpemerge
src/Middleware/HasMiddlewareDefinitionsTrait.php
HasMiddlewareDefinitionsTrait.expandMiddlewareAtom
public function expandMiddlewareAtom( $middleware ) { if ( isset( $this->middleware[ $middleware ] ) ) { return $this->middleware[ $middleware ]; } if ( class_exists( $middleware ) ) { return $middleware; } throw new ConfigurationException( 'Unknown middleware "' . $middleware . '" used.' ); }
php
public function expandMiddlewareAtom( $middleware ) { if ( isset( $this->middleware[ $middleware ] ) ) { return $this->middleware[ $middleware ]; } if ( class_exists( $middleware ) ) { return $middleware; } throw new ConfigurationException( 'Unknown middleware "' . $middleware . '" used.' ); }
[ "public", "function", "expandMiddlewareAtom", "(", "$", "middleware", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "middleware", "[", "$", "middleware", "]", ")", ")", "{", "return", "$", "this", "->", "middleware", "[", "$", "middleware", "]", ...
Expand a single middleware a fully qualified class name. @param string $middleware @return string
[ "Expand", "a", "single", "middleware", "a", "fully", "qualified", "class", "name", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Middleware/HasMiddlewareDefinitionsTrait.php#L140-L150
htmlburger/wpemerge
src/Routing/RoutingServiceProvider.php
RoutingServiceProvider.register
public function register( $container ) { $this->extendConfig( $container, 'routes', [ 'web' => '', 'ajax' => '', 'admin' => '', ] ); /** @var $container \Pimple\Container */ $container[ WPEMERGE_ROUTING_CONDITION_TYPES_KEY ] = static::$condition_types; $container[ WPEMERGE_ROUTING_ROUTER_KEY ] = function ( $c ) { return new Router( $c[ WPEMERGE_ROUTING_CONDITIONS_CONDITION_FACTORY_KEY ] ); }; $container[ WPEMERGE_ROUTING_CONDITIONS_CONDITION_FACTORY_KEY ] = function ( $c ) { return new ConditionFactory( $c[ WPEMERGE_ROUTING_CONDITION_TYPES_KEY ] ); }; $container[ WPEMERGE_ROUTING_ROUTE_BLUEPRINT_KEY ] = $container->factory( function ( $c ) { return new RouteBlueprint( $c[ WPEMERGE_ROUTING_ROUTER_KEY ] ); } ); Application::alias( 'Route', RouteFacade::class ); }
php
public function register( $container ) { $this->extendConfig( $container, 'routes', [ 'web' => '', 'ajax' => '', 'admin' => '', ] ); /** @var $container \Pimple\Container */ $container[ WPEMERGE_ROUTING_CONDITION_TYPES_KEY ] = static::$condition_types; $container[ WPEMERGE_ROUTING_ROUTER_KEY ] = function ( $c ) { return new Router( $c[ WPEMERGE_ROUTING_CONDITIONS_CONDITION_FACTORY_KEY ] ); }; $container[ WPEMERGE_ROUTING_CONDITIONS_CONDITION_FACTORY_KEY ] = function ( $c ) { return new ConditionFactory( $c[ WPEMERGE_ROUTING_CONDITION_TYPES_KEY ] ); }; $container[ WPEMERGE_ROUTING_ROUTE_BLUEPRINT_KEY ] = $container->factory( function ( $c ) { return new RouteBlueprint( $c[ WPEMERGE_ROUTING_ROUTER_KEY ] ); } ); Application::alias( 'Route', RouteFacade::class ); }
[ "public", "function", "register", "(", "$", "container", ")", "{", "$", "this", "->", "extendConfig", "(", "$", "container", ",", "'routes'", ",", "[", "'web'", "=>", "''", ",", "'ajax'", "=>", "''", ",", "'admin'", "=>", "''", ",", "]", ")", ";", ...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/RoutingServiceProvider.php#L49-L73
htmlburger/wpemerge
src/Responses/ResponsesServiceProvider.php
ResponsesServiceProvider.register
public function register( $container ) { $container[ WPEMERGE_RESPONSE_SERVICE_KEY ] = function ( $c ) { return new ResponseService( $c[ WPEMERGE_REQUEST_KEY ] ); }; Application::alias( 'Response', ResponseFacade::class ); }
php
public function register( $container ) { $container[ WPEMERGE_RESPONSE_SERVICE_KEY ] = function ( $c ) { return new ResponseService( $c[ WPEMERGE_REQUEST_KEY ] ); }; Application::alias( 'Response', ResponseFacade::class ); }
[ "public", "function", "register", "(", "$", "container", ")", "{", "$", "container", "[", "WPEMERGE_RESPONSE_SERVICE_KEY", "]", "=", "function", "(", "$", "c", ")", "{", "return", "new", "ResponseService", "(", "$", "c", "[", "WPEMERGE_REQUEST_KEY", "]", ")"...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Responses/ResponsesServiceProvider.php#L25-L31
htmlburger/wpemerge
src/Routing/HasQueryFilterTrait.php
HasQueryFilterTrait.applyQueryFilter
public function applyQueryFilter( $request, $query_vars ) { $condition = $this->getCondition(); if ( $this->getQueryFilter() === null ) { return $query_vars; } if ( ! $condition instanceof UrlCondition ) { throw new ConfigurationException( 'Only routes with URL condition can use queries. ' . 'Make sure your route has a URL condition and it is not in a non-URL route group.' ); } $arguments = $this->getCondition()->getArguments( $request ); return call_user_func_array( $this->getQueryFilter(), array_merge( [$query_vars], array_values( $arguments ) ) ); }
php
public function applyQueryFilter( $request, $query_vars ) { $condition = $this->getCondition(); if ( $this->getQueryFilter() === null ) { return $query_vars; } if ( ! $condition instanceof UrlCondition ) { throw new ConfigurationException( 'Only routes with URL condition can use queries. ' . 'Make sure your route has a URL condition and it is not in a non-URL route group.' ); } $arguments = $this->getCondition()->getArguments( $request ); return call_user_func_array( $this->getQueryFilter(), array_merge( [$query_vars], array_values( $arguments ) ) ); }
[ "public", "function", "applyQueryFilter", "(", "$", "request", ",", "$", "query_vars", ")", "{", "$", "condition", "=", "$", "this", "->", "getCondition", "(", ")", ";", "if", "(", "$", "this", "->", "getQueryFilter", "(", ")", "===", "null", ")", "{",...
Apply the query filter, if any. @param RequestInterface $request @param array $query_vars @return array
[ "Apply", "the", "query", "filter", "if", "any", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/HasQueryFilterTrait.php#L57-L77
htmlburger/wpemerge
src/Middleware/ExecutesMiddlewareTrait.php
ExecutesMiddlewareTrait.executeMiddleware
public function executeMiddleware( $middleware, RequestInterface $request, Closure $next ) { $top_middleware = array_shift( $middleware ); if ( $top_middleware === null ) { return $next( $request ); } $top_middleware_next = function ( $request ) use ( $middleware, $next ) { return $this->executeMiddleware( $middleware, $request, $next ); }; $class = $top_middleware[0]; $arguments = array_merge( [$request, $top_middleware_next], array_slice( $top_middleware, 1 ) ); $instance = Application::instantiate( $class ); return call_user_func_array( [$instance, 'handle'], $arguments ); }
php
public function executeMiddleware( $middleware, RequestInterface $request, Closure $next ) { $top_middleware = array_shift( $middleware ); if ( $top_middleware === null ) { return $next( $request ); } $top_middleware_next = function ( $request ) use ( $middleware, $next ) { return $this->executeMiddleware( $middleware, $request, $next ); }; $class = $top_middleware[0]; $arguments = array_merge( [$request, $top_middleware_next], array_slice( $top_middleware, 1 ) ); $instance = Application::instantiate( $class ); return call_user_func_array( [$instance, 'handle'], $arguments ); }
[ "public", "function", "executeMiddleware", "(", "$", "middleware", ",", "RequestInterface", "$", "request", ",", "Closure", "$", "next", ")", "{", "$", "top_middleware", "=", "array_shift", "(", "$", "middleware", ")", ";", "if", "(", "$", "top_middleware", ...
Execute an array of middleware recursively (last in, first out). @param array<array<string>> $middleware @param RequestInterface $request @param Closure $next @return \Psr\Http\Message\ResponseInterface
[ "Execute", "an", "array", "of", "middleware", "recursively", "(", "last", "in", "first", "out", ")", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Middleware/ExecutesMiddlewareTrait.php#L28-L47
htmlburger/wpemerge
src/Routing/Router.php
Router.mergeConditionAttribute
public function mergeConditionAttribute( $old, $new ) { try { $condition = $this->condition_factory->merge( $old, $new ); } catch ( ConfigurationException $e ) { throw new ConfigurationException( 'Route condition is not a valid route string or condition.' ); } return $condition; }
php
public function mergeConditionAttribute( $old, $new ) { try { $condition = $this->condition_factory->merge( $old, $new ); } catch ( ConfigurationException $e ) { throw new ConfigurationException( 'Route condition is not a valid route string or condition.' ); } return $condition; }
[ "public", "function", "mergeConditionAttribute", "(", "$", "old", ",", "$", "new", ")", "{", "try", "{", "$", "condition", "=", "$", "this", "->", "condition_factory", "->", "merge", "(", "$", "old", ",", "$", "new", ")", ";", "}", "catch", "(", "Con...
Merge the condition attribute. @param string|array|\Closure|ConditionInterface|null $old @param string|array|\Closure|ConditionInterface|null $new @return ConditionInterface|string
[ "Merge", "the", "condition", "attribute", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Router.php#L93-L101
htmlburger/wpemerge
src/Routing/Router.php
Router.mergeQueryAttribute
public function mergeQueryAttribute( $old, $new ) { if ( $new === null ) { return $old; } if ( $old === null ) { return $new; } return function ( $query_vars ) use ( $old, $new ) { return call_user_func( $new, call_user_func( $old, $query_vars ) ); }; }
php
public function mergeQueryAttribute( $old, $new ) { if ( $new === null ) { return $old; } if ( $old === null ) { return $new; } return function ( $query_vars ) use ( $old, $new ) { return call_user_func( $new, call_user_func( $old, $query_vars ) ); }; }
[ "public", "function", "mergeQueryAttribute", "(", "$", "old", ",", "$", "new", ")", "{", "if", "(", "$", "new", "===", "null", ")", "{", "return", "$", "old", ";", "}", "if", "(", "$", "old", "===", "null", ")", "{", "return", "$", "new", ";", ...
Merge the handler attribute taking the latest value. @param callable|null $old @param callable|null $new @return string|\Closure
[ "Merge", "the", "handler", "attribute", "taking", "the", "latest", "value", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Router.php#L143-L155
htmlburger/wpemerge
src/Routing/Router.php
Router.mergeAttributes
public function mergeAttributes( $old, $new ) { $attributes = [ 'methods' => $this->mergeMethodsAttribute( (array) Arr::get( $old, 'methods', [] ), (array) Arr::get( $new, 'methods', [] ) ), 'condition' => $this->mergeConditionAttribute( Arr::get( $old, 'condition', null ), Arr::get( $new, 'condition', null ) ), 'middleware' => $this->mergeMiddlewareAttribute( (array) Arr::get( $old, 'middleware', [] ), (array) Arr::get( $new, 'middleware', [] ) ), 'namespace' => $this->mergeNamespaceAttribute( Arr::get( $old, 'namespace', '' ), Arr::get( $new, 'namespace', '' ) ), 'handler' => $this->mergeHandlerAttribute( Arr::get( $old, 'handler', '' ), Arr::get( $new, 'handler', '' ) ), 'query' => $this->mergeQueryAttribute( Arr::get( $old, 'query', null ), Arr::get( $new, 'query', null ) ), ]; return $attributes; }
php
public function mergeAttributes( $old, $new ) { $attributes = [ 'methods' => $this->mergeMethodsAttribute( (array) Arr::get( $old, 'methods', [] ), (array) Arr::get( $new, 'methods', [] ) ), 'condition' => $this->mergeConditionAttribute( Arr::get( $old, 'condition', null ), Arr::get( $new, 'condition', null ) ), 'middleware' => $this->mergeMiddlewareAttribute( (array) Arr::get( $old, 'middleware', [] ), (array) Arr::get( $new, 'middleware', [] ) ), 'namespace' => $this->mergeNamespaceAttribute( Arr::get( $old, 'namespace', '' ), Arr::get( $new, 'namespace', '' ) ), 'handler' => $this->mergeHandlerAttribute( Arr::get( $old, 'handler', '' ), Arr::get( $new, 'handler', '' ) ), 'query' => $this->mergeQueryAttribute( Arr::get( $old, 'query', null ), Arr::get( $new, 'query', null ) ), ]; return $attributes; }
[ "public", "function", "mergeAttributes", "(", "$", "old", ",", "$", "new", ")", "{", "$", "attributes", "=", "[", "'methods'", "=>", "$", "this", "->", "mergeMethodsAttribute", "(", "(", "array", ")", "Arr", "::", "get", "(", "$", "old", ",", "'methods...
Merge attributes into route. @param array<string, mixed> $old @param array<string, mixed> $new @return array<string, mixed>
[ "Merge", "attributes", "into", "route", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Router.php#L164-L198
htmlburger/wpemerge
src/Routing/Router.php
Router.group
public function group( $attributes, $routes ) { $this->pushGroup( $attributes ); if ( is_string( $routes ) ) { /** @noinspection PhpIncludeInspection */ /** @codeCoverageIgnore */ require_once $routes; } else { $routes(); } $this->popGroup(); }
php
public function group( $attributes, $routes ) { $this->pushGroup( $attributes ); if ( is_string( $routes ) ) { /** @noinspection PhpIncludeInspection */ /** @codeCoverageIgnore */ require_once $routes; } else { $routes(); } $this->popGroup(); }
[ "public", "function", "group", "(", "$", "attributes", ",", "$", "routes", ")", "{", "$", "this", "->", "pushGroup", "(", "$", "attributes", ")", ";", "if", "(", "is_string", "(", "$", "routes", ")", ")", "{", "/** @noinspection PhpIncludeInspection */", "...
Create a route group. @codeCoverageIgnore @param array<string, mixed> $attributes @param \Closure|string $routes Closure or path to file. @return void
[ "Create", "a", "route", "group", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Router.php#L239-L251
htmlburger/wpemerge
src/Routing/Router.php
Router.routeCondition
protected function routeCondition( $condition ) { if ( $condition === null ) { throw new ConfigurationException( 'No route condition specified. Did you miss to call url() or where()?' ); } if ( ! $condition instanceof ConditionInterface ) { $condition = $this->condition_factory->make( $condition ); } return $condition; }
php
protected function routeCondition( $condition ) { if ( $condition === null ) { throw new ConfigurationException( 'No route condition specified. Did you miss to call url() or where()?' ); } if ( ! $condition instanceof ConditionInterface ) { $condition = $this->condition_factory->make( $condition ); } return $condition; }
[ "protected", "function", "routeCondition", "(", "$", "condition", ")", "{", "if", "(", "$", "condition", "===", "null", ")", "{", "throw", "new", "ConfigurationException", "(", "'No route condition specified. Did you miss to call url() or where()?'", ")", ";", "}", "i...
Make a route condition. @param mixed $condition @return ConditionInterface
[ "Make", "a", "route", "condition", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Router.php#L259-L269
htmlburger/wpemerge
src/Routing/Router.php
Router.route
public function route( $attributes ) { $attributes = $this->mergeAttributes( $this->getGroup(), $attributes ); $methods = Arr::get( $attributes, 'methods', [] ); $condition = Arr::get( $attributes, 'condition', null ); $handler = Arr::get( $attributes, 'handler', '' ); $namespace = Arr::get( $attributes, 'namespace', '' ); if ( empty( $methods ) ) { throw new ConfigurationException( 'Route does not have any assigned request methods. ' . 'Did you miss to call get() or post() on your route definition, for example?' ); } $condition = $this->routeCondition( $condition ); $handler = $this->routeHandler( $handler, $namespace ); $route = new Route( $methods, $condition, $handler ); $route->decorate( $attributes ); return $route; }
php
public function route( $attributes ) { $attributes = $this->mergeAttributes( $this->getGroup(), $attributes ); $methods = Arr::get( $attributes, 'methods', [] ); $condition = Arr::get( $attributes, 'condition', null ); $handler = Arr::get( $attributes, 'handler', '' ); $namespace = Arr::get( $attributes, 'namespace', '' ); if ( empty( $methods ) ) { throw new ConfigurationException( 'Route does not have any assigned request methods. ' . 'Did you miss to call get() or post() on your route definition, for example?' ); } $condition = $this->routeCondition( $condition ); $handler = $this->routeHandler( $handler, $namespace ); $route = new Route( $methods, $condition, $handler ); $route->decorate( $attributes ); return $route; }
[ "public", "function", "route", "(", "$", "attributes", ")", "{", "$", "attributes", "=", "$", "this", "->", "mergeAttributes", "(", "$", "this", "->", "getGroup", "(", ")", ",", "$", "attributes", ")", ";", "$", "methods", "=", "Arr", "::", "get", "(...
Make a route. @param array<string, mixed> $attributes @return RouteInterface
[ "Make", "a", "route", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Router.php#L289-L312
htmlburger/wpemerge
src/Routing/Router.php
Router.execute
public function execute( $request ) { /** @var $routes \WPEmerge\Routing\RouteInterface[] */ $routes = $this->getRoutes(); foreach ( $routes as $route ) { if ( $route->isSatisfied( $request ) ) { $this->setCurrentRoute( $route ); return $route; } } return null; }
php
public function execute( $request ) { /** @var $routes \WPEmerge\Routing\RouteInterface[] */ $routes = $this->getRoutes(); foreach ( $routes as $route ) { if ( $route->isSatisfied( $request ) ) { $this->setCurrentRoute( $route ); return $route; } } return null; }
[ "public", "function", "execute", "(", "$", "request", ")", "{", "/** @var $routes \\WPEmerge\\Routing\\RouteInterface[] */", "$", "routes", "=", "$", "this", "->", "getRoutes", "(", ")", ";", "foreach", "(", "$", "routes", "as", "$", "route", ")", "{", "if", ...
Assign and return the first satisfied route (if any) as the current one for the given request. @param RequestInterface $request @return RouteInterface
[ "Assign", "and", "return", "the", "first", "satisfied", "route", "(", "if", "any", ")", "as", "the", "current", "one", "for", "the", "given", "request", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Router.php#L320-L332
htmlburger/wpemerge
src/Routing/PipelineHandler.php
PipelineHandler.getResponse
protected function getResponse( $response ) { if ( is_string( $response ) ) { return Response::output( $response ); } if ( is_array( $response ) ) { return Response::json( $response ); } if ( $response instanceof ResponsableInterface ) { return $response->toResponse(); } return $response; }
php
protected function getResponse( $response ) { if ( is_string( $response ) ) { return Response::output( $response ); } if ( is_array( $response ) ) { return Response::json( $response ); } if ( $response instanceof ResponsableInterface ) { return $response->toResponse(); } return $response; }
[ "protected", "function", "getResponse", "(", "$", "response", ")", "{", "if", "(", "is_string", "(", "$", "response", ")", ")", "{", "return", "Response", "::", "output", "(", "$", "response", ")", ";", "}", "if", "(", "is_array", "(", "$", "response",...
Convert a user returned response to a ResponseInterface instance if possible. Return the original value if unsupported. @param mixed $response @return mixed
[ "Convert", "a", "user", "returned", "response", "to", "a", "ResponseInterface", "instance", "if", "possible", ".", "Return", "the", "original", "value", "if", "unsupported", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/PipelineHandler.php#L54-L68
htmlburger/wpemerge
src/Routing/PipelineHandler.php
PipelineHandler.execute
public function execute() { $response = call_user_func_array( [$this->handler, 'execute'], func_get_args() ); $response = $this->getResponse( $response ); if ( ! $response instanceof ResponseInterface ) { throw new ConfigurationException( 'Response returned by controller is not valid ' . '(expected ' . ResponseInterface::class . '; received ' . gettype( $response ) . ').' ); } return $response; }
php
public function execute() { $response = call_user_func_array( [$this->handler, 'execute'], func_get_args() ); $response = $this->getResponse( $response ); if ( ! $response instanceof ResponseInterface ) { throw new ConfigurationException( 'Response returned by controller is not valid ' . '(expected ' . ResponseInterface::class . '; received ' . gettype( $response ) . ').' ); } return $response; }
[ "public", "function", "execute", "(", ")", "{", "$", "response", "=", "call_user_func_array", "(", "[", "$", "this", "->", "handler", ",", "'execute'", "]", ",", "func_get_args", "(", ")", ")", ";", "$", "response", "=", "$", "this", "->", "getResponse",...
Execute the handler @param mixed ,...$arguments @return ResponseInterface
[ "Execute", "the", "handler" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/PipelineHandler.php#L76-L88
htmlburger/wpemerge
src/View/HasContextTrait.php
HasContextTrait.getContext
public function getContext( $key = null, $default = null ) { if ( $key === null ) { return $this->context; } return Arr::get( $this->context, $key, $default ); }
php
public function getContext( $key = null, $default = null ) { if ( $key === null ) { return $this->context; } return Arr::get( $this->context, $key, $default ); }
[ "public", "function", "getContext", "(", "$", "key", "=", "null", ",", "$", "default", "=", "null", ")", "{", "if", "(", "$", "key", "===", "null", ")", "{", "return", "$", "this", "->", "context", ";", "}", "return", "Arr", "::", "get", "(", "$"...
Get context values. @param string|null $key @param mixed|null $default @return mixed
[ "Get", "context", "values", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/HasContextTrait.php#L29-L35
htmlburger/wpemerge
src/View/HasContextTrait.php
HasContextTrait.with
public function with( $key, $value = null ) { if ( is_array( $key ) ) { $this->context = array_merge( $this->getContext(), $key ); } else { $this->context[ $key ] = $value; } return $this; }
php
public function with( $key, $value = null ) { if ( is_array( $key ) ) { $this->context = array_merge( $this->getContext(), $key ); } else { $this->context[ $key ] = $value; } return $this; }
[ "public", "function", "with", "(", "$", "key", ",", "$", "value", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "$", "this", "->", "context", "=", "array_merge", "(", "$", "this", "->", "getContext", "(", ")", ",",...
Add context values. @param string|array<string, mixed> $key @param mixed $value @return static $this
[ "Add", "context", "values", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/View/HasContextTrait.php#L44-L51
htmlburger/wpemerge
src/Input/OldInputMiddleware.php
OldInputMiddleware.handle
public function handle( RequestInterface $request, Closure $next ) { if ( OldInputService::enabled() && $request->isPost() ) { OldInputService::set( $request->post() ); } return $next( $request ); }
php
public function handle( RequestInterface $request, Closure $next ) { if ( OldInputService::enabled() && $request->isPost() ) { OldInputService::set( $request->post() ); } return $next( $request ); }
[ "public", "function", "handle", "(", "RequestInterface", "$", "request", ",", "Closure", "$", "next", ")", "{", "if", "(", "OldInputService", "::", "enabled", "(", ")", "&&", "$", "request", "->", "isPost", "(", ")", ")", "{", "OldInputService", "::", "s...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Input/OldInputMiddleware.php#L23-L29
htmlburger/wpemerge
src/Helpers/Url.php
Url.getPath
public static function getPath( RequestInterface $request ) { $url = $request->getUrl(); $relative_url = substr( $url, strlen( home_url( '/' ) ) ); $relative_url = static::addLeadingSlash( $relative_url ); $relative_url = preg_replace( '~\?.*~', '', $relative_url ); $relative_url = static::addTrailingSlash( $relative_url ); return $relative_url; }
php
public static function getPath( RequestInterface $request ) { $url = $request->getUrl(); $relative_url = substr( $url, strlen( home_url( '/' ) ) ); $relative_url = static::addLeadingSlash( $relative_url ); $relative_url = preg_replace( '~\?.*~', '', $relative_url ); $relative_url = static::addTrailingSlash( $relative_url ); return $relative_url; }
[ "public", "static", "function", "getPath", "(", "RequestInterface", "$", "request", ")", "{", "$", "url", "=", "$", "request", "->", "getUrl", "(", ")", ";", "$", "relative_url", "=", "substr", "(", "$", "url", ",", "strlen", "(", "home_url", "(", "'/'...
Get the path for the request relative to the home url @param RequestInterface $request @return string
[ "Get", "the", "path", "for", "the", "request", "relative", "to", "the", "home", "url" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Helpers/Url.php#L24-L31
htmlburger/wpemerge
src/Routing/RouteBlueprint.php
RouteBlueprint.setAttribute
public function setAttribute( $key, $value ) { $this->setAttributes( array_merge( $this->getAttributes(), [$key => $value] ) ); }
php
public function setAttribute( $key, $value ) { $this->setAttributes( array_merge( $this->getAttributes(), [$key => $value] ) ); }
[ "public", "function", "setAttribute", "(", "$", "key", ",", "$", "value", ")", "{", "$", "this", "->", "setAttributes", "(", "array_merge", "(", "$", "this", "->", "getAttributes", "(", ")", ",", "[", "$", "key", "=>", "$", "value", "]", ")", ")", ...
Set attribute. @param string $key @param mixed $value @return void
[ "Set", "attribute", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/RouteBlueprint.php#L94-L99
htmlburger/wpemerge
src/Routing/RouteBlueprint.php
RouteBlueprint.methods
public function methods( $methods ) { $methods = array_merge( $this->getAttribute( 'methods', [] ), $methods ); return $this->attribute( 'methods', $methods ); }
php
public function methods( $methods ) { $methods = array_merge( $this->getAttribute( 'methods', [] ), $methods ); return $this->attribute( 'methods', $methods ); }
[ "public", "function", "methods", "(", "$", "methods", ")", "{", "$", "methods", "=", "array_merge", "(", "$", "this", "->", "getAttribute", "(", "'methods'", ",", "[", "]", ")", ",", "$", "methods", ")", ";", "return", "$", "this", "->", "attribute", ...
Match requests using one of the specified methods. @param array<string> $methods @return static $this
[ "Match", "requests", "using", "one", "of", "the", "specified", "methods", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/RouteBlueprint.php#L121-L128
htmlburger/wpemerge
src/Routing/RouteBlueprint.php
RouteBlueprint.where
public function where( $condition ) { if ( ! $condition instanceof ConditionInterface ) { $condition = func_get_args(); } $condition = $this->router->mergeConditionAttribute( $this->getAttribute( 'condition' ), $condition ); return $this->attribute( 'condition', $condition ); }
php
public function where( $condition ) { if ( ! $condition instanceof ConditionInterface ) { $condition = func_get_args(); } $condition = $this->router->mergeConditionAttribute( $this->getAttribute( 'condition' ), $condition ); return $this->attribute( 'condition', $condition ); }
[ "public", "function", "where", "(", "$", "condition", ")", "{", "if", "(", "!", "$", "condition", "instanceof", "ConditionInterface", ")", "{", "$", "condition", "=", "func_get_args", "(", ")", ";", "}", "$", "condition", "=", "$", "this", "->", "router"...
Set the condition attribute. @param string|array|ConditionInterface $condition @param mixed ,...$arguments @return static $this
[ "Set", "the", "condition", "attribute", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/RouteBlueprint.php#L148-L159
htmlburger/wpemerge
src/Routing/RouteBlueprint.php
RouteBlueprint.middleware
public function middleware( $middleware ) { $middleware = array_merge( (array) $this->getAttribute( 'middleware', [] ), (array) $middleware ); return $this->attribute( 'middleware', $middleware ); }
php
public function middleware( $middleware ) { $middleware = array_merge( (array) $this->getAttribute( 'middleware', [] ), (array) $middleware ); return $this->attribute( 'middleware', $middleware ); }
[ "public", "function", "middleware", "(", "$", "middleware", ")", "{", "$", "middleware", "=", "array_merge", "(", "(", "array", ")", "$", "this", "->", "getAttribute", "(", "'middleware'", ",", "[", "]", ")", ",", "(", "array", ")", "$", "middleware", ...
Set the middleware attribute. @param string|array<string> $middleware @return static $this
[ "Set", "the", "middleware", "attribute", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/RouteBlueprint.php#L167-L174
htmlburger/wpemerge
src/Routing/RouteBlueprint.php
RouteBlueprint.query
public function query( $query ) { $query = $this->router->mergeQueryAttribute( $this->getAttribute( 'query', null ), $query ); return $this->attribute( 'query', $query ); }
php
public function query( $query ) { $query = $this->router->mergeQueryAttribute( $this->getAttribute( 'query', null ), $query ); return $this->attribute( 'query', $query ); }
[ "public", "function", "query", "(", "$", "query", ")", "{", "$", "query", "=", "$", "this", "->", "router", "->", "mergeQueryAttribute", "(", "$", "this", "->", "getAttribute", "(", "'query'", ",", "null", ")", ",", "$", "query", ")", ";", "return", ...
Set the query attribute. @param callable $query @return static $this
[ "Set", "the", "query", "attribute", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/RouteBlueprint.php#L194-L201
htmlburger/wpemerge
src/Routing/RouteBlueprint.php
RouteBlueprint.handle
public function handle( $handler = '' ) { if ( ! empty( $handler ) ) { $this->attribute( 'handler', $handler ); } $this->router->addRoute( $this->router->route( $this->getAttributes() ) ); }
php
public function handle( $handler = '' ) { if ( ! empty( $handler ) ) { $this->attribute( 'handler', $handler ); } $this->router->addRoute( $this->router->route( $this->getAttributes() ) ); }
[ "public", "function", "handle", "(", "$", "handler", "=", "''", ")", "{", "if", "(", "!", "empty", "(", "$", "handler", ")", ")", "{", "$", "this", "->", "attribute", "(", "'handler'", ",", "$", "handler", ")", ";", "}", "$", "this", "->", "route...
Create a route. @param string|\Closure $handler @return void
[ "Create", "a", "route", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/RouteBlueprint.php#L219-L225
htmlburger/wpemerge
src/Kernels/KernelsServiceProvider.php
KernelsServiceProvider.register
public function register( $container ) { $this->extendConfig( $container, 'middleware', [ 'flash' => \WPEmerge\Flash\FlashMiddleware::class, 'oldinput' => \WPEmerge\Input\OldInputMiddleware::class, ] ); $this->extendConfig( $container, 'middleware_groups', [ 'global' => [ 'flash', 'oldinput', ], 'web' => [], 'ajax' => [], 'admin' => [], ] ); $this->extendConfig( $container, 'middleware_priority', [] ); $container[ WPEMERGE_WORDPRESS_HTTP_KERNEL_KEY ] = function ( $c ) { $kernel = new HttpKernel( $c[ WPEMERGE_APPLICATION_KEY ], $c[ WPEMERGE_REQUEST_KEY ], $c[ WPEMERGE_ROUTING_ROUTER_KEY ], $c[ WPEMERGE_EXCEPTIONS_ERROR_HANDLER_KEY ] ); $kernel->setMiddleware( $c[ WPEMERGE_CONFIG_KEY ]['middleware'] ); $kernel->setMiddlewareGroups( $c[ WPEMERGE_CONFIG_KEY ]['middleware_groups'] ); $kernel->setMiddlewarePriority( $c[ WPEMERGE_CONFIG_KEY ]['middleware_priority'] ); return $kernel; }; }
php
public function register( $container ) { $this->extendConfig( $container, 'middleware', [ 'flash' => \WPEmerge\Flash\FlashMiddleware::class, 'oldinput' => \WPEmerge\Input\OldInputMiddleware::class, ] ); $this->extendConfig( $container, 'middleware_groups', [ 'global' => [ 'flash', 'oldinput', ], 'web' => [], 'ajax' => [], 'admin' => [], ] ); $this->extendConfig( $container, 'middleware_priority', [] ); $container[ WPEMERGE_WORDPRESS_HTTP_KERNEL_KEY ] = function ( $c ) { $kernel = new HttpKernel( $c[ WPEMERGE_APPLICATION_KEY ], $c[ WPEMERGE_REQUEST_KEY ], $c[ WPEMERGE_ROUTING_ROUTER_KEY ], $c[ WPEMERGE_EXCEPTIONS_ERROR_HANDLER_KEY ] ); $kernel->setMiddleware( $c[ WPEMERGE_CONFIG_KEY ]['middleware'] ); $kernel->setMiddlewareGroups( $c[ WPEMERGE_CONFIG_KEY ]['middleware_groups'] ); $kernel->setMiddlewarePriority( $c[ WPEMERGE_CONFIG_KEY ]['middleware_priority'] ); return $kernel; }; }
[ "public", "function", "register", "(", "$", "container", ")", "{", "$", "this", "->", "extendConfig", "(", "$", "container", ",", "'middleware'", ",", "[", "'flash'", "=>", "\\", "WPEmerge", "\\", "Flash", "\\", "FlashMiddleware", "::", "class", ",", "'old...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/KernelsServiceProvider.php#L26-L57
htmlburger/wpemerge
src/Routing/SortsMiddlewareTrait.php
SortsMiddlewareTrait.getMiddlewarePriorityForMiddleware
public function getMiddlewarePriorityForMiddleware( $middleware ) { if ( is_array( $middleware ) ) { $middleware = $middleware[0]; } $increasing_priority = array_reverse( $this->middleware_priority ); $priority = array_search( $middleware, $increasing_priority ); return $priority !== false ? (int) $priority : -1; }
php
public function getMiddlewarePriorityForMiddleware( $middleware ) { if ( is_array( $middleware ) ) { $middleware = $middleware[0]; } $increasing_priority = array_reverse( $this->middleware_priority ); $priority = array_search( $middleware, $increasing_priority ); return $priority !== false ? (int) $priority : -1; }
[ "public", "function", "getMiddlewarePriorityForMiddleware", "(", "$", "middleware", ")", "{", "if", "(", "is_array", "(", "$", "middleware", ")", ")", "{", "$", "middleware", "=", "$", "middleware", "[", "0", "]", ";", "}", "$", "increasing_priority", "=", ...
Get priority for a specific middleware. This is in reverse compared to definition order. Middleware with unspecified priority will yield -1. @param string|array $middleware @return integer
[ "Get", "priority", "for", "a", "specific", "middleware", ".", "This", "is", "in", "reverse", "compared", "to", "definition", "order", ".", "Middleware", "with", "unspecified", "priority", "will", "yield", "-", "1", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/SortsMiddlewareTrait.php#L52-L60
htmlburger/wpemerge
src/Routing/SortsMiddlewareTrait.php
SortsMiddlewareTrait.sortMiddleware
public function sortMiddleware( $middleware ) { $sorted = $middleware; usort( $sorted, function ( $a, $b ) use ( $middleware ) { $a_priority = $this->getMiddlewarePriorityForMiddleware( $a ); $b_priority = $this->getMiddlewarePriorityForMiddleware( $b ); $priority = $b_priority - $a_priority; if ( $priority !== 0 ) { return $priority; } // Keep relative order from original array. return array_search( $a, $middleware ) - array_search( $b, $middleware ); } ); return array_values( $sorted ); }
php
public function sortMiddleware( $middleware ) { $sorted = $middleware; usort( $sorted, function ( $a, $b ) use ( $middleware ) { $a_priority = $this->getMiddlewarePriorityForMiddleware( $a ); $b_priority = $this->getMiddlewarePriorityForMiddleware( $b ); $priority = $b_priority - $a_priority; if ( $priority !== 0 ) { return $priority; } // Keep relative order from original array. return array_search( $a, $middleware ) - array_search( $b, $middleware ); } ); return array_values( $sorted ); }
[ "public", "function", "sortMiddleware", "(", "$", "middleware", ")", "{", "$", "sorted", "=", "$", "middleware", ";", "usort", "(", "$", "sorted", ",", "function", "(", "$", "a", ",", "$", "b", ")", "use", "(", "$", "middleware", ")", "{", "$", "a_...
Sort array of fully qualified middleware class names by priority in ascending order. @param array<string> $middleware @return array
[ "Sort", "array", "of", "fully", "qualified", "middleware", "class", "names", "by", "priority", "in", "ascending", "order", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/SortsMiddlewareTrait.php#L68-L85
htmlburger/wpemerge
src/ServiceProviders/ExtendsConfigTrait.php
ExtendsConfigTrait.extendConfig
public function extendConfig( $container, $key, $default ) { $config = isset( $container[ WPEMERGE_CONFIG_KEY ] ) ? $container[ WPEMERGE_CONFIG_KEY ] : []; $config = Arr::get( $config, $key, $default ); if ( $config !== $default && is_array( $config ) && is_array( $default ) ) { $config = array_replace_recursive( $default, $config ); } $container[ WPEMERGE_CONFIG_KEY ] = array_merge( $container[ WPEMERGE_CONFIG_KEY ], [ $key => $config ] ); }
php
public function extendConfig( $container, $key, $default ) { $config = isset( $container[ WPEMERGE_CONFIG_KEY ] ) ? $container[ WPEMERGE_CONFIG_KEY ] : []; $config = Arr::get( $config, $key, $default ); if ( $config !== $default && is_array( $config ) && is_array( $default ) ) { $config = array_replace_recursive( $default, $config ); } $container[ WPEMERGE_CONFIG_KEY ] = array_merge( $container[ WPEMERGE_CONFIG_KEY ], [ $key => $config ] ); }
[ "public", "function", "extendConfig", "(", "$", "container", ",", "$", "key", ",", "$", "default", ")", "{", "$", "config", "=", "isset", "(", "$", "container", "[", "WPEMERGE_CONFIG_KEY", "]", ")", "?", "$", "container", "[", "WPEMERGE_CONFIG_KEY", "]", ...
Extends the WP Emerge config in the container with a new key. @param \Pimple\Container $container @param string $key @param mixed $default @return void
[ "Extends", "the", "WP", "Emerge", "config", "in", "the", "container", "with", "a", "new", "key", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/ServiceProviders/ExtendsConfigTrait.php#L26-L38
htmlburger/wpemerge
src/Routing/Conditions/QueryVarCondition.php
QueryVarCondition.isSatisfied
public function isSatisfied( RequestInterface $request ) { $query_var_value = get_query_var( $this->query_var, null ); if ( $query_var_value === null ) { return false; } if ( $this->value === null ) { return true; } return (string) $this->value === $query_var_value; }
php
public function isSatisfied( RequestInterface $request ) { $query_var_value = get_query_var( $this->query_var, null ); if ( $query_var_value === null ) { return false; } if ( $this->value === null ) { return true; } return (string) $this->value === $query_var_value; }
[ "public", "function", "isSatisfied", "(", "RequestInterface", "$", "request", ")", "{", "$", "query_var_value", "=", "get_query_var", "(", "$", "this", "->", "query_var", ",", "null", ")", ";", "if", "(", "$", "query_var_value", "===", "null", ")", "{", "r...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/QueryVarCondition.php#L49-L61
htmlburger/wpemerge
src/Helpers/Arguments.php
Arguments.flip
public static function flip() { $arguments = func_get_args(); $first_null = array_search( null, $arguments, true ); if ( $first_null === false ) { return $arguments; } // Support integer keys only. $first_null = (int) $first_null; $arguments = array_values( array_merge( array_slice( $arguments, $first_null ), array_slice( $arguments, 0, $first_null ) ) ); return $arguments; }
php
public static function flip() { $arguments = func_get_args(); $first_null = array_search( null, $arguments, true ); if ( $first_null === false ) { return $arguments; } // Support integer keys only. $first_null = (int) $first_null; $arguments = array_values( array_merge( array_slice( $arguments, $first_null ), array_slice( $arguments, 0, $first_null ) ) ); return $arguments; }
[ "public", "static", "function", "flip", "(", ")", "{", "$", "arguments", "=", "func_get_args", "(", ")", ";", "$", "first_null", "=", "array_search", "(", "null", ",", "$", "arguments", ",", "true", ")", ";", "if", "(", "$", "first_null", "===", "false...
Get a closure which will flip preceding optional arguments around. @example list( $argument1, $argument2 ) = Arguments::flip( $argument1, $argument2 ); @return array
[ "Get", "a", "closure", "which", "will", "flip", "preceding", "optional", "arguments", "around", ".", "@example", "list", "(", "$argument1", "$argument2", ")", "=", "Arguments", "::", "flip", "(", "$argument1", "$argument2", ")", ";" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Helpers/Arguments.php#L22-L39
htmlburger/wpemerge
src/Routing/Conditions/MultipleCondition.php
MultipleCondition.isSatisfied
public function isSatisfied( RequestInterface $request ) { foreach ( $this->conditions as $condition ) { if ( ! $condition->isSatisfied( $request ) ) { return false; } } return true; }
php
public function isSatisfied( RequestInterface $request ) { foreach ( $this->conditions as $condition ) { if ( ! $condition->isSatisfied( $request ) ) { return false; } } return true; }
[ "public", "function", "isSatisfied", "(", "RequestInterface", "$", "request", ")", "{", "foreach", "(", "$", "this", "->", "conditions", "as", "$", "condition", ")", "{", "if", "(", "!", "$", "condition", "->", "isSatisfied", "(", "$", "request", ")", ")...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/MultipleCondition.php#L48-L55
htmlburger/wpemerge
src/Routing/Conditions/MultipleCondition.php
MultipleCondition.getArguments
public function getArguments( RequestInterface $request ) { $arguments = []; foreach ( $this->conditions as $condition ) { $arguments = array_merge( $arguments, $condition->getArguments( $request ) ); } return $arguments; }
php
public function getArguments( RequestInterface $request ) { $arguments = []; foreach ( $this->conditions as $condition ) { $arguments = array_merge( $arguments, $condition->getArguments( $request ) ); } return $arguments; }
[ "public", "function", "getArguments", "(", "RequestInterface", "$", "request", ")", "{", "$", "arguments", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "conditions", "as", "$", "condition", ")", "{", "$", "arguments", "=", "array_merge", "(", "...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/MultipleCondition.php#L60-L68
htmlburger/wpemerge
src/Flash/FlashMiddleware.php
FlashMiddleware.handle
public function handle( RequestInterface $request, Closure $next ) { $response = $next( $request ); if ( FlashService::enabled() ) { FlashService::shift(); FlashService::save(); } return $response; }
php
public function handle( RequestInterface $request, Closure $next ) { $response = $next( $request ); if ( FlashService::enabled() ) { FlashService::shift(); FlashService::save(); } return $response; }
[ "public", "function", "handle", "(", "RequestInterface", "$", "request", ",", "Closure", "$", "next", ")", "{", "$", "response", "=", "$", "next", "(", "$", "request", ")", ";", "if", "(", "FlashService", "::", "enabled", "(", ")", ")", "{", "FlashServ...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Flash/FlashMiddleware.php#L23-L32
htmlburger/wpemerge
src/Routing/Pipeline.php
Pipeline.run
public function run( RequestInterface $request, $arguments ) { return $this->executeMiddleware( $this->middleware, $request, function () use ( $arguments ) { return call_user_func_array( [$this->getHandler(), 'execute'], $arguments ); } ); }
php
public function run( RequestInterface $request, $arguments ) { return $this->executeMiddleware( $this->middleware, $request, function () use ( $arguments ) { return call_user_func_array( [$this->getHandler(), 'execute'], $arguments ); } ); }
[ "public", "function", "run", "(", "RequestInterface", "$", "request", ",", "$", "arguments", ")", "{", "return", "$", "this", "->", "executeMiddleware", "(", "$", "this", "->", "middleware", ",", "$", "request", ",", "function", "(", ")", "use", "(", "$"...
Get a response for the given request. @param RequestInterface $request @param array $arguments @return \Psr\Http\Message\ResponseInterface
[ "Get", "a", "response", "for", "the", "given", "request", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Pipeline.php#L89-L93
htmlburger/wpemerge
src/Routing/Conditions/AdminCondition.php
AdminCondition.isSatisfied
public function isSatisfied( RequestInterface $request ) { if ( ! $this->isAdminPage() ) { return false; } $screen = get_current_screen(); if ( ! $screen ) { return false; } return $screen->id === get_plugin_page_hookname( $this->menu, $this->parent_menu ); }
php
public function isSatisfied( RequestInterface $request ) { if ( ! $this->isAdminPage() ) { return false; } $screen = get_current_screen(); if ( ! $screen ) { return false; } return $screen->id === get_plugin_page_hookname( $this->menu, $this->parent_menu ); }
[ "public", "function", "isSatisfied", "(", "RequestInterface", "$", "request", ")", "{", "if", "(", "!", "$", "this", "->", "isAdminPage", "(", ")", ")", "{", "return", "false", ";", "}", "$", "screen", "=", "get_current_screen", "(", ")", ";", "if", "(...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/AdminCondition.php#L58-L70
htmlburger/wpemerge
src/Exceptions/ExceptionsServiceProvider.php
ExceptionsServiceProvider.register
public function register( $container ) { $this->extendConfig( $container, 'debug', [ 'pretty_errors' => true, ] ); $container['whoops'] = function () { if ( ! class_exists( Run::class ) ) { return null; } $handler = new PrettyPageHandler(); $handler->addResourcePath( implode( DIRECTORY_SEPARATOR, [WPEMERGE_DIR, 'src', 'Exceptions', 'Whoops'] ) ); $run = new Run(); $run->allowQuit( false ); $run->pushHandler( $handler ); return $run; }; $container[ WPEMERGE_EXCEPTIONS_ERROR_HANDLER_KEY ] = function ( $c ) { $whoops = $c[ WPEMERGE_CONFIG_KEY ]['debug']['pretty_errors'] ? $c['whoops'] : null; return new ErrorHandler( $whoops, Application::debugging() ); }; $container[ WPEMERGE_EXCEPTIONS_CONFIGURATION_ERROR_HANDLER_KEY ] = function ( $c ) { $whoops = $c[ WPEMERGE_CONFIG_KEY ]['debug']['pretty_errors'] ? $c['whoops'] : null; return new ErrorHandler( $whoops, Application::debugging() ); }; }
php
public function register( $container ) { $this->extendConfig( $container, 'debug', [ 'pretty_errors' => true, ] ); $container['whoops'] = function () { if ( ! class_exists( Run::class ) ) { return null; } $handler = new PrettyPageHandler(); $handler->addResourcePath( implode( DIRECTORY_SEPARATOR, [WPEMERGE_DIR, 'src', 'Exceptions', 'Whoops'] ) ); $run = new Run(); $run->allowQuit( false ); $run->pushHandler( $handler ); return $run; }; $container[ WPEMERGE_EXCEPTIONS_ERROR_HANDLER_KEY ] = function ( $c ) { $whoops = $c[ WPEMERGE_CONFIG_KEY ]['debug']['pretty_errors'] ? $c['whoops'] : null; return new ErrorHandler( $whoops, Application::debugging() ); }; $container[ WPEMERGE_EXCEPTIONS_CONFIGURATION_ERROR_HANDLER_KEY ] = function ( $c ) { $whoops = $c[ WPEMERGE_CONFIG_KEY ]['debug']['pretty_errors'] ? $c['whoops'] : null; return new ErrorHandler( $whoops, Application::debugging() ); }; }
[ "public", "function", "register", "(", "$", "container", ")", "{", "$", "this", "->", "extendConfig", "(", "$", "container", ",", "'debug'", ",", "[", "'pretty_errors'", "=>", "true", ",", "]", ")", ";", "$", "container", "[", "'whoops'", "]", "=", "fu...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Exceptions/ExceptionsServiceProvider.php#L29-L57
htmlburger/wpemerge
src/Routing/Conditions/PostTemplateCondition.php
PostTemplateCondition.isSatisfied
public function isSatisfied( RequestInterface $request ) { $template = get_post_meta( (int) get_the_ID(), '_wp_page_template', true ); $template = $template ? $template : 'default'; return ( is_singular( $this->post_types ) && $this->post_template === $template ); }
php
public function isSatisfied( RequestInterface $request ) { $template = get_post_meta( (int) get_the_ID(), '_wp_page_template', true ); $template = $template ? $template : 'default'; return ( is_singular( $this->post_types ) && $this->post_template === $template ); }
[ "public", "function", "isSatisfied", "(", "RequestInterface", "$", "request", ")", "{", "$", "template", "=", "get_post_meta", "(", "(", "int", ")", "get_the_ID", "(", ")", ",", "'_wp_page_template'", ",", "true", ")", ";", "$", "template", "=", "$", "temp...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/PostTemplateCondition.php#L49-L53
htmlburger/wpemerge
src/Routing/Conditions/AjaxCondition.php
AjaxCondition.isSatisfied
public function isSatisfied( RequestInterface $request ) { if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) { return false; } if ( ! $this->matchesActionRequirement( $request ) ) { return false; } return $this->matchesPrivateRequirement() || $this->matchesPublicRequirement(); }
php
public function isSatisfied( RequestInterface $request ) { if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) { return false; } if ( ! $this->matchesActionRequirement( $request ) ) { return false; } return $this->matchesPrivateRequirement() || $this->matchesPublicRequirement(); }
[ "public", "function", "isSatisfied", "(", "RequestInterface", "$", "request", ")", "{", "if", "(", "!", "defined", "(", "'DOING_AJAX'", ")", "||", "!", "DOING_AJAX", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "matchesAction...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/AjaxCondition.php#L86-L96
htmlburger/wpemerge
src/Kernels/HttpKernel.php
HttpKernel.handle
public function handle( RequestInterface $request, $arguments = [] ) { $route = $this->router->execute( $request ); if ( $route === null ) { return null; } $handler = function () use ( $route ) { $arguments = func_get_args(); $request = array_shift( $arguments ); return call_user_func( [$route, 'handle'], $request, $arguments ); }; $response = $this->run( $request, $route->getMiddleware(), $handler, $arguments ); $container = $this->app->getContainer(); $container[ WPEMERGE_RESPONSE_KEY ] = $response; return $response; }
php
public function handle( RequestInterface $request, $arguments = [] ) { $route = $this->router->execute( $request ); if ( $route === null ) { return null; } $handler = function () use ( $route ) { $arguments = func_get_args(); $request = array_shift( $arguments ); return call_user_func( [$route, 'handle'], $request, $arguments ); }; $response = $this->run( $request, $route->getMiddleware(), $handler, $arguments ); $container = $this->app->getContainer(); $container[ WPEMERGE_RESPONSE_KEY ] = $response; return $response; }
[ "public", "function", "handle", "(", "RequestInterface", "$", "request", ",", "$", "arguments", "=", "[", "]", ")", "{", "$", "route", "=", "$", "this", "->", "router", "->", "execute", "(", "$", "request", ")", ";", "if", "(", "$", "route", "===", ...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/HttpKernel.php#L99-L118
htmlburger/wpemerge
src/Kernels/HttpKernel.php
HttpKernel.run
public function run( RequestInterface $request, $middleware, $handler, $arguments = [] ) { $this->error_handler->register(); try { $middleware = $this->expandMiddleware( $middleware ); $middleware = $this->uniqueMiddleware( $middleware ); $middleware = $this->sortMiddleware( $middleware ); $response = ( new Pipeline() ) ->pipe( $middleware ) ->to( $handler ) ->run( $request, array_merge( [$request], $arguments ) ); } catch ( Exception $exception ) { $response = $this->error_handler->getResponse( $request, $exception ); } $this->error_handler->unregister(); return $response; }
php
public function run( RequestInterface $request, $middleware, $handler, $arguments = [] ) { $this->error_handler->register(); try { $middleware = $this->expandMiddleware( $middleware ); $middleware = $this->uniqueMiddleware( $middleware ); $middleware = $this->sortMiddleware( $middleware ); $response = ( new Pipeline() ) ->pipe( $middleware ) ->to( $handler ) ->run( $request, array_merge( [$request], $arguments ) ); } catch ( Exception $exception ) { $response = $this->error_handler->getResponse( $request, $exception ); } $this->error_handler->unregister(); return $response; }
[ "public", "function", "run", "(", "RequestInterface", "$", "request", ",", "$", "middleware", ",", "$", "handler", ",", "$", "arguments", "=", "[", "]", ")", "{", "$", "this", "->", "error_handler", "->", "register", "(", ")", ";", "try", "{", "$", "...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/HttpKernel.php#L123-L142
htmlburger/wpemerge
src/Kernels/HttpKernel.php
HttpKernel.filterRequest
public function filterRequest( $query_vars ) { /** @var $routes \WPEmerge\Routing\RouteInterface[] */ $routes = $this->router->getRoutes(); foreach ( $routes as $route ) { if ( ! $route instanceof HasQueryFilterInterface ) { continue; } if ( ! $route->isSatisfied( $this->request ) ) { continue; } $query_vars = $route->applyQueryFilter( $this->request, $query_vars ); break; } return $query_vars; }
php
public function filterRequest( $query_vars ) { /** @var $routes \WPEmerge\Routing\RouteInterface[] */ $routes = $this->router->getRoutes(); foreach ( $routes as $route ) { if ( ! $route instanceof HasQueryFilterInterface ) { continue; } if ( ! $route->isSatisfied( $this->request ) ) { continue; } $query_vars = $route->applyQueryFilter( $this->request, $query_vars ); break; } return $query_vars; }
[ "public", "function", "filterRequest", "(", "$", "query_vars", ")", "{", "/** @var $routes \\WPEmerge\\Routing\\RouteInterface[] */", "$", "routes", "=", "$", "this", "->", "router", "->", "getRoutes", "(", ")", ";", "foreach", "(", "$", "routes", "as", "$", "ro...
Filter the main query vars. @param array $query_vars @return array
[ "Filter", "the", "main", "query", "vars", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/HttpKernel.php#L150-L168
htmlburger/wpemerge
src/Kernels/HttpKernel.php
HttpKernel.filterTemplateInclude
public function filterTemplateInclude( $view ) { /** @var $wp_query \WP_Query */ global $wp_query; $response = $this->handle( $this->request, [$view] ); if ( $response instanceof ResponseInterface ) { if ( $response->getStatusCode() === 404 ) { $wp_query->set_404(); } return WPEMERGE_DIR . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'view.php'; } return $view; }
php
public function filterTemplateInclude( $view ) { /** @var $wp_query \WP_Query */ global $wp_query; $response = $this->handle( $this->request, [$view] ); if ( $response instanceof ResponseInterface ) { if ( $response->getStatusCode() === 404 ) { $wp_query->set_404(); } return WPEMERGE_DIR . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'view.php'; } return $view; }
[ "public", "function", "filterTemplateInclude", "(", "$", "view", ")", "{", "/** @var $wp_query \\WP_Query */", "global", "$", "wp_query", ";", "$", "response", "=", "$", "this", "->", "handle", "(", "$", "this", "->", "request", ",", "[", "$", "view", "]", ...
Filter the main template file. @param string $view @return string
[ "Filter", "the", "main", "template", "file", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/HttpKernel.php#L176-L191
htmlburger/wpemerge
src/Kernels/HttpKernel.php
HttpKernel.registerAjaxAction
public function registerAjaxAction() { if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) { return; } $action = $this->request->post( 'action', $this->request->get( 'action' ) ); $action = sanitize_text_field( $action ); add_action( "wp_ajax_{$action}", [$this, 'actionAjax'] ); add_action( "wp_ajax_nopriv_{$action}", [$this, 'actionAjax'] ); }
php
public function registerAjaxAction() { if ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) { return; } $action = $this->request->post( 'action', $this->request->get( 'action' ) ); $action = sanitize_text_field( $action ); add_action( "wp_ajax_{$action}", [$this, 'actionAjax'] ); add_action( "wp_ajax_nopriv_{$action}", [$this, 'actionAjax'] ); }
[ "public", "function", "registerAjaxAction", "(", ")", "{", "if", "(", "!", "defined", "(", "'DOING_AJAX'", ")", "||", "!", "DOING_AJAX", ")", "{", "return", ";", "}", "$", "action", "=", "$", "this", "->", "request", "->", "post", "(", "'action'", ",",...
Register ajax action to hook into current one. @return void
[ "Register", "ajax", "action", "to", "hook", "into", "current", "one", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/HttpKernel.php#L198-L208
htmlburger/wpemerge
src/Kernels/HttpKernel.php
HttpKernel.actionAjax
public function actionAjax() { $response = $this->handle( $this->request, [''] ); if ( ! $response instanceof ResponseInterface ) { return; } Response::respond( $response ); wp_die( '', '', ['response' => null] ); }
php
public function actionAjax() { $response = $this->handle( $this->request, [''] ); if ( ! $response instanceof ResponseInterface ) { return; } Response::respond( $response ); wp_die( '', '', ['response' => null] ); }
[ "public", "function", "actionAjax", "(", ")", "{", "$", "response", "=", "$", "this", "->", "handle", "(", "$", "this", "->", "request", ",", "[", "''", "]", ")", ";", "if", "(", "!", "$", "response", "instanceof", "ResponseInterface", ")", "{", "ret...
Act on ajax action. @return void
[ "Act", "on", "ajax", "action", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/HttpKernel.php#L215-L224
htmlburger/wpemerge
src/Kernels/HttpKernel.php
HttpKernel.getAdminPageHook
protected function getAdminPageHook() { global $pagenow, $typenow, $plugin_page; $page_hook = ''; if ( isset( $plugin_page ) ) { if ( ! empty( $typenow ) ) { $the_parent = $pagenow . '?post_type=' . $typenow; } else { $the_parent = $pagenow; } $page_hook = get_plugin_page_hook( $plugin_page, $the_parent ); } return $page_hook; }
php
protected function getAdminPageHook() { global $pagenow, $typenow, $plugin_page; $page_hook = ''; if ( isset( $plugin_page ) ) { if ( ! empty( $typenow ) ) { $the_parent = $pagenow . '?post_type=' . $typenow; } else { $the_parent = $pagenow; } $page_hook = get_plugin_page_hook( $plugin_page, $the_parent ); } return $page_hook; }
[ "protected", "function", "getAdminPageHook", "(", ")", "{", "global", "$", "pagenow", ",", "$", "typenow", ",", "$", "plugin_page", ";", "$", "page_hook", "=", "''", ";", "if", "(", "isset", "(", "$", "plugin_page", ")", ")", "{", "if", "(", "!", "em...
Get page hook. Slightly modified version of code from wp-admin/admin.php. @return string
[ "Get", "page", "hook", ".", "Slightly", "modified", "version", "of", "code", "from", "wp", "-", "admin", "/", "admin", ".", "php", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/HttpKernel.php#L232-L247
htmlburger/wpemerge
src/Kernels/HttpKernel.php
HttpKernel.getAdminHook
protected function getAdminHook( $page_hook ) { global $pagenow, $plugin_page; $hook_suffix = ''; if ( ! empty( $page_hook ) ) { $hook_suffix = $page_hook; } else if ( isset( $plugin_page ) ) { $hook_suffix = $plugin_page; } else if ( isset( $pagenow ) ) { $hook_suffix = $pagenow; } return $hook_suffix; }
php
protected function getAdminHook( $page_hook ) { global $pagenow, $plugin_page; $hook_suffix = ''; if ( ! empty( $page_hook ) ) { $hook_suffix = $page_hook; } else if ( isset( $plugin_page ) ) { $hook_suffix = $plugin_page; } else if ( isset( $pagenow ) ) { $hook_suffix = $pagenow; } return $hook_suffix; }
[ "protected", "function", "getAdminHook", "(", "$", "page_hook", ")", "{", "global", "$", "pagenow", ",", "$", "plugin_page", ";", "$", "hook_suffix", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "page_hook", ")", ")", "{", "$", "hook_suffix", "="...
Get admin page hook. Slightly modified version of code from wp-admin/admin.php. @param string $page_hook @return string
[ "Get", "admin", "page", "hook", ".", "Slightly", "modified", "version", "of", "code", "from", "wp", "-", "admin", "/", "admin", ".", "php", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/HttpKernel.php#L256-L269
htmlburger/wpemerge
src/Kernels/HttpKernel.php
HttpKernel.registerAdminAction
public function registerAdminAction() { global $pagenow; if ( $pagenow !== 'admin.php' ) { return; } $page_hook = $this->getAdminPageHook(); $hook_suffix = $this->getAdminHook( $page_hook ); add_action( "load-{$hook_suffix}", [$this, 'actionAdminLoad'] ); add_action( $hook_suffix, [$this, 'actionAdmin'] ); }
php
public function registerAdminAction() { global $pagenow; if ( $pagenow !== 'admin.php' ) { return; } $page_hook = $this->getAdminPageHook(); $hook_suffix = $this->getAdminHook( $page_hook ); add_action( "load-{$hook_suffix}", [$this, 'actionAdminLoad'] ); add_action( $hook_suffix, [$this, 'actionAdmin'] ); }
[ "public", "function", "registerAdminAction", "(", ")", "{", "global", "$", "pagenow", ";", "if", "(", "$", "pagenow", "!==", "'admin.php'", ")", "{", "return", ";", "}", "$", "page_hook", "=", "$", "this", "->", "getAdminPageHook", "(", ")", ";", "$", ...
Register admin action to hook into current one. @return void
[ "Register", "admin", "action", "to", "hook", "into", "current", "one", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/HttpKernel.php#L276-L288
htmlburger/wpemerge
src/Kernels/HttpKernel.php
HttpKernel.actionAdminLoad
public function actionAdminLoad() { $response = $this->handle( $this->request, [''] ); if ( ! $response instanceof ResponseInterface ) { return; } if ( ! headers_sent() ) { Response::sendHeaders( $response ); } }
php
public function actionAdminLoad() { $response = $this->handle( $this->request, [''] ); if ( ! $response instanceof ResponseInterface ) { return; } if ( ! headers_sent() ) { Response::sendHeaders( $response ); } }
[ "public", "function", "actionAdminLoad", "(", ")", "{", "$", "response", "=", "$", "this", "->", "handle", "(", "$", "this", "->", "request", ",", "[", "''", "]", ")", ";", "if", "(", "!", "$", "response", "instanceof", "ResponseInterface", ")", "{", ...
Act on admin action load. @return void
[ "Act", "on", "admin", "action", "load", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/HttpKernel.php#L295-L305
htmlburger/wpemerge
src/Kernels/HttpKernel.php
HttpKernel.actionAdmin
public function actionAdmin() { $response = $this->app->resolve( WPEMERGE_RESPONSE_KEY ); if ( $response === null ) { return; } Response::sendBody( $response ); }
php
public function actionAdmin() { $response = $this->app->resolve( WPEMERGE_RESPONSE_KEY ); if ( $response === null ) { return; } Response::sendBody( $response ); }
[ "public", "function", "actionAdmin", "(", ")", "{", "$", "response", "=", "$", "this", "->", "app", "->", "resolve", "(", "WPEMERGE_RESPONSE_KEY", ")", ";", "if", "(", "$", "response", "===", "null", ")", "{", "return", ";", "}", "Response", "::", "sen...
Act on admin action. @return void
[ "Act", "on", "admin", "action", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Kernels/HttpKernel.php#L312-L320
htmlburger/wpemerge
src/Csrf/Csrf.php
Csrf.getTokenFromRequest
public function getTokenFromRequest( RequestInterface $request ) { if ( $request->get( $this->key ) ) { return $request->get( $this->key ); } if ( $request->post( $this->key ) ) { return $request->post( $this->key ); } if ( $request->headers( $this->header ) ) { return $request->headers( $this->header ); } return ''; }
php
public function getTokenFromRequest( RequestInterface $request ) { if ( $request->get( $this->key ) ) { return $request->get( $this->key ); } if ( $request->post( $this->key ) ) { return $request->post( $this->key ); } if ( $request->headers( $this->header ) ) { return $request->headers( $this->header ); } return ''; }
[ "public", "function", "getTokenFromRequest", "(", "RequestInterface", "$", "request", ")", "{", "if", "(", "$", "request", "->", "get", "(", "$", "this", "->", "key", ")", ")", "{", "return", "$", "request", "->", "get", "(", "$", "this", "->", "key", ...
Get the csrf token from a request. @param RequestInterface $request @return string
[ "Get", "the", "csrf", "token", "from", "a", "request", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Csrf/Csrf.php#L77-L91
htmlburger/wpemerge
src/Csrf/Csrf.php
Csrf.generateToken
public function generateToken( $action = -1 ) { $action = $action === -1 ? session_id() : $action; $this->token = wp_create_nonce( $action ); return $this->getToken(); }
php
public function generateToken( $action = -1 ) { $action = $action === -1 ? session_id() : $action; $this->token = wp_create_nonce( $action ); return $this->getToken(); }
[ "public", "function", "generateToken", "(", "$", "action", "=", "-", "1", ")", "{", "$", "action", "=", "$", "action", "===", "-", "1", "?", "session_id", "(", ")", ":", "$", "action", ";", "$", "this", "->", "token", "=", "wp_create_nonce", "(", "...
Generate a new token. @param int|string $action @return string
[ "Generate", "a", "new", "token", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Csrf/Csrf.php#L99-L103
htmlburger/wpemerge
src/Csrf/Csrf.php
Csrf.isValidToken
public function isValidToken( $token, $action = -1 ) { $action = $action === -1 ? session_id() : $action; $lifetime = (int) wp_verify_nonce( $token, $action ); return ( $lifetime > 0 && $lifetime <= $this->maximum_lifetime ); }
php
public function isValidToken( $token, $action = -1 ) { $action = $action === -1 ? session_id() : $action; $lifetime = (int) wp_verify_nonce( $token, $action ); return ( $lifetime > 0 && $lifetime <= $this->maximum_lifetime ); }
[ "public", "function", "isValidToken", "(", "$", "token", ",", "$", "action", "=", "-", "1", ")", "{", "$", "action", "=", "$", "action", "===", "-", "1", "?", "session_id", "(", ")", ":", "$", "action", ";", "$", "lifetime", "=", "(", "int", ")",...
Check if a token is valid. @param string $token @param int|string $action @return boolean
[ "Check", "if", "a", "token", "is", "valid", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Csrf/Csrf.php#L112-L116
htmlburger/wpemerge
src/Input/OldInputServiceProvider.php
OldInputServiceProvider.register
public function register( $container ) { $container[ WPEMERGE_OLD_INPUT_KEY ] = function ( $c ) { return new OldInput( $c[ WPEMERGE_FLASH_KEY ] ); }; Application::alias( 'OldInput', \WPEmerge\Facades\OldInput::class ); }
php
public function register( $container ) { $container[ WPEMERGE_OLD_INPUT_KEY ] = function ( $c ) { return new OldInput( $c[ WPEMERGE_FLASH_KEY ] ); }; Application::alias( 'OldInput', \WPEmerge\Facades\OldInput::class ); }
[ "public", "function", "register", "(", "$", "container", ")", "{", "$", "container", "[", "WPEMERGE_OLD_INPUT_KEY", "]", "=", "function", "(", "$", "c", ")", "{", "return", "new", "OldInput", "(", "$", "c", "[", "WPEMERGE_FLASH_KEY", "]", ")", ";", "}", ...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Input/OldInputServiceProvider.php#L24-L30
htmlburger/wpemerge
src/Csrf/CsrfServiceProvider.php
CsrfServiceProvider.register
public function register( $container ) { $container[ WPEMERGE_CSRF_KEY ] = function () { return new Csrf(); }; Application::alias( 'Csrf', \WPEmerge\Facades\Csrf::class ); }
php
public function register( $container ) { $container[ WPEMERGE_CSRF_KEY ] = function () { return new Csrf(); }; Application::alias( 'Csrf', \WPEmerge\Facades\Csrf::class ); }
[ "public", "function", "register", "(", "$", "container", ")", "{", "$", "container", "[", "WPEMERGE_CSRF_KEY", "]", "=", "function", "(", ")", "{", "return", "new", "Csrf", "(", ")", ";", "}", ";", "Application", "::", "alias", "(", "'Csrf'", ",", "\\"...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Csrf/CsrfServiceProvider.php#L24-L30
htmlburger/wpemerge
src/Support/Arr.php
Arr.collapse
public static function collapse($array) { $results = []; foreach ($array as $values) { if (! is_array($values)) { continue; } $results = array_merge($results, $values); } return $results; }
php
public static function collapse($array) { $results = []; foreach ($array as $values) { if (! is_array($values)) { continue; } $results = array_merge($results, $values); } return $results; }
[ "public", "static", "function", "collapse", "(", "$", "array", ")", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "array", "as", "$", "values", ")", "{", "if", "(", "!", "is_array", "(", "$", "values", ")", ")", "{", "continue", "...
Collapse an array of arrays into a single array. @param array $array @return array
[ "Collapse", "an", "array", "of", "arrays", "into", "a", "single", "array", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Support/Arr.php#L49-L59
htmlburger/wpemerge
src/Support/Arr.php
Arr.data_get
public static function data_get($target, $key, $default = null) { if (is_null($key)) { return $target; } $key = is_array($key) ? $key : explode('.', $key); while (! is_null($segment = array_shift($key))) { if ($segment === '*') { if (! is_array($target)) { return $default; } $result = static::pluck($target, $key); return in_array('*', $key) ? static::collapse($result) : $result; } if (static::accessible($target) && static::exists($target, $segment)) { $target = $target[$segment]; } elseif (is_object($target) && isset($target->{$segment})) { $target = $target->{$segment}; } else { return $default; } } return $target; }
php
public static function data_get($target, $key, $default = null) { if (is_null($key)) { return $target; } $key = is_array($key) ? $key : explode('.', $key); while (! is_null($segment = array_shift($key))) { if ($segment === '*') { if (! is_array($target)) { return $default; } $result = static::pluck($target, $key); return in_array('*', $key) ? static::collapse($result) : $result; } if (static::accessible($target) && static::exists($target, $segment)) { $target = $target[$segment]; } elseif (is_object($target) && isset($target->{$segment})) { $target = $target->{$segment}; } else { return $default; } } return $target; }
[ "public", "static", "function", "data_get", "(", "$", "target", ",", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "return", "$", "target", ";", "}", "$", "key", "=", "is_array", "("...
Get an item from an array or object using "dot" notation. @param mixed $target @param string|array $key @param mixed $default @return mixed
[ "Get", "an", "item", "from", "an", "array", "or", "object", "using", "dot", "notation", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Support/Arr.php#L480-L503
htmlburger/wpemerge
src/Flash/FlashServiceProvider.php
FlashServiceProvider.register
public function register( $container ) { $container[ WPEMERGE_FLASH_KEY ] = function ( $c ) { $session = null; if ( isset( $c[ WPEMERGE_SESSION_KEY ] ) ) { $session = &$c[ WPEMERGE_SESSION_KEY ]; } else if ( isset( $_SESSION ) ) { $session = &$_SESSION; } return new Flash( $session ); }; Application::alias( 'Flash', \WPEmerge\Facades\Flash::class ); }
php
public function register( $container ) { $container[ WPEMERGE_FLASH_KEY ] = function ( $c ) { $session = null; if ( isset( $c[ WPEMERGE_SESSION_KEY ] ) ) { $session = &$c[ WPEMERGE_SESSION_KEY ]; } else if ( isset( $_SESSION ) ) { $session = &$_SESSION; } return new Flash( $session ); }; Application::alias( 'Flash', \WPEmerge\Facades\Flash::class ); }
[ "public", "function", "register", "(", "$", "container", ")", "{", "$", "container", "[", "WPEMERGE_FLASH_KEY", "]", "=", "function", "(", "$", "c", ")", "{", "$", "session", "=", "null", ";", "if", "(", "isset", "(", "$", "c", "[", "WPEMERGE_SESSION_K...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Flash/FlashServiceProvider.php#L24-L36
htmlburger/wpemerge
src/Csrf/CsrfMiddleware.php
CsrfMiddleware.handle
public function handle( RequestInterface $request, Closure $next ) { if ( ! $request->isReadVerb() ) { $token = CsrfService::getTokenFromRequest( $request ); if ( ! CsrfService::isValidToken( $token ) ) { throw new InvalidCsrfTokenException(); } } CsrfService::generateToken(); return $next( $request ); }
php
public function handle( RequestInterface $request, Closure $next ) { if ( ! $request->isReadVerb() ) { $token = CsrfService::getTokenFromRequest( $request ); if ( ! CsrfService::isValidToken( $token ) ) { throw new InvalidCsrfTokenException(); } } CsrfService::generateToken(); return $next( $request ); }
[ "public", "function", "handle", "(", "RequestInterface", "$", "request", ",", "Closure", "$", "next", ")", "{", "if", "(", "!", "$", "request", "->", "isReadVerb", "(", ")", ")", "{", "$", "token", "=", "CsrfService", "::", "getTokenFromRequest", "(", "$...
{@inheritDoc} @throws InvalidCsrfTokenException
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Csrf/CsrfMiddleware.php#L24-L35
htmlburger/wpemerge
src/Routing/Conditions/UrlCondition.php
UrlCondition.whereIsSatisfied
protected function whereIsSatisfied( RequestInterface $request ) { $where = $this->getUrlWhere(); $arguments = $this->getArguments( $request ); foreach ( $where as $parameter => $pattern ) { $value = Arr::get( $arguments, $parameter, '' ); if ( ! preg_match( $pattern, $value ) ) { return false; } } return true; }
php
protected function whereIsSatisfied( RequestInterface $request ) { $where = $this->getUrlWhere(); $arguments = $this->getArguments( $request ); foreach ( $where as $parameter => $pattern ) { $value = Arr::get( $arguments, $parameter, '' ); if ( ! preg_match( $pattern, $value ) ) { return false; } } return true; }
[ "protected", "function", "whereIsSatisfied", "(", "RequestInterface", "$", "request", ")", "{", "$", "where", "=", "$", "this", "->", "getUrlWhere", "(", ")", ";", "$", "arguments", "=", "$", "this", "->", "getArguments", "(", "$", "request", ")", ";", "...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/UrlCondition.php#L73-L86
htmlburger/wpemerge
src/Routing/Conditions/UrlCondition.php
UrlCondition.isSatisfied
public function isSatisfied( RequestInterface $request ) { if ( $this->getUrl() === static::WILDCARD ) { return true; } $validation_pattern = $this->getValidationPattern( $this->getUrl() ); $url = UrlUtility::getPath( $request ); $match = (bool) preg_match( $validation_pattern, $url ); if ( ! $match || empty( $this->getUrlWhere() ) ) { return $match; } return $this->whereIsSatisfied( $request ); }
php
public function isSatisfied( RequestInterface $request ) { if ( $this->getUrl() === static::WILDCARD ) { return true; } $validation_pattern = $this->getValidationPattern( $this->getUrl() ); $url = UrlUtility::getPath( $request ); $match = (bool) preg_match( $validation_pattern, $url ); if ( ! $match || empty( $this->getUrlWhere() ) ) { return $match; } return $this->whereIsSatisfied( $request ); }
[ "public", "function", "isSatisfied", "(", "RequestInterface", "$", "request", ")", "{", "if", "(", "$", "this", "->", "getUrl", "(", ")", "===", "static", "::", "WILDCARD", ")", "{", "return", "true", ";", "}", "$", "validation_pattern", "=", "$", "this"...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/UrlCondition.php#L91-L105
htmlburger/wpemerge
src/Routing/Conditions/UrlCondition.php
UrlCondition.getArguments
public function getArguments( RequestInterface $request ) { $validation_pattern = $this->getValidationPattern( $this->getUrl() ); $url = UrlUtility::getPath( $request ); $matches = []; $success = preg_match( $validation_pattern, $url, $matches ); if ( ! $success ) { return []; // this should not normally happen } $arguments = []; $parameter_names = $this->getParameterNames( $this->getUrl() ); foreach ( $parameter_names as $parameter_name ) { $arguments[ $parameter_name ] = isset( $matches[ $parameter_name ] ) ? $matches[ $parameter_name ] : ''; } return $arguments; }
php
public function getArguments( RequestInterface $request ) { $validation_pattern = $this->getValidationPattern( $this->getUrl() ); $url = UrlUtility::getPath( $request ); $matches = []; $success = preg_match( $validation_pattern, $url, $matches ); if ( ! $success ) { return []; // this should not normally happen } $arguments = []; $parameter_names = $this->getParameterNames( $this->getUrl() ); foreach ( $parameter_names as $parameter_name ) { $arguments[ $parameter_name ] = isset( $matches[ $parameter_name ] ) ? $matches[ $parameter_name ] : ''; } return $arguments; }
[ "public", "function", "getArguments", "(", "RequestInterface", "$", "request", ")", "{", "$", "validation_pattern", "=", "$", "this", "->", "getValidationPattern", "(", "$", "this", "->", "getUrl", "(", ")", ")", ";", "$", "url", "=", "UrlUtility", "::", "...
{@inheritDoc}
[ "{" ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/UrlCondition.php#L110-L127
htmlburger/wpemerge
src/Routing/Conditions/UrlCondition.php
UrlCondition.setUrl
public function setUrl( $url ) { if ( $url !== static::WILDCARD ) { $url = UrlUtility::addLeadingSlash( UrlUtility::addTrailingSlash( $url ) ); } $this->url = $url; }
php
public function setUrl( $url ) { if ( $url !== static::WILDCARD ) { $url = UrlUtility::addLeadingSlash( UrlUtility::addTrailingSlash( $url ) ); } $this->url = $url; }
[ "public", "function", "setUrl", "(", "$", "url", ")", "{", "if", "(", "$", "url", "!==", "static", "::", "WILDCARD", ")", "{", "$", "url", "=", "UrlUtility", "::", "addLeadingSlash", "(", "UrlUtility", "::", "addTrailingSlash", "(", "$", "url", ")", ")...
Set the url for this condition. @param string $url @return void
[ "Set", "the", "url", "for", "this", "condition", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/UrlCondition.php#L144-L150
htmlburger/wpemerge
src/Routing/Conditions/UrlCondition.php
UrlCondition.concatenate
public function concatenate( $url, $where = [] ) { if ( $this->getUrl() === static::WILDCARD || $url === static::WILDCARD ) { return new static( static::WILDCARD ); } $leading = UrlUtility::addLeadingSlash( UrlUtility::removeTrailingSlash( $this->getUrl() ), true ); $trailing = UrlUtility::addLeadingSlash( UrlUtility::addTrailingSlash( $url ) ); $concatenated = new static( $leading . $trailing, array_merge( $this->getUrlWhere(), $where ) ); return $concatenated; }
php
public function concatenate( $url, $where = [] ) { if ( $this->getUrl() === static::WILDCARD || $url === static::WILDCARD ) { return new static( static::WILDCARD ); } $leading = UrlUtility::addLeadingSlash( UrlUtility::removeTrailingSlash( $this->getUrl() ), true ); $trailing = UrlUtility::addLeadingSlash( UrlUtility::addTrailingSlash( $url ) ); $concatenated = new static( $leading . $trailing, array_merge( $this->getUrlWhere(), $where ) ); return $concatenated; }
[ "public", "function", "concatenate", "(", "$", "url", ",", "$", "where", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "getUrl", "(", ")", "===", "static", "::", "WILDCARD", "||", "$", "url", "===", "static", "::", "WILDCARD", ")", "{", ...
Append a url to this one returning a new instance. @param string $url @param array<string, string> $where @return static
[ "Append", "a", "url", "to", "this", "one", "returning", "a", "new", "instance", "." ]
train
https://github.com/htmlburger/wpemerge/blob/783123521d413c812442673185cc61e7af27cccf/src/Routing/Conditions/UrlCondition.php#L173-L187