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 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
crysalead/chaos-orm | src/Schema.php | Schema.append | public function append($fields)
{
if (is_array($fields)) {
foreach ($fields as $key => $value) {
$this->column($key, $value);
}
} else {
foreach ($fields->fields() as $name) {
$this->column($name, $fields->column($name));
}
}
return $this;
} | php | public function append($fields)
{
if (is_array($fields)) {
foreach ($fields as $key => $value) {
$this->column($key, $value);
}
} else {
foreach ($fields->fields() as $name) {
$this->column($name, $fields->column($name));
}
}
return $this;
} | [
"public",
"function",
"append",
"(",
"$",
"fields",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"column",
"(",
"$",
"key",
... | Appends additional fields to the schema. Will overwrite existing fields if a
conflicts arise.
@param mixed $fields The fields array or a schema instance to merge.
@param array $meta New meta data.
@return object Returns `$this`. | [
"Appends",
"additional",
"fields",
"to",
"the",
"schema",
".",
"Will",
"overwrite",
"existing",
"fields",
"if",
"a",
"conflicts",
"arise",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L473-L485 | train |
crysalead/chaos-orm | src/Schema.php | Schema.virtuals | public function virtuals($attribute = null)
{
$fields = [];
foreach ($this->_columns as $name => $field) {
if (empty($field['virtual'])) {
continue;
}
$fields[] = $name;
}
return $fields;
} | php | public function virtuals($attribute = null)
{
$fields = [];
foreach ($this->_columns as $name => $field) {
if (empty($field['virtual'])) {
continue;
}
$fields[] = $name;
}
return $fields;
} | [
"public",
"function",
"virtuals",
"(",
"$",
"attribute",
"=",
"null",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_columns",
"as",
"$",
"name",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"fiel... | Gets all virtual fields.
@return array | [
"Gets",
"all",
"virtual",
"fields",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L492-L502 | train |
crysalead/chaos-orm | src/Schema.php | Schema.belongsTo | public function belongsTo($name, $to, $config = []) {
$defaults = [
'to' => $to,
'relation' => 'belongsTo'
];
$config += $defaults;
return $this->bind($name, $config);
} | php | public function belongsTo($name, $to, $config = []) {
$defaults = [
'to' => $to,
'relation' => 'belongsTo'
];
$config += $defaults;
return $this->bind($name, $config);
} | [
"public",
"function",
"belongsTo",
"(",
"$",
"name",
",",
"$",
"to",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'to'",
"=>",
"$",
"to",
",",
"'relation'",
"=>",
"'belongsTo'",
"]",
";",
"$",
"config",
"+=",
"$",
"def... | Sets a BelongsTo relation.
@param string $name The name of the relation (i.e. field name where it will be binded).
@param string $to The document class name to bind.
@param array $config The configuration that should be specified in the relationship.
See the `Relationship` class for more information.
@return boolean | [
"Sets",
"a",
"BelongsTo",
"relation",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L551-L558 | train |
crysalead/chaos-orm | src/Schema.php | Schema.hasMany | public function hasMany($name, $to, $config = []) {
$defaults = [
'to' => $to,
'relation' => 'hasMany'
];
$config += $defaults;
return $this->bind($name, $config);
} | php | public function hasMany($name, $to, $config = []) {
$defaults = [
'to' => $to,
'relation' => 'hasMany'
];
$config += $defaults;
return $this->bind($name, $config);
} | [
"public",
"function",
"hasMany",
"(",
"$",
"name",
",",
"$",
"to",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'to'",
"=>",
"$",
"to",
",",
"'relation'",
"=>",
"'hasMany'",
"]",
";",
"$",
"config",
"+=",
"$",
"default... | Sets a hasMany relation.
@param string $name The name of the relation (i.e. field name where it will be binded).
@param string $to The document class name to bind.
@param array $config The configuration that should be specified in the relationship.
See the `Relationship` class for more information.
@return boolean | [
"Sets",
"a",
"hasMany",
"relation",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L569-L576 | train |
crysalead/chaos-orm | src/Schema.php | Schema.hasOne | public function hasOne($name, $to, $config = []) {
$defaults = [
'to' => $to,
'relation' => 'hasOne'
];
$config += $defaults;
return $this->bind($name, $config);
} | php | public function hasOne($name, $to, $config = []) {
$defaults = [
'to' => $to,
'relation' => 'hasOne'
];
$config += $defaults;
return $this->bind($name, $config);
} | [
"public",
"function",
"hasOne",
"(",
"$",
"name",
",",
"$",
"to",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'to'",
"=>",
"$",
"to",
",",
"'relation'",
"=>",
"'hasOne'",
"]",
";",
"$",
"config",
"+=",
"$",
"defaults"... | Sets a hasOne relation.
@param string $name The name of the relation (i.e. field name where it will be binded).
@param string $to The document class name to bind.
@param array $config The configuration that should be specified in the relationship.
See the `Relationship` class for more information.
@return boolean | [
"Sets",
"a",
"hasOne",
"relation",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L587-L594 | train |
crysalead/chaos-orm | src/Schema.php | Schema.hasManyThrough | public function hasManyThrough($name, $through, $using, $config = []) {
$defaults = [
'through' => $through,
'using' => $using,
'relation' => 'hasManyThrough'
];
$config += $defaults;
return $this->bind($name, $config);
} | php | public function hasManyThrough($name, $through, $using, $config = []) {
$defaults = [
'through' => $through,
'using' => $using,
'relation' => 'hasManyThrough'
];
$config += $defaults;
return $this->bind($name, $config);
} | [
"public",
"function",
"hasManyThrough",
"(",
"$",
"name",
",",
"$",
"through",
",",
"$",
"using",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'through'",
"=>",
"$",
"through",
",",
"'using'",
"=>",
"$",
"using",
",",
"'... | Sets a hasManyThrough relation.
@param string $name The name of the relation (i.e. field name where it will be binded).
@param string $through the relation name to pivot table.
@param string $using the target relation name in the through relation.
@param array $config The configuration that should be specified in the relationship.
See the `Relationship` class for more information.
@return boolean | [
"Sets",
"a",
"hasManyThrough",
"relation",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L606-L614 | train |
crysalead/chaos-orm | src/Schema.php | Schema.unbind | public function unbind($name)
{
if (!isset($this->_relations[$name])) {
return;
}
unset($this->_relations[$name]);
unset($this->_relationships[$name]);
} | php | public function unbind($name)
{
if (!isset($this->_relations[$name])) {
return;
}
unset($this->_relations[$name]);
unset($this->_relationships[$name]);
} | [
"public",
"function",
"unbind",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_relations",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"_relations",
"[",
"$",
"name",
... | Unbinds a relation.
@param string $name The name of the relation to unbind. | [
"Unbinds",
"a",
"relation",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L686-L693 | train |
crysalead/chaos-orm | src/Schema.php | Schema.relation | public function relation($name)
{
if (isset($this->_relationships[$name])) {
return $this->_relationships[$name];
}
if (!isset($this->_relations[$name])) {
throw new ORMException("Relationship `{$name}` not found.");
}
$config = $this->_relations[$name];
$relationship = $config['relation'];
unset($config['relation']);
$relation = $this->_classes[$relationship];
return $this->_relationships[$name] = new $relation($config + [
'name' => $name,
'conventions' => $this->_conventions
]);
} | php | public function relation($name)
{
if (isset($this->_relationships[$name])) {
return $this->_relationships[$name];
}
if (!isset($this->_relations[$name])) {
throw new ORMException("Relationship `{$name}` not found.");
}
$config = $this->_relations[$name];
$relationship = $config['relation'];
unset($config['relation']);
$relation = $this->_classes[$relationship];
return $this->_relationships[$name] = new $relation($config + [
'name' => $name,
'conventions' => $this->_conventions
]);
} | [
"public",
"function",
"relation",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_relationships",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_relationships",
"[",
"$",
"name",
"]",
";",
"}",
"if",
... | Returns a relationship instance.
@param string $name The name of a relation.
@return object Returns a relationship intance or `null` if it doesn't exists. | [
"Returns",
"a",
"relationship",
"instance",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L701-L718 | train |
crysalead/chaos-orm | src/Schema.php | Schema.relations | public function relations($embedded = false)
{
$result = [];
foreach ($this->_relations as $field => $config) {
if (!$config['embedded'] || $embedded) {
$result[] = $field;
}
}
return $result;
} | php | public function relations($embedded = false)
{
$result = [];
foreach ($this->_relations as $field => $config) {
if (!$config['embedded'] || $embedded) {
$result[] = $field;
}
}
return $result;
} | [
"public",
"function",
"relations",
"(",
"$",
"embedded",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"_relations",
"as",
"$",
"field",
"=>",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"$",
"config",
... | Returns an array of external relation names.
@param boolean $embedded Include or not embedded relations.
@return array Returns an array of relation names. | [
"Returns",
"an",
"array",
"of",
"external",
"relation",
"names",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L726-L735 | train |
crysalead/chaos-orm | src/Schema.php | Schema.hasRelation | public function hasRelation($name, $embedded = null)
{
if (!isset($this->_relations[$name])) {
return false;
}
$relation = $this->_relations[$name];
if ($embedded === null) {
return true;
}
return $embedded === $relation['embedded'];
} | php | public function hasRelation($name, $embedded = null)
{
if (!isset($this->_relations[$name])) {
return false;
}
$relation = $this->_relations[$name];
if ($embedded === null) {
return true;
}
return $embedded === $relation['embedded'];
} | [
"public",
"function",
"hasRelation",
"(",
"$",
"name",
",",
"$",
"embedded",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_relations",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"relation",
... | Checks if a relation exists.
@param string $name The name of a relation.
@param boolean $embedded Check for embedded relations or not. `null` means indifferent, `true` means embedded only
and `false` mean external only.
@return boolean Returns `true` if the relation exists, `false` otherwise. | [
"Checks",
"if",
"a",
"relation",
"exists",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L745-L755 | train |
crysalead/chaos-orm | src/Schema.php | Schema.embed | public function embed(&$collection, $relations, $options = [])
{
$expanded = [];
$relations = $this->expand($relations);
$tree = $this->treeify($relations);
$habtm = [];
foreach ($tree as $name => $subtree) {
$rel = $this->relation($name);
if ($rel->type() === 'hasManyThrough') {
$habtm[] = $name;
continue;
}
$to = $rel->to();
$query = empty($relations[$name]) ? [] : $relations[$name];
if (is_callable($query)) {
$options['query']['handler'] = $query;
} else {
$options['query'] = $query;
}
$related = $rel->embed($collection, $options);
$subrelations = [];
foreach ($relations as $path => $value) {
if (preg_match('~^'.$name.'\.(.*)$~', $path, $matches)) {
$subrelations[$matches[1]] = $value;
}
}
if ($subrelations) {
$to::definition()->embed($related, $subrelations, $options);
}
}
foreach ($habtm as $name) {
$rel = $this->relation($name);
$related = $rel->embed($collection, $options);
}
} | php | public function embed(&$collection, $relations, $options = [])
{
$expanded = [];
$relations = $this->expand($relations);
$tree = $this->treeify($relations);
$habtm = [];
foreach ($tree as $name => $subtree) {
$rel = $this->relation($name);
if ($rel->type() === 'hasManyThrough') {
$habtm[] = $name;
continue;
}
$to = $rel->to();
$query = empty($relations[$name]) ? [] : $relations[$name];
if (is_callable($query)) {
$options['query']['handler'] = $query;
} else {
$options['query'] = $query;
}
$related = $rel->embed($collection, $options);
$subrelations = [];
foreach ($relations as $path => $value) {
if (preg_match('~^'.$name.'\.(.*)$~', $path, $matches)) {
$subrelations[$matches[1]] = $value;
}
}
if ($subrelations) {
$to::definition()->embed($related, $subrelations, $options);
}
}
foreach ($habtm as $name) {
$rel = $this->relation($name);
$related = $rel->embed($collection, $options);
}
} | [
"public",
"function",
"embed",
"(",
"&",
"$",
"collection",
",",
"$",
"relations",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"expanded",
"=",
"[",
"]",
";",
"$",
"relations",
"=",
"$",
"this",
"->",
"expand",
"(",
"$",
"relations",
")",
... | Eager loads relations.
@param array $collection The collection to extend.
@param array $relations The relations to eager load.
@param array $options The fetching options. | [
"Eager",
"loads",
"relations",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L764-L803 | train |
crysalead/chaos-orm | src/Schema.php | Schema.expand | public function expand($relations)
{
if (is_string($relations)) {
$relations = [$relations];
}
$relations = Set::normalize($relations);
foreach ($relations as $path => $value) {
$num = strpos($path, '.');
$name = $num !== false ? substr($path, 0, $num) : $path;
$rel = $this->relation($name);
if ($rel->type() !== 'hasManyThrough') {
continue;
}
$relPath = $rel->through() . '.' . $rel->using() . ($num !== false ? '.' . substr($path, $num + 1) : '');
if (!isset($relations[$relPath])) {
$relations[$relPath] = $relations[$path];
}
}
return $relations;
} | php | public function expand($relations)
{
if (is_string($relations)) {
$relations = [$relations];
}
$relations = Set::normalize($relations);
foreach ($relations as $path => $value) {
$num = strpos($path, '.');
$name = $num !== false ? substr($path, 0, $num) : $path;
$rel = $this->relation($name);
if ($rel->type() !== 'hasManyThrough') {
continue;
}
$relPath = $rel->through() . '.' . $rel->using() . ($num !== false ? '.' . substr($path, $num + 1) : '');
if (!isset($relations[$relPath])) {
$relations[$relPath] = $relations[$path];
}
}
return $relations;
} | [
"public",
"function",
"expand",
"(",
"$",
"relations",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"relations",
")",
")",
"{",
"$",
"relations",
"=",
"[",
"$",
"relations",
"]",
";",
"}",
"$",
"relations",
"=",
"Set",
"::",
"normalize",
"(",
"$",
"... | Expands all `'hasManyThrough'` relations into their full path.
@param array $relations The relations to eager load.
@return array The relations with expanded `'hasManyThrough'` relations. | [
"Expands",
"all",
"hasManyThrough",
"relations",
"into",
"their",
"full",
"path",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L811-L831 | train |
crysalead/chaos-orm | src/Schema.php | Schema.treeify | public function treeify($embed)
{
if (!$embed) {
return [];
}
$embed = Set::expand(Set::normalize((array) $embed), ['affix' => 'embed']);
$result = [];
foreach ($embed as $relName => $value) {
if (!isset($this->_relations[$relName])) {
continue;
}
if ($this->_relations[$relName]['relation'] === 'hasManyThrough') {
$rel = $this->relation($relName);
if (!isset($result[$rel->through()]['embed'][$rel->using()])) {
$result[$rel->through()]['embed'][$rel->using()] = $value;
}
}
$result[$relName] = $value;
}
return $result;
} | php | public function treeify($embed)
{
if (!$embed) {
return [];
}
$embed = Set::expand(Set::normalize((array) $embed), ['affix' => 'embed']);
$result = [];
foreach ($embed as $relName => $value) {
if (!isset($this->_relations[$relName])) {
continue;
}
if ($this->_relations[$relName]['relation'] === 'hasManyThrough') {
$rel = $this->relation($relName);
if (!isset($result[$rel->through()]['embed'][$rel->using()])) {
$result[$rel->through()]['embed'][$rel->using()] = $value;
}
}
$result[$relName] = $value;
}
return $result;
} | [
"public",
"function",
"treeify",
"(",
"$",
"embed",
")",
"{",
"if",
"(",
"!",
"$",
"embed",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"embed",
"=",
"Set",
"::",
"expand",
"(",
"Set",
"::",
"normalize",
"(",
"(",
"array",
")",
"$",
"embed",
"... | Returns a nested tree representation of `'embed'` option.
@return array The corresponding nested tree representation. | [
"Returns",
"a",
"nested",
"tree",
"representation",
"of",
"embed",
"option",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L838-L859 | train |
crysalead/chaos-orm | src/Schema.php | Schema.cast | public function cast($field = null, $data = [], $options = [])
{
$defaults = [
'parent' => null,
'basePath' => null,
'exists' => null,
'defaults' => true
];
$options += $defaults;
$options['class'] = $this->reference();
if ($field !== null) {
$name = $options['basePath'] ? $options['basePath'] . '.' . $field : (string) $field;
} else {
$name = $options['basePath'];
}
if ($name === null) {
return $this->_cast($name, $data, $options);
}
foreach([$name, preg_replace('~[^.]*$~', '*', $name, 1)] as $entry) {
if (isset($this->_relations[$entry])) {
return $this->_relationCast($field, $entry, $data, $options);
}
if (isset($this->_columns[$entry])) {
return $this->_columnCast($field, $entry, $data, $options);
}
}
if ($this->locked()) {
return $data;
}
if (is_array($data)) {
$options['class'] = Document::class;
$options['basePath'] = $name;
if (isset($data[0])) {
return $this->_castArray($name, $data, $options);
} else {
return $this->_cast($name, $data, $options);
}
}
return $data;
} | php | public function cast($field = null, $data = [], $options = [])
{
$defaults = [
'parent' => null,
'basePath' => null,
'exists' => null,
'defaults' => true
];
$options += $defaults;
$options['class'] = $this->reference();
if ($field !== null) {
$name = $options['basePath'] ? $options['basePath'] . '.' . $field : (string) $field;
} else {
$name = $options['basePath'];
}
if ($name === null) {
return $this->_cast($name, $data, $options);
}
foreach([$name, preg_replace('~[^.]*$~', '*', $name, 1)] as $entry) {
if (isset($this->_relations[$entry])) {
return $this->_relationCast($field, $entry, $data, $options);
}
if (isset($this->_columns[$entry])) {
return $this->_columnCast($field, $entry, $data, $options);
}
}
if ($this->locked()) {
return $data;
}
if (is_array($data)) {
$options['class'] = Document::class;
$options['basePath'] = $name;
if (isset($data[0])) {
return $this->_castArray($name, $data, $options);
} else {
return $this->_cast($name, $data, $options);
}
}
return $data;
} | [
"public",
"function",
"cast",
"(",
"$",
"field",
"=",
"null",
",",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'parent'",
"=>",
"null",
",",
"'basePath'",
"=>",
"null",
",",
"'exists'",
"=... | Cast data according to the schema definition.
@param string $field The field name.
@param array $data Some data to cast.
@param array $options Options for the casting.
@return object The casted data. | [
"Cast",
"data",
"according",
"to",
"the",
"schema",
"definition",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L869-L916 | train |
crysalead/chaos-orm | src/Schema.php | Schema._relationCast | protected function _relationCast($field, $name, $data, $options)
{
$options = $this->_relations[$name] + $options;
$options['basePath'] = $options['embedded'] ? $name : null;
$options['schema'] = $options['embedded'] ? $this : null;
if ($options['relation'] !== 'hasManyThrough') {
$options['class'] = $options['to'];
} else {
$through = $this->relation($name);
$options['class'] = $through->to();
}
if ($field) {
return $options['array'] ? $this->_castArray($name, $data, $options) : $this->_cast($name, $data, $options);
}
if (!isset($this->_columns[$name])) {
return $data;
}
$column = $this->_columns[$name];
return $this->convert('cast', $column['type'], $data, $column, $options);
} | php | protected function _relationCast($field, $name, $data, $options)
{
$options = $this->_relations[$name] + $options;
$options['basePath'] = $options['embedded'] ? $name : null;
$options['schema'] = $options['embedded'] ? $this : null;
if ($options['relation'] !== 'hasManyThrough') {
$options['class'] = $options['to'];
} else {
$through = $this->relation($name);
$options['class'] = $through->to();
}
if ($field) {
return $options['array'] ? $this->_castArray($name, $data, $options) : $this->_cast($name, $data, $options);
}
if (!isset($this->_columns[$name])) {
return $data;
}
$column = $this->_columns[$name];
return $this->convert('cast', $column['type'], $data, $column, $options);
} | [
"protected",
"function",
"_relationCast",
"(",
"$",
"field",
",",
"$",
"name",
",",
"$",
"data",
",",
"$",
"options",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"_relations",
"[",
"$",
"name",
"]",
"+",
"$",
"options",
";",
"$",
"options",
"... | Casting helper for relations.
@param string $field The field name to cast.
@param string $name The full field name to cast.
@param array $data Some data to cast.
@param array $options Options for the casting.
@return mixed The casted data. | [
"Casting",
"helper",
"for",
"relations",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L927-L947 | train |
crysalead/chaos-orm | src/Schema.php | Schema._columnCast | protected function _columnCast($field, $name, $data, $options)
{
$column = $this->_columns[$name];
if (!empty($column['setter'])) {
$data = $column['setter']($options['parent'], $data, $name);
}
if ($column['array'] && $field) {
return $this->_castArray($name, $data, $options);
}
return $this->convert('cast', $column['type'], $data, $column/*, []*/);
} | php | protected function _columnCast($field, $name, $data, $options)
{
$column = $this->_columns[$name];
if (!empty($column['setter'])) {
$data = $column['setter']($options['parent'], $data, $name);
}
if ($column['array'] && $field) {
return $this->_castArray($name, $data, $options);
}
return $this->convert('cast', $column['type'], $data, $column/*, []*/);
} | [
"protected",
"function",
"_columnCast",
"(",
"$",
"field",
",",
"$",
"name",
",",
"$",
"data",
",",
"$",
"options",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"_columns",
"[",
"$",
"name",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"colum... | Casting helper for columns.
@param string $field The field name to cast.
@param string $name The full field name to cast.
@param array $data Some data to cast.
@param array $options Options for the casting.
@return mixed The casted data. | [
"Casting",
"helper",
"for",
"columns",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L958-L968 | train |
crysalead/chaos-orm | src/Schema.php | Schema._cast | public function _cast($name, $data, $options)
{
if ($data === null) {
return;
}
if ($data instanceof Document) {
return $data;
}
$class = ltrim($options['class'], '\\');
$config = [
'schema' => $class === Document::class ? $this : null,
'basePath' => $options['basePath'],
'exists' => $options['exists'],
'defaults' => $options['defaults']
];
if (isset($options['config'])){
$config = Set::extend($config, $options['config']);
}
$column = isset($this->_columns[$name]) ? $this->_columns[$name] : [];
if (!empty($column['format'])) {
$data = $this->convert('cast', $column['format'], $data, $column, $config);
}
return $class::create($data ? $data : [], $config);
} | php | public function _cast($name, $data, $options)
{
if ($data === null) {
return;
}
if ($data instanceof Document) {
return $data;
}
$class = ltrim($options['class'], '\\');
$config = [
'schema' => $class === Document::class ? $this : null,
'basePath' => $options['basePath'],
'exists' => $options['exists'],
'defaults' => $options['defaults']
];
if (isset($options['config'])){
$config = Set::extend($config, $options['config']);
}
$column = isset($this->_columns[$name]) ? $this->_columns[$name] : [];
if (!empty($column['format'])) {
$data = $this->convert('cast', $column['format'], $data, $column, $config);
}
return $class::create($data ? $data : [], $config);
} | [
"public",
"function",
"_cast",
"(",
"$",
"name",
",",
"$",
"data",
",",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"data",
"instanceof",
"Document",
")",
"{",
"return",
"$",
"dat... | Casting helper for entities.
@param string $name The field name to cast.
@param array $data Some data to cast.
@param array $options Options for the casting.
@return mixed The casted data. | [
"Casting",
"helper",
"for",
"entities",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L978-L1005 | train |
crysalead/chaos-orm | src/Schema.php | Schema._castArray | public function _castArray($name, $data, $options)
{
$options['type'] = isset($options['relation']) && $options['relation'] === 'hasManyThrough' ? 'through' : 'set';
$class = ltrim($options['class'], '\\');
$classes = $class::classes();
$collection = $classes[$options['type']];
if ($data instanceof $collection) {
return $data;
}
$isThrough = $options['type'] === 'through';
$isDocument = $class === Document::class;
$config = [
'schema' => $isDocument ? $this : $class::definition(),
'basePath' => $isDocument ? $name : null,
'meta' => isset($options['meta']) ? $options['meta'] : [],
'exists' => $options['exists'],
'defaults' => $options['defaults']
];
if (isset($options['config'])){
$config = Set::extend($config, $options['config']);
}
$column = isset($this->_columns[$name]) ? $this->_columns[$name] : [];
if (!empty($column['format']) && $data !== null) {
$type = $column['format'];
$data = $this->convert('cast', $type, $data, $column, $config);
}
if ($isThrough) {
$config['parent'] = $options['parent'];
$config['through'] = $options['through'];
$config['using'] = $options['using'];
$config['data'] = $data;
} else {
$config['data'] = $data ?: [];
}
return new $collection($config);
} | php | public function _castArray($name, $data, $options)
{
$options['type'] = isset($options['relation']) && $options['relation'] === 'hasManyThrough' ? 'through' : 'set';
$class = ltrim($options['class'], '\\');
$classes = $class::classes();
$collection = $classes[$options['type']];
if ($data instanceof $collection) {
return $data;
}
$isThrough = $options['type'] === 'through';
$isDocument = $class === Document::class;
$config = [
'schema' => $isDocument ? $this : $class::definition(),
'basePath' => $isDocument ? $name : null,
'meta' => isset($options['meta']) ? $options['meta'] : [],
'exists' => $options['exists'],
'defaults' => $options['defaults']
];
if (isset($options['config'])){
$config = Set::extend($config, $options['config']);
}
$column = isset($this->_columns[$name]) ? $this->_columns[$name] : [];
if (!empty($column['format']) && $data !== null) {
$type = $column['format'];
$data = $this->convert('cast', $type, $data, $column, $config);
}
if ($isThrough) {
$config['parent'] = $options['parent'];
$config['through'] = $options['through'];
$config['using'] = $options['using'];
$config['data'] = $data;
} else {
$config['data'] = $data ?: [];
}
return new $collection($config);
} | [
"public",
"function",
"_castArray",
"(",
"$",
"name",
",",
"$",
"data",
",",
"$",
"options",
")",
"{",
"$",
"options",
"[",
"'type'",
"]",
"=",
"isset",
"(",
"$",
"options",
"[",
"'relation'",
"]",
")",
"&&",
"$",
"options",
"[",
"'relation'",
"]",
... | Casting helper for arrays.
@param string $name The field name to cast.
@param array $data Some data to cast.
@param array $options Options for the casting.
@return mixed The casted data. | [
"Casting",
"helper",
"for",
"arrays",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L1015-L1056 | train |
crysalead/chaos-orm | src/Schema.php | Schema.format | public function format($mode, $name, $data)
{
if ($mode === 'cast') {
throw new InvalidArgumentException("Use `Schema::cast()` to perform casting.");
}
if (!isset($this->_columns[$name])) {
// Formatting non defined columns or relations doesn't make sense, bailing out.
return $this->convert($mode, '_default_', $data, []);
}
$column = $this->_columns[$name];
$isNull = $data === null;
$type = $isNull ? 'null' : $this->type($name);
if (!$column['array']) {
$data = $this->convert($mode, $type, $data, $column);
} else {
$data = Collection::format($mode, $data);
}
if (!$isNull && !empty($column['format'])) {
$data = $this->convert($mode, $column['format'], $data, $column);
}
return $data;
} | php | public function format($mode, $name, $data)
{
if ($mode === 'cast') {
throw new InvalidArgumentException("Use `Schema::cast()` to perform casting.");
}
if (!isset($this->_columns[$name])) {
// Formatting non defined columns or relations doesn't make sense, bailing out.
return $this->convert($mode, '_default_', $data, []);
}
$column = $this->_columns[$name];
$isNull = $data === null;
$type = $isNull ? 'null' : $this->type($name);
if (!$column['array']) {
$data = $this->convert($mode, $type, $data, $column);
} else {
$data = Collection::format($mode, $data);
}
if (!$isNull && !empty($column['format'])) {
$data = $this->convert($mode, $column['format'], $data, $column);
}
return $data;
} | [
"public",
"function",
"format",
"(",
"$",
"mode",
",",
"$",
"name",
",",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"mode",
"===",
"'cast'",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Use `Schema::cast()` to perform casting.\"",
")",
";",
"}",... | Formats a value according to a field definition.
@param string $mode The format mode (i.e. `'array'` or `'datasource'`).
@param string $name The field name.
@param mixed $data The data to format.
@return mixed The formated value. | [
"Formats",
"a",
"value",
"according",
"to",
"a",
"field",
"definition",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L1167-L1189 | train |
crysalead/chaos-orm | src/Schema.php | Schema.convert | public function convert($mode, $type, $data, $column = [], $options = [])
{
$formatter = null;
$type = $data === null ? 'null' : $type;
if (isset($this->_formatters[$mode][$type])) {
$formatter = $this->_formatters[$mode][$type];
} elseif (isset($this->_formatters[$mode]['_default_'])) {
$formatter = $this->_formatters[$mode]['_default_'];
}
return $formatter ? $formatter($data, $column, $options) : $data;
} | php | public function convert($mode, $type, $data, $column = [], $options = [])
{
$formatter = null;
$type = $data === null ? 'null' : $type;
if (isset($this->_formatters[$mode][$type])) {
$formatter = $this->_formatters[$mode][$type];
} elseif (isset($this->_formatters[$mode]['_default_'])) {
$formatter = $this->_formatters[$mode]['_default_'];
}
return $formatter ? $formatter($data, $column, $options) : $data;
} | [
"public",
"function",
"convert",
"(",
"$",
"mode",
",",
"$",
"type",
",",
"$",
"data",
",",
"$",
"column",
"=",
"[",
"]",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"formatter",
"=",
"null",
";",
"$",
"type",
"=",
"$",
"data",
"===",
... | Formats a value according to its type.
@param string $mode The format mode (i.e. `'cast'` or `'datasource'`).
@param string $type The field name.
@param mixed $data The value to format.
@param array $column The column options to pass the the formatter handler.
@param array $options The options to pass the the formatter handler (for `'cast'` mode only).
@return mixed The formated value. | [
"Formats",
"a",
"value",
"according",
"to",
"its",
"type",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L1201-L1211 | train |
crysalead/chaos-orm | src/Schema.php | Schema.saveRelation | public function saveRelation($instance, $types, $options = [])
{
$defaults = ['embed' => []];
$options += $defaults;
$types = (array) $types;
$collection = $instance instanceof Document ? [$instance] : $instance;
$success = true;
foreach ($collection as $entity) {
foreach ($types as $type) {
foreach ($options['embed'] as $relName => $value) {
if (!($rel = $this->relation($relName)) || $rel->type() !== $type) {
continue;
}
$success = $success && $rel->save($entity, $value ? $value + $options : $options);
}
}
}
return $success;
} | php | public function saveRelation($instance, $types, $options = [])
{
$defaults = ['embed' => []];
$options += $defaults;
$types = (array) $types;
$collection = $instance instanceof Document ? [$instance] : $instance;
$success = true;
foreach ($collection as $entity) {
foreach ($types as $type) {
foreach ($options['embed'] as $relName => $value) {
if (!($rel = $this->relation($relName)) || $rel->type() !== $type) {
continue;
}
$success = $success && $rel->save($entity, $value ? $value + $options : $options);
}
}
}
return $success;
} | [
"public",
"function",
"saveRelation",
"(",
"$",
"instance",
",",
"$",
"types",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'embed'",
"=>",
"[",
"]",
"]",
";",
"$",
"options",
"+=",
"$",
"defaults",
";",
"$",
"types",
... | Save data related to relations.
@param object $instance The entity instance.
@param array $types Type of relations to save.
@param array $options Options array.
@return boolean Returns `true` on a successful save operation, `false` on failure. | [
"Save",
"data",
"related",
"to",
"relations",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Schema.php#L1357-L1377 | train |
usemarkup/contentful | src/Promise/EntryPromise.php | EntryPromise.getField | public function getField($key)
{
$resolved = $this->getResolved();
if (!$resolved instanceof EntryInterface) {
return null;
}
return $resolved->getField($key);
} | php | public function getField($key)
{
$resolved = $this->getResolved();
if (!$resolved instanceof EntryInterface) {
return null;
}
return $resolved->getField($key);
} | [
"public",
"function",
"getField",
"(",
"$",
"key",
")",
"{",
"$",
"resolved",
"=",
"$",
"this",
"->",
"getResolved",
"(",
")",
";",
"if",
"(",
"!",
"$",
"resolved",
"instanceof",
"EntryInterface",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
... | Gets an individual field value, or null if the field is not defined.
@return mixed | [
"Gets",
"an",
"individual",
"field",
"value",
"or",
"null",
"if",
"the",
"field",
"is",
"not",
"defined",
"."
] | ac5902bf891c52fd00d349bd5aae78d516dcd601 | https://github.com/usemarkup/contentful/blob/ac5902bf891c52fd00d349bd5aae78d516dcd601/src/Promise/EntryPromise.php#L35-L43 | train |
yangjian102621/herosphp | src/string/StringBuffer.php | StringBuffer.appendTab | public function appendTab($str=null, $tabNum=1) {
$tab = "";
for ( $i = 0; $i < $tabNum; $i++ ) {
$tab .= "\t";
}
$this->appendLine($tab.$str);
} | php | public function appendTab($str=null, $tabNum=1) {
$tab = "";
for ( $i = 0; $i < $tabNum; $i++ ) {
$tab .= "\t";
}
$this->appendLine($tab.$str);
} | [
"public",
"function",
"appendTab",
"(",
"$",
"str",
"=",
"null",
",",
"$",
"tabNum",
"=",
"1",
")",
"{",
"$",
"tab",
"=",
"\"\"",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"tabNum",
";",
"$",
"i",
"++",
")",
"{",
"$",
... | append line with tab symbol | [
"append",
"line",
"with",
"tab",
"symbol"
] | dc0a7b1c73b005098fd627977cd787eb0ab4a4e2 | https://github.com/yangjian102621/herosphp/blob/dc0a7b1c73b005098fd627977cd787eb0ab4a4e2/src/string/StringBuffer.php#L36-L44 | train |
thelia-modules/AttributeType | Model/Base/AttributeTypeQuery.php | AttributeTypeQuery.filterByHasAttributeAvValue | public function filterByHasAttributeAvValue($hasAttributeAvValue = null, $comparison = null)
{
if (is_array($hasAttributeAvValue)) {
$useMinMax = false;
if (isset($hasAttributeAvValue['min'])) {
$this->addUsingAlias(AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE, $hasAttributeAvValue['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($hasAttributeAvValue['max'])) {
$this->addUsingAlias(AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE, $hasAttributeAvValue['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE, $hasAttributeAvValue, $comparison);
} | php | public function filterByHasAttributeAvValue($hasAttributeAvValue = null, $comparison = null)
{
if (is_array($hasAttributeAvValue)) {
$useMinMax = false;
if (isset($hasAttributeAvValue['min'])) {
$this->addUsingAlias(AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE, $hasAttributeAvValue['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($hasAttributeAvValue['max'])) {
$this->addUsingAlias(AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE, $hasAttributeAvValue['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(AttributeTypeTableMap::HAS_ATTRIBUTE_AV_VALUE, $hasAttributeAvValue, $comparison);
} | [
"public",
"function",
"filterByHasAttributeAvValue",
"(",
"$",
"hasAttributeAvValue",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"hasAttributeAvValue",
")",
")",
"{",
"$",
"useMinMax",
"=",
"false",
";",
"if"... | Filter the query on the has_attribute_av_value column
Example usage:
<code>
$query->filterByHasAttributeAvValue(1234); // WHERE has_attribute_av_value = 1234
$query->filterByHasAttributeAvValue(array(12, 34)); // WHERE has_attribute_av_value IN (12, 34)
$query->filterByHasAttributeAvValue(array('min' => 12)); // WHERE has_attribute_av_value > 12
</code>
@param mixed $hasAttributeAvValue The value to use as filter.
Use scalar values for equality.
Use array values for in_array() equivalent.
Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildAttributeTypeQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"has_attribute_av_value",
"column"
] | 674a18afab276039a251720c1779726084b2a639 | https://github.com/thelia-modules/AttributeType/blob/674a18afab276039a251720c1779726084b2a639/Model/Base/AttributeTypeQuery.php#L368-L389 | train |
thelia-modules/AttributeType | Model/Base/AttributeTypeQuery.php | AttributeTypeQuery.filterByIsMultilingualAttributeAvValue | public function filterByIsMultilingualAttributeAvValue($isMultilingualAttributeAvValue = null, $comparison = null)
{
if (is_array($isMultilingualAttributeAvValue)) {
$useMinMax = false;
if (isset($isMultilingualAttributeAvValue['min'])) {
$this->addUsingAlias(AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, $isMultilingualAttributeAvValue['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($isMultilingualAttributeAvValue['max'])) {
$this->addUsingAlias(AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, $isMultilingualAttributeAvValue['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, $isMultilingualAttributeAvValue, $comparison);
} | php | public function filterByIsMultilingualAttributeAvValue($isMultilingualAttributeAvValue = null, $comparison = null)
{
if (is_array($isMultilingualAttributeAvValue)) {
$useMinMax = false;
if (isset($isMultilingualAttributeAvValue['min'])) {
$this->addUsingAlias(AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, $isMultilingualAttributeAvValue['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($isMultilingualAttributeAvValue['max'])) {
$this->addUsingAlias(AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, $isMultilingualAttributeAvValue['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(AttributeTypeTableMap::IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE, $isMultilingualAttributeAvValue, $comparison);
} | [
"public",
"function",
"filterByIsMultilingualAttributeAvValue",
"(",
"$",
"isMultilingualAttributeAvValue",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"isMultilingualAttributeAvValue",
")",
")",
"{",
"$",
"useMinMax"... | Filter the query on the is_multilingual_attribute_av_value column
Example usage:
<code>
$query->filterByIsMultilingualAttributeAvValue(1234); // WHERE is_multilingual_attribute_av_value = 1234
$query->filterByIsMultilingualAttributeAvValue(array(12, 34)); // WHERE is_multilingual_attribute_av_value IN (12, 34)
$query->filterByIsMultilingualAttributeAvValue(array('min' => 12)); // WHERE is_multilingual_attribute_av_value > 12
</code>
@param mixed $isMultilingualAttributeAvValue The value to use as filter.
Use scalar values for equality.
Use array values for in_array() equivalent.
Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildAttributeTypeQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"is_multilingual_attribute_av_value",
"column"
] | 674a18afab276039a251720c1779726084b2a639 | https://github.com/thelia-modules/AttributeType/blob/674a18afab276039a251720c1779726084b2a639/Model/Base/AttributeTypeQuery.php#L409-L430 | train |
thelia-modules/AttributeType | Model/Base/AttributeTypeQuery.php | AttributeTypeQuery.filterByPattern | public function filterByPattern($pattern = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($pattern)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $pattern)) {
$pattern = str_replace('*', '%', $pattern);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(AttributeTypeTableMap::PATTERN, $pattern, $comparison);
} | php | public function filterByPattern($pattern = null, $comparison = null)
{
if (null === $comparison) {
if (is_array($pattern)) {
$comparison = Criteria::IN;
} elseif (preg_match('/[\%\*]/', $pattern)) {
$pattern = str_replace('*', '%', $pattern);
$comparison = Criteria::LIKE;
}
}
return $this->addUsingAlias(AttributeTypeTableMap::PATTERN, $pattern, $comparison);
} | [
"public",
"function",
"filterByPattern",
"(",
"$",
"pattern",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"comparison",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"pattern",
")",
")",
"{",
"$",
"comparis... | Filter the query on the pattern column
Example usage:
<code>
$query->filterByPattern('fooValue'); // WHERE pattern = 'fooValue'
$query->filterByPattern('%fooValue%'); // WHERE pattern LIKE '%fooValue%'
</code>
@param string $pattern The value to use as filter.
Accepts wildcards (* and % trigger a LIKE)
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildAttributeTypeQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"pattern",
"column"
] | 674a18afab276039a251720c1779726084b2a639 | https://github.com/thelia-modules/AttributeType/blob/674a18afab276039a251720c1779726084b2a639/Model/Base/AttributeTypeQuery.php#L447-L459 | train |
thelia-modules/AttributeType | Model/Base/AttributeTypeQuery.php | AttributeTypeQuery.filterByImageRatio | public function filterByImageRatio($imageRatio = null, $comparison = null)
{
if (is_array($imageRatio)) {
$useMinMax = false;
if (isset($imageRatio['min'])) {
$this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($imageRatio['max'])) {
$this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio, $comparison);
} | php | public function filterByImageRatio($imageRatio = null, $comparison = null)
{
if (is_array($imageRatio)) {
$useMinMax = false;
if (isset($imageRatio['min'])) {
$this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($imageRatio['max'])) {
$this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(AttributeTypeTableMap::IMAGE_RATIO, $imageRatio, $comparison);
} | [
"public",
"function",
"filterByImageRatio",
"(",
"$",
"imageRatio",
"=",
"null",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"imageRatio",
")",
")",
"{",
"$",
"useMinMax",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
... | Filter the query on the image_ratio column
Example usage:
<code>
$query->filterByImageRatio(1234); // WHERE image_ratio = 1234
$query->filterByImageRatio(array(12, 34)); // WHERE image_ratio IN (12, 34)
$query->filterByImageRatio(array('min' => 12)); // WHERE image_ratio > 12
</code>
@param mixed $imageRatio The value to use as filter.
Use scalar values for equality.
Use array values for in_array() equivalent.
Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildAttributeTypeQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"on",
"the",
"image_ratio",
"column"
] | 674a18afab276039a251720c1779726084b2a639 | https://github.com/thelia-modules/AttributeType/blob/674a18afab276039a251720c1779726084b2a639/Model/Base/AttributeTypeQuery.php#L742-L763 | train |
thelia-modules/AttributeType | Model/Base/AttributeTypeQuery.php | AttributeTypeQuery.filterByAttributeTypeI18n | public function filterByAttributeTypeI18n($attributeTypeI18n, $comparison = null)
{
if ($attributeTypeI18n instanceof \AttributeType\Model\AttributeTypeI18n) {
return $this
->addUsingAlias(AttributeTypeTableMap::ID, $attributeTypeI18n->getId(), $comparison);
} elseif ($attributeTypeI18n instanceof ObjectCollection) {
return $this
->useAttributeTypeI18nQuery()
->filterByPrimaryKeys($attributeTypeI18n->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByAttributeTypeI18n() only accepts arguments of type \AttributeType\Model\AttributeTypeI18n or Collection');
}
} | php | public function filterByAttributeTypeI18n($attributeTypeI18n, $comparison = null)
{
if ($attributeTypeI18n instanceof \AttributeType\Model\AttributeTypeI18n) {
return $this
->addUsingAlias(AttributeTypeTableMap::ID, $attributeTypeI18n->getId(), $comparison);
} elseif ($attributeTypeI18n instanceof ObjectCollection) {
return $this
->useAttributeTypeI18nQuery()
->filterByPrimaryKeys($attributeTypeI18n->getPrimaryKeys())
->endUse();
} else {
throw new PropelException('filterByAttributeTypeI18n() only accepts arguments of type \AttributeType\Model\AttributeTypeI18n or Collection');
}
} | [
"public",
"function",
"filterByAttributeTypeI18n",
"(",
"$",
"attributeTypeI18n",
",",
"$",
"comparison",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"attributeTypeI18n",
"instanceof",
"\\",
"AttributeType",
"\\",
"Model",
"\\",
"AttributeTypeI18n",
")",
"{",
"return",... | Filter the query by a related \AttributeType\Model\AttributeTypeI18n object
@param \AttributeType\Model\AttributeTypeI18n|ObjectCollection $attributeTypeI18n the related object to use as filter
@param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
@return ChildAttributeTypeQuery The current query, for fluid interface | [
"Filter",
"the",
"query",
"by",
"a",
"related",
"\\",
"AttributeType",
"\\",
"Model",
"\\",
"AttributeTypeI18n",
"object"
] | 674a18afab276039a251720c1779726084b2a639 | https://github.com/thelia-modules/AttributeType/blob/674a18afab276039a251720c1779726084b2a639/Model/Base/AttributeTypeQuery.php#L932-L945 | train |
thelia-modules/AttributeType | Model/Base/AttributeTypeQuery.php | AttributeTypeQuery.useAttributeTypeI18nQuery | public function useAttributeTypeI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinAttributeTypeI18n($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'AttributeTypeI18n', '\AttributeType\Model\AttributeTypeI18nQuery');
} | php | public function useAttributeTypeI18nQuery($relationAlias = null, $joinType = 'LEFT JOIN')
{
return $this
->joinAttributeTypeI18n($relationAlias, $joinType)
->useQuery($relationAlias ? $relationAlias : 'AttributeTypeI18n', '\AttributeType\Model\AttributeTypeI18nQuery');
} | [
"public",
"function",
"useAttributeTypeI18nQuery",
"(",
"$",
"relationAlias",
"=",
"null",
",",
"$",
"joinType",
"=",
"'LEFT JOIN'",
")",
"{",
"return",
"$",
"this",
"->",
"joinAttributeTypeI18n",
"(",
"$",
"relationAlias",
",",
"$",
"joinType",
")",
"->",
"us... | Use the AttributeTypeI18n relation AttributeTypeI18n object
@see useQuery()
@param string $relationAlias optional alias for the relation,
to be used as main alias in the secondary query
@param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
@return \AttributeType\Model\AttributeTypeI18nQuery A secondary query class using the current class as primary query | [
"Use",
"the",
"AttributeTypeI18n",
"relation",
"AttributeTypeI18n",
"object"
] | 674a18afab276039a251720c1779726084b2a639 | https://github.com/thelia-modules/AttributeType/blob/674a18afab276039a251720c1779726084b2a639/Model/Base/AttributeTypeQuery.php#L990-L995 | train |
thelia-modules/AttributeType | Model/Base/AttributeTypeI18nQuery.php | AttributeTypeI18nQuery.create | public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \AttributeType\Model\AttributeTypeI18nQuery) {
return $criteria;
}
$query = new \AttributeType\Model\AttributeTypeI18nQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
} | php | public static function create($modelAlias = null, $criteria = null)
{
if ($criteria instanceof \AttributeType\Model\AttributeTypeI18nQuery) {
return $criteria;
}
$query = new \AttributeType\Model\AttributeTypeI18nQuery();
if (null !== $modelAlias) {
$query->setModelAlias($modelAlias);
}
if ($criteria instanceof Criteria) {
$query->mergeWith($criteria);
}
return $query;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"modelAlias",
"=",
"null",
",",
"$",
"criteria",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"criteria",
"instanceof",
"\\",
"AttributeType",
"\\",
"Model",
"\\",
"AttributeTypeI18nQuery",
")",
"{",
"return",
... | Returns a new ChildAttributeTypeI18nQuery object.
@param string $modelAlias The alias of a model in the query
@param Criteria $criteria Optional Criteria to build the query from
@return ChildAttributeTypeI18nQuery | [
"Returns",
"a",
"new",
"ChildAttributeTypeI18nQuery",
"object",
"."
] | 674a18afab276039a251720c1779726084b2a639 | https://github.com/thelia-modules/AttributeType/blob/674a18afab276039a251720c1779726084b2a639/Model/Base/AttributeTypeI18nQuery.php#L79-L93 | train |
thelia/CurrencyConverter | src/CurrencyConverter.php | CurrencyConverter.validate | private function validate()
{
if (null === $this->provider) {
throw new MissingProviderException('A provider must be set for converting a currency');
}
if (null === $this->from || null === $this->to) {
throw new \RuntimeException('from and to parameters must be provided');
}
} | php | private function validate()
{
if (null === $this->provider) {
throw new MissingProviderException('A provider must be set for converting a currency');
}
if (null === $this->from || null === $this->to) {
throw new \RuntimeException('from and to parameters must be provided');
}
} | [
"private",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"provider",
")",
"{",
"throw",
"new",
"MissingProviderException",
"(",
"'A provider must be set for converting a currency'",
")",
";",
"}",
"if",
"(",
"null",
"===",
... | Verify if the conversation can be done.
@throws MissingProviderException thrown if the provider is missing
@throws \RuntimeException thrown if to or from parameters are missing | [
"Verify",
"if",
"the",
"conversation",
"can",
"be",
"done",
"."
] | 93dae743cf7cd82cf169012bfd6a8dd43d68b974 | https://github.com/thelia/CurrencyConverter/blob/93dae743cf7cd82cf169012bfd6a8dd43d68b974/src/CurrencyConverter.php#L118-L127 | train |
kyozhou/zookeeper-client | ZookeeperClient.php | ZookeeperClient.set | public function set($path, $value) {
if (!$this->zookeeper->exists($path)) {
$this->makePath($path);
$this->makeNode($path, $value);
} else {
$this->zookeeper->set($path, $value);
}
} | php | public function set($path, $value) {
if (!$this->zookeeper->exists($path)) {
$this->makePath($path);
$this->makeNode($path, $value);
} else {
$this->zookeeper->set($path, $value);
}
} | [
"public",
"function",
"set",
"(",
"$",
"path",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"zookeeper",
"->",
"exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"this",
"->",
"makePath",
"(",
"$",
"path",
")",
";",
"$",
"this",... | Set a node to a value. If the node doesn't exist yet, it is created.
Existing values of the node are overwritten
@param string $path The path to the node
@param mixed $value The new value for the node
@return mixed previous value if set, or null | [
"Set",
"a",
"node",
"to",
"a",
"value",
".",
"If",
"the",
"node",
"doesn",
"t",
"exist",
"yet",
"it",
"is",
"created",
".",
"Existing",
"values",
"of",
"the",
"node",
"are",
"overwritten"
] | 59969b8257da2ea91f7228b787f0d4e96779bf34 | https://github.com/kyozhou/zookeeper-client/blob/59969b8257da2ea91f7228b787f0d4e96779bf34/ZookeeperClient.php#L47-L54 | train |
kyozhou/zookeeper-client | ZookeeperClient.php | ZookeeperClient.makePath | public function makePath($path, $value = '') {
$parts = explode('/', $path);
$parts = array_filter($parts);
$subpath = '';
while (count($parts) > 1) {
$subpath .= '/' . array_shift($parts);
if (!$this->zookeeper->exists($subpath)) {
$this->makeNode($subpath, $value);
}
}
} | php | public function makePath($path, $value = '') {
$parts = explode('/', $path);
$parts = array_filter($parts);
$subpath = '';
while (count($parts) > 1) {
$subpath .= '/' . array_shift($parts);
if (!$this->zookeeper->exists($subpath)) {
$this->makeNode($subpath, $value);
}
}
} | [
"public",
"function",
"makePath",
"(",
"$",
"path",
",",
"$",
"value",
"=",
"''",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"parts",
"=",
"array_filter",
"(",
"$",
"parts",
")",
";",
"$",
"subpath",
"=",... | Equivalent of "mkdir -p" on ZooKeeper
@param string $path The path to the node
@param string $value The value to assign to each new node along the path
@return bool | [
"Equivalent",
"of",
"mkdir",
"-",
"p",
"on",
"ZooKeeper"
] | 59969b8257da2ea91f7228b787f0d4e96779bf34 | https://github.com/kyozhou/zookeeper-client/blob/59969b8257da2ea91f7228b787f0d4e96779bf34/ZookeeperClient.php#L64-L74 | train |
kyozhou/zookeeper-client | ZookeeperClient.php | ZookeeperClient.makeNode | public function makeNode($path, $value, array $params = array()) {
if (empty($params)) {
$params = array(
array(
'perms' => \Zookeeper::PERM_ALL,
'scheme' => 'world',
'id' => 'anyone',
)
);
}
return $this->zookeeper->create($path, $value, $params);
} | php | public function makeNode($path, $value, array $params = array()) {
if (empty($params)) {
$params = array(
array(
'perms' => \Zookeeper::PERM_ALL,
'scheme' => 'world',
'id' => 'anyone',
)
);
}
return $this->zookeeper->create($path, $value, $params);
} | [
"public",
"function",
"makeNode",
"(",
"$",
"path",
",",
"$",
"value",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"array",
"(",
"'perms'"... | Create a node on ZooKeeper at the given path
@param string $path The path to the node
@param string $value The value to assign to the new node
@param array $params Optional parameters for the Zookeeper node.
By default, a public node is created
@return string the path to the newly created node or null on failure | [
"Create",
"a",
"node",
"on",
"ZooKeeper",
"at",
"the",
"given",
"path"
] | 59969b8257da2ea91f7228b787f0d4e96779bf34 | https://github.com/kyozhou/zookeeper-client/blob/59969b8257da2ea91f7228b787f0d4e96779bf34/ZookeeperClient.php#L86-L97 | train |
kyozhou/zookeeper-client | ZookeeperClient.php | ZookeeperClient.get | public function get($path) {
if (!$this->zookeeper->exists($path)) {
return null;
}
return $this->zookeeper->get($path);
} | php | public function get($path) {
if (!$this->zookeeper->exists($path)) {
return null;
}
return $this->zookeeper->get($path);
} | [
"public",
"function",
"get",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"zookeeper",
"->",
"exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"zookeeper",
"->",
"get",
"(",
"$",... | Get the value for the node
@param string $path the path to the node
@return string|null | [
"Get",
"the",
"value",
"for",
"the",
"node"
] | 59969b8257da2ea91f7228b787f0d4e96779bf34 | https://github.com/kyozhou/zookeeper-client/blob/59969b8257da2ea91f7228b787f0d4e96779bf34/ZookeeperClient.php#L106-L111 | train |
kyozhou/zookeeper-client | ZookeeperClient.php | ZookeeperClient.getChildren | public function getChildren($path) {
if (strlen($path) > 1 && preg_match('@/$@', $path)) {
// remove trailing /
$path = substr($path, 0, -1);
}
return $this->zookeeper->getChildren($path);
} | php | public function getChildren($path) {
if (strlen($path) > 1 && preg_match('@/$@', $path)) {
// remove trailing /
$path = substr($path, 0, -1);
}
return $this->zookeeper->getChildren($path);
} | [
"public",
"function",
"getChildren",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"path",
")",
">",
"1",
"&&",
"preg_match",
"(",
"'@/$@'",
",",
"$",
"path",
")",
")",
"{",
"// remove trailing /",
"$",
"path",
"=",
"substr",
"(",
"$",
... | List the children of the given path, i.e. the name of the directories
within the current node, if any
@param string $path the path to the node
@return array the subpaths within the given node | [
"List",
"the",
"children",
"of",
"the",
"given",
"path",
"i",
".",
"e",
".",
"the",
"name",
"of",
"the",
"directories",
"within",
"the",
"current",
"node",
"if",
"any"
] | 59969b8257da2ea91f7228b787f0d4e96779bf34 | https://github.com/kyozhou/zookeeper-client/blob/59969b8257da2ea91f7228b787f0d4e96779bf34/ZookeeperClient.php#L121-L127 | train |
kyozhou/zookeeper-client | ZookeeperClient.php | ZookeeperClient.deleteNode | public function deleteNode($path)
{
if(!$this->zookeeper->exists($path))
{
return null;
}
else
{
return $this->zookeeper->delete($path);
}
} | php | public function deleteNode($path)
{
if(!$this->zookeeper->exists($path))
{
return null;
}
else
{
return $this->zookeeper->delete($path);
}
} | [
"public",
"function",
"deleteNode",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"zookeeper",
"->",
"exists",
"(",
"$",
"path",
")",
")",
"{",
"return",
"null",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"zookeeper",
"->"... | Delete the node if it does not have any children
@param string $path the path to the node
@return true if node is deleted else null | [
"Delete",
"the",
"node",
"if",
"it",
"does",
"not",
"have",
"any",
"children"
] | 59969b8257da2ea91f7228b787f0d4e96779bf34 | https://github.com/kyozhou/zookeeper-client/blob/59969b8257da2ea91f7228b787f0d4e96779bf34/ZookeeperClient.php#L137-L147 | train |
kyozhou/zookeeper-client | ZookeeperClient.php | ZookeeperClient.watch | public function watch($path, $callback)
{
if (!is_callable($callback)) {
return null;
}
if ($this->zookeeper->exists($path)) {
if (!isset($this->callback[$path])) {
$this->callback[$path] = array();
}
if (!in_array($callback, $this->callback[$path])) {
$this->callback[$path][] = $callback;
return $this->zookeeper->get($path, array($this, 'watchCallback'));
}
}
} | php | public function watch($path, $callback)
{
if (!is_callable($callback)) {
return null;
}
if ($this->zookeeper->exists($path)) {
if (!isset($this->callback[$path])) {
$this->callback[$path] = array();
}
if (!in_array($callback, $this->callback[$path])) {
$this->callback[$path][] = $callback;
return $this->zookeeper->get($path, array($this, 'watchCallback'));
}
}
} | [
"public",
"function",
"watch",
"(",
"$",
"path",
",",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"zookeeper",
"->",
"exists",
"(",
"$",
... | Wath a given path
@param string $path the path to node
@param callable $callback callback function
@return string|null | [
"Wath",
"a",
"given",
"path"
] | 59969b8257da2ea91f7228b787f0d4e96779bf34 | https://github.com/kyozhou/zookeeper-client/blob/59969b8257da2ea91f7228b787f0d4e96779bf34/ZookeeperClient.php#L155-L170 | train |
kyozhou/zookeeper-client | ZookeeperClient.php | ZookeeperClient.watchCallback | public function watchCallback($event_type, $stat, $path)
{
if (!isset($this->callback[$path])) {
return null;
}
foreach ($this->callback[$path] as $callback) {
$this->zookeeper->get($path, array($this, 'watchCallback'));
return call_user_func($callback);
}
} | php | public function watchCallback($event_type, $stat, $path)
{
if (!isset($this->callback[$path])) {
return null;
}
foreach ($this->callback[$path] as $callback) {
$this->zookeeper->get($path, array($this, 'watchCallback'));
return call_user_func($callback);
}
} | [
"public",
"function",
"watchCallback",
"(",
"$",
"event_type",
",",
"$",
"stat",
",",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"callback",
"[",
"$",
"path",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"foreach",
... | Wath event callback warper
@param int $event_type
@param int $stat
@param string $path
@return the return of the callback or null | [
"Wath",
"event",
"callback",
"warper"
] | 59969b8257da2ea91f7228b787f0d4e96779bf34 | https://github.com/kyozhou/zookeeper-client/blob/59969b8257da2ea91f7228b787f0d4e96779bf34/ZookeeperClient.php#L179-L189 | train |
kyozhou/zookeeper-client | ZookeeperClient.php | ZookeeperClient.loadNode | public function loadNode($path) {
$list = @$this->zookeeper->getChildren($path);
if(!empty($list)) {
$data = [];
foreach($list as $key) {
$value = $this->zookeeper->get($path . '/' . $key);
if(!empty($value)) {
$data[$key] = $value;
}else {
$data[$key] = $this->loadNode($path . '/' . $key);
}
}
return $data;
}else {
$value = @$this->zookeeper->get($path);
return $value;
}
} | php | public function loadNode($path) {
$list = @$this->zookeeper->getChildren($path);
if(!empty($list)) {
$data = [];
foreach($list as $key) {
$value = $this->zookeeper->get($path . '/' . $key);
if(!empty($value)) {
$data[$key] = $value;
}else {
$data[$key] = $this->loadNode($path . '/' . $key);
}
}
return $data;
}else {
$value = @$this->zookeeper->get($path);
return $value;
}
} | [
"public",
"function",
"loadNode",
"(",
"$",
"path",
")",
"{",
"$",
"list",
"=",
"@",
"$",
"this",
"->",
"zookeeper",
"->",
"getChildren",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"list",
")",
")",
"{",
"$",
"data",
"=",
"[... | return treed-config or string | [
"return",
"treed",
"-",
"config",
"or",
"string"
] | 59969b8257da2ea91f7228b787f0d4e96779bf34 | https://github.com/kyozhou/zookeeper-client/blob/59969b8257da2ea91f7228b787f0d4e96779bf34/ZookeeperClient.php#L219-L236 | train |
crysalead/chaos-orm | src/Conventions.php | Conventions.config | public function config($config = [])
{
$defaults = [
'conventions' => [
'source' => function($class) {
$basename = substr(strrchr($class, '\\'), 1);
return Inflector::underscore($basename);
},
'key' => function() {
return 'id';
},
'reference' => function($class) {
$pos = strrpos($class, '\\');
$basename = substr($class, $pos !== false ? $pos + 1 : 0);
return Inflector::underscore(Inflector::singularize($basename)). '_id';
},
'references' => function($class) {
$pos = strrpos($class, '\\');
$basename = substr($class, $pos !== false ? $pos + 1 : 0);
return Inflector::underscore(Inflector::singularize($basename)). '_ids';
},
'field' => function($class) {
$pos = strrpos($class, '\\');
$basename = substr($class, $pos !== false ? $pos + 1 : 0);
return Inflector::underscore(Inflector::singularize($basename));
},
'multiple' => function($name) {
return Inflector::pluralize($name);
},
'single' => function($name) {
return Inflector::singularize($name);
}
]
];
$config = Set::extend($defaults, $config);
$this->_conventions = $config['conventions'];
} | php | public function config($config = [])
{
$defaults = [
'conventions' => [
'source' => function($class) {
$basename = substr(strrchr($class, '\\'), 1);
return Inflector::underscore($basename);
},
'key' => function() {
return 'id';
},
'reference' => function($class) {
$pos = strrpos($class, '\\');
$basename = substr($class, $pos !== false ? $pos + 1 : 0);
return Inflector::underscore(Inflector::singularize($basename)). '_id';
},
'references' => function($class) {
$pos = strrpos($class, '\\');
$basename = substr($class, $pos !== false ? $pos + 1 : 0);
return Inflector::underscore(Inflector::singularize($basename)). '_ids';
},
'field' => function($class) {
$pos = strrpos($class, '\\');
$basename = substr($class, $pos !== false ? $pos + 1 : 0);
return Inflector::underscore(Inflector::singularize($basename));
},
'multiple' => function($name) {
return Inflector::pluralize($name);
},
'single' => function($name) {
return Inflector::singularize($name);
}
]
];
$config = Set::extend($defaults, $config);
$this->_conventions = $config['conventions'];
} | [
"public",
"function",
"config",
"(",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"$",
"defaults",
"=",
"[",
"'conventions'",
"=>",
"[",
"'source'",
"=>",
"function",
"(",
"$",
"class",
")",
"{",
"$",
"basename",
"=",
"substr",
"(",
"strrchr",
"(",
"$",
... | Configures the schema class.
@param array $config Possible options are:
- `'conventions'` _array_: Allow to override the default convention rules for generating
primary or foreign key as well as for table/collection names
from an entity class name. | [
"Configures",
"the",
"schema",
"class",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Conventions.php#L41-L77 | train |
crysalead/chaos-orm | src/Conventions.php | Conventions.get | public function get($name = null)
{
if (!$name) {
return $this->_conventions;
}
if (!isset($this->_conventions[$name])) {
throw new ORMException("Convention for `'{$name}'` doesn't exists.");
}
return $this->_conventions[$name];
} | php | public function get($name = null)
{
if (!$name) {
return $this->_conventions;
}
if (!isset($this->_conventions[$name])) {
throw new ORMException("Convention for `'{$name}'` doesn't exists.");
}
return $this->_conventions[$name];
} | [
"public",
"function",
"get",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"name",
")",
"{",
"return",
"$",
"this",
"->",
"_conventions",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_conventions",
"[",
"$",
"name",... | Gets a specific or all convention rules.
@param string $name The name of the convention or `null` to get all.
@return mixed The closure or an array of closures.
@throws Exception Throws a `ORMException` if no rule has been found. | [
"Gets",
"a",
"specific",
"or",
"all",
"convention",
"rules",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Conventions.php#L98-L107 | train |
crysalead/chaos-orm | src/Conventions.php | Conventions.apply | public function apply($name) {
$params = func_get_args();
array_shift($params);
$convention = $this->get($name);
return call_user_func_array($convention, $params);
} | php | public function apply($name) {
$params = func_get_args();
array_shift($params);
$convention = $this->get($name);
return call_user_func_array($convention, $params);
} | [
"public",
"function",
"apply",
"(",
"$",
"name",
")",
"{",
"$",
"params",
"=",
"func_get_args",
"(",
")",
";",
"array_shift",
"(",
"$",
"params",
")",
";",
"$",
"convention",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"name",
")",
";",
"return",
"cal... | Applies a specific convention rules.
@param string $name The name of the convention.
@param mixed $param Parameter to pass to the closure.
@param mixed ... Parameter to pass to the closure.
@return mixed
@throws Exception Throws a `ORMException` if no rule has been found. | [
"Applies",
"a",
"specific",
"convention",
"rules",
"."
] | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Conventions.php#L118-L123 | train |
dreamfactorysoftware/df-script | src/Components/ScriptEngineType.php | ScriptEngineType.toArray | public function toArray()
{
return [
'name' => $this->name,
'label' => $this->label,
'description' => $this->description,
'sandboxed' => $this->sandboxed,
'supports_inline_execution' => $this->supportsInlineExecution,
];
} | php | public function toArray()
{
return [
'name' => $this->name,
'label' => $this->label,
'description' => $this->description,
'sandboxed' => $this->sandboxed,
'supports_inline_execution' => $this->supportsInlineExecution,
];
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"name",
",",
"'label'",
"=>",
"$",
"this",
"->",
"label",
",",
"'description'",
"=>",
"$",
"this",
"->",
"description",
",",
"'sandboxed'",
"=>",
"$",
"th... | The configuration handler interface for this script type
@return array | null | [
"The",
"configuration",
"handler",
"interface",
"for",
"this",
"script",
"type"
] | 14941f5dada6077286a0d992d6aa8c3d9243d5a0 | https://github.com/dreamfactorysoftware/df-script/blob/14941f5dada6077286a0d992d6aa8c3d9243d5a0/src/Components/ScriptEngineType.php#L129-L138 | train |
crysalead/chaos-orm | src/Relationship/HasMany.php | HasMany.junction | public function junction($boolean = null)
{
if (func_num_args()) {
$this->_junction = $boolean;
return $this;
}
return $this->_junction;
} | php | public function junction($boolean = null)
{
if (func_num_args()) {
$this->_junction = $boolean;
return $this;
}
return $this->_junction;
} | [
"public",
"function",
"junction",
"(",
"$",
"boolean",
"=",
"null",
")",
"{",
"if",
"(",
"func_num_args",
"(",
")",
")",
"{",
"$",
"this",
"->",
"_junction",
"=",
"$",
"boolean",
";",
"return",
"$",
"this",
";",
"}",
"return",
"$",
"this",
"->",
"_... | Sets the behavior of associative entities. If a hasMany relation is marked as a "junction table",
associative entities will be removed once a foreign key is unsetted. When a hasMany relation is
not marked as a "junction table", associative entities will simply have their foreign key unsetted.
@param boolean $boolean The junction value to set or none to get it.
@return object Returns `$this` on set and the junction value on get. | [
"Sets",
"the",
"behavior",
"of",
"associative",
"entities",
".",
"If",
"a",
"hasMany",
"relation",
"is",
"marked",
"as",
"a",
"junction",
"table",
"associative",
"entities",
"will",
"be",
"removed",
"once",
"a",
"foreign",
"key",
"is",
"unsetted",
".",
"When... | 835f891311bb30c9178910df7223d1cdfd269560 | https://github.com/crysalead/chaos-orm/blob/835f891311bb30c9178910df7223d1cdfd269560/src/Relationship/HasMany.php#L52-L59 | train |
orchestral/model | src/Eloquent.php | Eloquent.saveIfExists | public function saveIfExists(array $options = []): bool
{
if ($this->exists === false) {
return false;
}
return $this->save($options);
} | php | public function saveIfExists(array $options = []): bool
{
if ($this->exists === false) {
return false;
}
return $this->save($options);
} | [
"public",
"function",
"saveIfExists",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"exists",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"save",
"(",
"$",
... | Save the model to the database if exists.
@param array $options
@return bool | [
"Save",
"the",
"model",
"to",
"the",
"database",
"if",
"exists",
"."
] | 59eb60a022afb3caa0ac5824d6faac85f3255c0d | https://github.com/orchestral/model/blob/59eb60a022afb3caa0ac5824d6faac85f3255c0d/src/Eloquent.php#L46-L53 | train |
orchestral/model | src/Eloquent.php | Eloquent.saveIfExistsOrFail | public function saveIfExistsOrFail(array $options = []): bool
{
if ($this->exists === false) {
return false;
}
return $this->saveOrFail($options);
} | php | public function saveIfExistsOrFail(array $options = []): bool
{
if ($this->exists === false) {
return false;
}
return $this->saveOrFail($options);
} | [
"public",
"function",
"saveIfExistsOrFail",
"(",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"exists",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"saveOrFail",
... | Save the model to the database using transaction if exists.
@param array $options
@return bool | [
"Save",
"the",
"model",
"to",
"the",
"database",
"using",
"transaction",
"if",
"exists",
"."
] | 59eb60a022afb3caa0ac5824d6faac85f3255c0d | https://github.com/orchestral/model/blob/59eb60a022afb3caa0ac5824d6faac85f3255c0d/src/Eloquent.php#L62-L69 | train |
wikiworldorder/survloop | src/Controllers/Tree/TreeCore.php | TreeCore.loadRawOrder | protected function loadRawOrder($tmpSubTier)
{
$nID = $tmpSubTier[0];
$this->nodesRawIndex[$nID] = sizeof($this->nodesRawOrder);
$this->nodesRawOrder[] = $nID;
if (sizeof($tmpSubTier[1]) > 0) {
foreach ($tmpSubTier[1] as $deeper) {
$this->loadRawOrder($deeper);
}
}
return true;
} | php | protected function loadRawOrder($tmpSubTier)
{
$nID = $tmpSubTier[0];
$this->nodesRawIndex[$nID] = sizeof($this->nodesRawOrder);
$this->nodesRawOrder[] = $nID;
if (sizeof($tmpSubTier[1]) > 0) {
foreach ($tmpSubTier[1] as $deeper) {
$this->loadRawOrder($deeper);
}
}
return true;
} | [
"protected",
"function",
"loadRawOrder",
"(",
"$",
"tmpSubTier",
")",
"{",
"$",
"nID",
"=",
"$",
"tmpSubTier",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"nodesRawIndex",
"[",
"$",
"nID",
"]",
"=",
"sizeof",
"(",
"$",
"this",
"->",
"nodesRawOrder",
")",
... | Cache tree's standard Pre-Order Traversal | [
"Cache",
"tree",
"s",
"standard",
"Pre",
"-",
"Order",
"Traversal"
] | 7fbd61a453e2ea8c3e55bbdd6b0bed1c859c8f4a | https://github.com/wikiworldorder/survloop/blob/7fbd61a453e2ea8c3e55bbdd6b0bed1c859c8f4a/src/Controllers/Tree/TreeCore.php#L184-L195 | train |
wikiworldorder/survloop | src/Controllers/Tree/TreeCore.php | TreeCore.prevNode | public function prevNode($nID)
{
$nodeOverride = $this->movePrevOverride($nID);
if ($nodeOverride > 0) {
return $nodeOverride;
}
if (!isset($this->nodesRawIndex[$nID])) {
return -3;
}
$prevNodeInd = $this->nodesRawIndex[$nID]-1;
if ($prevNodeInd < 0 || !isset($this->nodesRawOrder[$prevNodeInd])) {
return -3;
}
$prevNodeID = $this->nodesRawOrder[$prevNodeInd];
return $prevNodeID;
} | php | public function prevNode($nID)
{
$nodeOverride = $this->movePrevOverride($nID);
if ($nodeOverride > 0) {
return $nodeOverride;
}
if (!isset($this->nodesRawIndex[$nID])) {
return -3;
}
$prevNodeInd = $this->nodesRawIndex[$nID]-1;
if ($prevNodeInd < 0 || !isset($this->nodesRawOrder[$prevNodeInd])) {
return -3;
}
$prevNodeID = $this->nodesRawOrder[$prevNodeInd];
return $prevNodeID;
} | [
"public",
"function",
"prevNode",
"(",
"$",
"nID",
")",
"{",
"$",
"nodeOverride",
"=",
"$",
"this",
"->",
"movePrevOverride",
"(",
"$",
"nID",
")",
";",
"if",
"(",
"$",
"nodeOverride",
">",
"0",
")",
"{",
"return",
"$",
"nodeOverride",
";",
"}",
"if"... | Locate previous node in standard Pre-Order Traversal | [
"Locate",
"previous",
"node",
"in",
"standard",
"Pre",
"-",
"Order",
"Traversal"
] | 7fbd61a453e2ea8c3e55bbdd6b0bed1c859c8f4a | https://github.com/wikiworldorder/survloop/blob/7fbd61a453e2ea8c3e55bbdd6b0bed1c859c8f4a/src/Controllers/Tree/TreeCore.php#L198-L213 | train |
wikiworldorder/survloop | src/Controllers/Tree/TreeCore.php | TreeCore.nextNode | public function nextNode($nID)
{
if ($nID <= 0 || !isset($this->nodesRawIndex[$nID])) {
return -3;
}
$this->runCurrNode($nID);
$nodeOverride = $this->moveNextOverride($nID);
if ($nodeOverride > 0) {
return $nodeOverride;
}
//if ($nID == $GLOBALS["SL"]->treeRow->TreeLastPage) return -37;
$nextNodeInd = $this->nodesRawIndex[$nID]+1;
if (!isset($this->nodesRawOrder[$nextNodeInd])) {
return -3;
}
$nextNodeID = $this->nodesRawOrder[$nextNodeInd];
return $nextNodeID;
} | php | public function nextNode($nID)
{
if ($nID <= 0 || !isset($this->nodesRawIndex[$nID])) {
return -3;
}
$this->runCurrNode($nID);
$nodeOverride = $this->moveNextOverride($nID);
if ($nodeOverride > 0) {
return $nodeOverride;
}
//if ($nID == $GLOBALS["SL"]->treeRow->TreeLastPage) return -37;
$nextNodeInd = $this->nodesRawIndex[$nID]+1;
if (!isset($this->nodesRawOrder[$nextNodeInd])) {
return -3;
}
$nextNodeID = $this->nodesRawOrder[$nextNodeInd];
return $nextNodeID;
} | [
"public",
"function",
"nextNode",
"(",
"$",
"nID",
")",
"{",
"if",
"(",
"$",
"nID",
"<=",
"0",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"nodesRawIndex",
"[",
"$",
"nID",
"]",
")",
")",
"{",
"return",
"-",
"3",
";",
"}",
"$",
"this",
"->",
... | Locate next node in standard Pre-Order Traversal | [
"Locate",
"next",
"node",
"in",
"standard",
"Pre",
"-",
"Order",
"Traversal"
] | 7fbd61a453e2ea8c3e55bbdd6b0bed1c859c8f4a | https://github.com/wikiworldorder/survloop/blob/7fbd61a453e2ea8c3e55bbdd6b0bed1c859c8f4a/src/Controllers/Tree/TreeCore.php#L216-L233 | train |
wikiworldorder/survloop | src/Controllers/Tree/TreeCore.php | TreeCore.nextNodeSibling | public function nextNodeSibling($nID)
{
//if ($nID == $this->tree->TreeLastPage) return -37;
if (!$this->hasNode($nID) || $this->allNodes[$nID]->parentID <= 0) {
return -3;
}
$nodeOverride = $this->moveNextOverride($nID);
if ($nodeOverride > 0) {
return $nodeOverride;
}
$nextSibling = SLNode::where('NodeTree', $this->treeID)
->where('NodeParentID', $this->allNodes[$nID]->parentID)
->where('NodeParentOrder', (1+$this->allNodes[$nID]->parentOrd))
->select('NodeID')
->first();
if ($nextSibling && isset($nextSibling->NodeID)) {
return $nextSibling->NodeID;
}
return $this->nextNodeSibling($this->allNodes[$nID]->parentID);
} | php | public function nextNodeSibling($nID)
{
//if ($nID == $this->tree->TreeLastPage) return -37;
if (!$this->hasNode($nID) || $this->allNodes[$nID]->parentID <= 0) {
return -3;
}
$nodeOverride = $this->moveNextOverride($nID);
if ($nodeOverride > 0) {
return $nodeOverride;
}
$nextSibling = SLNode::where('NodeTree', $this->treeID)
->where('NodeParentID', $this->allNodes[$nID]->parentID)
->where('NodeParentOrder', (1+$this->allNodes[$nID]->parentOrd))
->select('NodeID')
->first();
if ($nextSibling && isset($nextSibling->NodeID)) {
return $nextSibling->NodeID;
}
return $this->nextNodeSibling($this->allNodes[$nID]->parentID);
} | [
"public",
"function",
"nextNodeSibling",
"(",
"$",
"nID",
")",
"{",
"//if ($nID == $this->tree->TreeLastPage) return -37;",
"if",
"(",
"!",
"$",
"this",
"->",
"hasNode",
"(",
"$",
"nID",
")",
"||",
"$",
"this",
"->",
"allNodes",
"[",
"$",
"nID",
"]",
"->",
... | Locate the next node, outside this node's descendants | [
"Locate",
"the",
"next",
"node",
"outside",
"this",
"node",
"s",
"descendants"
] | 7fbd61a453e2ea8c3e55bbdd6b0bed1c859c8f4a | https://github.com/wikiworldorder/survloop/blob/7fbd61a453e2ea8c3e55bbdd6b0bed1c859c8f4a/src/Controllers/Tree/TreeCore.php#L241-L260 | train |
wikiworldorder/survloop | src/Controllers/Tree/TreeCore.php | TreeCore.updateCurrNode | public function updateCurrNode($nID = -3)
{
if ($nID > 0) {
if (!isset($GLOBALS["SL"]->formTree->TreeID)) {
if (!$this->sessInfo) {
$this->createNewSess();
}
$this->sessInfo->SessCurrNode = $nID;
$this->sessInfo->save();
if ($GLOBALS["SL"]->coreTblAbbr() != '' && isset($this->sessData->dataSets[$GLOBALS["SL"]->coreTbl])) {
$this->sessData->currSessData($nID, $GLOBALS["SL"]->coreTbl,
$GLOBALS["SL"]->coreTblAbbr() . 'SubmissionProgress', 'update', $nID);
}
}
$this->currNodeSubTier = $this->loadNodeSubTier($nID);
$this->loadNodeDataBranch($nID);
}
return true;
} | php | public function updateCurrNode($nID = -3)
{
if ($nID > 0) {
if (!isset($GLOBALS["SL"]->formTree->TreeID)) {
if (!$this->sessInfo) {
$this->createNewSess();
}
$this->sessInfo->SessCurrNode = $nID;
$this->sessInfo->save();
if ($GLOBALS["SL"]->coreTblAbbr() != '' && isset($this->sessData->dataSets[$GLOBALS["SL"]->coreTbl])) {
$this->sessData->currSessData($nID, $GLOBALS["SL"]->coreTbl,
$GLOBALS["SL"]->coreTblAbbr() . 'SubmissionProgress', 'update', $nID);
}
}
$this->currNodeSubTier = $this->loadNodeSubTier($nID);
$this->loadNodeDataBranch($nID);
}
return true;
} | [
"public",
"function",
"updateCurrNode",
"(",
"$",
"nID",
"=",
"-",
"3",
")",
"{",
"if",
"(",
"$",
"nID",
">",
"0",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"GLOBALS",
"[",
"\"SL\"",
"]",
"->",
"formTree",
"->",
"TreeID",
")",
")",
"{",
"if"... | Updates currNode without checking if this is a branch node | [
"Updates",
"currNode",
"without",
"checking",
"if",
"this",
"is",
"a",
"branch",
"node"
] | 7fbd61a453e2ea8c3e55bbdd6b0bed1c859c8f4a | https://github.com/wikiworldorder/survloop/blob/7fbd61a453e2ea8c3e55bbdd6b0bed1c859c8f4a/src/Controllers/Tree/TreeCore.php#L410-L428 | train |
CEikermann/apiTalk | src/apiTalk/Request.php | Request.setParameters | public function setParameters(array $parameters, $append = false)
{
if (!$append) {
$this->parameters = $parameters;
} else {
foreach ($parameters as $field => $value) {
$this->setParameter($field, $value);
}
}
} | php | public function setParameters(array $parameters, $append = false)
{
if (!$append) {
$this->parameters = $parameters;
} else {
foreach ($parameters as $field => $value) {
$this->setParameter($field, $value);
}
}
} | [
"public",
"function",
"setParameters",
"(",
"array",
"$",
"parameters",
",",
"$",
"append",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"append",
")",
"{",
"$",
"this",
"->",
"parameters",
"=",
"$",
"parameters",
";",
"}",
"else",
"{",
"foreach",
"(... | Set many GET or POST parameters
@param array $parameters Array of parameters (Format: array('key' => 'value',...))
@param bool $append Append the paramters
@return void | [
"Set",
"many",
"GET",
"or",
"POST",
"parameters"
] | 3890530728258d0b11e26bcef46e06abd497aa56 | https://github.com/CEikermann/apiTalk/blob/3890530728258d0b11e26bcef46e06abd497aa56/src/apiTalk/Request.php#L88-L97 | train |
CEikermann/apiTalk | src/apiTalk/Request.php | Request.getHeader | public function getHeader($field)
{
if (!isset($this->headers[$field])) {
return null;
}
return is_array($this->headers[$field]) ? implode(',', $this->headers[$field]) : $this->headers[$field];
} | php | public function getHeader($field)
{
if (!isset($this->headers[$field])) {
return null;
}
return is_array($this->headers[$field]) ? implode(',', $this->headers[$field]) : $this->headers[$field];
} | [
"public",
"function",
"getHeader",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"$",
"field",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"is_array",
"(",
"$",
"this",
"->",
"headers",
... | Return one field from header
@param string $field Header field name
@return null|string | [
"Return",
"one",
"field",
"from",
"header"
] | 3890530728258d0b11e26bcef46e06abd497aa56 | https://github.com/CEikermann/apiTalk/blob/3890530728258d0b11e26bcef46e06abd497aa56/src/apiTalk/Request.php#L116-L123 | train |
CEikermann/apiTalk | src/apiTalk/Request.php | Request.getHeaders | public function getHeaders()
{
$headerFields = array_keys($this->headers);
$result = array();
foreach ($headerFields as $field) {
$result[] = sprintf('%s: %s', $field, $this->getHeader($field));
}
return $result;
} | php | public function getHeaders()
{
$headerFields = array_keys($this->headers);
$result = array();
foreach ($headerFields as $field) {
$result[] = sprintf('%s: %s', $field, $this->getHeader($field));
}
return $result;
} | [
"public",
"function",
"getHeaders",
"(",
")",
"{",
"$",
"headerFields",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"headers",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"headerFields",
"as",
"$",
"field",
")",
"{",
"$"... | Return the HTTP header
@return array | [
"Return",
"the",
"HTTP",
"header"
] | 3890530728258d0b11e26bcef46e06abd497aa56 | https://github.com/CEikermann/apiTalk/blob/3890530728258d0b11e26bcef46e06abd497aa56/src/apiTalk/Request.php#L130-L140 | train |
CEikermann/apiTalk | src/apiTalk/Request.php | Request.setHeaders | public function setHeaders(array $headers, $append = false)
{
if (!$append) {
$this->headers = $headers;
} else {
foreach ($headers as $field => $value) {
$this->setHeader($field, $value);
}
}
} | php | public function setHeaders(array $headers, $append = false)
{
if (!$append) {
$this->headers = $headers;
} else {
foreach ($headers as $field => $value) {
$this->setHeader($field, $value);
}
}
} | [
"public",
"function",
"setHeaders",
"(",
"array",
"$",
"headers",
",",
"$",
"append",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"append",
")",
"{",
"$",
"this",
"->",
"headers",
"=",
"$",
"headers",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
... | Set or reset the headers
@param array $headers Array of headers
@param bool $reset (Optional) Reset the existing headers
@return void | [
"Set",
"or",
"reset",
"the",
"headers"
] | 3890530728258d0b11e26bcef46e06abd497aa56 | https://github.com/CEikermann/apiTalk/blob/3890530728258d0b11e26bcef46e06abd497aa56/src/apiTalk/Request.php#L161-L170 | train |
CEikermann/apiTalk | src/apiTalk/Adapter/Curl.php | Curl.send | public function send(Request $request)
{
$curl = $this->prepareRequest($request);
$data = curl_exec($curl);
if (false === $data) {
$errorMsg = curl_error($curl);
$errorNo = curl_errno($curl);
throw new \RuntimeException($errorMsg, $errorNo);
}
$data = $this->filterRawResponse($data);
return $this->prepareResponse($data, curl_getinfo($curl, CURLINFO_HTTP_CODE));
} | php | public function send(Request $request)
{
$curl = $this->prepareRequest($request);
$data = curl_exec($curl);
if (false === $data) {
$errorMsg = curl_error($curl);
$errorNo = curl_errno($curl);
throw new \RuntimeException($errorMsg, $errorNo);
}
$data = $this->filterRawResponse($data);
return $this->prepareResponse($data, curl_getinfo($curl, CURLINFO_HTTP_CODE));
} | [
"public",
"function",
"send",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"curl",
"=",
"$",
"this",
"->",
"prepareRequest",
"(",
"$",
"request",
")",
";",
"$",
"data",
"=",
"curl_exec",
"(",
"$",
"curl",
")",
";",
"if",
"(",
"false",
"===",
"$",... | Send the given HTTP request by using this adapter
@param \apiTalk\Request $request The request object
@return \apiTalk\Response The response object
@throws \RuntimeException Thrown when curl_exec return false | [
"Send",
"the",
"given",
"HTTP",
"request",
"by",
"using",
"this",
"adapter"
] | 3890530728258d0b11e26bcef46e06abd497aa56 | https://github.com/CEikermann/apiTalk/blob/3890530728258d0b11e26bcef46e06abd497aa56/src/apiTalk/Adapter/Curl.php#L33-L48 | train |
CEikermann/apiTalk | src/apiTalk/Adapter/Curl.php | Curl.prepareRequest | protected function prepareRequest(Request $request)
{
$curl = curl_init();
// TODO Timeout and Follow Redirect settings
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_CONNECTTIMEOUT_MS => 1000,
CURLOPT_TIMEOUT_MS => 3000,
CURLOPT_CUSTOMREQUEST => $request->getMethod(),
CURLOPT_URL => $request->getUri(),
CURLOPT_HTTPHEADER => $request->getHeaders(),
CURLOPT_HTTPGET => false,
CURLOPT_NOBODY => false,
CURLOPT_POST => false,
CURLOPT_POSTFIELDS => null,
);
switch ($request->getMethod()) {
case Request::METHOD_HEAD:
$options[CURLOPT_NOBODY] = true;
$query = http_build_query($request->getParameters());
if (!empty($query)) {
$options[CURLOPT_URL] = $request->getUri().'?'.$query;
}
break;
case Request::METHOD_GET:
$options[CURLOPT_HTTPGET] = true;
$query = http_build_query($request->getParameters());
if (!empty($query)) {
$options[CURLOPT_URL] = $request->getUri().'?'.$query;
}
break;
case Request::METHOD_POST:
case Request::METHOD_PUT:
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = http_build_query($request->getParameters());
break;
}
curl_setopt_array($curl, $options);
return $curl;
} | php | protected function prepareRequest(Request $request)
{
$curl = curl_init();
// TODO Timeout and Follow Redirect settings
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_CONNECTTIMEOUT_MS => 1000,
CURLOPT_TIMEOUT_MS => 3000,
CURLOPT_CUSTOMREQUEST => $request->getMethod(),
CURLOPT_URL => $request->getUri(),
CURLOPT_HTTPHEADER => $request->getHeaders(),
CURLOPT_HTTPGET => false,
CURLOPT_NOBODY => false,
CURLOPT_POST => false,
CURLOPT_POSTFIELDS => null,
);
switch ($request->getMethod()) {
case Request::METHOD_HEAD:
$options[CURLOPT_NOBODY] = true;
$query = http_build_query($request->getParameters());
if (!empty($query)) {
$options[CURLOPT_URL] = $request->getUri().'?'.$query;
}
break;
case Request::METHOD_GET:
$options[CURLOPT_HTTPGET] = true;
$query = http_build_query($request->getParameters());
if (!empty($query)) {
$options[CURLOPT_URL] = $request->getUri().'?'.$query;
}
break;
case Request::METHOD_POST:
case Request::METHOD_PUT:
$options[CURLOPT_POST] = true;
$options[CURLOPT_POSTFIELDS] = http_build_query($request->getParameters());
break;
}
curl_setopt_array($curl, $options);
return $curl;
} | [
"protected",
"function",
"prepareRequest",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"curl",
"=",
"curl_init",
"(",
")",
";",
"// TODO Timeout and Follow Redirect settings",
"$",
"options",
"=",
"array",
"(",
"CURLOPT_RETURNTRANSFER",
"=>",
"true",
",",
"CURL... | Prepare cURL with the given request
@param \apiTalk\Request $requst
@return void | [
"Prepare",
"cURL",
"with",
"the",
"given",
"request"
] | 3890530728258d0b11e26bcef46e06abd497aa56 | https://github.com/CEikermann/apiTalk/blob/3890530728258d0b11e26bcef46e06abd497aa56/src/apiTalk/Adapter/Curl.php#L57-L105 | train |
CEikermann/apiTalk | src/apiTalk/Adapter/Curl.php | Curl.prepareResponse | protected function prepareResponse($data, $code)
{
$rawHeaders = array();
$rawContent = null;
$lines = preg_split('/(\\r?\\n)/', $data, -1, PREG_SPLIT_DELIM_CAPTURE);
for ($i = 0, $count = count($lines); $i < $count; $i += 2) {
$line = $lines[$i];
if (!empty($line)) {
$rawHeaders[] = $line;
} else {
$rawContent = implode('', array_slice($lines, $i + 2));
break;
}
}
$headers = $this->prepareHeaders($rawHeaders);
return new Response($rawContent, $code, $headers);
} | php | protected function prepareResponse($data, $code)
{
$rawHeaders = array();
$rawContent = null;
$lines = preg_split('/(\\r?\\n)/', $data, -1, PREG_SPLIT_DELIM_CAPTURE);
for ($i = 0, $count = count($lines); $i < $count; $i += 2) {
$line = $lines[$i];
if (!empty($line)) {
$rawHeaders[] = $line;
} else {
$rawContent = implode('', array_slice($lines, $i + 2));
break;
}
}
$headers = $this->prepareHeaders($rawHeaders);
return new Response($rawContent, $code, $headers);
} | [
"protected",
"function",
"prepareResponse",
"(",
"$",
"data",
",",
"$",
"code",
")",
"{",
"$",
"rawHeaders",
"=",
"array",
"(",
")",
";",
"$",
"rawContent",
"=",
"null",
";",
"$",
"lines",
"=",
"preg_split",
"(",
"'/(\\\\r?\\\\n)/'",
",",
"$",
"data",
... | Generate the response object out of the raw response
@param string $data Raw response
@param int $code HTTP status code
@return \apiTalk\Response The response object | [
"Generate",
"the",
"response",
"object",
"out",
"of",
"the",
"raw",
"response"
] | 3890530728258d0b11e26bcef46e06abd497aa56 | https://github.com/CEikermann/apiTalk/blob/3890530728258d0b11e26bcef46e06abd497aa56/src/apiTalk/Adapter/Curl.php#L135-L155 | train |
CEikermann/apiTalk | src/apiTalk/Adapter/Curl.php | Curl.prepareHeaders | protected function prepareHeaders(array $rawHeaders)
{
$headers = array();
foreach ($rawHeaders as $rawHeader) {
if (strpos($rawHeader, ':')) {
$data = explode(':', $rawHeader);
$headers[$data[0]][] = trim($data[1]);
}
}
return $headers;
} | php | protected function prepareHeaders(array $rawHeaders)
{
$headers = array();
foreach ($rawHeaders as $rawHeader) {
if (strpos($rawHeader, ':')) {
$data = explode(':', $rawHeader);
$headers[$data[0]][] = trim($data[1]);
}
}
return $headers;
} | [
"protected",
"function",
"prepareHeaders",
"(",
"array",
"$",
"rawHeaders",
")",
"{",
"$",
"headers",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"rawHeaders",
"as",
"$",
"rawHeader",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"rawHeader",
",",
"':... | Returns the header as an associated array
@param array $rawHeaders
@return array | [
"Returns",
"the",
"header",
"as",
"an",
"associated",
"array"
] | 3890530728258d0b11e26bcef46e06abd497aa56 | https://github.com/CEikermann/apiTalk/blob/3890530728258d0b11e26bcef46e06abd497aa56/src/apiTalk/Adapter/Curl.php#L164-L176 | train |
supr-wcd/supr-finance | Core/Currency.php | Currency.valueOf | public static function valueOf($code = self::NONE)
{
if (self::isValidCode($code)) {
$details = self::getDetails($code);
$code = $details['code'];
$isoStatus = $details['isoStatus'];
$decimalDigits = $details['decimalDigits'];
$name = $details['name'];
return new Currency($code, $isoStatus, $decimalDigits, $name);
} else {
throw new \InvalidArgumentException('Unknown currency code \'' . $code . '\'.');
}
} | php | public static function valueOf($code = self::NONE)
{
if (self::isValidCode($code)) {
$details = self::getDetails($code);
$code = $details['code'];
$isoStatus = $details['isoStatus'];
$decimalDigits = $details['decimalDigits'];
$name = $details['name'];
return new Currency($code, $isoStatus, $decimalDigits, $name);
} else {
throw new \InvalidArgumentException('Unknown currency code \'' . $code . '\'.');
}
} | [
"public",
"static",
"function",
"valueOf",
"(",
"$",
"code",
"=",
"self",
"::",
"NONE",
")",
"{",
"if",
"(",
"self",
"::",
"isValidCode",
"(",
"$",
"code",
")",
")",
"{",
"$",
"details",
"=",
"self",
"::",
"getDetails",
"(",
"$",
"code",
")",
";",
... | Creates a new instance for the given code.
@param string $code the three-letter currency code
@return Currency
@throws \InvalidArgumentException if the code is unknown | [
"Creates",
"a",
"new",
"instance",
"for",
"the",
"given",
"code",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Currency.php#L79-L92 | train |
supr-wcd/supr-finance | Core/Currency.php | Currency.isValidCode | public static function isValidCode($code)
{
if (array_key_exists($code, self::getInfoForCurrencies())) {
return true;
} elseif (array_key_exists($code, self::getInfoForCurrenciesWithoutCurrencyCode())) {
return true;
} elseif (array_key_exists($code, self::getInfoForCurrenciesWithUnofficialCode())) {
return true;
} elseif (array_key_exists($code, self::getInfoForCurrenciesWithHistoricalCode())) {
return true;
} else {
return false;
}
} | php | public static function isValidCode($code)
{
if (array_key_exists($code, self::getInfoForCurrencies())) {
return true;
} elseif (array_key_exists($code, self::getInfoForCurrenciesWithoutCurrencyCode())) {
return true;
} elseif (array_key_exists($code, self::getInfoForCurrenciesWithUnofficialCode())) {
return true;
} elseif (array_key_exists($code, self::getInfoForCurrenciesWithHistoricalCode())) {
return true;
} else {
return false;
}
} | [
"public",
"static",
"function",
"isValidCode",
"(",
"$",
"code",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"code",
",",
"self",
"::",
"getInfoForCurrencies",
"(",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"array_key_exists",
... | Is the given code valid?
@param string $code the three-letter currency code
@return boolean | [
"Is",
"the",
"given",
"code",
"valid?"
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Currency.php#L101-L114 | train |
supr-wcd/supr-finance | Core/Currency.php | Currency.getDetails | public static function getDetails($code)
{
$infos = self::getInfoForCurrencies();
if (array_key_exists($code, $infos)) {
return $infos[$code];
}
$infos = self::getInfoForCurrenciesWithoutCurrencyCode();
if (array_key_exists($code, $infos)) {
return $infos[$code];
}
$infos = self::getInfoForCurrenciesWithUnofficialCode();
if (array_key_exists($code, $infos)) {
return $infos[$code];
}
$infos = self::getInfoForCurrenciesWithHistoricalCode();
if (array_key_exists($code, $infos)) {
return $infos[$code];
}
throw new \InvalidArgumentException('Unknown \$code: ' . $code);
} | php | public static function getDetails($code)
{
$infos = self::getInfoForCurrencies();
if (array_key_exists($code, $infos)) {
return $infos[$code];
}
$infos = self::getInfoForCurrenciesWithoutCurrencyCode();
if (array_key_exists($code, $infos)) {
return $infos[$code];
}
$infos = self::getInfoForCurrenciesWithUnofficialCode();
if (array_key_exists($code, $infos)) {
return $infos[$code];
}
$infos = self::getInfoForCurrenciesWithHistoricalCode();
if (array_key_exists($code, $infos)) {
return $infos[$code];
}
throw new \InvalidArgumentException('Unknown \$code: ' . $code);
} | [
"public",
"static",
"function",
"getDetails",
"(",
"$",
"code",
")",
"{",
"$",
"infos",
"=",
"self",
"::",
"getInfoForCurrencies",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"code",
",",
"$",
"infos",
")",
")",
"{",
"return",
"$",
"infos",... | Get details about a given ISO Currency.
@param string $code the three-letter currency code
@return array info about ISO Currency
@throws \InvalidArgumentException if currency code is unknown | [
"Get",
"details",
"about",
"a",
"given",
"ISO",
"Currency",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Currency.php#L125-L144 | train |
supr-wcd/supr-finance | Core/Currency.php | Currency.getInfoForCurrenciesWithoutCurrencyCode | public static function getInfoForCurrenciesWithoutCurrencyCode()
{
return array(
self::WITHOUT_CURRENCY_CODE_GGP => array(
'code' => self::WITHOUT_CURRENCY_CODE_GGP,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Guernsey pound',
),
self::WITHOUT_CURRENCY_CODE_JEP => array(
'code' => self::WITHOUT_CURRENCY_CODE_JEP,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Jersey pound',
),
self::WITHOUT_CURRENCY_CODE_IMP => array(
'code' => self::WITHOUT_CURRENCY_CODE_IMP,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Isle of Man pound also Manx pound',
),
self::WITHOUT_CURRENCY_CODE_KRI => array(
'code' => self::WITHOUT_CURRENCY_CODE_KRI,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Kiribati dollar',
),
self::WITHOUT_CURRENCY_CODE_SLS => array(
'code' => self::WITHOUT_CURRENCY_CODE_SLS,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Somaliland shilling',
),
self::WITHOUT_CURRENCY_CODE_PRB => array(
'code' => self::WITHOUT_CURRENCY_CODE_PRB,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Transnistrian ruble',
),
self::WITHOUT_CURRENCY_CODE_TVD => array(
'code' => self::WITHOUT_CURRENCY_CODE_TVD,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Tuvalu dollar',
)
);
} | php | public static function getInfoForCurrenciesWithoutCurrencyCode()
{
return array(
self::WITHOUT_CURRENCY_CODE_GGP => array(
'code' => self::WITHOUT_CURRENCY_CODE_GGP,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Guernsey pound',
),
self::WITHOUT_CURRENCY_CODE_JEP => array(
'code' => self::WITHOUT_CURRENCY_CODE_JEP,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Jersey pound',
),
self::WITHOUT_CURRENCY_CODE_IMP => array(
'code' => self::WITHOUT_CURRENCY_CODE_IMP,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Isle of Man pound also Manx pound',
),
self::WITHOUT_CURRENCY_CODE_KRI => array(
'code' => self::WITHOUT_CURRENCY_CODE_KRI,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Kiribati dollar',
),
self::WITHOUT_CURRENCY_CODE_SLS => array(
'code' => self::WITHOUT_CURRENCY_CODE_SLS,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Somaliland shilling',
),
self::WITHOUT_CURRENCY_CODE_PRB => array(
'code' => self::WITHOUT_CURRENCY_CODE_PRB,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Transnistrian ruble',
),
self::WITHOUT_CURRENCY_CODE_TVD => array(
'code' => self::WITHOUT_CURRENCY_CODE_TVD,
'isoStatus' => self::ISO_STATUS_WITHOUT_CURRENCY_CODE,
'decimalDigits' => 2,
'name' => 'Tuvalu dollar',
)
);
} | [
"public",
"static",
"function",
"getInfoForCurrenciesWithoutCurrencyCode",
"(",
")",
"{",
"return",
"array",
"(",
"self",
"::",
"WITHOUT_CURRENCY_CODE_GGP",
"=>",
"array",
"(",
"'code'",
"=>",
"self",
"::",
"WITHOUT_CURRENCY_CODE_GGP",
",",
"'isoStatus'",
"=>",
"self"... | Get details about all Currencies without ISO Code.
@return array info about Currencies without ISO Code | [
"Get",
"details",
"about",
"all",
"Currencies",
"without",
"ISO",
"Code",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Currency.php#L2745-L2791 | train |
supr-wcd/supr-finance | Core/Money.php | Money.round | public function round($decimalDigits = null, $mode = self::ROUND_HALF_AWAY_FROM_ZERO)
{
if (null === $decimalDigits) {
$decimalDigits = $this->currency->getDecimalDigits();
}
$factor = bcpow('10', $decimalDigits, self::BCSCALE);
$amount = bcmul($this->amount, $factor, self::BCSCALE);
switch ($mode) {
case self::ROUND_UP:
$result = self::roundUp($amount);
break;
case self::ROUND_DOWN:
$result = self::roundDown($amount);
break;
case self::ROUND_TOWARDS_ZERO:
$result = self::roundTowardsZero($amount);
break;
case self::ROUND_AWAY_FROM_ZERO:
$result = self::roundAwayFromZero($amount);
break;
case self::ROUND_HALF_UP:
$result = self::roundHalfUp($amount);
break;
case self::ROUND_HALF_DOWN:
$result = self::roundHalfDown($amount);
break;
case self::ROUND_HALF_TOWARDS_ZERO:
$result = self::roundHalfTowardsZero($amount);
break;
case self::ROUND_HALF_AWAY_FROM_ZERO:
$result = self::roundHalfAwayFromZero($amount);
break;
case self::ROUND_HALF_TO_EVEN:
$result = self::roundHalfToEven($amount);
break;
case self::ROUND_HALF_TO_ODD:
$result = self::roundHalfToOdd($amount);
break;
default:
throw new \InvalidArgumentException('Unknown rounding mode \''.$mode.'\'');
}
$result = bcdiv($result, $factor, self::BCSCALE);
return self::valueOf($result, $this->currency);
} | php | public function round($decimalDigits = null, $mode = self::ROUND_HALF_AWAY_FROM_ZERO)
{
if (null === $decimalDigits) {
$decimalDigits = $this->currency->getDecimalDigits();
}
$factor = bcpow('10', $decimalDigits, self::BCSCALE);
$amount = bcmul($this->amount, $factor, self::BCSCALE);
switch ($mode) {
case self::ROUND_UP:
$result = self::roundUp($amount);
break;
case self::ROUND_DOWN:
$result = self::roundDown($amount);
break;
case self::ROUND_TOWARDS_ZERO:
$result = self::roundTowardsZero($amount);
break;
case self::ROUND_AWAY_FROM_ZERO:
$result = self::roundAwayFromZero($amount);
break;
case self::ROUND_HALF_UP:
$result = self::roundHalfUp($amount);
break;
case self::ROUND_HALF_DOWN:
$result = self::roundHalfDown($amount);
break;
case self::ROUND_HALF_TOWARDS_ZERO:
$result = self::roundHalfTowardsZero($amount);
break;
case self::ROUND_HALF_AWAY_FROM_ZERO:
$result = self::roundHalfAwayFromZero($amount);
break;
case self::ROUND_HALF_TO_EVEN:
$result = self::roundHalfToEven($amount);
break;
case self::ROUND_HALF_TO_ODD:
$result = self::roundHalfToOdd($amount);
break;
default:
throw new \InvalidArgumentException('Unknown rounding mode \''.$mode.'\'');
}
$result = bcdiv($result, $factor, self::BCSCALE);
return self::valueOf($result, $this->currency);
} | [
"public",
"function",
"round",
"(",
"$",
"decimalDigits",
"=",
"null",
",",
"$",
"mode",
"=",
"self",
"::",
"ROUND_HALF_AWAY_FROM_ZERO",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"decimalDigits",
")",
"{",
"$",
"decimalDigits",
"=",
"$",
"this",
"->",
"cu... | Round to a given number of decimal digits, using a given mode.
@param int $decimalDigits the digits to truncate to, null for currency default
@param string $mode the rounding mode to use, see class constants
@return Money | [
"Round",
"to",
"a",
"given",
"number",
"of",
"decimal",
"digits",
"using",
"a",
"given",
"mode",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L298-L345 | train |
supr-wcd/supr-finance | Core/Money.php | Money.discardDecimalDigitsZero | private static function discardDecimalDigitsZero($amount, $minimumDecimalDigits = 0)
{
if (false !== strpos($amount, '.')) {
while ('0' == substr($amount, -1)) {
$amount = substr($amount, 0, -1);
}
if ('.' == substr($amount, -1)) {
$amount = substr($amount, 0, -1);
}
}
if ($minimumDecimalDigits > 0) {
if (false === strpos($amount, '.')) {
$amount .= '.';
}
$currentDecimalDigits = strlen(substr($amount, strpos($amount, '.') + 1));
$minimumDecimalDigits -= $currentDecimalDigits;
while ($minimumDecimalDigits > 0) {
$amount .= '0';
$minimumDecimalDigits--;
}
}
return $amount;
} | php | private static function discardDecimalDigitsZero($amount, $minimumDecimalDigits = 0)
{
if (false !== strpos($amount, '.')) {
while ('0' == substr($amount, -1)) {
$amount = substr($amount, 0, -1);
}
if ('.' == substr($amount, -1)) {
$amount = substr($amount, 0, -1);
}
}
if ($minimumDecimalDigits > 0) {
if (false === strpos($amount, '.')) {
$amount .= '.';
}
$currentDecimalDigits = strlen(substr($amount, strpos($amount, '.') + 1));
$minimumDecimalDigits -= $currentDecimalDigits;
while ($minimumDecimalDigits > 0) {
$amount .= '0';
$minimumDecimalDigits--;
}
}
return $amount;
} | [
"private",
"static",
"function",
"discardDecimalDigitsZero",
"(",
"$",
"amount",
",",
"$",
"minimumDecimalDigits",
"=",
"0",
")",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"amount",
",",
"'.'",
")",
")",
"{",
"while",
"(",
"'0'",
"==",
"substr"... | Remove trailing zeros up to and including the decimal point.
@param string $amount the amount to process
@param int $minimumDecimalDigits the number of decimal digits that has to remain under all circumstances
@return string | [
"Remove",
"trailing",
"zeros",
"up",
"to",
"and",
"including",
"the",
"decimal",
"point",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L355-L382 | train |
supr-wcd/supr-finance | Core/Money.php | Money.roundToNearestIntegerIgnoringTies | private static function roundToNearestIntegerIgnoringTies($amount)
{
$relevantDigit = substr(self::roundTowardsZero(bcmul($amount, '10', self::BCSCALE)), -1);
$result = null;
switch ($relevantDigit) {
case '0':
case '1':
case '2':
case '3':
case '4':
$result = self::roundTowardsZero($amount);
break;
case '5':
$result = null; // handled by tie-breaking rules
break;
case '6':
case '7':
case '8':
case '9':
$result = self::roundAwayFromZero($amount);
break;
}
return $result;
} | php | private static function roundToNearestIntegerIgnoringTies($amount)
{
$relevantDigit = substr(self::roundTowardsZero(bcmul($amount, '10', self::BCSCALE)), -1);
$result = null;
switch ($relevantDigit) {
case '0':
case '1':
case '2':
case '3':
case '4':
$result = self::roundTowardsZero($amount);
break;
case '5':
$result = null; // handled by tie-breaking rules
break;
case '6':
case '7':
case '8':
case '9':
$result = self::roundAwayFromZero($amount);
break;
}
return $result;
} | [
"private",
"static",
"function",
"roundToNearestIntegerIgnoringTies",
"(",
"$",
"amount",
")",
"{",
"$",
"relevantDigit",
"=",
"substr",
"(",
"self",
"::",
"roundTowardsZero",
"(",
"bcmul",
"(",
"$",
"amount",
",",
"'10'",
",",
"self",
"::",
"BCSCALE",
")",
... | Round towards the nearest integer, but return null if there's a tie, so specialized methods can break it
differently.
@param string $amount the amount to round
@return string|null | [
"Round",
"towards",
"the",
"nearest",
"integer",
"but",
"return",
"null",
"if",
"there",
"s",
"a",
"tie",
"so",
"specialized",
"methods",
"can",
"break",
"it",
"differently",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L470-L496 | train |
supr-wcd/supr-finance | Core/Money.php | Money.roundHalfUp | private static function roundHalfUp($amount)
{
$result = self::roundToNearestIntegerIgnoringTies($amount);
if (null == $result) {
$result = self::roundToNearestIntegerIgnoringTies(bcadd($amount, '0.1', self::BCSCALE));
}
return $result;
} | php | private static function roundHalfUp($amount)
{
$result = self::roundToNearestIntegerIgnoringTies($amount);
if (null == $result) {
$result = self::roundToNearestIntegerIgnoringTies(bcadd($amount, '0.1', self::BCSCALE));
}
return $result;
} | [
"private",
"static",
"function",
"roundHalfUp",
"(",
"$",
"amount",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"roundToNearestIntegerIgnoringTies",
"(",
"$",
"amount",
")",
";",
"if",
"(",
"null",
"==",
"$",
"result",
")",
"{",
"$",
"result",
"=",
"self... | If the fraction of the amount is exactly 0.5, then return the amount + 0.5.
@param string $amount the amount to round
@return string | [
"If",
"the",
"fraction",
"of",
"the",
"amount",
"is",
"exactly",
"0",
".",
"5",
"then",
"return",
"the",
"amount",
"+",
"0",
".",
"5",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L505-L514 | train |
supr-wcd/supr-finance | Core/Money.php | Money.roundHalfDown | private static function roundHalfDown($amount)
{
$result = self::roundToNearestIntegerIgnoringTies($amount);
if (null == $result) {
$result = self::roundToNearestIntegerIgnoringTies(bcsub($amount, '0.1', self::BCSCALE));
}
return $result;
} | php | private static function roundHalfDown($amount)
{
$result = self::roundToNearestIntegerIgnoringTies($amount);
if (null == $result) {
$result = self::roundToNearestIntegerIgnoringTies(bcsub($amount, '0.1', self::BCSCALE));
}
return $result;
} | [
"private",
"static",
"function",
"roundHalfDown",
"(",
"$",
"amount",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"roundToNearestIntegerIgnoringTies",
"(",
"$",
"amount",
")",
";",
"if",
"(",
"null",
"==",
"$",
"result",
")",
"{",
"$",
"result",
"=",
"se... | If the fraction of the amount is exactly 0.5, then return the amount - 0.5.
@param string $amount the amount to round
@return string | [
"If",
"the",
"fraction",
"of",
"the",
"amount",
"is",
"exactly",
"0",
".",
"5",
"then",
"return",
"the",
"amount",
"-",
"0",
".",
"5",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L523-L532 | train |
supr-wcd/supr-finance | Core/Money.php | Money.roundHalfTowardsZero | private static function roundHalfTowardsZero($amount)
{
if (0 <= bccomp($amount, '0', self::BCSCALE)) {
$result = self::roundHalfDown($amount);
} else {
$result = self::roundHalfUp($amount);
}
return $result;
} | php | private static function roundHalfTowardsZero($amount)
{
if (0 <= bccomp($amount, '0', self::BCSCALE)) {
$result = self::roundHalfDown($amount);
} else {
$result = self::roundHalfUp($amount);
}
return $result;
} | [
"private",
"static",
"function",
"roundHalfTowardsZero",
"(",
"$",
"amount",
")",
"{",
"if",
"(",
"0",
"<=",
"bccomp",
"(",
"$",
"amount",
",",
"'0'",
",",
"self",
"::",
"BCSCALE",
")",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"roundHalfDown",
"(",
... | If the fraction of the amount is exactly 0.5, then return the amount - 0.5 if the amount is positive, and return
the amount + 0.5 if the amount is negative.
@param string $amount the amount to round
@return string | [
"If",
"the",
"fraction",
"of",
"the",
"amount",
"is",
"exactly",
"0",
".",
"5",
"then",
"return",
"the",
"amount",
"-",
"0",
".",
"5",
"if",
"the",
"amount",
"is",
"positive",
"and",
"return",
"the",
"amount",
"+",
"0",
".",
"5",
"if",
"the",
"amou... | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L542-L551 | train |
supr-wcd/supr-finance | Core/Money.php | Money.roundHalfAwayFromZero | private static function roundHalfAwayFromZero($amount)
{
if (0 <= bccomp($amount, '0', self::BCSCALE)) {
$result = self::roundHalfUp($amount);
} else {
$result = self::roundHalfDown($amount);
}
return $result;
} | php | private static function roundHalfAwayFromZero($amount)
{
if (0 <= bccomp($amount, '0', self::BCSCALE)) {
$result = self::roundHalfUp($amount);
} else {
$result = self::roundHalfDown($amount);
}
return $result;
} | [
"private",
"static",
"function",
"roundHalfAwayFromZero",
"(",
"$",
"amount",
")",
"{",
"if",
"(",
"0",
"<=",
"bccomp",
"(",
"$",
"amount",
",",
"'0'",
",",
"self",
"::",
"BCSCALE",
")",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"roundHalfUp",
"(",
... | If the fraction of the amount is exactly 0.5, then return the amount + 0.5 if the amount is positive, and return
the amount - 0.5 if the amount is negative.
@param string $amount the amount to round
@return string | [
"If",
"the",
"fraction",
"of",
"the",
"amount",
"is",
"exactly",
"0",
".",
"5",
"then",
"return",
"the",
"amount",
"+",
"0",
".",
"5",
"if",
"the",
"amount",
"is",
"positive",
"and",
"return",
"the",
"amount",
"-",
"0",
".",
"5",
"if",
"the",
"amou... | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L561-L570 | train |
supr-wcd/supr-finance | Core/Money.php | Money.roundHalfToEven | private static function roundHalfToEven($amount)
{
$result = self::roundToNearestIntegerIgnoringTies($amount);
if (null == $result) {
$truncated = self::roundHalfTowardsZero($amount);
if (0 == bcmod($truncated, '2')) { // Even
$result = $truncated;
} else {
$result = self::roundHalfAwayFromZero($amount);
}
}
return $result;
} | php | private static function roundHalfToEven($amount)
{
$result = self::roundToNearestIntegerIgnoringTies($amount);
if (null == $result) {
$truncated = self::roundHalfTowardsZero($amount);
if (0 == bcmod($truncated, '2')) { // Even
$result = $truncated;
} else {
$result = self::roundHalfAwayFromZero($amount);
}
}
return $result;
} | [
"private",
"static",
"function",
"roundHalfToEven",
"(",
"$",
"amount",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"roundToNearestIntegerIgnoringTies",
"(",
"$",
"amount",
")",
";",
"if",
"(",
"null",
"==",
"$",
"result",
")",
"{",
"$",
"truncated",
"=",
... | If the fraction of the amount is 0.5, then return the even integer nearest to the amount.
@param string $amount the amount to round
@return string | [
"If",
"the",
"fraction",
"of",
"the",
"amount",
"is",
"0",
".",
"5",
"then",
"return",
"the",
"even",
"integer",
"nearest",
"to",
"the",
"amount",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L579-L594 | train |
supr-wcd/supr-finance | Core/Money.php | Money.zero | public static function zero(Currency $currency = null)
{
if (null === $currency) {
$currency = Currency::valueOf(Currency::NONE);
}
return self::valueOf('0', $currency);
} | php | public static function zero(Currency $currency = null)
{
if (null === $currency) {
$currency = Currency::valueOf(Currency::NONE);
}
return self::valueOf('0', $currency);
} | [
"public",
"static",
"function",
"zero",
"(",
"Currency",
"$",
"currency",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"currency",
")",
"{",
"$",
"currency",
"=",
"Currency",
"::",
"valueOf",
"(",
"Currency",
"::",
"NONE",
")",
";",
"}",
"re... | Creates a new instance with zero amount and Currency None or optional.
@param Currency $currency an optional currency to use
@return Money | [
"Creates",
"a",
"new",
"instance",
"with",
"zero",
"amount",
"and",
"Currency",
"None",
"or",
"optional",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L640-L647 | train |
supr-wcd/supr-finance | Core/Money.php | Money.noCurrency | public static function noCurrency($amount = null)
{
if (null === $amount) {
$amount = '0';
}
return self::valueOf(strval($amount), Currency::valueOf(Currency::NONE));
} | php | public static function noCurrency($amount = null)
{
if (null === $amount) {
$amount = '0';
}
return self::valueOf(strval($amount), Currency::valueOf(Currency::NONE));
} | [
"public",
"static",
"function",
"noCurrency",
"(",
"$",
"amount",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"amount",
")",
"{",
"$",
"amount",
"=",
"'0'",
";",
"}",
"return",
"self",
"::",
"valueOf",
"(",
"strval",
"(",
"$",
"amount",
"... | Creates a new instance with amount zero or optional and Currency None.
@param string $amount an optional amount to use
@return Money | [
"Creates",
"a",
"new",
"instance",
"with",
"amount",
"zero",
"or",
"optional",
"and",
"Currency",
"None",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L656-L663 | train |
supr-wcd/supr-finance | Core/Money.php | Money.compare | public function compare(Money $money)
{
return bccomp($this->amount, $money->getAmount(), self::BCSCALE);
} | php | public function compare(Money $money)
{
return bccomp($this->amount, $money->getAmount(), self::BCSCALE);
} | [
"public",
"function",
"compare",
"(",
"Money",
"$",
"money",
")",
"{",
"return",
"bccomp",
"(",
"$",
"this",
"->",
"amount",
",",
"$",
"money",
"->",
"getAmount",
"(",
")",
",",
"self",
"::",
"BCSCALE",
")",
";",
"}"
] | Compares this moneys amount with the given ones and returns 0 if they are equal, 1 if this amount is larger than
the given ones, -1 otherwise. This method explicitly disregards the Currency!
@param Money $money the money to compare with
@return integer | [
"Compares",
"this",
"moneys",
"amount",
"with",
"the",
"given",
"ones",
"and",
"returns",
"0",
"if",
"they",
"are",
"equal",
"1",
"if",
"this",
"amount",
"is",
"larger",
"than",
"the",
"given",
"ones",
"-",
"1",
"otherwise",
".",
"This",
"method",
"expli... | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L766-L769 | train |
supr-wcd/supr-finance | Core/Money.php | Money.equals | public function equals(Money $money)
{
if (!$this->currency->equals($money->getCurrency())) {
return false;
}
return (0 == $this->compare($money));
} | php | public function equals(Money $money)
{
if (!$this->currency->equals($money->getCurrency())) {
return false;
}
return (0 == $this->compare($money));
} | [
"public",
"function",
"equals",
"(",
"Money",
"$",
"money",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"currency",
"->",
"equals",
"(",
"$",
"money",
"->",
"getCurrency",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"0",
... | Are these to money equal?
@param Money $money the money to camplare with
@return boolean true if both amounts and currency are equal, false otherwise | [
"Are",
"these",
"to",
"money",
"equal?"
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L798-L805 | train |
supr-wcd/supr-finance | Core/Money.php | Money.modulus | public function modulus($modulus)
{
if (!is_numeric($modulus)) {
throw new \InvalidArgumentException('Modulus must be numeric');
}
$amount = bcmod($this->amount, strval($modulus));
return self::valueOf($amount, $this->currency);
} | php | public function modulus($modulus)
{
if (!is_numeric($modulus)) {
throw new \InvalidArgumentException('Modulus must be numeric');
}
$amount = bcmod($this->amount, strval($modulus));
return self::valueOf($amount, $this->currency);
} | [
"public",
"function",
"modulus",
"(",
"$",
"modulus",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"modulus",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Modulus must be numeric'",
")",
";",
"}",
"$",
"amount",
"=",
"bcmod"... | Calculates the modulus of this money.
@param mixed $modulus the modulus to apply
@return Money
@throws \InvalidArgumentException if the $modulus is not numeric | [
"Calculates",
"the",
"modulus",
"of",
"this",
"money",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L816-L825 | train |
supr-wcd/supr-finance | Core/Money.php | Money.squareRoot | public function squareRoot()
{
$amount = bcsqrt($this->amount, self::BCSCALE);
return self::valueOf($amount, $this->currency);
} | php | public function squareRoot()
{
$amount = bcsqrt($this->amount, self::BCSCALE);
return self::valueOf($amount, $this->currency);
} | [
"public",
"function",
"squareRoot",
"(",
")",
"{",
"$",
"amount",
"=",
"bcsqrt",
"(",
"$",
"this",
"->",
"amount",
",",
"self",
"::",
"BCSCALE",
")",
";",
"return",
"self",
"::",
"valueOf",
"(",
"$",
"amount",
",",
"$",
"this",
"->",
"currency",
")",... | Calculates the square root of this money.
@return Money | [
"Calculates",
"the",
"square",
"root",
"of",
"this",
"money",
"."
] | a424e72f3c3bcfb252a0a65100d78a6374de250c | https://github.com/supr-wcd/supr-finance/blob/a424e72f3c3bcfb252a0a65100d78a6374de250c/Core/Money.php#L900-L905 | train |
eloquent/composer-config-reader | src/Element/Configuration.php | Configuration.projectName | public function projectName()
{
$name = $this->name();
if (null === $name) {
return null;
}
$atoms = explode(static::NAME_SEPARATOR, $name);
return array_pop($atoms);
} | php | public function projectName()
{
$name = $this->name();
if (null === $name) {
return null;
}
$atoms = explode(static::NAME_SEPARATOR, $name);
return array_pop($atoms);
} | [
"public",
"function",
"projectName",
"(",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"name",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"name",
")",
"{",
"return",
"null",
";",
"}",
"$",
"atoms",
"=",
"explode",
"(",
"static",
"::",
"NAME_... | Get the project name, without the vendor prefix.
@return string|null The project name. | [
"Get",
"the",
"project",
"name",
"without",
"the",
"vendor",
"prefix",
"."
] | ee83a1cad8f68508f05b30c376003045a7cdfcd8 | https://github.com/eloquent/composer-config-reader/blob/ee83a1cad8f68508f05b30c376003045a7cdfcd8/src/Element/Configuration.php#L213-L223 | train |
eloquent/composer-config-reader | src/Element/Configuration.php | Configuration.vendorName | public function vendorName()
{
$name = $this->name();
if (null === $name) {
return null;
}
$atoms = explode(static::NAME_SEPARATOR, $name);
array_pop($atoms);
if (count($atoms) < 1) {
return null;
}
return implode(static::NAME_SEPARATOR, $atoms);
} | php | public function vendorName()
{
$name = $this->name();
if (null === $name) {
return null;
}
$atoms = explode(static::NAME_SEPARATOR, $name);
array_pop($atoms);
if (count($atoms) < 1) {
return null;
}
return implode(static::NAME_SEPARATOR, $atoms);
} | [
"public",
"function",
"vendorName",
"(",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"name",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"name",
")",
"{",
"return",
"null",
";",
"}",
"$",
"atoms",
"=",
"explode",
"(",
"static",
"::",
"NAME_S... | Get the vendor name, without the project suffix.
@return string|null The vendor name. | [
"Get",
"the",
"vendor",
"name",
"without",
"the",
"project",
"suffix",
"."
] | ee83a1cad8f68508f05b30c376003045a7cdfcd8 | https://github.com/eloquent/composer-config-reader/blob/ee83a1cad8f68508f05b30c376003045a7cdfcd8/src/Element/Configuration.php#L230-L244 | train |
eloquent/composer-config-reader | src/Element/Configuration.php | Configuration.allPsr4SourcePaths | public function allPsr4SourcePaths()
{
$autoloadPsr4Paths = array();
foreach ($this->autoloadPsr4() as $namespace => $paths) {
$autoloadPsr4Paths = array_merge($autoloadPsr4Paths, $paths);
}
return $autoloadPsr4Paths;
} | php | public function allPsr4SourcePaths()
{
$autoloadPsr4Paths = array();
foreach ($this->autoloadPsr4() as $namespace => $paths) {
$autoloadPsr4Paths = array_merge($autoloadPsr4Paths, $paths);
}
return $autoloadPsr4Paths;
} | [
"public",
"function",
"allPsr4SourcePaths",
"(",
")",
"{",
"$",
"autoloadPsr4Paths",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"autoloadPsr4",
"(",
")",
"as",
"$",
"namespace",
"=>",
"$",
"paths",
")",
"{",
"$",
"autoloadPsr4Paths",
... | Get an array of all source paths containing PSR-4 conformant code.
@return array<integer,string> The PSR-4 source paths. | [
"Get",
"an",
"array",
"of",
"all",
"source",
"paths",
"containing",
"PSR",
"-",
"4",
"conformant",
"code",
"."
] | ee83a1cad8f68508f05b30c376003045a7cdfcd8 | https://github.com/eloquent/composer-config-reader/blob/ee83a1cad8f68508f05b30c376003045a7cdfcd8/src/Element/Configuration.php#L465-L473 | train |
eloquent/composer-config-reader | src/Element/Configuration.php | Configuration.allPsr0SourcePaths | public function allPsr0SourcePaths()
{
$autoloadPsr0Paths = array();
foreach ($this->autoloadPsr0() as $namespace => $paths) {
$autoloadPsr0Paths = array_merge($autoloadPsr0Paths, $paths);
}
return $autoloadPsr0Paths;
} | php | public function allPsr0SourcePaths()
{
$autoloadPsr0Paths = array();
foreach ($this->autoloadPsr0() as $namespace => $paths) {
$autoloadPsr0Paths = array_merge($autoloadPsr0Paths, $paths);
}
return $autoloadPsr0Paths;
} | [
"public",
"function",
"allPsr0SourcePaths",
"(",
")",
"{",
"$",
"autoloadPsr0Paths",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"autoloadPsr0",
"(",
")",
"as",
"$",
"namespace",
"=>",
"$",
"paths",
")",
"{",
"$",
"autoloadPsr0Paths",
... | Get an array of all source paths containing PSR-0 conformant code.
@return array<integer,string> The PSR-0 source paths. | [
"Get",
"an",
"array",
"of",
"all",
"source",
"paths",
"containing",
"PSR",
"-",
"0",
"conformant",
"code",
"."
] | ee83a1cad8f68508f05b30c376003045a7cdfcd8 | https://github.com/eloquent/composer-config-reader/blob/ee83a1cad8f68508f05b30c376003045a7cdfcd8/src/Element/Configuration.php#L480-L488 | train |
eloquent/composer-config-reader | src/Element/Configuration.php | Configuration.allSourcePaths | public function allSourcePaths()
{
return array_merge(
$this->allPsr4SourcePaths(),
$this->allPsr0SourcePaths(),
$this->autoloadClassmap(),
$this->autoloadFiles(),
$this->includePath()
);
} | php | public function allSourcePaths()
{
return array_merge(
$this->allPsr4SourcePaths(),
$this->allPsr0SourcePaths(),
$this->autoloadClassmap(),
$this->autoloadFiles(),
$this->includePath()
);
} | [
"public",
"function",
"allSourcePaths",
"(",
")",
"{",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"allPsr4SourcePaths",
"(",
")",
",",
"$",
"this",
"->",
"allPsr0SourcePaths",
"(",
")",
",",
"$",
"this",
"->",
"autoloadClassmap",
"(",
")",
",",
"$",
... | Get an array of all source paths for this package.
@return array<integer,string> All source paths. | [
"Get",
"an",
"array",
"of",
"all",
"source",
"paths",
"for",
"this",
"package",
"."
] | ee83a1cad8f68508f05b30c376003045a7cdfcd8 | https://github.com/eloquent/composer-config-reader/blob/ee83a1cad8f68508f05b30c376003045a7cdfcd8/src/Element/Configuration.php#L495-L504 | train |
TypiCMS/Settings | src/Repositories/EloquentSetting.php | EloquentSetting.allToArray | public function allToArray()
{
$config = [];
try {
foreach ($this->findAll() as $object) {
$key = $object->key_name;
if ($object->group_name != 'config') {
$config[$object->group_name][$key] = $object->value;
} else {
$config[$key] = $object->value;
}
}
} catch (Exception $e) {
Log::error($e->getMessage());
}
return $config;
} | php | public function allToArray()
{
$config = [];
try {
foreach ($this->findAll() as $object) {
$key = $object->key_name;
if ($object->group_name != 'config') {
$config[$object->group_name][$key] = $object->value;
} else {
$config[$key] = $object->value;
}
}
} catch (Exception $e) {
Log::error($e->getMessage());
}
return $config;
} | [
"public",
"function",
"allToArray",
"(",
")",
"{",
"$",
"config",
"=",
"[",
"]",
";",
"try",
"{",
"foreach",
"(",
"$",
"this",
"->",
"findAll",
"(",
")",
"as",
"$",
"object",
")",
"{",
"$",
"key",
"=",
"$",
"object",
"->",
"key_name",
";",
"if",
... | Build Settings Array.
@return array | [
"Build",
"Settings",
"Array",
"."
] | 106e8509df8281ca3f1bddc14812bae6610dac40 | https://github.com/TypiCMS/Settings/blob/106e8509df8281ca3f1bddc14812bae6610dac40/src/Repositories/EloquentSetting.php#L47-L65 | train |
ynloultratech/graphql-bundle | src/Behat/Context/DoctrineContext.php | DoctrineContext.theFollowingRecordsInTheRepository | public function theFollowingRecordsInTheRepository($entity, YamlStringNode $records)
{
$manager = $this->getDoctrine()->getManager();
$accessor = new PropertyAccessor();
foreach ($records->toArray() as $record) {
$instance = new $entity();
foreach ($record as $prop => $value) {
$accessor->setValue($instance, $prop, $value);
}
$manager->persist($instance);
}
$manager->flush();
} | php | public function theFollowingRecordsInTheRepository($entity, YamlStringNode $records)
{
$manager = $this->getDoctrine()->getManager();
$accessor = new PropertyAccessor();
foreach ($records->toArray() as $record) {
$instance = new $entity();
foreach ($record as $prop => $value) {
$accessor->setValue($instance, $prop, $value);
}
$manager->persist($instance);
}
$manager->flush();
} | [
"public",
"function",
"theFollowingRecordsInTheRepository",
"(",
"$",
"entity",
",",
"YamlStringNode",
"$",
"records",
")",
"{",
"$",
"manager",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"accessor",
"=",
"new",
... | Use a YAML syntax to populate a repository with multiple records
Example: Given the following records in the repository "App\Entity\Post"
"""
- title: "Welcome"
body: "Welcome to web page"
- title: "Another Post"
body: "This is another post"
"""
@Given /^the following records in the repository "([^"]*)"$/ | [
"Use",
"a",
"YAML",
"syntax",
"to",
"populate",
"a",
"repository",
"with",
"multiple",
"records"
] | 390aa1ca77cf00ae02688839ea4fca1026954501 | https://github.com/ynloultratech/graphql-bundle/blob/390aa1ca77cf00ae02688839ea4fca1026954501/src/Behat/Context/DoctrineContext.php#L49-L62 | train |
ynloultratech/graphql-bundle | src/Behat/Context/DoctrineContext.php | DoctrineContext.grabInFromRepositoryFirstRecordsOrderedByMatching | public function grabInFromRepositoryFirstRecordsOrderedByMatching($variable, $repo, $limitAndOffset = null, $orderBy = null, YamlStringNode $criteria = null)
{
//support to use "limit:offset"
if (strpos($limitAndOffset, ':') !== false) {
list($limit, $offset) = explode(':', $limitAndOffset);
} else {
$limit = $limitAndOffset;
$offset = null;
}
// support field:ORDER, eg. name:ASC
if (is_string($orderBy)) {
list($field, $order) = explode(':', $orderBy);
$orderBy = [$field => $order];
}
$records = $this->getDoctrine()
->getRepository($repo)
->findBy($criteria ? $criteria->toArray() : [], $orderBy, $limit, $offset);
$this->storage->setValue($variable, $records);
} | php | public function grabInFromRepositoryFirstRecordsOrderedByMatching($variable, $repo, $limitAndOffset = null, $orderBy = null, YamlStringNode $criteria = null)
{
//support to use "limit:offset"
if (strpos($limitAndOffset, ':') !== false) {
list($limit, $offset) = explode(':', $limitAndOffset);
} else {
$limit = $limitAndOffset;
$offset = null;
}
// support field:ORDER, eg. name:ASC
if (is_string($orderBy)) {
list($field, $order) = explode(':', $orderBy);
$orderBy = [$field => $order];
}
$records = $this->getDoctrine()
->getRepository($repo)
->findBy($criteria ? $criteria->toArray() : [], $orderBy, $limit, $offset);
$this->storage->setValue($variable, $records);
} | [
"public",
"function",
"grabInFromRepositoryFirstRecordsOrderedByMatching",
"(",
"$",
"variable",
",",
"$",
"repo",
",",
"$",
"limitAndOffset",
"=",
"null",
",",
"$",
"orderBy",
"=",
"null",
",",
"YamlStringNode",
"$",
"criteria",
"=",
"null",
")",
"{",
"//suppor... | Grab a set of records from database in a temp variable inside the `"storage"` in order to use latter in an expression
The prefix `"grab in"` is optional and can be used in "Then" for readability
<code>
Given "users" from ....
Then grab in "users" from ...
</code>
The suffix `"matching:"` is optional too and can be used to set array of conditions to match.
### Placeholders:
- **$variable:** `(string)` name of the variable to save in the storage
- **$entity:** `(string)` name of the entity using bundle notation `"AppBundle:Entity"` or FQN
- **$limitAndOffset:** `(int|string)` amount of records to fetch `"limit"` or use `"limit:offset"` to use pagination
- **$orderBy:** `(string|array)` string like `"title:ASC"` or array inside expression like `"{ [{status: 'DESC', title: 'ASC'}] }"`
- **$criteria:** `(yaml)` YAML node to convert to array of criteria
### Examples:
<code>
- Given "orderedUsers" from repository "AppBundle:User" first 5 records ordered by "username:ASC" matching:
"""
enabled: true
"""
- Given "orderedUsers" from repository "AppBundle:User" first 5 records ordered by "username:ASC"
- And "orderedUsersWithOffset" from repository "AppBundle:User" first "10:20" records ordered by "username:ASC"
- Then grab in "orderedPosts" from repository "AppBundle:Post" first 10 records ordered by "{ [{status: 'DESC', title: 'ASC'}] }"
</code>
and later can be used:
<code>
- And "{orderedUsers[0].getUsername()}" should be equal to "{response.data.users.all.edges[0].node.login}"
</code>
@Given /^(?:grab in )?"([^"]*)" from repository "([^"]*)" first "?([^"]*)"? records ordered by "([^"]*)"(?: matching:)?$/ | [
"Grab",
"a",
"set",
"of",
"records",
"from",
"database",
"in",
"a",
"temp",
"variable",
"inside",
"the",
"storage",
"in",
"order",
"to",
"use",
"latter",
"in",
"an",
"expression"
] | 390aa1ca77cf00ae02688839ea4fca1026954501 | https://github.com/ynloultratech/graphql-bundle/blob/390aa1ca77cf00ae02688839ea4fca1026954501/src/Behat/Context/DoctrineContext.php#L153-L171 | train |
PlasmaPHP/core | src/Client.php | Client.create | static function create(\Plasma\DriverFactoryInterface $factory, string $uri, array $options = array()): \Plasma\ClientInterface {
return (new static($factory, $uri, $options));
} | php | static function create(\Plasma\DriverFactoryInterface $factory, string $uri, array $options = array()): \Plasma\ClientInterface {
return (new static($factory, $uri, $options));
} | [
"static",
"function",
"create",
"(",
"\\",
"Plasma",
"\\",
"DriverFactoryInterface",
"$",
"factory",
",",
"string",
"$",
"uri",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
":",
"\\",
"Plasma",
"\\",
"ClientInterface",
"{",
"return",
"(",
"... | Creates a client with the specified factory and options.
@param \Plasma\DriverFactoryInterface $factory
@param string $uri
@param array $options
@return \Plasma\ClientInterface
@throws \Throwable The client implementation may throw any exception during this operation.
@see Client::__construct() | [
"Creates",
"a",
"client",
"with",
"the",
"specified",
"factory",
"and",
"options",
"."
] | ce9b1a206e3777f3cf884eec5eee686a073ddfb2 | https://github.com/PlasmaPHP/core/blob/ce9b1a206e3777f3cf884eec5eee686a073ddfb2/src/Client.php#L95-L97 | train |
PlasmaPHP/core | src/Client.php | Client.checkinConnection | function checkinConnection(\Plasma\DriverInterface $driver): void {
if($driver->getConnectionState() !== \Plasma\DriverInterface::CONNECTION_UNUSABLE && !$this->goingAway) {
$this->connections->add($driver);
$this->busyConnections->delete($driver);
}
} | php | function checkinConnection(\Plasma\DriverInterface $driver): void {
if($driver->getConnectionState() !== \Plasma\DriverInterface::CONNECTION_UNUSABLE && !$this->goingAway) {
$this->connections->add($driver);
$this->busyConnections->delete($driver);
}
} | [
"function",
"checkinConnection",
"(",
"\\",
"Plasma",
"\\",
"DriverInterface",
"$",
"driver",
")",
":",
"void",
"{",
"if",
"(",
"$",
"driver",
"->",
"getConnectionState",
"(",
")",
"!==",
"\\",
"Plasma",
"\\",
"DriverInterface",
"::",
"CONNECTION_UNUSABLE",
"&... | Checks a connection back in, if usable and not closing.
@param \Plasma\DriverInterface $driver
@return void | [
"Checks",
"a",
"connection",
"back",
"in",
"if",
"usable",
"and",
"not",
"closing",
"."
] | ce9b1a206e3777f3cf884eec5eee686a073ddfb2 | https://github.com/PlasmaPHP/core/blob/ce9b1a206e3777f3cf884eec5eee686a073ddfb2/src/Client.php#L112-L117 | train |
PlasmaPHP/core | src/Client.php | Client.beginTransaction | function beginTransaction(int $isolation = \Plasma\TransactionInterface::ISOLATION_COMMITTED): \React\Promise\PromiseInterface {
if($this->goingAway) {
return \React\Promise\reject((new \Plasma\Exception('Client is closing all connections')));
}
$connection = $this->getOptimalConnection();
return $connection->beginTransaction($this, $isolation)->then(null, function (\Throwable $error) use (&$connection) {
$this->checkinConnection($connection);
throw $error;
});
} | php | function beginTransaction(int $isolation = \Plasma\TransactionInterface::ISOLATION_COMMITTED): \React\Promise\PromiseInterface {
if($this->goingAway) {
return \React\Promise\reject((new \Plasma\Exception('Client is closing all connections')));
}
$connection = $this->getOptimalConnection();
return $connection->beginTransaction($this, $isolation)->then(null, function (\Throwable $error) use (&$connection) {
$this->checkinConnection($connection);
throw $error;
});
} | [
"function",
"beginTransaction",
"(",
"int",
"$",
"isolation",
"=",
"\\",
"Plasma",
"\\",
"TransactionInterface",
"::",
"ISOLATION_COMMITTED",
")",
":",
"\\",
"React",
"\\",
"Promise",
"\\",
"PromiseInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"goingAway",
")... | Begins a transaction. Resolves with a `Transaction` instance.
Checks out a connection until the transaction gets committed or rolled back. If the transaction goes out of scope
and thus deallocated, the `Transaction` must check the connection back into the client.
Some databases, including MySQL, automatically issue an implicit COMMIT when a database definition language (DDL)
statement such as DROP TABLE or CREATE TABLE is issued within a transaction.
The implicit COMMIT will prevent you from rolling back any other changes within the transaction boundary.
@param int $isolation See the `TransactionInterface` constants.
@return \React\Promise\PromiseInterface
@throws \Plasma\Exception
@see \Plasma\Transaction | [
"Begins",
"a",
"transaction",
".",
"Resolves",
"with",
"a",
"Transaction",
"instance",
"."
] | ce9b1a206e3777f3cf884eec5eee686a073ddfb2 | https://github.com/PlasmaPHP/core/blob/ce9b1a206e3777f3cf884eec5eee686a073ddfb2/src/Client.php#L133-L144 | train |
PlasmaPHP/core | src/Client.php | Client.execute | function execute(string $query, array $params = array()): \React\Promise\PromiseInterface {
if($this->goingAway) {
return \React\Promise\reject((new \Plasma\Exception('Client is closing all connections')));
}
$connection = $this->getOptimalConnection();
return $connection->execute($this, $query, $params)->then(function ($value) use (&$connection) {
$this->checkinConnection($connection);
return $value;
}, function (\Throwable $error) use (&$connection) {
$this->checkinConnection($connection);
throw $error;
});
} | php | function execute(string $query, array $params = array()): \React\Promise\PromiseInterface {
if($this->goingAway) {
return \React\Promise\reject((new \Plasma\Exception('Client is closing all connections')));
}
$connection = $this->getOptimalConnection();
return $connection->execute($this, $query, $params)->then(function ($value) use (&$connection) {
$this->checkinConnection($connection);
return $value;
}, function (\Throwable $error) use (&$connection) {
$this->checkinConnection($connection);
throw $error;
});
} | [
"function",
"execute",
"(",
"string",
"$",
"query",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
":",
"\\",
"React",
"\\",
"Promise",
"\\",
"PromiseInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"goingAway",
")",
"{",
"return",
"\\",
"Re... | Prepares and executes a query. Resolves with a `QueryResultInterface` instance.
This is equivalent to prepare -> execute -> close.
If you need to execute a query multiple times, prepare the query manually for performance reasons.
@param string $query
@param array $params
@return \React\Promise\PromiseInterface
@throws \Plasma\Exception
@see \Plasma\StatementInterface | [
"Prepares",
"and",
"executes",
"a",
"query",
".",
"Resolves",
"with",
"a",
"QueryResultInterface",
"instance",
".",
"This",
"is",
"equivalent",
"to",
"prepare",
"-",
">",
"execute",
"-",
">",
"close",
".",
"If",
"you",
"need",
"to",
"execute",
"a",
"query"... | ce9b1a206e3777f3cf884eec5eee686a073ddfb2 | https://github.com/PlasmaPHP/core/blob/ce9b1a206e3777f3cf884eec5eee686a073ddfb2/src/Client.php#L194-L208 | train |
PlasmaPHP/core | src/Client.php | Client.close | function close(): \React\Promise\PromiseInterface {
if($this->goingAway) {
return $this->goingAway;
}
$deferred = new \React\Promise\Deferred();
$this->goingAway = $deferred->promise();
$closes = array();
/** @var \Plasma\DriverInterface $conn */
foreach($this->connections->all() as $conn) {
$closes[] = $conn->close();
$this->connections->delete($conn);
}
/** @var \Plasma\DriverInterface $conn */
foreach($this->busyConnections->all() as $conn) {
$closes[] = $conn->close();
$this->busyConnections->delete($conn);
}
\React\Promise\all($closes)->then(array($deferred, 'resolve'), array($deferred, 'reject'));
return $this->goingAway;
} | php | function close(): \React\Promise\PromiseInterface {
if($this->goingAway) {
return $this->goingAway;
}
$deferred = new \React\Promise\Deferred();
$this->goingAway = $deferred->promise();
$closes = array();
/** @var \Plasma\DriverInterface $conn */
foreach($this->connections->all() as $conn) {
$closes[] = $conn->close();
$this->connections->delete($conn);
}
/** @var \Plasma\DriverInterface $conn */
foreach($this->busyConnections->all() as $conn) {
$closes[] = $conn->close();
$this->busyConnections->delete($conn);
}
\React\Promise\all($closes)->then(array($deferred, 'resolve'), array($deferred, 'reject'));
return $this->goingAway;
} | [
"function",
"close",
"(",
")",
":",
"\\",
"React",
"\\",
"Promise",
"\\",
"PromiseInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"goingAway",
")",
"{",
"return",
"$",
"this",
"->",
"goingAway",
";",
"}",
"$",
"deferred",
"=",
"new",
"\\",
"React",
"\... | Closes all connections gracefully after processing all outstanding requests.
@return \React\Promise\PromiseInterface | [
"Closes",
"all",
"connections",
"gracefully",
"after",
"processing",
"all",
"outstanding",
"requests",
"."
] | ce9b1a206e3777f3cf884eec5eee686a073ddfb2 | https://github.com/PlasmaPHP/core/blob/ce9b1a206e3777f3cf884eec5eee686a073ddfb2/src/Client.php#L239-L263 | train |
PlasmaPHP/core | src/Client.php | Client.quit | function quit(): void {
if($this->goingAway) {
return;
}
$this->goingAway = \React\Promise\resolve();
/** @var \Plasma\DriverInterface $conn */
foreach($this->connections->all() as $conn) {
$conn->quit();
$this->connections->delete($conn);
}
/** @var \Plasma\DriverInterface $conn */
foreach($this->busyConnections->all() as $conn) {
$conn->quit();
$this->busyConnections->delete($conn);
}
} | php | function quit(): void {
if($this->goingAway) {
return;
}
$this->goingAway = \React\Promise\resolve();
/** @var \Plasma\DriverInterface $conn */
foreach($this->connections->all() as $conn) {
$conn->quit();
$this->connections->delete($conn);
}
/** @var \Plasma\DriverInterface $conn */
foreach($this->busyConnections->all() as $conn) {
$conn->quit();
$this->busyConnections->delete($conn);
}
} | [
"function",
"quit",
"(",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"goingAway",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"goingAway",
"=",
"\\",
"React",
"\\",
"Promise",
"\\",
"resolve",
"(",
")",
";",
"/** @var \\Plasma\\DriverInte... | Forcefully closes the connection, without waiting for any outstanding requests. This will reject all oustanding requests.
@return void | [
"Forcefully",
"closes",
"the",
"connection",
"without",
"waiting",
"for",
"any",
"outstanding",
"requests",
".",
"This",
"will",
"reject",
"all",
"oustanding",
"requests",
"."
] | ce9b1a206e3777f3cf884eec5eee686a073ddfb2 | https://github.com/PlasmaPHP/core/blob/ce9b1a206e3777f3cf884eec5eee686a073ddfb2/src/Client.php#L269-L287 | train |
PlasmaPHP/core | src/Client.php | Client.runQuery | function runQuery(\Plasma\QueryBuilderInterface $query): \React\Promise\PromiseInterface {
if($this->goingAway) {
return \React\Promise\reject((new \Plasma\Exception('Client is closing all connections')));
}
$connection = $this->getOptimalConnection();
try {
return $connection->runQuery($this, $query);
} catch (\Throwable $e) {
$this->checkinConnection($connection);
throw $e;
}
} | php | function runQuery(\Plasma\QueryBuilderInterface $query): \React\Promise\PromiseInterface {
if($this->goingAway) {
return \React\Promise\reject((new \Plasma\Exception('Client is closing all connections')));
}
$connection = $this->getOptimalConnection();
try {
return $connection->runQuery($this, $query);
} catch (\Throwable $e) {
$this->checkinConnection($connection);
throw $e;
}
} | [
"function",
"runQuery",
"(",
"\\",
"Plasma",
"\\",
"QueryBuilderInterface",
"$",
"query",
")",
":",
"\\",
"React",
"\\",
"Promise",
"\\",
"PromiseInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"goingAway",
")",
"{",
"return",
"\\",
"React",
"\\",
"Promise"... | Runs the given querybuilder on an underlying driver instance.
The driver CAN throw an exception if the given querybuilder is not supported.
An example would be a SQL querybuilder and a Cassandra driver.
@param \Plasma\QueryBuilderInterface $query
@return \React\Promise\PromiseInterface
@throws \Plasma\Exception | [
"Runs",
"the",
"given",
"querybuilder",
"on",
"an",
"underlying",
"driver",
"instance",
".",
"The",
"driver",
"CAN",
"throw",
"an",
"exception",
"if",
"the",
"given",
"querybuilder",
"is",
"not",
"supported",
".",
"An",
"example",
"would",
"be",
"a",
"SQL",
... | ce9b1a206e3777f3cf884eec5eee686a073ddfb2 | https://github.com/PlasmaPHP/core/blob/ce9b1a206e3777f3cf884eec5eee686a073ddfb2/src/Client.php#L318-L331 | train |
PlasmaPHP/core | src/Client.php | Client.createReadCursor | function createReadCursor(string $query, array $params = array()): \React\Promise\PromiseInterface {
if($this->goingAway) {
return \React\Promise\reject((new \Plasma\Exception('Client is closing all connections')));
}
$connection = $this->getOptimalConnection();
try {
return $connection->createReadCursor($this, $query, $params);
} catch (\Throwable $e) {
$this->checkinConnection($connection);
throw $e;
}
} | php | function createReadCursor(string $query, array $params = array()): \React\Promise\PromiseInterface {
if($this->goingAway) {
return \React\Promise\reject((new \Plasma\Exception('Client is closing all connections')));
}
$connection = $this->getOptimalConnection();
try {
return $connection->createReadCursor($this, $query, $params);
} catch (\Throwable $e) {
$this->checkinConnection($connection);
throw $e;
}
} | [
"function",
"createReadCursor",
"(",
"string",
"$",
"query",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
":",
"\\",
"React",
"\\",
"Promise",
"\\",
"PromiseInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"goingAway",
")",
"{",
"return",
"\... | Creates a new cursor to seek through SELECT query results.
@param string $query
@param array $params
@return \React\Promise\PromiseInterface
@throws \Plasma\Exception | [
"Creates",
"a",
"new",
"cursor",
"to",
"seek",
"through",
"SELECT",
"query",
"results",
"."
] | ce9b1a206e3777f3cf884eec5eee686a073ddfb2 | https://github.com/PlasmaPHP/core/blob/ce9b1a206e3777f3cf884eec5eee686a073ddfb2/src/Client.php#L340-L353 | train |
PlasmaPHP/core | src/Client.php | Client.getOptimalConnection | protected function getOptimalConnection(): \Plasma\DriverInterface {
if(\count($this->connections) === 0) {
$connection = $this->createNewConnection();
$this->busyConnections->add($connection);
return $connection;
}
/** @var \Plasma\DriverInterface $connection */
$this->connections->rewind();
$connection = $this->connections->current();
$backlog = $connection->getBacklogLength();
$state = $connection->getBusyState();
/** @var \Plasma\DriverInterface $conn */
foreach($this->connections as $conn) {
$cbacklog = $conn->getBacklogLength();
$cstate = $conn->getBusyState();
if($cbacklog === 0 && $conn->getConnectionState() === \Plasma\DriverInterface::CONNECTION_OK && $cstate == \Plasma\DriverInterface::STATE_IDLE) {
$this->connections->delete($conn);
$this->busyConnections->add($conn);
return $conn;
}
if($backlog > $cbacklog || $state > $cstate) {
$connection = $conn;
$backlog = $cbacklog;
$state = $cstate;
}
}
if($this->getConnectionCount() < $this->options['connections.max']) {
$connection = $this->createNewConnection();
}
$this->connections->delete($connection);
$this->busyConnections->add($connection);
return $connection;
} | php | protected function getOptimalConnection(): \Plasma\DriverInterface {
if(\count($this->connections) === 0) {
$connection = $this->createNewConnection();
$this->busyConnections->add($connection);
return $connection;
}
/** @var \Plasma\DriverInterface $connection */
$this->connections->rewind();
$connection = $this->connections->current();
$backlog = $connection->getBacklogLength();
$state = $connection->getBusyState();
/** @var \Plasma\DriverInterface $conn */
foreach($this->connections as $conn) {
$cbacklog = $conn->getBacklogLength();
$cstate = $conn->getBusyState();
if($cbacklog === 0 && $conn->getConnectionState() === \Plasma\DriverInterface::CONNECTION_OK && $cstate == \Plasma\DriverInterface::STATE_IDLE) {
$this->connections->delete($conn);
$this->busyConnections->add($conn);
return $conn;
}
if($backlog > $cbacklog || $state > $cstate) {
$connection = $conn;
$backlog = $cbacklog;
$state = $cstate;
}
}
if($this->getConnectionCount() < $this->options['connections.max']) {
$connection = $this->createNewConnection();
}
$this->connections->delete($connection);
$this->busyConnections->add($connection);
return $connection;
} | [
"protected",
"function",
"getOptimalConnection",
"(",
")",
":",
"\\",
"Plasma",
"\\",
"DriverInterface",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"this",
"->",
"connections",
")",
"===",
"0",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"createNe... | Get the optimal connection.
@return \Plasma\DriverInterface | [
"Get",
"the",
"optimal",
"connection",
"."
] | ce9b1a206e3777f3cf884eec5eee686a073ddfb2 | https://github.com/PlasmaPHP/core/blob/ce9b1a206e3777f3cf884eec5eee686a073ddfb2/src/Client.php#L359-L401 | train |
PlasmaPHP/core | src/Client.php | Client.createNewConnection | protected function createNewConnection(): \Plasma\DriverInterface {
$connection = $this->factory->createDriver();
// We relay a driver's specific events forward, e.g. PostgreSQL notifications
$connection->on('eventRelay', function (string $eventName, ...$args) use (&$connection) {
$args[] = $connection;
$this->emit($eventName, $args);
});
$connection->on('close', function () use (&$connection) {
$this->connections->delete($connection);
$this->busyConnections->delete($connection);
$this->emit('close', array($connection));
});
$connection->on('error', function (\Throwable $error) use (&$connection) {
$this->emit('error', array($error, $connection));
});
$connection->connect($this->uri)->then(function () use (&$connection) {
$this->connections->add($connection);
$this->busyConnections->delete($connection);
}, function (\Throwable $error) use (&$connection) {
$this->connections->delete($connection);
$this->busyConnections->delete($connection);
$this->emit('error', array($error, $connection));
});
return $connection;
} | php | protected function createNewConnection(): \Plasma\DriverInterface {
$connection = $this->factory->createDriver();
// We relay a driver's specific events forward, e.g. PostgreSQL notifications
$connection->on('eventRelay', function (string $eventName, ...$args) use (&$connection) {
$args[] = $connection;
$this->emit($eventName, $args);
});
$connection->on('close', function () use (&$connection) {
$this->connections->delete($connection);
$this->busyConnections->delete($connection);
$this->emit('close', array($connection));
});
$connection->on('error', function (\Throwable $error) use (&$connection) {
$this->emit('error', array($error, $connection));
});
$connection->connect($this->uri)->then(function () use (&$connection) {
$this->connections->add($connection);
$this->busyConnections->delete($connection);
}, function (\Throwable $error) use (&$connection) {
$this->connections->delete($connection);
$this->busyConnections->delete($connection);
$this->emit('error', array($error, $connection));
});
return $connection;
} | [
"protected",
"function",
"createNewConnection",
"(",
")",
":",
"\\",
"Plasma",
"\\",
"DriverInterface",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"factory",
"->",
"createDriver",
"(",
")",
";",
"// We relay a driver's specific events forward, e.g. PostgreSQL notif... | Create a new connection.
@return \Plasma\DriverInterface | [
"Create",
"a",
"new",
"connection",
"."
] | ce9b1a206e3777f3cf884eec5eee686a073ddfb2 | https://github.com/PlasmaPHP/core/blob/ce9b1a206e3777f3cf884eec5eee686a073ddfb2/src/Client.php#L407-L438 | train |
PlasmaPHP/core | src/Client.php | Client.validateOptions | protected function validateOptions(array $options) {
$validator = \CharlotteDunois\Validation\Validator::make($options, array(
'connections.max' => 'integer|min:1',
'connections.lazy' => 'boolean'
));
$validator->throw(\InvalidArgumentException::class);
} | php | protected function validateOptions(array $options) {
$validator = \CharlotteDunois\Validation\Validator::make($options, array(
'connections.max' => 'integer|min:1',
'connections.lazy' => 'boolean'
));
$validator->throw(\InvalidArgumentException::class);
} | [
"protected",
"function",
"validateOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"validator",
"=",
"\\",
"CharlotteDunois",
"\\",
"Validation",
"\\",
"Validator",
"::",
"make",
"(",
"$",
"options",
",",
"array",
"(",
"'connections.max'",
"=>",
"'intege... | Validates the given options.
@param array $options
@return void
@throws \InvalidArgumentException | [
"Validates",
"the",
"given",
"options",
"."
] | ce9b1a206e3777f3cf884eec5eee686a073ddfb2 | https://github.com/PlasmaPHP/core/blob/ce9b1a206e3777f3cf884eec5eee686a073ddfb2/src/Client.php#L446-L453 | train |
nyeholt/silverstripe-solr | code/extensions/SolrIndexable.php | SolrIndexable.onAfterWrite | public function onAfterWrite() {
if (!self::$indexing) return;
// No longer doing the 'ischanged' check to avoid problems with multivalue field NOT being indexed
//$changes = $this->owner->getChangedFields(true, 2);
$stage = null;
// if it's being written and a versionable, then save only in the draft
// repository.
if ($this->owner->hasMethod('canBeVersioned') && $this->owner->canBeVersioned($this->owner->baseTable())) {
$stage = Versioned::current_stage();
}
if ($this->canShowInSearch()) {
// DataObject::write() does _not_ set LastEdited until _after_ onAfterWrite completes
$this->owner->LastEdited = date('Y-m-d H:i:s');
$this->reindex($stage);
}
} | php | public function onAfterWrite() {
if (!self::$indexing) return;
// No longer doing the 'ischanged' check to avoid problems with multivalue field NOT being indexed
//$changes = $this->owner->getChangedFields(true, 2);
$stage = null;
// if it's being written and a versionable, then save only in the draft
// repository.
if ($this->owner->hasMethod('canBeVersioned') && $this->owner->canBeVersioned($this->owner->baseTable())) {
$stage = Versioned::current_stage();
}
if ($this->canShowInSearch()) {
// DataObject::write() does _not_ set LastEdited until _after_ onAfterWrite completes
$this->owner->LastEdited = date('Y-m-d H:i:s');
$this->reindex($stage);
}
} | [
"public",
"function",
"onAfterWrite",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"indexing",
")",
"return",
";",
"// No longer doing the 'ischanged' check to avoid problems with multivalue field NOT being indexed",
"//$changes = $this->owner->getChangedFields(true, 2);",
"... | Index after every write; this lets us search on Draft data as well as live data | [
"Index",
"after",
"every",
"write",
";",
"this",
"lets",
"us",
"search",
"on",
"Draft",
"data",
"as",
"well",
"as",
"live",
"data"
] | a573df88167ba9b2bec51e2660a4edfdad446fcf | https://github.com/nyeholt/silverstripe-solr/blob/a573df88167ba9b2bec51e2660a4edfdad446fcf/code/extensions/SolrIndexable.php#L64-L82 | train |
nyeholt/silverstripe-solr | code/extensions/SolrIndexable.php | SolrIndexable.reindex | public function reindex($stage = null) {
// Make sure the current data object is not orphaned.
if($this->owner->ParentID > 0) {
$parent = $this->owner->Parent();
if(is_null($parent) || ($parent === false)) {
return;
}
}
// Make sure the extension requirements have been met before enabling the custom site tree search index,
// since this may impact performance.
if((ClassInfo::baseDataClass($this->owner) === 'SiteTree')
&& SiteTree::has_extension('SiteTreePermissionIndexExtension')
&& SiteTree::has_extension('SolrSearchPermissionIndexExtension')
&& ClassInfo::exists('QueuedJob')
) {
// Queue a job to handle the recursive indexing.
$indexing = new SolrSiteTreePermissionIndexJob($this->owner, $stage);
singleton('QueuedJobService')->queueJob($indexing);
}
else {
// When the requirements haven't been met, trigger a normal index.
$this->searchService->index($this->owner, $stage);
}
} | php | public function reindex($stage = null) {
// Make sure the current data object is not orphaned.
if($this->owner->ParentID > 0) {
$parent = $this->owner->Parent();
if(is_null($parent) || ($parent === false)) {
return;
}
}
// Make sure the extension requirements have been met before enabling the custom site tree search index,
// since this may impact performance.
if((ClassInfo::baseDataClass($this->owner) === 'SiteTree')
&& SiteTree::has_extension('SiteTreePermissionIndexExtension')
&& SiteTree::has_extension('SolrSearchPermissionIndexExtension')
&& ClassInfo::exists('QueuedJob')
) {
// Queue a job to handle the recursive indexing.
$indexing = new SolrSiteTreePermissionIndexJob($this->owner, $stage);
singleton('QueuedJobService')->queueJob($indexing);
}
else {
// When the requirements haven't been met, trigger a normal index.
$this->searchService->index($this->owner, $stage);
}
} | [
"public",
"function",
"reindex",
"(",
"$",
"stage",
"=",
"null",
")",
"{",
"// Make sure the current data object is not orphaned.",
"if",
"(",
"$",
"this",
"->",
"owner",
"->",
"ParentID",
">",
"0",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"owner",
... | Index the current data object for a particular stage.
@param string | [
"Index",
"the",
"current",
"data",
"object",
"for",
"a",
"particular",
"stage",
"."
] | a573df88167ba9b2bec51e2660a4edfdad446fcf | https://github.com/nyeholt/silverstripe-solr/blob/a573df88167ba9b2bec51e2660a4edfdad446fcf/code/extensions/SolrIndexable.php#L116-L145 | train |
taion809/GuerrillaMail | src/GuerrillaMail/GuerrillaMail.php | GuerrillaMail.setEmailAddress | public function setEmailAddress($email_user, $lang = 'en')
{
$action = "set_email_user";
$options = array(
'email_user' => $email_user,
'lang' => $lang,
'sid_token' => $this->sid_token
);
return $this->client->post($action, $options);
} | php | public function setEmailAddress($email_user, $lang = 'en')
{
$action = "set_email_user";
$options = array(
'email_user' => $email_user,
'lang' => $lang,
'sid_token' => $this->sid_token
);
return $this->client->post($action, $options);
} | [
"public",
"function",
"setEmailAddress",
"(",
"$",
"email_user",
",",
"$",
"lang",
"=",
"'en'",
")",
"{",
"$",
"action",
"=",
"\"set_email_user\"",
";",
"$",
"options",
"=",
"array",
"(",
"'email_user'",
"=>",
"$",
"email_user",
",",
"'lang'",
"=>",
"$",
... | Change users email address
@param $email_user
@param string $lang
@return bool | [
"Change",
"users",
"email",
"address"
] | a0b3c7c605a0d0572f57caddc589206598f4266f | https://github.com/taion809/GuerrillaMail/blob/a0b3c7c605a0d0572f57caddc589206598f4266f/src/GuerrillaMail/GuerrillaMail.php#L130-L140 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.