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
creof/wkb-parser
lib/CrEOF/Geo/WKB/Parser.php
Parser.readLinearRings
private function readLinearRings($count) { $rings = array(); for ($i = 0; $i < $count; $i++) { $rings[] = $this->readPoints($this->readCount()); } return $rings; }
php
private function readLinearRings($count) { $rings = array(); for ($i = 0; $i < $count; $i++) { $rings[] = $this->readPoints($this->readCount()); } return $rings; }
[ "private", "function", "readLinearRings", "(", "$", "count", ")", "{", "$", "rings", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "rings", "[", "]", "=", "$", "this", "->", "readPoints", "(", "$", "this", "->", "readCount", "(", ")", ")", ";", "}", "return", "$", "rings", ";", "}" ]
@param int $count @return array @throws UnexpectedValueException
[ "@param", "int", "$count" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Parser.php#L398-L407
creof/wkb-parser
lib/CrEOF/Geo/WKB/Parser.php
Parser.multiPoint
private function multiPoint() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); if ($this->getDimensionedPrimitive(self::WKB_TYPE_POINT) !== $type) { throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_MULTIPOINT, array(self::WKB_TYPE_POINT))); } $values[] = $this->point(); } return $values; }
php
private function multiPoint() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); if ($this->getDimensionedPrimitive(self::WKB_TYPE_POINT) !== $type) { throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_MULTIPOINT, array(self::WKB_TYPE_POINT))); } $values[] = $this->point(); } return $values; }
[ "private", "function", "multiPoint", "(", ")", "{", "$", "values", "=", "array", "(", ")", ";", "$", "count", "=", "$", "this", "->", "readCount", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "this", "->", "readByteOrder", "(", ")", ";", "$", "type", "=", "$", "this", "->", "readType", "(", ")", ";", "if", "(", "$", "this", "->", "getDimensionedPrimitive", "(", "self", "::", "WKB_TYPE_POINT", ")", "!==", "$", "type", ")", "{", "throw", "new", "UnexpectedValueException", "(", "$", "this", "->", "getBadTypeInTypeMessage", "(", "$", "type", ",", "self", "::", "WKB_TYPE_MULTIPOINT", ",", "array", "(", "self", "::", "WKB_TYPE_POINT", ")", ")", ")", ";", "}", "$", "values", "[", "]", "=", "$", "this", "->", "point", "(", ")", ";", "}", "return", "$", "values", ";", "}" ]
Parse MULTIPOINT value @return array[] @throws UnexpectedValueException
[ "Parse", "MULTIPOINT", "value" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Parser.php#L459-L477
creof/wkb-parser
lib/CrEOF/Geo/WKB/Parser.php
Parser.multiLineString
private function multiLineString() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); if ($this->getDimensionedPrimitive(self::WKB_TYPE_LINESTRING) !== $type) { throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_MULTILINESTRING, array(self::WKB_TYPE_LINESTRING))); } $values[] = $this->readPoints($this->readCount()); } return $values; }
php
private function multiLineString() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); if ($this->getDimensionedPrimitive(self::WKB_TYPE_LINESTRING) !== $type) { throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_MULTILINESTRING, array(self::WKB_TYPE_LINESTRING))); } $values[] = $this->readPoints($this->readCount()); } return $values; }
[ "private", "function", "multiLineString", "(", ")", "{", "$", "values", "=", "array", "(", ")", ";", "$", "count", "=", "$", "this", "->", "readCount", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "this", "->", "readByteOrder", "(", ")", ";", "$", "type", "=", "$", "this", "->", "readType", "(", ")", ";", "if", "(", "$", "this", "->", "getDimensionedPrimitive", "(", "self", "::", "WKB_TYPE_LINESTRING", ")", "!==", "$", "type", ")", "{", "throw", "new", "UnexpectedValueException", "(", "$", "this", "->", "getBadTypeInTypeMessage", "(", "$", "type", ",", "self", "::", "WKB_TYPE_MULTILINESTRING", ",", "array", "(", "self", "::", "WKB_TYPE_LINESTRING", ")", ")", ")", ";", "}", "$", "values", "[", "]", "=", "$", "this", "->", "readPoints", "(", "$", "this", "->", "readCount", "(", ")", ")", ";", "}", "return", "$", "values", ";", "}" ]
Parse MULTILINESTRING value @return array[] @throws UnexpectedValueException
[ "Parse", "MULTILINESTRING", "value" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Parser.php#L485-L503
creof/wkb-parser
lib/CrEOF/Geo/WKB/Parser.php
Parser.multiPolygon
private function multiPolygon() { $count = $this->readCount(); $values = array(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); if ($this->getDimensionedPrimitive(self::WKB_TYPE_POLYGON) !== $type) { throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_MULTIPOLYGON, array(self::WKB_TYPE_POLYGON))); } $values[] = $this->readLinearRings($this->readCount()); } return $values; }
php
private function multiPolygon() { $count = $this->readCount(); $values = array(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); if ($this->getDimensionedPrimitive(self::WKB_TYPE_POLYGON) !== $type) { throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_MULTIPOLYGON, array(self::WKB_TYPE_POLYGON))); } $values[] = $this->readLinearRings($this->readCount()); } return $values; }
[ "private", "function", "multiPolygon", "(", ")", "{", "$", "count", "=", "$", "this", "->", "readCount", "(", ")", ";", "$", "values", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "this", "->", "readByteOrder", "(", ")", ";", "$", "type", "=", "$", "this", "->", "readType", "(", ")", ";", "if", "(", "$", "this", "->", "getDimensionedPrimitive", "(", "self", "::", "WKB_TYPE_POLYGON", ")", "!==", "$", "type", ")", "{", "throw", "new", "UnexpectedValueException", "(", "$", "this", "->", "getBadTypeInTypeMessage", "(", "$", "type", ",", "self", "::", "WKB_TYPE_MULTIPOLYGON", ",", "array", "(", "self", "::", "WKB_TYPE_POLYGON", ")", ")", ")", ";", "}", "$", "values", "[", "]", "=", "$", "this", "->", "readLinearRings", "(", "$", "this", "->", "readCount", "(", ")", ")", ";", "}", "return", "$", "values", ";", "}" ]
Parse MULTIPOLYGON value @return array[] @throws UnexpectedValueException
[ "Parse", "MULTIPOLYGON", "value" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Parser.php#L511-L529
creof/wkb-parser
lib/CrEOF/Geo/WKB/Parser.php
Parser.compoundCurve
private function compoundCurve() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); switch ($type) { case ($this->getDimensionedPrimitive(self::WKB_TYPE_LINESTRING)): // no break case ($this->getDimensionedPrimitive(self::WKB_TYPE_CIRCULARSTRING)): $value = $this->readPoints($this->readCount()); break; default: throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_COMPOUNDCURVE, array(self::WKB_TYPE_LINESTRING, self::WKB_TYPE_CIRCULARSTRING))); } $values[] = array( 'type' => $this->getTypeName($type), 'value' => $value, ); } return $values; }
php
private function compoundCurve() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); switch ($type) { case ($this->getDimensionedPrimitive(self::WKB_TYPE_LINESTRING)): // no break case ($this->getDimensionedPrimitive(self::WKB_TYPE_CIRCULARSTRING)): $value = $this->readPoints($this->readCount()); break; default: throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_COMPOUNDCURVE, array(self::WKB_TYPE_LINESTRING, self::WKB_TYPE_CIRCULARSTRING))); } $values[] = array( 'type' => $this->getTypeName($type), 'value' => $value, ); } return $values; }
[ "private", "function", "compoundCurve", "(", ")", "{", "$", "values", "=", "array", "(", ")", ";", "$", "count", "=", "$", "this", "->", "readCount", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "this", "->", "readByteOrder", "(", ")", ";", "$", "type", "=", "$", "this", "->", "readType", "(", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "(", "$", "this", "->", "getDimensionedPrimitive", "(", "self", "::", "WKB_TYPE_LINESTRING", ")", ")", ":", "// no break", "case", "(", "$", "this", "->", "getDimensionedPrimitive", "(", "self", "::", "WKB_TYPE_CIRCULARSTRING", ")", ")", ":", "$", "value", "=", "$", "this", "->", "readPoints", "(", "$", "this", "->", "readCount", "(", ")", ")", ";", "break", ";", "default", ":", "throw", "new", "UnexpectedValueException", "(", "$", "this", "->", "getBadTypeInTypeMessage", "(", "$", "type", ",", "self", "::", "WKB_TYPE_COMPOUNDCURVE", ",", "array", "(", "self", "::", "WKB_TYPE_LINESTRING", ",", "self", "::", "WKB_TYPE_CIRCULARSTRING", ")", ")", ")", ";", "}", "$", "values", "[", "]", "=", "array", "(", "'type'", "=>", "$", "this", "->", "getTypeName", "(", "$", "type", ")", ",", "'value'", "=>", "$", "value", ",", ")", ";", "}", "return", "$", "values", ";", "}" ]
Parse COMPOUNDCURVE value @return array @throws UnexpectedValueException
[ "Parse", "COMPOUNDCURVE", "value" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Parser.php#L537-L564
creof/wkb-parser
lib/CrEOF/Geo/WKB/Parser.php
Parser.multiSurface
private function multiSurface() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); switch ($type) { case ($this->getDimensionedPrimitive(self::WKB_TYPE_POLYGON)): $value = $this->polygon(); break; case ($this->getDimensionedPrimitive(self::WKB_TYPE_CURVEPOLYGON)): $value = $this->curvePolygon(); break; default: throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_MULTISURFACE, array(self::WKB_TYPE_POLYGON, self::WKB_TYPE_CURVEPOLYGON))); } $values[] = array( 'type' => $this->getTypeName($type), 'value' => $value, ); } return $values; }
php
private function multiSurface() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); switch ($type) { case ($this->getDimensionedPrimitive(self::WKB_TYPE_POLYGON)): $value = $this->polygon(); break; case ($this->getDimensionedPrimitive(self::WKB_TYPE_CURVEPOLYGON)): $value = $this->curvePolygon(); break; default: throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_MULTISURFACE, array(self::WKB_TYPE_POLYGON, self::WKB_TYPE_CURVEPOLYGON))); } $values[] = array( 'type' => $this->getTypeName($type), 'value' => $value, ); } return $values; }
[ "private", "function", "multiSurface", "(", ")", "{", "$", "values", "=", "array", "(", ")", ";", "$", "count", "=", "$", "this", "->", "readCount", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "this", "->", "readByteOrder", "(", ")", ";", "$", "type", "=", "$", "this", "->", "readType", "(", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "(", "$", "this", "->", "getDimensionedPrimitive", "(", "self", "::", "WKB_TYPE_POLYGON", ")", ")", ":", "$", "value", "=", "$", "this", "->", "polygon", "(", ")", ";", "break", ";", "case", "(", "$", "this", "->", "getDimensionedPrimitive", "(", "self", "::", "WKB_TYPE_CURVEPOLYGON", ")", ")", ":", "$", "value", "=", "$", "this", "->", "curvePolygon", "(", ")", ";", "break", ";", "default", ":", "throw", "new", "UnexpectedValueException", "(", "$", "this", "->", "getBadTypeInTypeMessage", "(", "$", "type", ",", "self", "::", "WKB_TYPE_MULTISURFACE", ",", "array", "(", "self", "::", "WKB_TYPE_POLYGON", ",", "self", "::", "WKB_TYPE_CURVEPOLYGON", ")", ")", ")", ";", "}", "$", "values", "[", "]", "=", "array", "(", "'type'", "=>", "$", "this", "->", "getTypeName", "(", "$", "type", ")", ",", "'value'", "=>", "$", "value", ",", ")", ";", "}", "return", "$", "values", ";", "}" ]
Parse MULTISURFACE value @return array @throws UnexpectedValueException
[ "Parse", "MULTISURFACE", "value" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Parser.php#L648-L676
creof/wkb-parser
lib/CrEOF/Geo/WKB/Parser.php
Parser.polyhedralSurface
private function polyhedralSurface() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); switch ($type) { case ($this->getDimensionedPrimitive(self::WKB_TYPE_POLYGON)): $value = $this->polygon(); break; // is polygon the only one? default: throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_POLYHEDRALSURFACE, array(self::WKB_TYPE_POLYGON))); } $values[] = array( 'type' => $this->getTypeName($type), 'value' => $value, ); } return $values; }
php
private function polyhedralSurface() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); switch ($type) { case ($this->getDimensionedPrimitive(self::WKB_TYPE_POLYGON)): $value = $this->polygon(); break; // is polygon the only one? default: throw new UnexpectedValueException($this->getBadTypeInTypeMessage($type, self::WKB_TYPE_POLYHEDRALSURFACE, array(self::WKB_TYPE_POLYGON))); } $values[] = array( 'type' => $this->getTypeName($type), 'value' => $value, ); } return $values; }
[ "private", "function", "polyhedralSurface", "(", ")", "{", "$", "values", "=", "array", "(", ")", ";", "$", "count", "=", "$", "this", "->", "readCount", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "this", "->", "readByteOrder", "(", ")", ";", "$", "type", "=", "$", "this", "->", "readType", "(", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "(", "$", "this", "->", "getDimensionedPrimitive", "(", "self", "::", "WKB_TYPE_POLYGON", ")", ")", ":", "$", "value", "=", "$", "this", "->", "polygon", "(", ")", ";", "break", ";", "// is polygon the only one?", "default", ":", "throw", "new", "UnexpectedValueException", "(", "$", "this", "->", "getBadTypeInTypeMessage", "(", "$", "type", ",", "self", "::", "WKB_TYPE_POLYHEDRALSURFACE", ",", "array", "(", "self", "::", "WKB_TYPE_POLYGON", ")", ")", ")", ";", "}", "$", "values", "[", "]", "=", "array", "(", "'type'", "=>", "$", "this", "->", "getTypeName", "(", "$", "type", ")", ",", "'value'", "=>", "$", "value", ",", ")", ";", "}", "return", "$", "values", ";", "}" ]
Parse POLYHEDRALSURFACE value @return array @throws UnexpectedValueException
[ "Parse", "POLYHEDRALSURFACE", "value" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Parser.php#L684-L710
creof/wkb-parser
lib/CrEOF/Geo/WKB/Parser.php
Parser.geometryCollection
private function geometryCollection() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); $typeName = $this->getTypeName($type); $values[] = array( 'type' => $typeName, 'value' => $this->$typeName() ); } return $values; }
php
private function geometryCollection() { $values = array(); $count = $this->readCount(); for ($i = 0; $i < $count; $i++) { $this->readByteOrder(); $type = $this->readType(); $typeName = $this->getTypeName($type); $values[] = array( 'type' => $typeName, 'value' => $this->$typeName() ); } return $values; }
[ "private", "function", "geometryCollection", "(", ")", "{", "$", "values", "=", "array", "(", ")", ";", "$", "count", "=", "$", "this", "->", "readCount", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "this", "->", "readByteOrder", "(", ")", ";", "$", "type", "=", "$", "this", "->", "readType", "(", ")", ";", "$", "typeName", "=", "$", "this", "->", "getTypeName", "(", "$", "type", ")", ";", "$", "values", "[", "]", "=", "array", "(", "'type'", "=>", "$", "typeName", ",", "'value'", "=>", "$", "this", "->", "$", "typeName", "(", ")", ")", ";", "}", "return", "$", "values", ";", "}" ]
Parse GEOMETRYCOLLECTION value @return array[] @throws UnexpectedValueException
[ "Parse", "GEOMETRYCOLLECTION", "value" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Parser.php#L718-L736
creof/wkb-parser
lib/CrEOF/Geo/WKB/Parser.php
Parser.getBadTypeInTypeMessage
private function getBadTypeInTypeMessage($childType, $parentType, array $expectedTypes) { if ($this->type !== $parentType) { $parentType = $this->type; } $message = sprintf( ' %s with dimensions 0x%X (%2$d) in %3$s, expected ', $this->getTypeName($childType), $this->getDimensions($childType), $this->getTypeName($parentType) ); if (! in_array($this->getTypePrimitive($childType), $expectedTypes, true)) { if (1 === count($expectedTypes)) { $message .= $this->getTypeName($expectedTypes[0]); } else { $last = $this->getTypeName(array_pop($expectedTypes)); $message .= implode(array_map(array($this, 'getTypeName'), $expectedTypes), ', ') . ' or ' . $last; } $message = 'Unexpected' . $message . ' with '; } else { $message = 'Bad' . $message; } return $message . sprintf('dimensions 0x%X (%1$d)', $this->dimensions); }
php
private function getBadTypeInTypeMessage($childType, $parentType, array $expectedTypes) { if ($this->type !== $parentType) { $parentType = $this->type; } $message = sprintf( ' %s with dimensions 0x%X (%2$d) in %3$s, expected ', $this->getTypeName($childType), $this->getDimensions($childType), $this->getTypeName($parentType) ); if (! in_array($this->getTypePrimitive($childType), $expectedTypes, true)) { if (1 === count($expectedTypes)) { $message .= $this->getTypeName($expectedTypes[0]); } else { $last = $this->getTypeName(array_pop($expectedTypes)); $message .= implode(array_map(array($this, 'getTypeName'), $expectedTypes), ', ') . ' or ' . $last; } $message = 'Unexpected' . $message . ' with '; } else { $message = 'Bad' . $message; } return $message . sprintf('dimensions 0x%X (%1$d)', $this->dimensions); }
[ "private", "function", "getBadTypeInTypeMessage", "(", "$", "childType", ",", "$", "parentType", ",", "array", "$", "expectedTypes", ")", "{", "if", "(", "$", "this", "->", "type", "!==", "$", "parentType", ")", "{", "$", "parentType", "=", "$", "this", "->", "type", ";", "}", "$", "message", "=", "sprintf", "(", "' %s with dimensions 0x%X (%2$d) in %3$s, expected '", ",", "$", "this", "->", "getTypeName", "(", "$", "childType", ")", ",", "$", "this", "->", "getDimensions", "(", "$", "childType", ")", ",", "$", "this", "->", "getTypeName", "(", "$", "parentType", ")", ")", ";", "if", "(", "!", "in_array", "(", "$", "this", "->", "getTypePrimitive", "(", "$", "childType", ")", ",", "$", "expectedTypes", ",", "true", ")", ")", "{", "if", "(", "1", "===", "count", "(", "$", "expectedTypes", ")", ")", "{", "$", "message", ".=", "$", "this", "->", "getTypeName", "(", "$", "expectedTypes", "[", "0", "]", ")", ";", "}", "else", "{", "$", "last", "=", "$", "this", "->", "getTypeName", "(", "array_pop", "(", "$", "expectedTypes", ")", ")", ";", "$", "message", ".=", "implode", "(", "array_map", "(", "array", "(", "$", "this", ",", "'getTypeName'", ")", ",", "$", "expectedTypes", ")", ",", "', '", ")", ".", "' or '", ".", "$", "last", ";", "}", "$", "message", "=", "'Unexpected'", ".", "$", "message", ".", "' with '", ";", "}", "else", "{", "$", "message", "=", "'Bad'", ".", "$", "message", ";", "}", "return", "$", "message", ".", "sprintf", "(", "'dimensions 0x%X (%1$d)'", ",", "$", "this", "->", "dimensions", ")", ";", "}" ]
@param int $childType @param int $parentType @param int[] $expectedTypes @return string
[ "@param", "int", "$childType", "@param", "int", "$parentType", "@param", "int", "[]", "$expectedTypes" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Parser.php#L745-L772
creof/wkb-parser
lib/CrEOF/Geo/WKB/Reader.php
Reader.load
public function load($input) { $this->position = 0; $this->previous = 0; if (ord($input) < 32) { $this->input = $input; $this->length = strlen($input); return; } $position = stripos($input, 'x'); if (false !== $position) { $input = substr($input, $position + 1); } $this->input = pack('H*', $input); $this->length = strlen($this->input); }
php
public function load($input) { $this->position = 0; $this->previous = 0; if (ord($input) < 32) { $this->input = $input; $this->length = strlen($input); return; } $position = stripos($input, 'x'); if (false !== $position) { $input = substr($input, $position + 1); } $this->input = pack('H*', $input); $this->length = strlen($this->input); }
[ "public", "function", "load", "(", "$", "input", ")", "{", "$", "this", "->", "position", "=", "0", ";", "$", "this", "->", "previous", "=", "0", ";", "if", "(", "ord", "(", "$", "input", ")", "<", "32", ")", "{", "$", "this", "->", "input", "=", "$", "input", ";", "$", "this", "->", "length", "=", "strlen", "(", "$", "input", ")", ";", "return", ";", "}", "$", "position", "=", "stripos", "(", "$", "input", ",", "'x'", ")", ";", "if", "(", "false", "!==", "$", "position", ")", "{", "$", "input", "=", "substr", "(", "$", "input", ",", "$", "position", "+", "1", ")", ";", "}", "$", "this", "->", "input", "=", "pack", "(", "'H*'", ",", "$", "input", ")", ";", "$", "this", "->", "length", "=", "strlen", "(", "$", "this", "->", "input", ")", ";", "}" ]
@param string $input @throws UnexpectedValueException
[ "@param", "string", "$input" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Reader.php#L87-L107
creof/wkb-parser
lib/CrEOF/Geo/WKB/Reader.php
Reader.readFloats
public function readFloats($count) { $floats = array(); for ($i = 0; $i < $count; $i++) { $float = $this->readFloat(); if (! is_nan($float)) { $floats[] = $float; } } return $floats; }
php
public function readFloats($count) { $floats = array(); for ($i = 0; $i < $count; $i++) { $float = $this->readFloat(); if (! is_nan($float)) { $floats[] = $float; } } return $floats; }
[ "public", "function", "readFloats", "(", "$", "count", ")", "{", "$", "floats", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "float", "=", "$", "this", "->", "readFloat", "(", ")", ";", "if", "(", "!", "is_nan", "(", "$", "float", ")", ")", "{", "$", "floats", "[", "]", "=", "$", "float", ";", "}", "}", "return", "$", "floats", ";", "}" ]
@param int $count @return float[] @throws RangeException @throws UnexpectedValueException
[ "@param", "int", "$count" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Reader.php#L175-L188
creof/wkb-parser
lib/CrEOF/Geo/WKB/Reader.php
Reader.unpackInput
private function unpackInput($format) { $code = version_compare(PHP_VERSION, '5.5.0-dev', '>=') ? 'a' : 'A'; try { $result = unpack($format . 'result/' . $code . '*input', $this->input); } catch (\Exception $e) { throw new RangeException($e->getMessage(), $e->getCode(), $e->getPrevious()); } $this->input = $result['input']; return $result['result']; }
php
private function unpackInput($format) { $code = version_compare(PHP_VERSION, '5.5.0-dev', '>=') ? 'a' : 'A'; try { $result = unpack($format . 'result/' . $code . '*input', $this->input); } catch (\Exception $e) { throw new RangeException($e->getMessage(), $e->getCode(), $e->getPrevious()); } $this->input = $result['input']; return $result['result']; }
[ "private", "function", "unpackInput", "(", "$", "format", ")", "{", "$", "code", "=", "version_compare", "(", "PHP_VERSION", ",", "'5.5.0-dev'", ",", "'>='", ")", "?", "'a'", ":", "'A'", ";", "try", "{", "$", "result", "=", "unpack", "(", "$", "format", ".", "'result/'", ".", "$", "code", ".", "'*input'", ",", "$", "this", "->", "input", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "RangeException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", "->", "getPrevious", "(", ")", ")", ";", "}", "$", "this", "->", "input", "=", "$", "result", "[", "'input'", "]", ";", "return", "$", "result", "[", "'result'", "]", ";", "}" ]
@param string $format @return array @throws RangeException
[ "@param", "string", "$format" ]
train
https://github.com/creof/wkb-parser/blob/1ddb69da8cc90607dd528fd9992ef1fc10cc8839/lib/CrEOF/Geo/WKB/Reader.php#L244-L257
msgphp/domain
Infrastructure/Doctrine/MappingConfig.php
MappingConfig.interpolate
public function interpolate(string $contents): string { return str_replace('{{ key_max_length }}', (string) ($this->keyMaxLength ?? self::DEFAULT_KEY_MAX_LENGTH), $contents); }
php
public function interpolate(string $contents): string { return str_replace('{{ key_max_length }}', (string) ($this->keyMaxLength ?? self::DEFAULT_KEY_MAX_LENGTH), $contents); }
[ "public", "function", "interpolate", "(", "string", "$", "contents", ")", ":", "string", "{", "return", "str_replace", "(", "'{{ key_max_length }}'", ",", "(", "string", ")", "(", "$", "this", "->", "keyMaxLength", "??", "self", "::", "DEFAULT_KEY_MAX_LENGTH", ")", ",", "$", "contents", ")", ";", "}" ]
Replaces config values in template and returns it.
[ "Replaces", "config", "values", "in", "template", "and", "returns", "it", "." ]
train
https://github.com/msgphp/domain/blob/e95012b6ea6667bcc5aabe38fa886c52aa13d4f7/Infrastructure/Doctrine/MappingConfig.php#L47-L50
msgphp/domain
Infrastructure/Console/Context/ClassContextFactory.php
ClassContextFactory.askRequiredValue
private static function askRequiredValue(StyleInterface $io, ContextElement $element, $emptyValue) { if (null === $emptyValue) { return $element->askString($io); } if (false === $emptyValue) { return $element->askBool($io); } if ([] === $emptyValue) { return $element->askIterable($io); } return $emptyValue; }
php
private static function askRequiredValue(StyleInterface $io, ContextElement $element, $emptyValue) { if (null === $emptyValue) { return $element->askString($io); } if (false === $emptyValue) { return $element->askBool($io); } if ([] === $emptyValue) { return $element->askIterable($io); } return $emptyValue; }
[ "private", "static", "function", "askRequiredValue", "(", "StyleInterface", "$", "io", ",", "ContextElement", "$", "element", ",", "$", "emptyValue", ")", "{", "if", "(", "null", "===", "$", "emptyValue", ")", "{", "return", "$", "element", "->", "askString", "(", "$", "io", ")", ";", "}", "if", "(", "false", "===", "$", "emptyValue", ")", "{", "return", "$", "element", "->", "askBool", "(", "$", "io", ")", ";", "}", "if", "(", "[", "]", "===", "$", "emptyValue", ")", "{", "return", "$", "element", "->", "askIterable", "(", "$", "io", ")", ";", "}", "return", "$", "emptyValue", ";", "}" ]
@param mixed $emptyValue @return mixed
[ "@param", "mixed", "$emptyValue" ]
train
https://github.com/msgphp/domain/blob/e95012b6ea6667bcc5aabe38fa886c52aa13d4f7/Infrastructure/Console/Context/ClassContextFactory.php#L227-L242
msgphp/domain
Infrastructure/ApiPlatform/ProjectionDataProvider.php
ProjectionDataProvider.getCollection
public function getCollection(string $resourceClass, string $operationName = null): iterable { $collection = $this->repository->findAll($resourceClass); return new Paginator(new GenericPaginatedDomainCollection((static function () use ($collection): iterable { foreach ($collection as $document) { yield $document->toProjection(); } })(), $collection->getOffset(), $collection->getLimit(), (float) \count($collection), $collection->getTotalCount())); }
php
public function getCollection(string $resourceClass, string $operationName = null): iterable { $collection = $this->repository->findAll($resourceClass); return new Paginator(new GenericPaginatedDomainCollection((static function () use ($collection): iterable { foreach ($collection as $document) { yield $document->toProjection(); } })(), $collection->getOffset(), $collection->getLimit(), (float) \count($collection), $collection->getTotalCount())); }
[ "public", "function", "getCollection", "(", "string", "$", "resourceClass", ",", "string", "$", "operationName", "=", "null", ")", ":", "iterable", "{", "$", "collection", "=", "$", "this", "->", "repository", "->", "findAll", "(", "$", "resourceClass", ")", ";", "return", "new", "Paginator", "(", "new", "GenericPaginatedDomainCollection", "(", "(", "static", "function", "(", ")", "use", "(", "$", "collection", ")", ":", "iterable", "{", "foreach", "(", "$", "collection", "as", "$", "document", ")", "{", "yield", "$", "document", "->", "toProjection", "(", ")", ";", "}", "}", ")", "(", ")", ",", "$", "collection", "->", "getOffset", "(", ")", ",", "$", "collection", "->", "getLimit", "(", ")", ",", "(", "float", ")", "\\", "count", "(", "$", "collection", ")", ",", "$", "collection", "->", "getTotalCount", "(", ")", ")", ")", ";", "}" ]
@psalm-suppress ImplementedReturnTypeMismatch @return iterable|Projection[]
[ "@psalm", "-", "suppress", "ImplementedReturnTypeMismatch" ]
train
https://github.com/msgphp/domain/blob/e95012b6ea6667bcc5aabe38fa886c52aa13d4f7/Infrastructure/ApiPlatform/ProjectionDataProvider.php#L46-L55
msgphp/domain
Infrastructure/Doctrine/DomainIdType.php
DomainIdType.resolveName
final public static function resolveName($value): ?string { if ($value instanceof DomainId) { $class = \get_class($value); /** @var string $type */ foreach (self::$mapping as $type => $mapping) { if ($class === $mapping['class']) { return $type::NAME; } } return self::NAME; } return null; }
php
final public static function resolveName($value): ?string { if ($value instanceof DomainId) { $class = \get_class($value); /** @var string $type */ foreach (self::$mapping as $type => $mapping) { if ($class === $mapping['class']) { return $type::NAME; } } return self::NAME; } return null; }
[ "final", "public", "static", "function", "resolveName", "(", "$", "value", ")", ":", "?", "string", "{", "if", "(", "$", "value", "instanceof", "DomainId", ")", "{", "$", "class", "=", "\\", "get_class", "(", "$", "value", ")", ";", "/** @var string $type */", "foreach", "(", "self", "::", "$", "mapping", "as", "$", "type", "=>", "$", "mapping", ")", "{", "if", "(", "$", "class", "===", "$", "mapping", "[", "'class'", "]", ")", "{", "return", "$", "type", "::", "NAME", ";", "}", "}", "return", "self", "::", "NAME", ";", "}", "return", "null", ";", "}" ]
@param mixed $value @internal
[ "@param", "mixed", "$value" ]
train
https://github.com/msgphp/domain/blob/e95012b6ea6667bcc5aabe38fa886c52aa13d4f7/Infrastructure/Doctrine/DomainIdType.php#L71-L87
msgphp/domain
Infrastructure/Doctrine/DomainIdType.php
DomainIdType.resolveValue
final public static function resolveValue($value, AbstractPlatform $platform) { if ($value instanceof DomainId) { $class = \get_class($value); $type = Type::INTEGER; foreach (self::$mapping as $mapping) { if ($class === $mapping['class']) { $type = $mapping['data_type'] ?? $type; break; } } return self::getType($type)->convertToPHPValue($value->isEmpty() ? null : $value->toString(), $platform); } return $value; }
php
final public static function resolveValue($value, AbstractPlatform $platform) { if ($value instanceof DomainId) { $class = \get_class($value); $type = Type::INTEGER; foreach (self::$mapping as $mapping) { if ($class === $mapping['class']) { $type = $mapping['data_type'] ?? $type; break; } } return self::getType($type)->convertToPHPValue($value->isEmpty() ? null : $value->toString(), $platform); } return $value; }
[ "final", "public", "static", "function", "resolveValue", "(", "$", "value", ",", "AbstractPlatform", "$", "platform", ")", "{", "if", "(", "$", "value", "instanceof", "DomainId", ")", "{", "$", "class", "=", "\\", "get_class", "(", "$", "value", ")", ";", "$", "type", "=", "Type", "::", "INTEGER", ";", "foreach", "(", "self", "::", "$", "mapping", "as", "$", "mapping", ")", "{", "if", "(", "$", "class", "===", "$", "mapping", "[", "'class'", "]", ")", "{", "$", "type", "=", "$", "mapping", "[", "'data_type'", "]", "??", "$", "type", ";", "break", ";", "}", "}", "return", "self", "::", "getType", "(", "$", "type", ")", "->", "convertToPHPValue", "(", "$", "value", "->", "isEmpty", "(", ")", "?", "null", ":", "$", "value", "->", "toString", "(", ")", ",", "$", "platform", ")", ";", "}", "return", "$", "value", ";", "}" ]
@param mixed $value @return mixed @internal
[ "@param", "mixed", "$value" ]
train
https://github.com/msgphp/domain/blob/e95012b6ea6667bcc5aabe38fa886c52aa13d4f7/Infrastructure/Doctrine/DomainIdType.php#L96-L113
msgphp/domain
Infrastructure/Doctrine/DomainEntityRepositoryTrait.php
DomainEntityRepositoryTrait.doFind
private function doFind($id) { $id = $this->toIdentity($id); $entity = null === $id ? null : $this->em->find($this->class, $id); if (null === $entity) { throw EntityNotFoundException::createForId($this->class, $id); } return $entity; }
php
private function doFind($id) { $id = $this->toIdentity($id); $entity = null === $id ? null : $this->em->find($this->class, $id); if (null === $entity) { throw EntityNotFoundException::createForId($this->class, $id); } return $entity; }
[ "private", "function", "doFind", "(", "$", "id", ")", "{", "$", "id", "=", "$", "this", "->", "toIdentity", "(", "$", "id", ")", ";", "$", "entity", "=", "null", "===", "$", "id", "?", "null", ":", "$", "this", "->", "em", "->", "find", "(", "$", "this", "->", "class", ",", "$", "id", ")", ";", "if", "(", "null", "===", "$", "entity", ")", "{", "throw", "EntityNotFoundException", "::", "createForId", "(", "$", "this", "->", "class", ",", "$", "id", ")", ";", "}", "return", "$", "entity", ";", "}" ]
@param mixed $id @return object
[ "@param", "mixed", "$id" ]
train
https://github.com/msgphp/domain/blob/e95012b6ea6667bcc5aabe38fa886c52aa13d4f7/Infrastructure/Doctrine/DomainEntityRepositoryTrait.php#L76-L86
Sylius/SyliusFixturesBundle
src/Listener/LoggerListener.php
LoggerListener.beforeSuite
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void { $this->logger->notice(sprintf('Running suite "%s"...', $suiteEvent->suite()->getName())); }
php
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void { $this->logger->notice(sprintf('Running suite "%s"...', $suiteEvent->suite()->getName())); }
[ "public", "function", "beforeSuite", "(", "SuiteEvent", "$", "suiteEvent", ",", "array", "$", "options", ")", ":", "void", "{", "$", "this", "->", "logger", "->", "notice", "(", "sprintf", "(", "'Running suite \"%s\"...'", ",", "$", "suiteEvent", "->", "suite", "(", ")", "->", "getName", "(", ")", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Listener/LoggerListener.php#L31-L34
Sylius/SyliusFixturesBundle
src/Listener/LoggerListener.php
LoggerListener.beforeFixture
public function beforeFixture(FixtureEvent $fixtureEvent, array $options): void { $this->logger->notice(sprintf('Running fixture "%s"...', $fixtureEvent->fixture()->getName())); }
php
public function beforeFixture(FixtureEvent $fixtureEvent, array $options): void { $this->logger->notice(sprintf('Running fixture "%s"...', $fixtureEvent->fixture()->getName())); }
[ "public", "function", "beforeFixture", "(", "FixtureEvent", "$", "fixtureEvent", ",", "array", "$", "options", ")", ":", "void", "{", "$", "this", "->", "logger", "->", "notice", "(", "sprintf", "(", "'Running fixture \"%s\"...'", ",", "$", "fixtureEvent", "->", "fixture", "(", ")", "->", "getName", "(", ")", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Listener/LoggerListener.php#L39-L42
Sylius/SyliusFixturesBundle
src/DependencyInjection/Compiler/FixtureRegistryPass.php
FixtureRegistryPass.process
public function process(ContainerBuilder $container): void { if (!$container->has('sylius_fixtures.fixture_registry')) { return; } $fixtureRegistry = $container->findDefinition('sylius_fixtures.fixture_registry'); $taggedServices = $container->findTaggedServiceIds(self::FIXTURE_SERVICE_TAG); foreach (array_keys($taggedServices) as $id) { $fixtureRegistry->addMethodCall('addFixture', [new Reference($id)]); } }
php
public function process(ContainerBuilder $container): void { if (!$container->has('sylius_fixtures.fixture_registry')) { return; } $fixtureRegistry = $container->findDefinition('sylius_fixtures.fixture_registry'); $taggedServices = $container->findTaggedServiceIds(self::FIXTURE_SERVICE_TAG); foreach (array_keys($taggedServices) as $id) { $fixtureRegistry->addMethodCall('addFixture', [new Reference($id)]); } }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", ":", "void", "{", "if", "(", "!", "$", "container", "->", "has", "(", "'sylius_fixtures.fixture_registry'", ")", ")", "{", "return", ";", "}", "$", "fixtureRegistry", "=", "$", "container", "->", "findDefinition", "(", "'sylius_fixtures.fixture_registry'", ")", ";", "$", "taggedServices", "=", "$", "container", "->", "findTaggedServiceIds", "(", "self", "::", "FIXTURE_SERVICE_TAG", ")", ";", "foreach", "(", "array_keys", "(", "$", "taggedServices", ")", "as", "$", "id", ")", "{", "$", "fixtureRegistry", "->", "addMethodCall", "(", "'addFixture'", ",", "[", "new", "Reference", "(", "$", "id", ")", "]", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/DependencyInjection/Compiler/FixtureRegistryPass.php#L27-L39
Sylius/SyliusFixturesBundle
src/Listener/PHPCRPurgerListener.php
PHPCRPurgerListener.configureOptionsNode
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void { $optionsNode ->children() ->arrayNode('managers') ->defaultValue([null]) ->scalarPrototype() ; }
php
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void { $optionsNode ->children() ->arrayNode('managers') ->defaultValue([null]) ->scalarPrototype() ; }
[ "protected", "function", "configureOptionsNode", "(", "ArrayNodeDefinition", "$", "optionsNode", ")", ":", "void", "{", "$", "optionsNode", "->", "children", "(", ")", "->", "arrayNode", "(", "'managers'", ")", "->", "defaultValue", "(", "[", "null", "]", ")", "->", "scalarPrototype", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Listener/PHPCRPurgerListener.php#L56-L64
Sylius/SyliusFixturesBundle
src/Listener/MongoDBPurgerListener.php
MongoDBPurgerListener.beforeSuite
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void { foreach ($options['managers'] as $managerName) { /** @var DocumentManager $manager */ $manager = $this->managerRegistry->getManager($managerName); $purger = new MongoDBPurger($manager); $purger->purge(); } }
php
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void { foreach ($options['managers'] as $managerName) { /** @var DocumentManager $manager */ $manager = $this->managerRegistry->getManager($managerName); $purger = new MongoDBPurger($manager); $purger->purge(); } }
[ "public", "function", "beforeSuite", "(", "SuiteEvent", "$", "suiteEvent", ",", "array", "$", "options", ")", ":", "void", "{", "foreach", "(", "$", "options", "[", "'managers'", "]", "as", "$", "managerName", ")", "{", "/** @var DocumentManager $manager */", "$", "manager", "=", "$", "this", "->", "managerRegistry", "->", "getManager", "(", "$", "managerName", ")", ";", "$", "purger", "=", "new", "MongoDBPurger", "(", "$", "manager", ")", ";", "$", "purger", "->", "purge", "(", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Listener/MongoDBPurgerListener.php#L34-L43
Sylius/SyliusFixturesBundle
src/Suite/Suite.php
Suite.getFixtures
public function getFixtures(): iterable { $fixtures = clone $this->fixtures; foreach ($fixtures as $fixture) { yield $fixture['fixture'] => $fixture['options']; } }
php
public function getFixtures(): iterable { $fixtures = clone $this->fixtures; foreach ($fixtures as $fixture) { yield $fixture['fixture'] => $fixture['options']; } }
[ "public", "function", "getFixtures", "(", ")", ":", "iterable", "{", "$", "fixtures", "=", "clone", "$", "this", "->", "fixtures", ";", "foreach", "(", "$", "fixtures", "as", "$", "fixture", ")", "{", "yield", "$", "fixture", "[", "'fixture'", "]", "=>", "$", "fixture", "[", "'options'", "]", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Suite/Suite.php#L59-L65
Sylius/SyliusFixturesBundle
src/Suite/Suite.php
Suite.getListeners
public function getListeners(): iterable { $listeners = clone $this->listeners; foreach ($listeners as $listener) { yield $listener['listener'] => $listener['options']; } }
php
public function getListeners(): iterable { $listeners = clone $this->listeners; foreach ($listeners as $listener) { yield $listener['listener'] => $listener['options']; } }
[ "public", "function", "getListeners", "(", ")", ":", "iterable", "{", "$", "listeners", "=", "clone", "$", "this", "->", "listeners", ";", "foreach", "(", "$", "listeners", "as", "$", "listener", ")", "{", "yield", "$", "listener", "[", "'listener'", "]", "=>", "$", "listener", "[", "'options'", "]", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Suite/Suite.php#L70-L76
Sylius/SyliusFixturesBundle
src/Command/FixturesListCommand.php
FixturesListCommand.execute
protected function execute(InputInterface $input, OutputInterface $output): void { $this->listSuites($output); $this->listFixtures($output); }
php
protected function execute(InputInterface $input, OutputInterface $output): void { $this->listSuites($output); $this->listFixtures($output); }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", ":", "void", "{", "$", "this", "->", "listSuites", "(", "$", "output", ")", ";", "$", "this", "->", "listFixtures", "(", "$", "output", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Command/FixturesListCommand.php#L38-L42
Sylius/SyliusFixturesBundle
src/Listener/AbstractListener.php
AbstractListener.getConfigTreeBuilder
final public function getConfigTreeBuilder(): TreeBuilder { if (method_exists(TreeBuilder::class, 'getRootNode')) { $treeBuilder = new TreeBuilder($this->getName()); /** @var ArrayNodeDefinition $optionsNode */ $optionsNode = $treeBuilder->getRootNode(); } else { // BC layer for symfony/config 4.1 and older $treeBuilder = new TreeBuilder(); /** @var ArrayNodeDefinition $optionsNode */ $optionsNode = $treeBuilder->root($this->getName()); } $this->configureOptionsNode($optionsNode); return $treeBuilder; }
php
final public function getConfigTreeBuilder(): TreeBuilder { if (method_exists(TreeBuilder::class, 'getRootNode')) { $treeBuilder = new TreeBuilder($this->getName()); /** @var ArrayNodeDefinition $optionsNode */ $optionsNode = $treeBuilder->getRootNode(); } else { // BC layer for symfony/config 4.1 and older $treeBuilder = new TreeBuilder(); /** @var ArrayNodeDefinition $optionsNode */ $optionsNode = $treeBuilder->root($this->getName()); } $this->configureOptionsNode($optionsNode); return $treeBuilder; }
[ "final", "public", "function", "getConfigTreeBuilder", "(", ")", ":", "TreeBuilder", "{", "if", "(", "method_exists", "(", "TreeBuilder", "::", "class", ",", "'getRootNode'", ")", ")", "{", "$", "treeBuilder", "=", "new", "TreeBuilder", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "/** @var ArrayNodeDefinition $optionsNode */", "$", "optionsNode", "=", "$", "treeBuilder", "->", "getRootNode", "(", ")", ";", "}", "else", "{", "// BC layer for symfony/config 4.1 and older", "$", "treeBuilder", "=", "new", "TreeBuilder", "(", ")", ";", "/** @var ArrayNodeDefinition $optionsNode */", "$", "optionsNode", "=", "$", "treeBuilder", "->", "root", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "}", "$", "this", "->", "configureOptionsNode", "(", "$", "optionsNode", ")", ";", "return", "$", "treeBuilder", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Listener/AbstractListener.php#L24-L42
Sylius/SyliusFixturesBundle
src/Suite/SuiteFactory.php
SuiteFactory.createSuite
public function createSuite(string $name, array $configuration): SuiteInterface { Assert::keyExists($configuration, 'fixtures'); Assert::keyExists($configuration, 'listeners'); $suite = new Suite($name); foreach ($configuration['fixtures'] as $fixtureAlias => $fixtureAttributes) { $this->addFixtureToSuite($suite, $fixtureAlias, $fixtureAttributes); } foreach ($configuration['listeners'] as $listenerName => $listenerAttributes) { $this->addListenerToSuite($suite, $listenerName, $listenerAttributes); } return $suite; }
php
public function createSuite(string $name, array $configuration): SuiteInterface { Assert::keyExists($configuration, 'fixtures'); Assert::keyExists($configuration, 'listeners'); $suite = new Suite($name); foreach ($configuration['fixtures'] as $fixtureAlias => $fixtureAttributes) { $this->addFixtureToSuite($suite, $fixtureAlias, $fixtureAttributes); } foreach ($configuration['listeners'] as $listenerName => $listenerAttributes) { $this->addListenerToSuite($suite, $listenerName, $listenerAttributes); } return $suite; }
[ "public", "function", "createSuite", "(", "string", "$", "name", ",", "array", "$", "configuration", ")", ":", "SuiteInterface", "{", "Assert", "::", "keyExists", "(", "$", "configuration", ",", "'fixtures'", ")", ";", "Assert", "::", "keyExists", "(", "$", "configuration", ",", "'listeners'", ")", ";", "$", "suite", "=", "new", "Suite", "(", "$", "name", ")", ";", "foreach", "(", "$", "configuration", "[", "'fixtures'", "]", "as", "$", "fixtureAlias", "=>", "$", "fixtureAttributes", ")", "{", "$", "this", "->", "addFixtureToSuite", "(", "$", "suite", ",", "$", "fixtureAlias", ",", "$", "fixtureAttributes", ")", ";", "}", "foreach", "(", "$", "configuration", "[", "'listeners'", "]", "as", "$", "listenerName", "=>", "$", "listenerAttributes", ")", "{", "$", "this", "->", "addListenerToSuite", "(", "$", "suite", ",", "$", "listenerName", ",", "$", "listenerAttributes", ")", ";", "}", "return", "$", "suite", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Suite/SuiteFactory.php#L45-L61
Sylius/SyliusFixturesBundle
src/SyliusFixturesBundle.php
SyliusFixturesBundle.build
public function build(ContainerBuilder $container): void { parent::build($container); $container->addCompilerPass(new FixtureRegistryPass()); $container->addCompilerPass(new ListenerRegistryPass()); }
php
public function build(ContainerBuilder $container): void { parent::build($container); $container->addCompilerPass(new FixtureRegistryPass()); $container->addCompilerPass(new ListenerRegistryPass()); }
[ "public", "function", "build", "(", "ContainerBuilder", "$", "container", ")", ":", "void", "{", "parent", "::", "build", "(", "$", "container", ")", ";", "$", "container", "->", "addCompilerPass", "(", "new", "FixtureRegistryPass", "(", ")", ")", ";", "$", "container", "->", "addCompilerPass", "(", "new", "ListenerRegistryPass", "(", ")", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/SyliusFixturesBundle.php#L26-L32
Sylius/SyliusFixturesBundle
src/Loader/FixtureLoader.php
FixtureLoader.load
public function load(SuiteInterface $suite, FixtureInterface $fixture, array $options): void { $fixture->load($options); }
php
public function load(SuiteInterface $suite, FixtureInterface $fixture, array $options): void { $fixture->load($options); }
[ "public", "function", "load", "(", "SuiteInterface", "$", "suite", ",", "FixtureInterface", "$", "fixture", ",", "array", "$", "options", ")", ":", "void", "{", "$", "fixture", "->", "load", "(", "$", "options", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Loader/FixtureLoader.php#L24-L27
Sylius/SyliusFixturesBundle
src/Command/FixturesLoadCommand.php
FixturesLoadCommand.execute
protected function execute(InputInterface $input, OutputInterface $output): void { if ($input->isInteractive()) { /** @var QuestionHelper $questionHelper */ $questionHelper = $this->getHelper('question'); $output->writeln(sprintf( "\n<error>Warning! Loading fixtures will purge your database for the %s environment.</error>\n", $this->getEnvironment() )); if (!$questionHelper->ask($input, $output, new ConfirmationQuestion('Continue? (y/N) ', false))) { return; } } $this->loadSuites($input); }
php
protected function execute(InputInterface $input, OutputInterface $output): void { if ($input->isInteractive()) { /** @var QuestionHelper $questionHelper */ $questionHelper = $this->getHelper('question'); $output->writeln(sprintf( "\n<error>Warning! Loading fixtures will purge your database for the %s environment.</error>\n", $this->getEnvironment() )); if (!$questionHelper->ask($input, $output, new ConfirmationQuestion('Continue? (y/N) ', false))) { return; } } $this->loadSuites($input); }
[ "protected", "function", "execute", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", ":", "void", "{", "if", "(", "$", "input", "->", "isInteractive", "(", ")", ")", "{", "/** @var QuestionHelper $questionHelper */", "$", "questionHelper", "=", "$", "this", "->", "getHelper", "(", "'question'", ")", ";", "$", "output", "->", "writeln", "(", "sprintf", "(", "\"\\n<error>Warning! Loading fixtures will purge your database for the %s environment.</error>\\n\"", ",", "$", "this", "->", "getEnvironment", "(", ")", ")", ")", ";", "if", "(", "!", "$", "questionHelper", "->", "ask", "(", "$", "input", ",", "$", "output", ",", "new", "ConfirmationQuestion", "(", "'Continue? (y/N) '", ",", "false", ")", ")", ")", "{", "return", ";", "}", "}", "$", "this", "->", "loadSuites", "(", "$", "input", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Command/FixturesLoadCommand.php#L42-L59
Sylius/SyliusFixturesBundle
src/Listener/ORMPurgerListener.php
ORMPurgerListener.beforeSuite
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void { foreach ($options['managers'] as $managerName) { /** @var EntityManagerInterface $manager */ $manager = $this->managerRegistry->getManager($managerName); $purger = new ORMPurger($manager, $options['exclude']); $purger->setPurgeMode(static::$purgeModes[$options['mode']]); $purger->purge(); } }
php
public function beforeSuite(SuiteEvent $suiteEvent, array $options): void { foreach ($options['managers'] as $managerName) { /** @var EntityManagerInterface $manager */ $manager = $this->managerRegistry->getManager($managerName); $purger = new ORMPurger($manager, $options['exclude']); $purger->setPurgeMode(static::$purgeModes[$options['mode']]); $purger->purge(); } }
[ "public", "function", "beforeSuite", "(", "SuiteEvent", "$", "suiteEvent", ",", "array", "$", "options", ")", ":", "void", "{", "foreach", "(", "$", "options", "[", "'managers'", "]", "as", "$", "managerName", ")", "{", "/** @var EntityManagerInterface $manager */", "$", "manager", "=", "$", "this", "->", "managerRegistry", "->", "getManager", "(", "$", "managerName", ")", ";", "$", "purger", "=", "new", "ORMPurger", "(", "$", "manager", ",", "$", "options", "[", "'exclude'", "]", ")", ";", "$", "purger", "->", "setPurgeMode", "(", "static", "::", "$", "purgeModes", "[", "$", "options", "[", "'mode'", "]", "]", ")", ";", "$", "purger", "->", "purge", "(", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Listener/ORMPurgerListener.php#L40-L50
Sylius/SyliusFixturesBundle
src/Listener/ORMPurgerListener.php
ORMPurgerListener.configureOptionsNode
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void { $optionsNodeBuilder = $optionsNode->children(); $optionsNodeBuilder ->enumNode('mode') ->values(['delete', 'truncate']) ->defaultValue('delete') ; $optionsNodeBuilder ->arrayNode('managers') ->defaultValue([null]) ->scalarPrototype() ; $optionsNodeBuilder ->arrayNode('exclude') ->defaultValue([]) ->scalarPrototype() ; }
php
protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void { $optionsNodeBuilder = $optionsNode->children(); $optionsNodeBuilder ->enumNode('mode') ->values(['delete', 'truncate']) ->defaultValue('delete') ; $optionsNodeBuilder ->arrayNode('managers') ->defaultValue([null]) ->scalarPrototype() ; $optionsNodeBuilder ->arrayNode('exclude') ->defaultValue([]) ->scalarPrototype() ; }
[ "protected", "function", "configureOptionsNode", "(", "ArrayNodeDefinition", "$", "optionsNode", ")", ":", "void", "{", "$", "optionsNodeBuilder", "=", "$", "optionsNode", "->", "children", "(", ")", ";", "$", "optionsNodeBuilder", "->", "enumNode", "(", "'mode'", ")", "->", "values", "(", "[", "'delete'", ",", "'truncate'", "]", ")", "->", "defaultValue", "(", "'delete'", ")", ";", "$", "optionsNodeBuilder", "->", "arrayNode", "(", "'managers'", ")", "->", "defaultValue", "(", "[", "null", "]", ")", "->", "scalarPrototype", "(", ")", ";", "$", "optionsNodeBuilder", "->", "arrayNode", "(", "'exclude'", ")", "->", "defaultValue", "(", "[", "]", ")", "->", "scalarPrototype", "(", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Listener/ORMPurgerListener.php#L63-L84
Sylius/SyliusFixturesBundle
src/DependencyInjection/Compiler/ListenerRegistryPass.php
ListenerRegistryPass.process
public function process(ContainerBuilder $container): void { if (!$container->has('sylius_fixtures.listener_registry')) { return; } $listenerRegistry = $container->findDefinition('sylius_fixtures.listener_registry'); $taggedServices = $container->findTaggedServiceIds(self::LISTENER_SERVICE_TAG); foreach (array_keys($taggedServices) as $id) { $listenerRegistry->addMethodCall('addListener', [new Reference($id)]); } }
php
public function process(ContainerBuilder $container): void { if (!$container->has('sylius_fixtures.listener_registry')) { return; } $listenerRegistry = $container->findDefinition('sylius_fixtures.listener_registry'); $taggedServices = $container->findTaggedServiceIds(self::LISTENER_SERVICE_TAG); foreach (array_keys($taggedServices) as $id) { $listenerRegistry->addMethodCall('addListener', [new Reference($id)]); } }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", ":", "void", "{", "if", "(", "!", "$", "container", "->", "has", "(", "'sylius_fixtures.listener_registry'", ")", ")", "{", "return", ";", "}", "$", "listenerRegistry", "=", "$", "container", "->", "findDefinition", "(", "'sylius_fixtures.listener_registry'", ")", ";", "$", "taggedServices", "=", "$", "container", "->", "findTaggedServiceIds", "(", "self", "::", "LISTENER_SERVICE_TAG", ")", ";", "foreach", "(", "array_keys", "(", "$", "taggedServices", ")", "as", "$", "id", ")", "{", "$", "listenerRegistry", "->", "addMethodCall", "(", "'addListener'", ",", "[", "new", "Reference", "(", "$", "id", ")", "]", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/DependencyInjection/Compiler/ListenerRegistryPass.php#L27-L39
Sylius/SyliusFixturesBundle
src/Loader/HookableSuiteLoader.php
HookableSuiteLoader.load
public function load(SuiteInterface $suite): void { $suiteEvent = new SuiteEvent($suite); $this->executeBeforeSuiteListeners($suite, $suiteEvent); $this->decoratedSuiteLoader->load($suite); $this->executeAfterSuiteListeners($suite, $suiteEvent); }
php
public function load(SuiteInterface $suite): void { $suiteEvent = new SuiteEvent($suite); $this->executeBeforeSuiteListeners($suite, $suiteEvent); $this->decoratedSuiteLoader->load($suite); $this->executeAfterSuiteListeners($suite, $suiteEvent); }
[ "public", "function", "load", "(", "SuiteInterface", "$", "suite", ")", ":", "void", "{", "$", "suiteEvent", "=", "new", "SuiteEvent", "(", "$", "suite", ")", ";", "$", "this", "->", "executeBeforeSuiteListeners", "(", "$", "suite", ",", "$", "suiteEvent", ")", ";", "$", "this", "->", "decoratedSuiteLoader", "->", "load", "(", "$", "suite", ")", ";", "$", "this", "->", "executeAfterSuiteListeners", "(", "$", "suite", ",", "$", "suiteEvent", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Loader/HookableSuiteLoader.php#L34-L43
Sylius/SyliusFixturesBundle
src/Loader/SuiteLoader.php
SuiteLoader.load
public function load(SuiteInterface $suite): void { /** @var FixtureInterface $fixture */ /** @var array $fixtureOptions */ foreach ($suite->getFixtures() as $fixture => $fixtureOptions) { $this->fixtureLoader->load($suite, $fixture, $fixtureOptions); } }
php
public function load(SuiteInterface $suite): void { /** @var FixtureInterface $fixture */ /** @var array $fixtureOptions */ foreach ($suite->getFixtures() as $fixture => $fixtureOptions) { $this->fixtureLoader->load($suite, $fixture, $fixtureOptions); } }
[ "public", "function", "load", "(", "SuiteInterface", "$", "suite", ")", ":", "void", "{", "/** @var FixtureInterface $fixture */", "/** @var array $fixtureOptions */", "foreach", "(", "$", "suite", "->", "getFixtures", "(", ")", "as", "$", "fixture", "=>", "$", "fixtureOptions", ")", "{", "$", "this", "->", "fixtureLoader", "->", "load", "(", "$", "suite", ",", "$", "fixture", ",", "$", "fixtureOptions", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Loader/SuiteLoader.php#L32-L39
Sylius/SyliusFixturesBundle
src/DependencyInjection/SyliusFixturesExtension.php
SyliusFixturesExtension.load
public function load(array $config, ContainerBuilder $container): void { $config = $this->processConfiguration($this->getConfiguration([], $container), $config); $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); $this->registerSuites($config, $container); $container ->registerForAutoconfiguration(FixtureInterface::class) ->addTag(FixtureRegistryPass::FIXTURE_SERVICE_TAG) ; $container ->registerForAutoconfiguration(ListenerInterface::class) ->addTag(ListenerRegistryPass::LISTENER_SERVICE_TAG) ; }
php
public function load(array $config, ContainerBuilder $container): void { $config = $this->processConfiguration($this->getConfiguration([], $container), $config); $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.xml'); $this->registerSuites($config, $container); $container ->registerForAutoconfiguration(FixtureInterface::class) ->addTag(FixtureRegistryPass::FIXTURE_SERVICE_TAG) ; $container ->registerForAutoconfiguration(ListenerInterface::class) ->addTag(ListenerRegistryPass::LISTENER_SERVICE_TAG) ; }
[ "public", "function", "load", "(", "array", "$", "config", ",", "ContainerBuilder", "$", "container", ")", ":", "void", "{", "$", "config", "=", "$", "this", "->", "processConfiguration", "(", "$", "this", "->", "getConfiguration", "(", "[", "]", ",", "$", "container", ")", ",", "$", "config", ")", ";", "$", "loader", "=", "new", "XmlFileLoader", "(", "$", "container", ",", "new", "FileLocator", "(", "__DIR__", ".", "'/../Resources/config'", ")", ")", ";", "$", "loader", "->", "load", "(", "'services.xml'", ")", ";", "$", "this", "->", "registerSuites", "(", "$", "config", ",", "$", "container", ")", ";", "$", "container", "->", "registerForAutoconfiguration", "(", "FixtureInterface", "::", "class", ")", "->", "addTag", "(", "FixtureRegistryPass", "::", "FIXTURE_SERVICE_TAG", ")", ";", "$", "container", "->", "registerForAutoconfiguration", "(", "ListenerInterface", "::", "class", ")", "->", "addTag", "(", "ListenerRegistryPass", "::", "LISTENER_SERVICE_TAG", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/DependencyInjection/SyliusFixturesExtension.php#L40-L57
Sylius/SyliusFixturesBundle
src/DependencyInjection/SyliusFixturesExtension.php
SyliusFixturesExtension.prepend
public function prepend(ContainerBuilder $container): void { $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $extensionsNamesToConfigurationFiles = [ 'doctrine' => 'doctrine/orm.xml', 'doctrine_mongodb' => 'doctrine/mongodb-odm.xml', 'doctrine_phpcr' => 'doctrine/phpcr-odm.xml', ]; foreach ($extensionsNamesToConfigurationFiles as $extensionName => $configurationFile) { if (!$container->hasExtension($extensionName)) { continue; } $loader->load('services/integrations/' . $configurationFile); } }
php
public function prepend(ContainerBuilder $container): void { $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $extensionsNamesToConfigurationFiles = [ 'doctrine' => 'doctrine/orm.xml', 'doctrine_mongodb' => 'doctrine/mongodb-odm.xml', 'doctrine_phpcr' => 'doctrine/phpcr-odm.xml', ]; foreach ($extensionsNamesToConfigurationFiles as $extensionName => $configurationFile) { if (!$container->hasExtension($extensionName)) { continue; } $loader->load('services/integrations/' . $configurationFile); } }
[ "public", "function", "prepend", "(", "ContainerBuilder", "$", "container", ")", ":", "void", "{", "$", "loader", "=", "new", "XmlFileLoader", "(", "$", "container", ",", "new", "FileLocator", "(", "__DIR__", ".", "'/../Resources/config'", ")", ")", ";", "$", "extensionsNamesToConfigurationFiles", "=", "[", "'doctrine'", "=>", "'doctrine/orm.xml'", ",", "'doctrine_mongodb'", "=>", "'doctrine/mongodb-odm.xml'", ",", "'doctrine_phpcr'", "=>", "'doctrine/phpcr-odm.xml'", ",", "]", ";", "foreach", "(", "$", "extensionsNamesToConfigurationFiles", "as", "$", "extensionName", "=>", "$", "configurationFile", ")", "{", "if", "(", "!", "$", "container", "->", "hasExtension", "(", "$", "extensionName", ")", ")", "{", "continue", ";", "}", "$", "loader", "->", "load", "(", "'services/integrations/'", ".", "$", "configurationFile", ")", ";", "}", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/DependencyInjection/SyliusFixturesExtension.php#L62-L79
Sylius/SyliusFixturesBundle
src/Listener/ListenerRegistry.php
ListenerRegistry.getListener
public function getListener(string $name): ListenerInterface { if (!isset($this->listeners[$name])) { throw new ListenerNotFoundException($name); } return $this->listeners[$name]; }
php
public function getListener(string $name): ListenerInterface { if (!isset($this->listeners[$name])) { throw new ListenerNotFoundException($name); } return $this->listeners[$name]; }
[ "public", "function", "getListener", "(", "string", "$", "name", ")", ":", "ListenerInterface", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "listeners", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "ListenerNotFoundException", "(", "$", "name", ")", ";", "}", "return", "$", "this", "->", "listeners", "[", "$", "name", "]", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Listener/ListenerRegistry.php#L33-L40
Sylius/SyliusFixturesBundle
src/Fixture/FixtureRegistry.php
FixtureRegistry.getFixture
public function getFixture(string $name): FixtureInterface { if (!isset($this->fixtures[$name])) { throw new FixtureNotFoundException($name); } return $this->fixtures[$name]; }
php
public function getFixture(string $name): FixtureInterface { if (!isset($this->fixtures[$name])) { throw new FixtureNotFoundException($name); } return $this->fixtures[$name]; }
[ "public", "function", "getFixture", "(", "string", "$", "name", ")", ":", "FixtureInterface", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "fixtures", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "FixtureNotFoundException", "(", "$", "name", ")", ";", "}", "return", "$", "this", "->", "fixtures", "[", "$", "name", "]", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Fixture/FixtureRegistry.php#L33-L40
Sylius/SyliusFixturesBundle
src/Suite/LazySuiteRegistry.php
LazySuiteRegistry.getSuite
public function getSuite(string $name): SuiteInterface { if (isset($this->suites[$name])) { return $this->suites[$name]; } if (!isset($this->suiteDefinitions[$name])) { throw new SuiteNotFoundException($name); } return $this->suites[$name] = $this->suiteFactory->createSuite($name, $this->suiteDefinitions[$name]); }
php
public function getSuite(string $name): SuiteInterface { if (isset($this->suites[$name])) { return $this->suites[$name]; } if (!isset($this->suiteDefinitions[$name])) { throw new SuiteNotFoundException($name); } return $this->suites[$name] = $this->suiteFactory->createSuite($name, $this->suiteDefinitions[$name]); }
[ "public", "function", "getSuite", "(", "string", "$", "name", ")", ":", "SuiteInterface", "{", "if", "(", "isset", "(", "$", "this", "->", "suites", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "suites", "[", "$", "name", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "suiteDefinitions", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "SuiteNotFoundException", "(", "$", "name", ")", ";", "}", "return", "$", "this", "->", "suites", "[", "$", "name", "]", "=", "$", "this", "->", "suiteFactory", "->", "createSuite", "(", "$", "name", ",", "$", "this", "->", "suiteDefinitions", "[", "$", "name", "]", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Suite/LazySuiteRegistry.php#L40-L51
Sylius/SyliusFixturesBundle
src/Suite/LazySuiteRegistry.php
LazySuiteRegistry.getSuites
public function getSuites(): array { $suites = []; foreach (array_keys($this->suiteDefinitions) as $name) { $suites[$name] = $this->getSuite($name); } return $suites; }
php
public function getSuites(): array { $suites = []; foreach (array_keys($this->suiteDefinitions) as $name) { $suites[$name] = $this->getSuite($name); } return $suites; }
[ "public", "function", "getSuites", "(", ")", ":", "array", "{", "$", "suites", "=", "[", "]", ";", "foreach", "(", "array_keys", "(", "$", "this", "->", "suiteDefinitions", ")", "as", "$", "name", ")", "{", "$", "suites", "[", "$", "name", "]", "=", "$", "this", "->", "getSuite", "(", "$", "name", ")", ";", "}", "return", "$", "suites", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Suite/LazySuiteRegistry.php#L56-L64
Sylius/SyliusFixturesBundle
src/Loader/HookableFixtureLoader.php
HookableFixtureLoader.load
public function load(SuiteInterface $suite, FixtureInterface $fixture, array $options): void { $fixtureEvent = new FixtureEvent($suite, $fixture, $options); $this->executeBeforeFixtureListeners($suite, $fixtureEvent); $this->decoratedFixtureLoader->load($suite, $fixture, $options); $this->executeAfterFixtureListeners($suite, $fixtureEvent); }
php
public function load(SuiteInterface $suite, FixtureInterface $fixture, array $options): void { $fixtureEvent = new FixtureEvent($suite, $fixture, $options); $this->executeBeforeFixtureListeners($suite, $fixtureEvent); $this->decoratedFixtureLoader->load($suite, $fixture, $options); $this->executeAfterFixtureListeners($suite, $fixtureEvent); }
[ "public", "function", "load", "(", "SuiteInterface", "$", "suite", ",", "FixtureInterface", "$", "fixture", ",", "array", "$", "options", ")", ":", "void", "{", "$", "fixtureEvent", "=", "new", "FixtureEvent", "(", "$", "suite", ",", "$", "fixture", ",", "$", "options", ")", ";", "$", "this", "->", "executeBeforeFixtureListeners", "(", "$", "suite", ",", "$", "fixtureEvent", ")", ";", "$", "this", "->", "decoratedFixtureLoader", "->", "load", "(", "$", "suite", ",", "$", "fixture", ",", "$", "options", ")", ";", "$", "this", "->", "executeAfterFixtureListeners", "(", "$", "suite", ",", "$", "fixtureEvent", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/Loader/HookableFixtureLoader.php#L35-L44
Sylius/SyliusFixturesBundle
src/DependencyInjection/Configuration.php
Configuration.getConfigTreeBuilder
public function getConfigTreeBuilder(): TreeBuilder { if (method_exists(TreeBuilder::class, 'getRootNode')) { $treeBuilder = new TreeBuilder('sylius_fixtures'); /** @var ArrayNodeDefinition $rootNode */ $rootNode = $treeBuilder->getRootNode(); } else { // BC layer for symfony/config 4.1 and older $treeBuilder = new TreeBuilder(); /** @var ArrayNodeDefinition $rootNode */ $rootNode = $treeBuilder->root('sylius_fixtures'); } $this->buildSuitesNode($rootNode); return $treeBuilder; }
php
public function getConfigTreeBuilder(): TreeBuilder { if (method_exists(TreeBuilder::class, 'getRootNode')) { $treeBuilder = new TreeBuilder('sylius_fixtures'); /** @var ArrayNodeDefinition $rootNode */ $rootNode = $treeBuilder->getRootNode(); } else { // BC layer for symfony/config 4.1 and older $treeBuilder = new TreeBuilder(); /** @var ArrayNodeDefinition $rootNode */ $rootNode = $treeBuilder->root('sylius_fixtures'); } $this->buildSuitesNode($rootNode); return $treeBuilder; }
[ "public", "function", "getConfigTreeBuilder", "(", ")", ":", "TreeBuilder", "{", "if", "(", "method_exists", "(", "TreeBuilder", "::", "class", ",", "'getRootNode'", ")", ")", "{", "$", "treeBuilder", "=", "new", "TreeBuilder", "(", "'sylius_fixtures'", ")", ";", "/** @var ArrayNodeDefinition $rootNode */", "$", "rootNode", "=", "$", "treeBuilder", "->", "getRootNode", "(", ")", ";", "}", "else", "{", "// BC layer for symfony/config 4.1 and older", "$", "treeBuilder", "=", "new", "TreeBuilder", "(", ")", ";", "/** @var ArrayNodeDefinition $rootNode */", "$", "rootNode", "=", "$", "treeBuilder", "->", "root", "(", "'sylius_fixtures'", ")", ";", "}", "$", "this", "->", "buildSuitesNode", "(", "$", "rootNode", ")", ";", "return", "$", "treeBuilder", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/Sylius/SyliusFixturesBundle/blob/f7543ea10ac5bb0dce93129dcd12a7996d1beac1/src/DependencyInjection/Configuration.php#L25-L43
contributte/di
src/Extension/NewExtensionsExtension.php
NewExtensionsExtension.loadConfiguration
public function loadConfiguration(): void { $extensions = []; // Collect all extensions foreach ($this->getConfig() as $name => $extension) { if (is_int($name)) { $name = null; } if (is_array($extension)) { $extension = array_merge([ 'priority' => 10, ], $extension); if (!array_key_exists('class', $extension)) { throw new InvalidStateException(sprintf('Key "class" is required')); } $extensions[] = [ 'name' => $name, 'class' => $extension['class'], 'arguments' => [], 'priority' => $extension['priority'], ]; } elseif ($extension instanceof Statement) { $extensions[] = [ 'name' => $name, 'class' => $extension->getEntity(), 'arguments' => $extension->arguments, 'priority' => $extension['priority'], ]; } elseif (is_string($extension)) { $extensions[] = [ 'name' => $name, 'class' => $extension, 'arguments' => [], 'priority' => 10, ]; } else { throw new InvalidStateException( sprintf( 'Invalid extension definition "%s" given', is_scalar($extension) ? $extension : gettype($extension) ) ); } } // Sort all extensions usort($extensions, function ($a, $b) { if ($a['priority'] === $b['priority']) return 0; return $a['priority'] > $b['priority'] ? 1 : -1; }); // Register all extensions foreach ($extensions as $extension) { $instance = new $extension['class'](...$extension['arguments']); $this->compiler->addExtension($extension['name'], $instance); } }
php
public function loadConfiguration(): void { $extensions = []; // Collect all extensions foreach ($this->getConfig() as $name => $extension) { if (is_int($name)) { $name = null; } if (is_array($extension)) { $extension = array_merge([ 'priority' => 10, ], $extension); if (!array_key_exists('class', $extension)) { throw new InvalidStateException(sprintf('Key "class" is required')); } $extensions[] = [ 'name' => $name, 'class' => $extension['class'], 'arguments' => [], 'priority' => $extension['priority'], ]; } elseif ($extension instanceof Statement) { $extensions[] = [ 'name' => $name, 'class' => $extension->getEntity(), 'arguments' => $extension->arguments, 'priority' => $extension['priority'], ]; } elseif (is_string($extension)) { $extensions[] = [ 'name' => $name, 'class' => $extension, 'arguments' => [], 'priority' => 10, ]; } else { throw new InvalidStateException( sprintf( 'Invalid extension definition "%s" given', is_scalar($extension) ? $extension : gettype($extension) ) ); } } // Sort all extensions usort($extensions, function ($a, $b) { if ($a['priority'] === $b['priority']) return 0; return $a['priority'] > $b['priority'] ? 1 : -1; }); // Register all extensions foreach ($extensions as $extension) { $instance = new $extension['class'](...$extension['arguments']); $this->compiler->addExtension($extension['name'], $instance); } }
[ "public", "function", "loadConfiguration", "(", ")", ":", "void", "{", "$", "extensions", "=", "[", "]", ";", "// Collect all extensions", "foreach", "(", "$", "this", "->", "getConfig", "(", ")", "as", "$", "name", "=>", "$", "extension", ")", "{", "if", "(", "is_int", "(", "$", "name", ")", ")", "{", "$", "name", "=", "null", ";", "}", "if", "(", "is_array", "(", "$", "extension", ")", ")", "{", "$", "extension", "=", "array_merge", "(", "[", "'priority'", "=>", "10", ",", "]", ",", "$", "extension", ")", ";", "if", "(", "!", "array_key_exists", "(", "'class'", ",", "$", "extension", ")", ")", "{", "throw", "new", "InvalidStateException", "(", "sprintf", "(", "'Key \"class\" is required'", ")", ")", ";", "}", "$", "extensions", "[", "]", "=", "[", "'name'", "=>", "$", "name", ",", "'class'", "=>", "$", "extension", "[", "'class'", "]", ",", "'arguments'", "=>", "[", "]", ",", "'priority'", "=>", "$", "extension", "[", "'priority'", "]", ",", "]", ";", "}", "elseif", "(", "$", "extension", "instanceof", "Statement", ")", "{", "$", "extensions", "[", "]", "=", "[", "'name'", "=>", "$", "name", ",", "'class'", "=>", "$", "extension", "->", "getEntity", "(", ")", ",", "'arguments'", "=>", "$", "extension", "->", "arguments", ",", "'priority'", "=>", "$", "extension", "[", "'priority'", "]", ",", "]", ";", "}", "elseif", "(", "is_string", "(", "$", "extension", ")", ")", "{", "$", "extensions", "[", "]", "=", "[", "'name'", "=>", "$", "name", ",", "'class'", "=>", "$", "extension", ",", "'arguments'", "=>", "[", "]", ",", "'priority'", "=>", "10", ",", "]", ";", "}", "else", "{", "throw", "new", "InvalidStateException", "(", "sprintf", "(", "'Invalid extension definition \"%s\" given'", ",", "is_scalar", "(", "$", "extension", ")", "?", "$", "extension", ":", "gettype", "(", "$", "extension", ")", ")", ")", ";", "}", "}", "// Sort all extensions", "usort", "(", "$", "extensions", ",", "function", "(", "$", "a", ",", "$", "b", ")", "{", "if", "(", "$", "a", "[", "'priority'", "]", "===", "$", "b", "[", "'priority'", "]", ")", "return", "0", ";", "return", "$", "a", "[", "'priority'", "]", ">", "$", "b", "[", "'priority'", "]", "?", "1", ":", "-", "1", ";", "}", ")", ";", "// Register all extensions", "foreach", "(", "$", "extensions", "as", "$", "extension", ")", "{", "$", "instance", "=", "new", "$", "extension", "[", "'class'", "]", "(", "...", "$", "extension", "[", "'arguments'", "]", ")", ";", "$", "this", "->", "compiler", "->", "addExtension", "(", "$", "extension", "[", "'name'", "]", ",", "$", "instance", ")", ";", "}", "}" ]
Register other extensions with pleasure.
[ "Register", "other", "extensions", "with", "pleasure", "." ]
train
https://github.com/contributte/di/blob/de531e26ba4b70d570b59a28cfd81cc17de6800a/src/Extension/NewExtensionsExtension.php#L15-L76
contributte/di
src/Extension/ContainerAwareExtension.php
ContainerAwareExtension.beforeCompile
public function beforeCompile(): void { $builder = $this->getContainerBuilder(); // Register as services foreach ($builder->findByType(IContainerAware::class) as $service) { $service->addSetup('setContainer'); } }
php
public function beforeCompile(): void { $builder = $this->getContainerBuilder(); // Register as services foreach ($builder->findByType(IContainerAware::class) as $service) { $service->addSetup('setContainer'); } }
[ "public", "function", "beforeCompile", "(", ")", ":", "void", "{", "$", "builder", "=", "$", "this", "->", "getContainerBuilder", "(", ")", ";", "// Register as services", "foreach", "(", "$", "builder", "->", "findByType", "(", "IContainerAware", "::", "class", ")", "as", "$", "service", ")", "{", "$", "service", "->", "addSetup", "(", "'setContainer'", ")", ";", "}", "}" ]
Tweak DI container
[ "Tweak", "DI", "container" ]
train
https://github.com/contributte/di/blob/de531e26ba4b70d570b59a28cfd81cc17de6800a/src/Extension/ContainerAwareExtension.php#L14-L22
contributte/di
src/Extension/ResourceExtension.php
ResourceExtension.loadConfiguration
public function loadConfiguration(): void { $builder = $this->getContainerBuilder(); // Expand config (cause %appDir% etc..) $config = $this->validateConfig($this->defaults); $config = $this->config = Helpers::expand($config, $builder->parameters); foreach ($config['resources'] as $namespace => $resource) { if (substr($namespace, -1) !== '\\') { throw new RuntimeException(sprintf('Resource "%s" must end with /', $namespace)); } // Merge and validace resource config $resource = $this->validateConfig($this->resource, $resource, $namespace); // Normalize resource config if (is_scalar($resource['paths'])) $resource['paths'] = [$resource['paths']]; if (is_scalar($resource['excludes'])) $resource['excludes'] = [$resource['excludes']]; // Find classes of given resource $classes = $this->findClasses($namespace, $resource['paths'], $resource['excludes']); // Register services of given resource $counter = 1; $name = preg_replace('#\W+#', '_', '.' . $namespace); foreach ($classes as $class) { // Check already registered classes if ($builder->getByType($class) !== null) return; $def = $builder->addDefinition($this->prefix($name . '.' . ($counter++))) ->setFactory($class); // Merge and validace decorator config $decorator = $this->validateConfig($this->decorator, $resource['decorator'], $namespace); if ($decorator['tags'] !== []) { $def->setTags(Arrays::normalize($decorator['tags'], true)); } if ($decorator['setup'] !== []) { foreach ($decorator['setup'] as $setup) { if (is_array($setup)) { $setup = new Statement(key($setup), array_values($setup)); } $def->addSetup($setup); } } if ($decorator['autowired'] !== null) { $def->setAutowired($decorator['autowired']); } if ($decorator['inject'] !== null) { $def->setInject($decorator['inject']); } } } }
php
public function loadConfiguration(): void { $builder = $this->getContainerBuilder(); // Expand config (cause %appDir% etc..) $config = $this->validateConfig($this->defaults); $config = $this->config = Helpers::expand($config, $builder->parameters); foreach ($config['resources'] as $namespace => $resource) { if (substr($namespace, -1) !== '\\') { throw new RuntimeException(sprintf('Resource "%s" must end with /', $namespace)); } // Merge and validace resource config $resource = $this->validateConfig($this->resource, $resource, $namespace); // Normalize resource config if (is_scalar($resource['paths'])) $resource['paths'] = [$resource['paths']]; if (is_scalar($resource['excludes'])) $resource['excludes'] = [$resource['excludes']]; // Find classes of given resource $classes = $this->findClasses($namespace, $resource['paths'], $resource['excludes']); // Register services of given resource $counter = 1; $name = preg_replace('#\W+#', '_', '.' . $namespace); foreach ($classes as $class) { // Check already registered classes if ($builder->getByType($class) !== null) return; $def = $builder->addDefinition($this->prefix($name . '.' . ($counter++))) ->setFactory($class); // Merge and validace decorator config $decorator = $this->validateConfig($this->decorator, $resource['decorator'], $namespace); if ($decorator['tags'] !== []) { $def->setTags(Arrays::normalize($decorator['tags'], true)); } if ($decorator['setup'] !== []) { foreach ($decorator['setup'] as $setup) { if (is_array($setup)) { $setup = new Statement(key($setup), array_values($setup)); } $def->addSetup($setup); } } if ($decorator['autowired'] !== null) { $def->setAutowired($decorator['autowired']); } if ($decorator['inject'] !== null) { $def->setInject($decorator['inject']); } } } }
[ "public", "function", "loadConfiguration", "(", ")", ":", "void", "{", "$", "builder", "=", "$", "this", "->", "getContainerBuilder", "(", ")", ";", "// Expand config (cause %appDir% etc..)", "$", "config", "=", "$", "this", "->", "validateConfig", "(", "$", "this", "->", "defaults", ")", ";", "$", "config", "=", "$", "this", "->", "config", "=", "Helpers", "::", "expand", "(", "$", "config", ",", "$", "builder", "->", "parameters", ")", ";", "foreach", "(", "$", "config", "[", "'resources'", "]", "as", "$", "namespace", "=>", "$", "resource", ")", "{", "if", "(", "substr", "(", "$", "namespace", ",", "-", "1", ")", "!==", "'\\\\'", ")", "{", "throw", "new", "RuntimeException", "(", "sprintf", "(", "'Resource \"%s\" must end with /'", ",", "$", "namespace", ")", ")", ";", "}", "// Merge and validace resource config", "$", "resource", "=", "$", "this", "->", "validateConfig", "(", "$", "this", "->", "resource", ",", "$", "resource", ",", "$", "namespace", ")", ";", "// Normalize resource config", "if", "(", "is_scalar", "(", "$", "resource", "[", "'paths'", "]", ")", ")", "$", "resource", "[", "'paths'", "]", "=", "[", "$", "resource", "[", "'paths'", "]", "]", ";", "if", "(", "is_scalar", "(", "$", "resource", "[", "'excludes'", "]", ")", ")", "$", "resource", "[", "'excludes'", "]", "=", "[", "$", "resource", "[", "'excludes'", "]", "]", ";", "// Find classes of given resource", "$", "classes", "=", "$", "this", "->", "findClasses", "(", "$", "namespace", ",", "$", "resource", "[", "'paths'", "]", ",", "$", "resource", "[", "'excludes'", "]", ")", ";", "// Register services of given resource", "$", "counter", "=", "1", ";", "$", "name", "=", "preg_replace", "(", "'#\\W+#'", ",", "'_'", ",", "'.'", ".", "$", "namespace", ")", ";", "foreach", "(", "$", "classes", "as", "$", "class", ")", "{", "// Check already registered classes", "if", "(", "$", "builder", "->", "getByType", "(", "$", "class", ")", "!==", "null", ")", "return", ";", "$", "def", "=", "$", "builder", "->", "addDefinition", "(", "$", "this", "->", "prefix", "(", "$", "name", ".", "'.'", ".", "(", "$", "counter", "++", ")", ")", ")", "->", "setFactory", "(", "$", "class", ")", ";", "// Merge and validace decorator config", "$", "decorator", "=", "$", "this", "->", "validateConfig", "(", "$", "this", "->", "decorator", ",", "$", "resource", "[", "'decorator'", "]", ",", "$", "namespace", ")", ";", "if", "(", "$", "decorator", "[", "'tags'", "]", "!==", "[", "]", ")", "{", "$", "def", "->", "setTags", "(", "Arrays", "::", "normalize", "(", "$", "decorator", "[", "'tags'", "]", ",", "true", ")", ")", ";", "}", "if", "(", "$", "decorator", "[", "'setup'", "]", "!==", "[", "]", ")", "{", "foreach", "(", "$", "decorator", "[", "'setup'", "]", "as", "$", "setup", ")", "{", "if", "(", "is_array", "(", "$", "setup", ")", ")", "{", "$", "setup", "=", "new", "Statement", "(", "key", "(", "$", "setup", ")", ",", "array_values", "(", "$", "setup", ")", ")", ";", "}", "$", "def", "->", "addSetup", "(", "$", "setup", ")", ";", "}", "}", "if", "(", "$", "decorator", "[", "'autowired'", "]", "!==", "null", ")", "{", "$", "def", "->", "setAutowired", "(", "$", "decorator", "[", "'autowired'", "]", ")", ";", "}", "if", "(", "$", "decorator", "[", "'inject'", "]", "!==", "null", ")", "{", "$", "def", "->", "setInject", "(", "$", "decorator", "[", "'inject'", "]", ")", ";", "}", "}", "}", "}" ]
Register services
[ "Register", "services" ]
train
https://github.com/contributte/di/blob/de531e26ba4b70d570b59a28cfd81cc17de6800a/src/Extension/ResourceExtension.php#L42-L100
contributte/di
src/Extension/ResourceExtension.php
ResourceExtension.findClasses
protected function findClasses(string $namespace, array $dirs, array $excludes = []): array { $loader = $this->createLoader(); $loader->addDirectory($dirs); $loader->rebuild(); $indexed = $loader->getIndexedClasses(); $classes = []; foreach ($indexed as $class => $file) { // Different namespace if (!Strings::startsWith($class, $namespace)) continue; // Excluded namespace if (array_filter($excludes, function (string $exclude) use ($class): bool { return Strings::startsWith($class, $exclude); }) !== []) continue; // Skip not existing class if (!class_exists($class, true)) continue; // Detect by reflection $ct = new ReflectionClass($class); // Skip abstract if ($ct->isAbstract()) continue; // All tests passed, it's our class $classes[] = $class; } return $classes; }
php
protected function findClasses(string $namespace, array $dirs, array $excludes = []): array { $loader = $this->createLoader(); $loader->addDirectory($dirs); $loader->rebuild(); $indexed = $loader->getIndexedClasses(); $classes = []; foreach ($indexed as $class => $file) { // Different namespace if (!Strings::startsWith($class, $namespace)) continue; // Excluded namespace if (array_filter($excludes, function (string $exclude) use ($class): bool { return Strings::startsWith($class, $exclude); }) !== []) continue; // Skip not existing class if (!class_exists($class, true)) continue; // Detect by reflection $ct = new ReflectionClass($class); // Skip abstract if ($ct->isAbstract()) continue; // All tests passed, it's our class $classes[] = $class; } return $classes; }
[ "protected", "function", "findClasses", "(", "string", "$", "namespace", ",", "array", "$", "dirs", ",", "array", "$", "excludes", "=", "[", "]", ")", ":", "array", "{", "$", "loader", "=", "$", "this", "->", "createLoader", "(", ")", ";", "$", "loader", "->", "addDirectory", "(", "$", "dirs", ")", ";", "$", "loader", "->", "rebuild", "(", ")", ";", "$", "indexed", "=", "$", "loader", "->", "getIndexedClasses", "(", ")", ";", "$", "classes", "=", "[", "]", ";", "foreach", "(", "$", "indexed", "as", "$", "class", "=>", "$", "file", ")", "{", "// Different namespace", "if", "(", "!", "Strings", "::", "startsWith", "(", "$", "class", ",", "$", "namespace", ")", ")", "continue", ";", "// Excluded namespace", "if", "(", "array_filter", "(", "$", "excludes", ",", "function", "(", "string", "$", "exclude", ")", "use", "(", "$", "class", ")", ":", "bool", "{", "return", "Strings", "::", "startsWith", "(", "$", "class", ",", "$", "exclude", ")", ";", "}", ")", "!==", "[", "]", ")", "continue", ";", "// Skip not existing class", "if", "(", "!", "class_exists", "(", "$", "class", ",", "true", ")", ")", "continue", ";", "// Detect by reflection", "$", "ct", "=", "new", "ReflectionClass", "(", "$", "class", ")", ";", "// Skip abstract", "if", "(", "$", "ct", "->", "isAbstract", "(", ")", ")", "continue", ";", "// All tests passed, it's our class", "$", "classes", "[", "]", "=", "$", "class", ";", "}", "return", "$", "classes", ";", "}" ]
Find classes by given arguments @param string[] $dirs @param string[] $excludes @return string[]
[ "Find", "classes", "by", "given", "arguments" ]
train
https://github.com/contributte/di/blob/de531e26ba4b70d570b59a28cfd81cc17de6800a/src/Extension/ResourceExtension.php#L109-L140
contributte/di
src/Extension/InjectValueExtension.php
InjectValueExtension.beforeCompile
public function beforeCompile(): void { $config = $this->validateConfig($this->defaults); $definitions = $config['all'] === true ? $this->getContainerBuilder()->getDefinitions() : array_map( [$this->getContainerBuilder(), 'getDefinition'], array_keys($this->getContainerBuilder()->findByTag(self::TAG_INJECT_VALUE)) ); foreach ($definitions as $def) { // If class is not defined, then skip it if ($def->getType() === null) continue; // Inject @value into definitin $this->inject($def); } }
php
public function beforeCompile(): void { $config = $this->validateConfig($this->defaults); $definitions = $config['all'] === true ? $this->getContainerBuilder()->getDefinitions() : array_map( [$this->getContainerBuilder(), 'getDefinition'], array_keys($this->getContainerBuilder()->findByTag(self::TAG_INJECT_VALUE)) ); foreach ($definitions as $def) { // If class is not defined, then skip it if ($def->getType() === null) continue; // Inject @value into definitin $this->inject($def); } }
[ "public", "function", "beforeCompile", "(", ")", ":", "void", "{", "$", "config", "=", "$", "this", "->", "validateConfig", "(", "$", "this", "->", "defaults", ")", ";", "$", "definitions", "=", "$", "config", "[", "'all'", "]", "===", "true", "?", "$", "this", "->", "getContainerBuilder", "(", ")", "->", "getDefinitions", "(", ")", ":", "array_map", "(", "[", "$", "this", "->", "getContainerBuilder", "(", ")", ",", "'getDefinition'", "]", ",", "array_keys", "(", "$", "this", "->", "getContainerBuilder", "(", ")", "->", "findByTag", "(", "self", "::", "TAG_INJECT_VALUE", ")", ")", ")", ";", "foreach", "(", "$", "definitions", "as", "$", "def", ")", "{", "// If class is not defined, then skip it", "if", "(", "$", "def", "->", "getType", "(", ")", "===", "null", ")", "continue", ";", "// Inject @value into definitin", "$", "this", "->", "inject", "(", "$", "def", ")", ";", "}", "}" ]
Find all definitions and inject into @value
[ "Find", "all", "definitions", "and", "inject", "into" ]
train
https://github.com/contributte/di/blob/de531e26ba4b70d570b59a28cfd81cc17de6800a/src/Extension/InjectValueExtension.php#L24-L42
contributte/di
src/Extension/InjectValueExtension.php
InjectValueExtension.inject
protected function inject(ServiceDefinition $def): void { $class = $def->getType(); if ($class === null) return; foreach (get_class_vars($class) as $name => $var) { $rp = new ReflectionProperty($def->getType(), $name); // Try to match property by regex // https://regex101.com/r/D6gc21/1 $match = Strings::match($rp->getDocComment(), '#@value\((.+)\)#U'); // If there's no @value annotation or it's not in propel format, // then skip it if ($match === null) continue; // Hooray, we have a match! [$doc, $content] = $match; // Expand content of @value and setup to definition $def->addSetup('$' . $name, [$this->expand($content)]); } }
php
protected function inject(ServiceDefinition $def): void { $class = $def->getType(); if ($class === null) return; foreach (get_class_vars($class) as $name => $var) { $rp = new ReflectionProperty($def->getType(), $name); // Try to match property by regex // https://regex101.com/r/D6gc21/1 $match = Strings::match($rp->getDocComment(), '#@value\((.+)\)#U'); // If there's no @value annotation or it's not in propel format, // then skip it if ($match === null) continue; // Hooray, we have a match! [$doc, $content] = $match; // Expand content of @value and setup to definition $def->addSetup('$' . $name, [$this->expand($content)]); } }
[ "protected", "function", "inject", "(", "ServiceDefinition", "$", "def", ")", ":", "void", "{", "$", "class", "=", "$", "def", "->", "getType", "(", ")", ";", "if", "(", "$", "class", "===", "null", ")", "return", ";", "foreach", "(", "get_class_vars", "(", "$", "class", ")", "as", "$", "name", "=>", "$", "var", ")", "{", "$", "rp", "=", "new", "ReflectionProperty", "(", "$", "def", "->", "getType", "(", ")", ",", "$", "name", ")", ";", "// Try to match property by regex", "// https://regex101.com/r/D6gc21/1", "$", "match", "=", "Strings", "::", "match", "(", "$", "rp", "->", "getDocComment", "(", ")", ",", "'#@value\\((.+)\\)#U'", ")", ";", "// If there's no @value annotation or it's not in propel format,", "// then skip it", "if", "(", "$", "match", "===", "null", ")", "continue", ";", "// Hooray, we have a match!", "[", "$", "doc", ",", "$", "content", "]", "=", "$", "match", ";", "// Expand content of @value and setup to definition", "$", "def", "->", "addSetup", "(", "'$'", ".", "$", "name", ",", "[", "$", "this", "->", "expand", "(", "$", "content", ")", "]", ")", ";", "}", "}" ]
Inject into @value property
[ "Inject", "into" ]
train
https://github.com/contributte/di/blob/de531e26ba4b70d570b59a28cfd81cc17de6800a/src/Extension/InjectValueExtension.php#L47-L70
ircmaxell/SecurityLib
lib/SecurityLib/AbstractFactory.php
AbstractFactory.registerType
protected function registerType( $type, $implements, $name, $class, $instantiate = false ) { $name = strtolower($name); $refl = new \ReflectionClass($class); if (!$refl->implementsInterface($implements)) { $message = sprintf('Class must implement %s', $implements); throw new \InvalidArgumentException($message); } if ($instantiate) { $class = new $class; } $this->{$type}[$name] = $class; }
php
protected function registerType( $type, $implements, $name, $class, $instantiate = false ) { $name = strtolower($name); $refl = new \ReflectionClass($class); if (!$refl->implementsInterface($implements)) { $message = sprintf('Class must implement %s', $implements); throw new \InvalidArgumentException($message); } if ($instantiate) { $class = new $class; } $this->{$type}[$name] = $class; }
[ "protected", "function", "registerType", "(", "$", "type", ",", "$", "implements", ",", "$", "name", ",", "$", "class", ",", "$", "instantiate", "=", "false", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "$", "refl", "=", "new", "\\", "ReflectionClass", "(", "$", "class", ")", ";", "if", "(", "!", "$", "refl", "->", "implementsInterface", "(", "$", "implements", ")", ")", "{", "$", "message", "=", "sprintf", "(", "'Class must implement %s'", ",", "$", "implements", ")", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "if", "(", "$", "instantiate", ")", "{", "$", "class", "=", "new", "$", "class", ";", "}", "$", "this", "->", "{", "$", "type", "}", "[", "$", "name", "]", "=", "$", "class", ";", "}" ]
Register a type with the factory by name This is an internal method to check if a provided class name implements an interface, and if it does to append that class to an internal array by name. @param string $type The name of the variable to store the class @param string $implements The interface to validate against @param string $name The name of this particular class @param string $class The fully qualified class name @param boolean $instantiate Should the class be stored instantiated @return void @throws InvalidArgumentException If class does not implement interface
[ "Register", "a", "type", "with", "the", "factory", "by", "name" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/AbstractFactory.php#L42-L60
ircmaxell/SecurityLib
lib/SecurityLib/AbstractFactory.php
AbstractFactory.loadFiles
protected function loadFiles($directory, $namespace, $callback) { foreach (new \DirectoryIterator($directory) as $file) { $filename = $file->getBasename(); if ($file->isFile() && substr($filename, -4) == '.php') { $name = substr($filename, 0, -4); $class = $namespace . $name; call_user_func($callback, $name, $class); } } }
php
protected function loadFiles($directory, $namespace, $callback) { foreach (new \DirectoryIterator($directory) as $file) { $filename = $file->getBasename(); if ($file->isFile() && substr($filename, -4) == '.php') { $name = substr($filename, 0, -4); $class = $namespace . $name; call_user_func($callback, $name, $class); } } }
[ "protected", "function", "loadFiles", "(", "$", "directory", ",", "$", "namespace", ",", "$", "callback", ")", "{", "foreach", "(", "new", "\\", "DirectoryIterator", "(", "$", "directory", ")", "as", "$", "file", ")", "{", "$", "filename", "=", "$", "file", "->", "getBasename", "(", ")", ";", "if", "(", "$", "file", "->", "isFile", "(", ")", "&&", "substr", "(", "$", "filename", ",", "-", "4", ")", "==", "'.php'", ")", "{", "$", "name", "=", "substr", "(", "$", "filename", ",", "0", ",", "-", "4", ")", ";", "$", "class", "=", "$", "namespace", ".", "$", "name", ";", "call_user_func", "(", "$", "callback", ",", "$", "name", ",", "$", "class", ")", ";", "}", "}", "}" ]
Load a set of classes from a directory into the factory @param string $directory The directory to search for classes in @param string $namespace The namespace prefix for any found classes @param callable $callback The callback with which to register the class @return void
[ "Load", "a", "set", "of", "classes", "from", "a", "directory", "into", "the", "factory" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/AbstractFactory.php#L71-L80
ircmaxell/SecurityLib
lib/SecurityLib/BigMath.php
BigMath.createFromServerConfiguration
public static function createFromServerConfiguration() { //@codeCoverageIgnoreStart if (extension_loaded('gmp')) { return new \SecurityLib\BigMath\GMP(); } elseif (extension_loaded('bcmath')) { return new \SecurityLib\BigMath\BCMath(); } else { return new \SecurityLib\BigMath\PHPMath(); } //@codeCoverageIgnoreEnd }
php
public static function createFromServerConfiguration() { //@codeCoverageIgnoreStart if (extension_loaded('gmp')) { return new \SecurityLib\BigMath\GMP(); } elseif (extension_loaded('bcmath')) { return new \SecurityLib\BigMath\BCMath(); } else { return new \SecurityLib\BigMath\PHPMath(); } //@codeCoverageIgnoreEnd }
[ "public", "static", "function", "createFromServerConfiguration", "(", ")", "{", "//@codeCoverageIgnoreStart", "if", "(", "extension_loaded", "(", "'gmp'", ")", ")", "{", "return", "new", "\\", "SecurityLib", "\\", "BigMath", "\\", "GMP", "(", ")", ";", "}", "elseif", "(", "extension_loaded", "(", "'bcmath'", ")", ")", "{", "return", "new", "\\", "SecurityLib", "\\", "BigMath", "\\", "BCMath", "(", ")", ";", "}", "else", "{", "return", "new", "\\", "SecurityLib", "\\", "BigMath", "\\", "PHPMath", "(", ")", ";", "}", "//@codeCoverageIgnoreEnd", "}" ]
Get an instance of the big math class This is NOT a singleton. It simply loads the proper strategy given the current server configuration @return \SecurityLib\BigMath A big math instance
[ "Get", "an", "instance", "of", "the", "big", "math", "class" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/BigMath.php#L33-L43
ircmaxell/SecurityLib
lib/SecurityLib/BigMath/PHPMath.php
PHPMath.add
public function add($left, $right) { if (empty($left)) { return $right; } elseif (empty($right)) { return $left; } $negative = ''; if ($left[0] == '-' && $right[0] == '-') { $negative = '-'; $left = substr($left, 1); $right = substr($right, 1); } elseif ($left[0] == '-') { return $this->subtract($right, substr($left, 1)); } elseif ($right[0] == '-') { return $this->subtract($left, substr($right, 1)); } $left = $this->normalize($left); $right = $this->normalize($right); $result = BaseConverter::convertFromBinary( $this->addBinary($left, $right), '0123456789' ); return $negative . $result; }
php
public function add($left, $right) { if (empty($left)) { return $right; } elseif (empty($right)) { return $left; } $negative = ''; if ($left[0] == '-' && $right[0] == '-') { $negative = '-'; $left = substr($left, 1); $right = substr($right, 1); } elseif ($left[0] == '-') { return $this->subtract($right, substr($left, 1)); } elseif ($right[0] == '-') { return $this->subtract($left, substr($right, 1)); } $left = $this->normalize($left); $right = $this->normalize($right); $result = BaseConverter::convertFromBinary( $this->addBinary($left, $right), '0123456789' ); return $negative . $result; }
[ "public", "function", "add", "(", "$", "left", ",", "$", "right", ")", "{", "if", "(", "empty", "(", "$", "left", ")", ")", "{", "return", "$", "right", ";", "}", "elseif", "(", "empty", "(", "$", "right", ")", ")", "{", "return", "$", "left", ";", "}", "$", "negative", "=", "''", ";", "if", "(", "$", "left", "[", "0", "]", "==", "'-'", "&&", "$", "right", "[", "0", "]", "==", "'-'", ")", "{", "$", "negative", "=", "'-'", ";", "$", "left", "=", "substr", "(", "$", "left", ",", "1", ")", ";", "$", "right", "=", "substr", "(", "$", "right", ",", "1", ")", ";", "}", "elseif", "(", "$", "left", "[", "0", "]", "==", "'-'", ")", "{", "return", "$", "this", "->", "subtract", "(", "$", "right", ",", "substr", "(", "$", "left", ",", "1", ")", ")", ";", "}", "elseif", "(", "$", "right", "[", "0", "]", "==", "'-'", ")", "{", "return", "$", "this", "->", "subtract", "(", "$", "left", ",", "substr", "(", "$", "right", ",", "1", ")", ")", ";", "}", "$", "left", "=", "$", "this", "->", "normalize", "(", "$", "left", ")", ";", "$", "right", "=", "$", "this", "->", "normalize", "(", "$", "right", ")", ";", "$", "result", "=", "BaseConverter", "::", "convertFromBinary", "(", "$", "this", "->", "addBinary", "(", "$", "left", ",", "$", "right", ")", ",", "'0123456789'", ")", ";", "return", "$", "negative", ".", "$", "result", ";", "}" ]
Add two numbers together @param string $left The left argument @param string $right The right argument @return string A base-10 string of the sum of the two arguments
[ "Add", "two", "numbers", "together" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/BigMath/PHPMath.php#L36-L59
ircmaxell/SecurityLib
lib/SecurityLib/BigMath/PHPMath.php
PHPMath.subtract
public function subtract($left, $right) { if (empty($left)) { return $right; } elseif (empty($right)) { return $left; } elseif ($right[0] == '-') { return $this->add($left, substr($right, 1)); } elseif ($left[0] == '-') { return '-' . $this->add(ltrim($left, '-'), $right); } $left = $this->normalize($left); $right = $this->normalize($right); $results = $this->subtractBinary($left, $right); $result = BaseConverter::convertFromBinary($results[1], '0123456789'); return $results[0] . $result; }
php
public function subtract($left, $right) { if (empty($left)) { return $right; } elseif (empty($right)) { return $left; } elseif ($right[0] == '-') { return $this->add($left, substr($right, 1)); } elseif ($left[0] == '-') { return '-' . $this->add(ltrim($left, '-'), $right); } $left = $this->normalize($left); $right = $this->normalize($right); $results = $this->subtractBinary($left, $right); $result = BaseConverter::convertFromBinary($results[1], '0123456789'); return $results[0] . $result; }
[ "public", "function", "subtract", "(", "$", "left", ",", "$", "right", ")", "{", "if", "(", "empty", "(", "$", "left", ")", ")", "{", "return", "$", "right", ";", "}", "elseif", "(", "empty", "(", "$", "right", ")", ")", "{", "return", "$", "left", ";", "}", "elseif", "(", "$", "right", "[", "0", "]", "==", "'-'", ")", "{", "return", "$", "this", "->", "add", "(", "$", "left", ",", "substr", "(", "$", "right", ",", "1", ")", ")", ";", "}", "elseif", "(", "$", "left", "[", "0", "]", "==", "'-'", ")", "{", "return", "'-'", ".", "$", "this", "->", "add", "(", "ltrim", "(", "$", "left", ",", "'-'", ")", ",", "$", "right", ")", ";", "}", "$", "left", "=", "$", "this", "->", "normalize", "(", "$", "left", ")", ";", "$", "right", "=", "$", "this", "->", "normalize", "(", "$", "right", ")", ";", "$", "results", "=", "$", "this", "->", "subtractBinary", "(", "$", "left", ",", "$", "right", ")", ";", "$", "result", "=", "BaseConverter", "::", "convertFromBinary", "(", "$", "results", "[", "1", "]", ",", "'0123456789'", ")", ";", "return", "$", "results", "[", "0", "]", ".", "$", "result", ";", "}" ]
Subtract two numbers @param string $left The left argument @param string $right The right argument @return string A base-10 string of the difference of the two arguments
[ "Subtract", "two", "numbers" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/BigMath/PHPMath.php#L69-L84
ircmaxell/SecurityLib
lib/SecurityLib/BigMath/PHPMath.php
PHPMath.addBinary
protected function addBinary($left, $right) { $len = max(strlen($left), strlen($right)); $left = str_pad($left, $len, chr(0), STR_PAD_LEFT); $right = str_pad($right, $len, chr(0), STR_PAD_LEFT); $result = ''; $carry = 0; for ($i = 0; $i < $len; $i++) { $sum = ord($left[$len - $i - 1]) + ord($right[$len - $i - 1]) + $carry; $result .= chr($sum % 256); $carry = $sum >> 8; } while ($carry) { $result .= chr($carry % 256); $carry >>= 8; } return strrev($result); }
php
protected function addBinary($left, $right) { $len = max(strlen($left), strlen($right)); $left = str_pad($left, $len, chr(0), STR_PAD_LEFT); $right = str_pad($right, $len, chr(0), STR_PAD_LEFT); $result = ''; $carry = 0; for ($i = 0; $i < $len; $i++) { $sum = ord($left[$len - $i - 1]) + ord($right[$len - $i - 1]) + $carry; $result .= chr($sum % 256); $carry = $sum >> 8; } while ($carry) { $result .= chr($carry % 256); $carry >>= 8; } return strrev($result); }
[ "protected", "function", "addBinary", "(", "$", "left", ",", "$", "right", ")", "{", "$", "len", "=", "max", "(", "strlen", "(", "$", "left", ")", ",", "strlen", "(", "$", "right", ")", ")", ";", "$", "left", "=", "str_pad", "(", "$", "left", ",", "$", "len", ",", "chr", "(", "0", ")", ",", "STR_PAD_LEFT", ")", ";", "$", "right", "=", "str_pad", "(", "$", "right", ",", "$", "len", ",", "chr", "(", "0", ")", ",", "STR_PAD_LEFT", ")", ";", "$", "result", "=", "''", ";", "$", "carry", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "len", ";", "$", "i", "++", ")", "{", "$", "sum", "=", "ord", "(", "$", "left", "[", "$", "len", "-", "$", "i", "-", "1", "]", ")", "+", "ord", "(", "$", "right", "[", "$", "len", "-", "$", "i", "-", "1", "]", ")", "+", "$", "carry", ";", "$", "result", ".=", "chr", "(", "$", "sum", "%", "256", ")", ";", "$", "carry", "=", "$", "sum", ">>", "8", ";", "}", "while", "(", "$", "carry", ")", "{", "$", "result", ".=", "chr", "(", "$", "carry", "%", "256", ")", ";", "$", "carry", ">>=", "8", ";", "}", "return", "strrev", "(", "$", "result", ")", ";", "}" ]
Add two binary strings together @param string $left The left argument @param string $right The right argument @return string The binary result
[ "Add", "two", "binary", "strings", "together" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/BigMath/PHPMath.php#L94-L112
ircmaxell/SecurityLib
lib/SecurityLib/BigMath/PHPMath.php
PHPMath.subtractBinary
protected function subtractBinary($left, $right) { $len = max(strlen($left), strlen($right)); $left = str_pad($left, $len, chr(0), STR_PAD_LEFT); $right = str_pad($right, $len, chr(0), STR_PAD_LEFT); $right = $this->compliment($right); $result = $this->addBinary($left, $right); if (strlen($result) > $len) { // Positive Result $carry = substr($result, 0, -1 * $len); $result = substr($result, strlen($carry)); return array( '', $this->addBinary($result, $carry) ); } return array('-', $this->compliment($result)); }
php
protected function subtractBinary($left, $right) { $len = max(strlen($left), strlen($right)); $left = str_pad($left, $len, chr(0), STR_PAD_LEFT); $right = str_pad($right, $len, chr(0), STR_PAD_LEFT); $right = $this->compliment($right); $result = $this->addBinary($left, $right); if (strlen($result) > $len) { // Positive Result $carry = substr($result, 0, -1 * $len); $result = substr($result, strlen($carry)); return array( '', $this->addBinary($result, $carry) ); } return array('-', $this->compliment($result)); }
[ "protected", "function", "subtractBinary", "(", "$", "left", ",", "$", "right", ")", "{", "$", "len", "=", "max", "(", "strlen", "(", "$", "left", ")", ",", "strlen", "(", "$", "right", ")", ")", ";", "$", "left", "=", "str_pad", "(", "$", "left", ",", "$", "len", ",", "chr", "(", "0", ")", ",", "STR_PAD_LEFT", ")", ";", "$", "right", "=", "str_pad", "(", "$", "right", ",", "$", "len", ",", "chr", "(", "0", ")", ",", "STR_PAD_LEFT", ")", ";", "$", "right", "=", "$", "this", "->", "compliment", "(", "$", "right", ")", ";", "$", "result", "=", "$", "this", "->", "addBinary", "(", "$", "left", ",", "$", "right", ")", ";", "if", "(", "strlen", "(", "$", "result", ")", ">", "$", "len", ")", "{", "// Positive Result", "$", "carry", "=", "substr", "(", "$", "result", ",", "0", ",", "-", "1", "*", "$", "len", ")", ";", "$", "result", "=", "substr", "(", "$", "result", ",", "strlen", "(", "$", "carry", ")", ")", ";", "return", "array", "(", "''", ",", "$", "this", "->", "addBinary", "(", "$", "result", ",", "$", "carry", ")", ")", ";", "}", "return", "array", "(", "'-'", ",", "$", "this", "->", "compliment", "(", "$", "result", ")", ")", ";", "}" ]
Subtract two binary strings using 256's compliment @param string $left The left argument @param string $right The right argument @return string The binary result
[ "Subtract", "two", "binary", "strings", "using", "256", "s", "compliment" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/BigMath/PHPMath.php#L122-L138
ircmaxell/SecurityLib
lib/SecurityLib/BigMath/PHPMath.php
PHPMath.compliment
protected function compliment($string) { $result = ''; $len = strlen($string); for ($i = 0; $i < $len; $i++) { $result .= chr(255 - ord($string[$i])); } return $result; }
php
protected function compliment($string) { $result = ''; $len = strlen($string); for ($i = 0; $i < $len; $i++) { $result .= chr(255 - ord($string[$i])); } return $result; }
[ "protected", "function", "compliment", "(", "$", "string", ")", "{", "$", "result", "=", "''", ";", "$", "len", "=", "strlen", "(", "$", "string", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "len", ";", "$", "i", "++", ")", "{", "$", "result", ".=", "chr", "(", "255", "-", "ord", "(", "$", "string", "[", "$", "i", "]", ")", ")", ";", "}", "return", "$", "result", ";", "}" ]
Take the 256 base compliment @param string $string The binary string to compliment @return string The complimented string
[ "Take", "the", "256", "base", "compliment" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/BigMath/PHPMath.php#L147-L154
ircmaxell/SecurityLib
lib/SecurityLib/BaseConverter.php
BaseConverter.convertFromBinary
public static function convertFromBinary($string, $characters) { if ($string === '' || empty($characters)) { return ''; } $string = str_split($string); $callback = function($str) { return ord($str); }; $string = array_map($callback, $string); $converted = static::baseConvert($string, 256, strlen($characters)); $callback = function ($num) use ($characters) { return $characters[$num]; }; $ret = implode('', array_map($callback, $converted)); return $ret; }
php
public static function convertFromBinary($string, $characters) { if ($string === '' || empty($characters)) { return ''; } $string = str_split($string); $callback = function($str) { return ord($str); }; $string = array_map($callback, $string); $converted = static::baseConvert($string, 256, strlen($characters)); $callback = function ($num) use ($characters) { return $characters[$num]; }; $ret = implode('', array_map($callback, $converted)); return $ret; }
[ "public", "static", "function", "convertFromBinary", "(", "$", "string", ",", "$", "characters", ")", "{", "if", "(", "$", "string", "===", "''", "||", "empty", "(", "$", "characters", ")", ")", "{", "return", "''", ";", "}", "$", "string", "=", "str_split", "(", "$", "string", ")", ";", "$", "callback", "=", "function", "(", "$", "str", ")", "{", "return", "ord", "(", "$", "str", ")", ";", "}", ";", "$", "string", "=", "array_map", "(", "$", "callback", ",", "$", "string", ")", ";", "$", "converted", "=", "static", "::", "baseConvert", "(", "$", "string", ",", "256", ",", "strlen", "(", "$", "characters", ")", ")", ";", "$", "callback", "=", "function", "(", "$", "num", ")", "use", "(", "$", "characters", ")", "{", "return", "$", "characters", "[", "$", "num", "]", ";", "}", ";", "$", "ret", "=", "implode", "(", "''", ",", "array_map", "(", "$", "callback", ",", "$", "converted", ")", ")", ";", "return", "$", "ret", ";", "}" ]
Convert from a raw binary string to a string of characters @param string $string The string to convert from @param string $characters The list of characters to convert to @return string The converted string
[ "Convert", "from", "a", "raw", "binary", "string", "to", "a", "string", "of", "characters" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/BaseConverter.php#L37-L52
ircmaxell/SecurityLib
lib/SecurityLib/BaseConverter.php
BaseConverter.convertToBinary
public static function convertToBinary($string, $characters) { if (empty($string) || empty($characters)) { return ''; } $string = str_split($string); $callback = function($str) use ($characters) { return strpos($characters, $str); }; $string = array_map($callback, $string); $converted = static::baseConvert($string, strlen($characters), 256); $callback = function ($num) { return chr($num); }; return implode('', array_map($callback, $converted)); }
php
public static function convertToBinary($string, $characters) { if (empty($string) || empty($characters)) { return ''; } $string = str_split($string); $callback = function($str) use ($characters) { return strpos($characters, $str); }; $string = array_map($callback, $string); $converted = static::baseConvert($string, strlen($characters), 256); $callback = function ($num) { return chr($num); }; return implode('', array_map($callback, $converted)); }
[ "public", "static", "function", "convertToBinary", "(", "$", "string", ",", "$", "characters", ")", "{", "if", "(", "empty", "(", "$", "string", ")", "||", "empty", "(", "$", "characters", ")", ")", "{", "return", "''", ";", "}", "$", "string", "=", "str_split", "(", "$", "string", ")", ";", "$", "callback", "=", "function", "(", "$", "str", ")", "use", "(", "$", "characters", ")", "{", "return", "strpos", "(", "$", "characters", ",", "$", "str", ")", ";", "}", ";", "$", "string", "=", "array_map", "(", "$", "callback", ",", "$", "string", ")", ";", "$", "converted", "=", "static", "::", "baseConvert", "(", "$", "string", ",", "strlen", "(", "$", "characters", ")", ",", "256", ")", ";", "$", "callback", "=", "function", "(", "$", "num", ")", "{", "return", "chr", "(", "$", "num", ")", ";", "}", ";", "return", "implode", "(", "''", ",", "array_map", "(", "$", "callback", ",", "$", "converted", ")", ")", ";", "}" ]
Convert to a raw binary string from a string of characters @param string $string The string to convert from @param string $characters The list of characters to convert to @return string The converted string
[ "Convert", "to", "a", "raw", "binary", "string", "from", "a", "string", "of", "characters" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/BaseConverter.php#L62-L76
ircmaxell/SecurityLib
lib/SecurityLib/BaseConverter.php
BaseConverter.baseConvert
public static function baseConvert(array $source, $srcBase, $dstBase) { if ($dstBase < 2) { $message = sprintf('Invalid Destination Base: %d', $dstBase); throw new \InvalidArgumentException($message); } $result = array(); $count = count($source); while ($count) { $itMax = $count; $remainder = $count = $loop = 0; while($loop < $itMax) { $dividend = $source[$loop++] + $remainder * $srcBase; $remainder = $dividend % $dstBase; $res = ($dividend - $remainder) / $dstBase; if ($count || $res) { $source[$count++] = $res; } } $result[] = $remainder; } return array_reverse($result); }
php
public static function baseConvert(array $source, $srcBase, $dstBase) { if ($dstBase < 2) { $message = sprintf('Invalid Destination Base: %d', $dstBase); throw new \InvalidArgumentException($message); } $result = array(); $count = count($source); while ($count) { $itMax = $count; $remainder = $count = $loop = 0; while($loop < $itMax) { $dividend = $source[$loop++] + $remainder * $srcBase; $remainder = $dividend % $dstBase; $res = ($dividend - $remainder) / $dstBase; if ($count || $res) { $source[$count++] = $res; } } $result[] = $remainder; } return array_reverse($result); }
[ "public", "static", "function", "baseConvert", "(", "array", "$", "source", ",", "$", "srcBase", ",", "$", "dstBase", ")", "{", "if", "(", "$", "dstBase", "<", "2", ")", "{", "$", "message", "=", "sprintf", "(", "'Invalid Destination Base: %d'", ",", "$", "dstBase", ")", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "count", "=", "count", "(", "$", "source", ")", ";", "while", "(", "$", "count", ")", "{", "$", "itMax", "=", "$", "count", ";", "$", "remainder", "=", "$", "count", "=", "$", "loop", "=", "0", ";", "while", "(", "$", "loop", "<", "$", "itMax", ")", "{", "$", "dividend", "=", "$", "source", "[", "$", "loop", "++", "]", "+", "$", "remainder", "*", "$", "srcBase", ";", "$", "remainder", "=", "$", "dividend", "%", "$", "dstBase", ";", "$", "res", "=", "(", "$", "dividend", "-", "$", "remainder", ")", "/", "$", "dstBase", ";", "if", "(", "$", "count", "||", "$", "res", ")", "{", "$", "source", "[", "$", "count", "++", "]", "=", "$", "res", ";", "}", "}", "$", "result", "[", "]", "=", "$", "remainder", ";", "}", "return", "array_reverse", "(", "$", "result", ")", ";", "}" ]
Convert an array of input blocks to another numeric base This function was modified from an implementation found on StackOverflow. Special Thanks to @KeithRandall for supplying the implementation. @param int[] $source The source number, as an array @param int $srcBase The source base as an integer @param int $dstBase The destination base as an integer @see http://codegolf.stackexchange.com/questions/1620/arb/1626#1626 @return int[] An array of integers in the encoded base
[ "Convert", "an", "array", "of", "input", "blocks", "to", "another", "numeric", "base" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/BaseConverter.php#L91-L112
ircmaxell/SecurityLib
lib/SecurityLib/Enum.php
Enum.compare
public function compare(Enum $arg) { if ($this->value == $arg->value) { return 0; } elseif ($this->value > $arg->value) { return -1; } else { return 1; } }
php
public function compare(Enum $arg) { if ($this->value == $arg->value) { return 0; } elseif ($this->value > $arg->value) { return -1; } else { return 1; } }
[ "public", "function", "compare", "(", "Enum", "$", "arg", ")", "{", "if", "(", "$", "this", "->", "value", "==", "$", "arg", "->", "value", ")", "{", "return", "0", ";", "}", "elseif", "(", "$", "this", "->", "value", ">", "$", "arg", "->", "value", ")", "{", "return", "-", "1", ";", "}", "else", "{", "return", "1", ";", "}", "}" ]
Compare two enums using numeric comparison @param Enum $arg The enum to compare this instance to @return int 0 if same, 1 if the argument is greater, -1 else
[ "Compare", "two", "enums", "using", "numeric", "comparison" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/Enum.php#L84-L92
ircmaxell/SecurityLib
lib/SecurityLib/Enum.php
Enum.getConstList
public function getConstList($include_default = false) { static $constCache = array(); $class = get_class($this); if (!isset($constCache[$class])) { $reflector = new ReflectionObject($this); $constCache[$class] = $reflector->getConstants(); } if (!$include_default) { $constants = $constCache[$class]; unset($constants['__DEFAULT']); return $constants; } return $constCache[$class]; }
php
public function getConstList($include_default = false) { static $constCache = array(); $class = get_class($this); if (!isset($constCache[$class])) { $reflector = new ReflectionObject($this); $constCache[$class] = $reflector->getConstants(); } if (!$include_default) { $constants = $constCache[$class]; unset($constants['__DEFAULT']); return $constants; } return $constCache[$class]; }
[ "public", "function", "getConstList", "(", "$", "include_default", "=", "false", ")", "{", "static", "$", "constCache", "=", "array", "(", ")", ";", "$", "class", "=", "get_class", "(", "$", "this", ")", ";", "if", "(", "!", "isset", "(", "$", "constCache", "[", "$", "class", "]", ")", ")", "{", "$", "reflector", "=", "new", "ReflectionObject", "(", "$", "this", ")", ";", "$", "constCache", "[", "$", "class", "]", "=", "$", "reflector", "->", "getConstants", "(", ")", ";", "}", "if", "(", "!", "$", "include_default", ")", "{", "$", "constants", "=", "$", "constCache", "[", "$", "class", "]", ";", "unset", "(", "$", "constants", "[", "'__DEFAULT'", "]", ")", ";", "return", "$", "constants", ";", "}", "return", "$", "constCache", "[", "$", "class", "]", ";", "}" ]
Returns all constants (including values) as an associative array @param boolean $include_default Include the __default magic value? @return array All of the constants found against this instance
[ "Returns", "all", "constants", "(", "including", "values", ")", "as", "an", "associative", "array" ]
train
https://github.com/ircmaxell/SecurityLib/blob/d337741719027c14c9fefafc9cd918251831e3e9/lib/SecurityLib/Enum.php#L101-L114
inhere/php-srouter
src/ServerRouter.php
ServerRouter.match
public function match(string $path, string $method = 'GET'): array { // For HEAD requests, attempt fallback to GET $method = \strtoupper($method); if ($method === 'HEAD') { $method = 'GET'; } $path = RouteHelper::formatPath($path, $this->ignoreLastSlash); $sKey = $method . ' ' . $path; // It is a static route path if (isset($this->staticRoutes[$sKey])) { return [self::FOUND, $path, $this->staticRoutes[$sKey]]; } // Find in route caches. if ($this->cacheRoutes && isset($this->cacheRoutes[$sKey])) { return [self::FOUND, $path, $this->cacheRoutes[$sKey]]; } // It is a dynamic route, match by regexp $result = $this->matchDynamicRoute($path, $method); if ($result[0] === self::FOUND) { // will cache param route. $this->cacheMatchedParamRoute($path, $method, $result[2]); return $result; } // Handle Auto Route if ($this->autoRoute && ($handler = $this->matchAutoRoute($path))) { return [self::FOUND, $path, Route::create($method, $path, $handler)]; } // If nothing else matches, try fallback routes. $router->any('*', 'handler'); $sKey = $method . ' /*'; if ($this->staticRoutes && isset($this->staticRoutes[$sKey])) { return [self::FOUND, $path, $this->staticRoutes[$sKey]]; } if ($this->handleMethodNotAllowed) { return $this->findAllowedMethods($path, $method); } return [self::NOT_FOUND, $path, null]; }
php
public function match(string $path, string $method = 'GET'): array { // For HEAD requests, attempt fallback to GET $method = \strtoupper($method); if ($method === 'HEAD') { $method = 'GET'; } $path = RouteHelper::formatPath($path, $this->ignoreLastSlash); $sKey = $method . ' ' . $path; // It is a static route path if (isset($this->staticRoutes[$sKey])) { return [self::FOUND, $path, $this->staticRoutes[$sKey]]; } // Find in route caches. if ($this->cacheRoutes && isset($this->cacheRoutes[$sKey])) { return [self::FOUND, $path, $this->cacheRoutes[$sKey]]; } // It is a dynamic route, match by regexp $result = $this->matchDynamicRoute($path, $method); if ($result[0] === self::FOUND) { // will cache param route. $this->cacheMatchedParamRoute($path, $method, $result[2]); return $result; } // Handle Auto Route if ($this->autoRoute && ($handler = $this->matchAutoRoute($path))) { return [self::FOUND, $path, Route::create($method, $path, $handler)]; } // If nothing else matches, try fallback routes. $router->any('*', 'handler'); $sKey = $method . ' /*'; if ($this->staticRoutes && isset($this->staticRoutes[$sKey])) { return [self::FOUND, $path, $this->staticRoutes[$sKey]]; } if ($this->handleMethodNotAllowed) { return $this->findAllowedMethods($path, $method); } return [self::NOT_FOUND, $path, null]; }
[ "public", "function", "match", "(", "string", "$", "path", ",", "string", "$", "method", "=", "'GET'", ")", ":", "array", "{", "// For HEAD requests, attempt fallback to GET", "$", "method", "=", "\\", "strtoupper", "(", "$", "method", ")", ";", "if", "(", "$", "method", "===", "'HEAD'", ")", "{", "$", "method", "=", "'GET'", ";", "}", "$", "path", "=", "RouteHelper", "::", "formatPath", "(", "$", "path", ",", "$", "this", "->", "ignoreLastSlash", ")", ";", "$", "sKey", "=", "$", "method", ".", "' '", ".", "$", "path", ";", "// It is a static route path", "if", "(", "isset", "(", "$", "this", "->", "staticRoutes", "[", "$", "sKey", "]", ")", ")", "{", "return", "[", "self", "::", "FOUND", ",", "$", "path", ",", "$", "this", "->", "staticRoutes", "[", "$", "sKey", "]", "]", ";", "}", "// Find in route caches.", "if", "(", "$", "this", "->", "cacheRoutes", "&&", "isset", "(", "$", "this", "->", "cacheRoutes", "[", "$", "sKey", "]", ")", ")", "{", "return", "[", "self", "::", "FOUND", ",", "$", "path", ",", "$", "this", "->", "cacheRoutes", "[", "$", "sKey", "]", "]", ";", "}", "// It is a dynamic route, match by regexp", "$", "result", "=", "$", "this", "->", "matchDynamicRoute", "(", "$", "path", ",", "$", "method", ")", ";", "if", "(", "$", "result", "[", "0", "]", "===", "self", "::", "FOUND", ")", "{", "// will cache param route.", "$", "this", "->", "cacheMatchedParamRoute", "(", "$", "path", ",", "$", "method", ",", "$", "result", "[", "2", "]", ")", ";", "return", "$", "result", ";", "}", "// Handle Auto Route", "if", "(", "$", "this", "->", "autoRoute", "&&", "(", "$", "handler", "=", "$", "this", "->", "matchAutoRoute", "(", "$", "path", ")", ")", ")", "{", "return", "[", "self", "::", "FOUND", ",", "$", "path", ",", "Route", "::", "create", "(", "$", "method", ",", "$", "path", ",", "$", "handler", ")", "]", ";", "}", "// If nothing else matches, try fallback routes. $router->any('*', 'handler');", "$", "sKey", "=", "$", "method", ".", "' /*'", ";", "if", "(", "$", "this", "->", "staticRoutes", "&&", "isset", "(", "$", "this", "->", "staticRoutes", "[", "$", "sKey", "]", ")", ")", "{", "return", "[", "self", "::", "FOUND", ",", "$", "path", ",", "$", "this", "->", "staticRoutes", "[", "$", "sKey", "]", "]", ";", "}", "if", "(", "$", "this", "->", "handleMethodNotAllowed", ")", "{", "return", "$", "this", "->", "findAllowedMethods", "(", "$", "path", ",", "$", "method", ")", ";", "}", "return", "[", "self", "::", "NOT_FOUND", ",", "$", "path", ",", "null", "]", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/ServerRouter.php#L61-L105
inhere/php-srouter
src/RouterConfigTrait.php
RouterConfigTrait.config
public function config(array $config): void { if ($this->routeCounter > 0) { throw new \LogicException('Routing has been added, and configuration is not allowed!'); } $props = [ 'name' => 1, 'chains' => 1, // 'defaultRoute' => 1, 'ignoreLastSlash' => 1, 'tmpCacheNumber' => 1, 'handleMethodNotAllowed' => 1, 'autoRoute' => 1, 'controllerNamespace' => 1, 'controllerSuffix' => 1, ]; foreach ($config as $name => $value) { if (isset($props[$name])) { $this->$name = $value; } } }
php
public function config(array $config): void { if ($this->routeCounter > 0) { throw new \LogicException('Routing has been added, and configuration is not allowed!'); } $props = [ 'name' => 1, 'chains' => 1, // 'defaultRoute' => 1, 'ignoreLastSlash' => 1, 'tmpCacheNumber' => 1, 'handleMethodNotAllowed' => 1, 'autoRoute' => 1, 'controllerNamespace' => 1, 'controllerSuffix' => 1, ]; foreach ($config as $name => $value) { if (isset($props[$name])) { $this->$name = $value; } } }
[ "public", "function", "config", "(", "array", "$", "config", ")", ":", "void", "{", "if", "(", "$", "this", "->", "routeCounter", ">", "0", ")", "{", "throw", "new", "\\", "LogicException", "(", "'Routing has been added, and configuration is not allowed!'", ")", ";", "}", "$", "props", "=", "[", "'name'", "=>", "1", ",", "'chains'", "=>", "1", ",", "// 'defaultRoute' => 1,", "'ignoreLastSlash'", "=>", "1", ",", "'tmpCacheNumber'", "=>", "1", ",", "'handleMethodNotAllowed'", "=>", "1", ",", "'autoRoute'", "=>", "1", ",", "'controllerNamespace'", "=>", "1", ",", "'controllerSuffix'", "=>", "1", ",", "]", ";", "foreach", "(", "$", "config", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "isset", "(", "$", "props", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "$", "name", "=", "$", "value", ";", "}", "}", "}" ]
config the router @param array $config @throws \LogicException
[ "config", "the", "router" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/RouterConfigTrait.php#L86-L109
inhere/php-srouter
src/Router.php
Router.middleware
public function middleware(...$middleware): Router { foreach ($middleware as $handler) { $this->chains[] = $handler; } return $this; }
php
public function middleware(...$middleware): Router { foreach ($middleware as $handler) { $this->chains[] = $handler; } return $this; }
[ "public", "function", "middleware", "(", "...", "$", "middleware", ")", ":", "Router", "{", "foreach", "(", "$", "middleware", "as", "$", "handler", ")", "{", "$", "this", "->", "chains", "[", "]", "=", "$", "handler", ";", "}", "return", "$", "this", ";", "}" ]
push middleware(s) for the route @param mixed ...$middleware @return Router
[ "push", "middleware", "(", "s", ")", "for", "the", "route" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Router.php#L141-L148
inhere/php-srouter
src/Router.php
Router.get
public function get(string $path, $handler, array $pathParams = [], array $opts = []): Route { return $this->add('GET', $path, $handler, $pathParams, $opts); // return $this->map(['GET', 'HEAD'], $path, $handler, $pathParams, $opts); }
php
public function get(string $path, $handler, array $pathParams = [], array $opts = []): Route { return $this->add('GET', $path, $handler, $pathParams, $opts); // return $this->map(['GET', 'HEAD'], $path, $handler, $pathParams, $opts); }
[ "public", "function", "get", "(", "string", "$", "path", ",", "$", "handler", ",", "array", "$", "pathParams", "=", "[", "]", ",", "array", "$", "opts", "=", "[", "]", ")", ":", "Route", "{", "return", "$", "this", "->", "add", "(", "'GET'", ",", "$", "path", ",", "$", "handler", ",", "$", "pathParams", ",", "$", "opts", ")", ";", "// return $this->map(['GET', 'HEAD'], $path, $handler, $pathParams, $opts);", "}" ]
register a route, allow GET request method. {@inheritdoc}
[ "register", "a", "route", "allow", "GET", "request", "method", ".", "{" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Router.php#L158-L162
inhere/php-srouter
src/Router.php
Router.any
public function any(string $path, $handler, array $pathParams = [], array $opts = []): void { $this->map(self::METHODS_ARRAY, $path, $handler, $pathParams, $opts); }
php
public function any(string $path, $handler, array $pathParams = [], array $opts = []): void { $this->map(self::METHODS_ARRAY, $path, $handler, $pathParams, $opts); }
[ "public", "function", "any", "(", "string", "$", "path", ",", "$", "handler", ",", "array", "$", "pathParams", "=", "[", "]", ",", "array", "$", "opts", "=", "[", "]", ")", ":", "void", "{", "$", "this", "->", "map", "(", "self", "::", "METHODS_ARRAY", ",", "$", "path", ",", "$", "handler", ",", "$", "pathParams", ",", "$", "opts", ")", ";", "}" ]
register a route, allow any request METHOD. {@inheritdoc}
[ "register", "a", "route", "allow", "any", "request", "METHOD", ".", "{" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Router.php#L231-L234
inhere/php-srouter
src/Router.php
Router.group
public function group(string $prefix, \Closure $callback, array $middleware = [], array $opts = []): void { // Backups $previousGroupPrefix = $this->currentGroupPrefix; $previousGroupOption = $this->currentGroupOption; $previousGroupChains = $this->currentGroupChains; $this->currentGroupOption = $opts; $this->currentGroupChains = $middleware; $this->currentGroupPrefix = $previousGroupPrefix . '/' . \trim($prefix, '/'); // Run callback. $callback($this); // Reverts $this->currentGroupPrefix = $previousGroupPrefix; $this->currentGroupOption = $previousGroupOption; $this->currentGroupChains = $previousGroupChains; }
php
public function group(string $prefix, \Closure $callback, array $middleware = [], array $opts = []): void { // Backups $previousGroupPrefix = $this->currentGroupPrefix; $previousGroupOption = $this->currentGroupOption; $previousGroupChains = $this->currentGroupChains; $this->currentGroupOption = $opts; $this->currentGroupChains = $middleware; $this->currentGroupPrefix = $previousGroupPrefix . '/' . \trim($prefix, '/'); // Run callback. $callback($this); // Reverts $this->currentGroupPrefix = $previousGroupPrefix; $this->currentGroupOption = $previousGroupOption; $this->currentGroupChains = $previousGroupChains; }
[ "public", "function", "group", "(", "string", "$", "prefix", ",", "\\", "Closure", "$", "callback", ",", "array", "$", "middleware", "=", "[", "]", ",", "array", "$", "opts", "=", "[", "]", ")", ":", "void", "{", "// Backups", "$", "previousGroupPrefix", "=", "$", "this", "->", "currentGroupPrefix", ";", "$", "previousGroupOption", "=", "$", "this", "->", "currentGroupOption", ";", "$", "previousGroupChains", "=", "$", "this", "->", "currentGroupChains", ";", "$", "this", "->", "currentGroupOption", "=", "$", "opts", ";", "$", "this", "->", "currentGroupChains", "=", "$", "middleware", ";", "$", "this", "->", "currentGroupPrefix", "=", "$", "previousGroupPrefix", ".", "'/'", ".", "\\", "trim", "(", "$", "prefix", ",", "'/'", ")", ";", "// Run callback.", "$", "callback", "(", "$", "this", ")", ";", "// Reverts", "$", "this", "->", "currentGroupPrefix", "=", "$", "previousGroupPrefix", ";", "$", "this", "->", "currentGroupOption", "=", "$", "previousGroupOption", ";", "$", "this", "->", "currentGroupChains", "=", "$", "previousGroupChains", ";", "}" ]
Create a route group with a common prefix. All routes created in the passed callback will have the given group prefix prepended. @param string $prefix @param \Closure $callback @param array $middleware @param array $opts
[ "Create", "a", "route", "group", "with", "a", "common", "prefix", ".", "All", "routes", "created", "in", "the", "passed", "callback", "will", "have", "the", "given", "group", "prefix", "prepended", "." ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Router.php#L326-L344
inhere/php-srouter
src/Router.php
Router.appendGroupInfo
protected function appendGroupInfo(Route $route): void { $path = $bak = $route->getPath(); // Always add '/' prefix. $path = \strpos($path, '/') === 0 ? $path : '/' . $path; $path = $this->currentGroupPrefix . $path; // Has setting 'ignoreLastSlash' if ($path !== '/' && $this->ignoreLastSlash) { $path = \rtrim($path, '/'); } // Not in group and path not change. if ($bak === $path) { return; } $route->setPath($path); // Not in group if (!$this->currentGroupPrefix) { return; } if ($this->currentGroupOption) { $route->setOptions(\array_merge($this->currentGroupOption, $route->getOptions())); } // Prepend group middleware at before. if ($this->currentGroupChains) { $route->setChains(\array_merge($this->currentGroupChains, $route->getChains())); } }
php
protected function appendGroupInfo(Route $route): void { $path = $bak = $route->getPath(); // Always add '/' prefix. $path = \strpos($path, '/') === 0 ? $path : '/' . $path; $path = $this->currentGroupPrefix . $path; // Has setting 'ignoreLastSlash' if ($path !== '/' && $this->ignoreLastSlash) { $path = \rtrim($path, '/'); } // Not in group and path not change. if ($bak === $path) { return; } $route->setPath($path); // Not in group if (!$this->currentGroupPrefix) { return; } if ($this->currentGroupOption) { $route->setOptions(\array_merge($this->currentGroupOption, $route->getOptions())); } // Prepend group middleware at before. if ($this->currentGroupChains) { $route->setChains(\array_merge($this->currentGroupChains, $route->getChains())); } }
[ "protected", "function", "appendGroupInfo", "(", "Route", "$", "route", ")", ":", "void", "{", "$", "path", "=", "$", "bak", "=", "$", "route", "->", "getPath", "(", ")", ";", "// Always add '/' prefix.", "$", "path", "=", "\\", "strpos", "(", "$", "path", ",", "'/'", ")", "===", "0", "?", "$", "path", ":", "'/'", ".", "$", "path", ";", "$", "path", "=", "$", "this", "->", "currentGroupPrefix", ".", "$", "path", ";", "// Has setting 'ignoreLastSlash'", "if", "(", "$", "path", "!==", "'/'", "&&", "$", "this", "->", "ignoreLastSlash", ")", "{", "$", "path", "=", "\\", "rtrim", "(", "$", "path", ",", "'/'", ")", ";", "}", "// Not in group and path not change.", "if", "(", "$", "bak", "===", "$", "path", ")", "{", "return", ";", "}", "$", "route", "->", "setPath", "(", "$", "path", ")", ";", "// Not in group", "if", "(", "!", "$", "this", "->", "currentGroupPrefix", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "currentGroupOption", ")", "{", "$", "route", "->", "setOptions", "(", "\\", "array_merge", "(", "$", "this", "->", "currentGroupOption", ",", "$", "route", "->", "getOptions", "(", ")", ")", ")", ";", "}", "// Prepend group middleware at before.", "if", "(", "$", "this", "->", "currentGroupChains", ")", "{", "$", "route", "->", "setChains", "(", "\\", "array_merge", "(", "$", "this", "->", "currentGroupChains", ",", "$", "route", "->", "getChains", "(", ")", ")", ")", ";", "}", "}" ]
prepare for add @param Route $route @return void
[ "prepare", "for", "add" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Router.php#L351-L384
inhere/php-srouter
src/Router.php
Router.matchDynamicRoute
protected function matchDynamicRoute(string $path, string $method): array { $first = \strstr(\ltrim($path, '/'), '/', true); $fKey = $first ? $method . ' ' . $first : ''; // It is a regular dynamic route(the first node is 1th level index key). if ($fKey && isset($this->regularRoutes[$fKey])) { /** @var Route $route */ foreach ($this->regularRoutes[$fKey] as $route) { // Check path start string $pathStart = $route->getPathStart(); if (\strpos($path, $pathStart) !== 0) { continue; } $result = $route->matchRegex($path); if ($result[0]) { return [self::FOUND, $path, $route->copyWithParams($result[1])]; } } } // It is a irregular dynamic route // if ($routeList = $this->vagueRoutes[$method] ?? false) { if (isset($this->vagueRoutes[$method])) { foreach ($this->vagueRoutes[$method] as $route) { $result = $route->matchRegex($path); if ($result[0]) { return [self::FOUND, $path, $route->copyWithParams($result[1])]; } } } return [self::NOT_FOUND, $path, null]; }
php
protected function matchDynamicRoute(string $path, string $method): array { $first = \strstr(\ltrim($path, '/'), '/', true); $fKey = $first ? $method . ' ' . $first : ''; // It is a regular dynamic route(the first node is 1th level index key). if ($fKey && isset($this->regularRoutes[$fKey])) { /** @var Route $route */ foreach ($this->regularRoutes[$fKey] as $route) { // Check path start string $pathStart = $route->getPathStart(); if (\strpos($path, $pathStart) !== 0) { continue; } $result = $route->matchRegex($path); if ($result[0]) { return [self::FOUND, $path, $route->copyWithParams($result[1])]; } } } // It is a irregular dynamic route // if ($routeList = $this->vagueRoutes[$method] ?? false) { if (isset($this->vagueRoutes[$method])) { foreach ($this->vagueRoutes[$method] as $route) { $result = $route->matchRegex($path); if ($result[0]) { return [self::FOUND, $path, $route->copyWithParams($result[1])]; } } } return [self::NOT_FOUND, $path, null]; }
[ "protected", "function", "matchDynamicRoute", "(", "string", "$", "path", ",", "string", "$", "method", ")", ":", "array", "{", "$", "first", "=", "\\", "strstr", "(", "\\", "ltrim", "(", "$", "path", ",", "'/'", ")", ",", "'/'", ",", "true", ")", ";", "$", "fKey", "=", "$", "first", "?", "$", "method", ".", "' '", ".", "$", "first", ":", "''", ";", "// It is a regular dynamic route(the first node is 1th level index key).", "if", "(", "$", "fKey", "&&", "isset", "(", "$", "this", "->", "regularRoutes", "[", "$", "fKey", "]", ")", ")", "{", "/** @var Route $route */", "foreach", "(", "$", "this", "->", "regularRoutes", "[", "$", "fKey", "]", "as", "$", "route", ")", "{", "// Check path start string", "$", "pathStart", "=", "$", "route", "->", "getPathStart", "(", ")", ";", "if", "(", "\\", "strpos", "(", "$", "path", ",", "$", "pathStart", ")", "!==", "0", ")", "{", "continue", ";", "}", "$", "result", "=", "$", "route", "->", "matchRegex", "(", "$", "path", ")", ";", "if", "(", "$", "result", "[", "0", "]", ")", "{", "return", "[", "self", "::", "FOUND", ",", "$", "path", ",", "$", "route", "->", "copyWithParams", "(", "$", "result", "[", "1", "]", ")", "]", ";", "}", "}", "}", "// It is a irregular dynamic route", "// if ($routeList = $this->vagueRoutes[$method] ?? false) {", "if", "(", "isset", "(", "$", "this", "->", "vagueRoutes", "[", "$", "method", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "vagueRoutes", "[", "$", "method", "]", "as", "$", "route", ")", "{", "$", "result", "=", "$", "route", "->", "matchRegex", "(", "$", "path", ")", ";", "if", "(", "$", "result", "[", "0", "]", ")", "{", "return", "[", "self", "::", "FOUND", ",", "$", "path", ",", "$", "route", "->", "copyWithParams", "(", "$", "result", "[", "1", "]", ")", "]", ";", "}", "}", "}", "return", "[", "self", "::", "NOT_FOUND", ",", "$", "path", ",", "null", "]", ";", "}" ]
is a dynamic route, match by regexp @param string $path @param string $method @return array [ status, path, Route(object) -> it's a raw Route clone. ]
[ "is", "a", "dynamic", "route", "match", "by", "regexp" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Router.php#L452-L486
inhere/php-srouter
src/Router.php
Router.matchAutoRoute
public function matchAutoRoute(string $path) { if (!$cnp = \trim($this->controllerNamespace)) { return false; } $sfx = \trim($this->controllerSuffix); return RouteHelper::parseAutoRoute($path, $cnp, $sfx); }
php
public function matchAutoRoute(string $path) { if (!$cnp = \trim($this->controllerNamespace)) { return false; } $sfx = \trim($this->controllerSuffix); return RouteHelper::parseAutoRoute($path, $cnp, $sfx); }
[ "public", "function", "matchAutoRoute", "(", "string", "$", "path", ")", "{", "if", "(", "!", "$", "cnp", "=", "\\", "trim", "(", "$", "this", "->", "controllerNamespace", ")", ")", "{", "return", "false", ";", "}", "$", "sfx", "=", "\\", "trim", "(", "$", "this", "->", "controllerSuffix", ")", ";", "return", "RouteHelper", "::", "parseAutoRoute", "(", "$", "path", ",", "$", "cnp", ",", "$", "sfx", ")", ";", "}" ]
handle auto route match, when config `'autoRoute' => true` @param string $path The route path @return bool|callable
[ "handle", "auto", "route", "match", "when", "config", "autoRoute", "=", ">", "true" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Router.php#L493-L502
inhere/php-srouter
src/Router.php
Router.dispatch
public function dispatch($dispatcher = null, $path = null, $method = null) { if (!$dispatcher) { $dispatcher = new Dispatcher; } elseif (\is_array($dispatcher)) { $dispatcher = new Dispatcher($dispatcher); } if (!$dispatcher instanceof DispatcherInterface) { throw new \InvalidArgumentException( 'The first argument is must an array OR an object instanceof the DispatcherInterface' ); } if (!$dispatcher->hasRouter()) { $dispatcher->setRouter($this); } return $dispatcher->dispatchUri($path, $method); }
php
public function dispatch($dispatcher = null, $path = null, $method = null) { if (!$dispatcher) { $dispatcher = new Dispatcher; } elseif (\is_array($dispatcher)) { $dispatcher = new Dispatcher($dispatcher); } if (!$dispatcher instanceof DispatcherInterface) { throw new \InvalidArgumentException( 'The first argument is must an array OR an object instanceof the DispatcherInterface' ); } if (!$dispatcher->hasRouter()) { $dispatcher->setRouter($this); } return $dispatcher->dispatchUri($path, $method); }
[ "public", "function", "dispatch", "(", "$", "dispatcher", "=", "null", ",", "$", "path", "=", "null", ",", "$", "method", "=", "null", ")", "{", "if", "(", "!", "$", "dispatcher", ")", "{", "$", "dispatcher", "=", "new", "Dispatcher", ";", "}", "elseif", "(", "\\", "is_array", "(", "$", "dispatcher", ")", ")", "{", "$", "dispatcher", "=", "new", "Dispatcher", "(", "$", "dispatcher", ")", ";", "}", "if", "(", "!", "$", "dispatcher", "instanceof", "DispatcherInterface", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'The first argument is must an array OR an object instanceof the DispatcherInterface'", ")", ";", "}", "if", "(", "!", "$", "dispatcher", "->", "hasRouter", "(", ")", ")", "{", "$", "dispatcher", "->", "setRouter", "(", "$", "this", ")", ";", "}", "return", "$", "dispatcher", "->", "dispatchUri", "(", "$", "path", ",", "$", "method", ")", ";", "}" ]
Runs the callback for the given request @param DispatcherInterface|array $dispatcher @param null|string $path @param null|string $method @return mixed @throws \LogicException @throws \Throwable
[ "Runs", "the", "callback", "for", "the", "given", "request" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Router.php#L548-L567
inhere/php-srouter
src/Router.php
Router.getRoutes
public function getRoutes(): array { $routes = []; $this->each(function (Route $route) use (&$routes) { $routes[] = $route; }); return $routes; }
php
public function getRoutes(): array { $routes = []; $this->each(function (Route $route) use (&$routes) { $routes[] = $route; }); return $routes; }
[ "public", "function", "getRoutes", "(", ")", ":", "array", "{", "$", "routes", "=", "[", "]", ";", "$", "this", "->", "each", "(", "function", "(", "Route", "$", "route", ")", "use", "(", "&", "$", "routes", ")", "{", "$", "routes", "[", "]", "=", "$", "route", ";", "}", ")", ";", "return", "$", "routes", ";", "}" ]
get all routes @return array
[ "get", "all", "routes" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Router.php#L643-L651
inhere/php-srouter
src/RouterManager.php
RouterManager.get
public function get($condition = null): Router { if (!$condition) { return $this->getDefault(); } // alias of getByName() if (\is_string($condition)) { return $this->getByName($condition); } $useName = self::DEFAULT_ROUTER; foreach ($this->conditions as $name => $cond) { if ($this->compareArray($cond, $condition)) { $useName = $name; break; } } return $this->getByName($useName); }
php
public function get($condition = null): Router { if (!$condition) { return $this->getDefault(); } // alias of getByName() if (\is_string($condition)) { return $this->getByName($condition); } $useName = self::DEFAULT_ROUTER; foreach ($this->conditions as $name => $cond) { if ($this->compareArray($cond, $condition)) { $useName = $name; break; } } return $this->getByName($useName); }
[ "public", "function", "get", "(", "$", "condition", "=", "null", ")", ":", "Router", "{", "if", "(", "!", "$", "condition", ")", "{", "return", "$", "this", "->", "getDefault", "(", ")", ";", "}", "// alias of getByName()", "if", "(", "\\", "is_string", "(", "$", "condition", ")", ")", "{", "return", "$", "this", "->", "getByName", "(", "$", "condition", ")", ";", "}", "$", "useName", "=", "self", "::", "DEFAULT_ROUTER", ";", "foreach", "(", "$", "this", "->", "conditions", "as", "$", "name", "=>", "$", "cond", ")", "{", "if", "(", "$", "this", "->", "compareArray", "(", "$", "cond", ",", "$", "condition", ")", ")", "{", "$", "useName", "=", "$", "name", ";", "break", ";", "}", "}", "return", "$", "this", "->", "getByName", "(", "$", "useName", ")", ";", "}" ]
get router by condition @param array|string $condition array: [ 'domain' => 'abc.com', 'scheme' => 'https', ] string: get by name. same of call getByName() @return Router |RouterInterface @throws \InvalidArgumentException
[ "get", "router", "by", "condition" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/RouterManager.php#L142-L163
inhere/php-srouter
src/CachedRouter.php
CachedRouter.add
public function add(string $method, string $path, $handler, array $binds = [], array $opts = []): Route { // file cache exists check. if ($this->cacheLoaded) { return Route::createFromArray(); } return parent::add($method, $path, $handler, $binds, $opts); }
php
public function add(string $method, string $path, $handler, array $binds = [], array $opts = []): Route { // file cache exists check. if ($this->cacheLoaded) { return Route::createFromArray(); } return parent::add($method, $path, $handler, $binds, $opts); }
[ "public", "function", "add", "(", "string", "$", "method", ",", "string", "$", "path", ",", "$", "handler", ",", "array", "$", "binds", "=", "[", "]", ",", "array", "$", "opts", "=", "[", "]", ")", ":", "Route", "{", "// file cache exists check.", "if", "(", "$", "this", "->", "cacheLoaded", ")", "{", "return", "Route", "::", "createFromArray", "(", ")", ";", "}", "return", "parent", "::", "add", "(", "$", "method", ",", "$", "path", ",", "$", "handler", ",", "$", "binds", ",", "$", "opts", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/CachedRouter.php#L71-L79
inhere/php-srouter
src/CachedRouter.php
CachedRouter.addRoute
public function addRoute(Route $route): Route { // file cache exists check. if ($this->cacheLoaded) { return $route; } return parent::addRoute($route); }
php
public function addRoute(Route $route): Route { // file cache exists check. if ($this->cacheLoaded) { return $route; } return parent::addRoute($route); }
[ "public", "function", "addRoute", "(", "Route", "$", "route", ")", ":", "Route", "{", "// file cache exists check.", "if", "(", "$", "this", "->", "cacheLoaded", ")", "{", "return", "$", "route", ";", "}", "return", "parent", "::", "addRoute", "(", "$", "route", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/CachedRouter.php#L84-L92
inhere/php-srouter
src/CachedRouter.php
CachedRouter.loadRoutesCache
public function loadRoutesCache(): bool { if (!$this->isCacheEnable()) { return false; } $file = $this->cacheFile; if (!$file || !\file_exists($file)) { return false; } // load routes $map = require $file; $this->routeCounter = 0; $staticRoutes = $regularRoutes = $vagueRoutes = []; foreach ($map['staticRoutes'] as $key => $info) { $this->routeCounter++; $staticRoutes[$key] = Route::createFromArray($info); } foreach ($map['regularRoutes'] as $key => $routes) { foreach ($routes as $info) { $this->routeCounter++; $regularRoutes[$key][] = Route::createFromArray($info); } } foreach ($map['vagueRoutes'] as $key => $routes) { foreach ($routes as $info) { $this->routeCounter++; $vagueRoutes[$key][] = Route::createFromArray($info); } } $this->staticRoutes = $staticRoutes; $this->regularRoutes = $regularRoutes; $this->vagueRoutes = $vagueRoutes; $this->cacheLoaded = true; return true; }
php
public function loadRoutesCache(): bool { if (!$this->isCacheEnable()) { return false; } $file = $this->cacheFile; if (!$file || !\file_exists($file)) { return false; } // load routes $map = require $file; $this->routeCounter = 0; $staticRoutes = $regularRoutes = $vagueRoutes = []; foreach ($map['staticRoutes'] as $key => $info) { $this->routeCounter++; $staticRoutes[$key] = Route::createFromArray($info); } foreach ($map['regularRoutes'] as $key => $routes) { foreach ($routes as $info) { $this->routeCounter++; $regularRoutes[$key][] = Route::createFromArray($info); } } foreach ($map['vagueRoutes'] as $key => $routes) { foreach ($routes as $info) { $this->routeCounter++; $vagueRoutes[$key][] = Route::createFromArray($info); } } $this->staticRoutes = $staticRoutes; $this->regularRoutes = $regularRoutes; $this->vagueRoutes = $vagueRoutes; $this->cacheLoaded = true; return true; }
[ "public", "function", "loadRoutesCache", "(", ")", ":", "bool", "{", "if", "(", "!", "$", "this", "->", "isCacheEnable", "(", ")", ")", "{", "return", "false", ";", "}", "$", "file", "=", "$", "this", "->", "cacheFile", ";", "if", "(", "!", "$", "file", "||", "!", "\\", "file_exists", "(", "$", "file", ")", ")", "{", "return", "false", ";", "}", "// load routes", "$", "map", "=", "require", "$", "file", ";", "$", "this", "->", "routeCounter", "=", "0", ";", "$", "staticRoutes", "=", "$", "regularRoutes", "=", "$", "vagueRoutes", "=", "[", "]", ";", "foreach", "(", "$", "map", "[", "'staticRoutes'", "]", "as", "$", "key", "=>", "$", "info", ")", "{", "$", "this", "->", "routeCounter", "++", ";", "$", "staticRoutes", "[", "$", "key", "]", "=", "Route", "::", "createFromArray", "(", "$", "info", ")", ";", "}", "foreach", "(", "$", "map", "[", "'regularRoutes'", "]", "as", "$", "key", "=>", "$", "routes", ")", "{", "foreach", "(", "$", "routes", "as", "$", "info", ")", "{", "$", "this", "->", "routeCounter", "++", ";", "$", "regularRoutes", "[", "$", "key", "]", "[", "]", "=", "Route", "::", "createFromArray", "(", "$", "info", ")", ";", "}", "}", "foreach", "(", "$", "map", "[", "'vagueRoutes'", "]", "as", "$", "key", "=>", "$", "routes", ")", "{", "foreach", "(", "$", "routes", "as", "$", "info", ")", "{", "$", "this", "->", "routeCounter", "++", ";", "$", "vagueRoutes", "[", "$", "key", "]", "[", "]", "=", "Route", "::", "createFromArray", "(", "$", "info", ")", ";", "}", "}", "$", "this", "->", "staticRoutes", "=", "$", "staticRoutes", ";", "$", "this", "->", "regularRoutes", "=", "$", "regularRoutes", ";", "$", "this", "->", "vagueRoutes", "=", "$", "vagueRoutes", ";", "$", "this", "->", "cacheLoaded", "=", "true", ";", "return", "true", ";", "}" ]
load route caches from the cache file @return bool
[ "load", "route", "caches", "from", "the", "cache", "file" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/CachedRouter.php#L102-L143
inhere/php-srouter
src/CachedRouter.php
CachedRouter.dumpRoutesCache
protected function dumpRoutesCache(): int { if (!$file = $this->cacheFile) { return 0; } if ($this->isCacheEnable() && \file_exists($file)) { return 1; } $date = \date('Y-m-d H:i:s'); $class = static::class; $count = $this->count(); $staticRoutes = \var_export($this->staticRoutes, true); $regularRoutes = \var_export($this->regularRoutes, true); $vagueRoutes = \var_export($this->vagueRoutes, true); $code = <<<EOF <?php /* * This is routes cache file of the package `inhere/sroute`. * It is auto generate by $class. * @date $date * @count $count * @notice Please don't edit it. */ return array ( // static routes 'staticRoutes' => $staticRoutes, // regular routes 'regularRoutes' => $regularRoutes, // vague routes 'vagueRoutes' => $vagueRoutes, );\n EOF; return \file_put_contents($file, \preg_replace( ['/\s+\n\s+Inhere\\\\Route\\\\Route::__set_state\(/', '/\)\),/', '/=>\s+\n\s+array \(/'], [' ', '),', '=> array ('], $code )); }
php
protected function dumpRoutesCache(): int { if (!$file = $this->cacheFile) { return 0; } if ($this->isCacheEnable() && \file_exists($file)) { return 1; } $date = \date('Y-m-d H:i:s'); $class = static::class; $count = $this->count(); $staticRoutes = \var_export($this->staticRoutes, true); $regularRoutes = \var_export($this->regularRoutes, true); $vagueRoutes = \var_export($this->vagueRoutes, true); $code = <<<EOF <?php /* * This is routes cache file of the package `inhere/sroute`. * It is auto generate by $class. * @date $date * @count $count * @notice Please don't edit it. */ return array ( // static routes 'staticRoutes' => $staticRoutes, // regular routes 'regularRoutes' => $regularRoutes, // vague routes 'vagueRoutes' => $vagueRoutes, );\n EOF; return \file_put_contents($file, \preg_replace( ['/\s+\n\s+Inhere\\\\Route\\\\Route::__set_state\(/', '/\)\),/', '/=>\s+\n\s+array \(/'], [' ', '),', '=> array ('], $code )); }
[ "protected", "function", "dumpRoutesCache", "(", ")", ":", "int", "{", "if", "(", "!", "$", "file", "=", "$", "this", "->", "cacheFile", ")", "{", "return", "0", ";", "}", "if", "(", "$", "this", "->", "isCacheEnable", "(", ")", "&&", "\\", "file_exists", "(", "$", "file", ")", ")", "{", "return", "1", ";", "}", "$", "date", "=", "\\", "date", "(", "'Y-m-d H:i:s'", ")", ";", "$", "class", "=", "static", "::", "class", ";", "$", "count", "=", "$", "this", "->", "count", "(", ")", ";", "$", "staticRoutes", "=", "\\", "var_export", "(", "$", "this", "->", "staticRoutes", ",", "true", ")", ";", "$", "regularRoutes", "=", "\\", "var_export", "(", "$", "this", "->", "regularRoutes", ",", "true", ")", ";", "$", "vagueRoutes", "=", "\\", "var_export", "(", "$", "this", "->", "vagueRoutes", ",", "true", ")", ";", "$", "code", "=", " <<<EOF\n<?php\n/*\n * This is routes cache file of the package `inhere/sroute`.\n * It is auto generate by $class.\n * @date $date\n * @count $count\n * @notice Please don't edit it.\n */\nreturn array (\n// static routes\n'staticRoutes' => $staticRoutes,\n// regular routes\n'regularRoutes' => $regularRoutes,\n// vague routes\n'vagueRoutes' => $vagueRoutes,\n);\\n\nEOF", ";", "return", "\\", "file_put_contents", "(", "$", "file", ",", "\\", "preg_replace", "(", "[", "'/\\s+\\n\\s+Inhere\\\\\\\\Route\\\\\\\\Route::__set_state\\(/'", ",", "'/\\)\\),/'", ",", "'/=>\\s+\\n\\s+array \\(/'", "]", ",", "[", "' '", ",", "'),'", ",", "'=> array ('", "]", ",", "$", "code", ")", ")", ";", "}" ]
dump routes to cache file @return int
[ "dump", "routes", "to", "cache", "file" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/CachedRouter.php#L149-L190
inhere/php-srouter
src/Route.php
Route.namedTo
public function namedTo(string $name, Router $router, bool $register = false): void { // not empty if ($name = $this->setName($name)->name) { if ($register) { $router->addRoute($this); } else { $router->nameRoute($name, $this); } } }
php
public function namedTo(string $name, Router $router, bool $register = false): void { // not empty if ($name = $this->setName($name)->name) { if ($register) { $router->addRoute($this); } else { $router->nameRoute($name, $this); } } }
[ "public", "function", "namedTo", "(", "string", "$", "name", ",", "Router", "$", "router", ",", "bool", "$", "register", "=", "false", ")", ":", "void", "{", "// not empty", "if", "(", "$", "name", "=", "$", "this", "->", "setName", "(", "$", "name", ")", "->", "name", ")", "{", "if", "(", "$", "register", ")", "{", "$", "router", "->", "addRoute", "(", "$", "this", ")", ";", "}", "else", "{", "$", "router", "->", "nameRoute", "(", "$", "name", ",", "$", "this", ")", ";", "}", "}", "}" ]
name the route and bind name to router. @param string $name @param Router $router @param bool $register
[ "name", "the", "route", "and", "bind", "name", "to", "router", "." ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Route.php#L170-L180
inhere/php-srouter
src/Route.php
Route.parseParam
public function parseParam(array $bindParams = []): string { $argPos = \strpos($this->path, '{'); $optPos = \strpos($this->path, '['); return $this->quickParseParams($argPos, $optPos, $bindParams); }
php
public function parseParam(array $bindParams = []): string { $argPos = \strpos($this->path, '{'); $optPos = \strpos($this->path, '['); return $this->quickParseParams($argPos, $optPos, $bindParams); }
[ "public", "function", "parseParam", "(", "array", "$", "bindParams", "=", "[", "]", ")", ":", "string", "{", "$", "argPos", "=", "\\", "strpos", "(", "$", "this", "->", "path", ",", "'{'", ")", ";", "$", "optPos", "=", "\\", "strpos", "(", "$", "this", "->", "path", ",", "'['", ")", ";", "return", "$", "this", "->", "quickParseParams", "(", "$", "argPos", ",", "$", "optPos", ",", "$", "bindParams", ")", ";", "}" ]
parse route path string. fetch route params @param array $bindParams @return string returns the first node string.
[ "parse", "route", "path", "string", ".", "fetch", "route", "params" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Route.php#L191-L197
inhere/php-srouter
src/Route.php
Route.middleware
public function middleware(...$middleware): self { foreach ($middleware as $handler) { $this->chains[] = $handler; } return $this; }
php
public function middleware(...$middleware): self { foreach ($middleware as $handler) { $this->chains[] = $handler; } return $this; }
[ "public", "function", "middleware", "(", "...", "$", "middleware", ")", ":", "self", "{", "foreach", "(", "$", "middleware", "as", "$", "handler", ")", "{", "$", "this", "->", "chains", "[", "]", "=", "$", "handler", ";", "}", "return", "$", "this", ";", "}" ]
push middleware(s) to the route @param array ...$middleware @return Route
[ "push", "middleware", "(", "s", ")", "to", "the", "route" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Route.php#L334-L341
inhere/php-srouter
src/Route.php
Route.toUri
public function toUri(array $pathVars = []): string { if ($pathVars) { return \strtr($this->path, $pathVars); } return $this->path; }
php
public function toUri(array $pathVars = []): string { if ($pathVars) { return \strtr($this->path, $pathVars); } return $this->path; }
[ "public", "function", "toUri", "(", "array", "$", "pathVars", "=", "[", "]", ")", ":", "string", "{", "if", "(", "$", "pathVars", ")", "{", "return", "\\", "strtr", "(", "$", "this", "->", "path", ",", "$", "pathVars", ")", ";", "}", "return", "$", "this", "->", "path", ";", "}" ]
build uri string. @param array $pathVars @return string
[ "build", "uri", "string", "." ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Route.php#L368-L375
inhere/php-srouter
src/Route.php
Route.toArray
public function toArray(): array { return [ 'name' => $this->name, 'path' => $this->path, 'method' => $this->method, 'handler' => $this->handler, 'binds' => $this->bindVars, 'params' => $this->params, 'options' => $this->options, // 'pathVars' => $this->pathVars, 'pathStart' => $this->pathStart, 'pathRegex' => $this->pathRegex, // 'chains' => $this->chains, ]; }
php
public function toArray(): array { return [ 'name' => $this->name, 'path' => $this->path, 'method' => $this->method, 'handler' => $this->handler, 'binds' => $this->bindVars, 'params' => $this->params, 'options' => $this->options, // 'pathVars' => $this->pathVars, 'pathStart' => $this->pathStart, 'pathRegex' => $this->pathRegex, // 'chains' => $this->chains, ]; }
[ "public", "function", "toArray", "(", ")", ":", "array", "{", "return", "[", "'name'", "=>", "$", "this", "->", "name", ",", "'path'", "=>", "$", "this", "->", "path", ",", "'method'", "=>", "$", "this", "->", "method", ",", "'handler'", "=>", "$", "this", "->", "handler", ",", "'binds'", "=>", "$", "this", "->", "bindVars", ",", "'params'", "=>", "$", "this", "->", "params", ",", "'options'", "=>", "$", "this", "->", "options", ",", "//", "'pathVars'", "=>", "$", "this", "->", "pathVars", ",", "'pathStart'", "=>", "$", "this", "->", "pathStart", ",", "'pathRegex'", "=>", "$", "this", "->", "pathRegex", ",", "//", "'chains'", "=>", "$", "this", "->", "chains", ",", "]", ";", "}" ]
get all info data @return array
[ "get", "all", "info", "data" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Route.php#L394-L411
inhere/php-srouter
src/Helper/RouteHelper.php
RouteHelper.isStaticRoute
public static function isStaticRoute(string $route): bool { return \strpos($route, '{') === false && \strpos($route, '[') === false; }
php
public static function isStaticRoute(string $route): bool { return \strpos($route, '{') === false && \strpos($route, '[') === false; }
[ "public", "static", "function", "isStaticRoute", "(", "string", "$", "route", ")", ":", "bool", "{", "return", "\\", "strpos", "(", "$", "route", ",", "'{'", ")", "===", "false", "&&", "\\", "strpos", "(", "$", "route", ",", "'['", ")", "===", "false", ";", "}" ]
is Static Route @param string $route @return bool
[ "is", "Static", "Route" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Helper/RouteHelper.php#L22-L25
inhere/php-srouter
src/Helper/RouteHelper.php
RouteHelper.formatPath
public static function formatPath(string $path, bool $ignoreLastSlash = true): string { if ($path === '/') { return '/'; } // Clear '//', '///' => '/' if (false !== \strpos($path, '//')) { $path = \preg_replace('#\/\/+#', '/', $path); } // Must be start withs '/' if (\strpos($path, '/') !== 0) { $path = '/' . $path; } // Decode $path = \rawurldecode($path); return $ignoreLastSlash ? \rtrim($path, '/') : $path; }
php
public static function formatPath(string $path, bool $ignoreLastSlash = true): string { if ($path === '/') { return '/'; } // Clear '//', '///' => '/' if (false !== \strpos($path, '//')) { $path = \preg_replace('#\/\/+#', '/', $path); } // Must be start withs '/' if (\strpos($path, '/') !== 0) { $path = '/' . $path; } // Decode $path = \rawurldecode($path); return $ignoreLastSlash ? \rtrim($path, '/') : $path; }
[ "public", "static", "function", "formatPath", "(", "string", "$", "path", ",", "bool", "$", "ignoreLastSlash", "=", "true", ")", ":", "string", "{", "if", "(", "$", "path", "===", "'/'", ")", "{", "return", "'/'", ";", "}", "// Clear '//', '///' => '/'", "if", "(", "false", "!==", "\\", "strpos", "(", "$", "path", ",", "'//'", ")", ")", "{", "$", "path", "=", "\\", "preg_replace", "(", "'#\\/\\/+#'", ",", "'/'", ",", "$", "path", ")", ";", "}", "// Must be start withs '/'", "if", "(", "\\", "strpos", "(", "$", "path", ",", "'/'", ")", "!==", "0", ")", "{", "$", "path", "=", "'/'", ".", "$", "path", ";", "}", "// Decode", "$", "path", "=", "\\", "rawurldecode", "(", "$", "path", ")", ";", "return", "$", "ignoreLastSlash", "?", "\\", "rtrim", "(", "$", "path", ",", "'/'", ")", ":", "$", "path", ";", "}" ]
format URI path @param string $path @param bool $ignoreLastSlash @return string
[ "format", "URI", "path" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Helper/RouteHelper.php#L33-L53
inhere/php-srouter
src/Helper/RouteHelper.php
RouteHelper.parseAutoRoute
public static function parseAutoRoute(string $path, string $cnp, string $sfx) { $tmp = \trim($path, '/- '); // one node. eg: 'home' if (!\strpos($tmp, '/')) { $tmp = self::str2Camel($tmp); $class = "$cnp\\" . \ucfirst($tmp) . $sfx; return \class_exists($class) ? $class : false; } $ary = \array_map(self::class . '::str2Camel', \explode('/', $tmp)); $cnt = \count($ary); // two nodes. eg: 'home/test' 'admin/user' if ($cnt === 2) { [$n1, $n2] = $ary; // last node is an controller class name. eg: 'admin/user' $class = "$cnp\\$n1\\" . \ucfirst($n2) . $sfx; if (\class_exists($class)) { return $class; } // first node is an controller class name, second node is a action name, $class = "$cnp\\" . \ucfirst($n1) . $sfx; return \class_exists($class) ? "$class@$n2" : false; } // max allow 5 nodes if ($cnt > 5) { return false; } // last node is an controller class name $n2 = \array_pop($ary); $class = \sprintf('%s\\%s\\%s', $cnp, \implode('\\', $ary), \ucfirst($n2) . $sfx); if (\class_exists($class)) { return $class; } // last second is an controller class name, last node is a action name, $n1 = \array_pop($ary); $class = \sprintf('%s\\%s\\%s', $cnp, \implode('\\', $ary), \ucfirst($n1) . $sfx); return \class_exists($class) ? "$class@$n2" : false; }
php
public static function parseAutoRoute(string $path, string $cnp, string $sfx) { $tmp = \trim($path, '/- '); // one node. eg: 'home' if (!\strpos($tmp, '/')) { $tmp = self::str2Camel($tmp); $class = "$cnp\\" . \ucfirst($tmp) . $sfx; return \class_exists($class) ? $class : false; } $ary = \array_map(self::class . '::str2Camel', \explode('/', $tmp)); $cnt = \count($ary); // two nodes. eg: 'home/test' 'admin/user' if ($cnt === 2) { [$n1, $n2] = $ary; // last node is an controller class name. eg: 'admin/user' $class = "$cnp\\$n1\\" . \ucfirst($n2) . $sfx; if (\class_exists($class)) { return $class; } // first node is an controller class name, second node is a action name, $class = "$cnp\\" . \ucfirst($n1) . $sfx; return \class_exists($class) ? "$class@$n2" : false; } // max allow 5 nodes if ($cnt > 5) { return false; } // last node is an controller class name $n2 = \array_pop($ary); $class = \sprintf('%s\\%s\\%s', $cnp, \implode('\\', $ary), \ucfirst($n2) . $sfx); if (\class_exists($class)) { return $class; } // last second is an controller class name, last node is a action name, $n1 = \array_pop($ary); $class = \sprintf('%s\\%s\\%s', $cnp, \implode('\\', $ary), \ucfirst($n1) . $sfx); return \class_exists($class) ? "$class@$n2" : false; }
[ "public", "static", "function", "parseAutoRoute", "(", "string", "$", "path", ",", "string", "$", "cnp", ",", "string", "$", "sfx", ")", "{", "$", "tmp", "=", "\\", "trim", "(", "$", "path", ",", "'/- '", ")", ";", "// one node. eg: 'home'", "if", "(", "!", "\\", "strpos", "(", "$", "tmp", ",", "'/'", ")", ")", "{", "$", "tmp", "=", "self", "::", "str2Camel", "(", "$", "tmp", ")", ";", "$", "class", "=", "\"$cnp\\\\\"", ".", "\\", "ucfirst", "(", "$", "tmp", ")", ".", "$", "sfx", ";", "return", "\\", "class_exists", "(", "$", "class", ")", "?", "$", "class", ":", "false", ";", "}", "$", "ary", "=", "\\", "array_map", "(", "self", "::", "class", ".", "'::str2Camel'", ",", "\\", "explode", "(", "'/'", ",", "$", "tmp", ")", ")", ";", "$", "cnt", "=", "\\", "count", "(", "$", "ary", ")", ";", "// two nodes. eg: 'home/test' 'admin/user'", "if", "(", "$", "cnt", "===", "2", ")", "{", "[", "$", "n1", ",", "$", "n2", "]", "=", "$", "ary", ";", "// last node is an controller class name. eg: 'admin/user'", "$", "class", "=", "\"$cnp\\\\$n1\\\\\"", ".", "\\", "ucfirst", "(", "$", "n2", ")", ".", "$", "sfx", ";", "if", "(", "\\", "class_exists", "(", "$", "class", ")", ")", "{", "return", "$", "class", ";", "}", "// first node is an controller class name, second node is a action name,", "$", "class", "=", "\"$cnp\\\\\"", ".", "\\", "ucfirst", "(", "$", "n1", ")", ".", "$", "sfx", ";", "return", "\\", "class_exists", "(", "$", "class", ")", "?", "\"$class@$n2\"", ":", "false", ";", "}", "// max allow 5 nodes", "if", "(", "$", "cnt", ">", "5", ")", "{", "return", "false", ";", "}", "// last node is an controller class name", "$", "n2", "=", "\\", "array_pop", "(", "$", "ary", ")", ";", "$", "class", "=", "\\", "sprintf", "(", "'%s\\\\%s\\\\%s'", ",", "$", "cnp", ",", "\\", "implode", "(", "'\\\\'", ",", "$", "ary", ")", ",", "\\", "ucfirst", "(", "$", "n2", ")", ".", "$", "sfx", ")", ";", "if", "(", "\\", "class_exists", "(", "$", "class", ")", ")", "{", "return", "$", "class", ";", "}", "// last second is an controller class name, last node is a action name,", "$", "n1", "=", "\\", "array_pop", "(", "$", "ary", ")", ";", "$", "class", "=", "\\", "sprintf", "(", "'%s\\\\%s\\\\%s'", ",", "$", "cnp", ",", "\\", "implode", "(", "'\\\\'", ",", "$", "ary", ")", ",", "\\", "ucfirst", "(", "$", "n1", ")", ".", "$", "sfx", ")", ";", "return", "\\", "class_exists", "(", "$", "class", ")", "?", "\"$class@$n2\"", ":", "false", ";", "}" ]
handle auto route match, when config `'autoRoute' => true` @param string $path The route path @param string $cnp controller namespace. eg: 'app\\controllers' @param string $sfx controller suffix. eg: 'Controller' @return bool|callable
[ "handle", "auto", "route", "match", "when", "config", "autoRoute", "=", ">", "true" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Helper/RouteHelper.php#L80-L130
inhere/php-srouter
src/Helper/RouteHelper.php
RouteHelper.call
public static function call($cb, array $args = []) { if (!$cb) { return true; } if (\is_array($cb)) { [$obj, $mhd] = $cb; return \is_object($obj) ? $obj->$mhd(...$args) : $obj::$mhd(...$args); } if (\is_string($cb)) { if (\function_exists($cb)) { return $cb(...$args); } // a class name if (\class_exists($cb)) { $cb = new $cb; } } // a \Closure or Object implement '__invoke' if (\is_object($cb) && \method_exists($cb, '__invoke')) { return $cb(...$args); } throw new \InvalidArgumentException('the callback handler is not callable!'); }
php
public static function call($cb, array $args = []) { if (!$cb) { return true; } if (\is_array($cb)) { [$obj, $mhd] = $cb; return \is_object($obj) ? $obj->$mhd(...$args) : $obj::$mhd(...$args); } if (\is_string($cb)) { if (\function_exists($cb)) { return $cb(...$args); } // a class name if (\class_exists($cb)) { $cb = new $cb; } } // a \Closure or Object implement '__invoke' if (\is_object($cb) && \method_exists($cb, '__invoke')) { return $cb(...$args); } throw new \InvalidArgumentException('the callback handler is not callable!'); }
[ "public", "static", "function", "call", "(", "$", "cb", ",", "array", "$", "args", "=", "[", "]", ")", "{", "if", "(", "!", "$", "cb", ")", "{", "return", "true", ";", "}", "if", "(", "\\", "is_array", "(", "$", "cb", ")", ")", "{", "[", "$", "obj", ",", "$", "mhd", "]", "=", "$", "cb", ";", "return", "\\", "is_object", "(", "$", "obj", ")", "?", "$", "obj", "->", "$", "mhd", "(", "...", "$", "args", ")", ":", "$", "obj", "::", "$", "mhd", "(", "...", "$", "args", ")", ";", "}", "if", "(", "\\", "is_string", "(", "$", "cb", ")", ")", "{", "if", "(", "\\", "function_exists", "(", "$", "cb", ")", ")", "{", "return", "$", "cb", "(", "...", "$", "args", ")", ";", "}", "// a class name", "if", "(", "\\", "class_exists", "(", "$", "cb", ")", ")", "{", "$", "cb", "=", "new", "$", "cb", ";", "}", "}", "// a \\Closure or Object implement '__invoke'", "if", "(", "\\", "is_object", "(", "$", "cb", ")", "&&", "\\", "method_exists", "(", "$", "cb", ",", "'__invoke'", ")", ")", "{", "return", "$", "cb", "(", "...", "$", "args", ")", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'the callback handler is not callable!'", ")", ";", "}" ]
@param callable|mixed $cb string - func name, class name array - [class, method] object - Closure, Object @param array $args @return mixed @throws \InvalidArgumentException
[ "@param", "callable|mixed", "$cb", "string", "-", "func", "name", "class", "name", "array", "-", "[", "class", "method", "]", "object", "-", "Closure", "Object" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Helper/RouteHelper.php#L142-L171
inhere/php-srouter
src/PreMatchRouter.php
PreMatchRouter.match
public function match(string $path, string $method = 'GET'): array { // If has been pre-matched. if ($this->preFounded) { return [self::FOUND, $path, $this->preFounded]; } return parent::match($path, $method); }
php
public function match(string $path, string $method = 'GET'): array { // If has been pre-matched. if ($this->preFounded) { return [self::FOUND, $path, $this->preFounded]; } return parent::match($path, $method); }
[ "public", "function", "match", "(", "string", "$", "path", ",", "string", "$", "method", "=", "'GET'", ")", ":", "array", "{", "// If has been pre-matched.", "if", "(", "$", "this", "->", "preFounded", ")", "{", "return", "[", "self", "::", "FOUND", ",", "$", "path", ",", "$", "this", "->", "preFounded", "]", ";", "}", "return", "parent", "::", "match", "(", "$", "path", ",", "$", "method", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/PreMatchRouter.php#L100-L108
inhere/php-srouter
src/Dispatcher/SimpleDispatcher.php
SimpleDispatcher.dispatchUri
public function dispatchUri(string $path = null, string $method = null) { $path = (string)($path ?: $_SERVER['REQUEST_URI']); if (\strpos($path, '?')) { $path = \parse_url($path, \PHP_URL_PATH); } // if 'filterFavicon' setting is TRUE if ($path === self::FAV_ICON && $this->options['filterFavicon']) { return null; } $method = (string)($method ?: $_SERVER['REQUEST_METHOD']); $method = \strtoupper($method); /** @var Route $route */ [$status, $path, $route] = $this->router->match($path, $method); return $this->dispatch($status, $path, $method, $route); }
php
public function dispatchUri(string $path = null, string $method = null) { $path = (string)($path ?: $_SERVER['REQUEST_URI']); if (\strpos($path, '?')) { $path = \parse_url($path, \PHP_URL_PATH); } // if 'filterFavicon' setting is TRUE if ($path === self::FAV_ICON && $this->options['filterFavicon']) { return null; } $method = (string)($method ?: $_SERVER['REQUEST_METHOD']); $method = \strtoupper($method); /** @var Route $route */ [$status, $path, $route] = $this->router->match($path, $method); return $this->dispatch($status, $path, $method, $route); }
[ "public", "function", "dispatchUri", "(", "string", "$", "path", "=", "null", ",", "string", "$", "method", "=", "null", ")", "{", "$", "path", "=", "(", "string", ")", "(", "$", "path", "?", ":", "$", "_SERVER", "[", "'REQUEST_URI'", "]", ")", ";", "if", "(", "\\", "strpos", "(", "$", "path", ",", "'?'", ")", ")", "{", "$", "path", "=", "\\", "parse_url", "(", "$", "path", ",", "\\", "PHP_URL_PATH", ")", ";", "}", "// if 'filterFavicon' setting is TRUE", "if", "(", "$", "path", "===", "self", "::", "FAV_ICON", "&&", "$", "this", "->", "options", "[", "'filterFavicon'", "]", ")", "{", "return", "null", ";", "}", "$", "method", "=", "(", "string", ")", "(", "$", "method", "?", ":", "$", "_SERVER", "[", "'REQUEST_METHOD'", "]", ")", ";", "$", "method", "=", "\\", "strtoupper", "(", "$", "method", ")", ";", "/** @var Route $route */", "[", "$", "status", ",", "$", "path", ",", "$", "route", "]", "=", "$", "this", "->", "router", "->", "match", "(", "$", "path", ",", "$", "method", ")", ";", "return", "$", "this", "->", "dispatch", "(", "$", "status", ",", "$", "path", ",", "$", "method", ",", "$", "route", ")", ";", "}" ]
Runs the callback for the given path and method. @param string $path @param null|string $method @return mixed @throws \Throwable @throws \RuntimeException @throws \InvalidArgumentException
[ "Runs", "the", "callback", "for", "the", "given", "path", "and", "method", "." ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Dispatcher/SimpleDispatcher.php#L119-L139
inhere/php-srouter
src/Dispatcher/SimpleDispatcher.php
SimpleDispatcher.callHandler
protected function callHandler(string $path, string $method, $handler, array $args = []) { // is a \Closure or a callable object if (\is_object($handler)) { return $handler($args); } //// $handler is string // is array ['controller', 'action'] if (\is_array($handler)) { $segments = $handler; } elseif (\is_string($handler)) { // is function if (\strpos($handler, '@') === false && \function_exists($handler)) { return $handler($args); } // e.g `Controllers\Home@index` Or only `Controllers\Home` $segments = \explode('@', \trim($handler)); } else { throw new \InvalidArgumentException("Invalid route handler for route '$path'"); } // Instantiation controller $controller = new $segments[0](); // Already assign action if (!empty($segments[1])) { $action = $segments[1]; // use dynamic action } elseif ($this->options['dynamicAction'] && ($var = $this->options['dynamicActionVar'])) { $action = isset($args[$var]) ? \trim($args[$var], '/') : $this->options['defaultAction']; // defined default action } elseif (!$action = $this->options['defaultAction']) { throw new \RuntimeException("please config the route path [$path] controller action to call"); } $action = RouteHelper::str2Camel($action); $actionMethod = $action . $this->options['actionSuffix']; // if set the 'actionExecutor', the action handle logic by it. if ($executor = $this->options['actionExecutor']) { return $controller->$executor($actionMethod, $args); } // action method is not exist if (!\method_exists($controller, $actionMethod)) { return $this->handleNotFound($path, $method, true); } // call controller's action method return $controller->$actionMethod($args); }
php
protected function callHandler(string $path, string $method, $handler, array $args = []) { // is a \Closure or a callable object if (\is_object($handler)) { return $handler($args); } //// $handler is string // is array ['controller', 'action'] if (\is_array($handler)) { $segments = $handler; } elseif (\is_string($handler)) { // is function if (\strpos($handler, '@') === false && \function_exists($handler)) { return $handler($args); } // e.g `Controllers\Home@index` Or only `Controllers\Home` $segments = \explode('@', \trim($handler)); } else { throw new \InvalidArgumentException("Invalid route handler for route '$path'"); } // Instantiation controller $controller = new $segments[0](); // Already assign action if (!empty($segments[1])) { $action = $segments[1]; // use dynamic action } elseif ($this->options['dynamicAction'] && ($var = $this->options['dynamicActionVar'])) { $action = isset($args[$var]) ? \trim($args[$var], '/') : $this->options['defaultAction']; // defined default action } elseif (!$action = $this->options['defaultAction']) { throw new \RuntimeException("please config the route path [$path] controller action to call"); } $action = RouteHelper::str2Camel($action); $actionMethod = $action . $this->options['actionSuffix']; // if set the 'actionExecutor', the action handle logic by it. if ($executor = $this->options['actionExecutor']) { return $controller->$executor($actionMethod, $args); } // action method is not exist if (!\method_exists($controller, $actionMethod)) { return $this->handleNotFound($path, $method, true); } // call controller's action method return $controller->$actionMethod($args); }
[ "protected", "function", "callHandler", "(", "string", "$", "path", ",", "string", "$", "method", ",", "$", "handler", ",", "array", "$", "args", "=", "[", "]", ")", "{", "// is a \\Closure or a callable object", "if", "(", "\\", "is_object", "(", "$", "handler", ")", ")", "{", "return", "$", "handler", "(", "$", "args", ")", ";", "}", "//// $handler is string", "// is array ['controller', 'action']", "if", "(", "\\", "is_array", "(", "$", "handler", ")", ")", "{", "$", "segments", "=", "$", "handler", ";", "}", "elseif", "(", "\\", "is_string", "(", "$", "handler", ")", ")", "{", "// is function", "if", "(", "\\", "strpos", "(", "$", "handler", ",", "'@'", ")", "===", "false", "&&", "\\", "function_exists", "(", "$", "handler", ")", ")", "{", "return", "$", "handler", "(", "$", "args", ")", ";", "}", "// e.g `Controllers\\Home@index` Or only `Controllers\\Home`", "$", "segments", "=", "\\", "explode", "(", "'@'", ",", "\\", "trim", "(", "$", "handler", ")", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Invalid route handler for route '$path'\"", ")", ";", "}", "// Instantiation controller", "$", "controller", "=", "new", "$", "segments", "[", "0", "]", "(", ")", ";", "// Already assign action", "if", "(", "!", "empty", "(", "$", "segments", "[", "1", "]", ")", ")", "{", "$", "action", "=", "$", "segments", "[", "1", "]", ";", "// use dynamic action", "}", "elseif", "(", "$", "this", "->", "options", "[", "'dynamicAction'", "]", "&&", "(", "$", "var", "=", "$", "this", "->", "options", "[", "'dynamicActionVar'", "]", ")", ")", "{", "$", "action", "=", "isset", "(", "$", "args", "[", "$", "var", "]", ")", "?", "\\", "trim", "(", "$", "args", "[", "$", "var", "]", ",", "'/'", ")", ":", "$", "this", "->", "options", "[", "'defaultAction'", "]", ";", "// defined default action", "}", "elseif", "(", "!", "$", "action", "=", "$", "this", "->", "options", "[", "'defaultAction'", "]", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"please config the route path [$path] controller action to call\"", ")", ";", "}", "$", "action", "=", "RouteHelper", "::", "str2Camel", "(", "$", "action", ")", ";", "$", "actionMethod", "=", "$", "action", ".", "$", "this", "->", "options", "[", "'actionSuffix'", "]", ";", "// if set the 'actionExecutor', the action handle logic by it.", "if", "(", "$", "executor", "=", "$", "this", "->", "options", "[", "'actionExecutor'", "]", ")", "{", "return", "$", "controller", "->", "$", "executor", "(", "$", "actionMethod", ",", "$", "args", ")", ";", "}", "// action method is not exist", "if", "(", "!", "\\", "method_exists", "(", "$", "controller", ",", "$", "actionMethod", ")", ")", "{", "return", "$", "this", "->", "handleNotFound", "(", "$", "path", ",", "$", "method", ",", "true", ")", ";", "}", "// call controller's action method", "return", "$", "controller", "->", "$", "actionMethod", "(", "$", "args", ")", ";", "}" ]
execute the matched Route Handler @param string $path The route path @param string $method The request method @param callable|mixed $handler The route path handler @param array $args Matched param from path [ 'name' => value ] @return mixed @throws \RuntimeException @throws \InvalidArgumentException @throws \Throwable
[ "execute", "the", "matched", "Route", "Handler" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Dispatcher/SimpleDispatcher.php#L196-L251
inhere/php-srouter
src/Dispatcher/SimpleDispatcher.php
SimpleDispatcher.on
public function on(string $event, $handler) { if (self::isSupportedEvent($event)) { $this->options[$event] = $handler; } }
php
public function on(string $event, $handler) { if (self::isSupportedEvent($event)) { $this->options[$event] = $handler; } }
[ "public", "function", "on", "(", "string", "$", "event", ",", "$", "handler", ")", "{", "if", "(", "self", "::", "isSupportedEvent", "(", "$", "event", ")", ")", "{", "$", "this", "->", "options", "[", "$", "event", "]", "=", "$", "handler", ";", "}", "}" ]
Defines callback on happen event @param $event @param callable $handler
[ "Defines", "callback", "on", "happen", "event" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Dispatcher/SimpleDispatcher.php#L357-L362
inhere/php-srouter
src/Dispatcher/SimpleDispatcher.php
SimpleDispatcher.fire
protected function fire(string $event, array $args = []) { if (!$cb = $this->getOption($event)) { return null; } return RouteHelper::call($cb, $args); }
php
protected function fire(string $event, array $args = []) { if (!$cb = $this->getOption($event)) { return null; } return RouteHelper::call($cb, $args); }
[ "protected", "function", "fire", "(", "string", "$", "event", ",", "array", "$", "args", "=", "[", "]", ")", "{", "if", "(", "!", "$", "cb", "=", "$", "this", "->", "getOption", "(", "$", "event", ")", ")", "{", "return", "null", ";", "}", "return", "RouteHelper", "::", "call", "(", "$", "cb", ",", "$", "args", ")", ";", "}" ]
Trigger event @param string $event @param array $args @return mixed @throws \InvalidArgumentException
[ "Trigger", "event" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Dispatcher/SimpleDispatcher.php#L371-L378
inhere/php-srouter
src/Dispatcher/Psr15Dispatcher.php
Psr15Dispatcher.dispatch
public function dispatch(int $status, string $path, string $method, $route) { // not found if ($status === RouterInterface::NOT_FOUND) { return $this->handleNotFound($path, $method); } // method not allowed if ($status === RouterInterface::METHOD_NOT_ALLOWED) { return $this->handleNotAllowed($path, $method, $route); } // trigger route found event $this->fire(self::ON_FOUND, [$path, $route]); $result = null; $options = $route->getOptions(); // fire enter event // schema,domains ... metadata validate if (isset($options['enter']) && false === RouteHelper::call($options['enter'], [$options, $path])) { return $result; } $handler = $route->getHandler(); $args = $route->getParams(); try { // trigger route exec_start event $this->fire(self::ON_EXEC_START, [$path, $route]); $globChains = $this->getRouter()->getChains(); $chains = $route->getChains(); $result = $this->callHandler($path, $method, $handler, $args); // fire leave event if (isset($options['leave'])) { RouteHelper::call($options['leave'], [$options, $path]); } // trigger route exec_end event $this->fire(self::ON_EXEC_END, [$path, $route, $result]); } catch (\Throwable $e) { // trigger route exec_error event if ($cb = $this->getOption(self::ON_EXEC_ERROR)) { return RouteHelper::call($cb, [$e, $path, $route]); } throw $e; } return $result; }
php
public function dispatch(int $status, string $path, string $method, $route) { // not found if ($status === RouterInterface::NOT_FOUND) { return $this->handleNotFound($path, $method); } // method not allowed if ($status === RouterInterface::METHOD_NOT_ALLOWED) { return $this->handleNotAllowed($path, $method, $route); } // trigger route found event $this->fire(self::ON_FOUND, [$path, $route]); $result = null; $options = $route->getOptions(); // fire enter event // schema,domains ... metadata validate if (isset($options['enter']) && false === RouteHelper::call($options['enter'], [$options, $path])) { return $result; } $handler = $route->getHandler(); $args = $route->getParams(); try { // trigger route exec_start event $this->fire(self::ON_EXEC_START, [$path, $route]); $globChains = $this->getRouter()->getChains(); $chains = $route->getChains(); $result = $this->callHandler($path, $method, $handler, $args); // fire leave event if (isset($options['leave'])) { RouteHelper::call($options['leave'], [$options, $path]); } // trigger route exec_end event $this->fire(self::ON_EXEC_END, [$path, $route, $result]); } catch (\Throwable $e) { // trigger route exec_error event if ($cb = $this->getOption(self::ON_EXEC_ERROR)) { return RouteHelper::call($cb, [$e, $path, $route]); } throw $e; } return $result; }
[ "public", "function", "dispatch", "(", "int", "$", "status", ",", "string", "$", "path", ",", "string", "$", "method", ",", "$", "route", ")", "{", "// not found", "if", "(", "$", "status", "===", "RouterInterface", "::", "NOT_FOUND", ")", "{", "return", "$", "this", "->", "handleNotFound", "(", "$", "path", ",", "$", "method", ")", ";", "}", "// method not allowed", "if", "(", "$", "status", "===", "RouterInterface", "::", "METHOD_NOT_ALLOWED", ")", "{", "return", "$", "this", "->", "handleNotAllowed", "(", "$", "path", ",", "$", "method", ",", "$", "route", ")", ";", "}", "// trigger route found event", "$", "this", "->", "fire", "(", "self", "::", "ON_FOUND", ",", "[", "$", "path", ",", "$", "route", "]", ")", ";", "$", "result", "=", "null", ";", "$", "options", "=", "$", "route", "->", "getOptions", "(", ")", ";", "// fire enter event", "// schema,domains ... metadata validate", "if", "(", "isset", "(", "$", "options", "[", "'enter'", "]", ")", "&&", "false", "===", "RouteHelper", "::", "call", "(", "$", "options", "[", "'enter'", "]", ",", "[", "$", "options", ",", "$", "path", "]", ")", ")", "{", "return", "$", "result", ";", "}", "$", "handler", "=", "$", "route", "->", "getHandler", "(", ")", ";", "$", "args", "=", "$", "route", "->", "getParams", "(", ")", ";", "try", "{", "// trigger route exec_start event", "$", "this", "->", "fire", "(", "self", "::", "ON_EXEC_START", ",", "[", "$", "path", ",", "$", "route", "]", ")", ";", "$", "globChains", "=", "$", "this", "->", "getRouter", "(", ")", "->", "getChains", "(", ")", ";", "$", "chains", "=", "$", "route", "->", "getChains", "(", ")", ";", "$", "result", "=", "$", "this", "->", "callHandler", "(", "$", "path", ",", "$", "method", ",", "$", "handler", ",", "$", "args", ")", ";", "// fire leave event", "if", "(", "isset", "(", "$", "options", "[", "'leave'", "]", ")", ")", "{", "RouteHelper", "::", "call", "(", "$", "options", "[", "'leave'", "]", ",", "[", "$", "options", ",", "$", "path", "]", ")", ";", "}", "// trigger route exec_end event", "$", "this", "->", "fire", "(", "self", "::", "ON_EXEC_END", ",", "[", "$", "path", ",", "$", "route", ",", "$", "result", "]", ")", ";", "}", "catch", "(", "\\", "Throwable", "$", "e", ")", "{", "// trigger route exec_error event", "if", "(", "$", "cb", "=", "$", "this", "->", "getOption", "(", "self", "::", "ON_EXEC_ERROR", ")", ")", "{", "return", "RouteHelper", "::", "call", "(", "$", "cb", ",", "[", "$", "e", ",", "$", "path", ",", "$", "route", "]", ")", ";", "}", "throw", "$", "e", ";", "}", "return", "$", "result", ";", "}" ]
Dispatch route handler for the given route info. {@inheritdoc} @throws \Exception @throws \Throwable
[ "Dispatch", "route", "handler", "for", "the", "given", "route", "info", ".", "{" ]
train
https://github.com/inhere/php-srouter/blob/b869feb27e4d41db39ad3603e19a16768a4efe62/src/Dispatcher/Psr15Dispatcher.php#L60-L113
apisearch-io/php-client
Repository/TransformableRepository.php
TransformableRepository.setRepositoryReference
public function setRepositoryReference(RepositoryReference $repositoryReference) { parent::setRepositoryReference($repositoryReference); $this ->repository ->setRepositoryReference($repositoryReference); }
php
public function setRepositoryReference(RepositoryReference $repositoryReference) { parent::setRepositoryReference($repositoryReference); $this ->repository ->setRepositoryReference($repositoryReference); }
[ "public", "function", "setRepositoryReference", "(", "RepositoryReference", "$", "repositoryReference", ")", "{", "parent", "::", "setRepositoryReference", "(", "$", "repositoryReference", ")", ";", "$", "this", "->", "repository", "->", "setRepositoryReference", "(", "$", "repositoryReference", ")", ";", "}" ]
Set repository reference. @param RepositoryReference $repositoryReference
[ "Set", "repository", "reference", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/TransformableRepository.php#L67-L73
apisearch-io/php-client
Repository/TransformableRepository.php
TransformableRepository.setCredentials
public function setCredentials( RepositoryReference $repositoryReference, TokenUUID $tokenUUID ) { parent::setCredentials($repositoryReference, $tokenUUID); $this ->repository ->setCredentials($repositoryReference, $tokenUUID); }
php
public function setCredentials( RepositoryReference $repositoryReference, TokenUUID $tokenUUID ) { parent::setCredentials($repositoryReference, $tokenUUID); $this ->repository ->setCredentials($repositoryReference, $tokenUUID); }
[ "public", "function", "setCredentials", "(", "RepositoryReference", "$", "repositoryReference", ",", "TokenUUID", "$", "tokenUUID", ")", "{", "parent", "::", "setCredentials", "(", "$", "repositoryReference", ",", "$", "tokenUUID", ")", ";", "$", "this", "->", "repository", "->", "setCredentials", "(", "$", "repositoryReference", ",", "$", "tokenUUID", ")", ";", "}" ]
Set credentials. @param RepositoryReference $repositoryReference @param TokenUUID $tokenUUID
[ "Set", "credentials", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/TransformableRepository.php#L81-L89
apisearch-io/php-client
Repository/TransformableRepository.php
TransformableRepository.query
public function query( Query $query, array $parameters = [] ): Result { $result = $this ->repository ->query($query, $parameters); return $this->applyTransformersToResult($result); }
php
public function query( Query $query, array $parameters = [] ): Result { $result = $this ->repository ->query($query, $parameters); return $this->applyTransformersToResult($result); }
[ "public", "function", "query", "(", "Query", "$", "query", ",", "array", "$", "parameters", "=", "[", "]", ")", ":", "Result", "{", "$", "result", "=", "$", "this", "->", "repository", "->", "query", "(", "$", "query", ",", "$", "parameters", ")", ";", "return", "$", "this", "->", "applyTransformersToResult", "(", "$", "result", ")", ";", "}" ]
Search across the index types. @param Query $query @param array $parameters @return Result @throws ResourceNotAvailableException
[ "Search", "across", "the", "index", "types", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/TransformableRepository.php#L129-L138
apisearch-io/php-client
Repository/TransformableRepository.php
TransformableRepository.applyTransformersToResult
private function applyTransformersToResult(Result $result): Result { return empty($result->getSubresults()) ? Result::create( $result->getQueryUUID(), $result->getTotalItems(), $result->getTotalHits(), $result->getAggregations(), $result->getSuggests(), $this ->transformer ->fromItems( $result->getItems() ) ) : Result::createMultiResult( array_map(function (Result $subresult) { return $this->applyTransformersToResult($subresult); }, $result->getSubresults()) ); }
php
private function applyTransformersToResult(Result $result): Result { return empty($result->getSubresults()) ? Result::create( $result->getQueryUUID(), $result->getTotalItems(), $result->getTotalHits(), $result->getAggregations(), $result->getSuggests(), $this ->transformer ->fromItems( $result->getItems() ) ) : Result::createMultiResult( array_map(function (Result $subresult) { return $this->applyTransformersToResult($subresult); }, $result->getSubresults()) ); }
[ "private", "function", "applyTransformersToResult", "(", "Result", "$", "result", ")", ":", "Result", "{", "return", "empty", "(", "$", "result", "->", "getSubresults", "(", ")", ")", "?", "Result", "::", "create", "(", "$", "result", "->", "getQueryUUID", "(", ")", ",", "$", "result", "->", "getTotalItems", "(", ")", ",", "$", "result", "->", "getTotalHits", "(", ")", ",", "$", "result", "->", "getAggregations", "(", ")", ",", "$", "result", "->", "getSuggests", "(", ")", ",", "$", "this", "->", "transformer", "->", "fromItems", "(", "$", "result", "->", "getItems", "(", ")", ")", ")", ":", "Result", "::", "createMultiResult", "(", "array_map", "(", "function", "(", "Result", "$", "subresult", ")", "{", "return", "$", "this", "->", "applyTransformersToResult", "(", "$", "subresult", ")", ";", "}", ",", "$", "result", "->", "getSubresults", "(", ")", ")", ")", ";", "}" ]
Apply transformers on Result. @param Result $result @return Result
[ "Apply", "transformers", "on", "Result", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/TransformableRepository.php#L147-L167
apisearch-io/php-client
Repository/TransformableRepository.php
TransformableRepository.updateItems
public function updateItems( Query $query, Changes $changes ) { $this ->repository ->updateItems( $query, $changes ); }
php
public function updateItems( Query $query, Changes $changes ) { $this ->repository ->updateItems( $query, $changes ); }
[ "public", "function", "updateItems", "(", "Query", "$", "query", ",", "Changes", "$", "changes", ")", "{", "$", "this", "->", "repository", "->", "updateItems", "(", "$", "query", ",", "$", "changes", ")", ";", "}" ]
Update items. @param Query $query @param Changes $changes
[ "Update", "items", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/TransformableRepository.php#L175-L185
apisearch-io/php-client
Repository/TransformableRepository.php
TransformableRepository.addObject
public function addObject($object) { $item = $this ->transformer ->toItem($object); if ($item instanceof Item) { $this->addItem($item); } }
php
public function addObject($object) { $item = $this ->transformer ->toItem($object); if ($item instanceof Item) { $this->addItem($item); } }
[ "public", "function", "addObject", "(", "$", "object", ")", "{", "$", "item", "=", "$", "this", "->", "transformer", "->", "toItem", "(", "$", "object", ")", ";", "if", "(", "$", "item", "instanceof", "Item", ")", "{", "$", "this", "->", "addItem", "(", "$", "item", ")", ";", "}", "}" ]
Generate item document by a simple object. @param mixed $object
[ "Generate", "item", "document", "by", "a", "simple", "object", "." ]
train
https://github.com/apisearch-io/php-client/blob/a6ecdd6dcd80cf1d28f58f2a23cdab618addb37a/Repository/TransformableRepository.php#L192-L201