id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
22,700
|
Innmind/neo4j-dbal
|
src/Query/Query.php
|
Query.return
|
public function return(string ...$variables): self
{
$query = new self;
$query->clauses = $this->clauses->add(
new Clause\ReturnClause(...$variables)
);
return $query;
}
|
php
|
public function return(string ...$variables): self
{
$query = new self;
$query->clauses = $this->clauses->add(
new Clause\ReturnClause(...$variables)
);
return $query;
}
|
[
"public",
"function",
"return",
"(",
"string",
"...",
"$",
"variables",
")",
":",
"self",
"{",
"$",
"query",
"=",
"new",
"self",
";",
"$",
"query",
"->",
"clauses",
"=",
"$",
"this",
"->",
"clauses",
"->",
"add",
"(",
"new",
"Clause",
"\\",
"ReturnClause",
"(",
"...",
"$",
"variables",
")",
")",
";",
"return",
"$",
"query",
";",
"}"
] |
Add a RETURN clause
@param string[] $variables
@return self
|
[
"Add",
"a",
"RETURN",
"clause"
] |
12cb71e698cc0f4d55b7f2eb40f7b353c778a20b
|
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L554-L562
|
22,701
|
Innmind/neo4j-dbal
|
src/Query/Query.php
|
Query.remove
|
public function remove(string $cypher): self
{
$query = new self;
$query->clauses = $this->clauses->add(
new Clause\RemoveClause($cypher)
);
return $query;
}
|
php
|
public function remove(string $cypher): self
{
$query = new self;
$query->clauses = $this->clauses->add(
new Clause\RemoveClause($cypher)
);
return $query;
}
|
[
"public",
"function",
"remove",
"(",
"string",
"$",
"cypher",
")",
":",
"self",
"{",
"$",
"query",
"=",
"new",
"self",
";",
"$",
"query",
"->",
"clauses",
"=",
"$",
"this",
"->",
"clauses",
"->",
"add",
"(",
"new",
"Clause",
"\\",
"RemoveClause",
"(",
"$",
"cypher",
")",
")",
";",
"return",
"$",
"query",
";",
"}"
] |
Add a REMOVE clause
@param string $cypher
@return self
|
[
"Add",
"a",
"REMOVE",
"clause"
] |
12cb71e698cc0f4d55b7f2eb40f7b353c778a20b
|
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L571-L579
|
22,702
|
Innmind/neo4j-dbal
|
src/Query/Query.php
|
Query.orderBy
|
public function orderBy(
string $cypher,
string $direction = 'ASC'
): self {
$direction = \strtolower($direction);
$query = new self;
$query->clauses = $this->clauses->add(
Clause\OrderByClause::$direction($cypher)
);
return $query;
}
|
php
|
public function orderBy(
string $cypher,
string $direction = 'ASC'
): self {
$direction = \strtolower($direction);
$query = new self;
$query->clauses = $this->clauses->add(
Clause\OrderByClause::$direction($cypher)
);
return $query;
}
|
[
"public",
"function",
"orderBy",
"(",
"string",
"$",
"cypher",
",",
"string",
"$",
"direction",
"=",
"'ASC'",
")",
":",
"self",
"{",
"$",
"direction",
"=",
"\\",
"strtolower",
"(",
"$",
"direction",
")",
";",
"$",
"query",
"=",
"new",
"self",
";",
"$",
"query",
"->",
"clauses",
"=",
"$",
"this",
"->",
"clauses",
"->",
"add",
"(",
"Clause",
"\\",
"OrderByClause",
"::",
"$",
"direction",
"(",
"$",
"cypher",
")",
")",
";",
"return",
"$",
"query",
";",
"}"
] |
Add a ORDER BY clause
@param string $cypher
@param string $direction
@return self
|
[
"Add",
"a",
"ORDER",
"BY",
"clause"
] |
12cb71e698cc0f4d55b7f2eb40f7b353c778a20b
|
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L589-L601
|
22,703
|
Innmind/neo4j-dbal
|
src/Query/Query.php
|
Query.onMatch
|
public function onMatch(string $cypher): self
{
$clause = $this->clauses->last();
if (
!$clause instanceof Clause\MergeClause &&
!$clause instanceof Clause\OnCreateClause
) {
throw new NonMergeClause;
}
$query = new self;
$query->clauses = $this->clauses->add(
new Clause\OnMatchClause($cypher)
);
return $query;
}
|
php
|
public function onMatch(string $cypher): self
{
$clause = $this->clauses->last();
if (
!$clause instanceof Clause\MergeClause &&
!$clause instanceof Clause\OnCreateClause
) {
throw new NonMergeClause;
}
$query = new self;
$query->clauses = $this->clauses->add(
new Clause\OnMatchClause($cypher)
);
return $query;
}
|
[
"public",
"function",
"onMatch",
"(",
"string",
"$",
"cypher",
")",
":",
"self",
"{",
"$",
"clause",
"=",
"$",
"this",
"->",
"clauses",
"->",
"last",
"(",
")",
";",
"if",
"(",
"!",
"$",
"clause",
"instanceof",
"Clause",
"\\",
"MergeClause",
"&&",
"!",
"$",
"clause",
"instanceof",
"Clause",
"\\",
"OnCreateClause",
")",
"{",
"throw",
"new",
"NonMergeClause",
";",
"}",
"$",
"query",
"=",
"new",
"self",
";",
"$",
"query",
"->",
"clauses",
"=",
"$",
"this",
"->",
"clauses",
"->",
"add",
"(",
"new",
"Clause",
"\\",
"OnMatchClause",
"(",
"$",
"cypher",
")",
")",
";",
"return",
"$",
"query",
";",
"}"
] |
Add a ON MATCH clause
@param string $cypher
@throws NonMergeClause
@return self
|
[
"Add",
"a",
"ON",
"MATCH",
"clause"
] |
12cb71e698cc0f4d55b7f2eb40f7b353c778a20b
|
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L612-L629
|
22,704
|
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"
] |
12cb71e698cc0f4d55b7f2eb40f7b353c778a20b
|
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L667-L677
|
22,705
|
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"
] |
12cb71e698cc0f4d55b7f2eb40f7b353c778a20b
|
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L687-L695
|
22,706
|
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"
] |
12cb71e698cc0f4d55b7f2eb40f7b353c778a20b
|
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L704-L712
|
22,707
|
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"
] |
12cb71e698cc0f4d55b7f2eb40f7b353c778a20b
|
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L722-L730
|
22,708
|
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"
] |
12cb71e698cc0f4d55b7f2eb40f7b353c778a20b
|
https://github.com/Innmind/neo4j-dbal/blob/12cb71e698cc0f4d55b7f2eb40f7b353c778a20b/src/Query/Query.php#L741-L755
|
22,709
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file.php#L126-L132
|
22,710
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file.php#L163-L180
|
22,711
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file.php#L188-L214
|
22,712
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file.php#L226-L245
|
22,713
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/file.php#L299-L328
|
22,714
|
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",
"."
] |
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
|
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Inputstream/String.php#L380-L384
|
22,715
|
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",
"."
] |
4ea8caf5b2618a82ca5061dcbb7421b31065c1c7
|
https://github.com/PHPPowertools/HTML5/blob/4ea8caf5b2618a82ca5061dcbb7421b31065c1c7/src/PowerTools/HTML5/Inputstream/String.php#L389-L395
|
22,716
|
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"
] |
f2f32eb693bd39385ceb93355efb5b2a429f27ce
|
https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/ICalendar/Event.php#L174-L200
|
22,717
|
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"
] |
f58ec75a3116d1a572782256e2b38bb9aab95e3c
|
https://github.com/eghojansu/moe/blob/f58ec75a3116d1a572782256e2b38bb9aab95e3c/src/tools/web/PingBack.php#L22-L41
|
22,718
|
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"
] |
f58ec75a3116d1a572782256e2b38bb9aab95e3c
|
https://github.com/eghojansu/moe/blob/f58ec75a3116d1a572782256e2b38bb9aab95e3c/src/tools/web/PingBack.php#L49-L86
|
22,719
|
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"
] |
f58ec75a3116d1a572782256e2b38bb9aab95e3c
|
https://github.com/eghojansu/moe/blob/f58ec75a3116d1a572782256e2b38bb9aab95e3c/src/tools/web/PingBack.php#L95-L143
|
22,720
|
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",
"."
] |
daf4a59098802fedcfd1f1a1d07847fcf2fea7bf
|
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Generator/AspectGenerator.php#L70-L75
|
22,721
|
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",
"."
] |
daf4a59098802fedcfd1f1a1d07847fcf2fea7bf
|
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Generator/AspectGenerator.php#L80-L89
|
22,722
|
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",
"."
] |
79f844c5c9c25ffbe18d142062e9bc3df00b36a1
|
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Concerns/ManagesTransactions.php#L63-L86
|
22,723
|
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",
"."
] |
79f844c5c9c25ffbe18d142062e9bc3df00b36a1
|
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Concerns/ManagesTransactions.php#L109-L120
|
22,724
|
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",
"."
] |
79f844c5c9c25ffbe18d142062e9bc3df00b36a1
|
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Concerns/ManagesTransactions.php#L207-L216
|
22,725
|
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"
] |
0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1
|
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Mvc/Model.php#L16-L36
|
22,726
|
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"
] |
0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1
|
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Mvc/Model.php#L43-L88
|
22,727
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L357-L368
|
22,728
|
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"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L376-L410
|
22,729
|
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"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L436-L467
|
22,730
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L880-L889
|
22,731
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1016-L1033
|
22,732
|
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"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1357-L1403
|
22,733
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1414-L1432
|
22,734
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1495-L1502
|
22,735
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1530-L1535
|
22,736
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1546-L1551
|
22,737
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1735-L1759
|
22,738
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1773-L1779
|
22,739
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1793-L1817
|
22,740
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L1980-L1988
|
22,741
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2001-L2012
|
22,742
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2035-L2040
|
22,743
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2080-L2099
|
22,744
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2126-L2132
|
22,745
|
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"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2173-L2204
|
22,746
|
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"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2214-L2277
|
22,747
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2363-L2372
|
22,748
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2422-L2429
|
22,749
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2459-L2465
|
22,750
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2487-L2493
|
22,751
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2523-L2529
|
22,752
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2551-L2557
|
22,753
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2587-L2596
|
22,754
|
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"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2613-L2622
|
22,755
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2681-L2687
|
22,756
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2712-L2726
|
22,757
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2742-L2744
|
22,758
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2760-L2781
|
22,759
|
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",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L2839-L2842
|
22,760
|
nabab/bbn
|
src/bbn/db.php
|
db.change
|
public function change(string $db): self
{
if ( $this->language->change($db) ){
$this->current = $db;
}
return $this;
}
|
php
|
public function change(string $db): self
{
if ( $this->language->change($db) ){
$this->current = $db;
}
return $this;
}
|
[
"public",
"function",
"change",
"(",
"string",
"$",
"db",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"language",
"->",
"change",
"(",
"$",
"db",
")",
")",
"{",
"$",
"this",
"->",
"current",
"=",
"$",
"db",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Changes the database used to the given one.
```php
$db = new db();
x::dump($db->change('db_example'));
// (db)
```
@param string $db The database's name
@return self
|
[
"Changes",
"the",
"database",
"used",
"to",
"the",
"given",
"one",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L3543-L3549
|
22,761
|
nabab/bbn
|
src/bbn/db.php
|
db.table_full_name
|
public function table_full_name(string $table, bool $escaped = false): ?string
{
return $this->language->table_full_name($table, $escaped);
}
|
php
|
public function table_full_name(string $table, bool $escaped = false): ?string
{
return $this->language->table_full_name($table, $escaped);
}
|
[
"public",
"function",
"table_full_name",
"(",
"string",
"$",
"table",
",",
"bool",
"$",
"escaped",
"=",
"false",
")",
":",
"?",
"string",
"{",
"return",
"$",
"this",
"->",
"language",
"->",
"table_full_name",
"(",
"$",
"table",
",",
"$",
"escaped",
")",
";",
"}"
] |
Return table's full name.
```php
bbn\x::dump($db->table_full_name("table_users"));
// (String) db_example.table_users
bbn\x::dump($db->table_full_name("table_users", true));
// (String) `db_example`.`table_users`
```
@param string $table The table's name (escaped or not).
@param bool $escaped If set to true the returned string will be escaped.
@return string | false
|
[
"Return",
"table",
"s",
"full",
"name",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L3581-L3584
|
22,762
|
nabab/bbn
|
src/bbn/db.php
|
db.table_simple_name
|
public function table_simple_name(string $table, bool $escaped = false): ?string
{
return $this->language->table_simple_name($table, $escaped);
}
|
php
|
public function table_simple_name(string $table, bool $escaped = false): ?string
{
return $this->language->table_simple_name($table, $escaped);
}
|
[
"public",
"function",
"table_simple_name",
"(",
"string",
"$",
"table",
",",
"bool",
"$",
"escaped",
"=",
"false",
")",
":",
"?",
"string",
"{",
"return",
"$",
"this",
"->",
"language",
"->",
"table_simple_name",
"(",
"$",
"table",
",",
"$",
"escaped",
")",
";",
"}"
] |
Return table's simple name.
```php
\bbn\x::dump($db->table_simple_name("example_db.table_users"));
// (string) table_users
\bbn\x::dump($db->table_simple_name("example.table_users", true));
// (string) `table_users`
```
@param string $table The table's name (escaped or not)
@param bool $escaped If set to true the returned string will be escaped
@return string | false
|
[
"Return",
"table",
"s",
"simple",
"name",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L3628-L3631
|
22,763
|
nabab/bbn
|
src/bbn/db.php
|
db.col_full_name
|
public function col_full_name(string $col, $table = '', $escaped = false): ?string
{
return $this->language->col_full_name($col, $table, $escaped);
}
|
php
|
public function col_full_name(string $col, $table = '', $escaped = false): ?string
{
return $this->language->col_full_name($col, $table, $escaped);
}
|
[
"public",
"function",
"col_full_name",
"(",
"string",
"$",
"col",
",",
"$",
"table",
"=",
"''",
",",
"$",
"escaped",
"=",
"false",
")",
":",
"?",
"string",
"{",
"return",
"$",
"this",
"->",
"language",
"->",
"col_full_name",
"(",
"$",
"col",
",",
"$",
"table",
",",
"$",
"escaped",
")",
";",
"}"
] |
Return column's full name.
```php
\bbn\x::dump($db->col_full_name("name", "table_users"));
// (string) table_users.name
\bbn\x::dump($db->col_full_name("name", "table_users", true));
// (string) \`table_users\`.\`name\`
```
@param string $col The column's name (escaped or not)
@param string $table The table's name (escaped or not)
@param bool $escaped If set to true the returned string will be escaped
@return string | false
|
[
"Return",
"column",
"s",
"full",
"name",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L3648-L3651
|
22,764
|
nabab/bbn
|
src/bbn/db.php
|
db.col_simple_name
|
public function col_simple_name(string $col, bool $escaped = false): ?string
{
return $this->language->col_simple_name($col, $escaped);
}
|
php
|
public function col_simple_name(string $col, bool $escaped = false): ?string
{
return $this->language->col_simple_name($col, $escaped);
}
|
[
"public",
"function",
"col_simple_name",
"(",
"string",
"$",
"col",
",",
"bool",
"$",
"escaped",
"=",
"false",
")",
":",
"?",
"string",
"{",
"return",
"$",
"this",
"->",
"language",
"->",
"col_simple_name",
"(",
"$",
"col",
",",
"$",
"escaped",
")",
";",
"}"
] |
Return the column's simple name.
```php
\bbn\x::dump($db->col_simple_name("table_users.name"));
// (string) name
\bbn\x::dump($db->col_simple_name("table_users.name", true));
// (string) `name`
```
@param string $col The column's complete name (escaped or not).
@param bool $escaped If set to true the returned string will be escaped.
@return string | false
|
[
"Return",
"the",
"column",
"s",
"simple",
"name",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L3667-L3670
|
22,765
|
nabab/bbn
|
src/bbn/db.php
|
db.get_tables
|
public function get_tables(string $database=''): ?array
{
if ( empty($database) ){
$database = $this->current;
}
return $this->_get_cache($database, 'tables');
}
|
php
|
public function get_tables(string $database=''): ?array
{
if ( empty($database) ){
$database = $this->current;
}
return $this->_get_cache($database, 'tables');
}
|
[
"public",
"function",
"get_tables",
"(",
"string",
"$",
"database",
"=",
"''",
")",
":",
"?",
"array",
"{",
"if",
"(",
"empty",
"(",
"$",
"database",
")",
")",
"{",
"$",
"database",
"=",
"$",
"this",
"->",
"current",
";",
"}",
"return",
"$",
"this",
"->",
"_get_cache",
"(",
"$",
"database",
",",
"'tables'",
")",
";",
"}"
] |
Return tables' names of a database as an array.
```php
\bbn\x::dump($db->get_tables('db_example'));
/*
(array) [
"clients",
"columns",
"cron",
"journal",
"dbs",
"examples",
"history",
"hosts",
"keys",
"mails",
"medias",
"notes",
"medias",
"versions"
]
```
@param string $database Database name
@return null|array
|
[
"Return",
"tables",
"names",
"of",
"a",
"database",
"as",
"an",
"array",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L3753-L3759
|
22,766
|
nabab/bbn
|
src/bbn/db.php
|
db.get_keys
|
public function get_keys(string $table): ?array
{
if ( $tmp = $this->_get_cache($table) ){
return [
'keys' => $tmp['keys'],
'cols' => $tmp['cols']
];
}
return null;
}
|
php
|
public function get_keys(string $table): ?array
{
if ( $tmp = $this->_get_cache($table) ){
return [
'keys' => $tmp['keys'],
'cols' => $tmp['cols']
];
}
return null;
}
|
[
"public",
"function",
"get_keys",
"(",
"string",
"$",
"table",
")",
":",
"?",
"array",
"{",
"if",
"(",
"$",
"tmp",
"=",
"$",
"this",
"->",
"_get_cache",
"(",
"$",
"table",
")",
")",
"{",
"return",
"[",
"'keys'",
"=>",
"$",
"tmp",
"[",
"'keys'",
"]",
",",
"'cols'",
"=>",
"$",
"tmp",
"[",
"'cols'",
"]",
"]",
";",
"}",
"return",
"null",
";",
"}"
] |
Return the table's keys as an array indexed with the fields names.
```php
\bbn\x::dump($db->get_keys("table_users"));
/*
(array)[
"keys" => [
"PRIMARY" => [
"columns" => [
"id",
],
"ref_db" => null,
"ref_table" => null,
"ref_column" => null,
"unique" => 1,
],
"number" => [
"columns" => [
"number",
],
"ref_db" => null,
"ref_table" => null,
"ref_column" => null,
"unique" => 1,
],
],
"cols" => [
"id" => [
"PRIMARY",
],
"number" => [
"number",
],
],
]
```
@param string $table The table's name
@return null|array
|
[
"Return",
"the",
"table",
"s",
"keys",
"as",
"an",
"array",
"indexed",
"with",
"the",
"fields",
"names",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L3862-L3871
|
22,767
|
nabab/bbn
|
src/bbn/db.php
|
db.get_insert
|
public function get_insert(array $cfg): string
{
$cfg['kind'] = 'INSERT';
return $this->language->get_insert($this->process_cfg($cfg));
}
|
php
|
public function get_insert(array $cfg): string
{
$cfg['kind'] = 'INSERT';
return $this->language->get_insert($this->process_cfg($cfg));
}
|
[
"public",
"function",
"get_insert",
"(",
"array",
"$",
"cfg",
")",
":",
"string",
"{",
"$",
"cfg",
"[",
"'kind'",
"]",
"=",
"'INSERT'",
";",
"return",
"$",
"this",
"->",
"language",
"->",
"get_insert",
"(",
"$",
"this",
"->",
"process_cfg",
"(",
"$",
"cfg",
")",
")",
";",
"}"
] |
Returns the SQL code for an INSERT statement.
```php
\bbn\x::dump($db->get_insert([
'tables' => ['table_users'],
'fields' => ['name','surname']
]));
/*
(string)
INSERT INTO `db_example`.`table_users` (
`name`, `surname`)
VALUES (?, ?)
```
@param array $cfg The configuration array
@return string
|
[
"Returns",
"the",
"SQL",
"code",
"for",
"an",
"INSERT",
"statement",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L3922-L3926
|
22,768
|
nabab/bbn
|
src/bbn/db.php
|
db.get_update
|
public function get_update(array $cfg): string
{
$cfg['kind'] = 'UPDATE';
return $this->language->get_update($this->process_cfg($cfg));
}
|
php
|
public function get_update(array $cfg): string
{
$cfg['kind'] = 'UPDATE';
return $this->language->get_update($this->process_cfg($cfg));
}
|
[
"public",
"function",
"get_update",
"(",
"array",
"$",
"cfg",
")",
":",
"string",
"{",
"$",
"cfg",
"[",
"'kind'",
"]",
"=",
"'UPDATE'",
";",
"return",
"$",
"this",
"->",
"language",
"->",
"get_update",
"(",
"$",
"this",
"->",
"process_cfg",
"(",
"$",
"cfg",
")",
")",
";",
"}"
] |
Returns the SQL code for an UPDATE statement.
```php
\bbn\x::dump($db->get_update([
'tables' => ['table_users'],
'fields' => ['name','surname']
]));
/*
(string)
UPDATE `db_example`.`table_users`
SET `table_users`.`name` = ?,
`table_users`.`surname` = ?
```
@param array $cfg The configuration array
@return string
|
[
"Returns",
"the",
"SQL",
"code",
"for",
"an",
"UPDATE",
"statement",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L3946-L3950
|
22,769
|
nabab/bbn
|
src/bbn/db.php
|
db.get_delete
|
public function get_delete(array $cfg): string
{
$cfg['kind'] = 'DELETE';
return $this->language->get_delete($this->process_cfg($cfg));
}
|
php
|
public function get_delete(array $cfg): string
{
$cfg['kind'] = 'DELETE';
return $this->language->get_delete($this->process_cfg($cfg));
}
|
[
"public",
"function",
"get_delete",
"(",
"array",
"$",
"cfg",
")",
":",
"string",
"{",
"$",
"cfg",
"[",
"'kind'",
"]",
"=",
"'DELETE'",
";",
"return",
"$",
"this",
"->",
"language",
"->",
"get_delete",
"(",
"$",
"this",
"->",
"process_cfg",
"(",
"$",
"cfg",
")",
")",
";",
"}"
] |
Returns the SQL code for a DELETE statement.
```php
\bbn\x::dump($db->get_delete('table_users',['id'=>1]));
// (string) DELETE FROM `db_example`.`table_users` * WHERE 1 AND `table_users`.`id` = ?
```
@param array $cfg The configuration array
@return string
|
[
"Returns",
"the",
"SQL",
"code",
"for",
"a",
"DELETE",
"statement",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L3963-L3967
|
22,770
|
nabab/bbn
|
src/bbn/db.php
|
db.delete_index
|
public function delete_index(string $table, string $key): bool
{
return $this->language->delete_index($table, $key);
}
|
php
|
public function delete_index(string $table, string $key): bool
{
return $this->language->delete_index($table, $key);
}
|
[
"public",
"function",
"delete_index",
"(",
"string",
"$",
"table",
",",
"string",
"$",
"key",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"language",
"->",
"delete_index",
"(",
"$",
"table",
",",
"$",
"key",
")",
";",
"}"
] |
Deletes index on a column of the table.
@todo far vedere a thomas perchè non funziona/return data
```php
\bbn\x::dump($db->delete_db_index('table_users','id_group'));
// (void)
```
@param string $table The table's name.
@param string $key The key's name.
@return bool
|
[
"Deletes",
"index",
"on",
"a",
"column",
"of",
"the",
"table",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/db.php#L4109-L4112
|
22,771
|
verdet23/SphinxSearchBundle
|
Services/Search/SphinxSearch.php
|
SphinxSearch.setLimits
|
public function setLimits($offset, $limit, $max = 0, $cutoff = 0)
{
$this->sphinx->setLimits($offset, $limit, $max, $cutoff);
}
|
php
|
public function setLimits($offset, $limit, $max = 0, $cutoff = 0)
{
$this->sphinx->setLimits($offset, $limit, $max, $cutoff);
}
|
[
"public",
"function",
"setLimits",
"(",
"$",
"offset",
",",
"$",
"limit",
",",
"$",
"max",
"=",
"0",
",",
"$",
"cutoff",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"sphinx",
"->",
"setLimits",
"(",
"$",
"offset",
",",
"$",
"limit",
",",
"$",
"max",
",",
"$",
"cutoff",
")",
";",
"}"
] |
Set limits on the range and number of results returned.
@param int $offset The number of results to seek past.
@param int $limit The number of results to return.
@param int $max The maximum number of matches to retrieve.
@param int $cutoff The cutoff to stop searching at.
|
[
"Set",
"limits",
"on",
"the",
"range",
"and",
"number",
"of",
"results",
"returned",
"."
] |
6452cc3a5fab83647b6c08574164249fb8f03b05
|
https://github.com/verdet23/SphinxSearchBundle/blob/6452cc3a5fab83647b6c08574164249fb8f03b05/Services/Search/SphinxSearch.php#L89-L92
|
22,772
|
verdet23/SphinxSearchBundle
|
Services/Search/SphinxSearch.php
|
SphinxSearch.setFilter
|
public function setFilter($attribute, $values, $exclude = false)
{
$this->sphinx->setFilter($attribute, $values, $exclude);
}
|
php
|
public function setFilter($attribute, $values, $exclude = false)
{
$this->sphinx->setFilter($attribute, $values, $exclude);
}
|
[
"public",
"function",
"setFilter",
"(",
"$",
"attribute",
",",
"$",
"values",
",",
"$",
"exclude",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"sphinx",
"->",
"setFilter",
"(",
"$",
"attribute",
",",
"$",
"values",
",",
"$",
"exclude",
")",
";",
"}"
] |
Set the desired search filter.
@param string $attribute The attribute to filter.
@param array $values The values to filter.
@param bool $exclude Is this an exclusion filter?
|
[
"Set",
"the",
"desired",
"search",
"filter",
"."
] |
6452cc3a5fab83647b6c08574164249fb8f03b05
|
https://github.com/verdet23/SphinxSearchBundle/blob/6452cc3a5fab83647b6c08574164249fb8f03b05/Services/Search/SphinxSearch.php#L116-L119
|
22,773
|
verdet23/SphinxSearchBundle
|
Services/Search/SphinxSearch.php
|
SphinxSearch.search
|
public function search($query, array $indexes, array $options = array(), $escapeQuery = true)
{
if ($escapeQuery) {
$query = $this->sphinx->escapeString($query);
}
/**
* Build the list of indexes to be queried.
*/
$indexNames = '';
foreach ($indexes as &$label) {
if (isset($this->indexes[$label])) {
$indexNames .= $this->indexes[$label] . ' ';
}
}
$indexNames = trim($indexNames);
/**
* If no valid indexes were specified, return an empty result set.
*/
if (empty($indexNames)) {
return array();
}
/**
* Set the offset and limit for the returned results.
*/
if (isset($options['result_offset']) && isset($options['result_limit'])) {
$this->sphinx->setLimits($options['result_offset'], $options['result_limit']);
}
/**
* Weight the individual fields.
*/
if (isset($options['field_weights'])) {
$this->sphinx->setFieldWeights($options['field_weights']);
}
/**
* Perform the query.
*/
$results = $this->sphinx->query($query, $indexNames);
if ($results === false || $results['status'] !== SEARCHD_OK) {
if(is_array($results) && $results['status'] === SEARCHD_WARNING) {
$errorText = $this->sphinx->getLastWarning();
} else {
$errorText = $this->sphinx->getLastError();
}
throw new \RuntimeException(sprintf(
'Searching index "%s" for "%s" failed with message "%s".',
$label,
$query,
$errorText
));
}
return $results;
}
|
php
|
public function search($query, array $indexes, array $options = array(), $escapeQuery = true)
{
if ($escapeQuery) {
$query = $this->sphinx->escapeString($query);
}
/**
* Build the list of indexes to be queried.
*/
$indexNames = '';
foreach ($indexes as &$label) {
if (isset($this->indexes[$label])) {
$indexNames .= $this->indexes[$label] . ' ';
}
}
$indexNames = trim($indexNames);
/**
* If no valid indexes were specified, return an empty result set.
*/
if (empty($indexNames)) {
return array();
}
/**
* Set the offset and limit for the returned results.
*/
if (isset($options['result_offset']) && isset($options['result_limit'])) {
$this->sphinx->setLimits($options['result_offset'], $options['result_limit']);
}
/**
* Weight the individual fields.
*/
if (isset($options['field_weights'])) {
$this->sphinx->setFieldWeights($options['field_weights']);
}
/**
* Perform the query.
*/
$results = $this->sphinx->query($query, $indexNames);
if ($results === false || $results['status'] !== SEARCHD_OK) {
if(is_array($results) && $results['status'] === SEARCHD_WARNING) {
$errorText = $this->sphinx->getLastWarning();
} else {
$errorText = $this->sphinx->getLastError();
}
throw new \RuntimeException(sprintf(
'Searching index "%s" for "%s" failed with message "%s".',
$label,
$query,
$errorText
));
}
return $results;
}
|
[
"public",
"function",
"search",
"(",
"$",
"query",
",",
"array",
"$",
"indexes",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"escapeQuery",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"escapeQuery",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"sphinx",
"->",
"escapeString",
"(",
"$",
"query",
")",
";",
"}",
"/**\n * Build the list of indexes to be queried.\n */",
"$",
"indexNames",
"=",
"''",
";",
"foreach",
"(",
"$",
"indexes",
"as",
"&",
"$",
"label",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"indexes",
"[",
"$",
"label",
"]",
")",
")",
"{",
"$",
"indexNames",
".=",
"$",
"this",
"->",
"indexes",
"[",
"$",
"label",
"]",
".",
"' '",
";",
"}",
"}",
"$",
"indexNames",
"=",
"trim",
"(",
"$",
"indexNames",
")",
";",
"/**\n * If no valid indexes were specified, return an empty result set.\n */",
"if",
"(",
"empty",
"(",
"$",
"indexNames",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"/**\n * Set the offset and limit for the returned results.\n */",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'result_offset'",
"]",
")",
"&&",
"isset",
"(",
"$",
"options",
"[",
"'result_limit'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sphinx",
"->",
"setLimits",
"(",
"$",
"options",
"[",
"'result_offset'",
"]",
",",
"$",
"options",
"[",
"'result_limit'",
"]",
")",
";",
"}",
"/**\n * Weight the individual fields.\n */",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'field_weights'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sphinx",
"->",
"setFieldWeights",
"(",
"$",
"options",
"[",
"'field_weights'",
"]",
")",
";",
"}",
"/**\n * Perform the query.\n */",
"$",
"results",
"=",
"$",
"this",
"->",
"sphinx",
"->",
"query",
"(",
"$",
"query",
",",
"$",
"indexNames",
")",
";",
"if",
"(",
"$",
"results",
"===",
"false",
"||",
"$",
"results",
"[",
"'status'",
"]",
"!==",
"SEARCHD_OK",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"results",
")",
"&&",
"$",
"results",
"[",
"'status'",
"]",
"===",
"SEARCHD_WARNING",
")",
"{",
"$",
"errorText",
"=",
"$",
"this",
"->",
"sphinx",
"->",
"getLastWarning",
"(",
")",
";",
"}",
"else",
"{",
"$",
"errorText",
"=",
"$",
"this",
"->",
"sphinx",
"->",
"getLastError",
"(",
")",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Searching index \"%s\" for \"%s\" failed with message \"%s\".'",
",",
"$",
"label",
",",
"$",
"query",
",",
"$",
"errorText",
")",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] |
Search for the specified query string.
@param string $query The query string that we are searching for.
@param array $indexes The indexes to perform the search on.
@param array $options The options for the query.
@param bool $escapeQuery Should the query string be escaped?
@return array|bool The results of the search.
@throws \RuntimeException
|
[
"Search",
"for",
"the",
"specified",
"query",
"string",
"."
] |
6452cc3a5fab83647b6c08574164249fb8f03b05
|
https://github.com/verdet23/SphinxSearchBundle/blob/6452cc3a5fab83647b6c08574164249fb8f03b05/Services/Search/SphinxSearch.php#L140-L200
|
22,774
|
verdet23/SphinxSearchBundle
|
Services/Search/SphinxSearch.php
|
SphinxSearch.addQuery
|
public function addQuery($query, array $indexes)
{
$indexNames = '';
foreach ($indexes as &$label) {
if (isset($this->indexes[$label])) {
$indexNames .= $this->indexes[$label] . ' ';
}
}
if (!empty($indexNames)) {
$this->sphinx->addQuery($query, $indexNames);
}
}
|
php
|
public function addQuery($query, array $indexes)
{
$indexNames = '';
foreach ($indexes as &$label) {
if (isset($this->indexes[$label])) {
$indexNames .= $this->indexes[$label] . ' ';
}
}
if (!empty($indexNames)) {
$this->sphinx->addQuery($query, $indexNames);
}
}
|
[
"public",
"function",
"addQuery",
"(",
"$",
"query",
",",
"array",
"$",
"indexes",
")",
"{",
"$",
"indexNames",
"=",
"''",
";",
"foreach",
"(",
"$",
"indexes",
"as",
"&",
"$",
"label",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"indexes",
"[",
"$",
"label",
"]",
")",
")",
"{",
"$",
"indexNames",
".=",
"$",
"this",
"->",
"indexes",
"[",
"$",
"label",
"]",
".",
"' '",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"indexNames",
")",
")",
"{",
"$",
"this",
"->",
"sphinx",
"->",
"addQuery",
"(",
"$",
"query",
",",
"$",
"indexNames",
")",
";",
"}",
"}"
] |
Adds a query to a multi-query batch using current settings.
@param string $query The query string that we are searching for.
@param array $indexes The indexes to perform the search on.
|
[
"Adds",
"a",
"query",
"to",
"a",
"multi",
"-",
"query",
"batch",
"using",
"current",
"settings",
"."
] |
6452cc3a5fab83647b6c08574164249fb8f03b05
|
https://github.com/verdet23/SphinxSearchBundle/blob/6452cc3a5fab83647b6c08574164249fb8f03b05/Services/Search/SphinxSearch.php#L208-L220
|
22,775
|
verdet23/SphinxSearchBundle
|
Services/Search/SphinxSearch.php
|
SphinxSearch.getSnippet
|
public function getSnippet($text, $index, $terms, $options = array())
{
$results = $this->getSnippets(array($text), $index, $terms, $options);
if ($results) {
return $results[0];
}
return false;
}
|
php
|
public function getSnippet($text, $index, $terms, $options = array())
{
$results = $this->getSnippets(array($text), $index, $terms, $options);
if ($results) {
return $results[0];
}
return false;
}
|
[
"public",
"function",
"getSnippet",
"(",
"$",
"text",
",",
"$",
"index",
",",
"$",
"terms",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"getSnippets",
"(",
"array",
"(",
"$",
"text",
")",
",",
"$",
"index",
",",
"$",
"terms",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"results",
")",
"{",
"return",
"$",
"results",
"[",
"0",
"]",
";",
"}",
"return",
"false",
";",
"}"
] |
Get snippet for text
@param string $text Text to process
@param string $index Search index
@param string $terms Words for highlight
@param array $options Generate snippet option
@return string|false
|
[
"Get",
"snippet",
"for",
"text"
] |
6452cc3a5fab83647b6c08574164249fb8f03b05
|
https://github.com/verdet23/SphinxSearchBundle/blob/6452cc3a5fab83647b6c08574164249fb8f03b05/Services/Search/SphinxSearch.php#L242-L251
|
22,776
|
verdet23/SphinxSearchBundle
|
Services/Search/SphinxSearch.php
|
SphinxSearch.getSnippets
|
public function getSnippets($text, $index, $terms, $options = array())
{
return $this->sphinx->BuildExcerpts($text, $index, $terms, $options);
}
|
php
|
public function getSnippets($text, $index, $terms, $options = array())
{
return $this->sphinx->BuildExcerpts($text, $index, $terms, $options);
}
|
[
"public",
"function",
"getSnippets",
"(",
"$",
"text",
",",
"$",
"index",
",",
"$",
"terms",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"sphinx",
"->",
"BuildExcerpts",
"(",
"$",
"text",
",",
"$",
"index",
",",
"$",
"terms",
",",
"$",
"options",
")",
";",
"}"
] |
Get snippets for array of text
@param array $text Array of text to process
@param string $index Search index
@param string $terms Words for highlight
@param array $options Generate snippet option
@return array|false
|
[
"Get",
"snippets",
"for",
"array",
"of",
"text"
] |
6452cc3a5fab83647b6c08574164249fb8f03b05
|
https://github.com/verdet23/SphinxSearchBundle/blob/6452cc3a5fab83647b6c08574164249fb8f03b05/Services/Search/SphinxSearch.php#L263-L266
|
22,777
|
verdet23/SphinxSearchBundle
|
Services/Search/SphinxSearch.php
|
SphinxSearch.resetAll
|
public function resetAll()
{
$this->sphinx->ResetFilters();
$this->sphinx->ResetGroupBy();
$this->sphinx->ResetOverrides();
$this->sphinx->SetSortMode(SPH_SORT_RELEVANCE);
$this->resetLimits();
}
|
php
|
public function resetAll()
{
$this->sphinx->ResetFilters();
$this->sphinx->ResetGroupBy();
$this->sphinx->ResetOverrides();
$this->sphinx->SetSortMode(SPH_SORT_RELEVANCE);
$this->resetLimits();
}
|
[
"public",
"function",
"resetAll",
"(",
")",
"{",
"$",
"this",
"->",
"sphinx",
"->",
"ResetFilters",
"(",
")",
";",
"$",
"this",
"->",
"sphinx",
"->",
"ResetGroupBy",
"(",
")",
";",
"$",
"this",
"->",
"sphinx",
"->",
"ResetOverrides",
"(",
")",
";",
"$",
"this",
"->",
"sphinx",
"->",
"SetSortMode",
"(",
"SPH_SORT_RELEVANCE",
")",
";",
"$",
"this",
"->",
"resetLimits",
"(",
")",
";",
"}"
] |
Reset filters, group by, overrides, limits
|
[
"Reset",
"filters",
"group",
"by",
"overrides",
"limits"
] |
6452cc3a5fab83647b6c08574164249fb8f03b05
|
https://github.com/verdet23/SphinxSearchBundle/blob/6452cc3a5fab83647b6c08574164249fb8f03b05/Services/Search/SphinxSearch.php#L271-L278
|
22,778
|
verdet23/SphinxSearchBundle
|
Services/Search/SphinxSearch.php
|
SphinxSearch.setFilterFloatRange
|
public function setFilterFloatRange($attribute, $min, $max, $exclude = false)
{
$this->sphinx->SetFilterFloatRange($attribute, $min, $max, $exclude);
}
|
php
|
public function setFilterFloatRange($attribute, $min, $max, $exclude = false)
{
$this->sphinx->SetFilterFloatRange($attribute, $min, $max, $exclude);
}
|
[
"public",
"function",
"setFilterFloatRange",
"(",
"$",
"attribute",
",",
"$",
"min",
",",
"$",
"max",
",",
"$",
"exclude",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"sphinx",
"->",
"SetFilterFloatRange",
"(",
"$",
"attribute",
",",
"$",
"min",
",",
"$",
"max",
",",
"$",
"exclude",
")",
";",
"}"
] |
Set float range filter
@param string $attribute Attribute name
@param float $min Min range value
@param float $max Max range value
@param bool $exclude Is this an exclusion filter?
|
[
"Set",
"float",
"range",
"filter"
] |
6452cc3a5fab83647b6c08574164249fb8f03b05
|
https://github.com/verdet23/SphinxSearchBundle/blob/6452cc3a5fab83647b6c08574164249fb8f03b05/Services/Search/SphinxSearch.php#L311-L314
|
22,779
|
verdet23/SphinxSearchBundle
|
Services/Search/SphinxSearch.php
|
SphinxSearch.setFilterRange
|
public function setFilterRange($attribute, $min, $max, $exclude = false)
{
$this->sphinx->SetFilterRange($attribute, $min, $max, $exclude);
}
|
php
|
public function setFilterRange($attribute, $min, $max, $exclude = false)
{
$this->sphinx->SetFilterRange($attribute, $min, $max, $exclude);
}
|
[
"public",
"function",
"setFilterRange",
"(",
"$",
"attribute",
",",
"$",
"min",
",",
"$",
"max",
",",
"$",
"exclude",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"sphinx",
"->",
"SetFilterRange",
"(",
"$",
"attribute",
",",
"$",
"min",
",",
"$",
"max",
",",
"$",
"exclude",
")",
";",
"}"
] |
Set range filter
@param string $attribute Attribute name
@param float $min Min range value
@param float $max Max range value
@param bool $exclude Is this an exclusion filter?
|
[
"Set",
"range",
"filter"
] |
6452cc3a5fab83647b6c08574164249fb8f03b05
|
https://github.com/verdet23/SphinxSearchBundle/blob/6452cc3a5fab83647b6c08574164249fb8f03b05/Services/Search/SphinxSearch.php#L324-L327
|
22,780
|
verdet23/SphinxSearchBundle
|
Services/Indexer/Indexer.php
|
Indexer.rotateAll
|
public function rotateAll()
{
$pb = $this->prepareProcessBuilder();
$pb->add('--all');
$indexer = $pb->getProcess();
$indexer->run();
if (strstr($indexer->getOutput(), 'FATAL:') || strstr($indexer->getOutput(), 'ERROR:')) {
throw new \RuntimeException(sprintf('Error rotating indexes: "%s".', rtrim($indexer->getOutput())));
}
}
|
php
|
public function rotateAll()
{
$pb = $this->prepareProcessBuilder();
$pb->add('--all');
$indexer = $pb->getProcess();
$indexer->run();
if (strstr($indexer->getOutput(), 'FATAL:') || strstr($indexer->getOutput(), 'ERROR:')) {
throw new \RuntimeException(sprintf('Error rotating indexes: "%s".', rtrim($indexer->getOutput())));
}
}
|
[
"public",
"function",
"rotateAll",
"(",
")",
"{",
"$",
"pb",
"=",
"$",
"this",
"->",
"prepareProcessBuilder",
"(",
")",
";",
"$",
"pb",
"->",
"add",
"(",
"'--all'",
")",
";",
"$",
"indexer",
"=",
"$",
"pb",
"->",
"getProcess",
"(",
")",
";",
"$",
"indexer",
"->",
"run",
"(",
")",
";",
"if",
"(",
"strstr",
"(",
"$",
"indexer",
"->",
"getOutput",
"(",
")",
",",
"'FATAL:'",
")",
"||",
"strstr",
"(",
"$",
"indexer",
"->",
"getOutput",
"(",
")",
",",
"'ERROR:'",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Error rotating indexes: \"%s\".'",
",",
"rtrim",
"(",
"$",
"indexer",
"->",
"getOutput",
"(",
")",
")",
")",
")",
";",
"}",
"}"
] |
Rebuild and rotate all indexes.
|
[
"Rebuild",
"and",
"rotate",
"all",
"indexes",
"."
] |
6452cc3a5fab83647b6c08574164249fb8f03b05
|
https://github.com/verdet23/SphinxSearchBundle/blob/6452cc3a5fab83647b6c08574164249fb8f03b05/Services/Indexer/Indexer.php#L51-L63
|
22,781
|
verdet23/SphinxSearchBundle
|
Services/Indexer/Indexer.php
|
Indexer.prepareProcessBuilder
|
protected function prepareProcessBuilder()
{
$pb = new ProcessBuilder();
$pb->inheritEnvironmentVariables();
if ($this->sudo) {
$pb->add('sudo');
}
$pb->add($this->bin);
if ($this->config) {
$pb->add('--config')
->add($this->config);
}
$pb->add('--rotate');
return $pb;
}
|
php
|
protected function prepareProcessBuilder()
{
$pb = new ProcessBuilder();
$pb->inheritEnvironmentVariables();
if ($this->sudo) {
$pb->add('sudo');
}
$pb->add($this->bin);
if ($this->config) {
$pb->add('--config')
->add($this->config);
}
$pb->add('--rotate');
return $pb;
}
|
[
"protected",
"function",
"prepareProcessBuilder",
"(",
")",
"{",
"$",
"pb",
"=",
"new",
"ProcessBuilder",
"(",
")",
";",
"$",
"pb",
"->",
"inheritEnvironmentVariables",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"sudo",
")",
"{",
"$",
"pb",
"->",
"add",
"(",
"'sudo'",
")",
";",
"}",
"$",
"pb",
"->",
"add",
"(",
"$",
"this",
"->",
"bin",
")",
";",
"if",
"(",
"$",
"this",
"->",
"config",
")",
"{",
"$",
"pb",
"->",
"add",
"(",
"'--config'",
")",
"->",
"add",
"(",
"$",
"this",
"->",
"config",
")",
";",
"}",
"$",
"pb",
"->",
"add",
"(",
"'--rotate'",
")",
";",
"return",
"$",
"pb",
";",
"}"
] |
Prepare process builder
@return ProcessBuilder
|
[
"Prepare",
"process",
"builder"
] |
6452cc3a5fab83647b6c08574164249fb8f03b05
|
https://github.com/verdet23/SphinxSearchBundle/blob/6452cc3a5fab83647b6c08574164249fb8f03b05/Services/Indexer/Indexer.php#L129-L146
|
22,782
|
kenphp/ken
|
src/Helpers/Url.php
|
Url.createAbsolute
|
public static function createAbsolute($url, array $params = array())
{
$url = self::addParams($url, $params);
$url = ltrim($url, '/');
$baseUrl = app()->request->getBaseUrl();
return $baseUrl.'/'.$url;
}
|
php
|
public static function createAbsolute($url, array $params = array())
{
$url = self::addParams($url, $params);
$url = ltrim($url, '/');
$baseUrl = app()->request->getBaseUrl();
return $baseUrl.'/'.$url;
}
|
[
"public",
"static",
"function",
"createAbsolute",
"(",
"$",
"url",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"addParams",
"(",
"$",
"url",
",",
"$",
"params",
")",
";",
"$",
"url",
"=",
"ltrim",
"(",
"$",
"url",
",",
"'/'",
")",
";",
"$",
"baseUrl",
"=",
"app",
"(",
")",
"->",
"request",
"->",
"getBaseUrl",
"(",
")",
";",
"return",
"$",
"baseUrl",
".",
"'/'",
".",
"$",
"url",
";",
"}"
] |
Creates absolute url.
@param string $url
@param array $params Assosiative array in format [key => value ] for GET parameters
@return string
|
[
"Creates",
"absolute",
"url",
"."
] |
c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb
|
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Helpers/Url.php#L33-L40
|
22,783
|
kenphp/ken
|
src/Helpers/Url.php
|
Url.addParams
|
private static function addParams($url, array $params = array())
{
$cParams = count($params);
if ($cParams > 0) {
$url .= '?';
$idx = 1;
foreach ($params as $key => $value) {
$url .= $key.'='.$value;
if ($idx < $cParams) {
$url .= '&';
}
++$idx;
}
}
return $url;
}
|
php
|
private static function addParams($url, array $params = array())
{
$cParams = count($params);
if ($cParams > 0) {
$url .= '?';
$idx = 1;
foreach ($params as $key => $value) {
$url .= $key.'='.$value;
if ($idx < $cParams) {
$url .= '&';
}
++$idx;
}
}
return $url;
}
|
[
"private",
"static",
"function",
"addParams",
"(",
"$",
"url",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"cParams",
"=",
"count",
"(",
"$",
"params",
")",
";",
"if",
"(",
"$",
"cParams",
">",
"0",
")",
"{",
"$",
"url",
".=",
"'?'",
";",
"$",
"idx",
"=",
"1",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"url",
".=",
"$",
"key",
".",
"'='",
".",
"$",
"value",
";",
"if",
"(",
"$",
"idx",
"<",
"$",
"cParams",
")",
"{",
"$",
"url",
".=",
"'&'",
";",
"}",
"++",
"$",
"idx",
";",
"}",
"}",
"return",
"$",
"url",
";",
"}"
] |
Appends GET parameters to url.
@param string $url
@param array $params Assosiative array in format [key => value ] for GET parameters
@return string
|
[
"Appends",
"GET",
"parameters",
"to",
"url",
"."
] |
c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb
|
https://github.com/kenphp/ken/blob/c454a86f0ab55c52c88e9bff5bc6fb4e7bd9e0eb/src/Helpers/Url.php#L50-L67
|
22,784
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/persistent/class_writer.php
|
ezcDbSchemaPersistentClassWriter.writeAttributes
|
private function writeAttributes( $file, $fields )
{
foreach ( $fields as $fieldName => $field )
{
fwrite( $file, " /**\n" );
fwrite( $file, " * $fieldName\n" );
fwrite( $file, " *\n" );
fwrite( $file, " * @var {$this->translateType($field->type)}\n" );
fwrite( $file, " */\n" );
fwrite( $file, " private \$$fieldName;\n" );
}
}
|
php
|
private function writeAttributes( $file, $fields )
{
foreach ( $fields as $fieldName => $field )
{
fwrite( $file, " /**\n" );
fwrite( $file, " * $fieldName\n" );
fwrite( $file, " *\n" );
fwrite( $file, " * @var {$this->translateType($field->type)}\n" );
fwrite( $file, " */\n" );
fwrite( $file, " private \$$fieldName;\n" );
}
}
|
[
"private",
"function",
"writeAttributes",
"(",
"$",
"file",
",",
"$",
"fields",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fieldName",
"=>",
"$",
"field",
")",
"{",
"fwrite",
"(",
"$",
"file",
",",
"\" /**\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\" * $fieldName\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\" *\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\" * @var {$this->translateType($field->type)}\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\" */\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\" private \\$$fieldName;\\n\"",
")",
";",
"}",
"}"
] |
Writes the list of attributes.
@param resource $file
@param array $fields
@return void
|
[
"Writes",
"the",
"list",
"of",
"attributes",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/persistent/class_writer.php#L99-L110
|
22,785
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/persistent/class_writer.php
|
ezcDbSchemaPersistentClassWriter.writeClass
|
private function writeClass( $dir, $tableName, ezcDbSchemaTable $table )
{
$file = $this->openFile( $dir, $tableName );
fwrite( $file, "/**\n" );
fwrite( $file, " * Data class $tableName.\n" );
fwrite( $file, " * Class to be used with eZ Components PersistentObject.\n" );
fwrite( $file, " */\n" );
fwrite( $file, "class {$this->prefix}$tableName\n" );
fwrite( $file, "{\n" );
// attributes
$this->writeAttributes( $file, $table->fields );
fwrite( $file, "\n" );
// methods
$this->writeSetState( $file );
fwrite( $file, "\n" );
$this->writeGetState( $file, $table->fields );
fwrite( $file, "}\n" );
$this->closeFile( $file );
}
|
php
|
private function writeClass( $dir, $tableName, ezcDbSchemaTable $table )
{
$file = $this->openFile( $dir, $tableName );
fwrite( $file, "/**\n" );
fwrite( $file, " * Data class $tableName.\n" );
fwrite( $file, " * Class to be used with eZ Components PersistentObject.\n" );
fwrite( $file, " */\n" );
fwrite( $file, "class {$this->prefix}$tableName\n" );
fwrite( $file, "{\n" );
// attributes
$this->writeAttributes( $file, $table->fields );
fwrite( $file, "\n" );
// methods
$this->writeSetState( $file );
fwrite( $file, "\n" );
$this->writeGetState( $file, $table->fields );
fwrite( $file, "}\n" );
$this->closeFile( $file );
}
|
[
"private",
"function",
"writeClass",
"(",
"$",
"dir",
",",
"$",
"tableName",
",",
"ezcDbSchemaTable",
"$",
"table",
")",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"openFile",
"(",
"$",
"dir",
",",
"$",
"tableName",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\"/**\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\" * Data class $tableName.\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\" * Class to be used with eZ Components PersistentObject.\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\" */\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\"class {$this->prefix}$tableName\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\"{\\n\"",
")",
";",
"// attributes ",
"$",
"this",
"->",
"writeAttributes",
"(",
"$",
"file",
",",
"$",
"table",
"->",
"fields",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\"\\n\"",
")",
";",
"// methods",
"$",
"this",
"->",
"writeSetState",
"(",
"$",
"file",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\"\\n\"",
")",
";",
"$",
"this",
"->",
"writeGetState",
"(",
"$",
"file",
",",
"$",
"table",
"->",
"fields",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\"}\\n\"",
")",
";",
"$",
"this",
"->",
"closeFile",
"(",
"$",
"file",
")",
";",
"}"
] |
Writes a PHP class.
This method writes a PHP class from a table definition.
@param string $dir The directory to write the defititions to.
@param string $tableName Name of the database table.
@param ezcDbSchemaTable $table The table definition.
|
[
"Writes",
"a",
"PHP",
"class",
".",
"This",
"method",
"writes",
"a",
"PHP",
"class",
"from",
"a",
"table",
"definition",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/persistent/class_writer.php#L168-L190
|
22,786
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/persistent/class_writer.php
|
ezcDbSchemaPersistentClassWriter.openFile
|
private function openFile( $dir, $name )
{
$filename = $dir . DIRECTORY_SEPARATOR . strtolower( $this->prefix ) . strtolower( $name ) . '.php';
// We do not want to overwrite files
if ( file_exists( $filename ) && ( $this->overwrite === false || is_writable( $filename ) === false ) )
{
throw new ezcBaseFileIoException( $filename, ezcBaseFileException::WRITE, "File already exists or is not writeable. Use --overwrite to ignore existance." );
}
$file = @fopen( $filename, 'w' );
if ( $file === false )
{
throw new ezcBaseFilePermissionException( $file, ezcBaseFileException::WRITE );
}
fwrite( $file, "<?php\n" );
fwrite( $file, "// Autogenerated class file\n" );
fwrite( $file, "\n" );
return $file;
}
|
php
|
private function openFile( $dir, $name )
{
$filename = $dir . DIRECTORY_SEPARATOR . strtolower( $this->prefix ) . strtolower( $name ) . '.php';
// We do not want to overwrite files
if ( file_exists( $filename ) && ( $this->overwrite === false || is_writable( $filename ) === false ) )
{
throw new ezcBaseFileIoException( $filename, ezcBaseFileException::WRITE, "File already exists or is not writeable. Use --overwrite to ignore existance." );
}
$file = @fopen( $filename, 'w' );
if ( $file === false )
{
throw new ezcBaseFilePermissionException( $file, ezcBaseFileException::WRITE );
}
fwrite( $file, "<?php\n" );
fwrite( $file, "// Autogenerated class file\n" );
fwrite( $file, "\n" );
return $file;
}
|
[
"private",
"function",
"openFile",
"(",
"$",
"dir",
",",
"$",
"name",
")",
"{",
"$",
"filename",
"=",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"strtolower",
"(",
"$",
"this",
"->",
"prefix",
")",
".",
"strtolower",
"(",
"$",
"name",
")",
".",
"'.php'",
";",
"// We do not want to overwrite files",
"if",
"(",
"file_exists",
"(",
"$",
"filename",
")",
"&&",
"(",
"$",
"this",
"->",
"overwrite",
"===",
"false",
"||",
"is_writable",
"(",
"$",
"filename",
")",
"===",
"false",
")",
")",
"{",
"throw",
"new",
"ezcBaseFileIoException",
"(",
"$",
"filename",
",",
"ezcBaseFileException",
"::",
"WRITE",
",",
"\"File already exists or is not writeable. Use --overwrite to ignore existance.\"",
")",
";",
"}",
"$",
"file",
"=",
"@",
"fopen",
"(",
"$",
"filename",
",",
"'w'",
")",
";",
"if",
"(",
"$",
"file",
"===",
"false",
")",
"{",
"throw",
"new",
"ezcBaseFilePermissionException",
"(",
"$",
"file",
",",
"ezcBaseFileException",
"::",
"WRITE",
")",
";",
"}",
"fwrite",
"(",
"$",
"file",
",",
"\"<?php\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\"// Autogenerated class file\\n\"",
")",
";",
"fwrite",
"(",
"$",
"file",
",",
"\"\\n\"",
")",
";",
"return",
"$",
"file",
";",
"}"
] |
Open a file for writing a PersistentObject definition to.
This method opens a file for writing a PersistentObject definition to
and writes the basic PHP open tag to it.
@param string $dir The diretory to open the file in.
@param string $name The table name.
@return resource(file) The file resource used for writing.
@throws ezcBaseFileIoException
if the file to write to already exists.
@throws ezcBaseFilePermissionException
if the file could not be opened for writing.
|
[
"Open",
"a",
"file",
"for",
"writing",
"a",
"PersistentObject",
"definition",
"to",
".",
"This",
"method",
"opens",
"a",
"file",
"for",
"writing",
"a",
"PersistentObject",
"definition",
"to",
"and",
"writes",
"the",
"basic",
"PHP",
"open",
"tag",
"to",
"it",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/DatabaseSchema/src/handlers/persistent/class_writer.php#L206-L223
|
22,787
|
Laralum/Permissions
|
src/PermissionsChecker.php
|
PermissionsChecker.check
|
public static function check($permissions)
{
if (Schema::hasTable('laralum_permissions')) {
foreach ($permissions as $permission) {
if (!self::allCached()->contains('slug', $permission['slug'])) {
Cache::forget('laralum_permissions');
if (!self::allCached()->contains('slug', $permission['slug'])) {
Permission::create([
'name' => $permission['name'],
'slug' => $permission['slug'],
'description' => $permission['desc'],
]);
}
}
}
}
session(['laralum_permissions::mandatory' => array_merge(static::mandatory(), $permissions)]);
}
|
php
|
public static function check($permissions)
{
if (Schema::hasTable('laralum_permissions')) {
foreach ($permissions as $permission) {
if (!self::allCached()->contains('slug', $permission['slug'])) {
Cache::forget('laralum_permissions');
if (!self::allCached()->contains('slug', $permission['slug'])) {
Permission::create([
'name' => $permission['name'],
'slug' => $permission['slug'],
'description' => $permission['desc'],
]);
}
}
}
}
session(['laralum_permissions::mandatory' => array_merge(static::mandatory(), $permissions)]);
}
|
[
"public",
"static",
"function",
"check",
"(",
"$",
"permissions",
")",
"{",
"if",
"(",
"Schema",
"::",
"hasTable",
"(",
"'laralum_permissions'",
")",
")",
"{",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"allCached",
"(",
")",
"->",
"contains",
"(",
"'slug'",
",",
"$",
"permission",
"[",
"'slug'",
"]",
")",
")",
"{",
"Cache",
"::",
"forget",
"(",
"'laralum_permissions'",
")",
";",
"if",
"(",
"!",
"self",
"::",
"allCached",
"(",
")",
"->",
"contains",
"(",
"'slug'",
",",
"$",
"permission",
"[",
"'slug'",
"]",
")",
")",
"{",
"Permission",
"::",
"create",
"(",
"[",
"'name'",
"=>",
"$",
"permission",
"[",
"'name'",
"]",
",",
"'slug'",
"=>",
"$",
"permission",
"[",
"'slug'",
"]",
",",
"'description'",
"=>",
"$",
"permission",
"[",
"'desc'",
"]",
",",
"]",
")",
";",
"}",
"}",
"}",
"}",
"session",
"(",
"[",
"'laralum_permissions::mandatory'",
"=>",
"array_merge",
"(",
"static",
"::",
"mandatory",
"(",
")",
",",
"$",
"permissions",
")",
"]",
")",
";",
"}"
] |
Checks if the permisions exists and if they dont, they will be added.
@param array $permissions
|
[
"Checks",
"if",
"the",
"permisions",
"exists",
"and",
"if",
"they",
"dont",
"they",
"will",
"be",
"added",
"."
] |
79970ee7d1bff816ad4b9adee29067faead3f756
|
https://github.com/Laralum/Permissions/blob/79970ee7d1bff816ad4b9adee29067faead3f756/src/PermissionsChecker.php#L41-L58
|
22,788
|
ellipsephp/session-start
|
src/StartSessionMiddleware.php
|
StartSessionMiddleware.process
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
// Fail when session is disabled or has already started.
$this->failWhenDisabled();
$this->failWhenStarted();
// Try to retrieve the session id from the request cookies.
$cookies = $request->getCookieParams();
$session_id = $cookies[$this->name] ?? '';
if ($session_id != '') session_id($session_id);
// Handle the request when session_start is successful.
if (session_start(self::SESSION_OPTIONS)) {
session_name($this->name);
$response = $handler->handle($request);
$this->failWhenClosed();
$session_id = session_id();
session_write_close();
return $this->withSessionCookie($response, $session_id);
}
throw new SessionStartException;
}
|
php
|
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
// Fail when session is disabled or has already started.
$this->failWhenDisabled();
$this->failWhenStarted();
// Try to retrieve the session id from the request cookies.
$cookies = $request->getCookieParams();
$session_id = $cookies[$this->name] ?? '';
if ($session_id != '') session_id($session_id);
// Handle the request when session_start is successful.
if (session_start(self::SESSION_OPTIONS)) {
session_name($this->name);
$response = $handler->handle($request);
$this->failWhenClosed();
$session_id = session_id();
session_write_close();
return $this->withSessionCookie($response, $session_id);
}
throw new SessionStartException;
}
|
[
"public",
"function",
"process",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"RequestHandlerInterface",
"$",
"handler",
")",
":",
"ResponseInterface",
"{",
"// Fail when session is disabled or has already started.",
"$",
"this",
"->",
"failWhenDisabled",
"(",
")",
";",
"$",
"this",
"->",
"failWhenStarted",
"(",
")",
";",
"// Try to retrieve the session id from the request cookies.",
"$",
"cookies",
"=",
"$",
"request",
"->",
"getCookieParams",
"(",
")",
";",
"$",
"session_id",
"=",
"$",
"cookies",
"[",
"$",
"this",
"->",
"name",
"]",
"??",
"''",
";",
"if",
"(",
"$",
"session_id",
"!=",
"''",
")",
"session_id",
"(",
"$",
"session_id",
")",
";",
"// Handle the request when session_start is successful.",
"if",
"(",
"session_start",
"(",
"self",
"::",
"SESSION_OPTIONS",
")",
")",
"{",
"session_name",
"(",
"$",
"this",
"->",
"name",
")",
";",
"$",
"response",
"=",
"$",
"handler",
"->",
"handle",
"(",
"$",
"request",
")",
";",
"$",
"this",
"->",
"failWhenClosed",
"(",
")",
";",
"$",
"session_id",
"=",
"session_id",
"(",
")",
";",
"session_write_close",
"(",
")",
";",
"return",
"$",
"this",
"->",
"withSessionCookie",
"(",
"$",
"response",
",",
"$",
"session_id",
")",
";",
"}",
"throw",
"new",
"SessionStartException",
";",
"}"
] |
Start the session, handle the request and add the session cookie to the
response.
@param \Psr\Http\Message\ServerRequestInterface $request
@param \Psr\Http\Server\RequestHandlerInterface $handler
@return \Psr\Http\Message\ResponseInterface
@throws \Ellipse\Session\Exceptions\SessionStartException
|
[
"Start",
"the",
"session",
"handle",
"the",
"request",
"and",
"add",
"the",
"session",
"cookie",
"to",
"the",
"response",
"."
] |
7272abfdc42bd8ffc1692c2a37114f6a187d4a24
|
https://github.com/ellipsephp/session-start/blob/7272abfdc42bd8ffc1692c2a37114f6a187d4a24/src/StartSessionMiddleware.php#L66-L97
|
22,789
|
ellipsephp/session-start
|
src/StartSessionMiddleware.php
|
StartSessionMiddleware.withSessionCookie
|
private function withSessionCookie(ResponseInterface $response, string $session_id): ResponseInterface
{
// Merge session cookie options.
$default = session_get_cookie_params();
$default = array_change_key_case($default, CASE_LOWER);
$options = array_change_key_case($this->options, CASE_LOWER);
$options = array_merge($default, $options);
if ($options['lifetime'] < 0) $options['lifetime'] = 0;
// Create a session cookie and attach it to the response.
$cookie = SetCookie::create($this->name, $session_id)
->withMaxAge($options['lifetime'])
->withPath($options['path'])
->withDomain($options['domain'])
->withSecure($options['secure'])
->withHttpOnly($options['httponly']);
if ($options['lifetime'] > 0) {
$cookie = $cookie->withExpires(time() + $options['lifetime']);
}
return FigResponseCookies::set($response, $cookie);
}
|
php
|
private function withSessionCookie(ResponseInterface $response, string $session_id): ResponseInterface
{
// Merge session cookie options.
$default = session_get_cookie_params();
$default = array_change_key_case($default, CASE_LOWER);
$options = array_change_key_case($this->options, CASE_LOWER);
$options = array_merge($default, $options);
if ($options['lifetime'] < 0) $options['lifetime'] = 0;
// Create a session cookie and attach it to the response.
$cookie = SetCookie::create($this->name, $session_id)
->withMaxAge($options['lifetime'])
->withPath($options['path'])
->withDomain($options['domain'])
->withSecure($options['secure'])
->withHttpOnly($options['httponly']);
if ($options['lifetime'] > 0) {
$cookie = $cookie->withExpires(time() + $options['lifetime']);
}
return FigResponseCookies::set($response, $cookie);
}
|
[
"private",
"function",
"withSessionCookie",
"(",
"ResponseInterface",
"$",
"response",
",",
"string",
"$",
"session_id",
")",
":",
"ResponseInterface",
"{",
"// Merge session cookie options.",
"$",
"default",
"=",
"session_get_cookie_params",
"(",
")",
";",
"$",
"default",
"=",
"array_change_key_case",
"(",
"$",
"default",
",",
"CASE_LOWER",
")",
";",
"$",
"options",
"=",
"array_change_key_case",
"(",
"$",
"this",
"->",
"options",
",",
"CASE_LOWER",
")",
";",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"default",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'lifetime'",
"]",
"<",
"0",
")",
"$",
"options",
"[",
"'lifetime'",
"]",
"=",
"0",
";",
"// Create a session cookie and attach it to the response.",
"$",
"cookie",
"=",
"SetCookie",
"::",
"create",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"session_id",
")",
"->",
"withMaxAge",
"(",
"$",
"options",
"[",
"'lifetime'",
"]",
")",
"->",
"withPath",
"(",
"$",
"options",
"[",
"'path'",
"]",
")",
"->",
"withDomain",
"(",
"$",
"options",
"[",
"'domain'",
"]",
")",
"->",
"withSecure",
"(",
"$",
"options",
"[",
"'secure'",
"]",
")",
"->",
"withHttpOnly",
"(",
"$",
"options",
"[",
"'httponly'",
"]",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'lifetime'",
"]",
">",
"0",
")",
"{",
"$",
"cookie",
"=",
"$",
"cookie",
"->",
"withExpires",
"(",
"time",
"(",
")",
"+",
"$",
"options",
"[",
"'lifetime'",
"]",
")",
";",
"}",
"return",
"FigResponseCookies",
"::",
"set",
"(",
"$",
"response",
",",
"$",
"cookie",
")",
";",
"}"
] |
Attach a session cookie with the given sesison id to the given response.
@param \Psr\Http\Message\ResponseInterface $response
@param string $session_id
@return \Psr\Http\Message\ResponseInterface
|
[
"Attach",
"a",
"session",
"cookie",
"with",
"the",
"given",
"sesison",
"id",
"to",
"the",
"given",
"response",
"."
] |
7272abfdc42bd8ffc1692c2a37114f6a187d4a24
|
https://github.com/ellipsephp/session-start/blob/7272abfdc42bd8ffc1692c2a37114f6a187d4a24/src/StartSessionMiddleware.php#L151-L178
|
22,790
|
netvlies/NetvliesFormBundle
|
Controller/FormAdminController.php
|
FormAdminController.createResponse
|
protected function createResponse(PHPExcel $excel, $fileName)
{
$writer = new PHPExcel_Writer_Excel2007($excel);
ob_start();
$writer->save('php://output');
$content = ob_get_clean();
$response = new Response();
$response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$response->headers->set('Content-Disposition', 'attachment;filename="'.$fileName.'"');
$response->headers->set('Cache-Control', 'max-age=0');
$response->setContent($content);
return $response;
}
|
php
|
protected function createResponse(PHPExcel $excel, $fileName)
{
$writer = new PHPExcel_Writer_Excel2007($excel);
ob_start();
$writer->save('php://output');
$content = ob_get_clean();
$response = new Response();
$response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
$response->headers->set('Content-Disposition', 'attachment;filename="'.$fileName.'"');
$response->headers->set('Cache-Control', 'max-age=0');
$response->setContent($content);
return $response;
}
|
[
"protected",
"function",
"createResponse",
"(",
"PHPExcel",
"$",
"excel",
",",
"$",
"fileName",
")",
"{",
"$",
"writer",
"=",
"new",
"PHPExcel_Writer_Excel2007",
"(",
"$",
"excel",
")",
";",
"ob_start",
"(",
")",
";",
"$",
"writer",
"->",
"save",
"(",
"'php://output'",
")",
";",
"$",
"content",
"=",
"ob_get_clean",
"(",
")",
";",
"$",
"response",
"=",
"new",
"Response",
"(",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Type'",
",",
"'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Disposition'",
",",
"'attachment;filename=\"'",
".",
"$",
"fileName",
".",
"'\"'",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Cache-Control'",
",",
"'max-age=0'",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"$",
"content",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Generates a response object for a PHPExcel object.
@param PHPExcel $excel
@param $fileName
@return Response
|
[
"Generates",
"a",
"response",
"object",
"for",
"a",
"PHPExcel",
"object",
"."
] |
93f9a3321d9925040111374e7c1014a6400a2d08
|
https://github.com/netvlies/NetvliesFormBundle/blob/93f9a3321d9925040111374e7c1014a6400a2d08/Controller/FormAdminController.php#L73-L86
|
22,791
|
ajant/SimpleArrayLibrary
|
src/Categories/Inspectors.php
|
Inspectors.haveSameKeys
|
public static function haveSameKeys(array $array1, array $array2)
{
return self::hasAllKeys($array1, array_keys($array2)) && self::hasAllKeys($array2, array_keys($array1)) ? true : false;
}
|
php
|
public static function haveSameKeys(array $array1, array $array2)
{
return self::hasAllKeys($array1, array_keys($array2)) && self::hasAllKeys($array2, array_keys($array1)) ? true : false;
}
|
[
"public",
"static",
"function",
"haveSameKeys",
"(",
"array",
"$",
"array1",
",",
"array",
"$",
"array2",
")",
"{",
"return",
"self",
"::",
"hasAllKeys",
"(",
"$",
"array1",
",",
"array_keys",
"(",
"$",
"array2",
")",
")",
"&&",
"self",
"::",
"hasAllKeys",
"(",
"$",
"array2",
",",
"array_keys",
"(",
"$",
"array1",
")",
")",
"?",
"true",
":",
"false",
";",
"}"
] |
Checks if two arrays have all equal keys
@param array $array1
@param array $array2
@return boolean
|
[
"Checks",
"if",
"two",
"arrays",
"have",
"all",
"equal",
"keys"
] |
374877c0f20a22a914eb3680eb1cf39e424071be
|
https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Inspectors.php#L75-L78
|
22,792
|
ajant/SimpleArrayLibrary
|
src/Categories/Inspectors.php
|
Inspectors.haveSameValues
|
public static function haveSameValues($array1, $array2)
{
return self::hasAllValues($array1, $array2) && self::hasAllValues($array2, $array1) ? true : false;
}
|
php
|
public static function haveSameValues($array1, $array2)
{
return self::hasAllValues($array1, $array2) && self::hasAllValues($array2, $array1) ? true : false;
}
|
[
"public",
"static",
"function",
"haveSameValues",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
"{",
"return",
"self",
"::",
"hasAllValues",
"(",
"$",
"array1",
",",
"$",
"array2",
")",
"&&",
"self",
"::",
"hasAllValues",
"(",
"$",
"array2",
",",
"$",
"array1",
")",
"?",
"true",
":",
"false",
";",
"}"
] |
Check if two arrays have all equal values
@param array $array1
@param array $array2
@return bool
|
[
"Check",
"if",
"two",
"arrays",
"have",
"all",
"equal",
"values"
] |
374877c0f20a22a914eb3680eb1cf39e424071be
|
https://github.com/ajant/SimpleArrayLibrary/blob/374877c0f20a22a914eb3680eb1cf39e424071be/src/Categories/Inspectors.php#L88-L91
|
22,793
|
inhere/php-librarys
|
src/Utils/Token.php
|
Token.gen
|
public static function gen($password)
{
return crypt($password, self::$algo . self::$cost . '$' . self::uniqueSalt());
}
|
php
|
public static function gen($password)
{
return crypt($password, self::$algo . self::$cost . '$' . self::uniqueSalt());
}
|
[
"public",
"static",
"function",
"gen",
"(",
"$",
"password",
")",
"{",
"return",
"crypt",
"(",
"$",
"password",
",",
"self",
"::",
"$",
"algo",
".",
"self",
"::",
"$",
"cost",
".",
"'$'",
".",
"self",
"::",
"uniqueSalt",
"(",
")",
")",
";",
"}"
] |
this will be used to generate a hash
@param $password
@return string
|
[
"this",
"will",
"be",
"used",
"to",
"generate",
"a",
"hash"
] |
e6ca598685469794f310e3ab0e2bc19519cd0ae6
|
https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Utils/Token.php#L56-L59
|
22,794
|
ekuiter/feature-php
|
FeaturePhp/Collaboration/Composer.php
|
Composer.getComposerMap
|
public static function getComposerMap() {
$composerMap = array();
foreach (self::getComposers() as $composer)
$composerMap[call_user_func(array($composer, "getKind"))] = $composer;
return $composerMap;
}
|
php
|
public static function getComposerMap() {
$composerMap = array();
foreach (self::getComposers() as $composer)
$composerMap[call_user_func(array($composer, "getKind"))] = $composer;
return $composerMap;
}
|
[
"public",
"static",
"function",
"getComposerMap",
"(",
")",
"{",
"$",
"composerMap",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"getComposers",
"(",
")",
"as",
"$",
"composer",
")",
"$",
"composerMap",
"[",
"call_user_func",
"(",
"array",
"(",
"$",
"composer",
",",
"\"getKind\"",
")",
")",
"]",
"=",
"$",
"composer",
";",
"return",
"$",
"composerMap",
";",
"}"
] |
Returns a map from all composer kinds to class names.
@return string[]
|
[
"Returns",
"a",
"map",
"from",
"all",
"composer",
"kinds",
"to",
"class",
"names",
"."
] |
daf4a59098802fedcfd1f1a1d07847fcf2fea7bf
|
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Collaboration/Composer.php#L37-L42
|
22,795
|
ekuiter/feature-php
|
FeaturePhp/Collaboration/Composer.php
|
Composer.fromKind
|
public static function fromKind($kind) {
$composerMap = self::getComposerMap();
if (!array_key_exists($kind, $composerMap))
throw new ComposerException("no composer found for \"$kind\"");
$class = $composerMap[$kind];
return new $class();
}
|
php
|
public static function fromKind($kind) {
$composerMap = self::getComposerMap();
if (!array_key_exists($kind, $composerMap))
throw new ComposerException("no composer found for \"$kind\"");
$class = $composerMap[$kind];
return new $class();
}
|
[
"public",
"static",
"function",
"fromKind",
"(",
"$",
"kind",
")",
"{",
"$",
"composerMap",
"=",
"self",
"::",
"getComposerMap",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"kind",
",",
"$",
"composerMap",
")",
")",
"throw",
"new",
"ComposerException",
"(",
"\"no composer found for \\\"$kind\\\"\"",
")",
";",
"$",
"class",
"=",
"$",
"composerMap",
"[",
"$",
"kind",
"]",
";",
"return",
"new",
"$",
"class",
"(",
")",
";",
"}"
] |
Creates a composer from a kind.
@param string $kind
@return Composer
|
[
"Creates",
"a",
"composer",
"from",
"a",
"kind",
"."
] |
daf4a59098802fedcfd1f1a1d07847fcf2fea7bf
|
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Collaboration/Composer.php#L49-L55
|
22,796
|
jnaxo/country-codes
|
src/CountryStore.php
|
CountryStore.routes
|
public function routes()
{
Route::get('countries/{id}', function ($id) {
$request = request();
return CountryStore::country($id, $request);
})->name('country');
Route::get('countries', function () {
$request = request();
return CountryStore::countries($request);
})->name('countries');
Route::get('administrative_areas/{id}', function ($id) {
$request = request();
return CountryStore::administrativeArea($id, $request);
})->name('administrative_area');
Route::get('cities/{city_id}', function ($city_id) {
$request = request();
return CountryStore::city($city_id, $request);
})->name('city');
}
|
php
|
public function routes()
{
Route::get('countries/{id}', function ($id) {
$request = request();
return CountryStore::country($id, $request);
})->name('country');
Route::get('countries', function () {
$request = request();
return CountryStore::countries($request);
})->name('countries');
Route::get('administrative_areas/{id}', function ($id) {
$request = request();
return CountryStore::administrativeArea($id, $request);
})->name('administrative_area');
Route::get('cities/{city_id}', function ($city_id) {
$request = request();
return CountryStore::city($city_id, $request);
})->name('city');
}
|
[
"public",
"function",
"routes",
"(",
")",
"{",
"Route",
"::",
"get",
"(",
"'countries/{id}'",
",",
"function",
"(",
"$",
"id",
")",
"{",
"$",
"request",
"=",
"request",
"(",
")",
";",
"return",
"CountryStore",
"::",
"country",
"(",
"$",
"id",
",",
"$",
"request",
")",
";",
"}",
")",
"->",
"name",
"(",
"'country'",
")",
";",
"Route",
"::",
"get",
"(",
"'countries'",
",",
"function",
"(",
")",
"{",
"$",
"request",
"=",
"request",
"(",
")",
";",
"return",
"CountryStore",
"::",
"countries",
"(",
"$",
"request",
")",
";",
"}",
")",
"->",
"name",
"(",
"'countries'",
")",
";",
"Route",
"::",
"get",
"(",
"'administrative_areas/{id}'",
",",
"function",
"(",
"$",
"id",
")",
"{",
"$",
"request",
"=",
"request",
"(",
")",
";",
"return",
"CountryStore",
"::",
"administrativeArea",
"(",
"$",
"id",
",",
"$",
"request",
")",
";",
"}",
")",
"->",
"name",
"(",
"'administrative_area'",
")",
";",
"Route",
"::",
"get",
"(",
"'cities/{city_id}'",
",",
"function",
"(",
"$",
"city_id",
")",
"{",
"$",
"request",
"=",
"request",
"(",
")",
";",
"return",
"CountryStore",
"::",
"city",
"(",
"$",
"city_id",
",",
"$",
"request",
")",
";",
"}",
")",
"->",
"name",
"(",
"'city'",
")",
";",
"}"
] |
Set routes for country API
@return void
|
[
"Set",
"routes",
"for",
"country",
"API"
] |
ab1f24886e1b49eef5fd4b4eb4fb37aa7faeacd9
|
https://github.com/jnaxo/country-codes/blob/ab1f24886e1b49eef5fd4b4eb4fb37aa7faeacd9/src/CountryStore.php#L21-L42
|
22,797
|
jnaxo/country-codes
|
src/CountryStore.php
|
CountryStore.country
|
public function country($country_id, Request $request = null)
{
$country = Country::with('zone')->find($country_id);
if ($request) {
$included = [];
$query = $country->getInlcudeResources($request->include);
if ($query) {
$collection = new Collection(
$query,
str_singular($request->include)
);
$included = $collection->toArray();
}
$links = $request ? ['self' => $request->url()] : [];
return $this->respondWithItem(
$country,
'country',
$links,
$included
);
}
return $country;
}
|
php
|
public function country($country_id, Request $request = null)
{
$country = Country::with('zone')->find($country_id);
if ($request) {
$included = [];
$query = $country->getInlcudeResources($request->include);
if ($query) {
$collection = new Collection(
$query,
str_singular($request->include)
);
$included = $collection->toArray();
}
$links = $request ? ['self' => $request->url()] : [];
return $this->respondWithItem(
$country,
'country',
$links,
$included
);
}
return $country;
}
|
[
"public",
"function",
"country",
"(",
"$",
"country_id",
",",
"Request",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"country",
"=",
"Country",
"::",
"with",
"(",
"'zone'",
")",
"->",
"find",
"(",
"$",
"country_id",
")",
";",
"if",
"(",
"$",
"request",
")",
"{",
"$",
"included",
"=",
"[",
"]",
";",
"$",
"query",
"=",
"$",
"country",
"->",
"getInlcudeResources",
"(",
"$",
"request",
"->",
"include",
")",
";",
"if",
"(",
"$",
"query",
")",
"{",
"$",
"collection",
"=",
"new",
"Collection",
"(",
"$",
"query",
",",
"str_singular",
"(",
"$",
"request",
"->",
"include",
")",
")",
";",
"$",
"included",
"=",
"$",
"collection",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"links",
"=",
"$",
"request",
"?",
"[",
"'self'",
"=>",
"$",
"request",
"->",
"url",
"(",
")",
"]",
":",
"[",
"]",
";",
"return",
"$",
"this",
"->",
"respondWithItem",
"(",
"$",
"country",
",",
"'country'",
",",
"$",
"links",
",",
"$",
"included",
")",
";",
"}",
"return",
"$",
"country",
";",
"}"
] |
Get Country item. Optional include administrative areas
@param int $country_id
@param Illuminate\Http\Request $request
@return mixed Jnaxo\CountryCodes\Country item
|
[
"Get",
"Country",
"item",
".",
"Optional",
"include",
"administrative",
"areas"
] |
ab1f24886e1b49eef5fd4b4eb4fb37aa7faeacd9
|
https://github.com/jnaxo/country-codes/blob/ab1f24886e1b49eef5fd4b4eb4fb37aa7faeacd9/src/CountryStore.php#L51-L74
|
22,798
|
jnaxo/country-codes
|
src/CountryStore.php
|
CountryStore.countries
|
public function countries(Request $request = null)
{
$query = Country::with('zone');
if ($request) {
$resource = new Collection($query, 'country', $request);
return $this->respondWithCollection($resource);
}
return $query->get();
}
|
php
|
public function countries(Request $request = null)
{
$query = Country::with('zone');
if ($request) {
$resource = new Collection($query, 'country', $request);
return $this->respondWithCollection($resource);
}
return $query->get();
}
|
[
"public",
"function",
"countries",
"(",
"Request",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"query",
"=",
"Country",
"::",
"with",
"(",
"'zone'",
")",
";",
"if",
"(",
"$",
"request",
")",
"{",
"$",
"resource",
"=",
"new",
"Collection",
"(",
"$",
"query",
",",
"'country'",
",",
"$",
"request",
")",
";",
"return",
"$",
"this",
"->",
"respondWithCollection",
"(",
"$",
"resource",
")",
";",
"}",
"return",
"$",
"query",
"->",
"get",
"(",
")",
";",
"}"
] |
Get Country list
@param Illuminate\Http\Request $request
@return mixed Jnaxo\CountryCodes\Country collection
|
[
"Get",
"Country",
"list"
] |
ab1f24886e1b49eef5fd4b4eb4fb37aa7faeacd9
|
https://github.com/jnaxo/country-codes/blob/ab1f24886e1b49eef5fd4b4eb4fb37aa7faeacd9/src/CountryStore.php#L82-L91
|
22,799
|
jnaxo/country-codes
|
src/CountryStore.php
|
CountryStore.administrativeArea
|
public function administrativeArea($admin_area_id, Request $request = null)
{
$admin_area = AdministrativeArea::find($admin_area_id);
if ($request) {
$included = [];
if (
$request->has('include') &&
AdministrativeArea::isIncludable($request->include)
) {
$cities = $admin_area->cities()->getQuery();
$cities_included = new Collection($cities, 'city');
$included = $cities_included->toArray();
}
$links = $request ? ['self' => $request->url()] : [];
return $this->respondWithItem(
$admin_area,
'administrative_area',
$links,
$included
);
}
return $admin_area;
}
|
php
|
public function administrativeArea($admin_area_id, Request $request = null)
{
$admin_area = AdministrativeArea::find($admin_area_id);
if ($request) {
$included = [];
if (
$request->has('include') &&
AdministrativeArea::isIncludable($request->include)
) {
$cities = $admin_area->cities()->getQuery();
$cities_included = new Collection($cities, 'city');
$included = $cities_included->toArray();
}
$links = $request ? ['self' => $request->url()] : [];
return $this->respondWithItem(
$admin_area,
'administrative_area',
$links,
$included
);
}
return $admin_area;
}
|
[
"public",
"function",
"administrativeArea",
"(",
"$",
"admin_area_id",
",",
"Request",
"$",
"request",
"=",
"null",
")",
"{",
"$",
"admin_area",
"=",
"AdministrativeArea",
"::",
"find",
"(",
"$",
"admin_area_id",
")",
";",
"if",
"(",
"$",
"request",
")",
"{",
"$",
"included",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"request",
"->",
"has",
"(",
"'include'",
")",
"&&",
"AdministrativeArea",
"::",
"isIncludable",
"(",
"$",
"request",
"->",
"include",
")",
")",
"{",
"$",
"cities",
"=",
"$",
"admin_area",
"->",
"cities",
"(",
")",
"->",
"getQuery",
"(",
")",
";",
"$",
"cities_included",
"=",
"new",
"Collection",
"(",
"$",
"cities",
",",
"'city'",
")",
";",
"$",
"included",
"=",
"$",
"cities_included",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"links",
"=",
"$",
"request",
"?",
"[",
"'self'",
"=>",
"$",
"request",
"->",
"url",
"(",
")",
"]",
":",
"[",
"]",
";",
"return",
"$",
"this",
"->",
"respondWithItem",
"(",
"$",
"admin_area",
",",
"'administrative_area'",
",",
"$",
"links",
",",
"$",
"included",
")",
";",
"}",
"return",
"$",
"admin_area",
";",
"}"
] |
Get Administrative area item, optional include cities
@param int $admin_area_id
@param Illuminate\Http\Request $request
@return mixed Jnaxo\CountryCodes\AdministrativeArea item
|
[
"Get",
"Administrative",
"area",
"item",
"optional",
"include",
"cities"
] |
ab1f24886e1b49eef5fd4b4eb4fb37aa7faeacd9
|
https://github.com/jnaxo/country-codes/blob/ab1f24886e1b49eef5fd4b4eb4fb37aa7faeacd9/src/CountryStore.php#L100-L123
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.