repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
sequencelengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
sequencelengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
Innmind/neo4j-dbal
src/Query/Query.php
Query.merge
public function merge(string $variable = null, array $labels = []): self { $query = new self; $query->clauses = $this->clauses->add( new Clause\MergeClause( Clause\Expression\Path::startWithNode($variable, $labels) ) ); return $query; }
php
public function merge(string $variable = null, array $labels = []): self { $query = new self; $query->clauses = $this->clauses->add( new Clause\MergeClause( Clause\Expression\Path::startWithNode($variable, $labels) ) ); return $query; }
[ "public", "function", "merge", "(", "string", "$", "variable", "=", "null", ",", "array", "$", "labels", "=", "[", "]", ")", ":", "self", "{", "$", "query", "=", "new", "self", ";", "$", "query", "->", "clauses", "=", "$", "this", "->", "clauses", "->", "add", "(", "new", "Clause", "\\", "MergeClause", "(", "Clause", "\\", "Expression", "\\", "Path", "::", "startWithNode", "(", "$", "variable", ",", "$", "labels", ")", ")", ")", ";", "return", "$", "query", ";", "}" ]
Add a MERGE clause @param string $variable @param array $labels @return self
[ "Add", "a", "MERGE", "clause" ]
train
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L667-L677
Innmind/neo4j-dbal
src/Query/Query.php
Query.limit
public function limit(string $cypher): self { $query = new self; $query->clauses = $this->clauses->add( new Clause\LimitClause($cypher) ); return $query; }
php
public function limit(string $cypher): self { $query = new self; $query->clauses = $this->clauses->add( new Clause\LimitClause($cypher) ); return $query; }
[ "public", "function", "limit", "(", "string", "$", "cypher", ")", ":", "self", "{", "$", "query", "=", "new", "self", ";", "$", "query", "->", "clauses", "=", "$", "this", "->", "clauses", "->", "add", "(", "new", "Clause", "\\", "LimitClause", "(", "$", "cypher", ")", ")", ";", "return", "$", "query", ";", "}" ]
Add a LIMIT clause @see http://neo4j.com/docs/stable/query-limit.html#limit-return-first-from-expression @param string $cypher @return self
[ "Add", "a", "LIMIT", "clause" ]
train
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L687-L695
Innmind/neo4j-dbal
src/Query/Query.php
Query.foreach
public function foreach(string $cypher): self { $query = new self; $query->clauses = $this->clauses->add( new Clause\ForeachClause($cypher) ); return $query; }
php
public function foreach(string $cypher): self { $query = new self; $query->clauses = $this->clauses->add( new Clause\ForeachClause($cypher) ); return $query; }
[ "public", "function", "foreach", "(", "string", "$", "cypher", ")", ":", "self", "{", "$", "query", "=", "new", "self", ";", "$", "query", "->", "clauses", "=", "$", "this", "->", "clauses", "->", "add", "(", "new", "Clause", "\\", "ForeachClause", "(", "$", "cypher", ")", ")", ";", "return", "$", "query", ";", "}" ]
Add a FOREACH clause @param string $cypher @return self
[ "Add", "a", "FOREACH", "clause" ]
train
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L704-L712
Innmind/neo4j-dbal
src/Query/Query.php
Query.delete
public function delete(string $variable, bool $detach = false): self { $query = new self; $query->clauses = $this->clauses->add( new Clause\DeleteClause($variable, $detach) ); return $query; }
php
public function delete(string $variable, bool $detach = false): self { $query = new self; $query->clauses = $this->clauses->add( new Clause\DeleteClause($variable, $detach) ); return $query; }
[ "public", "function", "delete", "(", "string", "$", "variable", ",", "bool", "$", "detach", "=", "false", ")", ":", "self", "{", "$", "query", "=", "new", "self", ";", "$", "query", "->", "clauses", "=", "$", "this", "->", "clauses", "->", "add", "(", "new", "Clause", "\\", "DeleteClause", "(", "$", "variable", ",", "$", "detach", ")", ")", ";", "return", "$", "query", ";", "}" ]
Add a DELETE clause @param string $variable @param bool $detach @return self
[ "Add", "a", "DELETE", "clause" ]
train
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L722-L730
Innmind/neo4j-dbal
src/Query/Query.php
Query.create
public function create( string $variable, array $labels = [], bool $unique = false ): self { $query = new self; $query->clauses = $this->clauses->add( new Clause\CreateClause( Clause\Expression\Path::startWithNode($variable, $labels), $unique ) ); return $query; }
php
public function create( string $variable, array $labels = [], bool $unique = false ): self { $query = new self; $query->clauses = $this->clauses->add( new Clause\CreateClause( Clause\Expression\Path::startWithNode($variable, $labels), $unique ) ); return $query; }
[ "public", "function", "create", "(", "string", "$", "variable", ",", "array", "$", "labels", "=", "[", "]", ",", "bool", "$", "unique", "=", "false", ")", ":", "self", "{", "$", "query", "=", "new", "self", ";", "$", "query", "->", "clauses", "=", "$", "this", "->", "clauses", "->", "add", "(", "new", "Clause", "\\", "CreateClause", "(", "Clause", "\\", "Expression", "\\", "Path", "::", "startWithNode", "(", "$", "variable", ",", "$", "labels", ")", ",", "$", "unique", ")", ")", ";", "return", "$", "query", ";", "}" ]
Add a CREATE clause @param string $variable @param array $labels @param bool $unique @return self
[ "Add", "a", "CREATE", "clause" ]
train
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L741-L755
j-d/draggy
src/Draggy/Autocode/Templates/PHP/Entity1.php
Entity1.getTypeCheckLines
protected function getTypeCheckLines(PHPAttribute $attribute, array $allowedTypes) { $phpTypes = ['boolean', 'integer', 'float', 'string', 'array', 'object', 'null', 'NULL']; $phpFunctions = [ 'boolean' => 'is_bool', 'integer' => 'is_numeric', 'float' => 'is_numeric', 'string' => 'is_string', 'array' => 'is_array' ]; $names = []; $condition = []; foreach ($allowedTypes as $type) { if ((!is_array($type) && !in_array($type, $phpTypes)) || (is_array($type) && !isset($type['object']))) { throw new \RuntimeException('Invalid allowedTypes passed to getTypeCheck (' . (!is_array($type) ? $type : current(array_keys($type))) . ').'); } if (is_array($type)) { $names[] = $type['object']; $condition[] = '!$' . $attribute->getFullName() . ' instanceof ' . $type['object']; } else { /** @var string $type */ $names[] = $type; if ('null' === $type || 'NULL' === $type) { $condition[] = 'null !== $' . $attribute->getLowerFullName(); } else { $condition[] = '!' . $phpFunctions[$type] . '($' . $attribute->getLowerFullName() . ')'; } } } if (count($names) > 2) { $types = implode(' or ', [implode(', ', array_slice($names, 0, -1)), end($names)]); } else { $types = implode(' or ', $names); } $lines = []; $lines[] = 'if (' . implode(' && ', $condition) . ') {'; $lines[] = 'throw new \InvalidArgumentException(\'The attribute ' . $attribute->getLowerFullName() . ' on the class ' . $attribute->getEntity()->getName() . ' has to be ' . $types . ' (\' . gettype($' . $attribute->getLowerFullName() . ') . (\'object\' === gettype($' . $attribute->getLowerFullName() . ') ? \' \' . get_class($' . $attribute->getLowerFullName() . ') : \'\') . \' given).\');'; $lines[] = '}'; return $lines; }
php
protected function getTypeCheckLines(PHPAttribute $attribute, array $allowedTypes) { $phpTypes = ['boolean', 'integer', 'float', 'string', 'array', 'object', 'null', 'NULL']; $phpFunctions = [ 'boolean' => 'is_bool', 'integer' => 'is_numeric', 'float' => 'is_numeric', 'string' => 'is_string', 'array' => 'is_array' ]; $names = []; $condition = []; foreach ($allowedTypes as $type) { if ((!is_array($type) && !in_array($type, $phpTypes)) || (is_array($type) && !isset($type['object']))) { throw new \RuntimeException('Invalid allowedTypes passed to getTypeCheck (' . (!is_array($type) ? $type : current(array_keys($type))) . ').'); } if (is_array($type)) { $names[] = $type['object']; $condition[] = '!$' . $attribute->getFullName() . ' instanceof ' . $type['object']; } else { /** @var string $type */ $names[] = $type; if ('null' === $type || 'NULL' === $type) { $condition[] = 'null !== $' . $attribute->getLowerFullName(); } else { $condition[] = '!' . $phpFunctions[$type] . '($' . $attribute->getLowerFullName() . ')'; } } } if (count($names) > 2) { $types = implode(' or ', [implode(', ', array_slice($names, 0, -1)), end($names)]); } else { $types = implode(' or ', $names); } $lines = []; $lines[] = 'if (' . implode(' && ', $condition) . ') {'; $lines[] = 'throw new \InvalidArgumentException(\'The attribute ' . $attribute->getLowerFullName() . ' on the class ' . $attribute->getEntity()->getName() . ' has to be ' . $types . ' (\' . gettype($' . $attribute->getLowerFullName() . ') . (\'object\' === gettype($' . $attribute->getLowerFullName() . ') ? \' \' . get_class($' . $attribute->getLowerFullName() . ') : \'\') . \' given).\');'; $lines[] = '}'; return $lines; }
[ "protected", "function", "getTypeCheckLines", "(", "PHPAttribute", "$", "attribute", ",", "array", "$", "allowedTypes", ")", "{", "$", "phpTypes", "=", "[", "'boolean'", ",", "'integer'", ",", "'float'", ",", "'string'", ",", "'array'", ",", "'object'", ",", "'null'", ",", "'NULL'", "]", ";", "$", "phpFunctions", "=", "[", "'boolean'", "=>", "'is_bool'", ",", "'integer'", "=>", "'is_numeric'", ",", "'float'", "=>", "'is_numeric'", ",", "'string'", "=>", "'is_string'", ",", "'array'", "=>", "'is_array'", "]", ";", "$", "names", "=", "[", "]", ";", "$", "condition", "=", "[", "]", ";", "foreach", "(", "$", "allowedTypes", "as", "$", "type", ")", "{", "if", "(", "(", "!", "is_array", "(", "$", "type", ")", "&&", "!", "in_array", "(", "$", "type", ",", "$", "phpTypes", ")", ")", "||", "(", "is_array", "(", "$", "type", ")", "&&", "!", "isset", "(", "$", "type", "[", "'object'", "]", ")", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Invalid allowedTypes passed to getTypeCheck ('", ".", "(", "!", "is_array", "(", "$", "type", ")", "?", "$", "type", ":", "current", "(", "array_keys", "(", "$", "type", ")", ")", ")", ".", "').'", ")", ";", "}", "if", "(", "is_array", "(", "$", "type", ")", ")", "{", "$", "names", "[", "]", "=", "$", "type", "[", "'object'", "]", ";", "$", "condition", "[", "]", "=", "'!$'", ".", "$", "attribute", "->", "getFullName", "(", ")", ".", "' instanceof '", ".", "$", "type", "[", "'object'", "]", ";", "}", "else", "{", "/** @var string $type */", "$", "names", "[", "]", "=", "$", "type", ";", "if", "(", "'null'", "===", "$", "type", "||", "'NULL'", "===", "$", "type", ")", "{", "$", "condition", "[", "]", "=", "'null !== $'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ";", "}", "else", "{", "$", "condition", "[", "]", "=", "'!'", ".", "$", "phpFunctions", "[", "$", "type", "]", ".", "'($'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "')'", ";", "}", "}", "}", "if", "(", "count", "(", "$", "names", ")", ">", "2", ")", "{", "$", "types", "=", "implode", "(", "' or '", ",", "[", "implode", "(", "', '", ",", "array_slice", "(", "$", "names", ",", "0", ",", "-", "1", ")", ")", ",", "end", "(", "$", "names", ")", "]", ")", ";", "}", "else", "{", "$", "types", "=", "implode", "(", "' or '", ",", "$", "names", ")", ";", "}", "$", "lines", "=", "[", "]", ";", "$", "lines", "[", "]", "=", "'if ('", ".", "implode", "(", "' && '", ",", "$", "condition", ")", ".", "') {'", ";", "$", "lines", "[", "]", "=", "'throw new \\InvalidArgumentException(\\'The attribute '", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "' on the class '", ".", "$", "attribute", "->", "getEntity", "(", ")", "->", "getName", "(", ")", ".", "' has to be '", ".", "$", "types", ".", "' (\\' . gettype($'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "') . (\\'object\\' === gettype($'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "') ? \\' \\' . get_class($'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "') : \\'\\') . \\' given).\\');'", ";", "$", "lines", "[", "]", "=", "'}'", ";", "return", "$", "lines", ";", "}" ]
Returns a condition to check for the $attribute type. It allows for one or more types, including objects. @param PHPAttribute $attribute @param string[] $allowedTypes An array with the basic types, or a sub array in case of objects. E.g. ['integer', ['object'=>'MyClass']] @return string @throws \RuntimeException if the allowedTypes array is not well formed
[ "Returns", "a", "condition", "to", "check", "for", "the", "$attribute", "type", ".", "It", "allows", "for", "one", "or", "more", "types", "including", "objects", "." ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Templates/PHP/Entity1.php#L81-L129
j-d/draggy
src/Draggy/Autocode/Templates/PHP/Entity1.php
Entity1.getAttributeDocumentationLinesBasePart
public function getAttributeDocumentationLinesBasePart(PHPAttribute $attribute) { $lines = []; if (null !== $attribute->getDescription()) { $lines[] = $attribute->getDescription(); $lines[] = ''; } $lines[] = '@var ' . $attribute->getPhpAnnotationType() . ' $' . $attribute->getLowerFullName(); return $lines; }
php
public function getAttributeDocumentationLinesBasePart(PHPAttribute $attribute) { $lines = []; if (null !== $attribute->getDescription()) { $lines[] = $attribute->getDescription(); $lines[] = ''; } $lines[] = '@var ' . $attribute->getPhpAnnotationType() . ' $' . $attribute->getLowerFullName(); return $lines; }
[ "public", "function", "getAttributeDocumentationLinesBasePart", "(", "PHPAttribute", "$", "attribute", ")", "{", "$", "lines", "=", "[", "]", ";", "if", "(", "null", "!==", "$", "attribute", "->", "getDescription", "(", ")", ")", "{", "$", "lines", "[", "]", "=", "$", "attribute", "->", "getDescription", "(", ")", ";", "$", "lines", "[", "]", "=", "''", ";", "}", "$", "lines", "[", "]", "=", "'@var '", ".", "$", "attribute", "->", "getPhpAnnotationType", "(", ")", ".", "' $'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ";", "return", "$", "lines", ";", "}" ]
<editor-fold desc="Attributes">
[ "<editor", "-", "fold", "desc", "=", "Attributes", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Templates/PHP/Entity1.php#L132-L144
j-d/draggy
src/Draggy/Autocode/Templates/PHP/Entity1.php
Entity1.getSetterInnerValidationCodeLines
public function getSetterInnerValidationCodeLines(PHPAttribute $attribute) { $lines = []; if (null === $attribute->getPhpParameterType()) { if ('boolean' === $attribute->getPhpType()) { if (!$attribute->getNull()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['boolean'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['boolean', 'null'])); } } elseif ('integer' === $attribute->getPhpType()) { if (!$attribute->getNull()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['integer'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['integer', 'null'])); } } elseif ('float' === $attribute->getPhpType()) { if (!$attribute->getNull()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['float'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['float', 'null'])); } } elseif ('string' === $attribute->getPhpType()) { if ('string' === $attribute->getType()) { if (!$attribute->getNull()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string'])); if (null !== $attribute->getMinSize()) { $lines[] = ''; $lines[] = 'if (strlen($' . $attribute->getLowerFullName() . ') < ' . $attribute->getMinSize() . ') {'; $lines[] = 'throw new \InvalidArgumentException(\'On the attribute ' . $attribute->getLowerFullName() . ', the length of the string \' . $' . $attribute->getLowerFullName() . ' . \' is \' . strlen($' . $attribute->getLowerFullName() . ') . \' which is shorter than the minimum allowed (' . $attribute->getMinSize() . ').\');'; $lines[] = '}'; } } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string', 'null'])); if (null !== $attribute->getMinSize()) { $lines[] = ''; $lines[] = 'if (strlen($' . $attribute->getLowerFullName() . ') < ' . $attribute->getMinSize() . ') {'; $lines[] = 'throw new \InvalidArgumentException(\'On the attribute ' . $attribute->getLowerFullName() . ', the length of the string \' . $' . $attribute->getLowerFullName() . ' . \' is \' . strlen($' . $attribute->getLowerFullName() . ') . \' which is shorter than the minimum allowed (' . $attribute->getMinSize() . ').\');'; $lines[] = '}'; } } } elseif ('text' === $attribute->getType()) { if (!$attribute->getNull()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string', 'null'])); } } } elseif ('OneToOne' === $attribute->getForeign()) { if ($attribute->getOwnerSide()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => $attribute->getForeignEntity()->getName()], 'null'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => $attribute->getForeignEntity()->getName()], 'null'])); } }elseif ('ManyToOne' === $attribute->getForeign()) { if ($attribute->getOwnerSide()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => $attribute->getForeignEntity()->getName()], 'null'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => 'Collection'], 'null'])); } } } return $lines; }
php
public function getSetterInnerValidationCodeLines(PHPAttribute $attribute) { $lines = []; if (null === $attribute->getPhpParameterType()) { if ('boolean' === $attribute->getPhpType()) { if (!$attribute->getNull()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['boolean'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['boolean', 'null'])); } } elseif ('integer' === $attribute->getPhpType()) { if (!$attribute->getNull()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['integer'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['integer', 'null'])); } } elseif ('float' === $attribute->getPhpType()) { if (!$attribute->getNull()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['float'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['float', 'null'])); } } elseif ('string' === $attribute->getPhpType()) { if ('string' === $attribute->getType()) { if (!$attribute->getNull()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string'])); if (null !== $attribute->getMinSize()) { $lines[] = ''; $lines[] = 'if (strlen($' . $attribute->getLowerFullName() . ') < ' . $attribute->getMinSize() . ') {'; $lines[] = 'throw new \InvalidArgumentException(\'On the attribute ' . $attribute->getLowerFullName() . ', the length of the string \' . $' . $attribute->getLowerFullName() . ' . \' is \' . strlen($' . $attribute->getLowerFullName() . ') . \' which is shorter than the minimum allowed (' . $attribute->getMinSize() . ').\');'; $lines[] = '}'; } } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string', 'null'])); if (null !== $attribute->getMinSize()) { $lines[] = ''; $lines[] = 'if (strlen($' . $attribute->getLowerFullName() . ') < ' . $attribute->getMinSize() . ') {'; $lines[] = 'throw new \InvalidArgumentException(\'On the attribute ' . $attribute->getLowerFullName() . ', the length of the string \' . $' . $attribute->getLowerFullName() . ' . \' is \' . strlen($' . $attribute->getLowerFullName() . ') . \' which is shorter than the minimum allowed (' . $attribute->getMinSize() . ').\');'; $lines[] = '}'; } } } elseif ('text' === $attribute->getType()) { if (!$attribute->getNull()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, ['string', 'null'])); } } } elseif ('OneToOne' === $attribute->getForeign()) { if ($attribute->getOwnerSide()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => $attribute->getForeignEntity()->getName()], 'null'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => $attribute->getForeignEntity()->getName()], 'null'])); } }elseif ('ManyToOne' === $attribute->getForeign()) { if ($attribute->getOwnerSide()) { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => $attribute->getForeignEntity()->getName()], 'null'])); } else { $lines = array_merge($lines, $this->getTypeCheckLines($attribute, [['object' => 'Collection'], 'null'])); } } } return $lines; }
[ "public", "function", "getSetterInnerValidationCodeLines", "(", "PHPAttribute", "$", "attribute", ")", "{", "$", "lines", "=", "[", "]", ";", "if", "(", "null", "===", "$", "attribute", "->", "getPhpParameterType", "(", ")", ")", "{", "if", "(", "'boolean'", "===", "$", "attribute", "->", "getPhpType", "(", ")", ")", "{", "if", "(", "!", "$", "attribute", "->", "getNull", "(", ")", ")", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "'boolean'", "]", ")", ")", ";", "}", "else", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "'boolean'", ",", "'null'", "]", ")", ")", ";", "}", "}", "elseif", "(", "'integer'", "===", "$", "attribute", "->", "getPhpType", "(", ")", ")", "{", "if", "(", "!", "$", "attribute", "->", "getNull", "(", ")", ")", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "'integer'", "]", ")", ")", ";", "}", "else", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "'integer'", ",", "'null'", "]", ")", ")", ";", "}", "}", "elseif", "(", "'float'", "===", "$", "attribute", "->", "getPhpType", "(", ")", ")", "{", "if", "(", "!", "$", "attribute", "->", "getNull", "(", ")", ")", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "'float'", "]", ")", ")", ";", "}", "else", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "'float'", ",", "'null'", "]", ")", ")", ";", "}", "}", "elseif", "(", "'string'", "===", "$", "attribute", "->", "getPhpType", "(", ")", ")", "{", "if", "(", "'string'", "===", "$", "attribute", "->", "getType", "(", ")", ")", "{", "if", "(", "!", "$", "attribute", "->", "getNull", "(", ")", ")", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "'string'", "]", ")", ")", ";", "if", "(", "null", "!==", "$", "attribute", "->", "getMinSize", "(", ")", ")", "{", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "[", "]", "=", "'if (strlen($'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "') < '", ".", "$", "attribute", "->", "getMinSize", "(", ")", ".", "') {'", ";", "$", "lines", "[", "]", "=", "'throw new \\InvalidArgumentException(\\'On the attribute '", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "', the length of the string \\' . $'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "' . \\' is \\' . strlen($'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "') . \\' which is shorter than the minimum allowed ('", ".", "$", "attribute", "->", "getMinSize", "(", ")", ".", "').\\');'", ";", "$", "lines", "[", "]", "=", "'}'", ";", "}", "}", "else", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "'string'", ",", "'null'", "]", ")", ")", ";", "if", "(", "null", "!==", "$", "attribute", "->", "getMinSize", "(", ")", ")", "{", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "[", "]", "=", "'if (strlen($'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "') < '", ".", "$", "attribute", "->", "getMinSize", "(", ")", ".", "') {'", ";", "$", "lines", "[", "]", "=", "'throw new \\InvalidArgumentException(\\'On the attribute '", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "', the length of the string \\' . $'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "' . \\' is \\' . strlen($'", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ".", "') . \\' which is shorter than the minimum allowed ('", ".", "$", "attribute", "->", "getMinSize", "(", ")", ".", "').\\');'", ";", "$", "lines", "[", "]", "=", "'}'", ";", "}", "}", "}", "elseif", "(", "'text'", "===", "$", "attribute", "->", "getType", "(", ")", ")", "{", "if", "(", "!", "$", "attribute", "->", "getNull", "(", ")", ")", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "'string'", "]", ")", ")", ";", "}", "else", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "'string'", ",", "'null'", "]", ")", ")", ";", "}", "}", "}", "elseif", "(", "'OneToOne'", "===", "$", "attribute", "->", "getForeign", "(", ")", ")", "{", "if", "(", "$", "attribute", "->", "getOwnerSide", "(", ")", ")", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "[", "'object'", "=>", "$", "attribute", "->", "getForeignEntity", "(", ")", "->", "getName", "(", ")", "]", ",", "'null'", "]", ")", ")", ";", "}", "else", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "[", "'object'", "=>", "$", "attribute", "->", "getForeignEntity", "(", ")", "->", "getName", "(", ")", "]", ",", "'null'", "]", ")", ")", ";", "}", "}", "elseif", "(", "'ManyToOne'", "===", "$", "attribute", "->", "getForeign", "(", ")", ")", "{", "if", "(", "$", "attribute", "->", "getOwnerSide", "(", ")", ")", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "[", "'object'", "=>", "$", "attribute", "->", "getForeignEntity", "(", ")", "->", "getName", "(", ")", "]", ",", "'null'", "]", ")", ")", ";", "}", "else", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getTypeCheckLines", "(", "$", "attribute", ",", "[", "[", "'object'", "=>", "'Collection'", "]", ",", "'null'", "]", ")", ")", ";", "}", "}", "}", "return", "$", "lines", ";", "}" ]
<editor-fold desc="Setters">
[ "<editor", "-", "fold", "desc", "=", "Setters", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Templates/PHP/Entity1.php#L202-L271
j-d/draggy
src/Draggy/Autocode/Templates/PHP/Entity1.php
Entity1.getGetterCodeDocumentationLines
public function getGetterCodeDocumentationLines(PHPAttribute $attribute) { $lines = []; $lines[] = 'Get ' . $attribute->getLowerFullName(); $lines[] = ''; $lines[] = '@return ' . $attribute->getPhpAnnotationTypeBase(); return $lines; }
php
public function getGetterCodeDocumentationLines(PHPAttribute $attribute) { $lines = []; $lines[] = 'Get ' . $attribute->getLowerFullName(); $lines[] = ''; $lines[] = '@return ' . $attribute->getPhpAnnotationTypeBase(); return $lines; }
[ "public", "function", "getGetterCodeDocumentationLines", "(", "PHPAttribute", "$", "attribute", ")", "{", "$", "lines", "=", "[", "]", ";", "$", "lines", "[", "]", "=", "'Get '", ".", "$", "attribute", "->", "getLowerFullName", "(", ")", ";", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "[", "]", "=", "'@return '", ".", "$", "attribute", "->", "getPhpAnnotationTypeBase", "(", ")", ";", "return", "$", "lines", ";", "}" ]
<editor-fold desc="Getters">
[ "<editor", "-", "fold", "desc", "=", "Getters", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Templates/PHP/Entity1.php#L423-L432
j-d/draggy
src/Draggy/Autocode/Templates/PHP/Entity1.php
Entity1.getSingleAdderCodeDocumentationParameterLines
public function getSingleAdderCodeDocumentationParameterLines(PHPAttribute $attribute) { $lines = []; $lines[] = '@param ' . $attribute->getPhpSingleTypeBase() . ' $' . $attribute->getSingleName(); $lines[] = '@param bool $_allowRepeatedValues'; return $lines; }
php
public function getSingleAdderCodeDocumentationParameterLines(PHPAttribute $attribute) { $lines = []; $lines[] = '@param ' . $attribute->getPhpSingleTypeBase() . ' $' . $attribute->getSingleName(); $lines[] = '@param bool $_allowRepeatedValues'; return $lines; }
[ "public", "function", "getSingleAdderCodeDocumentationParameterLines", "(", "PHPAttribute", "$", "attribute", ")", "{", "$", "lines", "=", "[", "]", ";", "$", "lines", "[", "]", "=", "'@param '", ".", "$", "attribute", "->", "getPhpSingleTypeBase", "(", ")", ".", "' $'", ".", "$", "attribute", "->", "getSingleName", "(", ")", ";", "$", "lines", "[", "]", "=", "'@param bool $_allowRepeatedValues'", ";", "return", "$", "lines", ";", "}" ]
<editor-fold desc="Adders">
[ "<editor", "-", "fold", "desc", "=", "Adders", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Templates/PHP/Entity1.php#L453-L461
j-d/draggy
src/Draggy/Autocode/Templates/PHP/Entity1.php
Entity1.getSingleContainsCodeDocumentationLines
public function getSingleContainsCodeDocumentationLines(PHPAttribute $attribute) { $lines = []; $lines[] = 'Contains ' . $attribute->getSingleName(); $lines[] = ''; $lines[] = '@param ' . $attribute->getPhpSingleTypeBase() /*. ($attribute->getEntity()->getProject()->getBase() ? 'Base' : '')*/ . ' $' . $attribute->getSingleName(); $lines[] = ''; $lines[] = '@return bool'; return $lines; }
php
public function getSingleContainsCodeDocumentationLines(PHPAttribute $attribute) { $lines = []; $lines[] = 'Contains ' . $attribute->getSingleName(); $lines[] = ''; $lines[] = '@param ' . $attribute->getPhpSingleTypeBase() /*. ($attribute->getEntity()->getProject()->getBase() ? 'Base' : '')*/ . ' $' . $attribute->getSingleName(); $lines[] = ''; $lines[] = '@return bool'; return $lines; }
[ "public", "function", "getSingleContainsCodeDocumentationLines", "(", "PHPAttribute", "$", "attribute", ")", "{", "$", "lines", "=", "[", "]", ";", "$", "lines", "[", "]", "=", "'Contains '", ".", "$", "attribute", "->", "getSingleName", "(", ")", ";", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "[", "]", "=", "'@param '", ".", "$", "attribute", "->", "getPhpSingleTypeBase", "(", ")", "/*. ($attribute->getEntity()->getProject()->getBase() ? 'Base' : '')*/", ".", "' $'", ".", "$", "attribute", "->", "getSingleName", "(", ")", ";", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "[", "]", "=", "'@return bool'", ";", "return", "$", "lines", ";", "}" ]
<editor-fold desc="Contains">
[ "<editor", "-", "fold", "desc", "=", "Contains", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Templates/PHP/Entity1.php#L604-L615
j-d/draggy
src/Draggy/Autocode/Templates/PHP/Entity1.php
Entity1.getSingleRemoverCodeDocumentationParameterLines
public function getSingleRemoverCodeDocumentationParameterLines(PHPAttribute $attribute) { $lines = []; $lines[] = '@param ' . $attribute->getPhpSingleTypeBase() /*. ($attribute->getEntity()->getProject()->getBase() ? 'Base' : '')*/ . ' $' . $attribute->getSingleName(); return $lines; }
php
public function getSingleRemoverCodeDocumentationParameterLines(PHPAttribute $attribute) { $lines = []; $lines[] = '@param ' . $attribute->getPhpSingleTypeBase() /*. ($attribute->getEntity()->getProject()->getBase() ? 'Base' : '')*/ . ' $' . $attribute->getSingleName(); return $lines; }
[ "public", "function", "getSingleRemoverCodeDocumentationParameterLines", "(", "PHPAttribute", "$", "attribute", ")", "{", "$", "lines", "=", "[", "]", ";", "$", "lines", "[", "]", "=", "'@param '", ".", "$", "attribute", "->", "getPhpSingleTypeBase", "(", ")", "/*. ($attribute->getEntity()->getProject()->getBase() ? 'Base' : '')*/", ".", "' $'", ".", "$", "attribute", "->", "getSingleName", "(", ")", ";", "return", "$", "lines", ";", "}" ]
<editor-fold desc="Removers">
[ "<editor", "-", "fold", "desc", "=", "Removers", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Templates/PHP/Entity1.php#L678-L685
j-d/draggy
src/Draggy/Autocode/Templates/PHP/Entity1.php
Entity1.getSetterGetterLines
public function getSetterGetterLines(PHPAttribute $attribute) { $lines = []; if ($attribute->getSetter()) { $lines = array_merge($lines, $this->getSetterCodeLines($attribute)); } if ('Collection' === $attribute->getPhpParameterType() || 'array' === $attribute->getType()) { if (0 !== count($lines)) { $lines[] = ''; } $lines = array_merge($lines, $this->getSingleAdderCodeLines($attribute)); $lines[] = ''; $lines = array_merge($lines, $this->getMultipleAdderCodeLines($attribute)); $lines[] = ''; $lines = array_merge($lines, $this->getSingleContainsCodeLines($attribute)); $lines[] = ''; $lines = array_merge($lines, $this->getMultipleContainsCodeLines($attribute)); $lines[] = ''; $lines = array_merge($lines, $this->getSingleRemoverCodeLines($attribute)); $lines[] = ''; $lines = array_merge($lines, $this->getMultipleRemoverCodeLines($attribute)); } if ($attribute->getGetter()) { if (0 !== count($lines)) { $lines[] = ''; } $lines = array_merge($lines, $this->getGetterCodeLines($attribute)); } return $lines; }
php
public function getSetterGetterLines(PHPAttribute $attribute) { $lines = []; if ($attribute->getSetter()) { $lines = array_merge($lines, $this->getSetterCodeLines($attribute)); } if ('Collection' === $attribute->getPhpParameterType() || 'array' === $attribute->getType()) { if (0 !== count($lines)) { $lines[] = ''; } $lines = array_merge($lines, $this->getSingleAdderCodeLines($attribute)); $lines[] = ''; $lines = array_merge($lines, $this->getMultipleAdderCodeLines($attribute)); $lines[] = ''; $lines = array_merge($lines, $this->getSingleContainsCodeLines($attribute)); $lines[] = ''; $lines = array_merge($lines, $this->getMultipleContainsCodeLines($attribute)); $lines[] = ''; $lines = array_merge($lines, $this->getSingleRemoverCodeLines($attribute)); $lines[] = ''; $lines = array_merge($lines, $this->getMultipleRemoverCodeLines($attribute)); } if ($attribute->getGetter()) { if (0 !== count($lines)) { $lines[] = ''; } $lines = array_merge($lines, $this->getGetterCodeLines($attribute)); } return $lines; }
[ "public", "function", "getSetterGetterLines", "(", "PHPAttribute", "$", "attribute", ")", "{", "$", "lines", "=", "[", "]", ";", "if", "(", "$", "attribute", "->", "getSetter", "(", ")", ")", "{", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getSetterCodeLines", "(", "$", "attribute", ")", ")", ";", "}", "if", "(", "'Collection'", "===", "$", "attribute", "->", "getPhpParameterType", "(", ")", "||", "'array'", "===", "$", "attribute", "->", "getType", "(", ")", ")", "{", "if", "(", "0", "!==", "count", "(", "$", "lines", ")", ")", "{", "$", "lines", "[", "]", "=", "''", ";", "}", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getSingleAdderCodeLines", "(", "$", "attribute", ")", ")", ";", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getMultipleAdderCodeLines", "(", "$", "attribute", ")", ")", ";", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getSingleContainsCodeLines", "(", "$", "attribute", ")", ")", ";", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getMultipleContainsCodeLines", "(", "$", "attribute", ")", ")", ";", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getSingleRemoverCodeLines", "(", "$", "attribute", ")", ")", ";", "$", "lines", "[", "]", "=", "''", ";", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getMultipleRemoverCodeLines", "(", "$", "attribute", ")", ")", ";", "}", "if", "(", "$", "attribute", "->", "getGetter", "(", ")", ")", "{", "if", "(", "0", "!==", "count", "(", "$", "lines", ")", ")", "{", "$", "lines", "[", "]", "=", "''", ";", "}", "$", "lines", "=", "array_merge", "(", "$", "lines", ",", "$", "this", "->", "getGetterCodeLines", "(", "$", "attribute", ")", ")", ";", "}", "return", "$", "lines", ";", "}" ]
</editor-fold>
[ "<", "/", "editor", "-", "fold", ">" ]
train
https://github.com/j-d/draggy/blob/97ffc66e1aacb5f685d7aac5251c4abb8888d4bb/src/Draggy/Autocode/Templates/PHP/Entity1.php#L825-L870
nabab/bbn
src/bbn/file.php
file.get_size
public function get_size() { if ( $this->file && $this->size === 0 ){ $this->size = filesize($this->file); } return $this->size; }
php
public function get_size() { if ( $this->file && $this->size === 0 ){ $this->size = filesize($this->file); } return $this->size; }
[ "public", "function", "get_size", "(", ")", "{", "if", "(", "$", "this", "->", "file", "&&", "$", "this", "->", "size", "===", "0", ")", "{", "$", "this", "->", "size", "=", "filesize", "(", "$", "this", "->", "file", ")", ";", "}", "return", "$", "this", "->", "size", ";", "}" ]
Return the filesize in byte. ```php $file = new bbn\file('C:/Test/file.txt'); bbn\x::dump($file->get_size()); // (int) 314 ``` @return int
[ "Return", "the", "filesize", "in", "byte", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file.php#L126-L132
nabab/bbn
src/bbn/file.php
file.get_extension
public function get_extension() { if ( $this->name ){ if ( !isset($this->ext) ){ if ( strpos($this->name, '.') !== false ){ $p = str::file_ext($this->name, 1); $this->ext = $p[1]; $this->title = $p[0]; } else{ $this->ext = ''; $this->title = substr($this->name,-1) === '/' ? substr($this->name,0,-1) : $this->name; } } return $this->ext; } return false; }
php
public function get_extension() { if ( $this->name ){ if ( !isset($this->ext) ){ if ( strpos($this->name, '.') !== false ){ $p = str::file_ext($this->name, 1); $this->ext = $p[1]; $this->title = $p[0]; } else{ $this->ext = ''; $this->title = substr($this->name,-1) === '/' ? substr($this->name,0,-1) : $this->name; } } return $this->ext; } return false; }
[ "public", "function", "get_extension", "(", ")", "{", "if", "(", "$", "this", "->", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "ext", ")", ")", "{", "if", "(", "strpos", "(", "$", "this", "->", "name", ",", "'.'", ")", "!==", "false", ")", "{", "$", "p", "=", "str", "::", "file_ext", "(", "$", "this", "->", "name", ",", "1", ")", ";", "$", "this", "->", "ext", "=", "$", "p", "[", "1", "]", ";", "$", "this", "->", "title", "=", "$", "p", "[", "0", "]", ";", "}", "else", "{", "$", "this", "->", "ext", "=", "''", ";", "$", "this", "->", "title", "=", "substr", "(", "$", "this", "->", "name", ",", "-", "1", ")", "===", "'/'", "?", "substr", "(", "$", "this", "->", "name", ",", "0", ",", "-", "1", ")", ":", "$", "this", "->", "name", ";", "}", "}", "return", "$", "this", "->", "ext", ";", "}", "return", "false", ";", "}" ]
Return the extension of the file. ```php $file = new file('C:/Test/file.txt'); bbn\x::dump($file->get_extension()); //(string) 'txt' ``` @return string|false
[ "Return", "the", "extension", "of", "the", "file", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file.php#L163-L180
nabab/bbn
src/bbn/file.php
file.make
protected function make() { if ( !$this->file && strpos($this->path,'http://') === 0 ){ $d = getcwd(); chdir(__DIR__); chdir('../tmp'); $f = tempnam('.','image'); try{ $c = file_get_contents($this->path.$this->name); if ( file_put_contents($f, $c) ){ if ( substr($this->name,-1) == '/' ){ $this->name = substr($this->name,0,-1); } chmod($f, 0644); $this->file = $f; $this->path = getcwd(); } else{ $this->error = 'Impossible to get the file '.$this->path.$this->name; } } catch ( Error $e ) { $this->error = 'Impossible to get the file '.$this->path.$this->name; } chdir($d); } return $this; }
php
protected function make() { if ( !$this->file && strpos($this->path,'http://') === 0 ){ $d = getcwd(); chdir(__DIR__); chdir('../tmp'); $f = tempnam('.','image'); try{ $c = file_get_contents($this->path.$this->name); if ( file_put_contents($f, $c) ){ if ( substr($this->name,-1) == '/' ){ $this->name = substr($this->name,0,-1); } chmod($f, 0644); $this->file = $f; $this->path = getcwd(); } else{ $this->error = 'Impossible to get the file '.$this->path.$this->name; } } catch ( Error $e ) { $this->error = 'Impossible to get the file '.$this->path.$this->name; } chdir($d); } return $this; }
[ "protected", "function", "make", "(", ")", "{", "if", "(", "!", "$", "this", "->", "file", "&&", "strpos", "(", "$", "this", "->", "path", ",", "'http://'", ")", "===", "0", ")", "{", "$", "d", "=", "getcwd", "(", ")", ";", "chdir", "(", "__DIR__", ")", ";", "chdir", "(", "'../tmp'", ")", ";", "$", "f", "=", "tempnam", "(", "'.'", ",", "'image'", ")", ";", "try", "{", "$", "c", "=", "file_get_contents", "(", "$", "this", "->", "path", ".", "$", "this", "->", "name", ")", ";", "if", "(", "file_put_contents", "(", "$", "f", ",", "$", "c", ")", ")", "{", "if", "(", "substr", "(", "$", "this", "->", "name", ",", "-", "1", ")", "==", "'/'", ")", "{", "$", "this", "->", "name", "=", "substr", "(", "$", "this", "->", "name", ",", "0", ",", "-", "1", ")", ";", "}", "chmod", "(", "$", "f", ",", "0644", ")", ";", "$", "this", "->", "file", "=", "$", "f", ";", "$", "this", "->", "path", "=", "getcwd", "(", ")", ";", "}", "else", "{", "$", "this", "->", "error", "=", "'Impossible to get the file '", ".", "$", "this", "->", "path", ".", "$", "this", "->", "name", ";", "}", "}", "catch", "(", "Error", "$", "e", ")", "{", "$", "this", "->", "error", "=", "'Impossible to get the file '", ".", "$", "this", "->", "path", ".", "$", "this", "->", "name", ";", "}", "chdir", "(", "$", "d", ")", ";", "}", "return", "$", "this", ";", "}" ]
Creates a temporary file in tmp directory. @todo of adjusting @return file
[ "Creates", "a", "temporary", "file", "in", "tmp", "directory", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file.php#L188-L214
nabab/bbn
src/bbn/file.php
file.download
public function download() { if ( $this->file ){ if ( !$this->size ){ $this->get_size(); } if ( $this->size && ($handle = fopen($this->file, 'r')) ){ header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.$this->name.'"'); while ( !feof($handle) ){ echo fread($handle, 65536); } fclose($handle); } else{ die('Impossible to read the file '.$this->name); } } return $this; }
php
public function download() { if ( $this->file ){ if ( !$this->size ){ $this->get_size(); } if ( $this->size && ($handle = fopen($this->file, 'r')) ){ header('Content-type: application/octet-stream'); header('Content-Disposition: attachment; filename="'.$this->name.'"'); while ( !feof($handle) ){ echo fread($handle, 65536); } fclose($handle); } else{ die('Impossible to read the file '.$this->name); } } return $this; }
[ "public", "function", "download", "(", ")", "{", "if", "(", "$", "this", "->", "file", ")", "{", "if", "(", "!", "$", "this", "->", "size", ")", "{", "$", "this", "->", "get_size", "(", ")", ";", "}", "if", "(", "$", "this", "->", "size", "&&", "(", "$", "handle", "=", "fopen", "(", "$", "this", "->", "file", ",", "'r'", ")", ")", ")", "{", "header", "(", "'Content-type: application/octet-stream'", ")", ";", "header", "(", "'Content-Disposition: attachment; filename=\"'", ".", "$", "this", "->", "name", ".", "'\"'", ")", ";", "while", "(", "!", "feof", "(", "$", "handle", ")", ")", "{", "echo", "fread", "(", "$", "handle", ",", "65536", ")", ";", "}", "fclose", "(", "$", "handle", ")", ";", "}", "else", "{", "die", "(", "'Impossible to read the file '", ".", "$", "this", "->", "name", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Downloads the file. At the end of the script the user will be invited to choose the file's destination. If the file doesn't exist return an object with parameter file = null. ```php $f = new \bbn\file('C:/Test/file.png'); $f->download(); ``` @return file
[ "Downloads", "the", "file", ".", "At", "the", "end", "of", "the", "script", "the", "user", "will", "be", "invited", "to", "choose", "the", "file", "s", "destination", ".", "If", "the", "file", "doesn", "t", "exist", "return", "an", "object", "with", "parameter", "file", "=", "null", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file.php#L226-L245
nabab/bbn
src/bbn/file.php
file.delete
public function delete() { if ( $this->file ){ unlink($this->file); } $this->file = false; return $this; }
php
public function delete() { if ( $this->file ){ unlink($this->file); } $this->file = false; return $this; }
[ "public", "function", "delete", "(", ")", "{", "if", "(", "$", "this", "->", "file", ")", "{", "unlink", "(", "$", "this", "->", "file", ")", ";", "}", "$", "this", "->", "file", "=", "false", ";", "return", "$", "this", ";", "}" ]
Deletes the file. ```php bbn\x::hdump( is_file('C:/Test/file.txt') ); // (bool) true $file = new file('C:/Test/file.txt'); $file->delete(); bbn\x::hdump( is_file('C:/Test/file.txt') ); // (bool) false ``` @return file
[ "Deletes", "the", "file", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file.php#L280-L287
nabab/bbn
src/bbn/file.php
file.save
public function save($dest='./') { $new_name = false; if ( substr($dest,-1) === '/' ){ if ( is_dir($dest) ){ $new_name = 0; } } else if ( is_dir($dest) ){ $dest .= '/'; $new_name = 0; } else if ( is_dir(substr($dest,0,strrpos($dest,'/'))) ){ $new_name = 1; } if ( $new_name !== false ){ if ( $new_name === 0 ){ $dest .= $this->name; } if ( null !== $_FILES ){ move_uploaded_file($this->file,$dest); $this->file = $dest; $this->uploaded = 1; } else{ copy($this->file, $dest); } } return $this; }
php
public function save($dest='./') { $new_name = false; if ( substr($dest,-1) === '/' ){ if ( is_dir($dest) ){ $new_name = 0; } } else if ( is_dir($dest) ){ $dest .= '/'; $new_name = 0; } else if ( is_dir(substr($dest,0,strrpos($dest,'/'))) ){ $new_name = 1; } if ( $new_name !== false ){ if ( $new_name === 0 ){ $dest .= $this->name; } if ( null !== $_FILES ){ move_uploaded_file($this->file,$dest); $this->file = $dest; $this->uploaded = 1; } else{ copy($this->file, $dest); } } return $this; }
[ "public", "function", "save", "(", "$", "dest", "=", "'./'", ")", "{", "$", "new_name", "=", "false", ";", "if", "(", "substr", "(", "$", "dest", ",", "-", "1", ")", "===", "'/'", ")", "{", "if", "(", "is_dir", "(", "$", "dest", ")", ")", "{", "$", "new_name", "=", "0", ";", "}", "}", "else", "if", "(", "is_dir", "(", "$", "dest", ")", ")", "{", "$", "dest", ".=", "'/'", ";", "$", "new_name", "=", "0", ";", "}", "else", "if", "(", "is_dir", "(", "substr", "(", "$", "dest", ",", "0", ",", "strrpos", "(", "$", "dest", ",", "'/'", ")", ")", ")", ")", "{", "$", "new_name", "=", "1", ";", "}", "if", "(", "$", "new_name", "!==", "false", ")", "{", "if", "(", "$", "new_name", "===", "0", ")", "{", "$", "dest", ".=", "$", "this", "->", "name", ";", "}", "if", "(", "null", "!==", "$", "_FILES", ")", "{", "move_uploaded_file", "(", "$", "this", "->", "file", ",", "$", "dest", ")", ";", "$", "this", "->", "file", "=", "$", "dest", ";", "$", "this", "->", "uploaded", "=", "1", ";", "}", "else", "{", "copy", "(", "$", "this", "->", "file", ",", "$", "dest", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
That feature saves the file as a parameter, and accepts a string that contains the path where to save. ```php $file->save('/home/user/desktop/'); ``` @param string $dest @return file
[ "That", "feature", "saves", "the", "file", "as", "a", "parameter", "and", "accepts", "a", "string", "that", "contains", "the", "path", "where", "to", "save", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file.php#L299-L328
PHPPowertools/HTML5
src/PowerTools/HTML5/Inputstream/String.php
HTML5_Inputstream_String.currentLine
public function currentLine() { if (empty($this->EOF) || $this->char == 0) { return 1; } // Add one to $this->char because we want the number for the next // byte to be processed. return substr_count($this->data, "\n", 0, min($this->char, $this->EOF)) + 1; }
php
public function currentLine() { if (empty($this->EOF) || $this->char == 0) { return 1; } // Add one to $this->char because we want the number for the next // byte to be processed. return substr_count($this->data, "\n", 0, min($this->char, $this->EOF)) + 1; }
[ "public", "function", "currentLine", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "EOF", ")", "||", "$", "this", "->", "char", "==", "0", ")", "{", "return", "1", ";", "}", "// Add one to $this->char because we want the number for the next", "// byte to be processed.", "return", "substr_count", "(", "$", "this", "->", "data", ",", "\"\\n\"", ",", "0", ",", "min", "(", "$", "this", "->", "char", ",", "$", "this", "->", "EOF", ")", ")", "+", "1", ";", "}" ]
Returns the current line that the tokenizer is at.
[ "Returns", "the", "current", "line", "that", "the", "tokenizer", "is", "at", "." ]
train
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Inputstream/String.php#L195-L202
PHPPowertools/HTML5
src/PowerTools/HTML5/Inputstream/String.php
HTML5_Inputstream_String.columnOffset
public function columnOffset() { // Short circuit for the first char. if ($this->char == 0) { return 0; } // strrpos is weird, and the offset needs to be negative for what we // want (i.e., the last \n before $this->char). This needs to not have // one (to make it point to the next character, the one we want the // position of) added to it because strrpos's behaviour includes the // final offset byte. $backwardFrom = $this->char - 1 - strlen($this->data); $lastLine = strrpos($this->data, "\n", $backwardFrom); // However, for here we want the length up until the next byte to be // processed, so add one to the current byte ($this->char). if ($lastLine !== false) { $findLengthOf = substr($this->data, $lastLine + 1, $this->char - 1 - $lastLine); } else { // After a newline. $findLengthOf = substr($this->data, 0, $this->char); } return HTML5_Parser_UTF8Utils::countChars($findLengthOf); }
php
public function columnOffset() { // Short circuit for the first char. if ($this->char == 0) { return 0; } // strrpos is weird, and the offset needs to be negative for what we // want (i.e., the last \n before $this->char). This needs to not have // one (to make it point to the next character, the one we want the // position of) added to it because strrpos's behaviour includes the // final offset byte. $backwardFrom = $this->char - 1 - strlen($this->data); $lastLine = strrpos($this->data, "\n", $backwardFrom); // However, for here we want the length up until the next byte to be // processed, so add one to the current byte ($this->char). if ($lastLine !== false) { $findLengthOf = substr($this->data, $lastLine + 1, $this->char - 1 - $lastLine); } else { // After a newline. $findLengthOf = substr($this->data, 0, $this->char); } return HTML5_Parser_UTF8Utils::countChars($findLengthOf); }
[ "public", "function", "columnOffset", "(", ")", "{", "// Short circuit for the first char.", "if", "(", "$", "this", "->", "char", "==", "0", ")", "{", "return", "0", ";", "}", "// strrpos is weird, and the offset needs to be negative for what we", "// want (i.e., the last \\n before $this->char). This needs to not have", "// one (to make it point to the next character, the one we want the", "// position of) added to it because strrpos's behaviour includes the", "// final offset byte.", "$", "backwardFrom", "=", "$", "this", "->", "char", "-", "1", "-", "strlen", "(", "$", "this", "->", "data", ")", ";", "$", "lastLine", "=", "strrpos", "(", "$", "this", "->", "data", ",", "\"\\n\"", ",", "$", "backwardFrom", ")", ";", "// However, for here we want the length up until the next byte to be", "// processed, so add one to the current byte ($this->char).", "if", "(", "$", "lastLine", "!==", "false", ")", "{", "$", "findLengthOf", "=", "substr", "(", "$", "this", "->", "data", ",", "$", "lastLine", "+", "1", ",", "$", "this", "->", "char", "-", "1", "-", "$", "lastLine", ")", ";", "}", "else", "{", "// After a newline.", "$", "findLengthOf", "=", "substr", "(", "$", "this", "->", "data", ",", "0", ",", "$", "this", "->", "char", ")", ";", "}", "return", "HTML5_Parser_UTF8Utils", "::", "countChars", "(", "$", "findLengthOf", ")", ";", "}" ]
Returns the current column of the current line that the tokenizer is at. Newlines are column 0. The first char after a newline is column 1. @return int The column number.
[ "Returns", "the", "current", "column", "of", "the", "current", "line", "that", "the", "tokenizer", "is", "at", "." ]
train
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Inputstream/String.php#L220-L243
PHPPowertools/HTML5
src/PowerTools/HTML5/Inputstream/String.php
HTML5_Inputstream_String.unconsume
public function unconsume($howMany = 1) { if (($this->char - $howMany) >= 0) { $this->char = $this->char - $howMany; } }
php
public function unconsume($howMany = 1) { if (($this->char - $howMany) >= 0) { $this->char = $this->char - $howMany; } }
[ "public", "function", "unconsume", "(", "$", "howMany", "=", "1", ")", "{", "if", "(", "(", "$", "this", "->", "char", "-", "$", "howMany", ")", ">=", "0", ")", "{", "$", "this", "->", "char", "=", "$", "this", "->", "char", "-", "$", "howMany", ";", "}", "}" ]
Unconsume characters. @param int $howMany The number of characters to unconsume.
[ "Unconsume", "characters", "." ]
train
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Inputstream/String.php#L380-L384
PHPPowertools/HTML5
src/PowerTools/HTML5/Inputstream/String.php
HTML5_Inputstream_String.peek
public function peek() { if (($this->char + 1) <= $this->EOF) { return $this->data[$this->char + 1]; } return false; }
php
public function peek() { if (($this->char + 1) <= $this->EOF) { return $this->data[$this->char + 1]; } return false; }
[ "public", "function", "peek", "(", ")", "{", "if", "(", "(", "$", "this", "->", "char", "+", "1", ")", "<=", "$", "this", "->", "EOF", ")", "{", "return", "$", "this", "->", "data", "[", "$", "this", "->", "char", "+", "1", "]", ";", "}", "return", "false", ";", "}" ]
Look ahead without moving cursor.
[ "Look", "ahead", "without", "moving", "cursor", "." ]
train
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Inputstream/String.php#L389-L395
spiral-modules/listing
source/Listing/InputState.php
InputState.isActive
public function isActive() { if (empty($this->source)) { return false; } $input = $this->input->getValue($this->source, "{$this->namespace}"); return !empty($input); }
php
public function isActive() { if (empty($this->source)) { return false; } $input = $this->input->getValue($this->source, "{$this->namespace}"); return !empty($input); }
[ "public", "function", "isActive", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "source", ")", ")", "{", "return", "false", ";", "}", "$", "input", "=", "$", "this", "->", "input", "->", "getValue", "(", "$", "this", "->", "source", ",", "\"{$this->namespace}\"", ")", ";", "return", "!", "empty", "(", "$", "input", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/InputState.php#L74-L83
spiral-modules/listing
source/Listing/InputState.php
InputState.activeFilters
public function activeFilters() { $filters = $this->input->getValue($this->source, "{$this->namespace}." . self::FILTERS); if (empty($filters) || !is_array($filters)) { $filters = []; } return array_values($filters); }
php
public function activeFilters() { $filters = $this->input->getValue($this->source, "{$this->namespace}." . self::FILTERS); if (empty($filters) || !is_array($filters)) { $filters = []; } return array_values($filters); }
[ "public", "function", "activeFilters", "(", ")", "{", "$", "filters", "=", "$", "this", "->", "input", "->", "getValue", "(", "$", "this", "->", "source", ",", "\"{$this->namespace}.\"", ".", "self", "::", "FILTERS", ")", ";", "if", "(", "empty", "(", "$", "filters", ")", "||", "!", "is_array", "(", "$", "filters", ")", ")", "{", "$", "filters", "=", "[", "]", ";", "}", "return", "array_values", "(", "$", "filters", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/InputState.php#L107-L116
spiral-modules/listing
source/Listing/InputState.php
InputState.getValue
public function getValue($filter, $default = null) { $value = $this->input->getValue( $this->source, "{$this->namespace}." . self::FILTER_VALUES . '.' . $filter ); if (null == $value) { return $default; } return $value; }
php
public function getValue($filter, $default = null) { $value = $this->input->getValue( $this->source, "{$this->namespace}." . self::FILTER_VALUES . '.' . $filter ); if (null == $value) { return $default; } return $value; }
[ "public", "function", "getValue", "(", "$", "filter", ",", "$", "default", "=", "null", ")", "{", "$", "value", "=", "$", "this", "->", "input", "->", "getValue", "(", "$", "this", "->", "source", ",", "\"{$this->namespace}.\"", ".", "self", "::", "FILTER_VALUES", ".", "'.'", ".", "$", "filter", ")", ";", "if", "(", "null", "==", "$", "value", ")", "{", "return", "$", "default", ";", "}", "return", "$", "value", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/InputState.php#L121-L133
spiral-modules/listing
source/Listing/InputState.php
InputState.activeSorter
public function activeSorter() { $sorter = $this->input->getValue($this->source, "{$this->namespace}." . self::SORTER); if (empty($sorter)) { $sorter = 'id'; } return $sorter; }
php
public function activeSorter() { $sorter = $this->input->getValue($this->source, "{$this->namespace}." . self::SORTER); if (empty($sorter)) { $sorter = 'id'; } return $sorter; }
[ "public", "function", "activeSorter", "(", ")", "{", "$", "sorter", "=", "$", "this", "->", "input", "->", "getValue", "(", "$", "this", "->", "source", ",", "\"{$this->namespace}.\"", ".", "self", "::", "SORTER", ")", ";", "if", "(", "empty", "(", "$", "sorter", ")", ")", "{", "$", "sorter", "=", "'id'", ";", "}", "return", "$", "sorter", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/InputState.php#L138-L146
spiral-modules/listing
source/Listing/InputState.php
InputState.sortDirection
public function sortDirection() { $direction = $this->input->getValue($this->source, "{$this->namespace}." . self::DIRECTION); if (strtolower($direction) == 'desc' || $direction == -1) { return DirectionalSorter::DESC; } return DirectionalSorter::ASC; }
php
public function sortDirection() { $direction = $this->input->getValue($this->source, "{$this->namespace}." . self::DIRECTION); if (strtolower($direction) == 'desc' || $direction == -1) { return DirectionalSorter::DESC; } return DirectionalSorter::ASC; }
[ "public", "function", "sortDirection", "(", ")", "{", "$", "direction", "=", "$", "this", "->", "input", "->", "getValue", "(", "$", "this", "->", "source", ",", "\"{$this->namespace}.\"", ".", "self", "::", "DIRECTION", ")", ";", "if", "(", "strtolower", "(", "$", "direction", ")", "==", "'desc'", "||", "$", "direction", "==", "-", "1", ")", "{", "return", "DirectionalSorter", "::", "DESC", ";", "}", "return", "DirectionalSorter", "::", "ASC", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/spiral-modules/listing/blob/89abe8939ce91cbf61b51b99e93ce1e57c8af83c/source/Listing/InputState.php#L151-L160
surebert/surebert-framework
src/sb/ICalendar/Event.php
Event.send
public function send() { $subject = 'EVENT'; if ($this->method == 'CANCEL') { $subject = 'CANCELED ' . $subject; if (empty($this->uid)) { throw(new \Exception('Must set uid to cancel an event.')); } } if (!empty($this->summary)) { $subject .= ': ' . substr($this->summary, 0, 20) . '...'; } $to = '"' . $this->organizer->dname . '" <' . $this->organizer->email . '>'; $mail = new \sb\Email($to, $subject, $this->summary, $to); $attendee_emails = Array(); foreach ($this->attendees as $attendee) { $attendee_emails[] = '"' . $attendee->dname . '" <' . $attendee->email . '>'; } $mail->cc = $attendee_emails; $mail->addIcalendarEvent($this); return $mail->send(); }
php
public function send() { $subject = 'EVENT'; if ($this->method == 'CANCEL') { $subject = 'CANCELED ' . $subject; if (empty($this->uid)) { throw(new \Exception('Must set uid to cancel an event.')); } } if (!empty($this->summary)) { $subject .= ': ' . substr($this->summary, 0, 20) . '...'; } $to = '"' . $this->organizer->dname . '" <' . $this->organizer->email . '>'; $mail = new \sb\Email($to, $subject, $this->summary, $to); $attendee_emails = Array(); foreach ($this->attendees as $attendee) { $attendee_emails[] = '"' . $attendee->dname . '" <' . $attendee->email . '>'; } $mail->cc = $attendee_emails; $mail->addIcalendarEvent($this); return $mail->send(); }
[ "public", "function", "send", "(", ")", "{", "$", "subject", "=", "'EVENT'", ";", "if", "(", "$", "this", "->", "method", "==", "'CANCEL'", ")", "{", "$", "subject", "=", "'CANCELED '", ".", "$", "subject", ";", "if", "(", "empty", "(", "$", "this", "->", "uid", ")", ")", "{", "throw", "(", "new", "\\", "Exception", "(", "'Must set uid to cancel an event.'", ")", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "summary", ")", ")", "{", "$", "subject", ".=", "': '", ".", "substr", "(", "$", "this", "->", "summary", ",", "0", ",", "20", ")", ".", "'...'", ";", "}", "$", "to", "=", "'\"'", ".", "$", "this", "->", "organizer", "->", "dname", ".", "'\" <'", ".", "$", "this", "->", "organizer", "->", "email", ".", "'>'", ";", "$", "mail", "=", "new", "\\", "sb", "\\", "Email", "(", "$", "to", ",", "$", "subject", ",", "$", "this", "->", "summary", ",", "$", "to", ")", ";", "$", "attendee_emails", "=", "Array", "(", ")", ";", "foreach", "(", "$", "this", "->", "attendees", "as", "$", "attendee", ")", "{", "$", "attendee_emails", "[", "]", "=", "'\"'", ".", "$", "attendee", "->", "dname", ".", "'\" <'", ".", "$", "attendee", "->", "email", ".", "'>'", ";", "}", "$", "mail", "->", "cc", "=", "$", "attendee_emails", ";", "$", "mail", "->", "addIcalendarEvent", "(", "$", "this", ")", ";", "return", "$", "mail", "->", "send", "(", ")", ";", "}" ]
Send via email the subject is the first 20 chars of the summary, the message is the summary. The email is sent to the organizer's email, The attendees all cc'd @return boolean
[ "Send", "via", "email", "the", "subject", "is", "the", "first", "20", "chars", "of", "the", "summary", "the", "message", "is", "the", "summary", ".", "The", "email", "is", "sent", "to", "the", "organizer", "s", "email", "The", "attendees", "all", "cc", "d" ]
train
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/ICalendar/Event.php#L174-L200
inhere/php-librarys
src/Helpers/ArrayHelper.php
ArrayHelper.valueTrim
public static function valueTrim(array $data) { if (is_scalar($data)) { return trim($data); } array_walk_recursive($data, function (&$value) { $value = trim($value); }); return $data; }
php
public static function valueTrim(array $data) { if (is_scalar($data)) { return trim($data); } array_walk_recursive($data, function (&$value) { $value = trim($value); }); return $data; }
[ "public", "static", "function", "valueTrim", "(", "array", "$", "data", ")", "{", "if", "(", "is_scalar", "(", "$", "data", ")", ")", "{", "return", "trim", "(", "$", "data", ")", ";", "}", "array_walk_recursive", "(", "$", "data", ",", "function", "(", "&", "$", "value", ")", "{", "$", "value", "=", "trim", "(", "$", "value", ")", ";", "}", ")", ";", "return", "$", "data", ";", "}" ]
清理数组值的空白 @param array $data @return array|string
[ "清理数组值的空白" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/ArrayHelper.php#L184-L195
inhere/php-librarys
src/Helpers/ArrayHelper.php
ArrayHelper.changeValueCase
public static function changeValueCase($arr, $toUpper = 1): array { $function = $toUpper ? 'strtoupper' : 'strtolower'; $newArr = array(); //格式化后的数组 foreach ($arr as $k => $v) { if (\is_array($v)) { $newArr[$k] = self::changeValueCase($v, $toUpper); } else { $v = trim($v); $newArr[$k] = $function($v); } } return $newArr; }
php
public static function changeValueCase($arr, $toUpper = 1): array { $function = $toUpper ? 'strtoupper' : 'strtolower'; $newArr = array(); //格式化后的数组 foreach ($arr as $k => $v) { if (\is_array($v)) { $newArr[$k] = self::changeValueCase($v, $toUpper); } else { $v = trim($v); $newArr[$k] = $function($v); } } return $newArr; }
[ "public", "static", "function", "changeValueCase", "(", "$", "arr", ",", "$", "toUpper", "=", "1", ")", ":", "array", "{", "$", "function", "=", "$", "toUpper", "?", "'strtoupper'", ":", "'strtolower'", ";", "$", "newArr", "=", "array", "(", ")", ";", "//格式化后的数组", "foreach", "(", "$", "arr", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "\\", "is_array", "(", "$", "v", ")", ")", "{", "$", "newArr", "[", "$", "k", "]", "=", "self", "::", "changeValueCase", "(", "$", "v", ",", "$", "toUpper", ")", ";", "}", "else", "{", "$", "v", "=", "trim", "(", "$", "v", ")", ";", "$", "newArr", "[", "$", "k", "]", "=", "$", "function", "(", "$", "v", ")", ";", "}", "}", "return", "$", "newArr", ";", "}" ]
将数组中的值全部转为大写或小写 @param array $arr @param int $toUpper 1 值大写 0 值小写 @return array
[ "将数组中的值全部转为大写或小写" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/ArrayHelper.php#L232-L247
inhere/php-librarys
src/Helpers/ArrayHelper.php
ArrayHelper.getByPath
public static function getByPath($data, $path, $default = null, $separator = '.') { if (isset($data[$path])) { return $data[$path]; } $nodes = Str::toArray($path, $separator); if (!$nodes) { return $default; } $dataTmp = $data; foreach ($nodes as $arg) { if (\is_object($dataTmp) && isset($dataTmp->$arg)) { $dataTmp = $dataTmp->$arg; } elseif ( (\is_array($dataTmp) || $dataTmp instanceof \ArrayAccess) && isset($dataTmp[$arg]) ) { $dataTmp = $dataTmp[$arg]; } else { return $default; } } return $dataTmp; }
php
public static function getByPath($data, $path, $default = null, $separator = '.') { if (isset($data[$path])) { return $data[$path]; } $nodes = Str::toArray($path, $separator); if (!$nodes) { return $default; } $dataTmp = $data; foreach ($nodes as $arg) { if (\is_object($dataTmp) && isset($dataTmp->$arg)) { $dataTmp = $dataTmp->$arg; } elseif ( (\is_array($dataTmp) || $dataTmp instanceof \ArrayAccess) && isset($dataTmp[$arg]) ) { $dataTmp = $dataTmp[$arg]; } else { return $default; } } return $dataTmp; }
[ "public", "static", "function", "getByPath", "(", "$", "data", ",", "$", "path", ",", "$", "default", "=", "null", ",", "$", "separator", "=", "'.'", ")", "{", "if", "(", "isset", "(", "$", "data", "[", "$", "path", "]", ")", ")", "{", "return", "$", "data", "[", "$", "path", "]", ";", "}", "$", "nodes", "=", "Str", "::", "toArray", "(", "$", "path", ",", "$", "separator", ")", ";", "if", "(", "!", "$", "nodes", ")", "{", "return", "$", "default", ";", "}", "$", "dataTmp", "=", "$", "data", ";", "foreach", "(", "$", "nodes", "as", "$", "arg", ")", "{", "if", "(", "\\", "is_object", "(", "$", "dataTmp", ")", "&&", "isset", "(", "$", "dataTmp", "->", "$", "arg", ")", ")", "{", "$", "dataTmp", "=", "$", "dataTmp", "->", "$", "arg", ";", "}", "elseif", "(", "(", "\\", "is_array", "(", "$", "dataTmp", ")", "||", "$", "dataTmp", "instanceof", "\\", "ArrayAccess", ")", "&&", "isset", "(", "$", "dataTmp", "[", "$", "arg", "]", ")", ")", "{", "$", "dataTmp", "=", "$", "dataTmp", "[", "$", "arg", "]", ";", "}", "else", "{", "return", "$", "default", ";", "}", "}", "return", "$", "dataTmp", ";", "}" ]
Get data from array or object by path. Example: `DataCollector::getByPath($array, 'foo.bar.yoo')` equals to $array['foo']['bar']['yoo']. @param array|\ArrayAccess $data An array or object to get value. @param mixed $path The key path. @param mixed $default @param string $separator Separator of paths. @return mixed Found value, null if not exists.
[ "Get", "data", "from", "array", "or", "object", "by", "path", ".", "Example", ":", "DataCollector", "::", "getByPath", "(", "$array", "foo", ".", "bar", ".", "yoo", ")", "equals", "to", "$array", "[", "foo", "]", "[", "bar", "]", "[", "yoo", "]", "." ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/ArrayHelper.php#L390-L418
inhere/php-librarys
src/Helpers/ArrayHelper.php
ArrayHelper.setByPath
public static function setByPath(&$data, $path, $value, $separator = '.') { if (false === strpos($path, $separator)) { $data[$path] = $value; return true; } if (!$nodes = Str::toArray($path, $separator)) { return false; } $dataTmp = &$data; foreach ($nodes as $node) { if (\is_array($dataTmp)) { if (empty($dataTmp[$node])) { $dataTmp[$node] = []; } $dataTmp = &$dataTmp[$node]; } else { // If a node is value but path is not go to the end, we replace this value as a new store. // Then next node can insert new value to this store. $dataTmp = array(); } } // Now, path go to the end, means we get latest node, set value to this node. $dataTmp = $value; return true; }
php
public static function setByPath(&$data, $path, $value, $separator = '.') { if (false === strpos($path, $separator)) { $data[$path] = $value; return true; } if (!$nodes = Str::toArray($path, $separator)) { return false; } $dataTmp = &$data; foreach ($nodes as $node) { if (\is_array($dataTmp)) { if (empty($dataTmp[$node])) { $dataTmp[$node] = []; } $dataTmp = &$dataTmp[$node]; } else { // If a node is value but path is not go to the end, we replace this value as a new store. // Then next node can insert new value to this store. $dataTmp = array(); } } // Now, path go to the end, means we get latest node, set value to this node. $dataTmp = $value; return true; }
[ "public", "static", "function", "setByPath", "(", "&", "$", "data", ",", "$", "path", ",", "$", "value", ",", "$", "separator", "=", "'.'", ")", "{", "if", "(", "false", "===", "strpos", "(", "$", "path", ",", "$", "separator", ")", ")", "{", "$", "data", "[", "$", "path", "]", "=", "$", "value", ";", "return", "true", ";", "}", "if", "(", "!", "$", "nodes", "=", "Str", "::", "toArray", "(", "$", "path", ",", "$", "separator", ")", ")", "{", "return", "false", ";", "}", "$", "dataTmp", "=", "&", "$", "data", ";", "foreach", "(", "$", "nodes", "as", "$", "node", ")", "{", "if", "(", "\\", "is_array", "(", "$", "dataTmp", ")", ")", "{", "if", "(", "empty", "(", "$", "dataTmp", "[", "$", "node", "]", ")", ")", "{", "$", "dataTmp", "[", "$", "node", "]", "=", "[", "]", ";", "}", "$", "dataTmp", "=", "&", "$", "dataTmp", "[", "$", "node", "]", ";", "}", "else", "{", "// If a node is value but path is not go to the end, we replace this value as a new store.", "// Then next node can insert new value to this store.", "$", "dataTmp", "=", "array", "(", ")", ";", "}", "}", "// Now, path go to the end, means we get latest node, set value to this node.", "$", "dataTmp", "=", "$", "value", ";", "return", "true", ";", "}" ]
setByPath @param array|\ArrayAccess &$data @param string $path @param mixed $value @param string $separator @return boolean
[ "setByPath" ]
train
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Helpers/ArrayHelper.php#L428-L460
heidelpay/PhpDoc
src/phpDocumentor/Descriptor/Builder/Reflector/Tags/VarAssembler.php
VarAssembler.create
public function create($data) { $descriptor = new VarDescriptor($data->getName()); $descriptor->setDescription($data->getDescription()); $descriptor->setVariableName($data->getVariableName()); $types = $this->builder->buildDescriptor( new Collection($data->getVariableName() == '$this' ? array('$this') : $data->getTypes()) ); $descriptor->setTypes($types); return $descriptor; }
php
public function create($data) { $descriptor = new VarDescriptor($data->getName()); $descriptor->setDescription($data->getDescription()); $descriptor->setVariableName($data->getVariableName()); $types = $this->builder->buildDescriptor( new Collection($data->getVariableName() == '$this' ? array('$this') : $data->getTypes()) ); $descriptor->setTypes($types); return $descriptor; }
[ "public", "function", "create", "(", "$", "data", ")", "{", "$", "descriptor", "=", "new", "VarDescriptor", "(", "$", "data", "->", "getName", "(", ")", ")", ";", "$", "descriptor", "->", "setDescription", "(", "$", "data", "->", "getDescription", "(", ")", ")", ";", "$", "descriptor", "->", "setVariableName", "(", "$", "data", "->", "getVariableName", "(", ")", ")", ";", "$", "types", "=", "$", "this", "->", "builder", "->", "buildDescriptor", "(", "new", "Collection", "(", "$", "data", "->", "getVariableName", "(", ")", "==", "'$this'", "?", "array", "(", "'$this'", ")", ":", "$", "data", "->", "getTypes", "(", ")", ")", ")", ";", "$", "descriptor", "->", "setTypes", "(", "$", "types", ")", ";", "return", "$", "descriptor", ";", "}" ]
Creates a new Descriptor from the given Reflector. @param VarTag $data @return VarDescriptor
[ "Creates", "a", "new", "Descriptor", "from", "the", "given", "Reflector", "." ]
train
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Descriptor/Builder/Reflector/Tags/VarAssembler.php#L34-L46
eghojansu/moe
src/tools/web/google/StaticMap.php
StaticMap.dump
function dump() { $fw=Base::instance(); $web=Web::instance(); $out=''; return ($req=$web->request( self::URL_Static.'?'.array_reduce( $this->query, function($out,$item) { return ($out.=($out?'&':''). urlencode($item[0]).'='.urlencode($item[1])); } ))) && $req['body']?$req['body']:FALSE; }
php
function dump() { $fw=Base::instance(); $web=Web::instance(); $out=''; return ($req=$web->request( self::URL_Static.'?'.array_reduce( $this->query, function($out,$item) { return ($out.=($out?'&':''). urlencode($item[0]).'='.urlencode($item[1])); } ))) && $req['body']?$req['body']:FALSE; }
[ "function", "dump", "(", ")", "{", "$", "fw", "=", "Base", "::", "instance", "(", ")", ";", "$", "web", "=", "Web", "::", "instance", "(", ")", ";", "$", "out", "=", "''", ";", "return", "(", "$", "req", "=", "$", "web", "->", "request", "(", "self", "::", "URL_Static", ".", "'?'", ".", "array_reduce", "(", "$", "this", "->", "query", ",", "function", "(", "$", "out", ",", "$", "item", ")", "{", "return", "(", "$", "out", ".=", "(", "$", "out", "?", "'&'", ":", "''", ")", ".", "urlencode", "(", "$", "item", "[", "0", "]", ")", ".", "'='", ".", "urlencode", "(", "$", "item", "[", "1", "]", ")", ")", ";", "}", ")", ")", ")", "&&", "$", "req", "[", "'body'", "]", "?", "$", "req", "[", "'body'", "]", ":", "FALSE", ";", "}" ]
Generate map @return string
[ "Generate", "map" ]
train
https://github.com/eghojansu/moe/blob/f58ec75a3116d1a572782256e2b38bb9aab95e3c/src/tools/web/google/StaticMap.php#L34-L46
zicht/z
src/Zicht/Tool/Script/Parser/Expression.php
Expression.parse
public function parse(TokenStream $stream) { if ($stream->match(Token::OPERATOR, array('!', '-'))) { $value = $stream->current()->value; $stream->next(); $ret = new Op\Unary($value, $this->parse($stream)); } elseif ($stream->match(Token::KEYWORD, array('true', 'false'))) { $ret = new Node\Expr\Literal($stream->current()->value === 'true'); $stream->next(); } elseif ($stream->match(Token::KEYWORD, 'null')) { $ret = new Node\Expr\Literal(null); $stream->next(); } elseif ($stream->match(Token::IDENTIFIER)) { $name = $stream->current()->value; $stream->next(); $ret = new Node\Expr\Variable($name); } elseif ($stream->match(Token::STRING)) { $ret = new Node\Expr\Str($stream->current()->value); $stream->next(); } elseif ($stream->match(Token::NUMBER)) { $value = $stream->current()->value; if (strpos('.', $value) !== false) { $ret = new Node\Expr\Number((float)$value); } else { $ret = new Node\Expr\Number((int)$value); } $stream->next(); } elseif ($stream->match(Token::OPERATOR, '(')) { $stream->next(); $ret = new Node\Expr\Parens($this->parse($stream)); $stream->expect(Token::OPERATOR, ')'); } elseif ($stream->match(Token::OPERATOR, '[')) { $stream->next(); $ret = new Node\Expr\ListNode(); if (!$stream->match(Token::OPERATOR, ']')) { $ret->append($this->parse($stream)); while ($stream->match(',')) { $stream->next(); $ret->append($this->parse($stream)); } } $stream->expect(Token::OPERATOR, ']'); } else { $this->err($stream); return null; } if ($stream->valid()) { while ($stream->valid() && $stream->match(Token::OPERATOR, array('(', '.', '['))) { $type = $stream->current(); $stream->next(); if ($type->value === '(') { $ret = new Node\Expr\Call($ret); if (!$stream->match(Token::OPERATOR, ')')) { do { $arg = $this->parse($stream); $ret->append($arg); if ($stream->match(',')) { $stream->next(); } else { break; } } while (true); } $stream->expect(Token::OPERATOR, ')'); } else { $ret = new Node\Expr\Subscript($ret); if ($type->value === '.') { $token = $stream->expect(Token::IDENTIFIER); $ret->append(new Node\Expr\Str($token->value)); } else { $ret->append($this->parse($stream)); } switch ($type->value) { case '[': $stream->expect(Token::OPERATOR, ']'); break; } } } } if ($stream->valid()) { if ($stream->match(Token::OPERATOR, self::$INFIX_BINARY) || $stream->match(Token::KEYWORD, 'in')) { $value = $stream->current()->value; $stream->next(); $ret = new Op\Binary($value, $ret, $this->parse($stream)); } elseif ($stream->match(Token::OPERATOR, '?')) { $stream->next(); if ($stream->match(Token::OPERATOR, ':')) { $then = null; } else { $then = $this->parse($stream); } if ($stream->valid() && $stream->match(Token::OPERATOR, ':')) { $stream->next(); $else = $this->parse($stream); } else { $else = null; } $ret = new Op\Ternary('?', $ret, $then, $else); } } // little syntactic sugar for function calls without parentheses: $allowInlineCallTokens = array(Token::IDENTIFIER, Token::STRING, Token::NUMBER); if ($stream->valid() && ($stream->match($allowInlineCallTokens))) { $ret = new Node\Expr\Call($ret); $ret->append($this->parse($stream)); } return $ret; }
php
public function parse(TokenStream $stream) { if ($stream->match(Token::OPERATOR, array('!', '-'))) { $value = $stream->current()->value; $stream->next(); $ret = new Op\Unary($value, $this->parse($stream)); } elseif ($stream->match(Token::KEYWORD, array('true', 'false'))) { $ret = new Node\Expr\Literal($stream->current()->value === 'true'); $stream->next(); } elseif ($stream->match(Token::KEYWORD, 'null')) { $ret = new Node\Expr\Literal(null); $stream->next(); } elseif ($stream->match(Token::IDENTIFIER)) { $name = $stream->current()->value; $stream->next(); $ret = new Node\Expr\Variable($name); } elseif ($stream->match(Token::STRING)) { $ret = new Node\Expr\Str($stream->current()->value); $stream->next(); } elseif ($stream->match(Token::NUMBER)) { $value = $stream->current()->value; if (strpos('.', $value) !== false) { $ret = new Node\Expr\Number((float)$value); } else { $ret = new Node\Expr\Number((int)$value); } $stream->next(); } elseif ($stream->match(Token::OPERATOR, '(')) { $stream->next(); $ret = new Node\Expr\Parens($this->parse($stream)); $stream->expect(Token::OPERATOR, ')'); } elseif ($stream->match(Token::OPERATOR, '[')) { $stream->next(); $ret = new Node\Expr\ListNode(); if (!$stream->match(Token::OPERATOR, ']')) { $ret->append($this->parse($stream)); while ($stream->match(',')) { $stream->next(); $ret->append($this->parse($stream)); } } $stream->expect(Token::OPERATOR, ']'); } else { $this->err($stream); return null; } if ($stream->valid()) { while ($stream->valid() && $stream->match(Token::OPERATOR, array('(', '.', '['))) { $type = $stream->current(); $stream->next(); if ($type->value === '(') { $ret = new Node\Expr\Call($ret); if (!$stream->match(Token::OPERATOR, ')')) { do { $arg = $this->parse($stream); $ret->append($arg); if ($stream->match(',')) { $stream->next(); } else { break; } } while (true); } $stream->expect(Token::OPERATOR, ')'); } else { $ret = new Node\Expr\Subscript($ret); if ($type->value === '.') { $token = $stream->expect(Token::IDENTIFIER); $ret->append(new Node\Expr\Str($token->value)); } else { $ret->append($this->parse($stream)); } switch ($type->value) { case '[': $stream->expect(Token::OPERATOR, ']'); break; } } } } if ($stream->valid()) { if ($stream->match(Token::OPERATOR, self::$INFIX_BINARY) || $stream->match(Token::KEYWORD, 'in')) { $value = $stream->current()->value; $stream->next(); $ret = new Op\Binary($value, $ret, $this->parse($stream)); } elseif ($stream->match(Token::OPERATOR, '?')) { $stream->next(); if ($stream->match(Token::OPERATOR, ':')) { $then = null; } else { $then = $this->parse($stream); } if ($stream->valid() && $stream->match(Token::OPERATOR, ':')) { $stream->next(); $else = $this->parse($stream); } else { $else = null; } $ret = new Op\Ternary('?', $ret, $then, $else); } } // little syntactic sugar for function calls without parentheses: $allowInlineCallTokens = array(Token::IDENTIFIER, Token::STRING, Token::NUMBER); if ($stream->valid() && ($stream->match($allowInlineCallTokens))) { $ret = new Node\Expr\Call($ret); $ret->append($this->parse($stream)); } return $ret; }
[ "public", "function", "parse", "(", "TokenStream", "$", "stream", ")", "{", "if", "(", "$", "stream", "->", "match", "(", "Token", "::", "OPERATOR", ",", "array", "(", "'!'", ",", "'-'", ")", ")", ")", "{", "$", "value", "=", "$", "stream", "->", "current", "(", ")", "->", "value", ";", "$", "stream", "->", "next", "(", ")", ";", "$", "ret", "=", "new", "Op", "\\", "Unary", "(", "$", "value", ",", "$", "this", "->", "parse", "(", "$", "stream", ")", ")", ";", "}", "elseif", "(", "$", "stream", "->", "match", "(", "Token", "::", "KEYWORD", ",", "array", "(", "'true'", ",", "'false'", ")", ")", ")", "{", "$", "ret", "=", "new", "Node", "\\", "Expr", "\\", "Literal", "(", "$", "stream", "->", "current", "(", ")", "->", "value", "===", "'true'", ")", ";", "$", "stream", "->", "next", "(", ")", ";", "}", "elseif", "(", "$", "stream", "->", "match", "(", "Token", "::", "KEYWORD", ",", "'null'", ")", ")", "{", "$", "ret", "=", "new", "Node", "\\", "Expr", "\\", "Literal", "(", "null", ")", ";", "$", "stream", "->", "next", "(", ")", ";", "}", "elseif", "(", "$", "stream", "->", "match", "(", "Token", "::", "IDENTIFIER", ")", ")", "{", "$", "name", "=", "$", "stream", "->", "current", "(", ")", "->", "value", ";", "$", "stream", "->", "next", "(", ")", ";", "$", "ret", "=", "new", "Node", "\\", "Expr", "\\", "Variable", "(", "$", "name", ")", ";", "}", "elseif", "(", "$", "stream", "->", "match", "(", "Token", "::", "STRING", ")", ")", "{", "$", "ret", "=", "new", "Node", "\\", "Expr", "\\", "Str", "(", "$", "stream", "->", "current", "(", ")", "->", "value", ")", ";", "$", "stream", "->", "next", "(", ")", ";", "}", "elseif", "(", "$", "stream", "->", "match", "(", "Token", "::", "NUMBER", ")", ")", "{", "$", "value", "=", "$", "stream", "->", "current", "(", ")", "->", "value", ";", "if", "(", "strpos", "(", "'.'", ",", "$", "value", ")", "!==", "false", ")", "{", "$", "ret", "=", "new", "Node", "\\", "Expr", "\\", "Number", "(", "(", "float", ")", "$", "value", ")", ";", "}", "else", "{", "$", "ret", "=", "new", "Node", "\\", "Expr", "\\", "Number", "(", "(", "int", ")", "$", "value", ")", ";", "}", "$", "stream", "->", "next", "(", ")", ";", "}", "elseif", "(", "$", "stream", "->", "match", "(", "Token", "::", "OPERATOR", ",", "'('", ")", ")", "{", "$", "stream", "->", "next", "(", ")", ";", "$", "ret", "=", "new", "Node", "\\", "Expr", "\\", "Parens", "(", "$", "this", "->", "parse", "(", "$", "stream", ")", ")", ";", "$", "stream", "->", "expect", "(", "Token", "::", "OPERATOR", ",", "')'", ")", ";", "}", "elseif", "(", "$", "stream", "->", "match", "(", "Token", "::", "OPERATOR", ",", "'['", ")", ")", "{", "$", "stream", "->", "next", "(", ")", ";", "$", "ret", "=", "new", "Node", "\\", "Expr", "\\", "ListNode", "(", ")", ";", "if", "(", "!", "$", "stream", "->", "match", "(", "Token", "::", "OPERATOR", ",", "']'", ")", ")", "{", "$", "ret", "->", "append", "(", "$", "this", "->", "parse", "(", "$", "stream", ")", ")", ";", "while", "(", "$", "stream", "->", "match", "(", "','", ")", ")", "{", "$", "stream", "->", "next", "(", ")", ";", "$", "ret", "->", "append", "(", "$", "this", "->", "parse", "(", "$", "stream", ")", ")", ";", "}", "}", "$", "stream", "->", "expect", "(", "Token", "::", "OPERATOR", ",", "']'", ")", ";", "}", "else", "{", "$", "this", "->", "err", "(", "$", "stream", ")", ";", "return", "null", ";", "}", "if", "(", "$", "stream", "->", "valid", "(", ")", ")", "{", "while", "(", "$", "stream", "->", "valid", "(", ")", "&&", "$", "stream", "->", "match", "(", "Token", "::", "OPERATOR", ",", "array", "(", "'('", ",", "'.'", ",", "'['", ")", ")", ")", "{", "$", "type", "=", "$", "stream", "->", "current", "(", ")", ";", "$", "stream", "->", "next", "(", ")", ";", "if", "(", "$", "type", "->", "value", "===", "'('", ")", "{", "$", "ret", "=", "new", "Node", "\\", "Expr", "\\", "Call", "(", "$", "ret", ")", ";", "if", "(", "!", "$", "stream", "->", "match", "(", "Token", "::", "OPERATOR", ",", "')'", ")", ")", "{", "do", "{", "$", "arg", "=", "$", "this", "->", "parse", "(", "$", "stream", ")", ";", "$", "ret", "->", "append", "(", "$", "arg", ")", ";", "if", "(", "$", "stream", "->", "match", "(", "','", ")", ")", "{", "$", "stream", "->", "next", "(", ")", ";", "}", "else", "{", "break", ";", "}", "}", "while", "(", "true", ")", ";", "}", "$", "stream", "->", "expect", "(", "Token", "::", "OPERATOR", ",", "')'", ")", ";", "}", "else", "{", "$", "ret", "=", "new", "Node", "\\", "Expr", "\\", "Subscript", "(", "$", "ret", ")", ";", "if", "(", "$", "type", "->", "value", "===", "'.'", ")", "{", "$", "token", "=", "$", "stream", "->", "expect", "(", "Token", "::", "IDENTIFIER", ")", ";", "$", "ret", "->", "append", "(", "new", "Node", "\\", "Expr", "\\", "Str", "(", "$", "token", "->", "value", ")", ")", ";", "}", "else", "{", "$", "ret", "->", "append", "(", "$", "this", "->", "parse", "(", "$", "stream", ")", ")", ";", "}", "switch", "(", "$", "type", "->", "value", ")", "{", "case", "'['", ":", "$", "stream", "->", "expect", "(", "Token", "::", "OPERATOR", ",", "']'", ")", ";", "break", ";", "}", "}", "}", "}", "if", "(", "$", "stream", "->", "valid", "(", ")", ")", "{", "if", "(", "$", "stream", "->", "match", "(", "Token", "::", "OPERATOR", ",", "self", "::", "$", "INFIX_BINARY", ")", "||", "$", "stream", "->", "match", "(", "Token", "::", "KEYWORD", ",", "'in'", ")", ")", "{", "$", "value", "=", "$", "stream", "->", "current", "(", ")", "->", "value", ";", "$", "stream", "->", "next", "(", ")", ";", "$", "ret", "=", "new", "Op", "\\", "Binary", "(", "$", "value", ",", "$", "ret", ",", "$", "this", "->", "parse", "(", "$", "stream", ")", ")", ";", "}", "elseif", "(", "$", "stream", "->", "match", "(", "Token", "::", "OPERATOR", ",", "'?'", ")", ")", "{", "$", "stream", "->", "next", "(", ")", ";", "if", "(", "$", "stream", "->", "match", "(", "Token", "::", "OPERATOR", ",", "':'", ")", ")", "{", "$", "then", "=", "null", ";", "}", "else", "{", "$", "then", "=", "$", "this", "->", "parse", "(", "$", "stream", ")", ";", "}", "if", "(", "$", "stream", "->", "valid", "(", ")", "&&", "$", "stream", "->", "match", "(", "Token", "::", "OPERATOR", ",", "':'", ")", ")", "{", "$", "stream", "->", "next", "(", ")", ";", "$", "else", "=", "$", "this", "->", "parse", "(", "$", "stream", ")", ";", "}", "else", "{", "$", "else", "=", "null", ";", "}", "$", "ret", "=", "new", "Op", "\\", "Ternary", "(", "'?'", ",", "$", "ret", ",", "$", "then", ",", "$", "else", ")", ";", "}", "}", "// little syntactic sugar for function calls without parentheses:", "$", "allowInlineCallTokens", "=", "array", "(", "Token", "::", "IDENTIFIER", ",", "Token", "::", "STRING", ",", "Token", "::", "NUMBER", ")", ";", "if", "(", "$", "stream", "->", "valid", "(", ")", "&&", "(", "$", "stream", "->", "match", "(", "$", "allowInlineCallTokens", ")", ")", ")", "{", "$", "ret", "=", "new", "Node", "\\", "Expr", "\\", "Call", "(", "$", "ret", ")", ";", "$", "ret", "->", "append", "(", "$", "this", "->", "parse", "(", "$", "stream", ")", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Does a recursive descent parsing of the token stream and returns the resulting node. @param \Zicht\Tool\Script\TokenStream $stream @return \Zicht\Tool\Script\Node\Node
[ "Does", "a", "recursive", "descent", "parsing", "of", "the", "token", "stream", "and", "returns", "the", "resulting", "node", "." ]
train
https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Script/Parser/Expression.php#L46-L164
FriendsOfApi/phraseapp
src/Model/Key/KeySearchResults.php
KeySearchResults.createFromArray
public static function createFromArray(array $data) { $self = new self(); foreach ($data as $searchResult) { $self->addSearchResult(KeySearchResult::createFromArray($searchResult)); } return $self; }
php
public static function createFromArray(array $data) { $self = new self(); foreach ($data as $searchResult) { $self->addSearchResult(KeySearchResult::createFromArray($searchResult)); } return $self; }
[ "public", "static", "function", "createFromArray", "(", "array", "$", "data", ")", "{", "$", "self", "=", "new", "self", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "searchResult", ")", "{", "$", "self", "->", "addSearchResult", "(", "KeySearchResult", "::", "createFromArray", "(", "$", "searchResult", ")", ")", ";", "}", "return", "$", "self", ";", "}" ]
@param array $data @return KeySearchResults
[ "@param", "array", "$data" ]
train
https://github.com/FriendsOfApi/phraseapp/blob/1553bf857eb0858f9a7eb905b085864d24f80886/src/Model/Key/KeySearchResults.php#L29-L38
kbond/ControllerUtil
src/Template.php
Template.createCached
public static function createCached($template, $sharedMaxAge, $parameters = array(), $statusCode = self::DEFAULT_STATUS_CODE) { return new static($template, $parameters, $statusCode, array('s_maxage' => $sharedMaxAge)); }
php
public static function createCached($template, $sharedMaxAge, $parameters = array(), $statusCode = self::DEFAULT_STATUS_CODE) { return new static($template, $parameters, $statusCode, array('s_maxage' => $sharedMaxAge)); }
[ "public", "static", "function", "createCached", "(", "$", "template", ",", "$", "sharedMaxAge", ",", "$", "parameters", "=", "array", "(", ")", ",", "$", "statusCode", "=", "self", "::", "DEFAULT_STATUS_CODE", ")", "{", "return", "new", "static", "(", "$", "template", ",", "$", "parameters", ",", "$", "statusCode", ",", "array", "(", "'s_maxage'", "=>", "$", "sharedMaxAge", ")", ")", ";", "}" ]
@param string|array $template @param int $sharedMaxAge @param array $parameters @param int $statusCode @return static
[ "@param", "string|array", "$template", "@param", "int", "$sharedMaxAge", "@param", "array", "$parameters", "@param", "int", "$statusCode" ]
train
https://github.com/kbond/ControllerUtil/blob/67375d43c73d6a3f16356f3d683f62b176766e91/src/Template.php#L20-L23
eghojansu/moe
src/tools/web/PingBack.php
Pingback.enabled
protected function enabled($url) { $web=Web::instance(); $req=$web->request($url); $found=FALSE; if ($req && $req['body']) { // Look for pingback header foreach ($req['headers'] as $header) if (preg_match('/^X-Pingback:\h*(.+)/',$header,$href)) { $found=$href[1]; break; } if (!$found && // Scan page for pingback link tag preg_match('/<link\h+(.+?)\h*\/?>/i',$req['body'],$parts) && preg_match('/rel\h*=\h*"pingback"/i',$parts[1]) && preg_match('/href\h*=\h*"\h*(.+?)\h*"/i',$parts[1],$href)) $found=$href[1]; } return $found; }
php
protected function enabled($url) { $web=Web::instance(); $req=$web->request($url); $found=FALSE; if ($req && $req['body']) { // Look for pingback header foreach ($req['headers'] as $header) if (preg_match('/^X-Pingback:\h*(.+)/',$header,$href)) { $found=$href[1]; break; } if (!$found && // Scan page for pingback link tag preg_match('/<link\h+(.+?)\h*\/?>/i',$req['body'],$parts) && preg_match('/rel\h*=\h*"pingback"/i',$parts[1]) && preg_match('/href\h*=\h*"\h*(.+?)\h*"/i',$parts[1],$href)) $found=$href[1]; } return $found; }
[ "protected", "function", "enabled", "(", "$", "url", ")", "{", "$", "web", "=", "Web", "::", "instance", "(", ")", ";", "$", "req", "=", "$", "web", "->", "request", "(", "$", "url", ")", ";", "$", "found", "=", "FALSE", ";", "if", "(", "$", "req", "&&", "$", "req", "[", "'body'", "]", ")", "{", "// Look for pingback header", "foreach", "(", "$", "req", "[", "'headers'", "]", "as", "$", "header", ")", "if", "(", "preg_match", "(", "'/^X-Pingback:\\h*(.+)/'", ",", "$", "header", ",", "$", "href", ")", ")", "{", "$", "found", "=", "$", "href", "[", "1", "]", ";", "break", ";", "}", "if", "(", "!", "$", "found", "&&", "// Scan page for pingback link tag", "preg_match", "(", "'/<link\\h+(.+?)\\h*\\/?>/i'", ",", "$", "req", "[", "'body'", "]", ",", "$", "parts", ")", "&&", "preg_match", "(", "'/rel\\h*=\\h*\"pingback\"/i'", ",", "$", "parts", "[", "1", "]", ")", "&&", "preg_match", "(", "'/href\\h*=\\h*\"\\h*(.+?)\\h*\"/i'", ",", "$", "parts", "[", "1", "]", ",", "$", "href", ")", ")", "$", "found", "=", "$", "href", "[", "1", "]", ";", "}", "return", "$", "found", ";", "}" ]
Return TRUE if URL points to a pingback-enabled resource @return bool @param $url
[ "Return", "TRUE", "if", "URL", "points", "to", "a", "pingback", "-", "enabled", "resource" ]
train
https://github.com/eghojansu/moe/blob/f58ec75a3116d1a572782256e2b38bb9aab95e3c/src/tools/web/PingBack.php#L22-L41
eghojansu/moe
src/tools/web/PingBack.php
Pingback.inspect
function inspect($source) { $fw=Base::instance(); $web=Web::instance(); $parts=parse_url($source); if (empty($parts['scheme']) || empty($parts['host']) || $parts['host']==$fw->get('HOST')) { $req=$web->request($source); $doc=new DOMDocument('1.0',$fw->get('ENCODING')); $doc->stricterrorchecking=FALSE; $doc->recover=TRUE; if ($req && @$doc->loadhtml($req['body'])) { // Parse anchor tags $links=$doc->getelementsbytagname('a'); foreach ($links as $link) { $permalink=$link->getattribute('href'); // Find pingback-enabled resources if ($permalink && $found=$this->enabled($permalink)) { $req=$web->request($found, array( 'method'=>'POST', 'header'=>'Content-Type: application/xml', 'content'=>xmlrpc_encode_request( 'pingback.ping', array($source,$permalink), array('encoding'=>$fw->get('ENCODING')) ) ) ); if ($req && $req['body']) $this->log.=date('r').' '. $permalink.' [permalink:'.$found.']'.PHP_EOL. $req['body'].PHP_EOL; } } } unset($doc); } }
php
function inspect($source) { $fw=Base::instance(); $web=Web::instance(); $parts=parse_url($source); if (empty($parts['scheme']) || empty($parts['host']) || $parts['host']==$fw->get('HOST')) { $req=$web->request($source); $doc=new DOMDocument('1.0',$fw->get('ENCODING')); $doc->stricterrorchecking=FALSE; $doc->recover=TRUE; if ($req && @$doc->loadhtml($req['body'])) { // Parse anchor tags $links=$doc->getelementsbytagname('a'); foreach ($links as $link) { $permalink=$link->getattribute('href'); // Find pingback-enabled resources if ($permalink && $found=$this->enabled($permalink)) { $req=$web->request($found, array( 'method'=>'POST', 'header'=>'Content-Type: application/xml', 'content'=>xmlrpc_encode_request( 'pingback.ping', array($source,$permalink), array('encoding'=>$fw->get('ENCODING')) ) ) ); if ($req && $req['body']) $this->log.=date('r').' '. $permalink.' [permalink:'.$found.']'.PHP_EOL. $req['body'].PHP_EOL; } } } unset($doc); } }
[ "function", "inspect", "(", "$", "source", ")", "{", "$", "fw", "=", "Base", "::", "instance", "(", ")", ";", "$", "web", "=", "Web", "::", "instance", "(", ")", ";", "$", "parts", "=", "parse_url", "(", "$", "source", ")", ";", "if", "(", "empty", "(", "$", "parts", "[", "'scheme'", "]", ")", "||", "empty", "(", "$", "parts", "[", "'host'", "]", ")", "||", "$", "parts", "[", "'host'", "]", "==", "$", "fw", "->", "get", "(", "'HOST'", ")", ")", "{", "$", "req", "=", "$", "web", "->", "request", "(", "$", "source", ")", ";", "$", "doc", "=", "new", "DOMDocument", "(", "'1.0'", ",", "$", "fw", "->", "get", "(", "'ENCODING'", ")", ")", ";", "$", "doc", "->", "stricterrorchecking", "=", "FALSE", ";", "$", "doc", "->", "recover", "=", "TRUE", ";", "if", "(", "$", "req", "&&", "@", "$", "doc", "->", "loadhtml", "(", "$", "req", "[", "'body'", "]", ")", ")", "{", "// Parse anchor tags", "$", "links", "=", "$", "doc", "->", "getelementsbytagname", "(", "'a'", ")", ";", "foreach", "(", "$", "links", "as", "$", "link", ")", "{", "$", "permalink", "=", "$", "link", "->", "getattribute", "(", "'href'", ")", ";", "// Find pingback-enabled resources", "if", "(", "$", "permalink", "&&", "$", "found", "=", "$", "this", "->", "enabled", "(", "$", "permalink", ")", ")", "{", "$", "req", "=", "$", "web", "->", "request", "(", "$", "found", ",", "array", "(", "'method'", "=>", "'POST'", ",", "'header'", "=>", "'Content-Type: application/xml'", ",", "'content'", "=>", "xmlrpc_encode_request", "(", "'pingback.ping'", ",", "array", "(", "$", "source", ",", "$", "permalink", ")", ",", "array", "(", "'encoding'", "=>", "$", "fw", "->", "get", "(", "'ENCODING'", ")", ")", ")", ")", ")", ";", "if", "(", "$", "req", "&&", "$", "req", "[", "'body'", "]", ")", "$", "this", "->", "log", ".=", "date", "(", "'r'", ")", ".", "' '", ".", "$", "permalink", ".", "' [permalink:'", ".", "$", "found", ".", "']'", ".", "PHP_EOL", ".", "$", "req", "[", "'body'", "]", ".", "PHP_EOL", ";", "}", "}", "}", "unset", "(", "$", "doc", ")", ";", "}", "}" ]
Load local page contents, parse HTML anchor tags, find permalinks, and send XML-RPC calls to corresponding pingback servers @return NULL @param $source string
[ "Load", "local", "page", "contents", "parse", "HTML", "anchor", "tags", "find", "permalinks", "and", "send", "XML", "-", "RPC", "calls", "to", "corresponding", "pingback", "servers" ]
train
https://github.com/eghojansu/moe/blob/f58ec75a3116d1a572782256e2b38bb9aab95e3c/src/tools/web/PingBack.php#L49-L86
eghojansu/moe
src/tools/web/PingBack.php
Pingback.listen
function listen($func,$path=NULL) { $fw=Base::instance(); if (PHP_SAPI!='cli') { header('X-Powered-By: '.$fw->get('PACKAGE')); header('Content-Type: application/xml; '. 'charset='.$charset=$fw->get('ENCODING')); } if (!$path) $path=$fw->get('BASE'); $web=Web::instance(); $args=xmlrpc_decode_request($fw->get('BODY'),$method,$charset); $options=array('encoding'=>$charset); if ($method=='pingback.ping' && isset($args[0],$args[1])) { list($source,$permalink)=$args; $doc=new DOMDocument('1.0',$fw->get('ENCODING')); // Check local page if pingback-enabled $parts=parse_url($permalink); if ((empty($parts['scheme']) || $parts['host']==$fw->get('HOST')) && preg_match('/^'.preg_quote($path,'/').'/'. ($fw->get('CASELESS')?'i':''),$parts['path']) && $this->enabled($permalink)) { // Check source $parts=parse_url($source); if ((empty($parts['scheme']) || $parts['host']==$fw->get('HOST')) && ($req=$web->request($source)) && $doc->loadhtml($req['body'])) { $links=$doc->getelementsbytagname('a'); foreach ($links as $link) { if ($link->getattribute('href')==$permalink) { call_user_func_array($func, array($source,$req['body'])); // Success die(xmlrpc_encode_request(NULL,$source,$options)); } } // No link to local page die(xmlrpc_encode_request(NULL,0x11,$options)); } // Source failure die(xmlrpc_encode_request(NULL,0x10,$options)); } // Doesn't exist (or not pingback-enabled) die(xmlrpc_encode_request(NULL,0x21,$options)); } // Access denied die(xmlrpc_encode_request(NULL,0x31,$options)); }
php
function listen($func,$path=NULL) { $fw=Base::instance(); if (PHP_SAPI!='cli') { header('X-Powered-By: '.$fw->get('PACKAGE')); header('Content-Type: application/xml; '. 'charset='.$charset=$fw->get('ENCODING')); } if (!$path) $path=$fw->get('BASE'); $web=Web::instance(); $args=xmlrpc_decode_request($fw->get('BODY'),$method,$charset); $options=array('encoding'=>$charset); if ($method=='pingback.ping' && isset($args[0],$args[1])) { list($source,$permalink)=$args; $doc=new DOMDocument('1.0',$fw->get('ENCODING')); // Check local page if pingback-enabled $parts=parse_url($permalink); if ((empty($parts['scheme']) || $parts['host']==$fw->get('HOST')) && preg_match('/^'.preg_quote($path,'/').'/'. ($fw->get('CASELESS')?'i':''),$parts['path']) && $this->enabled($permalink)) { // Check source $parts=parse_url($source); if ((empty($parts['scheme']) || $parts['host']==$fw->get('HOST')) && ($req=$web->request($source)) && $doc->loadhtml($req['body'])) { $links=$doc->getelementsbytagname('a'); foreach ($links as $link) { if ($link->getattribute('href')==$permalink) { call_user_func_array($func, array($source,$req['body'])); // Success die(xmlrpc_encode_request(NULL,$source,$options)); } } // No link to local page die(xmlrpc_encode_request(NULL,0x11,$options)); } // Source failure die(xmlrpc_encode_request(NULL,0x10,$options)); } // Doesn't exist (or not pingback-enabled) die(xmlrpc_encode_request(NULL,0x21,$options)); } // Access denied die(xmlrpc_encode_request(NULL,0x31,$options)); }
[ "function", "listen", "(", "$", "func", ",", "$", "path", "=", "NULL", ")", "{", "$", "fw", "=", "Base", "::", "instance", "(", ")", ";", "if", "(", "PHP_SAPI", "!=", "'cli'", ")", "{", "header", "(", "'X-Powered-By: '", ".", "$", "fw", "->", "get", "(", "'PACKAGE'", ")", ")", ";", "header", "(", "'Content-Type: application/xml; '", ".", "'charset='", ".", "$", "charset", "=", "$", "fw", "->", "get", "(", "'ENCODING'", ")", ")", ";", "}", "if", "(", "!", "$", "path", ")", "$", "path", "=", "$", "fw", "->", "get", "(", "'BASE'", ")", ";", "$", "web", "=", "Web", "::", "instance", "(", ")", ";", "$", "args", "=", "xmlrpc_decode_request", "(", "$", "fw", "->", "get", "(", "'BODY'", ")", ",", "$", "method", ",", "$", "charset", ")", ";", "$", "options", "=", "array", "(", "'encoding'", "=>", "$", "charset", ")", ";", "if", "(", "$", "method", "==", "'pingback.ping'", "&&", "isset", "(", "$", "args", "[", "0", "]", ",", "$", "args", "[", "1", "]", ")", ")", "{", "list", "(", "$", "source", ",", "$", "permalink", ")", "=", "$", "args", ";", "$", "doc", "=", "new", "DOMDocument", "(", "'1.0'", ",", "$", "fw", "->", "get", "(", "'ENCODING'", ")", ")", ";", "// Check local page if pingback-enabled", "$", "parts", "=", "parse_url", "(", "$", "permalink", ")", ";", "if", "(", "(", "empty", "(", "$", "parts", "[", "'scheme'", "]", ")", "||", "$", "parts", "[", "'host'", "]", "==", "$", "fw", "->", "get", "(", "'HOST'", ")", ")", "&&", "preg_match", "(", "'/^'", ".", "preg_quote", "(", "$", "path", ",", "'/'", ")", ".", "'/'", ".", "(", "$", "fw", "->", "get", "(", "'CASELESS'", ")", "?", "'i'", ":", "''", ")", ",", "$", "parts", "[", "'path'", "]", ")", "&&", "$", "this", "->", "enabled", "(", "$", "permalink", ")", ")", "{", "// Check source", "$", "parts", "=", "parse_url", "(", "$", "source", ")", ";", "if", "(", "(", "empty", "(", "$", "parts", "[", "'scheme'", "]", ")", "||", "$", "parts", "[", "'host'", "]", "==", "$", "fw", "->", "get", "(", "'HOST'", ")", ")", "&&", "(", "$", "req", "=", "$", "web", "->", "request", "(", "$", "source", ")", ")", "&&", "$", "doc", "->", "loadhtml", "(", "$", "req", "[", "'body'", "]", ")", ")", "{", "$", "links", "=", "$", "doc", "->", "getelementsbytagname", "(", "'a'", ")", ";", "foreach", "(", "$", "links", "as", "$", "link", ")", "{", "if", "(", "$", "link", "->", "getattribute", "(", "'href'", ")", "==", "$", "permalink", ")", "{", "call_user_func_array", "(", "$", "func", ",", "array", "(", "$", "source", ",", "$", "req", "[", "'body'", "]", ")", ")", ";", "// Success", "die", "(", "xmlrpc_encode_request", "(", "NULL", ",", "$", "source", ",", "$", "options", ")", ")", ";", "}", "}", "// No link to local page", "die", "(", "xmlrpc_encode_request", "(", "NULL", ",", "0x11", ",", "$", "options", ")", ")", ";", "}", "// Source failure", "die", "(", "xmlrpc_encode_request", "(", "NULL", ",", "0x10", ",", "$", "options", ")", ")", ";", "}", "// Doesn't exist (or not pingback-enabled)", "die", "(", "xmlrpc_encode_request", "(", "NULL", ",", "0x21", ",", "$", "options", ")", ")", ";", "}", "// Access denied", "die", "(", "xmlrpc_encode_request", "(", "NULL", ",", "0x31", ",", "$", "options", ")", ")", ";", "}" ]
Receive ping, check if local page is pingback-enabled, verify source contents, and return XML-RPC response @return string @param $func callback @param $path string
[ "Receive", "ping", "check", "if", "local", "page", "is", "pingback", "-", "enabled", "verify", "source", "contents", "and", "return", "XML", "-", "RPC", "response" ]
train
https://github.com/eghojansu/moe/blob/f58ec75a3116d1a572782256e2b38bb9aab95e3c/src/tools/web/PingBack.php#L95-L143
ekuiter/feature-php
FeaturePhp/Generator/AspectGenerator.php
AspectGenerator.processFileSpecification
protected function processFileSpecification($artifact, $fileSpecification) { $this->aspectKernel->addAspect(new fphp\Aspect\Aspect($artifact, $fileSpecification)); $this->tracingLinks[] = new fphp\Artifact\TracingLink( "aspect", $artifact, $fileSpecification->getSourcePlace(), $fileSpecification->getTargetPlace()); $this->logFile->log($artifact, "added aspect at \"{$fileSpecification->getTarget()}\""); }
php
protected function processFileSpecification($artifact, $fileSpecification) { $this->aspectKernel->addAspect(new fphp\Aspect\Aspect($artifact, $fileSpecification)); $this->tracingLinks[] = new fphp\Artifact\TracingLink( "aspect", $artifact, $fileSpecification->getSourcePlace(), $fileSpecification->getTargetPlace()); $this->logFile->log($artifact, "added aspect at \"{$fileSpecification->getTarget()}\""); }
[ "protected", "function", "processFileSpecification", "(", "$", "artifact", ",", "$", "fileSpecification", ")", "{", "$", "this", "->", "aspectKernel", "->", "addAspect", "(", "new", "fphp", "\\", "Aspect", "\\", "Aspect", "(", "$", "artifact", ",", "$", "fileSpecification", ")", ")", ";", "$", "this", "->", "tracingLinks", "[", "]", "=", "new", "fphp", "\\", "Artifact", "\\", "TracingLink", "(", "\"aspect\"", ",", "$", "artifact", ",", "$", "fileSpecification", "->", "getSourcePlace", "(", ")", ",", "$", "fileSpecification", "->", "getTargetPlace", "(", ")", ")", ";", "$", "this", "->", "logFile", "->", "log", "(", "$", "artifact", ",", "\"added aspect at \\\"{$fileSpecification->getTarget()}\\\"\"", ")", ";", "}" ]
Adds an aspect from a file to the aspect kernel. @param \FeaturePhp\Artifact\Artifact $artifact @param \FeaturePhp\Specification\FileSpecification $fileSpecification
[ "Adds", "an", "aspect", "from", "a", "file", "to", "the", "aspect", "kernel", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Generator/AspectGenerator.php#L70-L75
ekuiter/feature-php
FeaturePhp/Generator/AspectGenerator.php
AspectGenerator._generateFiles
protected function _generateFiles() { if ($this->feature && !$this->isSelectedFeature($this->feature)) { $this->logFile->log(null, "did not add aspect kernel because \"$this->feature\" is not selected"); return; } parent::_generateFiles(); $this->files = array_merge($this->files, $this->aspectKernel->generateFiles($this->class, $this->target)); }
php
protected function _generateFiles() { if ($this->feature && !$this->isSelectedFeature($this->feature)) { $this->logFile->log(null, "did not add aspect kernel because \"$this->feature\" is not selected"); return; } parent::_generateFiles(); $this->files = array_merge($this->files, $this->aspectKernel->generateFiles($this->class, $this->target)); }
[ "protected", "function", "_generateFiles", "(", ")", "{", "if", "(", "$", "this", "->", "feature", "&&", "!", "$", "this", "->", "isSelectedFeature", "(", "$", "this", "->", "feature", ")", ")", "{", "$", "this", "->", "logFile", "->", "log", "(", "null", ",", "\"did not add aspect kernel because \\\"$this->feature\\\" is not selected\"", ")", ";", "return", ";", "}", "parent", "::", "_generateFiles", "(", ")", ";", "$", "this", "->", "files", "=", "array_merge", "(", "$", "this", "->", "files", ",", "$", "this", "->", "aspectKernel", "->", "generateFiles", "(", "$", "this", "->", "class", ",", "$", "this", "->", "target", ")", ")", ";", "}" ]
Generates the aspect files and the aspect kernel.
[ "Generates", "the", "aspect", "files", "and", "the", "aspect", "kernel", "." ]
train
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Generator/AspectGenerator.php#L80-L89
jakubkratina/larachartie
src/DataTable/Factory/RowsFactory.php
RowsFactory.create
public function create(array $values, int $columns) { if (self::areSplatted($values) === true) { $values = $values[0]; } // TODO only at LineChartFormatter // if (count($values) !== $columns) { // throw new InvalidCellsCountException(count($values), $columns); // } return (new Row($this->cells))->addCells($values); }
php
public function create(array $values, int $columns) { if (self::areSplatted($values) === true) { $values = $values[0]; } // TODO only at LineChartFormatter // if (count($values) !== $columns) { // throw new InvalidCellsCountException(count($values), $columns); // } return (new Row($this->cells))->addCells($values); }
[ "public", "function", "create", "(", "array", "$", "values", ",", "int", "$", "columns", ")", "{", "if", "(", "self", "::", "areSplatted", "(", "$", "values", ")", "===", "true", ")", "{", "$", "values", "=", "$", "values", "[", "0", "]", ";", "}", "// TODO only at LineChartFormatter", "//\t\tif (count($values) !== $columns) {", "//\t\t\tthrow new InvalidCellsCountException(count($values), $columns);", "//\t\t}", "return", "(", "new", "Row", "(", "$", "this", "->", "cells", ")", ")", "->", "addCells", "(", "$", "values", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/jakubkratina/larachartie/blob/96c535650d61a2a6c1c1b12d374e5e59d33239f6/src/DataTable/Factory/RowsFactory.php#L35-L47
kbond/ControllerUtil
src/EventListener/ConvertExceptionListener.php
ConvertExceptionListener.findStatusCode
private function findStatusCode(\Exception $exception) { $exceptionClass = get_class($exception); foreach ($this->exceptionClassMap as $originalExceptionClass => $statusCode) { if ($exceptionClass === $originalExceptionClass || is_subclass_of($exceptionClass, $originalExceptionClass)) { return (int) $statusCode; } } return null; }
php
private function findStatusCode(\Exception $exception) { $exceptionClass = get_class($exception); foreach ($this->exceptionClassMap as $originalExceptionClass => $statusCode) { if ($exceptionClass === $originalExceptionClass || is_subclass_of($exceptionClass, $originalExceptionClass)) { return (int) $statusCode; } } return null; }
[ "private", "function", "findStatusCode", "(", "\\", "Exception", "$", "exception", ")", "{", "$", "exceptionClass", "=", "get_class", "(", "$", "exception", ")", ";", "foreach", "(", "$", "this", "->", "exceptionClassMap", "as", "$", "originalExceptionClass", "=>", "$", "statusCode", ")", "{", "if", "(", "$", "exceptionClass", "===", "$", "originalExceptionClass", "||", "is_subclass_of", "(", "$", "exceptionClass", ",", "$", "originalExceptionClass", ")", ")", "{", "return", "(", "int", ")", "$", "statusCode", ";", "}", "}", "return", "null", ";", "}" ]
@param \Exception $exception @return int|null
[ "@param", "\\", "Exception", "$exception" ]
train
https://github.com/kbond/ControllerUtil/blob/67375d43c73d6a3f16356f3d683f62b176766e91/src/EventListener/ConvertExceptionListener.php#L54-L65
willhoffmann/domuserp-php
src/Resources/Addresses/Secondary/Neighborhoods.php
Neighborhoods.getList
public function getList(array $query = []) { $resource = self::DOMUSERP_API_OPERACIONAL . '/' . $this->cityId .'/bairros'; $list = $this->pagination($resource); return $list; }
php
public function getList(array $query = []) { $resource = self::DOMUSERP_API_OPERACIONAL . '/' . $this->cityId .'/bairros'; $list = $this->pagination($resource); return $list; }
[ "public", "function", "getList", "(", "array", "$", "query", "=", "[", "]", ")", "{", "$", "resource", "=", "self", "::", "DOMUSERP_API_OPERACIONAL", ".", "'/'", ".", "$", "this", "->", "cityId", ".", "'/bairros'", ";", "$", "list", "=", "$", "this", "->", "pagination", "(", "$", "resource", ")", ";", "return", "$", "list", ";", "}" ]
List of neighborhoods @param array $query @return array|string @throws \GuzzleHttp\Exception\GuzzleException
[ "List", "of", "neighborhoods" ]
train
https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/Addresses/Secondary/Neighborhoods.php#L36-L42
willhoffmann/domuserp-php
src/Resources/Addresses/Secondary/Neighborhoods.php
Neighborhoods.save
public function save(DataReceiver $data) { $resource = self::DOMUSERP_API_OPERACIONAL . '/enderecos/localidade/'. $this->cityId .'/bairros'; return $this->execute(self::HTTP_POST, $resource, ['json' => $data->toArray()]); }
php
public function save(DataReceiver $data) { $resource = self::DOMUSERP_API_OPERACIONAL . '/enderecos/localidade/'. $this->cityId .'/bairros'; return $this->execute(self::HTTP_POST, $resource, ['json' => $data->toArray()]); }
[ "public", "function", "save", "(", "DataReceiver", "$", "data", ")", "{", "$", "resource", "=", "self", "::", "DOMUSERP_API_OPERACIONAL", ".", "'/enderecos/localidade/'", ".", "$", "this", "->", "cityId", ".", "'/bairros'", ";", "return", "$", "this", "->", "execute", "(", "self", "::", "HTTP_POST", ",", "$", "resource", ",", "[", "'json'", "=>", "$", "data", "->", "toArray", "(", ")", "]", ")", ";", "}" ]
Send the save request @param DataReceiver $data @return string @throws \GuzzleHttp\Exception\GuzzleException
[ "Send", "the", "save", "request" ]
train
https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/Addresses/Secondary/Neighborhoods.php#L87-L91
zhouyl/mellivora
Mellivora/Database/Concerns/ManagesTransactions.php
ManagesTransactions.transaction
public function transaction(Closure $callback, $attempts = 1) { for ($currentAttempt = 1; $currentAttempt <= $attempts; ++$currentAttempt) { $this->beginTransaction(); // We'll simply execute the given callback within a try / catch block and if we // catch any exception we can rollback this transaction so that none of this // gets actually persisted to a database or stored in a permanent fashion. try { return tap($callback($this), function ($result) { $this->commit(); }); } // If we catch an exception we'll rollback this transaction and try again if we // are not out of attempts. If we are out of attempts we will just throw the // exception back out and let the developer handle an uncaught exceptions. catch (Exception $e) { $this->handleTransactionException( $e, $currentAttempt, $attempts ); } catch (Throwable $e) { $this->rollBack(); throw $e; } } }
php
public function transaction(Closure $callback, $attempts = 1) { for ($currentAttempt = 1; $currentAttempt <= $attempts; ++$currentAttempt) { $this->beginTransaction(); // We'll simply execute the given callback within a try / catch block and if we // catch any exception we can rollback this transaction so that none of this // gets actually persisted to a database or stored in a permanent fashion. try { return tap($callback($this), function ($result) { $this->commit(); }); } // If we catch an exception we'll rollback this transaction and try again if we // are not out of attempts. If we are out of attempts we will just throw the // exception back out and let the developer handle an uncaught exceptions. catch (Exception $e) { $this->handleTransactionException( $e, $currentAttempt, $attempts ); } catch (Throwable $e) { $this->rollBack(); throw $e; } } }
[ "public", "function", "transaction", "(", "Closure", "$", "callback", ",", "$", "attempts", "=", "1", ")", "{", "for", "(", "$", "currentAttempt", "=", "1", ";", "$", "currentAttempt", "<=", "$", "attempts", ";", "++", "$", "currentAttempt", ")", "{", "$", "this", "->", "beginTransaction", "(", ")", ";", "// We'll simply execute the given callback within a try / catch block and if we", "// catch any exception we can rollback this transaction so that none of this", "// gets actually persisted to a database or stored in a permanent fashion.", "try", "{", "return", "tap", "(", "$", "callback", "(", "$", "this", ")", ",", "function", "(", "$", "result", ")", "{", "$", "this", "->", "commit", "(", ")", ";", "}", ")", ";", "}", "// If we catch an exception we'll rollback this transaction and try again if we", "// are not out of attempts. If we are out of attempts we will just throw the", "// exception back out and let the developer handle an uncaught exceptions.", "catch", "(", "Exception", "$", "e", ")", "{", "$", "this", "->", "handleTransactionException", "(", "$", "e", ",", "$", "currentAttempt", ",", "$", "attempts", ")", ";", "}", "catch", "(", "Throwable", "$", "e", ")", "{", "$", "this", "->", "rollBack", "(", ")", ";", "throw", "$", "e", ";", "}", "}", "}" ]
Execute a Closure within a transaction. @param \Closure $callback @param int $attempts @throws \Exception|\Throwable @return mixed
[ "Execute", "a", "Closure", "within", "a", "transaction", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Concerns/ManagesTransactions.php#L21-L50
zhouyl/mellivora
Mellivora/Database/Concerns/ManagesTransactions.php
ManagesTransactions.handleTransactionException
protected function handleTransactionException($e, $currentAttempt, $maxAttempts) { // On a deadlock, MySQL rolls back the entire transaction so we can't just // retry the query. We have to throw this exception all the way out and // let the developer handle it in another way. We will decrement too. if ($this->causedByDeadlock($e) && $this->transactions > 1) { --$this->transactions; throw $e; } // If there was an exception we will rollback this transaction and then we // can check if we have exceeded the maximum attempt count for this and // if we haven't we will return and try this query again in our loop. $this->rollBack(); if ($this->causedByDeadlock($e) && $currentAttempt < $maxAttempts) { return; } throw $e; }
php
protected function handleTransactionException($e, $currentAttempt, $maxAttempts) { // On a deadlock, MySQL rolls back the entire transaction so we can't just // retry the query. We have to throw this exception all the way out and // let the developer handle it in another way. We will decrement too. if ($this->causedByDeadlock($e) && $this->transactions > 1) { --$this->transactions; throw $e; } // If there was an exception we will rollback this transaction and then we // can check if we have exceeded the maximum attempt count for this and // if we haven't we will return and try this query again in our loop. $this->rollBack(); if ($this->causedByDeadlock($e) && $currentAttempt < $maxAttempts) { return; } throw $e; }
[ "protected", "function", "handleTransactionException", "(", "$", "e", ",", "$", "currentAttempt", ",", "$", "maxAttempts", ")", "{", "// On a deadlock, MySQL rolls back the entire transaction so we can't just", "// retry the query. We have to throw this exception all the way out and", "// let the developer handle it in another way. We will decrement too.", "if", "(", "$", "this", "->", "causedByDeadlock", "(", "$", "e", ")", "&&", "$", "this", "->", "transactions", ">", "1", ")", "{", "--", "$", "this", "->", "transactions", ";", "throw", "$", "e", ";", "}", "// If there was an exception we will rollback this transaction and then we", "// can check if we have exceeded the maximum attempt count for this and", "// if we haven't we will return and try this query again in our loop.", "$", "this", "->", "rollBack", "(", ")", ";", "if", "(", "$", "this", "->", "causedByDeadlock", "(", "$", "e", ")", "&&", "$", "currentAttempt", "<", "$", "maxAttempts", ")", "{", "return", ";", "}", "throw", "$", "e", ";", "}" ]
Handle an exception encountered when running a transacted statement. @param \Exception $e @param int $currentAttempt @param int $maxAttempts @throws \Exception @return void
[ "Handle", "an", "exception", "encountered", "when", "running", "a", "transacted", "statement", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Concerns/ManagesTransactions.php#L63-L86
zhouyl/mellivora
Mellivora/Database/Concerns/ManagesTransactions.php
ManagesTransactions.createTransaction
protected function createTransaction() { if ($this->transactions === 0) { try { $this->getPdo()->beginTransaction(); } catch (Exception $e) { $this->handleBeginTransactionException($e); } } elseif ($this->transactions >= 1 && $this->queryGrammar->supportsSavepoints()) { $this->createSavepoint(); } }
php
protected function createTransaction() { if ($this->transactions === 0) { try { $this->getPdo()->beginTransaction(); } catch (Exception $e) { $this->handleBeginTransactionException($e); } } elseif ($this->transactions >= 1 && $this->queryGrammar->supportsSavepoints()) { $this->createSavepoint(); } }
[ "protected", "function", "createTransaction", "(", ")", "{", "if", "(", "$", "this", "->", "transactions", "===", "0", ")", "{", "try", "{", "$", "this", "->", "getPdo", "(", ")", "->", "beginTransaction", "(", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "this", "->", "handleBeginTransactionException", "(", "$", "e", ")", ";", "}", "}", "elseif", "(", "$", "this", "->", "transactions", ">=", "1", "&&", "$", "this", "->", "queryGrammar", "->", "supportsSavepoints", "(", ")", ")", "{", "$", "this", "->", "createSavepoint", "(", ")", ";", "}", "}" ]
Create a transaction within the database. @return void
[ "Create", "a", "transaction", "within", "the", "database", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Concerns/ManagesTransactions.php#L109-L120
zhouyl/mellivora
Mellivora/Database/Concerns/ManagesTransactions.php
ManagesTransactions.rollBack
public function rollBack($toLevel = null) { // We allow developers to rollback to a certain transaction level. We will verify // that this given transaction level is valid before attempting to rollback to // that level. If it's not we will just return out and not attempt anything. $toLevel = is_null($toLevel) ? $this->transactions - 1 : $toLevel; if ($toLevel < 0 || $toLevel >= $this->transactions) { return; } // Next, we will actually perform this rollback within this database and fire the // rollback event. We will also set the current transaction level to the given // level that was passed into this method so it will be right from here out. $this->performRollBack($toLevel); $this->transactions = $toLevel; $this->fireConnectionEvent('rollingBack'); }
php
public function rollBack($toLevel = null) { // We allow developers to rollback to a certain transaction level. We will verify // that this given transaction level is valid before attempting to rollback to // that level. If it's not we will just return out and not attempt anything. $toLevel = is_null($toLevel) ? $this->transactions - 1 : $toLevel; if ($toLevel < 0 || $toLevel >= $this->transactions) { return; } // Next, we will actually perform this rollback within this database and fire the // rollback event. We will also set the current transaction level to the given // level that was passed into this method so it will be right from here out. $this->performRollBack($toLevel); $this->transactions = $toLevel; $this->fireConnectionEvent('rollingBack'); }
[ "public", "function", "rollBack", "(", "$", "toLevel", "=", "null", ")", "{", "// We allow developers to rollback to a certain transaction level. We will verify", "// that this given transaction level is valid before attempting to rollback to", "// that level. If it's not we will just return out and not attempt anything.", "$", "toLevel", "=", "is_null", "(", "$", "toLevel", ")", "?", "$", "this", "->", "transactions", "-", "1", ":", "$", "toLevel", ";", "if", "(", "$", "toLevel", "<", "0", "||", "$", "toLevel", ">=", "$", "this", "->", "transactions", ")", "{", "return", ";", "}", "// Next, we will actually perform this rollback within this database and fire the", "// rollback event. We will also set the current transaction level to the given", "// level that was passed into this method so it will be right from here out.", "$", "this", "->", "performRollBack", "(", "$", "toLevel", ")", ";", "$", "this", "->", "transactions", "=", "$", "toLevel", ";", "$", "this", "->", "fireConnectionEvent", "(", "'rollingBack'", ")", ";", "}" ]
Rollback the active database transaction. @param null|int $toLevel @return void
[ "Rollback", "the", "active", "database", "transaction", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Concerns/ManagesTransactions.php#L177-L198
zhouyl/mellivora
Mellivora/Database/Concerns/ManagesTransactions.php
ManagesTransactions.performRollBack
protected function performRollBack($toLevel) { if ($toLevel === 0) { $this->getPdo()->rollBack(); } elseif ($this->queryGrammar->supportsSavepoints()) { $this->getPdo()->exec( $this->queryGrammar->compileSavepointRollBack('trans' . ($toLevel + 1)) ); } }
php
protected function performRollBack($toLevel) { if ($toLevel === 0) { $this->getPdo()->rollBack(); } elseif ($this->queryGrammar->supportsSavepoints()) { $this->getPdo()->exec( $this->queryGrammar->compileSavepointRollBack('trans' . ($toLevel + 1)) ); } }
[ "protected", "function", "performRollBack", "(", "$", "toLevel", ")", "{", "if", "(", "$", "toLevel", "===", "0", ")", "{", "$", "this", "->", "getPdo", "(", ")", "->", "rollBack", "(", ")", ";", "}", "elseif", "(", "$", "this", "->", "queryGrammar", "->", "supportsSavepoints", "(", ")", ")", "{", "$", "this", "->", "getPdo", "(", ")", "->", "exec", "(", "$", "this", "->", "queryGrammar", "->", "compileSavepointRollBack", "(", "'trans'", ".", "(", "$", "toLevel", "+", "1", ")", ")", ")", ";", "}", "}" ]
Perform a rollback within the database. @param int $toLevel @return void
[ "Perform", "a", "rollback", "within", "the", "database", "." ]
train
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Concerns/ManagesTransactions.php#L207-L216
wenbinye/PhalconX
src/Mvc/Model.php
Model.findPk
public static function findPk($pk) { if (empty($pk)) { return false; } if (is_array($pk)) { $conditions = ''; $sep = ''; foreach ($pk as $name => $value) { $conditions .= $sep . "$name=:$name:"; $sep = ' AND '; } $pk = array( 'conditions' => $conditions, 'bind' => $pk ); } elseif ($pk instanceof Criteria) { $pk = $pk->getParams(); } return static::findFirst($pk); }
php
public static function findPk($pk) { if (empty($pk)) { return false; } if (is_array($pk)) { $conditions = ''; $sep = ''; foreach ($pk as $name => $value) { $conditions .= $sep . "$name=:$name:"; $sep = ' AND '; } $pk = array( 'conditions' => $conditions, 'bind' => $pk ); } elseif ($pk instanceof Criteria) { $pk = $pk->getParams(); } return static::findFirst($pk); }
[ "public", "static", "function", "findPk", "(", "$", "pk", ")", "{", "if", "(", "empty", "(", "$", "pk", ")", ")", "{", "return", "false", ";", "}", "if", "(", "is_array", "(", "$", "pk", ")", ")", "{", "$", "conditions", "=", "''", ";", "$", "sep", "=", "''", ";", "foreach", "(", "$", "pk", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "conditions", ".=", "$", "sep", ".", "\"$name=:$name:\"", ";", "$", "sep", "=", "' AND '", ";", "}", "$", "pk", "=", "array", "(", "'conditions'", "=>", "$", "conditions", ",", "'bind'", "=>", "$", "pk", ")", ";", "}", "elseif", "(", "$", "pk", "instanceof", "Criteria", ")", "{", "$", "pk", "=", "$", "pk", "->", "getParams", "(", ")", ";", "}", "return", "static", "::", "findFirst", "(", "$", "pk", ")", ";", "}" ]
Finds model by primary key @param string|array
[ "Finds", "model", "by", "primary", "key" ]
train
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Mvc/Model.php#L16-L36
wenbinye/PhalconX
src/Mvc/Model.php
Model.isChanged
public function isChanged() { $snapshot = $this->_snapshot; if (!is_array($snapshot)) { return true; } $metadata = $this->getModelsMetaData(); $attrs = $metadata->getNonPrimaryKeyAttributes($this); $automatic = $metadata->getAutomaticUpdateAttributes($this); $bindDataTypes = $metadata->getBindTypes($this); foreach ($attrs as $name) { if (isset($automatic[$name])) { continue; } $value = $this->readAttribute($name); $snapshotValue = ArrayHelper::fetch($snapshot, $name); if ($value === null) { if ($snapshotValue !== null) { return true; } } else { if ($snapshotValue === null) { return true; } $bindType = ArrayHelper::fetch($bindDataTypes, $name); switch ($bindType) { case Column::TYPE_DATE: case Column::TYPE_VARCHAR: case Column::TYPE_DATETIME: case Column::TYPE_CHAR: case Column::TYPE_TEXT: case Column::TYPE_VARCHAR: case Column::TYPE_BIGINTEGER: if (((string)$value) !== ((string)$snapshotValue)) { return true; } break; default: if ($value != $snapshotValue) { return true; } } } } return false; }
php
public function isChanged() { $snapshot = $this->_snapshot; if (!is_array($snapshot)) { return true; } $metadata = $this->getModelsMetaData(); $attrs = $metadata->getNonPrimaryKeyAttributes($this); $automatic = $metadata->getAutomaticUpdateAttributes($this); $bindDataTypes = $metadata->getBindTypes($this); foreach ($attrs as $name) { if (isset($automatic[$name])) { continue; } $value = $this->readAttribute($name); $snapshotValue = ArrayHelper::fetch($snapshot, $name); if ($value === null) { if ($snapshotValue !== null) { return true; } } else { if ($snapshotValue === null) { return true; } $bindType = ArrayHelper::fetch($bindDataTypes, $name); switch ($bindType) { case Column::TYPE_DATE: case Column::TYPE_VARCHAR: case Column::TYPE_DATETIME: case Column::TYPE_CHAR: case Column::TYPE_TEXT: case Column::TYPE_VARCHAR: case Column::TYPE_BIGINTEGER: if (((string)$value) !== ((string)$snapshotValue)) { return true; } break; default: if ($value != $snapshotValue) { return true; } } } } return false; }
[ "public", "function", "isChanged", "(", ")", "{", "$", "snapshot", "=", "$", "this", "->", "_snapshot", ";", "if", "(", "!", "is_array", "(", "$", "snapshot", ")", ")", "{", "return", "true", ";", "}", "$", "metadata", "=", "$", "this", "->", "getModelsMetaData", "(", ")", ";", "$", "attrs", "=", "$", "metadata", "->", "getNonPrimaryKeyAttributes", "(", "$", "this", ")", ";", "$", "automatic", "=", "$", "metadata", "->", "getAutomaticUpdateAttributes", "(", "$", "this", ")", ";", "$", "bindDataTypes", "=", "$", "metadata", "->", "getBindTypes", "(", "$", "this", ")", ";", "foreach", "(", "$", "attrs", "as", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "automatic", "[", "$", "name", "]", ")", ")", "{", "continue", ";", "}", "$", "value", "=", "$", "this", "->", "readAttribute", "(", "$", "name", ")", ";", "$", "snapshotValue", "=", "ArrayHelper", "::", "fetch", "(", "$", "snapshot", ",", "$", "name", ")", ";", "if", "(", "$", "value", "===", "null", ")", "{", "if", "(", "$", "snapshotValue", "!==", "null", ")", "{", "return", "true", ";", "}", "}", "else", "{", "if", "(", "$", "snapshotValue", "===", "null", ")", "{", "return", "true", ";", "}", "$", "bindType", "=", "ArrayHelper", "::", "fetch", "(", "$", "bindDataTypes", ",", "$", "name", ")", ";", "switch", "(", "$", "bindType", ")", "{", "case", "Column", "::", "TYPE_DATE", ":", "case", "Column", "::", "TYPE_VARCHAR", ":", "case", "Column", "::", "TYPE_DATETIME", ":", "case", "Column", "::", "TYPE_CHAR", ":", "case", "Column", "::", "TYPE_TEXT", ":", "case", "Column", "::", "TYPE_VARCHAR", ":", "case", "Column", "::", "TYPE_BIGINTEGER", ":", "if", "(", "(", "(", "string", ")", "$", "value", ")", "!==", "(", "(", "string", ")", "$", "snapshotValue", ")", ")", "{", "return", "true", ";", "}", "break", ";", "default", ":", "if", "(", "$", "value", "!=", "$", "snapshotValue", ")", "{", "return", "true", ";", "}", "}", "}", "}", "return", "false", ";", "}" ]
Checks whether the model changes @return bool
[ "Checks", "whether", "the", "model", "changes" ]
train
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Mvc/Model.php#L43-L88
nabab/bbn
src/bbn/db.php
db._get_cache
private function _get_cache($item, $mode = 'columns', $force = false): ?array { $cache_name = $this->_db_cache_name($item, $mode); if ( $force && isset($this->cache[$cache_name]) ){ unset($this->cache[$cache_name]); } if ( !isset($this->cache[$cache_name]) ){ if ( $force || !($tmp = $this->cache_get($cache_name)) ){ switch ( $mode ){ case 'columns': $keys = $this->language->get_keys($item); $cols = $this->language->get_columns($item); if ( \is_array($keys) && \is_array($cols) ){ $tmp = [ 'keys' => $keys['keys'], 'cols' => $keys['cols'], 'fields' => $cols ]; } break; case 'tables': $tmp = $this->language->get_tables($item); break; case 'databases': $tmp = $this->language->get_databases(); break; } if ( !\is_array($tmp) ){ die("Error while creating the cache for the table $item in mode $mode"); } if ( $tmp ){ $this->cache_set($cache_name, '', $tmp, $this->cache_renewal); } } if ( $tmp ){ $this->cache[$cache_name] = $tmp; } } return $this->cache[$cache_name] ?? null; }
php
private function _get_cache($item, $mode = 'columns', $force = false): ?array { $cache_name = $this->_db_cache_name($item, $mode); if ( $force && isset($this->cache[$cache_name]) ){ unset($this->cache[$cache_name]); } if ( !isset($this->cache[$cache_name]) ){ if ( $force || !($tmp = $this->cache_get($cache_name)) ){ switch ( $mode ){ case 'columns': $keys = $this->language->get_keys($item); $cols = $this->language->get_columns($item); if ( \is_array($keys) && \is_array($cols) ){ $tmp = [ 'keys' => $keys['keys'], 'cols' => $keys['cols'], 'fields' => $cols ]; } break; case 'tables': $tmp = $this->language->get_tables($item); break; case 'databases': $tmp = $this->language->get_databases(); break; } if ( !\is_array($tmp) ){ die("Error while creating the cache for the table $item in mode $mode"); } if ( $tmp ){ $this->cache_set($cache_name, '', $tmp, $this->cache_renewal); } } if ( $tmp ){ $this->cache[$cache_name] = $tmp; } } return $this->cache[$cache_name] ?? null; }
[ "private", "function", "_get_cache", "(", "$", "item", ",", "$", "mode", "=", "'columns'", ",", "$", "force", "=", "false", ")", ":", "?", "array", "{", "$", "cache_name", "=", "$", "this", "->", "_db_cache_name", "(", "$", "item", ",", "$", "mode", ")", ";", "if", "(", "$", "force", "&&", "isset", "(", "$", "this", "->", "cache", "[", "$", "cache_name", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "cache", "[", "$", "cache_name", "]", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "cache", "[", "$", "cache_name", "]", ")", ")", "{", "if", "(", "$", "force", "||", "!", "(", "$", "tmp", "=", "$", "this", "->", "cache_get", "(", "$", "cache_name", ")", ")", ")", "{", "switch", "(", "$", "mode", ")", "{", "case", "'columns'", ":", "$", "keys", "=", "$", "this", "->", "language", "->", "get_keys", "(", "$", "item", ")", ";", "$", "cols", "=", "$", "this", "->", "language", "->", "get_columns", "(", "$", "item", ")", ";", "if", "(", "\\", "is_array", "(", "$", "keys", ")", "&&", "\\", "is_array", "(", "$", "cols", ")", ")", "{", "$", "tmp", "=", "[", "'keys'", "=>", "$", "keys", "[", "'keys'", "]", ",", "'cols'", "=>", "$", "keys", "[", "'cols'", "]", ",", "'fields'", "=>", "$", "cols", "]", ";", "}", "break", ";", "case", "'tables'", ":", "$", "tmp", "=", "$", "this", "->", "language", "->", "get_tables", "(", "$", "item", ")", ";", "break", ";", "case", "'databases'", ":", "$", "tmp", "=", "$", "this", "->", "language", "->", "get_databases", "(", ")", ";", "break", ";", "}", "if", "(", "!", "\\", "is_array", "(", "$", "tmp", ")", ")", "{", "die", "(", "\"Error while creating the cache for the table $item in mode $mode\"", ")", ";", "}", "if", "(", "$", "tmp", ")", "{", "$", "this", "->", "cache_set", "(", "$", "cache_name", ",", "''", ",", "$", "tmp", ",", "$", "this", "->", "cache_renewal", ")", ";", "}", "}", "if", "(", "$", "tmp", ")", "{", "$", "this", "->", "cache", "[", "$", "cache_name", "]", "=", "$", "tmp", ";", "}", "}", "return", "$", "this", "->", "cache", "[", "$", "cache_name", "]", "??", "null", ";", "}" ]
Return the table's structure's array, either from the cache or from _modelize(). @param $item @param string $mode @param bool $force @return array|null
[ "Return", "the", "table", "s", "structure", "s", "array", "either", "from", "the", "cache", "or", "from", "_modelize", "()", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L244-L283
nabab/bbn
src/bbn/db.php
db._add_query
private function _add_query($hash, $statement, $kind, $placeholders, $options) { $this->queries[$hash] = [ 'sql' => $statement, 'kind' => $kind, 'write' => \in_array($kind, self::$write_kinds, true), 'structure' => \in_array($kind, self::$structure_kinds, true), 'placeholders' => $placeholders, 'options' => $options, 'num' => 0, 'exe_time' => 0, 'first' => microtime(true), 'last' => 0, 'prepared' => false ]; // Removing queries from global object when there are more than max_queries while ( \count($this->queries) > $this->max_queries ){ $max = 0; $index = null; foreach ( $this->queries as $k => $v ){ if ( \is_array($v) && ($v['last'] > $max) ){ $max = $v['last']; $index = $k; } } if ( null !== $index ){ unset($this->queries[$index]); } } }
php
private function _add_query($hash, $statement, $kind, $placeholders, $options) { $this->queries[$hash] = [ 'sql' => $statement, 'kind' => $kind, 'write' => \in_array($kind, self::$write_kinds, true), 'structure' => \in_array($kind, self::$structure_kinds, true), 'placeholders' => $placeholders, 'options' => $options, 'num' => 0, 'exe_time' => 0, 'first' => microtime(true), 'last' => 0, 'prepared' => false ]; // Removing queries from global object when there are more than max_queries while ( \count($this->queries) > $this->max_queries ){ $max = 0; $index = null; foreach ( $this->queries as $k => $v ){ if ( \is_array($v) && ($v['last'] > $max) ){ $max = $v['last']; $index = $k; } } if ( null !== $index ){ unset($this->queries[$index]); } } }
[ "private", "function", "_add_query", "(", "$", "hash", ",", "$", "statement", ",", "$", "kind", ",", "$", "placeholders", ",", "$", "options", ")", "{", "$", "this", "->", "queries", "[", "$", "hash", "]", "=", "[", "'sql'", "=>", "$", "statement", ",", "'kind'", "=>", "$", "kind", ",", "'write'", "=>", "\\", "in_array", "(", "$", "kind", ",", "self", "::", "$", "write_kinds", ",", "true", ")", ",", "'structure'", "=>", "\\", "in_array", "(", "$", "kind", ",", "self", "::", "$", "structure_kinds", ",", "true", ")", ",", "'placeholders'", "=>", "$", "placeholders", ",", "'options'", "=>", "$", "options", ",", "'num'", "=>", "0", ",", "'exe_time'", "=>", "0", ",", "'first'", "=>", "microtime", "(", "true", ")", ",", "'last'", "=>", "0", ",", "'prepared'", "=>", "false", "]", ";", "// Removing queries from global object when there are more than max_queries", "while", "(", "\\", "count", "(", "$", "this", "->", "queries", ")", ">", "$", "this", "->", "max_queries", ")", "{", "$", "max", "=", "0", ";", "$", "index", "=", "null", ";", "foreach", "(", "$", "this", "->", "queries", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "\\", "is_array", "(", "$", "v", ")", "&&", "(", "$", "v", "[", "'last'", "]", ">", "$", "max", ")", ")", "{", "$", "max", "=", "$", "v", "[", "'last'", "]", ";", "$", "index", "=", "$", "k", ";", "}", "}", "if", "(", "null", "!==", "$", "index", ")", "{", "unset", "(", "$", "this", "->", "queries", "[", "$", "index", "]", ")", ";", "}", "}", "}" ]
Adds the specs of a query to the $queries object. @param string $hash The hash of the statement. @param string $statement The SQL full statement. @param string $kind The type of statement. @param int $placeholders The number of placeholders. @param array $options The driver options.
[ "Adds", "the", "specs", "of", "a", "query", "to", "the", "$queries", "object", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L320-L349
nabab/bbn
src/bbn/db.php
db._make_hash
private function _make_hash(): string { $args = \func_get_args(); if ( (\count($args) === 1) && \is_array($args[0]) ){ $args = $args[0]; } $st = ''; foreach ( $args as $a ){ $st .= \is_array($a) ? serialize($a) : '--'.$a.'--'; } return $this->hash_contour.md5($st).$this->hash_contour; }
php
private function _make_hash(): string { $args = \func_get_args(); if ( (\count($args) === 1) && \is_array($args[0]) ){ $args = $args[0]; } $st = ''; foreach ( $args as $a ){ $st .= \is_array($a) ? serialize($a) : '--'.$a.'--'; } return $this->hash_contour.md5($st).$this->hash_contour; }
[ "private", "function", "_make_hash", "(", ")", ":", "string", "{", "$", "args", "=", "\\", "func_get_args", "(", ")", ";", "if", "(", "(", "\\", "count", "(", "$", "args", ")", "===", "1", ")", "&&", "\\", "is_array", "(", "$", "args", "[", "0", "]", ")", ")", "{", "$", "args", "=", "$", "args", "[", "0", "]", ";", "}", "$", "st", "=", "''", ";", "foreach", "(", "$", "args", "as", "$", "a", ")", "{", "$", "st", ".=", "\\", "is_array", "(", "$", "a", ")", "?", "serialize", "(", "$", "a", ")", ":", "'--'", ".", "$", "a", ".", "'--'", ";", "}", "return", "$", "this", "->", "hash_contour", ".", "md5", "(", "$", "st", ")", ".", "$", "this", "->", "hash_contour", ";", "}" ]
Makes a string that will be the id of the request. @return string
[ "Makes", "a", "string", "that", "will", "be", "the", "id", "of", "the", "request", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L357-L368
nabab/bbn
src/bbn/db.php
db._trigger
private function _trigger(array $cfg): array { if ( $this->triggers_disabled ){ $cfg['run'] = 1; $cfg['trig'] = 1; return $cfg; } if ( !isset($cfg['trig']) ){ $cfg['trig'] = 1; } if ( !isset($cfg['run']) ){ $cfg['run'] = 1; } if ( !empty($cfg['tables']) && !empty($this->triggers[$cfg['kind']][$cfg['moment']]) ){ $table = $this->tfn(\is_array($cfg['tables']) ? current($cfg['tables']) : $cfg['tables']); // Specific to a table if ( isset($this->triggers[$cfg['kind']][$cfg['moment']][$table]) ){ foreach ( $this->triggers[$cfg['kind']][$cfg['moment']][$table] as $i => $f ){ if ( $f && \is_callable($f) ){ if ( !($tmp = $f($cfg)) ){ $cfg['run'] = false; $cfg['trig'] = false; } else{ $cfg = $tmp; } } } //echo bbn\x::make_tree($trig); //echo x::make_tree($cfg); } } return $cfg; }
php
private function _trigger(array $cfg): array { if ( $this->triggers_disabled ){ $cfg['run'] = 1; $cfg['trig'] = 1; return $cfg; } if ( !isset($cfg['trig']) ){ $cfg['trig'] = 1; } if ( !isset($cfg['run']) ){ $cfg['run'] = 1; } if ( !empty($cfg['tables']) && !empty($this->triggers[$cfg['kind']][$cfg['moment']]) ){ $table = $this->tfn(\is_array($cfg['tables']) ? current($cfg['tables']) : $cfg['tables']); // Specific to a table if ( isset($this->triggers[$cfg['kind']][$cfg['moment']][$table]) ){ foreach ( $this->triggers[$cfg['kind']][$cfg['moment']][$table] as $i => $f ){ if ( $f && \is_callable($f) ){ if ( !($tmp = $f($cfg)) ){ $cfg['run'] = false; $cfg['trig'] = false; } else{ $cfg = $tmp; } } } //echo bbn\x::make_tree($trig); //echo x::make_tree($cfg); } } return $cfg; }
[ "private", "function", "_trigger", "(", "array", "$", "cfg", ")", ":", "array", "{", "if", "(", "$", "this", "->", "triggers_disabled", ")", "{", "$", "cfg", "[", "'run'", "]", "=", "1", ";", "$", "cfg", "[", "'trig'", "]", "=", "1", ";", "return", "$", "cfg", ";", "}", "if", "(", "!", "isset", "(", "$", "cfg", "[", "'trig'", "]", ")", ")", "{", "$", "cfg", "[", "'trig'", "]", "=", "1", ";", "}", "if", "(", "!", "isset", "(", "$", "cfg", "[", "'run'", "]", ")", ")", "{", "$", "cfg", "[", "'run'", "]", "=", "1", ";", "}", "if", "(", "!", "empty", "(", "$", "cfg", "[", "'tables'", "]", ")", "&&", "!", "empty", "(", "$", "this", "->", "triggers", "[", "$", "cfg", "[", "'kind'", "]", "]", "[", "$", "cfg", "[", "'moment'", "]", "]", ")", ")", "{", "$", "table", "=", "$", "this", "->", "tfn", "(", "\\", "is_array", "(", "$", "cfg", "[", "'tables'", "]", ")", "?", "current", "(", "$", "cfg", "[", "'tables'", "]", ")", ":", "$", "cfg", "[", "'tables'", "]", ")", ";", "// Specific to a table", "if", "(", "isset", "(", "$", "this", "->", "triggers", "[", "$", "cfg", "[", "'kind'", "]", "]", "[", "$", "cfg", "[", "'moment'", "]", "]", "[", "$", "table", "]", ")", ")", "{", "foreach", "(", "$", "this", "->", "triggers", "[", "$", "cfg", "[", "'kind'", "]", "]", "[", "$", "cfg", "[", "'moment'", "]", "]", "[", "$", "table", "]", "as", "$", "i", "=>", "$", "f", ")", "{", "if", "(", "$", "f", "&&", "\\", "is_callable", "(", "$", "f", ")", ")", "{", "if", "(", "!", "(", "$", "tmp", "=", "$", "f", "(", "$", "cfg", ")", ")", ")", "{", "$", "cfg", "[", "'run'", "]", "=", "false", ";", "$", "cfg", "[", "'trig'", "]", "=", "false", ";", "}", "else", "{", "$", "cfg", "=", "$", "tmp", ";", "}", "}", "}", "//echo bbn\\x::make_tree($trig);", "//echo x::make_tree($cfg);", "}", "}", "return", "$", "cfg", ";", "}" ]
Launches a function before or after @param array $cfg @return array
[ "Launches", "a", "function", "before", "or", "after" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L376-L410
nabab/bbn
src/bbn/db.php
db._add_primary
private function _add_primary(array &$cfg): void { // Inserting a row without primary when primary is needed and no auto-increment if ( !empty($cfg['primary']) && empty($cfg['auto_increment']) && (($idx = array_search($cfg['primary'], $cfg['fields'], true)) > -1) && (count($cfg['values']) === (count($cfg['fields']) - 1)) ){ $val = false; switch ( $cfg['primary_type'] ){ case 'int': $val = random_int( ceil(10 ** ($cfg['primary_length'] > 3 ? $cfg['primary_length'] - 3 : 1) / 2), ceil(10 ** ($cfg['primary_length'] > 3 ? $cfg['primary_length'] : 1) / 2) ); break; case 'binary': if ( $cfg['primary_length'] === 16 ){ x::log($cfg['tables'], 'add_options'); $val = $this->get_uid(); x::log($val, 'add_options'); } break; } if ( $val ){ array_splice($cfg['values'], $idx, 0, $val); $this->set_last_insert_id($val); x::log(['v' => $cfg['values'], 'f' => $cfg['fields']], 'add_options'); } } }
php
private function _add_primary(array &$cfg): void { // Inserting a row without primary when primary is needed and no auto-increment if ( !empty($cfg['primary']) && empty($cfg['auto_increment']) && (($idx = array_search($cfg['primary'], $cfg['fields'], true)) > -1) && (count($cfg['values']) === (count($cfg['fields']) - 1)) ){ $val = false; switch ( $cfg['primary_type'] ){ case 'int': $val = random_int( ceil(10 ** ($cfg['primary_length'] > 3 ? $cfg['primary_length'] - 3 : 1) / 2), ceil(10 ** ($cfg['primary_length'] > 3 ? $cfg['primary_length'] : 1) / 2) ); break; case 'binary': if ( $cfg['primary_length'] === 16 ){ x::log($cfg['tables'], 'add_options'); $val = $this->get_uid(); x::log($val, 'add_options'); } break; } if ( $val ){ array_splice($cfg['values'], $idx, 0, $val); $this->set_last_insert_id($val); x::log(['v' => $cfg['values'], 'f' => $cfg['fields']], 'add_options'); } } }
[ "private", "function", "_add_primary", "(", "array", "&", "$", "cfg", ")", ":", "void", "{", "// Inserting a row without primary when primary is needed and no auto-increment", "if", "(", "!", "empty", "(", "$", "cfg", "[", "'primary'", "]", ")", "&&", "empty", "(", "$", "cfg", "[", "'auto_increment'", "]", ")", "&&", "(", "(", "$", "idx", "=", "array_search", "(", "$", "cfg", "[", "'primary'", "]", ",", "$", "cfg", "[", "'fields'", "]", ",", "true", ")", ")", ">", "-", "1", ")", "&&", "(", "count", "(", "$", "cfg", "[", "'values'", "]", ")", "===", "(", "count", "(", "$", "cfg", "[", "'fields'", "]", ")", "-", "1", ")", ")", ")", "{", "$", "val", "=", "false", ";", "switch", "(", "$", "cfg", "[", "'primary_type'", "]", ")", "{", "case", "'int'", ":", "$", "val", "=", "random_int", "(", "ceil", "(", "10", "**", "(", "$", "cfg", "[", "'primary_length'", "]", ">", "3", "?", "$", "cfg", "[", "'primary_length'", "]", "-", "3", ":", "1", ")", "/", "2", ")", ",", "ceil", "(", "10", "**", "(", "$", "cfg", "[", "'primary_length'", "]", ">", "3", "?", "$", "cfg", "[", "'primary_length'", "]", ":", "1", ")", "/", "2", ")", ")", ";", "break", ";", "case", "'binary'", ":", "if", "(", "$", "cfg", "[", "'primary_length'", "]", "===", "16", ")", "{", "x", "::", "log", "(", "$", "cfg", "[", "'tables'", "]", ",", "'add_options'", ")", ";", "$", "val", "=", "$", "this", "->", "get_uid", "(", ")", ";", "x", "::", "log", "(", "$", "val", ",", "'add_options'", ")", ";", "}", "break", ";", "}", "if", "(", "$", "val", ")", "{", "array_splice", "(", "$", "cfg", "[", "'values'", "]", ",", "$", "idx", ",", "0", ",", "$", "val", ")", ";", "$", "this", "->", "set_last_insert_id", "(", "$", "val", ")", ";", "x", "::", "log", "(", "[", "'v'", "=>", "$", "cfg", "[", "'values'", "]", ",", "'f'", "=>", "$", "cfg", "[", "'fields'", "]", "]", ",", "'add_options'", ")", ";", "}", "}", "}" ]
Adds a random primary value when it is absent from the set and present in the fields @param array $cfg
[ "Adds", "a", "random", "primary", "value", "when", "it", "is", "absent", "from", "the", "set", "and", "present", "in", "the", "fields" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L436-L467
nabab/bbn
src/bbn/db.php
db._treat_arguments
private function _treat_arguments($cfg): array { while ( isset($cfg[0]) && \is_array($cfg[0]) ){ $cfg = $cfg[0]; } if ( \is_array($cfg) && array_key_exists('tables', $cfg) && !empty($cfg['bbn_db_treated']) && ($cfg['bbn_db_treated'] === true) ){ return $cfg; } $res = [ 'kind' => 'SELECT', 'fields' => [], 'where' => [], 'order' => [], 'limit' => 0, 'start' => 0, 'group_by' => [], 'having' => [], ]; if ( x::is_assoc($cfg) ){ if ( isset($cfg['table']) && !isset($cfg['tables']) ){ $cfg['tables'] = $cfg['table']; unset($cfg['table']); } $res = array_merge($res, $cfg); } else if ( count($cfg) > 1 ){ $res['kind'] = strtoupper($cfg[0]); $res['tables'] = $cfg[1]; if ( isset($cfg[2]) ){ $res['fields'] = $cfg[2]; } if ( isset($cfg[3]) ){ $res['where'] = $cfg[3]; } if ( isset($cfg[4]) ){ $res['order'] = \is_string($cfg[4]) ? [$cfg[4] => 'ASC'] : $cfg[4]; } if ( isset($cfg[5]) && str::is_integer($cfg[5]) ) { $res['limit'] = $cfg[5]; } if ( isset($cfg[6]) && !empty($res['limit']) ){ $res['start'] = $cfg[6]; } } $res = array_merge($res, [ 'values' => [], 'filters' => [], 'join' => [], 'hashed_join' => [], 'hashed_where' => [], 'hashed_having' => [], 'bbn_db_treated' => true ]); $res['kind'] = strtoupper($res['kind']); $res['write'] = \in_array($res['kind'], self::$write_kinds, true); $res['ignore'] = $res['write'] && !empty($res['ignore']); $res['count'] = !$res['write'] && !empty($res['count']); if ( !\is_array($res['tables']) ){ $res['tables'] = \is_string($res['tables']) ? [$res['tables']] : []; } if ( !empty($res['tables']) ){ foreach ( $res['tables'] as &$t ){ $t = $this->tfn($t); } unset($t); } else{ return []; } if ( !empty($res['fields']) ){ if ( \is_string($res['fields']) ){ $res['fields'] = [$res['fields']]; } } else if ( !empty($res['columns']) ){ $res['fields'] = (array)$res['columns']; } if ( !empty($res['fields']) && (($res['kind'] === 'INSERT') || ($res['kind'] === 'UPDATE')) && \is_string(array_keys($res['fields'])[0]) ){ $res['values'] = array_values($res['fields']); $res['fields'] = array_keys($res['fields']); } if ( !\is_array($res['group_by']) ){ $res['group_by'] = empty($res['group_by']) ? [] : [$res['group_by']]; } if ( !\is_array($res['where']) ){ $res['where'] = []; } if ( !\is_array($res['order']) ){ $res['order'] = \is_string($res['order']) ? [$res['order'] => 'ASC'] : []; } if ( !str::is_integer($res['limit']) ){ unset($res['limit']); } if ( !str::is_integer($res['start']) ){ unset($res['start']); } if ( !empty($cfg['join']) ){ foreach ( $cfg['join'] as $k => $join ){ if ( \is_array($join) ){ if ( \is_string($k) ){ if ( empty($join['table']) ){ $join['table'] = $k; } else if ( empty($join['alias']) ){ $join['alias'] = $k; } } if ( isset($join['table'], $join['on']) && ($tmp = $this->treat_conditions($join['on'])) ){ if ( !isset($join['type']) ){ $join['type'] = 'right'; } $res['join'][] = array_merge($join, ['on' => $tmp['where']]); $res['hashed_join'][] = $tmp['hashed']; if ( !empty($tmp['values']) ){ foreach ( $tmp['values'] as $v ){ $res['values'][] = $v; } } } } } } if ( $tmp = $this->treat_conditions($res['where']) ){ $res['filters'] = $tmp['where']; $res['hashed_where'] = $tmp['hashed']; if ( \is_array($tmp) && isset($tmp['values']) ){ foreach ( $tmp['values'] as $v ){ $res['values'][] = $v; } } } if ( !empty($res['having']) && ($tmp = $this->treat_conditions($res['having'])) ){ $res['having'] = $tmp['where']; $res['hashed_having'] = $tmp['hashed']; foreach ( $tmp['values'] as $v ){ $res['values'][] = $v; } } if ( empty($cfg['hash']) ){ $hash = $this->_make_hash( $res['kind'], $res['ignore'], $res['count'], $res['tables'], $res['fields'], $res['hashed_join'], $res['hashed_where'], $res['hashed_having'], $res['group_by'], $res['order'], $res['limit'] ?? 0, $res['start'] ?? 0 ); $res['hash'] = $hash; } else{ $res['hash'] = $cfg['hash']; } return $res; }
php
private function _treat_arguments($cfg): array { while ( isset($cfg[0]) && \is_array($cfg[0]) ){ $cfg = $cfg[0]; } if ( \is_array($cfg) && array_key_exists('tables', $cfg) && !empty($cfg['bbn_db_treated']) && ($cfg['bbn_db_treated'] === true) ){ return $cfg; } $res = [ 'kind' => 'SELECT', 'fields' => [], 'where' => [], 'order' => [], 'limit' => 0, 'start' => 0, 'group_by' => [], 'having' => [], ]; if ( x::is_assoc($cfg) ){ if ( isset($cfg['table']) && !isset($cfg['tables']) ){ $cfg['tables'] = $cfg['table']; unset($cfg['table']); } $res = array_merge($res, $cfg); } else if ( count($cfg) > 1 ){ $res['kind'] = strtoupper($cfg[0]); $res['tables'] = $cfg[1]; if ( isset($cfg[2]) ){ $res['fields'] = $cfg[2]; } if ( isset($cfg[3]) ){ $res['where'] = $cfg[3]; } if ( isset($cfg[4]) ){ $res['order'] = \is_string($cfg[4]) ? [$cfg[4] => 'ASC'] : $cfg[4]; } if ( isset($cfg[5]) && str::is_integer($cfg[5]) ) { $res['limit'] = $cfg[5]; } if ( isset($cfg[6]) && !empty($res['limit']) ){ $res['start'] = $cfg[6]; } } $res = array_merge($res, [ 'values' => [], 'filters' => [], 'join' => [], 'hashed_join' => [], 'hashed_where' => [], 'hashed_having' => [], 'bbn_db_treated' => true ]); $res['kind'] = strtoupper($res['kind']); $res['write'] = \in_array($res['kind'], self::$write_kinds, true); $res['ignore'] = $res['write'] && !empty($res['ignore']); $res['count'] = !$res['write'] && !empty($res['count']); if ( !\is_array($res['tables']) ){ $res['tables'] = \is_string($res['tables']) ? [$res['tables']] : []; } if ( !empty($res['tables']) ){ foreach ( $res['tables'] as &$t ){ $t = $this->tfn($t); } unset($t); } else{ return []; } if ( !empty($res['fields']) ){ if ( \is_string($res['fields']) ){ $res['fields'] = [$res['fields']]; } } else if ( !empty($res['columns']) ){ $res['fields'] = (array)$res['columns']; } if ( !empty($res['fields']) && (($res['kind'] === 'INSERT') || ($res['kind'] === 'UPDATE')) && \is_string(array_keys($res['fields'])[0]) ){ $res['values'] = array_values($res['fields']); $res['fields'] = array_keys($res['fields']); } if ( !\is_array($res['group_by']) ){ $res['group_by'] = empty($res['group_by']) ? [] : [$res['group_by']]; } if ( !\is_array($res['where']) ){ $res['where'] = []; } if ( !\is_array($res['order']) ){ $res['order'] = \is_string($res['order']) ? [$res['order'] => 'ASC'] : []; } if ( !str::is_integer($res['limit']) ){ unset($res['limit']); } if ( !str::is_integer($res['start']) ){ unset($res['start']); } if ( !empty($cfg['join']) ){ foreach ( $cfg['join'] as $k => $join ){ if ( \is_array($join) ){ if ( \is_string($k) ){ if ( empty($join['table']) ){ $join['table'] = $k; } else if ( empty($join['alias']) ){ $join['alias'] = $k; } } if ( isset($join['table'], $join['on']) && ($tmp = $this->treat_conditions($join['on'])) ){ if ( !isset($join['type']) ){ $join['type'] = 'right'; } $res['join'][] = array_merge($join, ['on' => $tmp['where']]); $res['hashed_join'][] = $tmp['hashed']; if ( !empty($tmp['values']) ){ foreach ( $tmp['values'] as $v ){ $res['values'][] = $v; } } } } } } if ( $tmp = $this->treat_conditions($res['where']) ){ $res['filters'] = $tmp['where']; $res['hashed_where'] = $tmp['hashed']; if ( \is_array($tmp) && isset($tmp['values']) ){ foreach ( $tmp['values'] as $v ){ $res['values'][] = $v; } } } if ( !empty($res['having']) && ($tmp = $this->treat_conditions($res['having'])) ){ $res['having'] = $tmp['where']; $res['hashed_having'] = $tmp['hashed']; foreach ( $tmp['values'] as $v ){ $res['values'][] = $v; } } if ( empty($cfg['hash']) ){ $hash = $this->_make_hash( $res['kind'], $res['ignore'], $res['count'], $res['tables'], $res['fields'], $res['hashed_join'], $res['hashed_where'], $res['hashed_having'], $res['group_by'], $res['order'], $res['limit'] ?? 0, $res['start'] ?? 0 ); $res['hash'] = $hash; } else{ $res['hash'] = $cfg['hash']; } return $res; }
[ "private", "function", "_treat_arguments", "(", "$", "cfg", ")", ":", "array", "{", "while", "(", "isset", "(", "$", "cfg", "[", "0", "]", ")", "&&", "\\", "is_array", "(", "$", "cfg", "[", "0", "]", ")", ")", "{", "$", "cfg", "=", "$", "cfg", "[", "0", "]", ";", "}", "if", "(", "\\", "is_array", "(", "$", "cfg", ")", "&&", "array_key_exists", "(", "'tables'", ",", "$", "cfg", ")", "&&", "!", "empty", "(", "$", "cfg", "[", "'bbn_db_treated'", "]", ")", "&&", "(", "$", "cfg", "[", "'bbn_db_treated'", "]", "===", "true", ")", ")", "{", "return", "$", "cfg", ";", "}", "$", "res", "=", "[", "'kind'", "=>", "'SELECT'", ",", "'fields'", "=>", "[", "]", ",", "'where'", "=>", "[", "]", ",", "'order'", "=>", "[", "]", ",", "'limit'", "=>", "0", ",", "'start'", "=>", "0", ",", "'group_by'", "=>", "[", "]", ",", "'having'", "=>", "[", "]", ",", "]", ";", "if", "(", "x", "::", "is_assoc", "(", "$", "cfg", ")", ")", "{", "if", "(", "isset", "(", "$", "cfg", "[", "'table'", "]", ")", "&&", "!", "isset", "(", "$", "cfg", "[", "'tables'", "]", ")", ")", "{", "$", "cfg", "[", "'tables'", "]", "=", "$", "cfg", "[", "'table'", "]", ";", "unset", "(", "$", "cfg", "[", "'table'", "]", ")", ";", "}", "$", "res", "=", "array_merge", "(", "$", "res", ",", "$", "cfg", ")", ";", "}", "else", "if", "(", "count", "(", "$", "cfg", ")", ">", "1", ")", "{", "$", "res", "[", "'kind'", "]", "=", "strtoupper", "(", "$", "cfg", "[", "0", "]", ")", ";", "$", "res", "[", "'tables'", "]", "=", "$", "cfg", "[", "1", "]", ";", "if", "(", "isset", "(", "$", "cfg", "[", "2", "]", ")", ")", "{", "$", "res", "[", "'fields'", "]", "=", "$", "cfg", "[", "2", "]", ";", "}", "if", "(", "isset", "(", "$", "cfg", "[", "3", "]", ")", ")", "{", "$", "res", "[", "'where'", "]", "=", "$", "cfg", "[", "3", "]", ";", "}", "if", "(", "isset", "(", "$", "cfg", "[", "4", "]", ")", ")", "{", "$", "res", "[", "'order'", "]", "=", "\\", "is_string", "(", "$", "cfg", "[", "4", "]", ")", "?", "[", "$", "cfg", "[", "4", "]", "=>", "'ASC'", "]", ":", "$", "cfg", "[", "4", "]", ";", "}", "if", "(", "isset", "(", "$", "cfg", "[", "5", "]", ")", "&&", "str", "::", "is_integer", "(", "$", "cfg", "[", "5", "]", ")", ")", "{", "$", "res", "[", "'limit'", "]", "=", "$", "cfg", "[", "5", "]", ";", "}", "if", "(", "isset", "(", "$", "cfg", "[", "6", "]", ")", "&&", "!", "empty", "(", "$", "res", "[", "'limit'", "]", ")", ")", "{", "$", "res", "[", "'start'", "]", "=", "$", "cfg", "[", "6", "]", ";", "}", "}", "$", "res", "=", "array_merge", "(", "$", "res", ",", "[", "'values'", "=>", "[", "]", ",", "'filters'", "=>", "[", "]", ",", "'join'", "=>", "[", "]", ",", "'hashed_join'", "=>", "[", "]", ",", "'hashed_where'", "=>", "[", "]", ",", "'hashed_having'", "=>", "[", "]", ",", "'bbn_db_treated'", "=>", "true", "]", ")", ";", "$", "res", "[", "'kind'", "]", "=", "strtoupper", "(", "$", "res", "[", "'kind'", "]", ")", ";", "$", "res", "[", "'write'", "]", "=", "\\", "in_array", "(", "$", "res", "[", "'kind'", "]", ",", "self", "::", "$", "write_kinds", ",", "true", ")", ";", "$", "res", "[", "'ignore'", "]", "=", "$", "res", "[", "'write'", "]", "&&", "!", "empty", "(", "$", "res", "[", "'ignore'", "]", ")", ";", "$", "res", "[", "'count'", "]", "=", "!", "$", "res", "[", "'write'", "]", "&&", "!", "empty", "(", "$", "res", "[", "'count'", "]", ")", ";", "if", "(", "!", "\\", "is_array", "(", "$", "res", "[", "'tables'", "]", ")", ")", "{", "$", "res", "[", "'tables'", "]", "=", "\\", "is_string", "(", "$", "res", "[", "'tables'", "]", ")", "?", "[", "$", "res", "[", "'tables'", "]", "]", ":", "[", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "res", "[", "'tables'", "]", ")", ")", "{", "foreach", "(", "$", "res", "[", "'tables'", "]", "as", "&", "$", "t", ")", "{", "$", "t", "=", "$", "this", "->", "tfn", "(", "$", "t", ")", ";", "}", "unset", "(", "$", "t", ")", ";", "}", "else", "{", "return", "[", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "res", "[", "'fields'", "]", ")", ")", "{", "if", "(", "\\", "is_string", "(", "$", "res", "[", "'fields'", "]", ")", ")", "{", "$", "res", "[", "'fields'", "]", "=", "[", "$", "res", "[", "'fields'", "]", "]", ";", "}", "}", "else", "if", "(", "!", "empty", "(", "$", "res", "[", "'columns'", "]", ")", ")", "{", "$", "res", "[", "'fields'", "]", "=", "(", "array", ")", "$", "res", "[", "'columns'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "res", "[", "'fields'", "]", ")", "&&", "(", "(", "$", "res", "[", "'kind'", "]", "===", "'INSERT'", ")", "||", "(", "$", "res", "[", "'kind'", "]", "===", "'UPDATE'", ")", ")", "&&", "\\", "is_string", "(", "array_keys", "(", "$", "res", "[", "'fields'", "]", ")", "[", "0", "]", ")", ")", "{", "$", "res", "[", "'values'", "]", "=", "array_values", "(", "$", "res", "[", "'fields'", "]", ")", ";", "$", "res", "[", "'fields'", "]", "=", "array_keys", "(", "$", "res", "[", "'fields'", "]", ")", ";", "}", "if", "(", "!", "\\", "is_array", "(", "$", "res", "[", "'group_by'", "]", ")", ")", "{", "$", "res", "[", "'group_by'", "]", "=", "empty", "(", "$", "res", "[", "'group_by'", "]", ")", "?", "[", "]", ":", "[", "$", "res", "[", "'group_by'", "]", "]", ";", "}", "if", "(", "!", "\\", "is_array", "(", "$", "res", "[", "'where'", "]", ")", ")", "{", "$", "res", "[", "'where'", "]", "=", "[", "]", ";", "}", "if", "(", "!", "\\", "is_array", "(", "$", "res", "[", "'order'", "]", ")", ")", "{", "$", "res", "[", "'order'", "]", "=", "\\", "is_string", "(", "$", "res", "[", "'order'", "]", ")", "?", "[", "$", "res", "[", "'order'", "]", "=>", "'ASC'", "]", ":", "[", "]", ";", "}", "if", "(", "!", "str", "::", "is_integer", "(", "$", "res", "[", "'limit'", "]", ")", ")", "{", "unset", "(", "$", "res", "[", "'limit'", "]", ")", ";", "}", "if", "(", "!", "str", "::", "is_integer", "(", "$", "res", "[", "'start'", "]", ")", ")", "{", "unset", "(", "$", "res", "[", "'start'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "cfg", "[", "'join'", "]", ")", ")", "{", "foreach", "(", "$", "cfg", "[", "'join'", "]", "as", "$", "k", "=>", "$", "join", ")", "{", "if", "(", "\\", "is_array", "(", "$", "join", ")", ")", "{", "if", "(", "\\", "is_string", "(", "$", "k", ")", ")", "{", "if", "(", "empty", "(", "$", "join", "[", "'table'", "]", ")", ")", "{", "$", "join", "[", "'table'", "]", "=", "$", "k", ";", "}", "else", "if", "(", "empty", "(", "$", "join", "[", "'alias'", "]", ")", ")", "{", "$", "join", "[", "'alias'", "]", "=", "$", "k", ";", "}", "}", "if", "(", "isset", "(", "$", "join", "[", "'table'", "]", ",", "$", "join", "[", "'on'", "]", ")", "&&", "(", "$", "tmp", "=", "$", "this", "->", "treat_conditions", "(", "$", "join", "[", "'on'", "]", ")", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "join", "[", "'type'", "]", ")", ")", "{", "$", "join", "[", "'type'", "]", "=", "'right'", ";", "}", "$", "res", "[", "'join'", "]", "[", "]", "=", "array_merge", "(", "$", "join", ",", "[", "'on'", "=>", "$", "tmp", "[", "'where'", "]", "]", ")", ";", "$", "res", "[", "'hashed_join'", "]", "[", "]", "=", "$", "tmp", "[", "'hashed'", "]", ";", "if", "(", "!", "empty", "(", "$", "tmp", "[", "'values'", "]", ")", ")", "{", "foreach", "(", "$", "tmp", "[", "'values'", "]", "as", "$", "v", ")", "{", "$", "res", "[", "'values'", "]", "[", "]", "=", "$", "v", ";", "}", "}", "}", "}", "}", "}", "if", "(", "$", "tmp", "=", "$", "this", "->", "treat_conditions", "(", "$", "res", "[", "'where'", "]", ")", ")", "{", "$", "res", "[", "'filters'", "]", "=", "$", "tmp", "[", "'where'", "]", ";", "$", "res", "[", "'hashed_where'", "]", "=", "$", "tmp", "[", "'hashed'", "]", ";", "if", "(", "\\", "is_array", "(", "$", "tmp", ")", "&&", "isset", "(", "$", "tmp", "[", "'values'", "]", ")", ")", "{", "foreach", "(", "$", "tmp", "[", "'values'", "]", "as", "$", "v", ")", "{", "$", "res", "[", "'values'", "]", "[", "]", "=", "$", "v", ";", "}", "}", "}", "if", "(", "!", "empty", "(", "$", "res", "[", "'having'", "]", ")", "&&", "(", "$", "tmp", "=", "$", "this", "->", "treat_conditions", "(", "$", "res", "[", "'having'", "]", ")", ")", ")", "{", "$", "res", "[", "'having'", "]", "=", "$", "tmp", "[", "'where'", "]", ";", "$", "res", "[", "'hashed_having'", "]", "=", "$", "tmp", "[", "'hashed'", "]", ";", "foreach", "(", "$", "tmp", "[", "'values'", "]", "as", "$", "v", ")", "{", "$", "res", "[", "'values'", "]", "[", "]", "=", "$", "v", ";", "}", "}", "if", "(", "empty", "(", "$", "cfg", "[", "'hash'", "]", ")", ")", "{", "$", "hash", "=", "$", "this", "->", "_make_hash", "(", "$", "res", "[", "'kind'", "]", ",", "$", "res", "[", "'ignore'", "]", ",", "$", "res", "[", "'count'", "]", ",", "$", "res", "[", "'tables'", "]", ",", "$", "res", "[", "'fields'", "]", ",", "$", "res", "[", "'hashed_join'", "]", ",", "$", "res", "[", "'hashed_where'", "]", ",", "$", "res", "[", "'hashed_having'", "]", ",", "$", "res", "[", "'group_by'", "]", ",", "$", "res", "[", "'order'", "]", ",", "$", "res", "[", "'limit'", "]", "??", "0", ",", "$", "res", "[", "'start'", "]", "??", "0", ")", ";", "$", "res", "[", "'hash'", "]", "=", "$", "hash", ";", "}", "else", "{", "$", "res", "[", "'hash'", "]", "=", "$", "cfg", "[", "'hash'", "]", ";", "}", "return", "$", "res", ";", "}" ]
Normalizes arguments by making it a uniform array. <ul><h3>The array will have the following indexes:</h3> <li>fields</li> <li>where</li> <li>filters</li> <li>order</li> <li>limit</li> <li>start</li> <li>join</li> <li>group_by</li> <li>having</li> <li>values</li> <li>hashed_join</li> <li>hashed_where</li> <li>hashed_having</li> <li>php</li> <li>done</li> </ul> @param $cfg @return array
[ "Normalizes", "arguments", "by", "making", "it", "a", "uniform", "array", ".", "<ul", ">", "<h3", ">", "The", "array", "will", "have", "the", "following", "indexes", ":", "<", "/", "h3", ">", "<li", ">", "fields<", "/", "li", ">", "<li", ">", "where<", "/", "li", ">", "<li", ">", "filters<", "/", "li", ">", "<li", ">", "order<", "/", "li", ">", "<li", ">", "limit<", "/", "li", ">", "<li", ">", "start<", "/", "li", ">", "<li", ">", "join<", "/", "li", ">", "<li", ">", "group_by<", "/", "li", ">", "<li", ">", "having<", "/", "li", ">", "<li", ">", "values<", "/", "li", ">", "<li", ">", "hashed_join<", "/", "li", ">", "<li", ">", "hashed_where<", "/", "li", ">", "<li", ">", "hashed_having<", "/", "li", ">", "<li", ">", "php<", "/", "li", ">", "<li", ">", "done<", "/", "li", ">", "<", "/", "ul", ">" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L582-L750
nabab/bbn
src/bbn/db.php
db.retrieve_query
public function retrieve_query(string $hash): ?array { if ( isset($this->queries[$hash]) ){ if ( \is_string($this->queries[$hash]) ){ $hash = $this->queries[$hash]; } return $this->queries[$hash]; } return null; }
php
public function retrieve_query(string $hash): ?array { if ( isset($this->queries[$hash]) ){ if ( \is_string($this->queries[$hash]) ){ $hash = $this->queries[$hash]; } return $this->queries[$hash]; } return null; }
[ "public", "function", "retrieve_query", "(", "string", "$", "hash", ")", ":", "?", "array", "{", "if", "(", "isset", "(", "$", "this", "->", "queries", "[", "$", "hash", "]", ")", ")", "{", "if", "(", "\\", "is_string", "(", "$", "this", "->", "queries", "[", "$", "hash", "]", ")", ")", "{", "$", "hash", "=", "$", "this", "->", "queries", "[", "$", "hash", "]", ";", "}", "return", "$", "this", "->", "queries", "[", "$", "hash", "]", ";", "}", "return", "null", ";", "}" ]
Retrieves a query array based on its hash. @param string $hash @return array|null
[ "Retrieves", "a", "query", "array", "based", "on", "its", "hash", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L880-L889
nabab/bbn
src/bbn/db.php
db.filter_filters
public function filter_filters(array $cfg, $field, $operator = null): ?array { if ( isset($cfg['filters']) ){ $f = function($cond, &$res = []) use (&$f, $field, $operator){ foreach ( $cond as $c ){ if ( isset($c['conditions']) ){ $f($c['conditions'], $res); } else if ( ($c['field'] === $field) && (!$operator || ($operator === $c['operator'])) ){ $res[] = $c; } } return $res; }; return isset($cfg['filters']['conditions']) ? $f($cfg['filters']['conditions']) : []; } return null; }
php
public function filter_filters(array $cfg, $field, $operator = null): ?array { if ( isset($cfg['filters']) ){ $f = function($cond, &$res = []) use (&$f, $field, $operator){ foreach ( $cond as $c ){ if ( isset($c['conditions']) ){ $f($c['conditions'], $res); } else if ( ($c['field'] === $field) && (!$operator || ($operator === $c['operator'])) ){ $res[] = $c; } } return $res; }; return isset($cfg['filters']['conditions']) ? $f($cfg['filters']['conditions']) : []; } return null; }
[ "public", "function", "filter_filters", "(", "array", "$", "cfg", ",", "$", "field", ",", "$", "operator", "=", "null", ")", ":", "?", "array", "{", "if", "(", "isset", "(", "$", "cfg", "[", "'filters'", "]", ")", ")", "{", "$", "f", "=", "function", "(", "$", "cond", ",", "&", "$", "res", "=", "[", "]", ")", "use", "(", "&", "$", "f", ",", "$", "field", ",", "$", "operator", ")", "{", "foreach", "(", "$", "cond", "as", "$", "c", ")", "{", "if", "(", "isset", "(", "$", "c", "[", "'conditions'", "]", ")", ")", "{", "$", "f", "(", "$", "c", "[", "'conditions'", "]", ",", "$", "res", ")", ";", "}", "else", "if", "(", "(", "$", "c", "[", "'field'", "]", "===", "$", "field", ")", "&&", "(", "!", "$", "operator", "||", "(", "$", "operator", "===", "$", "c", "[", "'operator'", "]", ")", ")", ")", "{", "$", "res", "[", "]", "=", "$", "c", ";", "}", "}", "return", "$", "res", ";", "}", ";", "return", "isset", "(", "$", "cfg", "[", "'filters'", "]", "[", "'conditions'", "]", ")", "?", "$", "f", "(", "$", "cfg", "[", "'filters'", "]", "[", "'conditions'", "]", ")", ":", "[", "]", ";", "}", "return", "null", ";", "}" ]
Retrieve an array of specific filters among the existing ones. @param array $cfg @param $field @param null $operator @return array|null
[ "Retrieve", "an", "array", "of", "specific", "filters", "among", "the", "existing", "ones", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1016-L1033
nabab/bbn
src/bbn/db.php
db.error
public function error($e): void { $this->has_error = true; self::has_error(); $msg = [ self::$line, self::get_log_line('ERROR DB!'), self::$line ]; if ( \is_string($e) ){ $msg[] = self::get_log_line('USER MESSAGE'); $msg[] = $e; } else if ( method_exists($e, 'getMessage') ){ $msg[] = self::get_log_line('DB MESSAGE'); $msg[] = $e->getMessage(); } $this->last_error = end($msg); $msg[] = self::get_log_line('QUERY'); $msg[] = $this->last(); if ( $this->last_params['values'] ){ $msg[] = self::get_log_line('VALUES'); foreach ( $this->last_params['values'] as $v ){ if ( $v === null ){ $msg[] = 'NULL'; } else if ( \is_bool($v) ){ $msg[] = $v ? 'TRUE' : 'FALSE'; } else if ( \is_string($v) ){ $msg[] = str::is_buid($v) ? bin2hex($v) : str::cut($v, 30); } else{ $msg[] = $v; } } } $msg[] = self::get_log_line('BACKTRACE'); $dbt = array_reverse(debug_backtrace()); array_walk($dbt, function($a, $i) use(&$msg){ $msg[] = str_repeat(' ', $i).($i ? '->' : '')."{$a['function']} (".basename(dirname($a['file'])).'/'.basename($a['file']).":{$a['line']})"; }); $this->log(implode(PHP_EOL, $msg)); if ( $this->on_error === self::E_DIE ){ die(\defined('BBN_IS_DEV') && BBN_IS_DEV ? '<pre>'.PHP_EOL.implode(PHP_EOL, $msg).PHP_EOL.'</pre>' : 'Database error'); } }
php
public function error($e): void { $this->has_error = true; self::has_error(); $msg = [ self::$line, self::get_log_line('ERROR DB!'), self::$line ]; if ( \is_string($e) ){ $msg[] = self::get_log_line('USER MESSAGE'); $msg[] = $e; } else if ( method_exists($e, 'getMessage') ){ $msg[] = self::get_log_line('DB MESSAGE'); $msg[] = $e->getMessage(); } $this->last_error = end($msg); $msg[] = self::get_log_line('QUERY'); $msg[] = $this->last(); if ( $this->last_params['values'] ){ $msg[] = self::get_log_line('VALUES'); foreach ( $this->last_params['values'] as $v ){ if ( $v === null ){ $msg[] = 'NULL'; } else if ( \is_bool($v) ){ $msg[] = $v ? 'TRUE' : 'FALSE'; } else if ( \is_string($v) ){ $msg[] = str::is_buid($v) ? bin2hex($v) : str::cut($v, 30); } else{ $msg[] = $v; } } } $msg[] = self::get_log_line('BACKTRACE'); $dbt = array_reverse(debug_backtrace()); array_walk($dbt, function($a, $i) use(&$msg){ $msg[] = str_repeat(' ', $i).($i ? '->' : '')."{$a['function']} (".basename(dirname($a['file'])).'/'.basename($a['file']).":{$a['line']})"; }); $this->log(implode(PHP_EOL, $msg)); if ( $this->on_error === self::E_DIE ){ die(\defined('BBN_IS_DEV') && BBN_IS_DEV ? '<pre>'.PHP_EOL.implode(PHP_EOL, $msg).PHP_EOL.'</pre>' : 'Database error'); } }
[ "public", "function", "error", "(", "$", "e", ")", ":", "void", "{", "$", "this", "->", "has_error", "=", "true", ";", "self", "::", "has_error", "(", ")", ";", "$", "msg", "=", "[", "self", "::", "$", "line", ",", "self", "::", "get_log_line", "(", "'ERROR DB!'", ")", ",", "self", "::", "$", "line", "]", ";", "if", "(", "\\", "is_string", "(", "$", "e", ")", ")", "{", "$", "msg", "[", "]", "=", "self", "::", "get_log_line", "(", "'USER MESSAGE'", ")", ";", "$", "msg", "[", "]", "=", "$", "e", ";", "}", "else", "if", "(", "method_exists", "(", "$", "e", ",", "'getMessage'", ")", ")", "{", "$", "msg", "[", "]", "=", "self", "::", "get_log_line", "(", "'DB MESSAGE'", ")", ";", "$", "msg", "[", "]", "=", "$", "e", "->", "getMessage", "(", ")", ";", "}", "$", "this", "->", "last_error", "=", "end", "(", "$", "msg", ")", ";", "$", "msg", "[", "]", "=", "self", "::", "get_log_line", "(", "'QUERY'", ")", ";", "$", "msg", "[", "]", "=", "$", "this", "->", "last", "(", ")", ";", "if", "(", "$", "this", "->", "last_params", "[", "'values'", "]", ")", "{", "$", "msg", "[", "]", "=", "self", "::", "get_log_line", "(", "'VALUES'", ")", ";", "foreach", "(", "$", "this", "->", "last_params", "[", "'values'", "]", "as", "$", "v", ")", "{", "if", "(", "$", "v", "===", "null", ")", "{", "$", "msg", "[", "]", "=", "'NULL'", ";", "}", "else", "if", "(", "\\", "is_bool", "(", "$", "v", ")", ")", "{", "$", "msg", "[", "]", "=", "$", "v", "?", "'TRUE'", ":", "'FALSE'", ";", "}", "else", "if", "(", "\\", "is_string", "(", "$", "v", ")", ")", "{", "$", "msg", "[", "]", "=", "str", "::", "is_buid", "(", "$", "v", ")", "?", "bin2hex", "(", "$", "v", ")", ":", "str", "::", "cut", "(", "$", "v", ",", "30", ")", ";", "}", "else", "{", "$", "msg", "[", "]", "=", "$", "v", ";", "}", "}", "}", "$", "msg", "[", "]", "=", "self", "::", "get_log_line", "(", "'BACKTRACE'", ")", ";", "$", "dbt", "=", "array_reverse", "(", "debug_backtrace", "(", ")", ")", ";", "array_walk", "(", "$", "dbt", ",", "function", "(", "$", "a", ",", "$", "i", ")", "use", "(", "&", "$", "msg", ")", "{", "$", "msg", "[", "]", "=", "str_repeat", "(", "' '", ",", "$", "i", ")", ".", "(", "$", "i", "?", "'->'", ":", "''", ")", ".", "\"{$a['function']} (\"", ".", "basename", "(", "dirname", "(", "$", "a", "[", "'file'", "]", ")", ")", ".", "'/'", ".", "basename", "(", "$", "a", "[", "'file'", "]", ")", ".", "\":{$a['line']})\"", ";", "}", ")", ";", "$", "this", "->", "log", "(", "implode", "(", "PHP_EOL", ",", "$", "msg", ")", ")", ";", "if", "(", "$", "this", "->", "on_error", "===", "self", "::", "E_DIE", ")", "{", "die", "(", "\\", "defined", "(", "'BBN_IS_DEV'", ")", "&&", "BBN_IS_DEV", "?", "'<pre>'", ".", "PHP_EOL", ".", "implode", "(", "PHP_EOL", ",", "$", "msg", ")", ".", "PHP_EOL", ".", "'</pre>'", ":", "'Database error'", ")", ";", "}", "}" ]
Set an error and acts appropriately based oon the error mode @param $e @return void
[ "Set", "an", "error", "and", "acts", "appropriately", "based", "oon", "the", "error", "mode" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1357-L1403
nabab/bbn
src/bbn/db.php
db.check
public function check(): bool { if ( $this->current !== null ){ // if $on_error is set to E_CONTINUE returns true if ( $this->on_error === self::E_CONTINUE ){ return true; } // If any connection has an error with mode E_STOP_ALL if ( self::$has_error_all && ($this->on_error !== self::E_STOP_ALL) ){ return false; } // If this connection has an error with mode E_STOP if ( $this->has_error && ($this->on_error !== self::E_STOP) ){ return false; } return true; } return false; }
php
public function check(): bool { if ( $this->current !== null ){ // if $on_error is set to E_CONTINUE returns true if ( $this->on_error === self::E_CONTINUE ){ return true; } // If any connection has an error with mode E_STOP_ALL if ( self::$has_error_all && ($this->on_error !== self::E_STOP_ALL) ){ return false; } // If this connection has an error with mode E_STOP if ( $this->has_error && ($this->on_error !== self::E_STOP) ){ return false; } return true; } return false; }
[ "public", "function", "check", "(", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "current", "!==", "null", ")", "{", "// if $on_error is set to E_CONTINUE returns true", "if", "(", "$", "this", "->", "on_error", "===", "self", "::", "E_CONTINUE", ")", "{", "return", "true", ";", "}", "// If any connection has an error with mode E_STOP_ALL", "if", "(", "self", "::", "$", "has_error_all", "&&", "(", "$", "this", "->", "on_error", "!==", "self", "::", "E_STOP_ALL", ")", ")", "{", "return", "false", ";", "}", "// If this connection has an error with mode E_STOP", "if", "(", "$", "this", "->", "has_error", "&&", "(", "$", "this", "->", "on_error", "!==", "self", "::", "E_STOP", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks if the database is ready to process a query. ```php bbn\x::dump($db->check()); // (bool) ``` @return bool
[ "Checks", "if", "the", "database", "is", "ready", "to", "process", "a", "query", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1414-L1432
nabab/bbn
src/bbn/db.php
db.log
public function log($st): self { $args = \func_get_args(); foreach ( $args as $a ){ x::log($a, 'db'); } return $this; }
php
public function log($st): self { $args = \func_get_args(); foreach ( $args as $a ){ x::log($a, 'db'); } return $this; }
[ "public", "function", "log", "(", "$", "st", ")", ":", "self", "{", "$", "args", "=", "\\", "func_get_args", "(", ")", ";", "foreach", "(", "$", "args", "as", "$", "a", ")", "{", "x", "::", "log", "(", "$", "a", ",", "'db'", ")", ";", "}", "return", "$", "this", ";", "}" ]
Writes in data/logs/db.log. ```php $db->$db->log('test'); ``` @param mixed $st @return db
[ "Writes", "in", "data", "/", "logs", "/", "db", ".", "log", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1443-L1450
nabab/bbn
src/bbn/db.php
db.clear_cache
public function clear_cache($item, $mode): self { $cache_name = $this->_cache_name($item, $mode); if ( $this->cache_has($cache_name) ){ $this->cache_delete($cache_name); } return $this; }
php
public function clear_cache($item, $mode): self { $cache_name = $this->_cache_name($item, $mode); if ( $this->cache_has($cache_name) ){ $this->cache_delete($cache_name); } return $this; }
[ "public", "function", "clear_cache", "(", "$", "item", ",", "$", "mode", ")", ":", "self", "{", "$", "cache_name", "=", "$", "this", "->", "_cache_name", "(", "$", "item", ",", "$", "mode", ")", ";", "if", "(", "$", "this", "->", "cache_has", "(", "$", "cache_name", ")", ")", "{", "$", "this", "->", "cache_delete", "(", "$", "cache_name", ")", ";", "}", "return", "$", "this", ";", "}" ]
Deletes a specific item from the cache. ```php bbn\x::dump($db->clear_cache('db_example','tables')); // (db) ``` @param string $item 'db_name' or 'table_name' @param string $mode 'columns','tables' or'databases' @return self
[ "Deletes", "a", "specific", "item", "from", "the", "cache", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1495-L1502
nabab/bbn
src/bbn/db.php
db.stop_fancy_stuff
public function stop_fancy_stuff(): self { $this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [\PDOStatement::class]); $this->fancy = false; return $this; }
php
public function stop_fancy_stuff(): self { $this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [\PDOStatement::class]); $this->fancy = false; return $this; }
[ "public", "function", "stop_fancy_stuff", "(", ")", ":", "self", "{", "$", "this", "->", "setAttribute", "(", "\\", "PDO", "::", "ATTR_STATEMENT_CLASS", ",", "[", "\\", "PDOStatement", "::", "class", "]", ")", ";", "$", "this", "->", "fancy", "=", "false", ";", "return", "$", "this", ";", "}" ]
Stops fancy stuff. ```php $db->stop_fancy_stuff(); // (void) ``` @return db
[ "Stops", "fancy", "stuff", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1530-L1535
nabab/bbn
src/bbn/db.php
db.start_fancy_stuff
public function start_fancy_stuff(): self { $this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [db\query::class, [$this]]); $this->fancy = 1; return $this; }
php
public function start_fancy_stuff(): self { $this->setAttribute(\PDO::ATTR_STATEMENT_CLASS, [db\query::class, [$this]]); $this->fancy = 1; return $this; }
[ "public", "function", "start_fancy_stuff", "(", ")", ":", "self", "{", "$", "this", "->", "setAttribute", "(", "\\", "PDO", "::", "ATTR_STATEMENT_CLASS", ",", "[", "db", "\\", "query", "::", "class", ",", "[", "$", "this", "]", "]", ")", ";", "$", "this", "->", "fancy", "=", "1", ";", "return", "$", "this", ";", "}" ]
Starts fancy stuff. ```php $db->start_fancy_stuff(); // (void) ``` @return db
[ "Starts", "fancy", "stuff", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1546-L1551
nabab/bbn
src/bbn/db.php
db.set_trigger
public function set_trigger(callable $function, $kind = null, $moment = null, $tables = '*' ): self { $kinds = ['SELECT', 'INSERT', 'UPDATE', 'DELETE']; $moments = ['before', 'after']; if ( empty($kind) ){ $kind = $kinds; } else if ( !\is_array($kind) ){ $kind = (array)strtoupper($kind); } else{ $kind = array_map('strtoupper', $kind); } if ( empty($moment) ){ $moment = $moments; } else { $moment = !\is_array($moment) ? (array)strtolower($moment) : array_map('strtolower', $moment); } foreach ( $kind as $k ){ if ( \in_array($k, $kinds, true) ){ foreach ( $moment as $m ){ if ( array_key_exists($m, $this->triggers[$k]) && \in_array($m, $moments, true) ){ if ( $tables === '*' ){ $tables = $this->get_tables(); } else if ( str::check_name($tables) ){ $tables = [$tables]; } if ( \is_array($tables) ){ foreach ( $tables as $table ){ $t = $this->tfn($table); if ( !isset($this->triggers[$k][$m][$t]) ){ $this->triggers[$k][$m][$t] = []; } $this->triggers[$k][$m][$t][] = $function; } } } } } } return $this; }
php
public function set_trigger(callable $function, $kind = null, $moment = null, $tables = '*' ): self { $kinds = ['SELECT', 'INSERT', 'UPDATE', 'DELETE']; $moments = ['before', 'after']; if ( empty($kind) ){ $kind = $kinds; } else if ( !\is_array($kind) ){ $kind = (array)strtoupper($kind); } else{ $kind = array_map('strtoupper', $kind); } if ( empty($moment) ){ $moment = $moments; } else { $moment = !\is_array($moment) ? (array)strtolower($moment) : array_map('strtolower', $moment); } foreach ( $kind as $k ){ if ( \in_array($k, $kinds, true) ){ foreach ( $moment as $m ){ if ( array_key_exists($m, $this->triggers[$k]) && \in_array($m, $moments, true) ){ if ( $tables === '*' ){ $tables = $this->get_tables(); } else if ( str::check_name($tables) ){ $tables = [$tables]; } if ( \is_array($tables) ){ foreach ( $tables as $table ){ $t = $this->tfn($table); if ( !isset($this->triggers[$k][$m][$t]) ){ $this->triggers[$k][$m][$t] = []; } $this->triggers[$k][$m][$t][] = $function; } } } } } } return $this; }
[ "public", "function", "set_trigger", "(", "callable", "$", "function", ",", "$", "kind", "=", "null", ",", "$", "moment", "=", "null", ",", "$", "tables", "=", "'*'", ")", ":", "self", "{", "$", "kinds", "=", "[", "'SELECT'", ",", "'INSERT'", ",", "'UPDATE'", ",", "'DELETE'", "]", ";", "$", "moments", "=", "[", "'before'", ",", "'after'", "]", ";", "if", "(", "empty", "(", "$", "kind", ")", ")", "{", "$", "kind", "=", "$", "kinds", ";", "}", "else", "if", "(", "!", "\\", "is_array", "(", "$", "kind", ")", ")", "{", "$", "kind", "=", "(", "array", ")", "strtoupper", "(", "$", "kind", ")", ";", "}", "else", "{", "$", "kind", "=", "array_map", "(", "'strtoupper'", ",", "$", "kind", ")", ";", "}", "if", "(", "empty", "(", "$", "moment", ")", ")", "{", "$", "moment", "=", "$", "moments", ";", "}", "else", "{", "$", "moment", "=", "!", "\\", "is_array", "(", "$", "moment", ")", "?", "(", "array", ")", "strtolower", "(", "$", "moment", ")", ":", "array_map", "(", "'strtolower'", ",", "$", "moment", ")", ";", "}", "foreach", "(", "$", "kind", "as", "$", "k", ")", "{", "if", "(", "\\", "in_array", "(", "$", "k", ",", "$", "kinds", ",", "true", ")", ")", "{", "foreach", "(", "$", "moment", "as", "$", "m", ")", "{", "if", "(", "array_key_exists", "(", "$", "m", ",", "$", "this", "->", "triggers", "[", "$", "k", "]", ")", "&&", "\\", "in_array", "(", "$", "m", ",", "$", "moments", ",", "true", ")", ")", "{", "if", "(", "$", "tables", "===", "'*'", ")", "{", "$", "tables", "=", "$", "this", "->", "get_tables", "(", ")", ";", "}", "else", "if", "(", "str", "::", "check_name", "(", "$", "tables", ")", ")", "{", "$", "tables", "=", "[", "$", "tables", "]", ";", "}", "if", "(", "\\", "is_array", "(", "$", "tables", ")", ")", "{", "foreach", "(", "$", "tables", "as", "$", "table", ")", "{", "$", "t", "=", "$", "this", "->", "tfn", "(", "$", "table", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "triggers", "[", "$", "k", "]", "[", "$", "m", "]", "[", "$", "t", "]", ")", ")", "{", "$", "this", "->", "triggers", "[", "$", "k", "]", "[", "$", "m", "]", "[", "$", "t", "]", "=", "[", "]", ";", "}", "$", "this", "->", "triggers", "[", "$", "k", "]", "[", "$", "m", "]", "[", "$", "t", "]", "[", "]", "=", "$", "function", ";", "}", "}", "}", "}", "}", "}", "return", "$", "this", ";", "}" ]
Apply a function each time the methods $kind are used @param callable $function @param array|string $kind select|insert|update|delete @param array|string $moment before|after @param null|string|array $tables database's table(s) name(s) @return db
[ "Apply", "a", "function", "each", "time", "the", "methods", "$kind", "are", "used" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1639-L1682
nabab/bbn
src/bbn/db.php
db.get_foreign_keys
public function get_foreign_keys(string $col, string $table, string $db = null): array { if ( !$db ){ $db = $this->current; } $res = []; $model = $this->modelize(); foreach ( $model as $tn => $m ){ foreach ( $m['keys'] as $k => $t ){ if ( ($t['ref_table'] === $table) && ($t['ref_column'] === $col) && ($t['ref_db'] === $db) && (\count($t['columns']) === 1) ){ if ( !isset($res[$tn]) ){ $res[$tn] = [$t['columns'][0]]; } else{ $res[$tn][] = $t['columns'][0]; } } } } return $res; }
php
public function get_foreign_keys(string $col, string $table, string $db = null): array { if ( !$db ){ $db = $this->current; } $res = []; $model = $this->modelize(); foreach ( $model as $tn => $m ){ foreach ( $m['keys'] as $k => $t ){ if ( ($t['ref_table'] === $table) && ($t['ref_column'] === $col) && ($t['ref_db'] === $db) && (\count($t['columns']) === 1) ){ if ( !isset($res[$tn]) ){ $res[$tn] = [$t['columns'][0]]; } else{ $res[$tn][] = $t['columns'][0]; } } } } return $res; }
[ "public", "function", "get_foreign_keys", "(", "string", "$", "col", ",", "string", "$", "table", ",", "string", "$", "db", "=", "null", ")", ":", "array", "{", "if", "(", "!", "$", "db", ")", "{", "$", "db", "=", "$", "this", "->", "current", ";", "}", "$", "res", "=", "[", "]", ";", "$", "model", "=", "$", "this", "->", "modelize", "(", ")", ";", "foreach", "(", "$", "model", "as", "$", "tn", "=>", "$", "m", ")", "{", "foreach", "(", "$", "m", "[", "'keys'", "]", "as", "$", "k", "=>", "$", "t", ")", "{", "if", "(", "(", "$", "t", "[", "'ref_table'", "]", "===", "$", "table", ")", "&&", "(", "$", "t", "[", "'ref_column'", "]", "===", "$", "col", ")", "&&", "(", "$", "t", "[", "'ref_db'", "]", "===", "$", "db", ")", "&&", "(", "\\", "count", "(", "$", "t", "[", "'columns'", "]", ")", "===", "1", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "res", "[", "$", "tn", "]", ")", ")", "{", "$", "res", "[", "$", "tn", "]", "=", "[", "$", "t", "[", "'columns'", "]", "[", "0", "]", "]", ";", "}", "else", "{", "$", "res", "[", "$", "tn", "]", "[", "]", "=", "$", "t", "[", "'columns'", "]", "[", "0", "]", ";", "}", "}", "}", "}", "return", "$", "res", ";", "}" ]
Return an array with tables and fields related to the searched foreign key. ```php bbn\x::dump($db->get_foreign_keys('id', 'table_users', 'db_example')); // (Array) ``` @param string $col The column's name @param string $table The table's name @param string $db The database name if different from the current one @return array with tables and fields related to the searched foreign key
[ "Return", "an", "array", "with", "tables", "and", "fields", "related", "to", "the", "searched", "foreign", "key", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1735-L1759
nabab/bbn
src/bbn/db.php
db.has_id_increment
public function has_id_increment($table): bool { return ($model = $this->modelize($table)) && isset($model['keys']['PRIMARY']) && (\count($model['keys']['PRIMARY']['columns']) === 1) && ($model['fields'][$model['keys']['PRIMARY']['columns'][0]]['extra'] === 'auto_increment'); }
php
public function has_id_increment($table): bool { return ($model = $this->modelize($table)) && isset($model['keys']['PRIMARY']) && (\count($model['keys']['PRIMARY']['columns']) === 1) && ($model['fields'][$model['keys']['PRIMARY']['columns'][0]]['extra'] === 'auto_increment'); }
[ "public", "function", "has_id_increment", "(", "$", "table", ")", ":", "bool", "{", "return", "(", "$", "model", "=", "$", "this", "->", "modelize", "(", "$", "table", ")", ")", "&&", "isset", "(", "$", "model", "[", "'keys'", "]", "[", "'PRIMARY'", "]", ")", "&&", "(", "\\", "count", "(", "$", "model", "[", "'keys'", "]", "[", "'PRIMARY'", "]", "[", "'columns'", "]", ")", "===", "1", ")", "&&", "(", "$", "model", "[", "'fields'", "]", "[", "$", "model", "[", "'keys'", "]", "[", "'PRIMARY'", "]", "[", "'columns'", "]", "[", "0", "]", "]", "[", "'extra'", "]", "===", "'auto_increment'", ")", ";", "}" ]
Return true if in the table there are fields with auto-increment. Working only on mysql. ```php \bbn\x::dump($db->has_id_increment('table_users')); // (bool) 1 ``` @param string $table The table's name @return bool
[ "Return", "true", "if", "in", "the", "table", "there", "are", "fields", "with", "auto", "-", "increment", ".", "Working", "only", "on", "mysql", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1773-L1779
nabab/bbn
src/bbn/db.php
db.modelize
public function modelize($table = null, bool $force = false): ?array { $r = []; $tables = false; if ( empty($table) || $table === '*' ){ $tables = $this->get_tables($this->current); } else if ( \is_string($table) ){ $tables = [$table]; } else if ( \is_array($table) ){ $tables = $table; } if ( \is_array($tables) ){ foreach ( $tables as $t ){ $full = $this->tfn($t); $r[$full] = $this->_get_cache($full, 'columns', $force); } if ( \count($r) === 1 ){ return end($r); } return $r; } return null; }
php
public function modelize($table = null, bool $force = false): ?array { $r = []; $tables = false; if ( empty($table) || $table === '*' ){ $tables = $this->get_tables($this->current); } else if ( \is_string($table) ){ $tables = [$table]; } else if ( \is_array($table) ){ $tables = $table; } if ( \is_array($tables) ){ foreach ( $tables as $t ){ $full = $this->tfn($t); $r[$full] = $this->_get_cache($full, 'columns', $force); } if ( \count($r) === 1 ){ return end($r); } return $r; } return null; }
[ "public", "function", "modelize", "(", "$", "table", "=", "null", ",", "bool", "$", "force", "=", "false", ")", ":", "?", "array", "{", "$", "r", "=", "[", "]", ";", "$", "tables", "=", "false", ";", "if", "(", "empty", "(", "$", "table", ")", "||", "$", "table", "===", "'*'", ")", "{", "$", "tables", "=", "$", "this", "->", "get_tables", "(", "$", "this", "->", "current", ")", ";", "}", "else", "if", "(", "\\", "is_string", "(", "$", "table", ")", ")", "{", "$", "tables", "=", "[", "$", "table", "]", ";", "}", "else", "if", "(", "\\", "is_array", "(", "$", "table", ")", ")", "{", "$", "tables", "=", "$", "table", ";", "}", "if", "(", "\\", "is_array", "(", "$", "tables", ")", ")", "{", "foreach", "(", "$", "tables", "as", "$", "t", ")", "{", "$", "full", "=", "$", "this", "->", "tfn", "(", "$", "t", ")", ";", "$", "r", "[", "$", "full", "]", "=", "$", "this", "->", "_get_cache", "(", "$", "full", ",", "'columns'", ",", "$", "force", ")", ";", "}", "if", "(", "\\", "count", "(", "$", "r", ")", "===", "1", ")", "{", "return", "end", "(", "$", "r", ")", ";", "}", "return", "$", "r", ";", "}", "return", "null", ";", "}" ]
Return the table's structure as an indexed array. ```php \bbn\x::dump($db->modelize("table_users")); // (array) [keys] => Array ( [PRIMARY] => Array ( [columns] => Array ( [0] => userid [1] => userdataid ) [ref_db] => [ref_table] => [ref_column] => [unique] => 1 ) [table_users_userId_userdataId_info] => Array ( [columns] => Array ( [0] => userid [1] => userdataid [2] => info ) [ref_db] => [ref_table] => [ref_column] => [unique] => 0 ) ) [cols] => Array ( [userid] => Array ( [0] => PRIMARY [1] => table_users_userId_userdataId_info ) [userdataid] => Array ( [0] => PRIMARY [1] => table_users_userId_userdataId_info ) [info] => Array ( [0] => table_users_userId_userdataId_info ) ) [fields] => Array ( [userid] => Array ( [position] => 1 [null] => 0 [key] => PRI [default] => [extra] => [signed] => 1 [maxlength] => 11 [type] => int ) [userdataid] => Array ( [position] => 2 [null] => 0 [key] => PRI [default] => [extra] => [signed] => 1 [maxlength] => 11 [type] => int ) [info] => Array ( [position] => 3 [null] => 1 [key] => [default] => NULL [extra] => [signed] => 0 [maxlength] => 200 [type] => varchar ) ) ``` @param null|array|string $table The table's name @param bool $force If set to true will force the modelization to reperform even if the cache exists @return null|array
[ "Return", "the", "table", "s", "structure", "as", "an", "indexed", "array", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1793-L1817
nabab/bbn
src/bbn/db.php
db.find_references
public function find_references($column, $db = ''): array { $changed = false; if ( $db && ($db !== $this->current) ){ $changed = $this->current; $this->change($db); } $column = $this->cfn($column); $bits = explode('.', $column); if ( \count($bits) === 2 ){ array_unshift($bits, $this->current); } if ( \count($bits) !== 3 ){ return false; } $refs = []; $schema = $this->modelize(); $test = function($key) use($bits){ return ($key['ref_db'] === $bits[0]) && ($key['ref_table'] === $bits[1]) && ($key['ref_column'] === $bits[2]); }; foreach ( $schema as $table => $cfg ){ foreach ( $cfg['keys'] as $k ){ if ( $test($k) ){ $refs[] = $table.'.'.$k['columns'][0]; } } } if ( $changed ){ $this->change($changed); } return $refs; }
php
public function find_references($column, $db = ''): array { $changed = false; if ( $db && ($db !== $this->current) ){ $changed = $this->current; $this->change($db); } $column = $this->cfn($column); $bits = explode('.', $column); if ( \count($bits) === 2 ){ array_unshift($bits, $this->current); } if ( \count($bits) !== 3 ){ return false; } $refs = []; $schema = $this->modelize(); $test = function($key) use($bits){ return ($key['ref_db'] === $bits[0]) && ($key['ref_table'] === $bits[1]) && ($key['ref_column'] === $bits[2]); }; foreach ( $schema as $table => $cfg ){ foreach ( $cfg['keys'] as $k ){ if ( $test($k) ){ $refs[] = $table.'.'.$k['columns'][0]; } } } if ( $changed ){ $this->change($changed); } return $refs; }
[ "public", "function", "find_references", "(", "$", "column", ",", "$", "db", "=", "''", ")", ":", "array", "{", "$", "changed", "=", "false", ";", "if", "(", "$", "db", "&&", "(", "$", "db", "!==", "$", "this", "->", "current", ")", ")", "{", "$", "changed", "=", "$", "this", "->", "current", ";", "$", "this", "->", "change", "(", "$", "db", ")", ";", "}", "$", "column", "=", "$", "this", "->", "cfn", "(", "$", "column", ")", ";", "$", "bits", "=", "explode", "(", "'.'", ",", "$", "column", ")", ";", "if", "(", "\\", "count", "(", "$", "bits", ")", "===", "2", ")", "{", "array_unshift", "(", "$", "bits", ",", "$", "this", "->", "current", ")", ";", "}", "if", "(", "\\", "count", "(", "$", "bits", ")", "!==", "3", ")", "{", "return", "false", ";", "}", "$", "refs", "=", "[", "]", ";", "$", "schema", "=", "$", "this", "->", "modelize", "(", ")", ";", "$", "test", "=", "function", "(", "$", "key", ")", "use", "(", "$", "bits", ")", "{", "return", "(", "$", "key", "[", "'ref_db'", "]", "===", "$", "bits", "[", "0", "]", ")", "&&", "(", "$", "key", "[", "'ref_table'", "]", "===", "$", "bits", "[", "1", "]", ")", "&&", "(", "$", "key", "[", "'ref_column'", "]", "===", "$", "bits", "[", "2", "]", ")", ";", "}", ";", "foreach", "(", "$", "schema", "as", "$", "table", "=>", "$", "cfg", ")", "{", "foreach", "(", "$", "cfg", "[", "'keys'", "]", "as", "$", "k", ")", "{", "if", "(", "$", "test", "(", "$", "k", ")", ")", "{", "$", "refs", "[", "]", "=", "$", "table", ".", "'.'", ".", "$", "k", "[", "'columns'", "]", "[", "0", "]", ";", "}", "}", "}", "if", "(", "$", "changed", ")", "{", "$", "this", "->", "change", "(", "$", "changed", ")", ";", "}", "return", "$", "refs", ";", "}" ]
find_references @param $column @param string $db @return array|bool
[ "find_references" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1849-L1881
nabab/bbn
src/bbn/db.php
db.find_relations
public function find_relations($column, $db = ''): ?array { $changed = false; if ( $db && ($db !== $this->current) ){ $changed = $this->current; $this->change($db); } $column = $this->cfn($column); $bits = explode('.', $column); if ( \count($bits) === 2 ){ array_unshift($bits, $db ?: $this->current); } if ( \count($bits) !== 3 ){ return null; } $table = $bits[1]; $refs = []; $schema = $this->modelize(); $test = function($key) use($bits){ return ($key['ref_db'] === $bits[0]) && ($key['ref_table'] === $bits[1]) && ($key['ref_column'] === $bits[2]); }; foreach ( $schema as $tf => $cfg ){ $t = $this->tsn($tf); if ( $t !== $table ){ foreach ( $cfg['keys'] as $k ){ if ( $test($k) ){ foreach ( $cfg['keys'] as $k2 ){ // Is not the same table if ( !$test($k2) && // Has a reference !empty($k2['ref_column']) && // and refers to a single column (\count($k['columns']) === 1) && // A unique reference (\count($k2['columns']) === 1) && // To a table with a primary isset($schema[$this->tfn($k2['ref_table'])]['cols'][$k2['ref_column']]) && // which is a sole column (\count($schema[$this->tfn($k2['ref_table'])]['cols'][$k2['ref_column']]) === 1) && // We retrieve the key name ($key_name = $schema[$this->tfn($k2['ref_table'])]['cols'][$k2['ref_column']][0]) && // which is unique !empty($schema[$this->tfn($k2['ref_table'])]['keys'][$key_name]['unique']) ){ if ( !isset($refs[$t]) ){ $refs[$t] = ['column' => $k['columns'][0], 'refs' => []]; } $refs[$t]['refs'][$k2['columns'][0]] = $k2['ref_table'].'.'.$k2['ref_column']; } } } } } } if ( $changed ){ $this->change($changed); } return $refs; }
php
public function find_relations($column, $db = ''): ?array { $changed = false; if ( $db && ($db !== $this->current) ){ $changed = $this->current; $this->change($db); } $column = $this->cfn($column); $bits = explode('.', $column); if ( \count($bits) === 2 ){ array_unshift($bits, $db ?: $this->current); } if ( \count($bits) !== 3 ){ return null; } $table = $bits[1]; $refs = []; $schema = $this->modelize(); $test = function($key) use($bits){ return ($key['ref_db'] === $bits[0]) && ($key['ref_table'] === $bits[1]) && ($key['ref_column'] === $bits[2]); }; foreach ( $schema as $tf => $cfg ){ $t = $this->tsn($tf); if ( $t !== $table ){ foreach ( $cfg['keys'] as $k ){ if ( $test($k) ){ foreach ( $cfg['keys'] as $k2 ){ // Is not the same table if ( !$test($k2) && // Has a reference !empty($k2['ref_column']) && // and refers to a single column (\count($k['columns']) === 1) && // A unique reference (\count($k2['columns']) === 1) && // To a table with a primary isset($schema[$this->tfn($k2['ref_table'])]['cols'][$k2['ref_column']]) && // which is a sole column (\count($schema[$this->tfn($k2['ref_table'])]['cols'][$k2['ref_column']]) === 1) && // We retrieve the key name ($key_name = $schema[$this->tfn($k2['ref_table'])]['cols'][$k2['ref_column']][0]) && // which is unique !empty($schema[$this->tfn($k2['ref_table'])]['keys'][$key_name]['unique']) ){ if ( !isset($refs[$t]) ){ $refs[$t] = ['column' => $k['columns'][0], 'refs' => []]; } $refs[$t]['refs'][$k2['columns'][0]] = $k2['ref_table'].'.'.$k2['ref_column']; } } } } } } if ( $changed ){ $this->change($changed); } return $refs; }
[ "public", "function", "find_relations", "(", "$", "column", ",", "$", "db", "=", "''", ")", ":", "?", "array", "{", "$", "changed", "=", "false", ";", "if", "(", "$", "db", "&&", "(", "$", "db", "!==", "$", "this", "->", "current", ")", ")", "{", "$", "changed", "=", "$", "this", "->", "current", ";", "$", "this", "->", "change", "(", "$", "db", ")", ";", "}", "$", "column", "=", "$", "this", "->", "cfn", "(", "$", "column", ")", ";", "$", "bits", "=", "explode", "(", "'.'", ",", "$", "column", ")", ";", "if", "(", "\\", "count", "(", "$", "bits", ")", "===", "2", ")", "{", "array_unshift", "(", "$", "bits", ",", "$", "db", "?", ":", "$", "this", "->", "current", ")", ";", "}", "if", "(", "\\", "count", "(", "$", "bits", ")", "!==", "3", ")", "{", "return", "null", ";", "}", "$", "table", "=", "$", "bits", "[", "1", "]", ";", "$", "refs", "=", "[", "]", ";", "$", "schema", "=", "$", "this", "->", "modelize", "(", ")", ";", "$", "test", "=", "function", "(", "$", "key", ")", "use", "(", "$", "bits", ")", "{", "return", "(", "$", "key", "[", "'ref_db'", "]", "===", "$", "bits", "[", "0", "]", ")", "&&", "(", "$", "key", "[", "'ref_table'", "]", "===", "$", "bits", "[", "1", "]", ")", "&&", "(", "$", "key", "[", "'ref_column'", "]", "===", "$", "bits", "[", "2", "]", ")", ";", "}", ";", "foreach", "(", "$", "schema", "as", "$", "tf", "=>", "$", "cfg", ")", "{", "$", "t", "=", "$", "this", "->", "tsn", "(", "$", "tf", ")", ";", "if", "(", "$", "t", "!==", "$", "table", ")", "{", "foreach", "(", "$", "cfg", "[", "'keys'", "]", "as", "$", "k", ")", "{", "if", "(", "$", "test", "(", "$", "k", ")", ")", "{", "foreach", "(", "$", "cfg", "[", "'keys'", "]", "as", "$", "k2", ")", "{", "// Is not the same table", "if", "(", "!", "$", "test", "(", "$", "k2", ")", "&&", "// Has a reference", "!", "empty", "(", "$", "k2", "[", "'ref_column'", "]", ")", "&&", "// and refers to a single column", "(", "\\", "count", "(", "$", "k", "[", "'columns'", "]", ")", "===", "1", ")", "&&", "// A unique reference", "(", "\\", "count", "(", "$", "k2", "[", "'columns'", "]", ")", "===", "1", ")", "&&", "// To a table with a primary", "isset", "(", "$", "schema", "[", "$", "this", "->", "tfn", "(", "$", "k2", "[", "'ref_table'", "]", ")", "]", "[", "'cols'", "]", "[", "$", "k2", "[", "'ref_column'", "]", "]", ")", "&&", "// which is a sole column", "(", "\\", "count", "(", "$", "schema", "[", "$", "this", "->", "tfn", "(", "$", "k2", "[", "'ref_table'", "]", ")", "]", "[", "'cols'", "]", "[", "$", "k2", "[", "'ref_column'", "]", "]", ")", "===", "1", ")", "&&", "// We retrieve the key name", "(", "$", "key_name", "=", "$", "schema", "[", "$", "this", "->", "tfn", "(", "$", "k2", "[", "'ref_table'", "]", ")", "]", "[", "'cols'", "]", "[", "$", "k2", "[", "'ref_column'", "]", "]", "[", "0", "]", ")", "&&", "// which is unique", "!", "empty", "(", "$", "schema", "[", "$", "this", "->", "tfn", "(", "$", "k2", "[", "'ref_table'", "]", ")", "]", "[", "'keys'", "]", "[", "$", "key_name", "]", "[", "'unique'", "]", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "refs", "[", "$", "t", "]", ")", ")", "{", "$", "refs", "[", "$", "t", "]", "=", "[", "'column'", "=>", "$", "k", "[", "'columns'", "]", "[", "0", "]", ",", "'refs'", "=>", "[", "]", "]", ";", "}", "$", "refs", "[", "$", "t", "]", "[", "'refs'", "]", "[", "$", "k2", "[", "'columns'", "]", "[", "0", "]", "]", "=", "$", "k2", "[", "'ref_table'", "]", ".", "'.'", ".", "$", "k2", "[", "'ref_column'", "]", ";", "}", "}", "}", "}", "}", "}", "if", "(", "$", "changed", ")", "{", "$", "this", "->", "change", "(", "$", "changed", ")", ";", "}", "return", "$", "refs", ";", "}" ]
find_relations @param $column @param string $db @return array|bool
[ "find_relations" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1890-L1948
nabab/bbn
src/bbn/db.php
db.get_unique_primary
public function get_unique_primary($table): ?string { if ( ($keys = $this->get_keys($table)) && isset($keys['keys']['PRIMARY']) && (\count($keys['keys']['PRIMARY']['columns']) === 1) ){ return $keys['keys']['PRIMARY']['columns'][0]; } return null; }
php
public function get_unique_primary($table): ?string { if ( ($keys = $this->get_keys($table)) && isset($keys['keys']['PRIMARY']) && (\count($keys['keys']['PRIMARY']['columns']) === 1) ){ return $keys['keys']['PRIMARY']['columns'][0]; } return null; }
[ "public", "function", "get_unique_primary", "(", "$", "table", ")", ":", "?", "string", "{", "if", "(", "(", "$", "keys", "=", "$", "this", "->", "get_keys", "(", "$", "table", ")", ")", "&&", "isset", "(", "$", "keys", "[", "'keys'", "]", "[", "'PRIMARY'", "]", ")", "&&", "(", "\\", "count", "(", "$", "keys", "[", "'keys'", "]", "[", "'PRIMARY'", "]", "[", "'columns'", "]", ")", "===", "1", ")", ")", "{", "return", "$", "keys", "[", "'keys'", "]", "[", "'PRIMARY'", "]", "[", "'columns'", "]", "[", "0", "]", ";", "}", "return", "null", ";", "}" ]
Return the unique primary key of the given table. ```php \bbn\x::dump($db->get_unique_primary('table_users')); // (string) id ``` @param string $table The table's name @return null|string
[ "Return", "the", "unique", "primary", "key", "of", "the", "given", "table", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1980-L1988
nabab/bbn
src/bbn/db.php
db.get_unique_keys
public function get_unique_keys($table): array { $fields = [[]]; if ( $ks = $this->get_keys($table) ){ foreach ( $ks['keys'] as $k ){ if ( $k['unique'] ){ $fields[] = $k['columns']; } } } return array_merge(...$fields); }
php
public function get_unique_keys($table): array { $fields = [[]]; if ( $ks = $this->get_keys($table) ){ foreach ( $ks['keys'] as $k ){ if ( $k['unique'] ){ $fields[] = $k['columns']; } } } return array_merge(...$fields); }
[ "public", "function", "get_unique_keys", "(", "$", "table", ")", ":", "array", "{", "$", "fields", "=", "[", "[", "]", "]", ";", "if", "(", "$", "ks", "=", "$", "this", "->", "get_keys", "(", "$", "table", ")", ")", "{", "foreach", "(", "$", "ks", "[", "'keys'", "]", "as", "$", "k", ")", "{", "if", "(", "$", "k", "[", "'unique'", "]", ")", "{", "$", "fields", "[", "]", "=", "$", "k", "[", "'columns'", "]", ";", "}", "}", "}", "return", "array_merge", "(", "...", "$", "fields", ")", ";", "}" ]
Return the unique keys of a table as a numeric array. ```php \bbn\x::dump($db->get_unique_keys('table_users')); // (array) ["userid", "userdataid"] ``` @param string $table The table's name @return array
[ "Return", "the", "unique", "keys", "of", "a", "table", "as", "a", "numeric", "array", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2001-L2012
nabab/bbn
src/bbn/db.php
db.escape_value
public function escape_value(string $value, $esc = "'"): string { return str_replace('%', '\\%', $esc === '"' ? str::escape_dquotes($value) : str::escape_squotes($value)); }
php
public function escape_value(string $value, $esc = "'"): string { return str_replace('%', '\\%', $esc === '"' ? str::escape_dquotes($value) : str::escape_squotes($value)); }
[ "public", "function", "escape_value", "(", "string", "$", "value", ",", "$", "esc", "=", "\"'\"", ")", ":", "string", "{", "return", "str_replace", "(", "'%'", ",", "'\\\\%'", ",", "$", "esc", "===", "'\"'", "?", "str", "::", "escape_dquotes", "(", "$", "value", ")", ":", "str", "::", "escape_squotes", "(", "$", "value", ")", ")", ";", "}" ]
Return a string with quotes and percent escaped. ```php bbn\x::dump($db->escape_value("My father's job is interesting"); // (string) My father\'s job is interesting ``` @param string $value The string to escape. @param string $esc @return string
[ "Return", "a", "string", "with", "quotes", "and", "percent", "escaped", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2035-L2040
nabab/bbn
src/bbn/db.php
db.set_last_insert_id
public function set_last_insert_id($id=''): self { if ( $id === '' ){ if ( $this->id_just_inserted ){ $id = $this->id_just_inserted; $this->id_just_inserted = null; } else{ $id = $this->lastInsertId(); if ( \is_string($id) && str::is_integer($id) ){ $id = (int)$id; } } } else{ $this->id_just_inserted = $id; } $this->last_insert_id = $id; return $this; }
php
public function set_last_insert_id($id=''): self { if ( $id === '' ){ if ( $this->id_just_inserted ){ $id = $this->id_just_inserted; $this->id_just_inserted = null; } else{ $id = $this->lastInsertId(); if ( \is_string($id) && str::is_integer($id) ){ $id = (int)$id; } } } else{ $this->id_just_inserted = $id; } $this->last_insert_id = $id; return $this; }
[ "public", "function", "set_last_insert_id", "(", "$", "id", "=", "''", ")", ":", "self", "{", "if", "(", "$", "id", "===", "''", ")", "{", "if", "(", "$", "this", "->", "id_just_inserted", ")", "{", "$", "id", "=", "$", "this", "->", "id_just_inserted", ";", "$", "this", "->", "id_just_inserted", "=", "null", ";", "}", "else", "{", "$", "id", "=", "$", "this", "->", "lastInsertId", "(", ")", ";", "if", "(", "\\", "is_string", "(", "$", "id", ")", "&&", "str", "::", "is_integer", "(", "$", "id", ")", ")", "{", "$", "id", "=", "(", "int", ")", "$", "id", ";", "}", "}", "}", "else", "{", "$", "this", "->", "id_just_inserted", "=", "$", "id", ";", "}", "$", "this", "->", "last_insert_id", "=", "$", "id", ";", "return", "$", "this", ";", "}" ]
Changes the value of last_insert_id (used by history). @todo this function should be private ```php bbn\x::dump($db->set_last_insert_id()); // (db) ``` @param mixed $id The last inserted id @return self
[ "Changes", "the", "value", "of", "last_insert_id", "(", "used", "by", "history", ")", ".", "@todo", "this", "function", "should", "be", "private" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2053-L2072
nabab/bbn
src/bbn/db.php
db.parse_query
public function parse_query(string $statement): ?array { if ( $this->parser === null ){ $this->parser = new \PHPSQLParser\PHPSQLParser(); } try { $r = $this->parser->parse($statement); if ( !count($r) ){ return null; } if ( isset($r['BRACKET']) && (\count($r) === 1) ){ return null; } return $r; } catch ( \Exception $e ){ $this->log('Impossible to parse the query '.$statement); } return null; }
php
public function parse_query(string $statement): ?array { if ( $this->parser === null ){ $this->parser = new \PHPSQLParser\PHPSQLParser(); } try { $r = $this->parser->parse($statement); if ( !count($r) ){ return null; } if ( isset($r['BRACKET']) && (\count($r) === 1) ){ return null; } return $r; } catch ( \Exception $e ){ $this->log('Impossible to parse the query '.$statement); } return null; }
[ "public", "function", "parse_query", "(", "string", "$", "statement", ")", ":", "?", "array", "{", "if", "(", "$", "this", "->", "parser", "===", "null", ")", "{", "$", "this", "->", "parser", "=", "new", "\\", "PHPSQLParser", "\\", "PHPSQLParser", "(", ")", ";", "}", "try", "{", "$", "r", "=", "$", "this", "->", "parser", "->", "parse", "(", "$", "statement", ")", ";", "if", "(", "!", "count", "(", "$", "r", ")", ")", "{", "return", "null", ";", "}", "if", "(", "isset", "(", "$", "r", "[", "'BRACKET'", "]", ")", "&&", "(", "\\", "count", "(", "$", "r", ")", "===", "1", ")", ")", "{", "return", "null", ";", "}", "return", "$", "r", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "this", "->", "log", "(", "'Impossible to parse the query '", ".", "$", "statement", ")", ";", "}", "return", "null", ";", "}" ]
Parses a SQL query and return an array. @param string $statement @return null|array
[ "Parses", "a", "SQL", "query", "and", "return", "an", "array", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2080-L2099
nabab/bbn
src/bbn/db.php
db.last_id
public function last_id() { if ( $this->last_insert_id ){ return str::is_buid($this->last_insert_id) ? bin2hex($this->last_insert_id) : $this->last_insert_id; } return false; }
php
public function last_id() { if ( $this->last_insert_id ){ return str::is_buid($this->last_insert_id) ? bin2hex($this->last_insert_id) : $this->last_insert_id; } return false; }
[ "public", "function", "last_id", "(", ")", "{", "if", "(", "$", "this", "->", "last_insert_id", ")", "{", "return", "str", "::", "is_buid", "(", "$", "this", "->", "last_insert_id", ")", "?", "bin2hex", "(", "$", "this", "->", "last_insert_id", ")", ":", "$", "this", "->", "last_insert_id", ";", "}", "return", "false", ";", "}" ]
Return the last inserted ID. ```php \bbn\x::dump($db->last_id()); // (int) 26 ``` @return mixed
[ "Return", "the", "last", "inserted", "ID", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2126-L2132
nabab/bbn
src/bbn/db.php
db.new_id
public function new_id($table, int $min = 1){ $tab = $this->modelize($table); if ( \count($tab['keys']['PRIMARY']['columns']) !== 1 ){ die("Error! Unique numeric primary key doesn't exist"); } if ( ($id_field = $tab['keys']['PRIMARY']['columns'][0]) && ($maxlength = $tab['fields'][$id_field]['maxlength'] )&& ($maxlength > 1) ){ $max = (10 ** $maxlength) - 1; if ( $max >= mt_getrandmax() ){ $max = mt_getrandmax(); } if ( ($max > $min) && ($table = $this->tfn($table, true)) ){ $i = 0; do { $id = random_int($min, $max); /** @todo */ /* if ( strpos($tab['fields'][$id_field]['type'], 'char') !== false ){ $id = substr(md5('bbn'.$id), 0, random_int(1, 10 ** $maxlength)); } */ $i++; } while ( ($i < 100) && $this->select($table, [$id_field], [$id_field => $id]) ); return $id; } } return null; }
php
public function new_id($table, int $min = 1){ $tab = $this->modelize($table); if ( \count($tab['keys']['PRIMARY']['columns']) !== 1 ){ die("Error! Unique numeric primary key doesn't exist"); } if ( ($id_field = $tab['keys']['PRIMARY']['columns'][0]) && ($maxlength = $tab['fields'][$id_field]['maxlength'] )&& ($maxlength > 1) ){ $max = (10 ** $maxlength) - 1; if ( $max >= mt_getrandmax() ){ $max = mt_getrandmax(); } if ( ($max > $min) && ($table = $this->tfn($table, true)) ){ $i = 0; do { $id = random_int($min, $max); /** @todo */ /* if ( strpos($tab['fields'][$id_field]['type'], 'char') !== false ){ $id = substr(md5('bbn'.$id), 0, random_int(1, 10 ** $maxlength)); } */ $i++; } while ( ($i < 100) && $this->select($table, [$id_field], [$id_field => $id]) ); return $id; } } return null; }
[ "public", "function", "new_id", "(", "$", "table", ",", "int", "$", "min", "=", "1", ")", "{", "$", "tab", "=", "$", "this", "->", "modelize", "(", "$", "table", ")", ";", "if", "(", "\\", "count", "(", "$", "tab", "[", "'keys'", "]", "[", "'PRIMARY'", "]", "[", "'columns'", "]", ")", "!==", "1", ")", "{", "die", "(", "\"Error! Unique numeric primary key doesn't exist\"", ")", ";", "}", "if", "(", "(", "$", "id_field", "=", "$", "tab", "[", "'keys'", "]", "[", "'PRIMARY'", "]", "[", "'columns'", "]", "[", "0", "]", ")", "&&", "(", "$", "maxlength", "=", "$", "tab", "[", "'fields'", "]", "[", "$", "id_field", "]", "[", "'maxlength'", "]", ")", "&&", "(", "$", "maxlength", ">", "1", ")", ")", "{", "$", "max", "=", "(", "10", "**", "$", "maxlength", ")", "-", "1", ";", "if", "(", "$", "max", ">=", "mt_getrandmax", "(", ")", ")", "{", "$", "max", "=", "mt_getrandmax", "(", ")", ";", "}", "if", "(", "(", "$", "max", ">", "$", "min", ")", "&&", "(", "$", "table", "=", "$", "this", "->", "tfn", "(", "$", "table", ",", "true", ")", ")", ")", "{", "$", "i", "=", "0", ";", "do", "{", "$", "id", "=", "random_int", "(", "$", "min", ",", "$", "max", ")", ";", "/** @todo */", "/*\n if ( strpos($tab['fields'][$id_field]['type'], 'char') !== false ){\n $id = substr(md5('bbn'.$id), 0, random_int(1, 10 ** $maxlength));\n }\n */", "$", "i", "++", ";", "}", "while", "(", "(", "$", "i", "<", "100", ")", "&&", "$", "this", "->", "select", "(", "$", "table", ",", "[", "$", "id_field", "]", ",", "[", "$", "id_field", "=>", "$", "id", "]", ")", ")", ";", "return", "$", "id", ";", "}", "}", "return", "null", ";", "}" ]
Generate a new casual id based on the max number of characters of id's column structure in the given table ```php \bbn\x::dump($db->new_id('table_users', 18)); // (int) 69991701 ``` @todo Either get rid of th efunction or include the UID types @param null|string $table The table's name. @param int $min @return mixed
[ "Generate", "a", "new", "casual", "id", "based", "on", "the", "max", "number", "of", "characters", "of", "id", "s", "column", "structure", "in", "the", "given", "table" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2173-L2204
nabab/bbn
src/bbn/db.php
db.random_value
public function random_value($col, $table){ $val = null; if ( ($tab = $this->modelize($table)) && isset($tab['fields'][$col]) ){ foreach ( $tab['keys'] as $key => $cfg ){ if ( $cfg['unique'] && !empty($cfg['ref_column']) && (\count($cfg['columns']) === 1) && ($col === $cfg['columns'][0]) ){ return ($num = $this->count($cfg['ref_column'])) ? $this->select_one([ 'tables' [$cfg['ref_table']], 'fields' => [$cfg['ref_column']], 'start' => random_int(0, $num - 1) ]) : null; } } switch ( $tab['fields'][$col]['type'] ){ case 'int': if ( ($tab['fields'][$col]['maxlength'] === 1) && !$tab['fields'][$col]['signed'] ){ $val = microtime(true) % 2 === 0 ? 1 : 0; } else { $max = 10 ** $tab['fields'][$col]['maxlength'] - 1; if ( $max > mt_getrandmax() ){ $max = mt_getrandmax(); } if ( $tab['fields'][$col]['signed'] ){ $max /= 2; } $min = $tab['fields'][$col]['signed'] ? -$max : 0; $val = random_int($min, $max); } break; case 'float': case 'double': case 'decimal': break; case 'varchar': break; case 'text': break; case 'date': break; case 'datetime': break; case 'timestamp': break; case 'time': break; case 'year': break; case 'blob': break; case 'binary': break; case 'varbinary': break; case 'enum': break; } } return $val; }
php
public function random_value($col, $table){ $val = null; if ( ($tab = $this->modelize($table)) && isset($tab['fields'][$col]) ){ foreach ( $tab['keys'] as $key => $cfg ){ if ( $cfg['unique'] && !empty($cfg['ref_column']) && (\count($cfg['columns']) === 1) && ($col === $cfg['columns'][0]) ){ return ($num = $this->count($cfg['ref_column'])) ? $this->select_one([ 'tables' [$cfg['ref_table']], 'fields' => [$cfg['ref_column']], 'start' => random_int(0, $num - 1) ]) : null; } } switch ( $tab['fields'][$col]['type'] ){ case 'int': if ( ($tab['fields'][$col]['maxlength'] === 1) && !$tab['fields'][$col]['signed'] ){ $val = microtime(true) % 2 === 0 ? 1 : 0; } else { $max = 10 ** $tab['fields'][$col]['maxlength'] - 1; if ( $max > mt_getrandmax() ){ $max = mt_getrandmax(); } if ( $tab['fields'][$col]['signed'] ){ $max /= 2; } $min = $tab['fields'][$col]['signed'] ? -$max : 0; $val = random_int($min, $max); } break; case 'float': case 'double': case 'decimal': break; case 'varchar': break; case 'text': break; case 'date': break; case 'datetime': break; case 'timestamp': break; case 'time': break; case 'year': break; case 'blob': break; case 'binary': break; case 'varbinary': break; case 'enum': break; } } return $val; }
[ "public", "function", "random_value", "(", "$", "col", ",", "$", "table", ")", "{", "$", "val", "=", "null", ";", "if", "(", "(", "$", "tab", "=", "$", "this", "->", "modelize", "(", "$", "table", ")", ")", "&&", "isset", "(", "$", "tab", "[", "'fields'", "]", "[", "$", "col", "]", ")", ")", "{", "foreach", "(", "$", "tab", "[", "'keys'", "]", "as", "$", "key", "=>", "$", "cfg", ")", "{", "if", "(", "$", "cfg", "[", "'unique'", "]", "&&", "!", "empty", "(", "$", "cfg", "[", "'ref_column'", "]", ")", "&&", "(", "\\", "count", "(", "$", "cfg", "[", "'columns'", "]", ")", "===", "1", ")", "&&", "(", "$", "col", "===", "$", "cfg", "[", "'columns'", "]", "[", "0", "]", ")", ")", "{", "return", "(", "$", "num", "=", "$", "this", "->", "count", "(", "$", "cfg", "[", "'ref_column'", "]", ")", ")", "?", "$", "this", "->", "select_one", "(", "[", "'tables'", "[", "$", "cfg", "[", "'ref_table'", "]", "]", ",", "'fields'", "=>", "[", "$", "cfg", "[", "'ref_column'", "]", "]", ",", "'start'", "=>", "random_int", "(", "0", ",", "$", "num", "-", "1", ")", "]", ")", ":", "null", ";", "}", "}", "switch", "(", "$", "tab", "[", "'fields'", "]", "[", "$", "col", "]", "[", "'type'", "]", ")", "{", "case", "'int'", ":", "if", "(", "(", "$", "tab", "[", "'fields'", "]", "[", "$", "col", "]", "[", "'maxlength'", "]", "===", "1", ")", "&&", "!", "$", "tab", "[", "'fields'", "]", "[", "$", "col", "]", "[", "'signed'", "]", ")", "{", "$", "val", "=", "microtime", "(", "true", ")", "%", "2", "===", "0", "?", "1", ":", "0", ";", "}", "else", "{", "$", "max", "=", "10", "**", "$", "tab", "[", "'fields'", "]", "[", "$", "col", "]", "[", "'maxlength'", "]", "-", "1", ";", "if", "(", "$", "max", ">", "mt_getrandmax", "(", ")", ")", "{", "$", "max", "=", "mt_getrandmax", "(", ")", ";", "}", "if", "(", "$", "tab", "[", "'fields'", "]", "[", "$", "col", "]", "[", "'signed'", "]", ")", "{", "$", "max", "/=", "2", ";", "}", "$", "min", "=", "$", "tab", "[", "'fields'", "]", "[", "$", "col", "]", "[", "'signed'", "]", "?", "-", "$", "max", ":", "0", ";", "$", "val", "=", "random_int", "(", "$", "min", ",", "$", "max", ")", ";", "}", "break", ";", "case", "'float'", ":", "case", "'double'", ":", "case", "'decimal'", ":", "break", ";", "case", "'varchar'", ":", "break", ";", "case", "'text'", ":", "break", ";", "case", "'date'", ":", "break", ";", "case", "'datetime'", ":", "break", ";", "case", "'timestamp'", ":", "break", ";", "case", "'time'", ":", "break", ";", "case", "'year'", ":", "break", ";", "case", "'blob'", ":", "break", ";", "case", "'binary'", ":", "break", ";", "case", "'varbinary'", ":", "break", ";", "case", "'enum'", ":", "break", ";", "}", "}", "return", "$", "val", ";", "}" ]
Returns a random value fitting the requested column's type @todo This great function has to be done properly @param $col @param $table @return mixed
[ "Returns", "a", "random", "value", "fitting", "the", "requested", "column", "s", "type" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2214-L2277
nabab/bbn
src/bbn/db.php
db.get_key_val
public function get_key_val(): ?array { if ( $r = $this->query(...\func_get_args()) ){ if ( $rows = $r->get_rows() ){ return x::index_by_first_val($rows); } return []; } return null; }
php
public function get_key_val(): ?array { if ( $r = $this->query(...\func_get_args()) ){ if ( $rows = $r->get_rows() ){ return x::index_by_first_val($rows); } return []; } return null; }
[ "public", "function", "get_key_val", "(", ")", ":", "?", "array", "{", "if", "(", "$", "r", "=", "$", "this", "->", "query", "(", "...", "\\", "func_get_args", "(", ")", ")", ")", "{", "if", "(", "$", "rows", "=", "$", "r", "->", "get_rows", "(", ")", ")", "{", "return", "x", "::", "index_by_first_val", "(", "$", "rows", ")", ";", "}", "return", "[", "]", ";", "}", "return", "null", ";", "}" ]
Return an array indexed on the first field of the request. The value will be an array if the request has more than two fields. ```php \bbn\x::dump($db->get_key_val("SELECT name,id_group FROM table_users")); /* (array)[ "John" => 1, "Michael" => 1, "Barbara" => 1 ] \bbn\x::dump($db->get_key_val("SELECT name, surname, id FROM table_users WHERE id > 2 ")); /* (array)[ "John" => [ "surname" => "Brown", "id" => 3 ], "Michael" => [ "surname" => "Smith", "id" => 4 ] ] ``` @param string query @param mixed values @return null|array
[ "Return", "an", "array", "indexed", "on", "the", "first", "field", "of", "the", "request", ".", "The", "value", "will", "be", "an", "array", "if", "the", "request", "has", "more", "than", "two", "fields", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2363-L2372
nabab/bbn
src/bbn/db.php
db.select
public function select($table, $fields = [], array $where = [], array $order = [], int $start = 0): ?\stdClass { $args = $this->_add_kind($this->_set_limit_1(\func_get_args())); if ( $r = $this->_exec(...$args) ){ return $r->get_object(); } return null; }
php
public function select($table, $fields = [], array $where = [], array $order = [], int $start = 0): ?\stdClass { $args = $this->_add_kind($this->_set_limit_1(\func_get_args())); if ( $r = $this->_exec(...$args) ){ return $r->get_object(); } return null; }
[ "public", "function", "select", "(", "$", "table", ",", "$", "fields", "=", "[", "]", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ",", "int", "$", "start", "=", "0", ")", ":", "?", "\\", "stdClass", "{", "$", "args", "=", "$", "this", "->", "_add_kind", "(", "$", "this", "->", "_set_limit_1", "(", "\\", "func_get_args", "(", ")", ")", ")", ";", "if", "(", "$", "r", "=", "$", "this", "->", "_exec", "(", "...", "$", "args", ")", ")", "{", "return", "$", "r", "->", "get_object", "(", ")", ";", "}", "return", "null", ";", "}" ]
Returns the first row resulting from the query as an object. ```php \bbn\x::dump($db->select('table_users', ['name', 'surname'], [['id','>','2']])); /* (object){ "name": "John", "surname": "Smith", } ``` @param string|array $table The table's name or a configuration array @param string|array $fields The fields' name @param array $where The "where" condition @param array | boolean $order The "order" condition, default: false @param int $start The "start" condition, default: 0 @return null|\stdClass
[ "Returns", "the", "first", "row", "resulting", "from", "the", "query", "as", "an", "object", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2422-L2429
nabab/bbn
src/bbn/db.php
db.select_all
public function select_all($table, $fields = [], array $where = [], array $order = [], int $limit = 0, int $start = 0): ?array { if ( $r = $this->_exec(...$this->_add_kind(\func_get_args())) ){ return $r->get_objects(); } return null; }
php
public function select_all($table, $fields = [], array $where = [], array $order = [], int $limit = 0, int $start = 0): ?array { if ( $r = $this->_exec(...$this->_add_kind(\func_get_args())) ){ return $r->get_objects(); } return null; }
[ "public", "function", "select_all", "(", "$", "table", ",", "$", "fields", "=", "[", "]", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ",", "int", "$", "limit", "=", "0", ",", "int", "$", "start", "=", "0", ")", ":", "?", "array", "{", "if", "(", "$", "r", "=", "$", "this", "->", "_exec", "(", "...", "$", "this", "->", "_add_kind", "(", "\\", "func_get_args", "(", ")", ")", ")", ")", "{", "return", "$", "r", "->", "get_objects", "(", ")", ";", "}", "return", "null", ";", "}" ]
Return table's rows resulting from the query as an array of objects. ```php \bbn\x::dump($db->select_all("tab_users", ["id", "name", "surname"],[["id", ">", 1]], ["id" => "ASC"], 2)); /* (array)[ Object stdClass: df { "id" => 2, "name" => "John", "surname" => "Smith", }, Object stdClass: df { "id" => 3, "name" => "Thomas", "surname" => "Jones", } ] ``` @param string|array $table The table's name or a configuration array @param string|array $fields The fields' name @param array $where The "where" condition @param array | boolean $order The "order" condition, default: false @param int $limit The "limit" condition, default: 0 @param int $start The "start" condition, default: 0 @return null|array
[ "Return", "table", "s", "rows", "resulting", "from", "the", "query", "as", "an", "array", "of", "objects", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2459-L2465
nabab/bbn
src/bbn/db.php
db.iselect
public function iselect($table, $fields = [], array $where = [], array $order = [], int $start = 0): ?array { if ( $r = $this->_exec(...$this->_add_kind($this->_set_limit_1(\func_get_args()))) ){ return $r->get_irow(); } return null; }
php
public function iselect($table, $fields = [], array $where = [], array $order = [], int $start = 0): ?array { if ( $r = $this->_exec(...$this->_add_kind($this->_set_limit_1(\func_get_args()))) ){ return $r->get_irow(); } return null; }
[ "public", "function", "iselect", "(", "$", "table", ",", "$", "fields", "=", "[", "]", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ",", "int", "$", "start", "=", "0", ")", ":", "?", "array", "{", "if", "(", "$", "r", "=", "$", "this", "->", "_exec", "(", "...", "$", "this", "->", "_add_kind", "(", "$", "this", "->", "_set_limit_1", "(", "\\", "func_get_args", "(", ")", ")", ")", ")", ")", "{", "return", "$", "r", "->", "get_irow", "(", ")", ";", "}", "return", "null", ";", "}" ]
Return the first row resulting from the query as a numeric array. ```php \bbn\x::dump($db->iselect("tab_users", ["id", "name", "surname"], [["id", ">", 1]], ["id" => "ASC"], 2)); /* (array)[ 4, "Jack", "Stewart" ] ``` @param string|array $table The table's name or a configuration array @param string|array $fields The fields' name @param array $where The "where" condition @param array | boolean $order The "order" condition, default: false @param int $start The "start" condition, default: 0 @return array
[ "Return", "the", "first", "row", "resulting", "from", "the", "query", "as", "a", "numeric", "array", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2487-L2493
nabab/bbn
src/bbn/db.php
db.iselect_all
public function iselect_all($table, $fields = [], array $where = [], array $order = [], int $limit = 0, int $start = 0): ?array { if ( $r = $this->_exec(...$this->_add_kind(\func_get_args())) ){ return $r->get_irows(); } return null; }
php
public function iselect_all($table, $fields = [], array $where = [], array $order = [], int $limit = 0, int $start = 0): ?array { if ( $r = $this->_exec(...$this->_add_kind(\func_get_args())) ){ return $r->get_irows(); } return null; }
[ "public", "function", "iselect_all", "(", "$", "table", ",", "$", "fields", "=", "[", "]", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ",", "int", "$", "limit", "=", "0", ",", "int", "$", "start", "=", "0", ")", ":", "?", "array", "{", "if", "(", "$", "r", "=", "$", "this", "->", "_exec", "(", "...", "$", "this", "->", "_add_kind", "(", "\\", "func_get_args", "(", ")", ")", ")", ")", "{", "return", "$", "r", "->", "get_irows", "(", ")", ";", "}", "return", "null", ";", "}" ]
Return the searched rows as an array of numeric arrays. ```php \bbn\x::dump($db->iselect_all("tab_users", ["id", "name", "surname"], [["id", ">", 1]],["id" => "ASC"],2)); /* (array)[ [ 2, "John", "Smith", ], [ 3, "Thomas", "Jones", ] ] ``` @param string|array $table The table's name or a configuration array @param string|array $fields The fields's name @param array $where The "where" condition @param array | boolean The "order" condition, default: false @param int $limit The "limit" condition, default: 0 @param int $start The "start" condition, default: 0 @return array
[ "Return", "the", "searched", "rows", "as", "an", "array", "of", "numeric", "arrays", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2523-L2529
nabab/bbn
src/bbn/db.php
db.rselect
public function rselect($table, $fields = [], array $where = [], array $order = [], int $start = 0): ?array { if ( $r = $this->_exec(...$this->_add_kind($this->_set_limit_1(\func_get_args()))) ){ return $r->get_row(); } return null; }
php
public function rselect($table, $fields = [], array $where = [], array $order = [], int $start = 0): ?array { if ( $r = $this->_exec(...$this->_add_kind($this->_set_limit_1(\func_get_args()))) ){ return $r->get_row(); } return null; }
[ "public", "function", "rselect", "(", "$", "table", ",", "$", "fields", "=", "[", "]", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ",", "int", "$", "start", "=", "0", ")", ":", "?", "array", "{", "if", "(", "$", "r", "=", "$", "this", "->", "_exec", "(", "...", "$", "this", "->", "_add_kind", "(", "$", "this", "->", "_set_limit_1", "(", "\\", "func_get_args", "(", ")", ")", ")", ")", ")", "{", "return", "$", "r", "->", "get_row", "(", ")", ";", "}", "return", "null", ";", "}" ]
Return the first row resulting from the query as an indexed array. ```php \bbn\x::dump($db->rselect("tab_users", ["id", "name", "surname"], ["id", ">", 1], ["id" => "ASC"], 2)); /* (array) [ "id" => 4, "name" => "John", "surname" => "Smith" ] ``` @param string|array $table The table's name or a configuration array @param string|array $fields The fields' name @param array $where The "where" condition @param array|boolean $order The "order" condition, default: false @param int $start The "start" condition, default: 0 @return null|array
[ "Return", "the", "first", "row", "resulting", "from", "the", "query", "as", "an", "indexed", "array", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2551-L2557
nabab/bbn
src/bbn/db.php
db.rselect_all
public function rselect_all($table, $fields = [], array $where = [], array $order = [], $limit = 0, $start = 0): ?array { if ( $r = $this->_exec(...$this->_add_kind(\func_get_args())) ){ if ( \is_object($r) ){ return $r->get_rows(); } $this->log('ERROR IN RSELECT_ALL', $r); } return []; }
php
public function rselect_all($table, $fields = [], array $where = [], array $order = [], $limit = 0, $start = 0): ?array { if ( $r = $this->_exec(...$this->_add_kind(\func_get_args())) ){ if ( \is_object($r) ){ return $r->get_rows(); } $this->log('ERROR IN RSELECT_ALL', $r); } return []; }
[ "public", "function", "rselect_all", "(", "$", "table", ",", "$", "fields", "=", "[", "]", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ",", "$", "limit", "=", "0", ",", "$", "start", "=", "0", ")", ":", "?", "array", "{", "if", "(", "$", "r", "=", "$", "this", "->", "_exec", "(", "...", "$", "this", "->", "_add_kind", "(", "\\", "func_get_args", "(", ")", ")", ")", ")", "{", "if", "(", "\\", "is_object", "(", "$", "r", ")", ")", "{", "return", "$", "r", "->", "get_rows", "(", ")", ";", "}", "$", "this", "->", "log", "(", "'ERROR IN RSELECT_ALL'", ",", "$", "r", ")", ";", "}", "return", "[", "]", ";", "}" ]
Return table's rows as an array of indexed arrays. ```php \bbn\x::dump($db->rselect_all("tab_users", ["id", "name", "surname"], [["id", ">", 1]], ["id" => "ASC"], 2)); /* (array) [ [ "id" => 2, "name" => "John", "surname" => "Smith", ], [ "id" => 3, "name" => "Thomas", "surname" => "Jones", ] ] ``` @param string|array $table The table's name or a configuration array @param string|array $fields The fields' name @param array $where The "where" condition @param array | boolean $order condition, default: false @param int $limit The "limit" condition, default: 0 @param int $start The "start" condition, default: 0 @return null|array
[ "Return", "table", "s", "rows", "as", "an", "array", "of", "indexed", "arrays", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2587-L2596
nabab/bbn
src/bbn/db.php
db.select_one
public function select_one($table, $field = null, array $where = [], array $order = [], int $start = 0) { if ( $r = $this->_exec(...$this->_add_kind($this->_set_limit_1(\func_get_args()))) ){ if ( \is_object($r) ){ return ($a = $r->get_irow()) ? $a[0] : false; } $this->log('ERROR IN RSELECT_ONE', $r); } return false; }
php
public function select_one($table, $field = null, array $where = [], array $order = [], int $start = 0) { if ( $r = $this->_exec(...$this->_add_kind($this->_set_limit_1(\func_get_args()))) ){ if ( \is_object($r) ){ return ($a = $r->get_irow()) ? $a[0] : false; } $this->log('ERROR IN RSELECT_ONE', $r); } return false; }
[ "public", "function", "select_one", "(", "$", "table", ",", "$", "field", "=", "null", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ",", "int", "$", "start", "=", "0", ")", "{", "if", "(", "$", "r", "=", "$", "this", "->", "_exec", "(", "...", "$", "this", "->", "_add_kind", "(", "$", "this", "->", "_set_limit_1", "(", "\\", "func_get_args", "(", ")", ")", ")", ")", ")", "{", "if", "(", "\\", "is_object", "(", "$", "r", ")", ")", "{", "return", "(", "$", "a", "=", "$", "r", "->", "get_irow", "(", ")", ")", "?", "$", "a", "[", "0", "]", ":", "false", ";", "}", "$", "this", "->", "log", "(", "'ERROR IN RSELECT_ONE'", ",", "$", "r", ")", ";", "}", "return", "false", ";", "}" ]
Return a single value ```php \bbn\x::dump($db->select_one("tab_users", "name", [["id", ">", 1]], ["id" => "DESC"], 2)); (string) 'Michael' ``` @param string|array $table The table's name or a configuration array @param string $field The field's name @param array $where The "where" condition @param array | boolean $order The "order" condition, default: false @param int $start The "start" condition, default: 0 @return mixed
[ "Return", "a", "single", "value" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2613-L2622
nabab/bbn
src/bbn/db.php
db.count
public function count($table, array $where = []): ?int { $args = \is_array($table) && isset($table['tables']) ? $table : [ 'tables' => [$table], 'where' => $where ]; $args['count'] = true; if ( !empty($args['bbn_db_processed']) ){ unset($args['bbn_db_processed']); } if ( \is_object($r = $this->_exec($args)) ){ $a = $r->get_irow(); return $a ? (int)$a[0] : null; } return null; }
php
public function count($table, array $where = []): ?int { $args = \is_array($table) && isset($table['tables']) ? $table : [ 'tables' => [$table], 'where' => $where ]; $args['count'] = true; if ( !empty($args['bbn_db_processed']) ){ unset($args['bbn_db_processed']); } if ( \is_object($r = $this->_exec($args)) ){ $a = $r->get_irow(); return $a ? (int)$a[0] : null; } return null; }
[ "public", "function", "count", "(", "$", "table", ",", "array", "$", "where", "=", "[", "]", ")", ":", "?", "int", "{", "$", "args", "=", "\\", "is_array", "(", "$", "table", ")", "&&", "isset", "(", "$", "table", "[", "'tables'", "]", ")", "?", "$", "table", ":", "[", "'tables'", "=>", "[", "$", "table", "]", ",", "'where'", "=>", "$", "where", "]", ";", "$", "args", "[", "'count'", "]", "=", "true", ";", "if", "(", "!", "empty", "(", "$", "args", "[", "'bbn_db_processed'", "]", ")", ")", "{", "unset", "(", "$", "args", "[", "'bbn_db_processed'", "]", ")", ";", "}", "if", "(", "\\", "is_object", "(", "$", "r", "=", "$", "this", "->", "_exec", "(", "$", "args", ")", ")", ")", "{", "$", "a", "=", "$", "r", "->", "get_irow", "(", ")", ";", "return", "$", "a", "?", "(", "int", ")", "$", "a", "[", "0", "]", ":", "null", ";", "}", "return", "null", ";", "}" ]
Return the number of records in the table corresponding to the $where condition (non mandatory). ```php \bbn\x::dump($db->count('table_users', ['name' => 'John'])); // (int) 2 ``` @param string|array $table The table's name or a configuration array @param array $where The "where" condition @return int
[ "Return", "the", "number", "of", "records", "in", "the", "table", "corresponding", "to", "the", "$where", "condition", "(", "non", "mandatory", ")", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2636-L2651
nabab/bbn
src/bbn/db.php
db.select_all_by_keys
public function select_all_by_keys($table, array $fields = [], array $where = [], array $order = [], int $limit = 0, int $start = 0): ?array { if ( $rows = $this->rselect_all($table, $fields, $where, $order, $limit, $start) ){ return x::index_by_first_val($rows); } return $this->check() ? [] : null; }
php
public function select_all_by_keys($table, array $fields = [], array $where = [], array $order = [], int $limit = 0, int $start = 0): ?array { if ( $rows = $this->rselect_all($table, $fields, $where, $order, $limit, $start) ){ return x::index_by_first_val($rows); } return $this->check() ? [] : null; }
[ "public", "function", "select_all_by_keys", "(", "$", "table", ",", "array", "$", "fields", "=", "[", "]", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ",", "int", "$", "limit", "=", "0", ",", "int", "$", "start", "=", "0", ")", ":", "?", "array", "{", "if", "(", "$", "rows", "=", "$", "this", "->", "rselect_all", "(", "$", "table", ",", "$", "fields", ",", "$", "where", ",", "$", "order", ",", "$", "limit", ",", "$", "start", ")", ")", "{", "return", "x", "::", "index_by_first_val", "(", "$", "rows", ")", ";", "}", "return", "$", "this", "->", "check", "(", ")", "?", "[", "]", ":", "null", ";", "}" ]
Return an array indexed on the first field of the request. The value will be an array if the request has more than two fields. Return the same value as "get_key_val". ```php \bbn\x::dump($db->select_all_by_keys("table_users", ["name","id","surname"], [["id", ">", "1"]], ["id" => "ASC"]); /* (array)[ "John" => [ "surname" => "Brown", "id" => 3 ], "Michael" => [ "surname" => "Smith", "id" => 4 ] ] ``` @param string|array $table The table's name or a configuration array @param array $fields The fields's name @param array $where The "where" condition @param array|boolean $order The "order" condition @param int $limit The $limit condition, default: 0 @param int $start The $limit condition, default: 0 @return array|false
[ "Return", "an", "array", "indexed", "on", "the", "first", "field", "of", "the", "request", ".", "The", "value", "will", "be", "an", "array", "if", "the", "request", "has", "more", "than", "two", "fields", ".", "Return", "the", "same", "value", "as", "get_key_val", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2681-L2687
nabab/bbn
src/bbn/db.php
db.stat
public function stat(string $table, string $column, array $where = [], array $order = []): ?array{ if ( $this->check() ){ return $this->rselect_all([ 'tables' => [$table], 'fields' => [ $column, 'num' => 'COUNT(*)' ], 'where' => $where, 'order' => $order, 'group_by' => [$column] ]); } return null; }
php
public function stat(string $table, string $column, array $where = [], array $order = []): ?array{ if ( $this->check() ){ return $this->rselect_all([ 'tables' => [$table], 'fields' => [ $column, 'num' => 'COUNT(*)' ], 'where' => $where, 'order' => $order, 'group_by' => [$column] ]); } return null; }
[ "public", "function", "stat", "(", "string", "$", "table", ",", "string", "$", "column", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ")", ":", "?", "array", "{", "if", "(", "$", "this", "->", "check", "(", ")", ")", "{", "return", "$", "this", "->", "rselect_all", "(", "[", "'tables'", "=>", "[", "$", "table", "]", ",", "'fields'", "=>", "[", "$", "column", ",", "'num'", "=>", "'COUNT(*)'", "]", ",", "'where'", "=>", "$", "where", ",", "'order'", "=>", "$", "order", ",", "'group_by'", "=>", "[", "$", "column", "]", "]", ")", ";", "}", "return", "null", ";", "}" ]
Return an array with the count of values corresponding to the where conditions. ```php \bbn\x::dump($db->stat('table_user', 'name', ['name' => '%n'])); /* (array) [ [ "num" => 1, "name" => "alan", ], [ "num" => 1, "name" => "karen", ], ] ``` @param string|array $table The table's name or a configuration array. @param string $column The field's name. @param array $where The "where" condition. @param array $order The "order" condition. @return array
[ "Return", "an", "array", "with", "the", "count", "of", "values", "corresponding", "to", "the", "where", "conditions", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2712-L2726
nabab/bbn
src/bbn/db.php
db.get_field_values
public function get_field_values($table, $field = null, array $where = [], array $order = []){ return $this->get_column_values($table, $field, $where, $order); }
php
public function get_field_values($table, $field = null, array $where = [], array $order = []){ return $this->get_column_values($table, $field, $where, $order); }
[ "public", "function", "get_field_values", "(", "$", "table", ",", "$", "field", "=", "null", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ")", "{", "return", "$", "this", "->", "get_column_values", "(", "$", "table", ",", "$", "field", ",", "$", "where", ",", "$", "order", ")", ";", "}" ]
Return the unique values of a column of a table as a numeric indexed array. ```php \bbn\x::dump($db->get_field_values("table_users", "surname", [['id', '>', '2']], 1, 1)); // (array) ["Smiths", "White"] ``` @param string|array $table The table's name or a configuration array @param string $field The field's name @param array $where The "where" condition @param array $order The "order" condition @return array | false
[ "Return", "the", "unique", "values", "of", "a", "column", "of", "a", "table", "as", "a", "numeric", "indexed", "array", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2742-L2744
nabab/bbn
src/bbn/db.php
db.count_field_values
public function count_field_values($table, string $field = null, array $where = [], array $order = []){ if ( \is_array($table) && \is_array($table['fields']) && count($table['fields']) ){ $args = $table; $field = array_values($table['fields'])[0]; } else{ $args = [ 'tables' => [$table], 'where' => $where, 'order' => $order ]; } $args = array_merge($args, [ 'kind' => 'SELECT', 'fields' => [ 'val' => $field, 'num' => 'COUNT(*)' ], 'group_by' => [$field] ]); return $this->rselect_all($args); }
php
public function count_field_values($table, string $field = null, array $where = [], array $order = []){ if ( \is_array($table) && \is_array($table['fields']) && count($table['fields']) ){ $args = $table; $field = array_values($table['fields'])[0]; } else{ $args = [ 'tables' => [$table], 'where' => $where, 'order' => $order ]; } $args = array_merge($args, [ 'kind' => 'SELECT', 'fields' => [ 'val' => $field, 'num' => 'COUNT(*)' ], 'group_by' => [$field] ]); return $this->rselect_all($args); }
[ "public", "function", "count_field_values", "(", "$", "table", ",", "string", "$", "field", "=", "null", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ")", "{", "if", "(", "\\", "is_array", "(", "$", "table", ")", "&&", "\\", "is_array", "(", "$", "table", "[", "'fields'", "]", ")", "&&", "count", "(", "$", "table", "[", "'fields'", "]", ")", ")", "{", "$", "args", "=", "$", "table", ";", "$", "field", "=", "array_values", "(", "$", "table", "[", "'fields'", "]", ")", "[", "0", "]", ";", "}", "else", "{", "$", "args", "=", "[", "'tables'", "=>", "[", "$", "table", "]", ",", "'where'", "=>", "$", "where", ",", "'order'", "=>", "$", "order", "]", ";", "}", "$", "args", "=", "array_merge", "(", "$", "args", ",", "[", "'kind'", "=>", "'SELECT'", ",", "'fields'", "=>", "[", "'val'", "=>", "$", "field", ",", "'num'", "=>", "'COUNT(*)'", "]", ",", "'group_by'", "=>", "[", "$", "field", "]", "]", ")", ";", "return", "$", "this", "->", "rselect_all", "(", "$", "args", ")", ";", "}" ]
Return a count of identical values in a field as array, reporting a structure type 'num' - 'val'. ```php \bbn\x::dump($db->count_field_values('table_users','surname',[['name','=','John']])); // (array) ["num" => 2, "val" => "John"] ``` @param string|array $table The table's name or a configuration array @param null|string $field The field's name @param array $where The "where" condition @param array $order The "order" condition @return array | false
[ "Return", "a", "count", "of", "identical", "values", "in", "a", "field", "as", "array", "reporting", "a", "structure", "type", "num", "-", "val", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2760-L2781
nabab/bbn
src/bbn/db.php
db.get_column_values
public function get_column_values($table, string $field = null, array $where = [], array $order = []): ?array { if ( \is_array($table) && isset($table['fields']) && \is_array($table['fields']) && !empty($table['fields'][0]) ){ array_splice($table['fields'], 0, 1, 'DISTINCT '.(string)$table['fields'][0]); } else if ( \is_string($table) && \is_string($field) && (stripos($field, 'DISTINCT') !== 0) ){ $field = 'DISTINCT '.$field; } if ( $rows = $this->iselect_all($table, $field, $where, $order) ){ $r = []; foreach ( $rows as $row ){ $r[] = $row[0]; } return $r; } return $this->check() ? [] : null; }
php
public function get_column_values($table, string $field = null, array $where = [], array $order = []): ?array { if ( \is_array($table) && isset($table['fields']) && \is_array($table['fields']) && !empty($table['fields'][0]) ){ array_splice($table['fields'], 0, 1, 'DISTINCT '.(string)$table['fields'][0]); } else if ( \is_string($table) && \is_string($field) && (stripos($field, 'DISTINCT') !== 0) ){ $field = 'DISTINCT '.$field; } if ( $rows = $this->iselect_all($table, $field, $where, $order) ){ $r = []; foreach ( $rows as $row ){ $r[] = $row[0]; } return $r; } return $this->check() ? [] : null; }
[ "public", "function", "get_column_values", "(", "$", "table", ",", "string", "$", "field", "=", "null", ",", "array", "$", "where", "=", "[", "]", ",", "array", "$", "order", "=", "[", "]", ")", ":", "?", "array", "{", "if", "(", "\\", "is_array", "(", "$", "table", ")", "&&", "isset", "(", "$", "table", "[", "'fields'", "]", ")", "&&", "\\", "is_array", "(", "$", "table", "[", "'fields'", "]", ")", "&&", "!", "empty", "(", "$", "table", "[", "'fields'", "]", "[", "0", "]", ")", ")", "{", "array_splice", "(", "$", "table", "[", "'fields'", "]", ",", "0", ",", "1", ",", "'DISTINCT '", ".", "(", "string", ")", "$", "table", "[", "'fields'", "]", "[", "0", "]", ")", ";", "}", "else", "if", "(", "\\", "is_string", "(", "$", "table", ")", "&&", "\\", "is_string", "(", "$", "field", ")", "&&", "(", "stripos", "(", "$", "field", ",", "'DISTINCT'", ")", "!==", "0", ")", ")", "{", "$", "field", "=", "'DISTINCT '", ".", "$", "field", ";", "}", "if", "(", "$", "rows", "=", "$", "this", "->", "iselect_all", "(", "$", "table", ",", "$", "field", ",", "$", "where", ",", "$", "order", ")", ")", "{", "$", "r", "=", "[", "]", ";", "foreach", "(", "$", "rows", "as", "$", "row", ")", "{", "$", "r", "[", "]", "=", "$", "row", "[", "0", "]", ";", "}", "return", "$", "r", ";", "}", "return", "$", "this", "->", "check", "(", ")", "?", "[", "]", ":", "null", ";", "}" ]
Return a numeric indexed array with the values of the unique column ($field) from the selected $table ```php \bbn\x::dump($db->get_column_values('table_users','surname',['id','>',1])); /* array [ "Smith", "Jones", "Williams", "Taylor" ] ``` @param string|array $table The table's name or a configuration array @param string $field The field's name @param array $where The "where" condition @param array $order The "order" condition @return array
[ "Return", "a", "numeric", "indexed", "array", "with", "the", "values", "of", "the", "unique", "column", "(", "$field", ")", "from", "the", "selected", "$table" ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2803-L2819
nabab/bbn
src/bbn/db.php
db.get_values_count
public function get_values_count($table, string $field = null, array $where = [], $order): array { return $this->count_field_values($table, $field, $where, $order); }
php
public function get_values_count($table, string $field = null, array $where = [], $order): array { return $this->count_field_values($table, $field, $where, $order); }
[ "public", "function", "get_values_count", "(", "$", "table", ",", "string", "$", "field", "=", "null", ",", "array", "$", "where", "=", "[", "]", ",", "$", "order", ")", ":", "array", "{", "return", "$", "this", "->", "count_field_values", "(", "$", "table", ",", "$", "field", ",", "$", "where", ",", "$", "order", ")", ";", "}" ]
Return a string with the sql query to count equal values in a field of the table. ```php \bbn\x::dump($db->get_values_count('table_users','name',['surname','=','smith'])); /* (string) SELECT COUNT(*) AS num, `name` AS val FROM `db_example`.`table_users` GROUP BY `name` ORDER BY `name` ``` @param string|array $table The table's name or a configuration array @param string $field The field's name @param array $where The "where" condition @param array $order The "order" condition @return array
[ "Return", "a", "string", "with", "the", "sql", "query", "to", "count", "equal", "values", "in", "a", "field", "of", "the", "table", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2839-L2842
nabab/bbn
src/bbn/db.php
db.insert
public function insert($table, array $values = null, $ignore = false): ?int { if ( \is_array($table) && isset($table['values']) ){ $values = $table['values']; } // Array of arrays if ( \is_array($values) && count($values) && !x::is_assoc($values) && \is_array($values[0]) ){ $res = 0; foreach ( $values as $v ){ $res += $this->insert($table, $v, $ignore); } return $res; } $cfg = \is_array($table) ? $table : [ 'tables' => [$table], 'fields' => $values, 'ignore' => $ignore ]; $cfg['kind'] = 'INSERT'; return $this->_exec($cfg); }
php
public function insert($table, array $values = null, $ignore = false): ?int { if ( \is_array($table) && isset($table['values']) ){ $values = $table['values']; } // Array of arrays if ( \is_array($values) && count($values) && !x::is_assoc($values) && \is_array($values[0]) ){ $res = 0; foreach ( $values as $v ){ $res += $this->insert($table, $v, $ignore); } return $res; } $cfg = \is_array($table) ? $table : [ 'tables' => [$table], 'fields' => $values, 'ignore' => $ignore ]; $cfg['kind'] = 'INSERT'; return $this->_exec($cfg); }
[ "public", "function", "insert", "(", "$", "table", ",", "array", "$", "values", "=", "null", ",", "$", "ignore", "=", "false", ")", ":", "?", "int", "{", "if", "(", "\\", "is_array", "(", "$", "table", ")", "&&", "isset", "(", "$", "table", "[", "'values'", "]", ")", ")", "{", "$", "values", "=", "$", "table", "[", "'values'", "]", ";", "}", "// Array of arrays", "if", "(", "\\", "is_array", "(", "$", "values", ")", "&&", "count", "(", "$", "values", ")", "&&", "!", "x", "::", "is_assoc", "(", "$", "values", ")", "&&", "\\", "is_array", "(", "$", "values", "[", "0", "]", ")", ")", "{", "$", "res", "=", "0", ";", "foreach", "(", "$", "values", "as", "$", "v", ")", "{", "$", "res", "+=", "$", "this", "->", "insert", "(", "$", "table", ",", "$", "v", ",", "$", "ignore", ")", ";", "}", "return", "$", "res", ";", "}", "$", "cfg", "=", "\\", "is_array", "(", "$", "table", ")", "?", "$", "table", ":", "[", "'tables'", "=>", "[", "$", "table", "]", ",", "'fields'", "=>", "$", "values", ",", "'ignore'", "=>", "$", "ignore", "]", ";", "$", "cfg", "[", "'kind'", "]", "=", "'INSERT'", ";", "return", "$", "this", "->", "_exec", "(", "$", "cfg", ")", ";", "}" ]
Inserts row(s) in a table. <code> $this->db->insert("table_users", [ ["name" => "Ted"], ["surname" => "McLow"] ]); </code> <code> $this->db->insert("table_users", [ ["name" => "July"], ["surname" => "O'neill"] ], [ ["name" => "Peter"], ["surname" => "Griffin"] ], [ ["name" => "Marge"], ["surname" => "Simpson"] ]); </code> @param string|array $table The table name or the configuration array. @param array $values The values to insert. @param bool $ignore If true, controls if the row is already existing and ignores it. @return int Number affected rows.
[ "Inserts", "row", "(", "s", ")", "in", "a", "table", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2881-L2908
nabab/bbn
src/bbn/db.php
db.insert_update
public function insert_update($table, array $values = null): ?int { // Twice the arguments if ( \is_array($table) && isset($table['values']) ){ $values = $table['values']; } if ( !x::is_assoc($values) ){ $res = 0; foreach ( $values as $v ){ $res += $this->insert_update($table, $v); } return $res; } $keys = $this->get_keys($table); $unique = []; foreach ( $keys['keys'] as $k ){ // Checking each unique key if ( $k['unique'] ){ $i = 0; foreach ( $k['columns'] as $c ){ if ( isset($values[$c]) ){ $unique[$c] = $values[$c]; $i++; } } // Only if the number of known field values matches the number of columns qhich are parts of the unique key if ( ($i === \count($k['columns'])) && $this->count($table, $unique) ){ // Removing unique matching fields from the values (as it is the where) foreach ( $unique as $f => $v ){ unset($values[$f]); } // For updating return $this->update($table, $values, $unique); } } } // No need to update, inserting return $this->insert($table, $values); }
php
public function insert_update($table, array $values = null): ?int { // Twice the arguments if ( \is_array($table) && isset($table['values']) ){ $values = $table['values']; } if ( !x::is_assoc($values) ){ $res = 0; foreach ( $values as $v ){ $res += $this->insert_update($table, $v); } return $res; } $keys = $this->get_keys($table); $unique = []; foreach ( $keys['keys'] as $k ){ // Checking each unique key if ( $k['unique'] ){ $i = 0; foreach ( $k['columns'] as $c ){ if ( isset($values[$c]) ){ $unique[$c] = $values[$c]; $i++; } } // Only if the number of known field values matches the number of columns qhich are parts of the unique key if ( ($i === \count($k['columns'])) && $this->count($table, $unique) ){ // Removing unique matching fields from the values (as it is the where) foreach ( $unique as $f => $v ){ unset($values[$f]); } // For updating return $this->update($table, $values, $unique); } } } // No need to update, inserting return $this->insert($table, $values); }
[ "public", "function", "insert_update", "(", "$", "table", ",", "array", "$", "values", "=", "null", ")", ":", "?", "int", "{", "// Twice the arguments", "if", "(", "\\", "is_array", "(", "$", "table", ")", "&&", "isset", "(", "$", "table", "[", "'values'", "]", ")", ")", "{", "$", "values", "=", "$", "table", "[", "'values'", "]", ";", "}", "if", "(", "!", "x", "::", "is_assoc", "(", "$", "values", ")", ")", "{", "$", "res", "=", "0", ";", "foreach", "(", "$", "values", "as", "$", "v", ")", "{", "$", "res", "+=", "$", "this", "->", "insert_update", "(", "$", "table", ",", "$", "v", ")", ";", "}", "return", "$", "res", ";", "}", "$", "keys", "=", "$", "this", "->", "get_keys", "(", "$", "table", ")", ";", "$", "unique", "=", "[", "]", ";", "foreach", "(", "$", "keys", "[", "'keys'", "]", "as", "$", "k", ")", "{", "// Checking each unique key", "if", "(", "$", "k", "[", "'unique'", "]", ")", "{", "$", "i", "=", "0", ";", "foreach", "(", "$", "k", "[", "'columns'", "]", "as", "$", "c", ")", "{", "if", "(", "isset", "(", "$", "values", "[", "$", "c", "]", ")", ")", "{", "$", "unique", "[", "$", "c", "]", "=", "$", "values", "[", "$", "c", "]", ";", "$", "i", "++", ";", "}", "}", "// Only if the number of known field values matches the number of columns qhich are parts of the unique key", "if", "(", "(", "$", "i", "===", "\\", "count", "(", "$", "k", "[", "'columns'", "]", ")", ")", "&&", "$", "this", "->", "count", "(", "$", "table", ",", "$", "unique", ")", ")", "{", "// Removing unique matching fields from the values (as it is the where)", "foreach", "(", "$", "unique", "as", "$", "f", "=>", "$", "v", ")", "{", "unset", "(", "$", "values", "[", "$", "f", "]", ")", ";", "}", "// For updating", "return", "$", "this", "->", "update", "(", "$", "table", ",", "$", "values", ",", "$", "unique", ")", ";", "}", "}", "}", "// No need to update, inserting", "return", "$", "this", "->", "insert", "(", "$", "table", ",", "$", "values", ")", ";", "}" ]
If not exist inserts row(s) in a table, else update. <code> $this->db->insert_update( "table_users", [ 'id' => '12', 'name' => 'Frank' ] ); </code> @param string|array $table The table name or the configuration array. @param array $values The values to insert. @return int The number of rows inserted or updated.
[ "If", "not", "exist", "inserts", "row", "(", "s", ")", "in", "a", "table", "else", "update", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2928-L2965
nabab/bbn
src/bbn/db.php
db.update
public function update($table, array $values = null, array $where = null, bool $ignore = false): ?int { $cfg = \is_array($table) ? $table : [ 'tables' => [$table], 'where' => $where, 'fields' => $values, 'ignore' => $ignore ]; $cfg['kind'] = 'UPDATE'; return $this->_exec($cfg); }
php
public function update($table, array $values = null, array $where = null, bool $ignore = false): ?int { $cfg = \is_array($table) ? $table : [ 'tables' => [$table], 'where' => $where, 'fields' => $values, 'ignore' => $ignore ]; $cfg['kind'] = 'UPDATE'; return $this->_exec($cfg); }
[ "public", "function", "update", "(", "$", "table", ",", "array", "$", "values", "=", "null", ",", "array", "$", "where", "=", "null", ",", "bool", "$", "ignore", "=", "false", ")", ":", "?", "int", "{", "$", "cfg", "=", "\\", "is_array", "(", "$", "table", ")", "?", "$", "table", ":", "[", "'tables'", "=>", "[", "$", "table", "]", ",", "'where'", "=>", "$", "where", ",", "'fields'", "=>", "$", "values", ",", "'ignore'", "=>", "$", "ignore", "]", ";", "$", "cfg", "[", "'kind'", "]", "=", "'UPDATE'", ";", "return", "$", "this", "->", "_exec", "(", "$", "cfg", ")", ";", "}" ]
Updates row(s) in a table. <code> $this->db->update( "table_users", [ ['name' => 'Frank'], ['surname' => 'Red'] ], ['id' => '127'] ); </code> @param string|array $table The table name or the configuration array. @param array $values The new value(s). @param array $where The "where" condition. @param boolean $ignore If IGNORE should be added to the statement @return int The number of rows updated.
[ "Updates", "row", "(", "s", ")", "in", "a", "table", "." ]
train
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2988-L2998