id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
26,100
|
balintsera/evista-perform
|
src/FormMarkupTranspiler.php
|
FormMarkupTranspiler.runIfNotCached
|
private function runIfNotCached($variableName, callable $function)
{
if (null === $this->{$variableName}) {
// Only assign that don't returns
if (null !== $result = $function()) {
$this->{$variableName} = $result;
}
}
}
|
php
|
private function runIfNotCached($variableName, callable $function)
{
if (null === $this->{$variableName}) {
// Only assign that don't returns
if (null !== $result = $function()) {
$this->{$variableName} = $result;
}
}
}
|
[
"private",
"function",
"runIfNotCached",
"(",
"$",
"variableName",
",",
"callable",
"$",
"function",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"{",
"$",
"variableName",
"}",
")",
"{",
"// Only assign that don't returns",
"if",
"(",
"null",
"!==",
"$",
"result",
"=",
"$",
"function",
"(",
")",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"variableName",
"}",
"=",
"$",
"result",
";",
"}",
"}",
"}"
] |
Check if a variable is empty and run function to
@param $variableName
@param callable $function
|
[
"Check",
"if",
"a",
"variable",
"is",
"empty",
"and",
"run",
"function",
"to"
] |
2b8723852ebe824ed721f30293e1e0d2c14f4b21
|
https://github.com/balintsera/evista-perform/blob/2b8723852ebe824ed721f30293e1e0d2c14f4b21/src/FormMarkupTranspiler.php#L248-L256
|
26,101
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/HasManyRelation.php
|
HasManyRelation.detach
|
public function detach(RecordInterface $record): RecordInterface
{
$this->loadData(true);
foreach ($this->instances as $index => $instance) {
if ($this->match($instance, $record)) {
//Remove from save
unset($this->instances[$index]);
return $instance;
}
}
throw new RelationException("Record {$record} not found in HasMany relation");
}
|
php
|
public function detach(RecordInterface $record): RecordInterface
{
$this->loadData(true);
foreach ($this->instances as $index => $instance) {
if ($this->match($instance, $record)) {
//Remove from save
unset($this->instances[$index]);
return $instance;
}
}
throw new RelationException("Record {$record} not found in HasMany relation");
}
|
[
"public",
"function",
"detach",
"(",
"RecordInterface",
"$",
"record",
")",
":",
"RecordInterface",
"{",
"$",
"this",
"->",
"loadData",
"(",
"true",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"instances",
"as",
"$",
"index",
"=>",
"$",
"instance",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"match",
"(",
"$",
"instance",
",",
"$",
"record",
")",
")",
"{",
"//Remove from save",
"unset",
"(",
"$",
"this",
"->",
"instances",
"[",
"$",
"index",
"]",
")",
";",
"return",
"$",
"instance",
";",
"}",
"}",
"throw",
"new",
"RelationException",
"(",
"\"Record {$record} not found in HasMany relation\"",
")",
";",
"}"
] |
Detach given object from set of instances but do not delete it in database, use it to
transfer object between sets.
@param \Spiral\ORM\RecordInterface $record
@return \Spiral\ORM\RecordInterface
@throws RelationException When object not presented in a set.
|
[
"Detach",
"given",
"object",
"from",
"set",
"of",
"instances",
"but",
"do",
"not",
"delete",
"it",
"in",
"database",
"use",
"it",
"to",
"transfer",
"object",
"between",
"sets",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/HasManyRelation.php#L143-L156
|
26,102
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/HasManyRelation.php
|
HasManyRelation.loadRelated
|
protected function loadRelated(): array
{
$innerKey = $this->parent->getField($this->key(Record::INNER_KEY));
if (!empty($innerKey)) {
return $this->createSelector($innerKey)->fetchData();
}
return [];
}
|
php
|
protected function loadRelated(): array
{
$innerKey = $this->parent->getField($this->key(Record::INNER_KEY));
if (!empty($innerKey)) {
return $this->createSelector($innerKey)->fetchData();
}
return [];
}
|
[
"protected",
"function",
"loadRelated",
"(",
")",
":",
"array",
"{",
"$",
"innerKey",
"=",
"$",
"this",
"->",
"parent",
"->",
"getField",
"(",
"$",
"this",
"->",
"key",
"(",
"Record",
"::",
"INNER_KEY",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"innerKey",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createSelector",
"(",
"$",
"innerKey",
")",
"->",
"fetchData",
"(",
")",
";",
"}",
"return",
"[",
"]",
";",
"}"
] |
Fetch data from database. Lazy load.
@return array
|
[
"Fetch",
"data",
"from",
"database",
".",
"Lazy",
"load",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/HasManyRelation.php#L227-L235
|
26,103
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/HasManyRelation.php
|
HasManyRelation.createSelector
|
protected function createSelector($innerKey): RecordSelector
{
$selector = $this->orm->selector($this->class)->where(
$this->key(Record::OUTER_KEY),
$innerKey
);
$decorator = new AliasDecorator($selector, 'where', $selector->getAlias());
if (!empty($this->schema[Record::WHERE])) {
//Configuring where conditions with alias resolution
$decorator->where($this->schema[Record::WHERE]);
}
if (!empty($this->key(Record::MORPH_KEY))) {
//Morph key
$decorator->where(
'{@}.' . $this->key(Record::MORPH_KEY),
$this->orm->define(get_class($this->parent), ORMInterface::R_ROLE_NAME)
);
}
if (!empty($this->schema[Record::ORDER_BY])) {
//Sorting
$decorator->orderBy((array)$this->schema[Record::ORDER_BY]);
}
return $selector;
}
|
php
|
protected function createSelector($innerKey): RecordSelector
{
$selector = $this->orm->selector($this->class)->where(
$this->key(Record::OUTER_KEY),
$innerKey
);
$decorator = new AliasDecorator($selector, 'where', $selector->getAlias());
if (!empty($this->schema[Record::WHERE])) {
//Configuring where conditions with alias resolution
$decorator->where($this->schema[Record::WHERE]);
}
if (!empty($this->key(Record::MORPH_KEY))) {
//Morph key
$decorator->where(
'{@}.' . $this->key(Record::MORPH_KEY),
$this->orm->define(get_class($this->parent), ORMInterface::R_ROLE_NAME)
);
}
if (!empty($this->schema[Record::ORDER_BY])) {
//Sorting
$decorator->orderBy((array)$this->schema[Record::ORDER_BY]);
}
return $selector;
}
|
[
"protected",
"function",
"createSelector",
"(",
"$",
"innerKey",
")",
":",
"RecordSelector",
"{",
"$",
"selector",
"=",
"$",
"this",
"->",
"orm",
"->",
"selector",
"(",
"$",
"this",
"->",
"class",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"key",
"(",
"Record",
"::",
"OUTER_KEY",
")",
",",
"$",
"innerKey",
")",
";",
"$",
"decorator",
"=",
"new",
"AliasDecorator",
"(",
"$",
"selector",
",",
"'where'",
",",
"$",
"selector",
"->",
"getAlias",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"WHERE",
"]",
")",
")",
"{",
"//Configuring where conditions with alias resolution",
"$",
"decorator",
"->",
"where",
"(",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"WHERE",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"key",
"(",
"Record",
"::",
"MORPH_KEY",
")",
")",
")",
"{",
"//Morph key",
"$",
"decorator",
"->",
"where",
"(",
"'{@}.'",
".",
"$",
"this",
"->",
"key",
"(",
"Record",
"::",
"MORPH_KEY",
")",
",",
"$",
"this",
"->",
"orm",
"->",
"define",
"(",
"get_class",
"(",
"$",
"this",
"->",
"parent",
")",
",",
"ORMInterface",
"::",
"R_ROLE_NAME",
")",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"ORDER_BY",
"]",
")",
")",
"{",
"//Sorting",
"$",
"decorator",
"->",
"orderBy",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"ORDER_BY",
"]",
")",
";",
"}",
"return",
"$",
"selector",
";",
"}"
] |
Create outer selector for a given inner key value.
@param mixed $innerKey
@return RecordSelector
|
[
"Create",
"outer",
"selector",
"for",
"a",
"given",
"inner",
"key",
"value",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/HasManyRelation.php#L244-L271
|
26,104
|
rinvex/cortex-foundation
|
src/Relations/BelongsToMorph.php
|
BelongsToMorph.build
|
public static function build(Model $parent, $related, $name, $type = null, $id = null, $otherKey = null, $relation = null)
{
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if (is_null($relation)) {
[$current, $caller] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$relation = $caller['function'];
}
$morphName = array_get(array_flip(Relation::morphMap()), $related, $related);
[$type, $id] = self::getMorphs(snake_case($name), $type, $id);
$instance = new $related();
// Once we have the foreign key names, we'll just create a new Eloquent query
// for the related models and returns the relationship instance which will
// actually be responsible for retrieving and hydrating every relations.
$query = $instance->newQuery();
$otherKey = $otherKey ?: $instance->getKeyName();
return new self($query, $parent, $morphName, $type, $id, $otherKey, $relation);
}
|
php
|
public static function build(Model $parent, $related, $name, $type = null, $id = null, $otherKey = null, $relation = null)
{
// If no relation name was given, we will use this debug backtrace to extract
// the calling method's name and use that as the relationship name as most
// of the time this will be what we desire to use for the relationships.
if (is_null($relation)) {
[$current, $caller] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
$relation = $caller['function'];
}
$morphName = array_get(array_flip(Relation::morphMap()), $related, $related);
[$type, $id] = self::getMorphs(snake_case($name), $type, $id);
$instance = new $related();
// Once we have the foreign key names, we'll just create a new Eloquent query
// for the related models and returns the relationship instance which will
// actually be responsible for retrieving and hydrating every relations.
$query = $instance->newQuery();
$otherKey = $otherKey ?: $instance->getKeyName();
return new self($query, $parent, $morphName, $type, $id, $otherKey, $relation);
}
|
[
"public",
"static",
"function",
"build",
"(",
"Model",
"$",
"parent",
",",
"$",
"related",
",",
"$",
"name",
",",
"$",
"type",
"=",
"null",
",",
"$",
"id",
"=",
"null",
",",
"$",
"otherKey",
"=",
"null",
",",
"$",
"relation",
"=",
"null",
")",
"{",
"// If no relation name was given, we will use this debug backtrace to extract",
"// the calling method's name and use that as the relationship name as most",
"// of the time this will be what we desire to use for the relationships.",
"if",
"(",
"is_null",
"(",
"$",
"relation",
")",
")",
"{",
"[",
"$",
"current",
",",
"$",
"caller",
"]",
"=",
"debug_backtrace",
"(",
"DEBUG_BACKTRACE_IGNORE_ARGS",
",",
"2",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"}",
"$",
"morphName",
"=",
"array_get",
"(",
"array_flip",
"(",
"Relation",
"::",
"morphMap",
"(",
")",
")",
",",
"$",
"related",
",",
"$",
"related",
")",
";",
"[",
"$",
"type",
",",
"$",
"id",
"]",
"=",
"self",
"::",
"getMorphs",
"(",
"snake_case",
"(",
"$",
"name",
")",
",",
"$",
"type",
",",
"$",
"id",
")",
";",
"$",
"instance",
"=",
"new",
"$",
"related",
"(",
")",
";",
"// Once we have the foreign key names, we'll just create a new Eloquent query",
"// for the related models and returns the relationship instance which will",
"// actually be responsible for retrieving and hydrating every relations.",
"$",
"query",
"=",
"$",
"instance",
"->",
"newQuery",
"(",
")",
";",
"$",
"otherKey",
"=",
"$",
"otherKey",
"?",
":",
"$",
"instance",
"->",
"getKeyName",
"(",
")",
";",
"return",
"new",
"self",
"(",
"$",
"query",
",",
"$",
"parent",
",",
"$",
"morphName",
",",
"$",
"type",
",",
"$",
"id",
",",
"$",
"otherKey",
",",
"$",
"relation",
")",
";",
"}"
] |
Define an inverse morph relationship.
@param Model $parent
@param string $related
@param string $name
@param string $type
@param string $id
@param string $otherKey
@param string $relation
@return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
[
"Define",
"an",
"inverse",
"morph",
"relationship",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Relations/BelongsToMorph.php#L109-L134
|
26,105
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/Traits/SyncedTrait.php
|
SyncedTrait.isSynced
|
protected function isSynced(RecordInterface $inner, RecordInterface $outer): bool
{
if (empty($inner->primaryKey()) || empty($outer->primaryKey())) {
//Parent not saved
return false;
}
//Comparing FK values
return $outer->getField(
$this->key(Record::OUTER_KEY)
) == $inner->getField(
$this->key(Record::INNER_KEY)
);
}
|
php
|
protected function isSynced(RecordInterface $inner, RecordInterface $outer): bool
{
if (empty($inner->primaryKey()) || empty($outer->primaryKey())) {
//Parent not saved
return false;
}
//Comparing FK values
return $outer->getField(
$this->key(Record::OUTER_KEY)
) == $inner->getField(
$this->key(Record::INNER_KEY)
);
}
|
[
"protected",
"function",
"isSynced",
"(",
"RecordInterface",
"$",
"inner",
",",
"RecordInterface",
"$",
"outer",
")",
":",
"bool",
"{",
"if",
"(",
"empty",
"(",
"$",
"inner",
"->",
"primaryKey",
"(",
")",
")",
"||",
"empty",
"(",
"$",
"outer",
"->",
"primaryKey",
"(",
")",
")",
")",
"{",
"//Parent not saved",
"return",
"false",
";",
"}",
"//Comparing FK values",
"return",
"$",
"outer",
"->",
"getField",
"(",
"$",
"this",
"->",
"key",
"(",
"Record",
"::",
"OUTER_KEY",
")",
")",
"==",
"$",
"inner",
"->",
"getField",
"(",
"$",
"this",
"->",
"key",
"(",
"Record",
"::",
"INNER_KEY",
")",
")",
";",
"}"
] |
If record not synced or can't be synced. Only work for PK based relations.
@param RecordInterface $inner
@param RecordInterface $outer
@return bool
|
[
"If",
"record",
"not",
"synced",
"or",
"can",
"t",
"be",
"synced",
".",
"Only",
"work",
"for",
"PK",
"based",
"relations",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/Traits/SyncedTrait.php#L26-L39
|
26,106
|
spiral/orm
|
source/Spiral/ORM/Entities/Loaders/ManyToManyLoader.php
|
ManyToManyLoader.pivotKey
|
protected function pivotKey(string $key)
{
if (!isset($this->schema[$key])) {
return null;
}
return $this->pivotAlias() . '.' . $this->schema[$key];
}
|
php
|
protected function pivotKey(string $key)
{
if (!isset($this->schema[$key])) {
return null;
}
return $this->pivotAlias() . '.' . $this->schema[$key];
}
|
[
"protected",
"function",
"pivotKey",
"(",
"string",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"schema",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"pivotAlias",
"(",
")",
".",
"'.'",
".",
"$",
"this",
"->",
"schema",
"[",
"$",
"key",
"]",
";",
"}"
] |
Key related to pivot table. Must include pivot table alias.
@see pivotKey()
@param string $key
@return null|string
|
[
"Key",
"related",
"to",
"pivot",
"table",
".",
"Must",
"include",
"pivot",
"table",
"alias",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Loaders/ManyToManyLoader.php#L251-L258
|
26,107
|
spiral/orm
|
source/Spiral/ORM/RecordEntity.php
|
RecordEntity.handleInsert
|
private function handleInsert(InsertCommand $command)
{
//Mounting PK
$this->setField($this->primaryColumn(), $command->getInsertID(), true, false);
//Once command executed we will know some information about it's context
//(for exampled added FKs), this information must already be in database (added to command),
//so no need to track changes
foreach ($command->getContext() as $name => $value) {
$this->setField($name, $value, true, false);
}
$this->state = ORMInterface::STATE_LOADED;
$this->dispatch('created', new RecordEvent($this, $command));
}
|
php
|
private function handleInsert(InsertCommand $command)
{
//Mounting PK
$this->setField($this->primaryColumn(), $command->getInsertID(), true, false);
//Once command executed we will know some information about it's context
//(for exampled added FKs), this information must already be in database (added to command),
//so no need to track changes
foreach ($command->getContext() as $name => $value) {
$this->setField($name, $value, true, false);
}
$this->state = ORMInterface::STATE_LOADED;
$this->dispatch('created', new RecordEvent($this, $command));
}
|
[
"private",
"function",
"handleInsert",
"(",
"InsertCommand",
"$",
"command",
")",
"{",
"//Mounting PK",
"$",
"this",
"->",
"setField",
"(",
"$",
"this",
"->",
"primaryColumn",
"(",
")",
",",
"$",
"command",
"->",
"getInsertID",
"(",
")",
",",
"true",
",",
"false",
")",
";",
"//Once command executed we will know some information about it's context",
"//(for exampled added FKs), this information must already be in database (added to command),",
"//so no need to track changes",
"foreach",
"(",
"$",
"command",
"->",
"getContext",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setField",
"(",
"$",
"name",
",",
"$",
"value",
",",
"true",
",",
"false",
")",
";",
"}",
"$",
"this",
"->",
"state",
"=",
"ORMInterface",
"::",
"STATE_LOADED",
";",
"$",
"this",
"->",
"dispatch",
"(",
"'created'",
",",
"new",
"RecordEvent",
"(",
"$",
"this",
",",
"$",
"command",
")",
")",
";",
"}"
] |
Handle result of insert command.
@param InsertCommand $command
|
[
"Handle",
"result",
"of",
"insert",
"command",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/RecordEntity.php#L445-L459
|
26,108
|
spiral/orm
|
source/Spiral/ORM/RecordEntity.php
|
RecordEntity.handleUpdate
|
private function handleUpdate(UpdateCommand $command)
{
//Once command executed we will know some information about it's context (for exampled added FKs)
foreach ($command->getContext() as $name => $value) {
$this->setField($name, $value, true, false);
}
$this->state = ORMInterface::STATE_LOADED;
$this->dispatch('updated', new RecordEvent($this, $command));
}
|
php
|
private function handleUpdate(UpdateCommand $command)
{
//Once command executed we will know some information about it's context (for exampled added FKs)
foreach ($command->getContext() as $name => $value) {
$this->setField($name, $value, true, false);
}
$this->state = ORMInterface::STATE_LOADED;
$this->dispatch('updated', new RecordEvent($this, $command));
}
|
[
"private",
"function",
"handleUpdate",
"(",
"UpdateCommand",
"$",
"command",
")",
"{",
"//Once command executed we will know some information about it's context (for exampled added FKs)",
"foreach",
"(",
"$",
"command",
"->",
"getContext",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setField",
"(",
"$",
"name",
",",
"$",
"value",
",",
"true",
",",
"false",
")",
";",
"}",
"$",
"this",
"->",
"state",
"=",
"ORMInterface",
"::",
"STATE_LOADED",
";",
"$",
"this",
"->",
"dispatch",
"(",
"'updated'",
",",
"new",
"RecordEvent",
"(",
"$",
"this",
",",
"$",
"command",
")",
")",
";",
"}"
] |
Handle result of update command.
@param UpdateCommand $command
|
[
"Handle",
"result",
"of",
"update",
"command",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/RecordEntity.php#L466-L475
|
26,109
|
spiral/orm
|
source/Spiral/ORM/RecordEntity.php
|
RecordEntity.handleDelete
|
private function handleDelete(DeleteCommand $command)
{
$this->state = ORMInterface::STATE_DELETED;
$this->dispatch('deleted', new RecordEvent($this, $command));
}
|
php
|
private function handleDelete(DeleteCommand $command)
{
$this->state = ORMInterface::STATE_DELETED;
$this->dispatch('deleted', new RecordEvent($this, $command));
}
|
[
"private",
"function",
"handleDelete",
"(",
"DeleteCommand",
"$",
"command",
")",
"{",
"$",
"this",
"->",
"state",
"=",
"ORMInterface",
"::",
"STATE_DELETED",
";",
"$",
"this",
"->",
"dispatch",
"(",
"'deleted'",
",",
"new",
"RecordEvent",
"(",
"$",
"this",
",",
"$",
"command",
")",
")",
";",
"}"
] |
Handle result of delete command.
@param DeleteCommand $command
|
[
"Handle",
"result",
"of",
"delete",
"command",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/RecordEntity.php#L482-L486
|
26,110
|
spiral/orm
|
source/Spiral/ORM/EntityMap.php
|
EntityMap.remember
|
public function remember(RecordInterface $entity, bool $ignoreLimit = false): RecordInterface
{
if (!$ignoreLimit && !is_null($this->maxSize) && count($this->entities) > $this->maxSize - 1) {
throw new MapException('Entity cache size exceeded');
}
if (empty($entity->primaryKey())) {
throw new MapException("Unable to store non identified entity " . get_class($entity));
}
$cacheID = get_class($entity) . ':' . $entity->primaryKey();
return $this->entities[$cacheID] = $entity;
}
|
php
|
public function remember(RecordInterface $entity, bool $ignoreLimit = false): RecordInterface
{
if (!$ignoreLimit && !is_null($this->maxSize) && count($this->entities) > $this->maxSize - 1) {
throw new MapException('Entity cache size exceeded');
}
if (empty($entity->primaryKey())) {
throw new MapException("Unable to store non identified entity " . get_class($entity));
}
$cacheID = get_class($entity) . ':' . $entity->primaryKey();
return $this->entities[$cacheID] = $entity;
}
|
[
"public",
"function",
"remember",
"(",
"RecordInterface",
"$",
"entity",
",",
"bool",
"$",
"ignoreLimit",
"=",
"false",
")",
":",
"RecordInterface",
"{",
"if",
"(",
"!",
"$",
"ignoreLimit",
"&&",
"!",
"is_null",
"(",
"$",
"this",
"->",
"maxSize",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"entities",
")",
">",
"$",
"this",
"->",
"maxSize",
"-",
"1",
")",
"{",
"throw",
"new",
"MapException",
"(",
"'Entity cache size exceeded'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"entity",
"->",
"primaryKey",
"(",
")",
")",
")",
"{",
"throw",
"new",
"MapException",
"(",
"\"Unable to store non identified entity \"",
".",
"get_class",
"(",
"$",
"entity",
")",
")",
";",
"}",
"$",
"cacheID",
"=",
"get_class",
"(",
"$",
"entity",
")",
".",
"':'",
".",
"$",
"entity",
"->",
"primaryKey",
"(",
")",
";",
"return",
"$",
"this",
"->",
"entities",
"[",
"$",
"cacheID",
"]",
"=",
"$",
"entity",
";",
"}"
] |
Add Record to entity cache. Primary key value will be used as
identifier.
Attention, existed entity will be replaced!
@param RecordInterface $entity
@param bool $ignoreLimit Cache overflow will be ignored.
@return RecordInterface Returns given entity.
@throws MapException When cache size exceeded.
|
[
"Add",
"Record",
"to",
"entity",
"cache",
".",
"Primary",
"key",
"value",
"will",
"be",
"used",
"as",
"identifier",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/EntityMap.php#L59-L72
|
26,111
|
spiral/orm
|
source/Spiral/ORM/EntityMap.php
|
EntityMap.forget
|
public function forget(RecordInterface $entity)
{
$cacheID = get_class($entity) . ':' . $entity->primaryKey();
unset($this->entities[$cacheID]);
}
|
php
|
public function forget(RecordInterface $entity)
{
$cacheID = get_class($entity) . ':' . $entity->primaryKey();
unset($this->entities[$cacheID]);
}
|
[
"public",
"function",
"forget",
"(",
"RecordInterface",
"$",
"entity",
")",
"{",
"$",
"cacheID",
"=",
"get_class",
"(",
"$",
"entity",
")",
".",
"':'",
".",
"$",
"entity",
"->",
"primaryKey",
"(",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"entities",
"[",
"$",
"cacheID",
"]",
")",
";",
"}"
] |
Remove entity record from entity cache. Primary key value will be used as identifier.
@param RecordInterface $entity
|
[
"Remove",
"entity",
"record",
"from",
"entity",
"cache",
".",
"Primary",
"key",
"value",
"will",
"be",
"used",
"as",
"identifier",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/EntityMap.php#L79-L83
|
26,112
|
spiral/orm
|
source/Spiral/ORM/EntityMap.php
|
EntityMap.get
|
public function get(string $class, string $identity)
{
if (!$this->has($class, $identity)) {
return null;
}
return $this->entities["{$class}:{$identity}"];
}
|
php
|
public function get(string $class, string $identity)
{
if (!$this->has($class, $identity)) {
return null;
}
return $this->entities["{$class}:{$identity}"];
}
|
[
"public",
"function",
"get",
"(",
"string",
"$",
"class",
",",
"string",
"$",
"identity",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"class",
",",
"$",
"identity",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"entities",
"[",
"\"{$class}:{$identity}\"",
"]",
";",
"}"
] |
Fetch entity from cache.
@param string $class
@param string $identity
@return null|mixed
|
[
"Fetch",
"entity",
"from",
"cache",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/EntityMap.php#L106-L113
|
26,113
|
spiral/orm
|
source/Spiral/ORM/Entities/Nodes/PivotedRootNode.php
|
PivotedRootNode.duplicateCriteria
|
protected function duplicateCriteria(array &$data)
{
$pivotData = $data[ORMInterface::PIVOT_DATA];
//Unique row criteria
return $pivotData[$this->innerPivotKey] . '.' . $pivotData[$this->outerPivotKey];
}
|
php
|
protected function duplicateCriteria(array &$data)
{
$pivotData = $data[ORMInterface::PIVOT_DATA];
//Unique row criteria
return $pivotData[$this->innerPivotKey] . '.' . $pivotData[$this->outerPivotKey];
}
|
[
"protected",
"function",
"duplicateCriteria",
"(",
"array",
"&",
"$",
"data",
")",
"{",
"$",
"pivotData",
"=",
"$",
"data",
"[",
"ORMInterface",
"::",
"PIVOT_DATA",
"]",
";",
"//Unique row criteria",
"return",
"$",
"pivotData",
"[",
"$",
"this",
"->",
"innerPivotKey",
"]",
".",
"'.'",
".",
"$",
"pivotData",
"[",
"$",
"this",
"->",
"outerPivotKey",
"]",
";",
"}"
] |
De-duplication in pivot tables based on values in pivot table.
@param array $data
@return string
|
[
"De",
"-",
"duplication",
"in",
"pivot",
"tables",
"based",
"on",
"values",
"in",
"pivot",
"table",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Nodes/PivotedRootNode.php#L94-L100
|
26,114
|
rinvex/cortex-foundation
|
src/Traits/Auditable.php
|
Auditable.bootAuditable
|
public static function bootAuditable()
{
static::creating(function (Model $model) {
$model->created_by_id || $model->created_by_id = optional(auth()->guard(request()->route('guard'))->user())->getKey();
$model->created_by_type || $model->created_by_type = optional(auth()->guard(request()->route('guard'))->user())->getMorphClass();
$model->updated_by_id || $model->updated_by_id = optional(auth()->guard(request()->route('guard'))->user())->getKey();
$model->updated_by_type || $model->updated_by_type = optional(auth()->guard(request()->route('guard'))->user())->getMorphClass();
});
static::updating(function (Model $model) {
$model->isDirty('updated_by_id') || $model->updated_by_id = optional(auth()->guard(request()->route('guard'))->user())->getKey();
$model->isDirty('updated_by_type') || $model->updated_by_type = optional(auth()->guard(request()->route('guard'))->user())->getMorphClass();
});
}
|
php
|
public static function bootAuditable()
{
static::creating(function (Model $model) {
$model->created_by_id || $model->created_by_id = optional(auth()->guard(request()->route('guard'))->user())->getKey();
$model->created_by_type || $model->created_by_type = optional(auth()->guard(request()->route('guard'))->user())->getMorphClass();
$model->updated_by_id || $model->updated_by_id = optional(auth()->guard(request()->route('guard'))->user())->getKey();
$model->updated_by_type || $model->updated_by_type = optional(auth()->guard(request()->route('guard'))->user())->getMorphClass();
});
static::updating(function (Model $model) {
$model->isDirty('updated_by_id') || $model->updated_by_id = optional(auth()->guard(request()->route('guard'))->user())->getKey();
$model->isDirty('updated_by_type') || $model->updated_by_type = optional(auth()->guard(request()->route('guard'))->user())->getMorphClass();
});
}
|
[
"public",
"static",
"function",
"bootAuditable",
"(",
")",
"{",
"static",
"::",
"creating",
"(",
"function",
"(",
"Model",
"$",
"model",
")",
"{",
"$",
"model",
"->",
"created_by_id",
"||",
"$",
"model",
"->",
"created_by_id",
"=",
"optional",
"(",
"auth",
"(",
")",
"->",
"guard",
"(",
"request",
"(",
")",
"->",
"route",
"(",
"'guard'",
")",
")",
"->",
"user",
"(",
")",
")",
"->",
"getKey",
"(",
")",
";",
"$",
"model",
"->",
"created_by_type",
"||",
"$",
"model",
"->",
"created_by_type",
"=",
"optional",
"(",
"auth",
"(",
")",
"->",
"guard",
"(",
"request",
"(",
")",
"->",
"route",
"(",
"'guard'",
")",
")",
"->",
"user",
"(",
")",
")",
"->",
"getMorphClass",
"(",
")",
";",
"$",
"model",
"->",
"updated_by_id",
"||",
"$",
"model",
"->",
"updated_by_id",
"=",
"optional",
"(",
"auth",
"(",
")",
"->",
"guard",
"(",
"request",
"(",
")",
"->",
"route",
"(",
"'guard'",
")",
")",
"->",
"user",
"(",
")",
")",
"->",
"getKey",
"(",
")",
";",
"$",
"model",
"->",
"updated_by_type",
"||",
"$",
"model",
"->",
"updated_by_type",
"=",
"optional",
"(",
"auth",
"(",
")",
"->",
"guard",
"(",
"request",
"(",
")",
"->",
"route",
"(",
"'guard'",
")",
")",
"->",
"user",
"(",
")",
")",
"->",
"getMorphClass",
"(",
")",
";",
"}",
")",
";",
"static",
"::",
"updating",
"(",
"function",
"(",
"Model",
"$",
"model",
")",
"{",
"$",
"model",
"->",
"isDirty",
"(",
"'updated_by_id'",
")",
"||",
"$",
"model",
"->",
"updated_by_id",
"=",
"optional",
"(",
"auth",
"(",
")",
"->",
"guard",
"(",
"request",
"(",
")",
"->",
"route",
"(",
"'guard'",
")",
")",
"->",
"user",
"(",
")",
")",
"->",
"getKey",
"(",
")",
";",
"$",
"model",
"->",
"isDirty",
"(",
"'updated_by_type'",
")",
"||",
"$",
"model",
"->",
"updated_by_type",
"=",
"optional",
"(",
"auth",
"(",
")",
"->",
"guard",
"(",
"request",
"(",
")",
"->",
"route",
"(",
"'guard'",
")",
")",
"->",
"user",
"(",
")",
")",
"->",
"getMorphClass",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Boot the Auditable trait for the model.
@return void
|
[
"Boot",
"the",
"Auditable",
"trait",
"for",
"the",
"model",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Traits/Auditable.php#L48-L62
|
26,115
|
rinvex/cortex-foundation
|
src/Traits/Auditable.php
|
Auditable.scopeOfCreator
|
public function scopeOfCreator(Builder $builder, Model $user): Builder
{
return $builder->where('created_by_type', $user->getMorphClass())->where('created_by_id', $user->getKey());
}
|
php
|
public function scopeOfCreator(Builder $builder, Model $user): Builder
{
return $builder->where('created_by_type', $user->getMorphClass())->where('created_by_id', $user->getKey());
}
|
[
"public",
"function",
"scopeOfCreator",
"(",
"Builder",
"$",
"builder",
",",
"Model",
"$",
"user",
")",
":",
"Builder",
"{",
"return",
"$",
"builder",
"->",
"where",
"(",
"'created_by_type'",
",",
"$",
"user",
"->",
"getMorphClass",
"(",
")",
")",
"->",
"where",
"(",
"'created_by_id'",
",",
"$",
"user",
"->",
"getKey",
"(",
")",
")",
";",
"}"
] |
Get audits of the given creator.
@param \Illuminate\Database\Eloquent\Builder $builder
@param \Illuminate\Database\Eloquent\Model $user
@return \Illuminate\Database\Eloquent\Builder
|
[
"Get",
"audits",
"of",
"the",
"given",
"creator",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Traits/Auditable.php#L92-L95
|
26,116
|
rinvex/cortex-foundation
|
src/Traits/Auditable.php
|
Auditable.scopeOfUpdater
|
public function scopeOfUpdater(Builder $builder, Model $user): Builder
{
return $builder->where('updated_by_type', $user->getMorphClass())->where('updated_by_id', $user->getKey());
}
|
php
|
public function scopeOfUpdater(Builder $builder, Model $user): Builder
{
return $builder->where('updated_by_type', $user->getMorphClass())->where('updated_by_id', $user->getKey());
}
|
[
"public",
"function",
"scopeOfUpdater",
"(",
"Builder",
"$",
"builder",
",",
"Model",
"$",
"user",
")",
":",
"Builder",
"{",
"return",
"$",
"builder",
"->",
"where",
"(",
"'updated_by_type'",
",",
"$",
"user",
"->",
"getMorphClass",
"(",
")",
")",
"->",
"where",
"(",
"'updated_by_id'",
",",
"$",
"user",
"->",
"getKey",
"(",
")",
")",
";",
"}"
] |
Get audits of the given updater.
@param \Illuminate\Database\Eloquent\Builder $builder
@param \Illuminate\Database\Eloquent\Model $user
@return \Illuminate\Database\Eloquent\Builder
|
[
"Get",
"audits",
"of",
"the",
"given",
"updater",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Traits/Auditable.php#L105-L108
|
26,117
|
spiral/orm
|
source/Spiral/ORM/Entities/RecordIterator.php
|
RecordIterator.getIterator
|
public function getIterator(): \Generator
{
foreach ($this->data as $index => $data) {
if (isset($data[ORMInterface::PIVOT_DATA])) {
/*
* When pivot data is provided we are able to use it as array key.
*/
$index = $data[ORMInterface::PIVOT_DATA];
unset($data[ORMInterface::PIVOT_DATA]);
}
yield $index => $this->orm->make(
$this->class,
$data,
ORMInterface::STATE_LOADED,
true
);
}
}
|
php
|
public function getIterator(): \Generator
{
foreach ($this->data as $index => $data) {
if (isset($data[ORMInterface::PIVOT_DATA])) {
/*
* When pivot data is provided we are able to use it as array key.
*/
$index = $data[ORMInterface::PIVOT_DATA];
unset($data[ORMInterface::PIVOT_DATA]);
}
yield $index => $this->orm->make(
$this->class,
$data,
ORMInterface::STATE_LOADED,
true
);
}
}
|
[
"public",
"function",
"getIterator",
"(",
")",
":",
"\\",
"Generator",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"index",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"ORMInterface",
"::",
"PIVOT_DATA",
"]",
")",
")",
"{",
"/*\n * When pivot data is provided we are able to use it as array key.\n */",
"$",
"index",
"=",
"$",
"data",
"[",
"ORMInterface",
"::",
"PIVOT_DATA",
"]",
";",
"unset",
"(",
"$",
"data",
"[",
"ORMInterface",
"::",
"PIVOT_DATA",
"]",
")",
";",
"}",
"yield",
"$",
"index",
"=>",
"$",
"this",
"->",
"orm",
"->",
"make",
"(",
"$",
"this",
"->",
"class",
",",
"$",
"data",
",",
"ORMInterface",
"::",
"STATE_LOADED",
",",
"true",
")",
";",
"}",
"}"
] |
Generate over data.
Method will use pibot
@return \Generator
|
[
"Generate",
"over",
"data",
".",
"Method",
"will",
"use",
"pibot"
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RecordIterator.php#L57-L75
|
26,118
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/HasOneRelation.php
|
HasOneRelation.queueRelated
|
private function queueRelated(ContextualCommandInterface $parentCommand): CommandInterface
{
if (empty($this->instance)) {
return new NullCommand();
}
//Related entity store command
$innerCommand = $this->instance->queueStore(true);
//Inversed version of BelongsTo
if (!$this->isSynced($this->parent, $this->instance)) {
//Syncing FKs after primary command been executed
$parentCommand->onExecute(function ($outerCommand) use ($innerCommand) {
$innerCommand->addContext(
$this->key(Record::OUTER_KEY),
$this->lookupKey(Record::INNER_KEY, $this->parent, $outerCommand)
);
if (!empty($morphKey = $this->key(Record::MORPH_KEY))) {
//HasOne relation support additional morph key
$innerCommand->addContext(
$this->key(Record::MORPH_KEY),
$this->orm->define(get_class($this->parent), ORMInterface::R_ROLE_NAME)
);
}
});
}
return $innerCommand;
}
|
php
|
private function queueRelated(ContextualCommandInterface $parentCommand): CommandInterface
{
if (empty($this->instance)) {
return new NullCommand();
}
//Related entity store command
$innerCommand = $this->instance->queueStore(true);
//Inversed version of BelongsTo
if (!$this->isSynced($this->parent, $this->instance)) {
//Syncing FKs after primary command been executed
$parentCommand->onExecute(function ($outerCommand) use ($innerCommand) {
$innerCommand->addContext(
$this->key(Record::OUTER_KEY),
$this->lookupKey(Record::INNER_KEY, $this->parent, $outerCommand)
);
if (!empty($morphKey = $this->key(Record::MORPH_KEY))) {
//HasOne relation support additional morph key
$innerCommand->addContext(
$this->key(Record::MORPH_KEY),
$this->orm->define(get_class($this->parent), ORMInterface::R_ROLE_NAME)
);
}
});
}
return $innerCommand;
}
|
[
"private",
"function",
"queueRelated",
"(",
"ContextualCommandInterface",
"$",
"parentCommand",
")",
":",
"CommandInterface",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"instance",
")",
")",
"{",
"return",
"new",
"NullCommand",
"(",
")",
";",
"}",
"//Related entity store command",
"$",
"innerCommand",
"=",
"$",
"this",
"->",
"instance",
"->",
"queueStore",
"(",
"true",
")",
";",
"//Inversed version of BelongsTo",
"if",
"(",
"!",
"$",
"this",
"->",
"isSynced",
"(",
"$",
"this",
"->",
"parent",
",",
"$",
"this",
"->",
"instance",
")",
")",
"{",
"//Syncing FKs after primary command been executed",
"$",
"parentCommand",
"->",
"onExecute",
"(",
"function",
"(",
"$",
"outerCommand",
")",
"use",
"(",
"$",
"innerCommand",
")",
"{",
"$",
"innerCommand",
"->",
"addContext",
"(",
"$",
"this",
"->",
"key",
"(",
"Record",
"::",
"OUTER_KEY",
")",
",",
"$",
"this",
"->",
"lookupKey",
"(",
"Record",
"::",
"INNER_KEY",
",",
"$",
"this",
"->",
"parent",
",",
"$",
"outerCommand",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"morphKey",
"=",
"$",
"this",
"->",
"key",
"(",
"Record",
"::",
"MORPH_KEY",
")",
")",
")",
"{",
"//HasOne relation support additional morph key",
"$",
"innerCommand",
"->",
"addContext",
"(",
"$",
"this",
"->",
"key",
"(",
"Record",
"::",
"MORPH_KEY",
")",
",",
"$",
"this",
"->",
"orm",
"->",
"define",
"(",
"get_class",
"(",
"$",
"this",
"->",
"parent",
")",
",",
"ORMInterface",
"::",
"R_ROLE_NAME",
")",
")",
";",
"}",
"}",
")",
";",
"}",
"return",
"$",
"innerCommand",
";",
"}"
] |
Store related instance.
@param ContextualCommandInterface $parentCommand
@return CommandInterface
|
[
"Store",
"related",
"instance",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/HasOneRelation.php#L83-L112
|
26,119
|
robertlemke/RobertLemke.Plugin.Blog
|
Classes/Service/NotificationService.php
|
NotificationService.sendNewCommentNotification
|
public function sendNewCommentNotification(NodeInterface $commentNode, NodeInterface $postNode)
{
if ($this->settings['notifications']['to']['email'] === '') {
return;
}
if (!class_exists('Neos\SwiftMailer\Message')) {
$this->systemLogger->log('The package "Neos.SwiftMailer" is required to send notifications!');
return;
}
try {
$mail = new Message();
$mail
->setFrom([$this->settings['notifications']['to']['email'] => $this->settings['notifications']['to']['name']])
->setReplyTo([$commentNode->getProperty('emailAddress') => $commentNode->getProperty('author')])
->setTo([$this->settings['notifications']['to']['email'] => $this->settings['notifications']['to']['name']])
->setSubject('New comment on blog post "' . $postNode->getProperty('title') . '"' . ($commentNode->getProperty('spam') ? ' (SPAM)' : ''))
->setBody($commentNode->getProperty('text'))
->send();
} catch (\Exception $e) {
$this->systemLogger->logException($e);
}
}
|
php
|
public function sendNewCommentNotification(NodeInterface $commentNode, NodeInterface $postNode)
{
if ($this->settings['notifications']['to']['email'] === '') {
return;
}
if (!class_exists('Neos\SwiftMailer\Message')) {
$this->systemLogger->log('The package "Neos.SwiftMailer" is required to send notifications!');
return;
}
try {
$mail = new Message();
$mail
->setFrom([$this->settings['notifications']['to']['email'] => $this->settings['notifications']['to']['name']])
->setReplyTo([$commentNode->getProperty('emailAddress') => $commentNode->getProperty('author')])
->setTo([$this->settings['notifications']['to']['email'] => $this->settings['notifications']['to']['name']])
->setSubject('New comment on blog post "' . $postNode->getProperty('title') . '"' . ($commentNode->getProperty('spam') ? ' (SPAM)' : ''))
->setBody($commentNode->getProperty('text'))
->send();
} catch (\Exception $e) {
$this->systemLogger->logException($e);
}
}
|
[
"public",
"function",
"sendNewCommentNotification",
"(",
"NodeInterface",
"$",
"commentNode",
",",
"NodeInterface",
"$",
"postNode",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"settings",
"[",
"'notifications'",
"]",
"[",
"'to'",
"]",
"[",
"'email'",
"]",
"===",
"''",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"'Neos\\SwiftMailer\\Message'",
")",
")",
"{",
"$",
"this",
"->",
"systemLogger",
"->",
"log",
"(",
"'The package \"Neos.SwiftMailer\" is required to send notifications!'",
")",
";",
"return",
";",
"}",
"try",
"{",
"$",
"mail",
"=",
"new",
"Message",
"(",
")",
";",
"$",
"mail",
"->",
"setFrom",
"(",
"[",
"$",
"this",
"->",
"settings",
"[",
"'notifications'",
"]",
"[",
"'to'",
"]",
"[",
"'email'",
"]",
"=>",
"$",
"this",
"->",
"settings",
"[",
"'notifications'",
"]",
"[",
"'to'",
"]",
"[",
"'name'",
"]",
"]",
")",
"->",
"setReplyTo",
"(",
"[",
"$",
"commentNode",
"->",
"getProperty",
"(",
"'emailAddress'",
")",
"=>",
"$",
"commentNode",
"->",
"getProperty",
"(",
"'author'",
")",
"]",
")",
"->",
"setTo",
"(",
"[",
"$",
"this",
"->",
"settings",
"[",
"'notifications'",
"]",
"[",
"'to'",
"]",
"[",
"'email'",
"]",
"=>",
"$",
"this",
"->",
"settings",
"[",
"'notifications'",
"]",
"[",
"'to'",
"]",
"[",
"'name'",
"]",
"]",
")",
"->",
"setSubject",
"(",
"'New comment on blog post \"'",
".",
"$",
"postNode",
"->",
"getProperty",
"(",
"'title'",
")",
".",
"'\"'",
".",
"(",
"$",
"commentNode",
"->",
"getProperty",
"(",
"'spam'",
")",
"?",
"' (SPAM)'",
":",
"''",
")",
")",
"->",
"setBody",
"(",
"$",
"commentNode",
"->",
"getProperty",
"(",
"'text'",
")",
")",
"->",
"send",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"systemLogger",
"->",
"logException",
"(",
"$",
"e",
")",
";",
"}",
"}"
] |
Send a new notification that a comment has been created
@param NodeInterface $commentNode The comment node
@param NodeInterface $postNode The post node
@return void
|
[
"Send",
"a",
"new",
"notification",
"that",
"a",
"comment",
"has",
"been",
"created"
] |
7780d7e37022056ebe31088c7917ecaad8881dde
|
https://github.com/robertlemke/RobertLemke.Plugin.Blog/blob/7780d7e37022056ebe31088c7917ecaad8881dde/Classes/Service/NotificationService.php#L53-L77
|
26,120
|
flownative/flow-google-cloudstorage
|
Classes/StorageFactory.php
|
StorageFactory.create
|
public function create($credentialsProfileName = 'default')
{
if (!isset($this->credentialProfiles[$credentialsProfileName])) {
throw new Exception(sprintf('The specified Google Cloud Storage credentials profile "%s" does not exist, please check your settings.', $credentialsProfileName), 1446553024);
}
if (!empty($this->credentialProfiles[$credentialsProfileName]['credentials']['privateKeyJsonBase64Encoded'])) {
$googleCloud = new ServiceBuilder([
'keyFile' => json_decode(base64_decode($this->credentialProfiles[$credentialsProfileName]['credentials']['privateKeyJsonBase64Encoded']), true)
]);
} else {
if (substr($this->credentialProfiles[$credentialsProfileName]['credentials']['privateKeyJsonPathAndFilename'], 0, 1) !== '/') {
$privateKeyPathAndFilename = FLOW_PATH_ROOT . $this->credentialProfiles[$credentialsProfileName]['credentials']['privateKeyJsonPathAndFilename'];
} else {
$privateKeyPathAndFilename = $this->credentialProfiles[$credentialsProfileName]['credentials']['privateKeyJsonPathAndFilename'];
}
if (!file_exists($privateKeyPathAndFilename)) {
throw new Exception(sprintf('The Google Cloud Storage private key file "%s" does not exist. Either the file is missing or you need to adjust your settings.', $privateKeyPathAndFilename), 1446553054);
}
$googleCloud = new ServiceBuilder([
'keyFilePath' => $privateKeyPathAndFilename
]);
}
return $googleCloud->storage();
}
|
php
|
public function create($credentialsProfileName = 'default')
{
if (!isset($this->credentialProfiles[$credentialsProfileName])) {
throw new Exception(sprintf('The specified Google Cloud Storage credentials profile "%s" does not exist, please check your settings.', $credentialsProfileName), 1446553024);
}
if (!empty($this->credentialProfiles[$credentialsProfileName]['credentials']['privateKeyJsonBase64Encoded'])) {
$googleCloud = new ServiceBuilder([
'keyFile' => json_decode(base64_decode($this->credentialProfiles[$credentialsProfileName]['credentials']['privateKeyJsonBase64Encoded']), true)
]);
} else {
if (substr($this->credentialProfiles[$credentialsProfileName]['credentials']['privateKeyJsonPathAndFilename'], 0, 1) !== '/') {
$privateKeyPathAndFilename = FLOW_PATH_ROOT . $this->credentialProfiles[$credentialsProfileName]['credentials']['privateKeyJsonPathAndFilename'];
} else {
$privateKeyPathAndFilename = $this->credentialProfiles[$credentialsProfileName]['credentials']['privateKeyJsonPathAndFilename'];
}
if (!file_exists($privateKeyPathAndFilename)) {
throw new Exception(sprintf('The Google Cloud Storage private key file "%s" does not exist. Either the file is missing or you need to adjust your settings.', $privateKeyPathAndFilename), 1446553054);
}
$googleCloud = new ServiceBuilder([
'keyFilePath' => $privateKeyPathAndFilename
]);
}
return $googleCloud->storage();
}
|
[
"public",
"function",
"create",
"(",
"$",
"credentialsProfileName",
"=",
"'default'",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"credentialProfiles",
"[",
"$",
"credentialsProfileName",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'The specified Google Cloud Storage credentials profile \"%s\" does not exist, please check your settings.'",
",",
"$",
"credentialsProfileName",
")",
",",
"1446553024",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"credentialProfiles",
"[",
"$",
"credentialsProfileName",
"]",
"[",
"'credentials'",
"]",
"[",
"'privateKeyJsonBase64Encoded'",
"]",
")",
")",
"{",
"$",
"googleCloud",
"=",
"new",
"ServiceBuilder",
"(",
"[",
"'keyFile'",
"=>",
"json_decode",
"(",
"base64_decode",
"(",
"$",
"this",
"->",
"credentialProfiles",
"[",
"$",
"credentialsProfileName",
"]",
"[",
"'credentials'",
"]",
"[",
"'privateKeyJsonBase64Encoded'",
"]",
")",
",",
"true",
")",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"credentialProfiles",
"[",
"$",
"credentialsProfileName",
"]",
"[",
"'credentials'",
"]",
"[",
"'privateKeyJsonPathAndFilename'",
"]",
",",
"0",
",",
"1",
")",
"!==",
"'/'",
")",
"{",
"$",
"privateKeyPathAndFilename",
"=",
"FLOW_PATH_ROOT",
".",
"$",
"this",
"->",
"credentialProfiles",
"[",
"$",
"credentialsProfileName",
"]",
"[",
"'credentials'",
"]",
"[",
"'privateKeyJsonPathAndFilename'",
"]",
";",
"}",
"else",
"{",
"$",
"privateKeyPathAndFilename",
"=",
"$",
"this",
"->",
"credentialProfiles",
"[",
"$",
"credentialsProfileName",
"]",
"[",
"'credentials'",
"]",
"[",
"'privateKeyJsonPathAndFilename'",
"]",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"privateKeyPathAndFilename",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'The Google Cloud Storage private key file \"%s\" does not exist. Either the file is missing or you need to adjust your settings.'",
",",
"$",
"privateKeyPathAndFilename",
")",
",",
"1446553054",
")",
";",
"}",
"$",
"googleCloud",
"=",
"new",
"ServiceBuilder",
"(",
"[",
"'keyFilePath'",
"=>",
"$",
"privateKeyPathAndFilename",
"]",
")",
";",
"}",
"return",
"$",
"googleCloud",
"->",
"storage",
"(",
")",
";",
"}"
] |
Creates a new Storage instance and authenticates against the Google API
@param string $credentialsProfileName
@return \Google\Cloud\Storage\StorageClient
@throws Exception
|
[
"Creates",
"a",
"new",
"Storage",
"instance",
"and",
"authenticates",
"against",
"the",
"Google",
"API"
] |
78c76b2a0eb10fa514bbae71f93f351ee58dacd3
|
https://github.com/flownative/flow-google-cloudstorage/blob/78c76b2a0eb10fa514bbae71f93f351ee58dacd3/Classes/StorageFactory.php#L43-L69
|
26,121
|
spiral/orm
|
source/Spiral/ORM/Schemas/Relations/ManyToManySchema.php
|
ManyToManySchema.pivotTable
|
protected function pivotTable(): string
{
if (!empty($this->option(Record::PIVOT_TABLE))) {
return $this->option(Record::PIVOT_TABLE);
}
$source = $this->definition->sourceContext();
$target = $this->definition->targetContext();
//Generating pivot table name
$names = [$source->getRole(), $target->getRole()];
asort($names);
return implode('_', $names) . static::PIVOT_POSTFIX;
}
|
php
|
protected function pivotTable(): string
{
if (!empty($this->option(Record::PIVOT_TABLE))) {
return $this->option(Record::PIVOT_TABLE);
}
$source = $this->definition->sourceContext();
$target = $this->definition->targetContext();
//Generating pivot table name
$names = [$source->getRole(), $target->getRole()];
asort($names);
return implode('_', $names) . static::PIVOT_POSTFIX;
}
|
[
"protected",
"function",
"pivotTable",
"(",
")",
":",
"string",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"option",
"(",
"Record",
"::",
"PIVOT_TABLE",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"option",
"(",
"Record",
"::",
"PIVOT_TABLE",
")",
";",
"}",
"$",
"source",
"=",
"$",
"this",
"->",
"definition",
"->",
"sourceContext",
"(",
")",
";",
"$",
"target",
"=",
"$",
"this",
"->",
"definition",
"->",
"targetContext",
"(",
")",
";",
"//Generating pivot table name",
"$",
"names",
"=",
"[",
"$",
"source",
"->",
"getRole",
"(",
")",
",",
"$",
"target",
"->",
"getRole",
"(",
")",
"]",
";",
"asort",
"(",
"$",
"names",
")",
";",
"return",
"implode",
"(",
"'_'",
",",
"$",
"names",
")",
".",
"static",
"::",
"PIVOT_POSTFIX",
";",
"}"
] |
Generate name of pivot table or fetch if from schema.
@return string
|
[
"Generate",
"name",
"of",
"pivot",
"table",
"or",
"fetch",
"if",
"from",
"schema",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/Relations/ManyToManySchema.php#L301-L315
|
26,122
|
robertlemke/RobertLemke.Plugin.Blog
|
Classes/Eel/FilterByReferenceOperation.php
|
FilterByReferenceOperation.evaluate
|
public function evaluate(FlowQuery $flowQuery, array $arguments) {
if (empty($arguments[0])) {
throw new FlowQueryException('filterByReference() needs reference property name by which nodes should be filtered', 1545778273);
}
if (empty($arguments[1])) {
throw new FlowQueryException('filterByReference() needs node reference by which nodes should be filtered', 1545778276);
}
/** @var NodeInterface $nodeReference */
list($filterByPropertyPath, $nodeReference) = $arguments;
$filteredNodes = [];
foreach ($flowQuery->getContext() as $node) {
/** @var NodeInterface $node */
$propertyValue = $node->getProperty($filterByPropertyPath);
if ($nodeReference === $propertyValue || (is_array($propertyValue) && in_array($nodeReference, $propertyValue, TRUE))) {
$filteredNodes[] = $node;
}
}
$flowQuery->setContext($filteredNodes);
}
|
php
|
public function evaluate(FlowQuery $flowQuery, array $arguments) {
if (empty($arguments[0])) {
throw new FlowQueryException('filterByReference() needs reference property name by which nodes should be filtered', 1545778273);
}
if (empty($arguments[1])) {
throw new FlowQueryException('filterByReference() needs node reference by which nodes should be filtered', 1545778276);
}
/** @var NodeInterface $nodeReference */
list($filterByPropertyPath, $nodeReference) = $arguments;
$filteredNodes = [];
foreach ($flowQuery->getContext() as $node) {
/** @var NodeInterface $node */
$propertyValue = $node->getProperty($filterByPropertyPath);
if ($nodeReference === $propertyValue || (is_array($propertyValue) && in_array($nodeReference, $propertyValue, TRUE))) {
$filteredNodes[] = $node;
}
}
$flowQuery->setContext($filteredNodes);
}
|
[
"public",
"function",
"evaluate",
"(",
"FlowQuery",
"$",
"flowQuery",
",",
"array",
"$",
"arguments",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"arguments",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"new",
"FlowQueryException",
"(",
"'filterByReference() needs reference property name by which nodes should be filtered'",
",",
"1545778273",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"arguments",
"[",
"1",
"]",
")",
")",
"{",
"throw",
"new",
"FlowQueryException",
"(",
"'filterByReference() needs node reference by which nodes should be filtered'",
",",
"1545778276",
")",
";",
"}",
"/** @var NodeInterface $nodeReference */",
"list",
"(",
"$",
"filterByPropertyPath",
",",
"$",
"nodeReference",
")",
"=",
"$",
"arguments",
";",
"$",
"filteredNodes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"flowQuery",
"->",
"getContext",
"(",
")",
"as",
"$",
"node",
")",
"{",
"/** @var NodeInterface $node */",
"$",
"propertyValue",
"=",
"$",
"node",
"->",
"getProperty",
"(",
"$",
"filterByPropertyPath",
")",
";",
"if",
"(",
"$",
"nodeReference",
"===",
"$",
"propertyValue",
"||",
"(",
"is_array",
"(",
"$",
"propertyValue",
")",
"&&",
"in_array",
"(",
"$",
"nodeReference",
",",
"$",
"propertyValue",
",",
"TRUE",
")",
")",
")",
"{",
"$",
"filteredNodes",
"[",
"]",
"=",
"$",
"node",
";",
"}",
"}",
"$",
"flowQuery",
"->",
"setContext",
"(",
"$",
"filteredNodes",
")",
";",
"}"
] |
First argument is property to filter by, must be of reference of references type.
Second is object to filter by, must be Node.
@param FlowQuery $flowQuery
@param array $arguments The arguments for this operation.
@return void
@throws FlowQueryException
@throws \Neos\ContentRepository\Exception\NodeException
|
[
"First",
"argument",
"is",
"property",
"to",
"filter",
"by",
"must",
"be",
"of",
"reference",
"of",
"references",
"type",
".",
"Second",
"is",
"object",
"to",
"filter",
"by",
"must",
"be",
"Node",
"."
] |
7780d7e37022056ebe31088c7917ecaad8881dde
|
https://github.com/robertlemke/RobertLemke.Plugin.Blog/blob/7780d7e37022056ebe31088c7917ecaad8881dde/Classes/Eel/FilterByReferenceOperation.php#L47-L68
|
26,123
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/ManyToMorphedRelation.php
|
ManyToMorphedRelation.getVariation
|
public function getVariation(string $variation): ManyToManyRelation
{
if (isset($this->nested[$variation])) {
return $this->nested[$variation];
}
if (!isset($this->schema[Record::MORPHED_ALIASES][$variation])) {
throw new RelationException("Undefined morphed variation '{$variation}'");
}
$class = $this->schema[Record::MORPHED_ALIASES][$variation];
$relation = new ManyToManyRelation(
$class,
$this->makeSchema($class),
$this->orm,
$this->orm->define($class, ORMInterface::R_ROLE_NAME)
);
return $this->nested[$variation] = $relation->withContext($this->parent, false);
}
|
php
|
public function getVariation(string $variation): ManyToManyRelation
{
if (isset($this->nested[$variation])) {
return $this->nested[$variation];
}
if (!isset($this->schema[Record::MORPHED_ALIASES][$variation])) {
throw new RelationException("Undefined morphed variation '{$variation}'");
}
$class = $this->schema[Record::MORPHED_ALIASES][$variation];
$relation = new ManyToManyRelation(
$class,
$this->makeSchema($class),
$this->orm,
$this->orm->define($class, ORMInterface::R_ROLE_NAME)
);
return $this->nested[$variation] = $relation->withContext($this->parent, false);
}
|
[
"public",
"function",
"getVariation",
"(",
"string",
"$",
"variation",
")",
":",
"ManyToManyRelation",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"nested",
"[",
"$",
"variation",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"nested",
"[",
"$",
"variation",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"MORPHED_ALIASES",
"]",
"[",
"$",
"variation",
"]",
")",
")",
"{",
"throw",
"new",
"RelationException",
"(",
"\"Undefined morphed variation '{$variation}'\"",
")",
";",
"}",
"$",
"class",
"=",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"MORPHED_ALIASES",
"]",
"[",
"$",
"variation",
"]",
";",
"$",
"relation",
"=",
"new",
"ManyToManyRelation",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"makeSchema",
"(",
"$",
"class",
")",
",",
"$",
"this",
"->",
"orm",
",",
"$",
"this",
"->",
"orm",
"->",
"define",
"(",
"$",
"class",
",",
"ORMInterface",
"::",
"R_ROLE_NAME",
")",
")",
";",
"return",
"$",
"this",
"->",
"nested",
"[",
"$",
"variation",
"]",
"=",
"$",
"relation",
"->",
"withContext",
"(",
"$",
"this",
"->",
"parent",
",",
"false",
")",
";",
"}"
] |
Get nested relation for a given variation.
@param string $variation
@return ManyToManyRelation
@throws RelationException
|
[
"Get",
"nested",
"relation",
"for",
"a",
"given",
"variation",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/ManyToMorphedRelation.php#L101-L121
|
26,124
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/ManyToMorphedRelation.php
|
ManyToMorphedRelation.makeSchema
|
protected function makeSchema(string $class): array
{
//Using as basement
$schema = $this->schema;
unset($schema[Record::MORPHED_ALIASES]);
//We do not have this information in morphed relation but it's required for ManyToMany
$schema[Record::WHERE] = [];
//This must be unified in future, for now we can fetch columns directly from there
$recordSchema = $this->orm->define($class, ORMInterface::R_SCHEMA);
$schema[Record::RELATION_COLUMNS] = array_keys($recordSchema[Record::SH_DEFAULTS]);
return $schema;
}
|
php
|
protected function makeSchema(string $class): array
{
//Using as basement
$schema = $this->schema;
unset($schema[Record::MORPHED_ALIASES]);
//We do not have this information in morphed relation but it's required for ManyToMany
$schema[Record::WHERE] = [];
//This must be unified in future, for now we can fetch columns directly from there
$recordSchema = $this->orm->define($class, ORMInterface::R_SCHEMA);
$schema[Record::RELATION_COLUMNS] = array_keys($recordSchema[Record::SH_DEFAULTS]);
return $schema;
}
|
[
"protected",
"function",
"makeSchema",
"(",
"string",
"$",
"class",
")",
":",
"array",
"{",
"//Using as basement",
"$",
"schema",
"=",
"$",
"this",
"->",
"schema",
";",
"unset",
"(",
"$",
"schema",
"[",
"Record",
"::",
"MORPHED_ALIASES",
"]",
")",
";",
"//We do not have this information in morphed relation but it's required for ManyToMany",
"$",
"schema",
"[",
"Record",
"::",
"WHERE",
"]",
"=",
"[",
"]",
";",
"//This must be unified in future, for now we can fetch columns directly from there",
"$",
"recordSchema",
"=",
"$",
"this",
"->",
"orm",
"->",
"define",
"(",
"$",
"class",
",",
"ORMInterface",
"::",
"R_SCHEMA",
")",
";",
"$",
"schema",
"[",
"Record",
"::",
"RELATION_COLUMNS",
"]",
"=",
"array_keys",
"(",
"$",
"recordSchema",
"[",
"Record",
"::",
"SH_DEFAULTS",
"]",
")",
";",
"return",
"$",
"schema",
";",
"}"
] |
Create relation schema for nested relation.
@param string $class
@return array
|
[
"Create",
"relation",
"schema",
"for",
"nested",
"relation",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/ManyToMorphedRelation.php#L182-L196
|
26,125
|
spiral/orm
|
source/Spiral/ORM/AbstractRecord.php
|
AbstractRecord.packChanges
|
protected function packChanges(bool $skipPrimary = false): array
{
if (!$this->hasChanges() && !$this->isSolid()) {
return [];
}
if ($this->isSolid()) {
//Solid record always updated as one big solid
$updates = $this->packValue();
} else {
//Updating each field individually
$updates = [];
foreach ($this->getFields(false) as $field => $value) {
//Handled by sub-accessor
if ($value instanceof RecordAccessorInterface) {
if ($value->hasChanges()) {
$updates[$field] = $value->compileUpdates($field);
continue;
}
$value = $value->packValue();
}
//Field change registered
if (array_key_exists($field, $this->changes)) {
$updates[$field] = $value;
}
}
}
if ($skipPrimary) {
unset($updates[$this->primaryColumn()]);
}
return $updates;
}
|
php
|
protected function packChanges(bool $skipPrimary = false): array
{
if (!$this->hasChanges() && !$this->isSolid()) {
return [];
}
if ($this->isSolid()) {
//Solid record always updated as one big solid
$updates = $this->packValue();
} else {
//Updating each field individually
$updates = [];
foreach ($this->getFields(false) as $field => $value) {
//Handled by sub-accessor
if ($value instanceof RecordAccessorInterface) {
if ($value->hasChanges()) {
$updates[$field] = $value->compileUpdates($field);
continue;
}
$value = $value->packValue();
}
//Field change registered
if (array_key_exists($field, $this->changes)) {
$updates[$field] = $value;
}
}
}
if ($skipPrimary) {
unset($updates[$this->primaryColumn()]);
}
return $updates;
}
|
[
"protected",
"function",
"packChanges",
"(",
"bool",
"$",
"skipPrimary",
"=",
"false",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasChanges",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isSolid",
"(",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isSolid",
"(",
")",
")",
"{",
"//Solid record always updated as one big solid",
"$",
"updates",
"=",
"$",
"this",
"->",
"packValue",
"(",
")",
";",
"}",
"else",
"{",
"//Updating each field individually",
"$",
"updates",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getFields",
"(",
"false",
")",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"//Handled by sub-accessor",
"if",
"(",
"$",
"value",
"instanceof",
"RecordAccessorInterface",
")",
"{",
"if",
"(",
"$",
"value",
"->",
"hasChanges",
"(",
")",
")",
"{",
"$",
"updates",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
"->",
"compileUpdates",
"(",
"$",
"field",
")",
";",
"continue",
";",
"}",
"$",
"value",
"=",
"$",
"value",
"->",
"packValue",
"(",
")",
";",
"}",
"//Field change registered",
"if",
"(",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"changes",
")",
")",
"{",
"$",
"updates",
"[",
"$",
"field",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"skipPrimary",
")",
"{",
"unset",
"(",
"$",
"updates",
"[",
"$",
"this",
"->",
"primaryColumn",
"(",
")",
"]",
")",
";",
"}",
"return",
"$",
"updates",
";",
"}"
] |
Create set of fields to be sent to UPDATE statement.
@param bool $skipPrimary Skip primary key
@return array
|
[
"Create",
"set",
"of",
"fields",
"to",
"be",
"sent",
"to",
"UPDATE",
"statement",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/AbstractRecord.php#L297-L332
|
26,126
|
rinvex/cortex-foundation
|
src/Http/Controllers/AbstractController.php
|
AbstractController.guessGuard
|
protected function guessGuard(): string
{
$accessarea = str_before(Route::currentRouteName(), '.');
$guard = str_plural(mb_strstr($accessarea, 'area', true));
return config('auth.guards.'.$guard) ? $guard : config('auth.defaults.guard');
}
|
php
|
protected function guessGuard(): string
{
$accessarea = str_before(Route::currentRouteName(), '.');
$guard = str_plural(mb_strstr($accessarea, 'area', true));
return config('auth.guards.'.$guard) ? $guard : config('auth.defaults.guard');
}
|
[
"protected",
"function",
"guessGuard",
"(",
")",
":",
"string",
"{",
"$",
"accessarea",
"=",
"str_before",
"(",
"Route",
"::",
"currentRouteName",
"(",
")",
",",
"'.'",
")",
";",
"$",
"guard",
"=",
"str_plural",
"(",
"mb_strstr",
"(",
"$",
"accessarea",
",",
"'area'",
",",
"true",
")",
")",
";",
"return",
"config",
"(",
"'auth.guards.'",
".",
"$",
"guard",
")",
"?",
"$",
"guard",
":",
"config",
"(",
"'auth.defaults.guard'",
")",
";",
"}"
] |
Guess guard from accessarea.
@return string
|
[
"Guess",
"guard",
"from",
"accessarea",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Http/Controllers/AbstractController.php#L73-L79
|
26,127
|
rinvex/cortex-foundation
|
src/Http/Controllers/AbstractController.php
|
AbstractController.guessPasswordResetBroker
|
protected function guessPasswordResetBroker(): string
{
$accessarea = str_before(Route::currentRouteName(), '.');
$passwordResetBroker = str_plural(mb_strstr($accessarea, 'area', true));
return config('auth.passwords.'.$passwordResetBroker) ? $passwordResetBroker : config('auth.defaults.passwords');
}
|
php
|
protected function guessPasswordResetBroker(): string
{
$accessarea = str_before(Route::currentRouteName(), '.');
$passwordResetBroker = str_plural(mb_strstr($accessarea, 'area', true));
return config('auth.passwords.'.$passwordResetBroker) ? $passwordResetBroker : config('auth.defaults.passwords');
}
|
[
"protected",
"function",
"guessPasswordResetBroker",
"(",
")",
":",
"string",
"{",
"$",
"accessarea",
"=",
"str_before",
"(",
"Route",
"::",
"currentRouteName",
"(",
")",
",",
"'.'",
")",
";",
"$",
"passwordResetBroker",
"=",
"str_plural",
"(",
"mb_strstr",
"(",
"$",
"accessarea",
",",
"'area'",
",",
"true",
")",
")",
";",
"return",
"config",
"(",
"'auth.passwords.'",
".",
"$",
"passwordResetBroker",
")",
"?",
"$",
"passwordResetBroker",
":",
"config",
"(",
"'auth.defaults.passwords'",
")",
";",
"}"
] |
Guess password reset broker from accessarea.
@return string
|
[
"Guess",
"password",
"reset",
"broker",
"from",
"accessarea",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Http/Controllers/AbstractController.php#L114-L120
|
26,128
|
rinvex/cortex-foundation
|
src/Http/Controllers/AbstractController.php
|
AbstractController.guessEmailVerificationBroker
|
protected function guessEmailVerificationBroker(): string
{
$accessarea = str_before(Route::currentRouteName(), '.');
$emailVerificationBroker = str_plural(mb_strstr($accessarea, 'area', true));
return config('auth.passwords.'.$emailVerificationBroker) ? $emailVerificationBroker : config('auth.defaults.passwords');
}
|
php
|
protected function guessEmailVerificationBroker(): string
{
$accessarea = str_before(Route::currentRouteName(), '.');
$emailVerificationBroker = str_plural(mb_strstr($accessarea, 'area', true));
return config('auth.passwords.'.$emailVerificationBroker) ? $emailVerificationBroker : config('auth.defaults.passwords');
}
|
[
"protected",
"function",
"guessEmailVerificationBroker",
"(",
")",
":",
"string",
"{",
"$",
"accessarea",
"=",
"str_before",
"(",
"Route",
"::",
"currentRouteName",
"(",
")",
",",
"'.'",
")",
";",
"$",
"emailVerificationBroker",
"=",
"str_plural",
"(",
"mb_strstr",
"(",
"$",
"accessarea",
",",
"'area'",
",",
"true",
")",
")",
";",
"return",
"config",
"(",
"'auth.passwords.'",
".",
"$",
"emailVerificationBroker",
")",
"?",
"$",
"emailVerificationBroker",
":",
"config",
"(",
"'auth.defaults.passwords'",
")",
";",
"}"
] |
Guess email verification broker from accessarea.
@return string
|
[
"Guess",
"email",
"verification",
"broker",
"from",
"accessarea",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Http/Controllers/AbstractController.php#L137-L143
|
26,129
|
spiral/orm
|
source/Spiral/ORM/Schemas/Relations/Traits/MorphedTrait.php
|
MorphedTrait.findOuter
|
protected function findOuter(SchemaBuilder $builder)
{
foreach ($this->findTargets($builder) as $schema) {
$outerTable = $builder->requestTable($schema->getTable(), $schema->getDatabase());
$outerKey = $this->option(Record::OUTER_KEY);
if ($outerKey == ORMInterface::R_PRIMARY_KEY) {
$outerKey = current($outerTable->getPrimaryKeys());
}
if (!$outerTable->hasColumn($outerKey)) {
throw new RelationSchemaException(sprintf("Outer key '%s'.'%s' (%s) does not exists",
$outerTable->getName(),
$outerKey,
$this->getDefinition()->getName()
));
}
return $outerTable->column($outerKey);
}
return null;
}
|
php
|
protected function findOuter(SchemaBuilder $builder)
{
foreach ($this->findTargets($builder) as $schema) {
$outerTable = $builder->requestTable($schema->getTable(), $schema->getDatabase());
$outerKey = $this->option(Record::OUTER_KEY);
if ($outerKey == ORMInterface::R_PRIMARY_KEY) {
$outerKey = current($outerTable->getPrimaryKeys());
}
if (!$outerTable->hasColumn($outerKey)) {
throw new RelationSchemaException(sprintf("Outer key '%s'.'%s' (%s) does not exists",
$outerTable->getName(),
$outerKey,
$this->getDefinition()->getName()
));
}
return $outerTable->column($outerKey);
}
return null;
}
|
[
"protected",
"function",
"findOuter",
"(",
"SchemaBuilder",
"$",
"builder",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"findTargets",
"(",
"$",
"builder",
")",
"as",
"$",
"schema",
")",
"{",
"$",
"outerTable",
"=",
"$",
"builder",
"->",
"requestTable",
"(",
"$",
"schema",
"->",
"getTable",
"(",
")",
",",
"$",
"schema",
"->",
"getDatabase",
"(",
")",
")",
";",
"$",
"outerKey",
"=",
"$",
"this",
"->",
"option",
"(",
"Record",
"::",
"OUTER_KEY",
")",
";",
"if",
"(",
"$",
"outerKey",
"==",
"ORMInterface",
"::",
"R_PRIMARY_KEY",
")",
"{",
"$",
"outerKey",
"=",
"current",
"(",
"$",
"outerTable",
"->",
"getPrimaryKeys",
"(",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"outerTable",
"->",
"hasColumn",
"(",
"$",
"outerKey",
")",
")",
"{",
"throw",
"new",
"RelationSchemaException",
"(",
"sprintf",
"(",
"\"Outer key '%s'.'%s' (%s) does not exists\"",
",",
"$",
"outerTable",
"->",
"getName",
"(",
")",
",",
"$",
"outerKey",
",",
"$",
"this",
"->",
"getDefinition",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"outerTable",
"->",
"column",
"(",
"$",
"outerKey",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Resolving outer key.
@param \Spiral\ORM\Schemas\SchemaBuilder $builder
@return \Spiral\Database\Schemas\Prototypes\AbstractColumn|null When no outer records found
NULL will be returned.
|
[
"Resolving",
"outer",
"key",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/Relations/Traits/MorphedTrait.php#L30-L52
|
26,130
|
spiral/orm
|
source/Spiral/ORM/Schemas/Relations/Traits/MorphedTrait.php
|
MorphedTrait.verifyOuter
|
protected function verifyOuter(SchemaBuilder $builder, AbstractColumn $column)
{
foreach ($this->findTargets($builder) as $schema) {
$outerTable = $builder->requestTable($schema->getTable(), $schema->getDatabase());
if (!$outerTable->hasColumn($column->getName())) {
//Column is missing
throw new RelationSchemaException(
"Unable to build morphed relation, outer key '{$column->getName()}' "
. "is missing in '{$outerTable->getName()}'"
);
}
if ($outerTable->column($column->getName())->phpType() != $column->phpType()) {
//Inconsistent type
throw new RelationSchemaException(
"Unable to build morphed relation, outer key '{$column->getName()}' "
. "has different type in '{$outerTable->getName()}'"
);
}
}
}
|
php
|
protected function verifyOuter(SchemaBuilder $builder, AbstractColumn $column)
{
foreach ($this->findTargets($builder) as $schema) {
$outerTable = $builder->requestTable($schema->getTable(), $schema->getDatabase());
if (!$outerTable->hasColumn($column->getName())) {
//Column is missing
throw new RelationSchemaException(
"Unable to build morphed relation, outer key '{$column->getName()}' "
. "is missing in '{$outerTable->getName()}'"
);
}
if ($outerTable->column($column->getName())->phpType() != $column->phpType()) {
//Inconsistent type
throw new RelationSchemaException(
"Unable to build morphed relation, outer key '{$column->getName()}' "
. "has different type in '{$outerTable->getName()}'"
);
}
}
}
|
[
"protected",
"function",
"verifyOuter",
"(",
"SchemaBuilder",
"$",
"builder",
",",
"AbstractColumn",
"$",
"column",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"findTargets",
"(",
"$",
"builder",
")",
"as",
"$",
"schema",
")",
"{",
"$",
"outerTable",
"=",
"$",
"builder",
"->",
"requestTable",
"(",
"$",
"schema",
"->",
"getTable",
"(",
")",
",",
"$",
"schema",
"->",
"getDatabase",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"outerTable",
"->",
"hasColumn",
"(",
"$",
"column",
"->",
"getName",
"(",
")",
")",
")",
"{",
"//Column is missing",
"throw",
"new",
"RelationSchemaException",
"(",
"\"Unable to build morphed relation, outer key '{$column->getName()}' \"",
".",
"\"is missing in '{$outerTable->getName()}'\"",
")",
";",
"}",
"if",
"(",
"$",
"outerTable",
"->",
"column",
"(",
"$",
"column",
"->",
"getName",
"(",
")",
")",
"->",
"phpType",
"(",
")",
"!=",
"$",
"column",
"->",
"phpType",
"(",
")",
")",
"{",
"//Inconsistent type",
"throw",
"new",
"RelationSchemaException",
"(",
"\"Unable to build morphed relation, outer key '{$column->getName()}' \"",
".",
"\"has different type in '{$outerTable->getName()}'\"",
")",
";",
"}",
"}",
"}"
] |
Make sure all tables have same outer key.
@param \Spiral\ORM\Schemas\SchemaBuilder $builder
@param \Spiral\Database\Schemas\Prototypes\AbstractColumn $column
@throws RelationSchemaException
|
[
"Make",
"sure",
"all",
"tables",
"have",
"same",
"outer",
"key",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/Relations/Traits/MorphedTrait.php#L62-L83
|
26,131
|
spiral/orm
|
source/Spiral/ORM/Schemas/Relations/Traits/MorphedTrait.php
|
MorphedTrait.findTargets
|
protected function findTargets(SchemaBuilder $builder): \Generator
{
foreach ($builder->getSchemas() as $schema) {
if (!is_a($schema->getClass(), $this->getDefinition()->getTarget(), true)) {
//Not our targets
continue;
}
yield $schema;
}
}
|
php
|
protected function findTargets(SchemaBuilder $builder): \Generator
{
foreach ($builder->getSchemas() as $schema) {
if (!is_a($schema->getClass(), $this->getDefinition()->getTarget(), true)) {
//Not our targets
continue;
}
yield $schema;
}
}
|
[
"protected",
"function",
"findTargets",
"(",
"SchemaBuilder",
"$",
"builder",
")",
":",
"\\",
"Generator",
"{",
"foreach",
"(",
"$",
"builder",
"->",
"getSchemas",
"(",
")",
"as",
"$",
"schema",
")",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"schema",
"->",
"getClass",
"(",
")",
",",
"$",
"this",
"->",
"getDefinition",
"(",
")",
"->",
"getTarget",
"(",
")",
",",
"true",
")",
")",
"{",
"//Not our targets",
"continue",
";",
"}",
"yield",
"$",
"schema",
";",
"}",
"}"
] |
Find all matched schemas.
@param \Spiral\ORM\Schemas\SchemaBuilder $builder
@return \Generator|\Spiral\ORM\Schemas\SchemaInterface[]
|
[
"Find",
"all",
"matched",
"schemas",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/Relations/Traits/MorphedTrait.php#L92-L101
|
26,132
|
swoft-cloud/swoft-rpc-server
|
src/Router/HandlerMapping.php
|
HandlerMapping.getHandler
|
public function getHandler(...$params): array
{
list($interfaceClass, $version, $method) = $params;
return $this->match($interfaceClass, $version, $method);
}
|
php
|
public function getHandler(...$params): array
{
list($interfaceClass, $version, $method) = $params;
return $this->match($interfaceClass, $version, $method);
}
|
[
"public",
"function",
"getHandler",
"(",
"...",
"$",
"params",
")",
":",
"array",
"{",
"list",
"(",
"$",
"interfaceClass",
",",
"$",
"version",
",",
"$",
"method",
")",
"=",
"$",
"params",
";",
"return",
"$",
"this",
"->",
"match",
"(",
"$",
"interfaceClass",
",",
"$",
"version",
",",
"$",
"method",
")",
";",
"}"
] |
Get handler from router
@param array ...$params
@return array
@throws \InvalidArgumentException
|
[
"Get",
"handler",
"from",
"router"
] |
527ce20421ad46919b16ebdcc12658f0e3807a07
|
https://github.com/swoft-cloud/swoft-rpc-server/blob/527ce20421ad46919b16ebdcc12658f0e3807a07/src/Router/HandlerMapping.php#L28-L32
|
26,133
|
swoft-cloud/swoft-rpc-server
|
src/Router/HandlerMapping.php
|
HandlerMapping.getServiceKey
|
private function getServiceKey(string $interfaceClass, string $version, string $method): string
{
return \sprintf('%s_%s_%s', $interfaceClass, $version, $method);
}
|
php
|
private function getServiceKey(string $interfaceClass, string $version, string $method): string
{
return \sprintf('%s_%s_%s', $interfaceClass, $version, $method);
}
|
[
"private",
"function",
"getServiceKey",
"(",
"string",
"$",
"interfaceClass",
",",
"string",
"$",
"version",
",",
"string",
"$",
"method",
")",
":",
"string",
"{",
"return",
"\\",
"sprintf",
"(",
"'%s_%s_%s'",
",",
"$",
"interfaceClass",
",",
"$",
"version",
",",
"$",
"method",
")",
";",
"}"
] |
Get service key
@param string $interfaceClass
@param string $version
@param string $method
@return string
|
[
"Get",
"service",
"key"
] |
527ce20421ad46919b16ebdcc12658f0e3807a07
|
https://github.com/swoft-cloud/swoft-rpc-server/blob/527ce20421ad46919b16ebdcc12658f0e3807a07/src/Router/HandlerMapping.php#L101-L104
|
26,134
|
spiral/orm
|
source/Spiral/ORM/Schemas/Relations/AbstractSchema.php
|
AbstractSchema.isConstrained
|
public function isConstrained()
{
$source = $this->definition->sourceContext();
$target = $this->definition->targetContext();
if (empty($target)) {
return false;
}
if ($source->getDatabase() != $target->getDatabase()) {
//Unable to create constrains for records in different databases
return false;
}
return $this->option(Record::CREATE_CONSTRAINT);
}
|
php
|
public function isConstrained()
{
$source = $this->definition->sourceContext();
$target = $this->definition->targetContext();
if (empty($target)) {
return false;
}
if ($source->getDatabase() != $target->getDatabase()) {
//Unable to create constrains for records in different databases
return false;
}
return $this->option(Record::CREATE_CONSTRAINT);
}
|
[
"public",
"function",
"isConstrained",
"(",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"definition",
"->",
"sourceContext",
"(",
")",
";",
"$",
"target",
"=",
"$",
"this",
"->",
"definition",
"->",
"targetContext",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"target",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"source",
"->",
"getDatabase",
"(",
")",
"!=",
"$",
"target",
"->",
"getDatabase",
"(",
")",
")",
"{",
"//Unable to create constrains for records in different databases",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"option",
"(",
"Record",
"::",
"CREATE_CONSTRAINT",
")",
";",
"}"
] |
Check if relation requests foreign key constraints to be created.
@return bool
|
[
"Check",
"if",
"relation",
"requests",
"foreign",
"key",
"constraints",
"to",
"be",
"created",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/Relations/AbstractSchema.php#L126-L140
|
26,135
|
spiral/orm
|
source/Spiral/ORM/Entities/Nodes/AbstractNode.php
|
AbstractNode.getReferences
|
public function getReferences(): array
{
if (empty($this->parent)) {
throw new NodeException("Unable to aggregate reference values, parent is missing");
}
if (empty($this->parent->references[$this->outerKey])) {
return [];
}
return array_keys($this->parent->references[$this->outerKey]);
}
|
php
|
public function getReferences(): array
{
if (empty($this->parent)) {
throw new NodeException("Unable to aggregate reference values, parent is missing");
}
if (empty($this->parent->references[$this->outerKey])) {
return [];
}
return array_keys($this->parent->references[$this->outerKey]);
}
|
[
"public",
"function",
"getReferences",
"(",
")",
":",
"array",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"parent",
")",
")",
"{",
"throw",
"new",
"NodeException",
"(",
"\"Unable to aggregate reference values, parent is missing\"",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"parent",
"->",
"references",
"[",
"$",
"this",
"->",
"outerKey",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"array_keys",
"(",
"$",
"this",
"->",
"parent",
"->",
"references",
"[",
"$",
"this",
"->",
"outerKey",
"]",
")",
";",
"}"
] |
Get list of reference key values aggregated by parent.
@return array
@throws NodeException
|
[
"Get",
"list",
"of",
"reference",
"key",
"values",
"aggregated",
"by",
"parent",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Nodes/AbstractNode.php#L118-L129
|
26,136
|
spiral/orm
|
source/Spiral/ORM/Entities/Nodes/AbstractNode.php
|
AbstractNode.registerNode
|
final public function registerNode(string $container, AbstractNode $node)
{
$node->container = $container;
$node->parent = $this;
$this->nodes[$container] = $node;
if (!empty($node->outerKey)) {
//This will make parser to aggregate such key in order to be used in later statement
$this->trackReference($node->outerKey);
}
}
|
php
|
final public function registerNode(string $container, AbstractNode $node)
{
$node->container = $container;
$node->parent = $this;
$this->nodes[$container] = $node;
if (!empty($node->outerKey)) {
//This will make parser to aggregate such key in order to be used in later statement
$this->trackReference($node->outerKey);
}
}
|
[
"final",
"public",
"function",
"registerNode",
"(",
"string",
"$",
"container",
",",
"AbstractNode",
"$",
"node",
")",
"{",
"$",
"node",
"->",
"container",
"=",
"$",
"container",
";",
"$",
"node",
"->",
"parent",
"=",
"$",
"this",
";",
"$",
"this",
"->",
"nodes",
"[",
"$",
"container",
"]",
"=",
"$",
"node",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"node",
"->",
"outerKey",
")",
")",
"{",
"//This will make parser to aggregate such key in order to be used in later statement",
"$",
"this",
"->",
"trackReference",
"(",
"$",
"node",
"->",
"outerKey",
")",
";",
"}",
"}"
] |
Register new node into NodeTree. Nodes used to convert flat results into tree representation
using reference aggregations.
@param string $container
@param AbstractNode $node
@throws NodeException
|
[
"Register",
"new",
"node",
"into",
"NodeTree",
".",
"Nodes",
"used",
"to",
"convert",
"flat",
"results",
"into",
"tree",
"representation",
"using",
"reference",
"aggregations",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Nodes/AbstractNode.php#L140-L151
|
26,137
|
spiral/orm
|
source/Spiral/ORM/Entities/Nodes/AbstractNode.php
|
AbstractNode.fetchNode
|
final public function fetchNode(string $container): AbstractNode
{
if (!isset($this->nodes[$container])) {
throw new NodeException("Undefined node {$container}");
}
return $this->nodes[$container];
}
|
php
|
final public function fetchNode(string $container): AbstractNode
{
if (!isset($this->nodes[$container])) {
throw new NodeException("Undefined node {$container}");
}
return $this->nodes[$container];
}
|
[
"final",
"public",
"function",
"fetchNode",
"(",
"string",
"$",
"container",
")",
":",
"AbstractNode",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"nodes",
"[",
"$",
"container",
"]",
")",
")",
"{",
"throw",
"new",
"NodeException",
"(",
"\"Undefined node {$container}\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"nodes",
"[",
"$",
"container",
"]",
";",
"}"
] |
Fetch sub node.
@param string $container
@return AbstractNode
@throws NodeException
|
[
"Fetch",
"sub",
"node",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Nodes/AbstractNode.php#L173-L180
|
26,138
|
spiral/orm
|
source/Spiral/ORM/Entities/Nodes/AbstractNode.php
|
AbstractNode.parseRow
|
final public function parseRow(int $dataOffset, array $row): int
{
//Fetching Node specific data from resulted row
$data = $this->fetchData($dataOffset, $row);
if ($this->deduplicate($data)) {
//Create reference keys
$this->collectReferences($data);
//Make sure that all nested relations are registered
$this->ensurePlaceholders($data);
//Add data into result set
$this->pushData($data);
} elseif (!empty($this->parent)) {
//Registering duplicates rows in each parent row
$this->pushData($data);
}
$innerOffset = 0;
foreach ($this->nodes as $container => $node) {
if ($node->joined) {
/**
* We are looking into branch like structure:
* node
* - node
* - node
* - node
* node
*
* This means offset has to be calculated using all nested nodes
*/
$innerColumns = $node->parseRow($this->countColumns + $dataOffset, $row);
//Counting next selection offset
$dataOffset += $innerColumns;
//Counting nested tree offset
$innerOffset += $innerColumns;
}
}
return $this->countColumns + $innerOffset;
}
|
php
|
final public function parseRow(int $dataOffset, array $row): int
{
//Fetching Node specific data from resulted row
$data = $this->fetchData($dataOffset, $row);
if ($this->deduplicate($data)) {
//Create reference keys
$this->collectReferences($data);
//Make sure that all nested relations are registered
$this->ensurePlaceholders($data);
//Add data into result set
$this->pushData($data);
} elseif (!empty($this->parent)) {
//Registering duplicates rows in each parent row
$this->pushData($data);
}
$innerOffset = 0;
foreach ($this->nodes as $container => $node) {
if ($node->joined) {
/**
* We are looking into branch like structure:
* node
* - node
* - node
* - node
* node
*
* This means offset has to be calculated using all nested nodes
*/
$innerColumns = $node->parseRow($this->countColumns + $dataOffset, $row);
//Counting next selection offset
$dataOffset += $innerColumns;
//Counting nested tree offset
$innerOffset += $innerColumns;
}
}
return $this->countColumns + $innerOffset;
}
|
[
"final",
"public",
"function",
"parseRow",
"(",
"int",
"$",
"dataOffset",
",",
"array",
"$",
"row",
")",
":",
"int",
"{",
"//Fetching Node specific data from resulted row",
"$",
"data",
"=",
"$",
"this",
"->",
"fetchData",
"(",
"$",
"dataOffset",
",",
"$",
"row",
")",
";",
"if",
"(",
"$",
"this",
"->",
"deduplicate",
"(",
"$",
"data",
")",
")",
"{",
"//Create reference keys",
"$",
"this",
"->",
"collectReferences",
"(",
"$",
"data",
")",
";",
"//Make sure that all nested relations are registered",
"$",
"this",
"->",
"ensurePlaceholders",
"(",
"$",
"data",
")",
";",
"//Add data into result set",
"$",
"this",
"->",
"pushData",
"(",
"$",
"data",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"parent",
")",
")",
"{",
"//Registering duplicates rows in each parent row",
"$",
"this",
"->",
"pushData",
"(",
"$",
"data",
")",
";",
"}",
"$",
"innerOffset",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"as",
"$",
"container",
"=>",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"joined",
")",
"{",
"/**\n * We are looking into branch like structure:\n * node\n * - node\n * - node\n * - node\n * node\n *\n * This means offset has to be calculated using all nested nodes\n */",
"$",
"innerColumns",
"=",
"$",
"node",
"->",
"parseRow",
"(",
"$",
"this",
"->",
"countColumns",
"+",
"$",
"dataOffset",
",",
"$",
"row",
")",
";",
"//Counting next selection offset",
"$",
"dataOffset",
"+=",
"$",
"innerColumns",
";",
"//Counting nested tree offset",
"$",
"innerOffset",
"+=",
"$",
"innerColumns",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"countColumns",
"+",
"$",
"innerOffset",
";",
"}"
] |
Parser result work, fetch data and mount it into parent tree.
@param int $dataOffset
@param array $row
@return int Must return number of handled columns.
|
[
"Parser",
"result",
"work",
"fetch",
"data",
"and",
"mount",
"it",
"into",
"parent",
"tree",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Nodes/AbstractNode.php#L190-L233
|
26,139
|
spiral/orm
|
source/Spiral/ORM/Entities/Nodes/AbstractNode.php
|
AbstractNode.fetchData
|
protected function fetchData(int $dataOffset, array $line): array
{
if (empty($this->columns)) {
return $line;
}
try {
//Combine column names with sliced piece of row
return array_combine(
$this->columns,
array_slice($line, $dataOffset, $this->countColumns)
);
} catch (\Exception $e) {
throw new NodeException("Unable to parse incoming row", $e->getCode(), $e);
}
}
|
php
|
protected function fetchData(int $dataOffset, array $line): array
{
if (empty($this->columns)) {
return $line;
}
try {
//Combine column names with sliced piece of row
return array_combine(
$this->columns,
array_slice($line, $dataOffset, $this->countColumns)
);
} catch (\Exception $e) {
throw new NodeException("Unable to parse incoming row", $e->getCode(), $e);
}
}
|
[
"protected",
"function",
"fetchData",
"(",
"int",
"$",
"dataOffset",
",",
"array",
"$",
"line",
")",
":",
"array",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"columns",
")",
")",
"{",
"return",
"$",
"line",
";",
"}",
"try",
"{",
"//Combine column names with sliced piece of row",
"return",
"array_combine",
"(",
"$",
"this",
"->",
"columns",
",",
"array_slice",
"(",
"$",
"line",
",",
"$",
"dataOffset",
",",
"$",
"this",
"->",
"countColumns",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"NodeException",
"(",
"\"Unable to parse incoming row\"",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"}"
] |
Fetch record columns from query row, must use data offset to slice required part of query.
@param int $dataOffset
@param array $line
@return array
|
[
"Fetch",
"record",
"columns",
"from",
"query",
"row",
"must",
"use",
"data",
"offset",
"to",
"slice",
"required",
"part",
"of",
"query",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Nodes/AbstractNode.php#L357-L372
|
26,140
|
spiral/orm
|
source/Spiral/ORM/Entities/Nodes/AbstractNode.php
|
AbstractNode.ensurePlaceholders
|
private function ensurePlaceholders(array &$data)
{
//Let's force placeholders for every sub loaded
foreach ($this->nodes as $name => $node) {
$data[$name] = $node instanceof ArrayInterface ? [] : null;
}
}
|
php
|
private function ensurePlaceholders(array &$data)
{
//Let's force placeholders for every sub loaded
foreach ($this->nodes as $name => $node) {
$data[$name] = $node instanceof ArrayInterface ? [] : null;
}
}
|
[
"private",
"function",
"ensurePlaceholders",
"(",
"array",
"&",
"$",
"data",
")",
"{",
"//Let's force placeholders for every sub loaded",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"as",
"$",
"name",
"=>",
"$",
"node",
")",
"{",
"$",
"data",
"[",
"$",
"name",
"]",
"=",
"$",
"node",
"instanceof",
"ArrayInterface",
"?",
"[",
"]",
":",
"null",
";",
"}",
"}"
] |
Create placeholders for each of sub nodes.
@param array $data
|
[
"Create",
"placeholders",
"for",
"each",
"of",
"sub",
"nodes",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Nodes/AbstractNode.php#L398-L404
|
26,141
|
spiral/orm
|
source/Spiral/ORM/Entities/Nodes/AbstractNode.php
|
AbstractNode.trackReference
|
private function trackReference(string $key)
{
if (!in_array($key, $this->columns)) {
throw new NodeException("Unable to create reference, key {$key} does not exist");
}
if (!in_array($key, $this->trackReferences)) {
//We are only tracking unique references
$this->trackReferences[] = $key;
}
}
|
php
|
private function trackReference(string $key)
{
if (!in_array($key, $this->columns)) {
throw new NodeException("Unable to create reference, key {$key} does not exist");
}
if (!in_array($key, $this->trackReferences)) {
//We are only tracking unique references
$this->trackReferences[] = $key;
}
}
|
[
"private",
"function",
"trackReference",
"(",
"string",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"columns",
")",
")",
"{",
"throw",
"new",
"NodeException",
"(",
"\"Unable to create reference, key {$key} does not exist\"",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"trackReferences",
")",
")",
"{",
"//We are only tracking unique references",
"$",
"this",
"->",
"trackReferences",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}"
] |
Add key to be tracked
@param string $key
@throws NodeException
|
[
"Add",
"key",
"to",
"be",
"tracked"
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Nodes/AbstractNode.php#L413-L423
|
26,142
|
spiral/orm
|
source/Spiral/ORM/Entities/Loaders/RootLoader.php
|
RootLoader.withColumns
|
public function withColumns(array $columns): self
{
$loader = clone $this;
$loader->columns = array_merge(
[$loader->schema[Record::SH_PRIMARY_KEY]],
$columns
);
return $loader;
}
|
php
|
public function withColumns(array $columns): self
{
$loader = clone $this;
$loader->columns = array_merge(
[$loader->schema[Record::SH_PRIMARY_KEY]],
$columns
);
return $loader;
}
|
[
"public",
"function",
"withColumns",
"(",
"array",
"$",
"columns",
")",
":",
"self",
"{",
"$",
"loader",
"=",
"clone",
"$",
"this",
";",
"$",
"loader",
"->",
"columns",
"=",
"array_merge",
"(",
"[",
"$",
"loader",
"->",
"schema",
"[",
"Record",
"::",
"SH_PRIMARY_KEY",
"]",
"]",
",",
"$",
"columns",
")",
";",
"return",
"$",
"loader",
";",
"}"
] |
Columns to be selected, please note, primary will always be included, DO not include
column aliases in here, aliases will be added automatically. Creates new loader tree copy.
@param array $columns
@return RootLoader
|
[
"Columns",
"to",
"be",
"selected",
"please",
"note",
"primary",
"will",
"always",
"be",
"included",
"DO",
"not",
"include",
"column",
"aliases",
"in",
"here",
"aliases",
"will",
"be",
"added",
"automatically",
".",
"Creates",
"new",
"loader",
"tree",
"copy",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Loaders/RootLoader.php#L70-L79
|
26,143
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/MultipleRelation.php
|
MultipleRelation.matchOne
|
public function matchOne($query)
{
foreach ($this->loadData(true)->instances as $instance) {
if ($this->match($instance, $query)) {
return $instance;
}
}
return null;
}
|
php
|
public function matchOne($query)
{
foreach ($this->loadData(true)->instances as $instance) {
if ($this->match($instance, $query)) {
return $instance;
}
}
return null;
}
|
[
"public",
"function",
"matchOne",
"(",
"$",
"query",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"loadData",
"(",
"true",
")",
"->",
"instances",
"as",
"$",
"instance",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"match",
"(",
"$",
"instance",
",",
"$",
"query",
")",
")",
"{",
"return",
"$",
"instance",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Fine one entity for a given query or return null. Method will autoload data.
Example: ->matchOne(['value' => 'something', ...]);
@param array|RecordInterface|mixed $query Fields, entity or PK.
@return RecordInterface|null
|
[
"Fine",
"one",
"entity",
"for",
"a",
"given",
"query",
"or",
"return",
"null",
".",
"Method",
"will",
"autoload",
"data",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/MultipleRelation.php#L108-L117
|
26,144
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/MultipleRelation.php
|
MultipleRelation.matchMultiple
|
public function matchMultiple($query)
{
$result = [];
foreach ($this->loadData(true)->instances as $instance) {
if ($this->match($instance, $query)) {
$result[] = $instance;
}
}
return new \ArrayIterator($result);
}
|
php
|
public function matchMultiple($query)
{
$result = [];
foreach ($this->loadData(true)->instances as $instance) {
if ($this->match($instance, $query)) {
$result[] = $instance;
}
}
return new \ArrayIterator($result);
}
|
[
"public",
"function",
"matchMultiple",
"(",
"$",
"query",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"loadData",
"(",
"true",
")",
"->",
"instances",
"as",
"$",
"instance",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"match",
"(",
"$",
"instance",
",",
"$",
"query",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"instance",
";",
"}",
"}",
"return",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"result",
")",
";",
"}"
] |
Return only instances matched given query, performed in memory! Only simple conditions are
allowed. Not "find" due trademark violation. Method will autoload data.
Example: ->matchMultiple(['value' => 'something', ...]);
@param array|RecordInterface|mixed $query Fields, entity or PK.
@return \ArrayIterator
|
[
"Return",
"only",
"instances",
"matched",
"given",
"query",
"performed",
"in",
"memory!",
"Only",
"simple",
"conditions",
"are",
"allowed",
".",
"Not",
"find",
"due",
"trademark",
"violation",
".",
"Method",
"will",
"autoload",
"data",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/MultipleRelation.php#L129-L139
|
26,145
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/MultipleRelation.php
|
MultipleRelation.initInstances
|
protected function initInstances(): self
{
if (is_array($this->data) && !empty($this->data)) {
//Iterates and instantiate records
$iterator = new RecordIterator($this->data, $this->class, $this->orm);
foreach ($iterator as $item) {
if (in_array($item, $this->instances, true)) {
//Skip duplicates
continue;
}
$this->instances[] = $item;
}
}
//Memory free
$this->data = null;
return $this;
}
|
php
|
protected function initInstances(): self
{
if (is_array($this->data) && !empty($this->data)) {
//Iterates and instantiate records
$iterator = new RecordIterator($this->data, $this->class, $this->orm);
foreach ($iterator as $item) {
if (in_array($item, $this->instances, true)) {
//Skip duplicates
continue;
}
$this->instances[] = $item;
}
}
//Memory free
$this->data = null;
return $this;
}
|
[
"protected",
"function",
"initInstances",
"(",
")",
":",
"self",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"//Iterates and instantiate records",
"$",
"iterator",
"=",
"new",
"RecordIterator",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"this",
"->",
"class",
",",
"$",
"this",
"->",
"orm",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"instances",
",",
"true",
")",
")",
"{",
"//Skip duplicates",
"continue",
";",
"}",
"$",
"this",
"->",
"instances",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"//Memory free",
"$",
"this",
"->",
"data",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}"
] |
Init pre-loaded data.
@return HasManyRelation|self
|
[
"Init",
"pre",
"-",
"loaded",
"data",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/MultipleRelation.php#L174-L194
|
26,146
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/Traits/MatchTrait.php
|
MatchTrait.match
|
protected function match(RecordInterface $record, $query): bool
{
if ($record === $query) {
//Strict search
return true;
}
//Primary key comparision
if (is_scalar($query) && $record->primaryKey() == $query) {
return true;
}
//Record based comparision
if ($query instanceof RecordInterface) {
//Matched by PK (assuming both same class)
if (!empty($query->primaryKey()) && $query->primaryKey() == $record->primaryKey()) {
return true;
}
//Matched by content (this is a bit tricky!)
if ($record->packValue() == $query->packValue()) {
return true;
}
return false;
}
//Field intersection
if (is_array($query) && array_intersect_assoc($record->packValue(), $query) == $query) {
return true;
}
return false;
}
|
php
|
protected function match(RecordInterface $record, $query): bool
{
if ($record === $query) {
//Strict search
return true;
}
//Primary key comparision
if (is_scalar($query) && $record->primaryKey() == $query) {
return true;
}
//Record based comparision
if ($query instanceof RecordInterface) {
//Matched by PK (assuming both same class)
if (!empty($query->primaryKey()) && $query->primaryKey() == $record->primaryKey()) {
return true;
}
//Matched by content (this is a bit tricky!)
if ($record->packValue() == $query->packValue()) {
return true;
}
return false;
}
//Field intersection
if (is_array($query) && array_intersect_assoc($record->packValue(), $query) == $query) {
return true;
}
return false;
}
|
[
"protected",
"function",
"match",
"(",
"RecordInterface",
"$",
"record",
",",
"$",
"query",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"record",
"===",
"$",
"query",
")",
"{",
"//Strict search",
"return",
"true",
";",
"}",
"//Primary key comparision",
"if",
"(",
"is_scalar",
"(",
"$",
"query",
")",
"&&",
"$",
"record",
"->",
"primaryKey",
"(",
")",
"==",
"$",
"query",
")",
"{",
"return",
"true",
";",
"}",
"//Record based comparision",
"if",
"(",
"$",
"query",
"instanceof",
"RecordInterface",
")",
"{",
"//Matched by PK (assuming both same class)",
"if",
"(",
"!",
"empty",
"(",
"$",
"query",
"->",
"primaryKey",
"(",
")",
")",
"&&",
"$",
"query",
"->",
"primaryKey",
"(",
")",
"==",
"$",
"record",
"->",
"primaryKey",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"//Matched by content (this is a bit tricky!)",
"if",
"(",
"$",
"record",
"->",
"packValue",
"(",
")",
"==",
"$",
"query",
"->",
"packValue",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}",
"//Field intersection",
"if",
"(",
"is_array",
"(",
"$",
"query",
")",
"&&",
"array_intersect_assoc",
"(",
"$",
"record",
"->",
"packValue",
"(",
")",
",",
"$",
"query",
")",
"==",
"$",
"query",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Match entity by field intersection, instance values or primary key.
@param RecordInterface $record
@param RecordInterface|array|mixed $query
@return bool
|
[
"Match",
"entity",
"by",
"field",
"intersection",
"instance",
"values",
"or",
"primary",
"key",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/Traits/MatchTrait.php#L25-L58
|
26,147
|
spiral/orm
|
source/Spiral/ORM/ORM.php
|
ORM.schemaBuilder
|
public function schemaBuilder(bool $locate = true): SchemaBuilder
{
/**
* @var SchemaBuilder $builder
*/
$builder = $this->getFactory()->make(SchemaBuilder::class, ['manager' => $this->manager]);
if ($locate) {
foreach ($this->locator->locateSchemas() as $schema) {
$builder->addSchema($schema);
}
foreach ($this->locator->locateSources() as $class => $source) {
$builder->addSource($class, $source);
}
}
return $builder;
}
|
php
|
public function schemaBuilder(bool $locate = true): SchemaBuilder
{
/**
* @var SchemaBuilder $builder
*/
$builder = $this->getFactory()->make(SchemaBuilder::class, ['manager' => $this->manager]);
if ($locate) {
foreach ($this->locator->locateSchemas() as $schema) {
$builder->addSchema($schema);
}
foreach ($this->locator->locateSources() as $class => $source) {
$builder->addSource($class, $source);
}
}
return $builder;
}
|
[
"public",
"function",
"schemaBuilder",
"(",
"bool",
"$",
"locate",
"=",
"true",
")",
":",
"SchemaBuilder",
"{",
"/**\n * @var SchemaBuilder $builder\n */",
"$",
"builder",
"=",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"make",
"(",
"SchemaBuilder",
"::",
"class",
",",
"[",
"'manager'",
"=>",
"$",
"this",
"->",
"manager",
"]",
")",
";",
"if",
"(",
"$",
"locate",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"locator",
"->",
"locateSchemas",
"(",
")",
"as",
"$",
"schema",
")",
"{",
"$",
"builder",
"->",
"addSchema",
"(",
"$",
"schema",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"locator",
"->",
"locateSources",
"(",
")",
"as",
"$",
"class",
"=>",
"$",
"source",
")",
"{",
"$",
"builder",
"->",
"addSource",
"(",
"$",
"class",
",",
"$",
"source",
")",
";",
"}",
"}",
"return",
"$",
"builder",
";",
"}"
] |
Create instance of ORM SchemaBuilder.
@param bool $locate Set to true to automatically locate available records and record sources
sources in a project files (based on tokenizer scope).
@return SchemaBuilder
@throws SchemaException
|
[
"Create",
"instance",
"of",
"ORM",
"SchemaBuilder",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/ORM.php#L158-L176
|
26,148
|
spiral/orm
|
source/Spiral/ORM/ORM.php
|
ORM.getFactory
|
protected function getFactory(): FactoryInterface
{
if ($this->container instanceof FactoryInterface) {
return $this->container;
}
return $this->container->get(FactoryInterface::class);
}
|
php
|
protected function getFactory(): FactoryInterface
{
if ($this->container instanceof FactoryInterface) {
return $this->container;
}
return $this->container->get(FactoryInterface::class);
}
|
[
"protected",
"function",
"getFactory",
"(",
")",
":",
"FactoryInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"container",
"instanceof",
"FactoryInterface",
")",
"{",
"return",
"$",
"this",
"->",
"container",
";",
"}",
"return",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"FactoryInterface",
"::",
"class",
")",
";",
"}"
] |
Get ODM specific factory.
@return FactoryInterface
|
[
"Get",
"ODM",
"specific",
"factory",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/ORM.php#L429-L436
|
26,149
|
robertlemke/RobertLemke.Plugin.Blog
|
Classes/Controller/CommentController.php
|
CommentController.createAction
|
public function createAction(NodeInterface $postNode, NodeTemplate $newComment)
{
# Workaround until we can validate node templates properly:
if (strlen($newComment->getProperty('author')) < 2) {
$this->throwStatus(400, 'Your comment was NOT created - please specify your name.');
}
if (filter_var($newComment->getProperty('emailAddress'), FILTER_VALIDATE_EMAIL) === false) {
$this->throwStatus(400, 'Your comment was NOT created - you must specify a valid email address.');
}
if (strlen($newComment->getProperty('text')) < 5) {
$this->throwStatus(400, 'Your comment was NOT created - it was too short.');
}
$newComment->setProperty('text', filter_var($newComment->getProperty('text'), FILTER_SANITIZE_STRIPPED));
$newComment->setProperty('author', filter_var($newComment->getProperty('author'), FILTER_SANITIZE_STRIPPED));
$newComment->setProperty('emailAddress', filter_var($newComment->getProperty('emailAddress'), FILTER_SANITIZE_STRIPPED));
$commentNode = $postNode->getNode('comments')->createNodeFromTemplate($newComment, uniqid('comment-'));
$commentNode->setProperty('spam', false);
$commentNode->setProperty('datePublished', new \DateTime());
if ($this->akismetService->isCommentSpam('', $commentNode->getProperty('text'), 'comment', $commentNode->getProperty('author'), $commentNode->getProperty('emailAddress'))) {
$commentNode->setProperty('spam', true);
}
$this->emitCommentCreated($commentNode, $postNode);
$this->response->setStatus(201);
return 'Thank you for your comment!';
}
|
php
|
public function createAction(NodeInterface $postNode, NodeTemplate $newComment)
{
# Workaround until we can validate node templates properly:
if (strlen($newComment->getProperty('author')) < 2) {
$this->throwStatus(400, 'Your comment was NOT created - please specify your name.');
}
if (filter_var($newComment->getProperty('emailAddress'), FILTER_VALIDATE_EMAIL) === false) {
$this->throwStatus(400, 'Your comment was NOT created - you must specify a valid email address.');
}
if (strlen($newComment->getProperty('text')) < 5) {
$this->throwStatus(400, 'Your comment was NOT created - it was too short.');
}
$newComment->setProperty('text', filter_var($newComment->getProperty('text'), FILTER_SANITIZE_STRIPPED));
$newComment->setProperty('author', filter_var($newComment->getProperty('author'), FILTER_SANITIZE_STRIPPED));
$newComment->setProperty('emailAddress', filter_var($newComment->getProperty('emailAddress'), FILTER_SANITIZE_STRIPPED));
$commentNode = $postNode->getNode('comments')->createNodeFromTemplate($newComment, uniqid('comment-'));
$commentNode->setProperty('spam', false);
$commentNode->setProperty('datePublished', new \DateTime());
if ($this->akismetService->isCommentSpam('', $commentNode->getProperty('text'), 'comment', $commentNode->getProperty('author'), $commentNode->getProperty('emailAddress'))) {
$commentNode->setProperty('spam', true);
}
$this->emitCommentCreated($commentNode, $postNode);
$this->response->setStatus(201);
return 'Thank you for your comment!';
}
|
[
"public",
"function",
"createAction",
"(",
"NodeInterface",
"$",
"postNode",
",",
"NodeTemplate",
"$",
"newComment",
")",
"{",
"# Workaround until we can validate node templates properly:",
"if",
"(",
"strlen",
"(",
"$",
"newComment",
"->",
"getProperty",
"(",
"'author'",
")",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"throwStatus",
"(",
"400",
",",
"'Your comment was NOT created - please specify your name.'",
")",
";",
"}",
"if",
"(",
"filter_var",
"(",
"$",
"newComment",
"->",
"getProperty",
"(",
"'emailAddress'",
")",
",",
"FILTER_VALIDATE_EMAIL",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"throwStatus",
"(",
"400",
",",
"'Your comment was NOT created - you must specify a valid email address.'",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"newComment",
"->",
"getProperty",
"(",
"'text'",
")",
")",
"<",
"5",
")",
"{",
"$",
"this",
"->",
"throwStatus",
"(",
"400",
",",
"'Your comment was NOT created - it was too short.'",
")",
";",
"}",
"$",
"newComment",
"->",
"setProperty",
"(",
"'text'",
",",
"filter_var",
"(",
"$",
"newComment",
"->",
"getProperty",
"(",
"'text'",
")",
",",
"FILTER_SANITIZE_STRIPPED",
")",
")",
";",
"$",
"newComment",
"->",
"setProperty",
"(",
"'author'",
",",
"filter_var",
"(",
"$",
"newComment",
"->",
"getProperty",
"(",
"'author'",
")",
",",
"FILTER_SANITIZE_STRIPPED",
")",
")",
";",
"$",
"newComment",
"->",
"setProperty",
"(",
"'emailAddress'",
",",
"filter_var",
"(",
"$",
"newComment",
"->",
"getProperty",
"(",
"'emailAddress'",
")",
",",
"FILTER_SANITIZE_STRIPPED",
")",
")",
";",
"$",
"commentNode",
"=",
"$",
"postNode",
"->",
"getNode",
"(",
"'comments'",
")",
"->",
"createNodeFromTemplate",
"(",
"$",
"newComment",
",",
"uniqid",
"(",
"'comment-'",
")",
")",
";",
"$",
"commentNode",
"->",
"setProperty",
"(",
"'spam'",
",",
"false",
")",
";",
"$",
"commentNode",
"->",
"setProperty",
"(",
"'datePublished'",
",",
"new",
"\\",
"DateTime",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"akismetService",
"->",
"isCommentSpam",
"(",
"''",
",",
"$",
"commentNode",
"->",
"getProperty",
"(",
"'text'",
")",
",",
"'comment'",
",",
"$",
"commentNode",
"->",
"getProperty",
"(",
"'author'",
")",
",",
"$",
"commentNode",
"->",
"getProperty",
"(",
"'emailAddress'",
")",
")",
")",
"{",
"$",
"commentNode",
"->",
"setProperty",
"(",
"'spam'",
",",
"true",
")",
";",
"}",
"$",
"this",
"->",
"emitCommentCreated",
"(",
"$",
"commentNode",
",",
"$",
"postNode",
")",
";",
"$",
"this",
"->",
"response",
"->",
"setStatus",
"(",
"201",
")",
";",
"return",
"'Thank you for your comment!'",
";",
"}"
] |
Creates a new comment
@param NodeInterface $postNode The post node which will contain the new comment
@param NodeTemplate<RobertLemke.Plugin.Blog:Comment> $newComment
@return string
|
[
"Creates",
"a",
"new",
"comment"
] |
7780d7e37022056ebe31088c7917ecaad8881dde
|
https://github.com/robertlemke/RobertLemke.Plugin.Blog/blob/7780d7e37022056ebe31088c7917ecaad8881dde/Classes/Controller/CommentController.php#L48-L79
|
26,150
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/AbstractRelation.php
|
AbstractRelation.primaryColumnOf
|
protected function primaryColumnOf(RecordInterface $record): string
{
return $this->orm->define(get_class($record), ORMInterface::R_PRIMARY_KEY);
}
|
php
|
protected function primaryColumnOf(RecordInterface $record): string
{
return $this->orm->define(get_class($record), ORMInterface::R_PRIMARY_KEY);
}
|
[
"protected",
"function",
"primaryColumnOf",
"(",
"RecordInterface",
"$",
"record",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"orm",
"->",
"define",
"(",
"get_class",
"(",
"$",
"record",
")",
",",
"ORMInterface",
"::",
"R_PRIMARY_KEY",
")",
";",
"}"
] |
Get primary key column
@param RecordInterface $record
@return string
|
[
"Get",
"primary",
"key",
"column"
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/AbstractRelation.php#L140-L143
|
26,151
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php
|
ManyToManyRelation.getPivot
|
public function getPivot(RecordInterface $record): array
{
if (empty($matched = $this->matchOne($record))) {
return [];
}
return $this->pivotData->offsetGet($matched);
}
|
php
|
public function getPivot(RecordInterface $record): array
{
if (empty($matched = $this->matchOne($record))) {
return [];
}
return $this->pivotData->offsetGet($matched);
}
|
[
"public",
"function",
"getPivot",
"(",
"RecordInterface",
"$",
"record",
")",
":",
"array",
"{",
"if",
"(",
"empty",
"(",
"$",
"matched",
"=",
"$",
"this",
"->",
"matchOne",
"(",
"$",
"record",
")",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"pivotData",
"->",
"offsetGet",
"(",
"$",
"matched",
")",
";",
"}"
] |
Get pivot data associated with specific instance.
@param RecordInterface $record
@return array
|
[
"Get",
"pivot",
"data",
"associated",
"with",
"specific",
"instance",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php#L150-L157
|
26,152
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php
|
ManyToManyRelation.link
|
public function link(RecordInterface $record, array $pivotData = []): self
{
$this->loadData(true);
$this->assertValid($record);
$this->assertPivot($pivotData);
//Ensure reference
$record = $this->matchOne($record) ?? $record;
if (in_array($record, $this->instances, true)) {
//Merging pivot data
$this->pivotData->offsetSet($record, $pivotData + $this->getPivot($record));
if (!in_array($record, $this->updated, true) && !in_array($record, $this->scheduled, true)) {
//Indicating that record pivot data has been changed
$this->updated[] = $record;
}
return $this;
}
//New association
$this->instances[] = $record;
$this->scheduled[] = $record;
$this->pivotData->offsetSet($record, $pivotData);
return $this;
}
|
php
|
public function link(RecordInterface $record, array $pivotData = []): self
{
$this->loadData(true);
$this->assertValid($record);
$this->assertPivot($pivotData);
//Ensure reference
$record = $this->matchOne($record) ?? $record;
if (in_array($record, $this->instances, true)) {
//Merging pivot data
$this->pivotData->offsetSet($record, $pivotData + $this->getPivot($record));
if (!in_array($record, $this->updated, true) && !in_array($record, $this->scheduled, true)) {
//Indicating that record pivot data has been changed
$this->updated[] = $record;
}
return $this;
}
//New association
$this->instances[] = $record;
$this->scheduled[] = $record;
$this->pivotData->offsetSet($record, $pivotData);
return $this;
}
|
[
"public",
"function",
"link",
"(",
"RecordInterface",
"$",
"record",
",",
"array",
"$",
"pivotData",
"=",
"[",
"]",
")",
":",
"self",
"{",
"$",
"this",
"->",
"loadData",
"(",
"true",
")",
";",
"$",
"this",
"->",
"assertValid",
"(",
"$",
"record",
")",
";",
"$",
"this",
"->",
"assertPivot",
"(",
"$",
"pivotData",
")",
";",
"//Ensure reference",
"$",
"record",
"=",
"$",
"this",
"->",
"matchOne",
"(",
"$",
"record",
")",
"??",
"$",
"record",
";",
"if",
"(",
"in_array",
"(",
"$",
"record",
",",
"$",
"this",
"->",
"instances",
",",
"true",
")",
")",
"{",
"//Merging pivot data",
"$",
"this",
"->",
"pivotData",
"->",
"offsetSet",
"(",
"$",
"record",
",",
"$",
"pivotData",
"+",
"$",
"this",
"->",
"getPivot",
"(",
"$",
"record",
")",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"record",
",",
"$",
"this",
"->",
"updated",
",",
"true",
")",
"&&",
"!",
"in_array",
"(",
"$",
"record",
",",
"$",
"this",
"->",
"scheduled",
",",
"true",
")",
")",
"{",
"//Indicating that record pivot data has been changed",
"$",
"this",
"->",
"updated",
"[",
"]",
"=",
"$",
"record",
";",
"}",
"return",
"$",
"this",
";",
"}",
"//New association",
"$",
"this",
"->",
"instances",
"[",
"]",
"=",
"$",
"record",
";",
"$",
"this",
"->",
"scheduled",
"[",
"]",
"=",
"$",
"record",
";",
"$",
"this",
"->",
"pivotData",
"->",
"offsetSet",
"(",
"$",
"record",
",",
"$",
"pivotData",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Link record with parent entity. Only record instances is accepted.
Attention, attached instances MIGHT be de-referenced IF parent object was reselected in a
different scope.
@param RecordInterface $record
@param array $pivotData
@return self
@throws RelationException
|
[
"Link",
"record",
"with",
"parent",
"entity",
".",
"Only",
"record",
"instances",
"is",
"accepted",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php#L172-L199
|
26,153
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php
|
ManyToManyRelation.unlink
|
public function unlink(RecordInterface $record): self
{
$this->loadData(true);
//Ensure reference
$record = $this->matchOne($record) ?? $record;
foreach ($this->instances as $index => $linked) {
if ($this->match($linked, $record)) {
//Removing locally
unset($this->instances[$index]);
if (!in_array($linked, $this->scheduled, true) || !$this->autoload) {
//Scheduling unlink in db when we know relation OR partial mode is on
$this->unlinked[] = $linked;
}
break;
}
}
$this->instances = array_values($this->instances);
return $this;
}
|
php
|
public function unlink(RecordInterface $record): self
{
$this->loadData(true);
//Ensure reference
$record = $this->matchOne($record) ?? $record;
foreach ($this->instances as $index => $linked) {
if ($this->match($linked, $record)) {
//Removing locally
unset($this->instances[$index]);
if (!in_array($linked, $this->scheduled, true) || !$this->autoload) {
//Scheduling unlink in db when we know relation OR partial mode is on
$this->unlinked[] = $linked;
}
break;
}
}
$this->instances = array_values($this->instances);
return $this;
}
|
[
"public",
"function",
"unlink",
"(",
"RecordInterface",
"$",
"record",
")",
":",
"self",
"{",
"$",
"this",
"->",
"loadData",
"(",
"true",
")",
";",
"//Ensure reference",
"$",
"record",
"=",
"$",
"this",
"->",
"matchOne",
"(",
"$",
"record",
")",
"??",
"$",
"record",
";",
"foreach",
"(",
"$",
"this",
"->",
"instances",
"as",
"$",
"index",
"=>",
"$",
"linked",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"match",
"(",
"$",
"linked",
",",
"$",
"record",
")",
")",
"{",
"//Removing locally",
"unset",
"(",
"$",
"this",
"->",
"instances",
"[",
"$",
"index",
"]",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"linked",
",",
"$",
"this",
"->",
"scheduled",
",",
"true",
")",
"||",
"!",
"$",
"this",
"->",
"autoload",
")",
"{",
"//Scheduling unlink in db when we know relation OR partial mode is on",
"$",
"this",
"->",
"unlinked",
"[",
"]",
"=",
"$",
"linked",
";",
"}",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"instances",
"=",
"array_values",
"(",
"$",
"this",
"->",
"instances",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Unlink specific entity from relation. Will load relation data! Record to delete will be
automatically matched to a give record.
@param RecordInterface $record
@return self
@throws RelationException When entity not linked.
|
[
"Unlink",
"specific",
"entity",
"from",
"relation",
".",
"Will",
"load",
"relation",
"data!",
"Record",
"to",
"delete",
"will",
"be",
"automatically",
"matched",
"to",
"a",
"give",
"record",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php#L211-L234
|
26,154
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php
|
ManyToManyRelation.loadRelated
|
protected function loadRelated(): array
{
$innerKey = $this->parent->getField($this->key(Record::INNER_KEY));
if (empty($innerKey)) {
return [];
}
//Work with pre-build query
$query = $this->createQuery($innerKey);
//Use custom node to parse data
$node = new PivotedRootNode(
$this->schema[Record::RELATION_COLUMNS],
$this->schema[Record::PIVOT_COLUMNS],
$this->schema[Record::OUTER_KEY],
$this->schema[Record::THOUGHT_INNER_KEY],
$this->schema[Record::THOUGHT_OUTER_KEY]
);
$iterator = $query->getIterator();
foreach ($iterator as $row) {
//Time to parse some data
$node->parseRow(0, $row);
}
//Memory free
$iterator->close();
return $node->getResult();
}
|
php
|
protected function loadRelated(): array
{
$innerKey = $this->parent->getField($this->key(Record::INNER_KEY));
if (empty($innerKey)) {
return [];
}
//Work with pre-build query
$query = $this->createQuery($innerKey);
//Use custom node to parse data
$node = new PivotedRootNode(
$this->schema[Record::RELATION_COLUMNS],
$this->schema[Record::PIVOT_COLUMNS],
$this->schema[Record::OUTER_KEY],
$this->schema[Record::THOUGHT_INNER_KEY],
$this->schema[Record::THOUGHT_OUTER_KEY]
);
$iterator = $query->getIterator();
foreach ($iterator as $row) {
//Time to parse some data
$node->parseRow(0, $row);
}
//Memory free
$iterator->close();
return $node->getResult();
}
|
[
"protected",
"function",
"loadRelated",
"(",
")",
":",
"array",
"{",
"$",
"innerKey",
"=",
"$",
"this",
"->",
"parent",
"->",
"getField",
"(",
"$",
"this",
"->",
"key",
"(",
"Record",
"::",
"INNER_KEY",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"innerKey",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"//Work with pre-build query",
"$",
"query",
"=",
"$",
"this",
"->",
"createQuery",
"(",
"$",
"innerKey",
")",
";",
"//Use custom node to parse data",
"$",
"node",
"=",
"new",
"PivotedRootNode",
"(",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"RELATION_COLUMNS",
"]",
",",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"PIVOT_COLUMNS",
"]",
",",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"OUTER_KEY",
"]",
",",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"THOUGHT_INNER_KEY",
"]",
",",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"THOUGHT_OUTER_KEY",
"]",
")",
";",
"$",
"iterator",
"=",
"$",
"query",
"->",
"getIterator",
"(",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"row",
")",
"{",
"//Time to parse some data",
"$",
"node",
"->",
"parseRow",
"(",
"0",
",",
"$",
"row",
")",
";",
"}",
"//Memory free",
"$",
"iterator",
"->",
"close",
"(",
")",
";",
"return",
"$",
"node",
"->",
"getResult",
"(",
")",
";",
"}"
] |
Fetch data from database. Lazy load. Method require a bit of love.
@return array
|
[
"Fetch",
"data",
"from",
"database",
".",
"Lazy",
"load",
".",
"Method",
"require",
"a",
"bit",
"of",
"love",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php#L372-L401
|
26,155
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php
|
ManyToManyRelation.createQuery
|
protected function createQuery($innerKey): SelectQuery
{
$table = $this->orm->table($this->class);
$query = $table->select();
//Loader will take care of query configuration
$loader = new ManyToManyLoader(
$this->class,
$table->getName(),
$this->schema,
$this->orm,
$this->targetRole()
);
//This is root loader, we can do self-alias (THIS IS SAFE due loader in POSTLOAD mode)
$loader = $loader->withContext(
$loader,
[
'alias' => $table->getName(),
'pivotAlias' => $table->getName() . '_pivot',
'method' => RelationLoader::POSTLOAD
]
);
//Configuring query using parent inner key value as reference
/** @var ManyToManyLoader $loader */
$query = $loader->configureQuery($query, true, [$innerKey]);
//Additional pivot conditions
$pivotDecorator = new AliasDecorator($query, 'onWhere', $table->getName() . '_pivot');
$pivotDecorator->where($this->schema[Record::WHERE_PIVOT]);
$decorator = new AliasDecorator($query, 'where', 'root');
//Additional where conditions!
if (!empty($this->schema[Record::WHERE])) {
$decorator->where($this->schema[Record::WHERE]);
}
if (!empty($this->schema[Record::ORDER_BY])) {
//Sorting
$decorator->orderBy((array)$this->schema[Record::ORDER_BY]);
}
return $query;
}
|
php
|
protected function createQuery($innerKey): SelectQuery
{
$table = $this->orm->table($this->class);
$query = $table->select();
//Loader will take care of query configuration
$loader = new ManyToManyLoader(
$this->class,
$table->getName(),
$this->schema,
$this->orm,
$this->targetRole()
);
//This is root loader, we can do self-alias (THIS IS SAFE due loader in POSTLOAD mode)
$loader = $loader->withContext(
$loader,
[
'alias' => $table->getName(),
'pivotAlias' => $table->getName() . '_pivot',
'method' => RelationLoader::POSTLOAD
]
);
//Configuring query using parent inner key value as reference
/** @var ManyToManyLoader $loader */
$query = $loader->configureQuery($query, true, [$innerKey]);
//Additional pivot conditions
$pivotDecorator = new AliasDecorator($query, 'onWhere', $table->getName() . '_pivot');
$pivotDecorator->where($this->schema[Record::WHERE_PIVOT]);
$decorator = new AliasDecorator($query, 'where', 'root');
//Additional where conditions!
if (!empty($this->schema[Record::WHERE])) {
$decorator->where($this->schema[Record::WHERE]);
}
if (!empty($this->schema[Record::ORDER_BY])) {
//Sorting
$decorator->orderBy((array)$this->schema[Record::ORDER_BY]);
}
return $query;
}
|
[
"protected",
"function",
"createQuery",
"(",
"$",
"innerKey",
")",
":",
"SelectQuery",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"orm",
"->",
"table",
"(",
"$",
"this",
"->",
"class",
")",
";",
"$",
"query",
"=",
"$",
"table",
"->",
"select",
"(",
")",
";",
"//Loader will take care of query configuration",
"$",
"loader",
"=",
"new",
"ManyToManyLoader",
"(",
"$",
"this",
"->",
"class",
",",
"$",
"table",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"schema",
",",
"$",
"this",
"->",
"orm",
",",
"$",
"this",
"->",
"targetRole",
"(",
")",
")",
";",
"//This is root loader, we can do self-alias (THIS IS SAFE due loader in POSTLOAD mode)",
"$",
"loader",
"=",
"$",
"loader",
"->",
"withContext",
"(",
"$",
"loader",
",",
"[",
"'alias'",
"=>",
"$",
"table",
"->",
"getName",
"(",
")",
",",
"'pivotAlias'",
"=>",
"$",
"table",
"->",
"getName",
"(",
")",
".",
"'_pivot'",
",",
"'method'",
"=>",
"RelationLoader",
"::",
"POSTLOAD",
"]",
")",
";",
"//Configuring query using parent inner key value as reference",
"/** @var ManyToManyLoader $loader */",
"$",
"query",
"=",
"$",
"loader",
"->",
"configureQuery",
"(",
"$",
"query",
",",
"true",
",",
"[",
"$",
"innerKey",
"]",
")",
";",
"//Additional pivot conditions",
"$",
"pivotDecorator",
"=",
"new",
"AliasDecorator",
"(",
"$",
"query",
",",
"'onWhere'",
",",
"$",
"table",
"->",
"getName",
"(",
")",
".",
"'_pivot'",
")",
";",
"$",
"pivotDecorator",
"->",
"where",
"(",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"WHERE_PIVOT",
"]",
")",
";",
"$",
"decorator",
"=",
"new",
"AliasDecorator",
"(",
"$",
"query",
",",
"'where'",
",",
"'root'",
")",
";",
"//Additional where conditions!",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"WHERE",
"]",
")",
")",
"{",
"$",
"decorator",
"->",
"where",
"(",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"WHERE",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"ORDER_BY",
"]",
")",
")",
"{",
"//Sorting",
"$",
"decorator",
"->",
"orderBy",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"ORDER_BY",
"]",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
] |
Create query for lazy loading.
@param mixed $innerKey
@return SelectQuery
|
[
"Create",
"query",
"for",
"lazy",
"loading",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php#L410-L455
|
26,156
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php
|
ManyToManyRelation.initInstances
|
protected function initInstances(): MultipleRelation
{
if (is_array($this->data) && !empty($this->data)) {
//Iterates and instantiate records
$iterator = new RecordIterator($this->data, $this->class, $this->orm);
foreach ($iterator as $pivotData => $item) {
if (in_array($item, $this->instances, true)) {
//Skip duplicates (if any?)
continue;
}
$this->pivotData->attach($item, $pivotData);
$this->instances[] = $item;
}
}
//Memory free
$this->data = [];
return $this;
}
|
php
|
protected function initInstances(): MultipleRelation
{
if (is_array($this->data) && !empty($this->data)) {
//Iterates and instantiate records
$iterator = new RecordIterator($this->data, $this->class, $this->orm);
foreach ($iterator as $pivotData => $item) {
if (in_array($item, $this->instances, true)) {
//Skip duplicates (if any?)
continue;
}
$this->pivotData->attach($item, $pivotData);
$this->instances[] = $item;
}
}
//Memory free
$this->data = [];
return $this;
}
|
[
"protected",
"function",
"initInstances",
"(",
")",
":",
"MultipleRelation",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"//Iterates and instantiate records",
"$",
"iterator",
"=",
"new",
"RecordIterator",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"this",
"->",
"class",
",",
"$",
"this",
"->",
"orm",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"pivotData",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"item",
",",
"$",
"this",
"->",
"instances",
",",
"true",
")",
")",
"{",
"//Skip duplicates (if any?)",
"continue",
";",
"}",
"$",
"this",
"->",
"pivotData",
"->",
"attach",
"(",
"$",
"item",
",",
"$",
"pivotData",
")",
";",
"$",
"this",
"->",
"instances",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"//Memory free",
"$",
"this",
"->",
"data",
"=",
"[",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Init relations and populate pivot map.
@return self|MultipleRelation
|
[
"Init",
"relations",
"and",
"populate",
"pivot",
"map",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php#L462-L483
|
26,157
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php
|
ManyToManyRelation.assertPivot
|
private function assertPivot(array $pivotData)
{
if ($diff = array_diff(array_keys($pivotData), $this->schema[Record::PIVOT_COLUMNS])) {
throw new RelationException(
"Invalid pivot data, undefined columns found: " . join(', ', $diff)
);
}
}
|
php
|
private function assertPivot(array $pivotData)
{
if ($diff = array_diff(array_keys($pivotData), $this->schema[Record::PIVOT_COLUMNS])) {
throw new RelationException(
"Invalid pivot data, undefined columns found: " . join(', ', $diff)
);
}
}
|
[
"private",
"function",
"assertPivot",
"(",
"array",
"$",
"pivotData",
")",
"{",
"if",
"(",
"$",
"diff",
"=",
"array_diff",
"(",
"array_keys",
"(",
"$",
"pivotData",
")",
",",
"$",
"this",
"->",
"schema",
"[",
"Record",
"::",
"PIVOT_COLUMNS",
"]",
")",
")",
"{",
"throw",
"new",
"RelationException",
"(",
"\"Invalid pivot data, undefined columns found: \"",
".",
"join",
"(",
"', '",
",",
"$",
"diff",
")",
")",
";",
"}",
"}"
] |
Make sure that pivot data in a valid format.
@param array $pivotData
@throws RelationException
|
[
"Make",
"sure",
"that",
"pivot",
"data",
"in",
"a",
"valid",
"format",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php#L508-L515
|
26,158
|
spiral/orm
|
source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php
|
ManyToManyRelation.targetRole
|
private function targetRole(): string
{
return $this->targetRole ?? $this->orm->define(
get_class($this->parent),
ORMInterface::R_ROLE_NAME
);
}
|
php
|
private function targetRole(): string
{
return $this->targetRole ?? $this->orm->define(
get_class($this->parent),
ORMInterface::R_ROLE_NAME
);
}
|
[
"private",
"function",
"targetRole",
"(",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"targetRole",
"??",
"$",
"this",
"->",
"orm",
"->",
"define",
"(",
"get_class",
"(",
"$",
"this",
"->",
"parent",
")",
",",
"ORMInterface",
"::",
"R_ROLE_NAME",
")",
";",
"}"
] |
Defined role to be used in morphed relations.
@return string
|
[
"Defined",
"role",
"to",
"be",
"used",
"in",
"morphed",
"relations",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/Relations/ManyToManyRelation.php#L522-L528
|
26,159
|
spiral/orm
|
source/Spiral/ORM/Transaction.php
|
Transaction.getCommands
|
public function getCommands()
{
foreach ($this->commands as $command) {
if ($command instanceof \Traversable) {
//Nested commands
yield from $command;
}
yield $command;
}
}
|
php
|
public function getCommands()
{
foreach ($this->commands as $command) {
if ($command instanceof \Traversable) {
//Nested commands
yield from $command;
}
yield $command;
}
}
|
[
"public",
"function",
"getCommands",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"commands",
"as",
"$",
"command",
")",
"{",
"if",
"(",
"$",
"command",
"instanceof",
"\\",
"Traversable",
")",
"{",
"//Nested commands",
"yield",
"from",
"$",
"command",
";",
"}",
"yield",
"$",
"command",
";",
"}",
"}"
] |
Will return flattened list of commands.
@return \Generator
|
[
"Will",
"return",
"flattened",
"list",
"of",
"commands",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Transaction.php#L68-L78
|
26,160
|
rinvex/cortex-foundation
|
src/Providers/FoundationServiceProvider.php
|
FoundationServiceProvider.overrideNotificationMiddleware
|
protected function overrideNotificationMiddleware(): void
{
$this->app->singleton('Cortex\Foundation\Http\Middleware\NotificationMiddleware', function ($app) {
return new NotificationMiddleware(
$app['session.store'],
$app['notification'],
$app['config']->get('notification.session_key')
);
});
}
|
php
|
protected function overrideNotificationMiddleware(): void
{
$this->app->singleton('Cortex\Foundation\Http\Middleware\NotificationMiddleware', function ($app) {
return new NotificationMiddleware(
$app['session.store'],
$app['notification'],
$app['config']->get('notification.session_key')
);
});
}
|
[
"protected",
"function",
"overrideNotificationMiddleware",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Cortex\\Foundation\\Http\\Middleware\\NotificationMiddleware'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"NotificationMiddleware",
"(",
"$",
"app",
"[",
"'session.store'",
"]",
",",
"$",
"app",
"[",
"'notification'",
"]",
",",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'notification.session_key'",
")",
")",
";",
"}",
")",
";",
"}"
] |
Override notification middleware.
@return void
|
[
"Override",
"notification",
"middleware",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Providers/FoundationServiceProvider.php#L163-L172
|
26,161
|
rinvex/cortex-foundation
|
src/Providers/FoundationServiceProvider.php
|
FoundationServiceProvider.bindBladeCompiler
|
protected function bindBladeCompiler(): void
{
$this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
// @alerts('container')
$bladeCompiler->directive('alerts', function ($container = null) {
if (strcasecmp('()', $container) === 0) {
$container = null;
}
return "<?php echo app('notification')->container({$container})->show(); ?>";
});
});
}
|
php
|
protected function bindBladeCompiler(): void
{
$this->app->afterResolving('blade.compiler', function (BladeCompiler $bladeCompiler) {
// @alerts('container')
$bladeCompiler->directive('alerts', function ($container = null) {
if (strcasecmp('()', $container) === 0) {
$container = null;
}
return "<?php echo app('notification')->container({$container})->show(); ?>";
});
});
}
|
[
"protected",
"function",
"bindBladeCompiler",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"afterResolving",
"(",
"'blade.compiler'",
",",
"function",
"(",
"BladeCompiler",
"$",
"bladeCompiler",
")",
"{",
"// @alerts('container')",
"$",
"bladeCompiler",
"->",
"directive",
"(",
"'alerts'",
",",
"function",
"(",
"$",
"container",
"=",
"null",
")",
"{",
"if",
"(",
"strcasecmp",
"(",
"'()'",
",",
"$",
"container",
")",
"===",
"0",
")",
"{",
"$",
"container",
"=",
"null",
";",
"}",
"return",
"\"<?php echo app('notification')->container({$container})->show(); ?>\"",
";",
"}",
")",
";",
"}",
")",
";",
"}"
] |
Bind blade compiler.
@return void
|
[
"Bind",
"blade",
"compiler",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Providers/FoundationServiceProvider.php#L179-L192
|
26,162
|
rinvex/cortex-foundation
|
src/Providers/FoundationServiceProvider.php
|
FoundationServiceProvider.overrideRedirector
|
protected function overrideRedirector(): void
{
$this->app->singleton('redirect', function ($app) {
$redirector = new Redirector($app['url']);
// If the session is set on the application instance, we'll inject it into
// the redirector instance. This allows the redirect responses to allow
// for the quite convenient "with" methods that flash to the session.
if (isset($app['session.store'])) {
$redirector->setSession($app['session.store']);
}
return $redirector;
});
}
|
php
|
protected function overrideRedirector(): void
{
$this->app->singleton('redirect', function ($app) {
$redirector = new Redirector($app['url']);
// If the session is set on the application instance, we'll inject it into
// the redirector instance. This allows the redirect responses to allow
// for the quite convenient "with" methods that flash to the session.
if (isset($app['session.store'])) {
$redirector->setSession($app['session.store']);
}
return $redirector;
});
}
|
[
"protected",
"function",
"overrideRedirector",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'redirect'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"redirector",
"=",
"new",
"Redirector",
"(",
"$",
"app",
"[",
"'url'",
"]",
")",
";",
"// If the session is set on the application instance, we'll inject it into",
"// the redirector instance. This allows the redirect responses to allow",
"// for the quite convenient \"with\" methods that flash to the session.",
"if",
"(",
"isset",
"(",
"$",
"app",
"[",
"'session.store'",
"]",
")",
")",
"{",
"$",
"redirector",
"->",
"setSession",
"(",
"$",
"app",
"[",
"'session.store'",
"]",
")",
";",
"}",
"return",
"$",
"redirector",
";",
"}",
")",
";",
"}"
] |
Override the Redirector instance.
@return void
|
[
"Override",
"the",
"Redirector",
"instance",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Providers/FoundationServiceProvider.php#L199-L213
|
26,163
|
rinvex/cortex-foundation
|
src/Providers/FoundationServiceProvider.php
|
FoundationServiceProvider.overrideUrlGenerator
|
protected function overrideUrlGenerator(): void
{
$this->app->singleton('url', function ($app) {
$routes = $app['router']->getRoutes();
// The URL generator needs the route collection that exists on the router.
// Keep in mind this is an object, so we're passing by references here
// and all the registered routes will be available to the generator.
$app->instance('routes', $routes);
$url = new UrlGenerator(
$routes, $app->rebinding(
'request', $this->requestRebinder()
)
);
$url->setSessionResolver(function () {
return $this->app['session'];
});
// If the route collection is "rebound", for example, when the routes stay
// cached for the application, we will need to rebind the routes on the
// URL generator instance so it has the latest version of the routes.
$app->rebinding('routes', function ($app, $routes) {
$app['url']->setRoutes($routes);
});
return $url;
});
}
|
php
|
protected function overrideUrlGenerator(): void
{
$this->app->singleton('url', function ($app) {
$routes = $app['router']->getRoutes();
// The URL generator needs the route collection that exists on the router.
// Keep in mind this is an object, so we're passing by references here
// and all the registered routes will be available to the generator.
$app->instance('routes', $routes);
$url = new UrlGenerator(
$routes, $app->rebinding(
'request', $this->requestRebinder()
)
);
$url->setSessionResolver(function () {
return $this->app['session'];
});
// If the route collection is "rebound", for example, when the routes stay
// cached for the application, we will need to rebind the routes on the
// URL generator instance so it has the latest version of the routes.
$app->rebinding('routes', function ($app, $routes) {
$app['url']->setRoutes($routes);
});
return $url;
});
}
|
[
"protected",
"function",
"overrideUrlGenerator",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'url'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"routes",
"=",
"$",
"app",
"[",
"'router'",
"]",
"->",
"getRoutes",
"(",
")",
";",
"// The URL generator needs the route collection that exists on the router.",
"// Keep in mind this is an object, so we're passing by references here",
"// and all the registered routes will be available to the generator.",
"$",
"app",
"->",
"instance",
"(",
"'routes'",
",",
"$",
"routes",
")",
";",
"$",
"url",
"=",
"new",
"UrlGenerator",
"(",
"$",
"routes",
",",
"$",
"app",
"->",
"rebinding",
"(",
"'request'",
",",
"$",
"this",
"->",
"requestRebinder",
"(",
")",
")",
")",
";",
"$",
"url",
"->",
"setSessionResolver",
"(",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"app",
"[",
"'session'",
"]",
";",
"}",
")",
";",
"// If the route collection is \"rebound\", for example, when the routes stay",
"// cached for the application, we will need to rebind the routes on the",
"// URL generator instance so it has the latest version of the routes.",
"$",
"app",
"->",
"rebinding",
"(",
"'routes'",
",",
"function",
"(",
"$",
"app",
",",
"$",
"routes",
")",
"{",
"$",
"app",
"[",
"'url'",
"]",
"->",
"setRoutes",
"(",
"$",
"routes",
")",
";",
"}",
")",
";",
"return",
"$",
"url",
";",
"}",
")",
";",
"}"
] |
Override the UrlGenerator instance.
@return void
|
[
"Override",
"the",
"UrlGenerator",
"instance",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Providers/FoundationServiceProvider.php#L220-L249
|
26,164
|
rinvex/cortex-foundation
|
src/Providers/FoundationServiceProvider.php
|
FoundationServiceProvider.bindPresenceVerifier
|
protected function bindPresenceVerifier(): void
{
$this->app->bind('cortex.foundation.presence.verifier', function ($app) {
return new EloquentPresenceVerifier($app['db'], new $app[AbstractModel::class]());
});
}
|
php
|
protected function bindPresenceVerifier(): void
{
$this->app->bind('cortex.foundation.presence.verifier', function ($app) {
return new EloquentPresenceVerifier($app['db'], new $app[AbstractModel::class]());
});
}
|
[
"protected",
"function",
"bindPresenceVerifier",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"'cortex.foundation.presence.verifier'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"EloquentPresenceVerifier",
"(",
"$",
"app",
"[",
"'db'",
"]",
",",
"new",
"$",
"app",
"[",
"AbstractModel",
"::",
"class",
"]",
"(",
")",
")",
";",
"}",
")",
";",
"}"
] |
Bind presence verifier.
@return void
|
[
"Bind",
"presence",
"verifier",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Providers/FoundationServiceProvider.php#L337-L342
|
26,165
|
rinvex/cortex-foundation
|
src/Providers/FoundationServiceProvider.php
|
FoundationServiceProvider.bindBlueprintMacro
|
protected function bindBlueprintMacro(): void
{
Blueprint::macro('auditable', function () {
$this->integer('created_by_id')->unsigned()->after('created_at')->nullable();
$this->string('created_by_type')->after('created_at')->nullable();
$this->integer('updated_by_id')->unsigned()->after('updated_at')->nullable();
$this->string('updated_by_type')->after('updated_at')->nullable();
});
Blueprint::macro('dropAuditable', function () {
$this->dropForeign($this->createIndexName('foreign', ['updated_by_type']));
$this->dropForeign($this->createIndexName('foreign', ['updated_by_id']));
$this->dropForeign($this->createIndexName('foreign', ['created_by_type']));
$this->dropForeign($this->createIndexName('foreign', ['created_by_id']));
$this->dropColumn(['updated_by_type', 'updated_by_id', 'created_by_type', 'created_by_id']);
});
Blueprint::macro('auditableAndTimestamps', function ($precision = 0) {
$this->timestamp('created_at', $precision)->nullable();
$this->integer('created_by_id')->unsigned()->nullable();
$this->string('created_by_type')->nullable();
$this->timestamp('updated_at', $precision)->nullable();
$this->integer('updated_by_id')->unsigned()->nullable();
$this->string('updated_by_type')->nullable();
});
Blueprint::macro('dropauditableAndTimestamps', function () {
$this->dropForeign($this->createIndexName('foreign', ['updated_by_type']));
$this->dropForeign($this->createIndexName('foreign', ['updated_by_id']));
$this->dropForeign($this->createIndexName('foreign', ['updated_at']));
$this->dropForeign($this->createIndexName('foreign', ['created_by_type']));
$this->dropForeign($this->createIndexName('foreign', ['created_by_id']));
$this->dropForeign($this->createIndexName('foreign', ['created_at']));
$this->dropColumn(['updated_by_type', 'updated_by_id', 'updated_at', 'created_by_type', 'created_by_id', 'created_at']);
});
}
|
php
|
protected function bindBlueprintMacro(): void
{
Blueprint::macro('auditable', function () {
$this->integer('created_by_id')->unsigned()->after('created_at')->nullable();
$this->string('created_by_type')->after('created_at')->nullable();
$this->integer('updated_by_id')->unsigned()->after('updated_at')->nullable();
$this->string('updated_by_type')->after('updated_at')->nullable();
});
Blueprint::macro('dropAuditable', function () {
$this->dropForeign($this->createIndexName('foreign', ['updated_by_type']));
$this->dropForeign($this->createIndexName('foreign', ['updated_by_id']));
$this->dropForeign($this->createIndexName('foreign', ['created_by_type']));
$this->dropForeign($this->createIndexName('foreign', ['created_by_id']));
$this->dropColumn(['updated_by_type', 'updated_by_id', 'created_by_type', 'created_by_id']);
});
Blueprint::macro('auditableAndTimestamps', function ($precision = 0) {
$this->timestamp('created_at', $precision)->nullable();
$this->integer('created_by_id')->unsigned()->nullable();
$this->string('created_by_type')->nullable();
$this->timestamp('updated_at', $precision)->nullable();
$this->integer('updated_by_id')->unsigned()->nullable();
$this->string('updated_by_type')->nullable();
});
Blueprint::macro('dropauditableAndTimestamps', function () {
$this->dropForeign($this->createIndexName('foreign', ['updated_by_type']));
$this->dropForeign($this->createIndexName('foreign', ['updated_by_id']));
$this->dropForeign($this->createIndexName('foreign', ['updated_at']));
$this->dropForeign($this->createIndexName('foreign', ['created_by_type']));
$this->dropForeign($this->createIndexName('foreign', ['created_by_id']));
$this->dropForeign($this->createIndexName('foreign', ['created_at']));
$this->dropColumn(['updated_by_type', 'updated_by_id', 'updated_at', 'created_by_type', 'created_by_id', 'created_at']);
});
}
|
[
"protected",
"function",
"bindBlueprintMacro",
"(",
")",
":",
"void",
"{",
"Blueprint",
"::",
"macro",
"(",
"'auditable'",
",",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"integer",
"(",
"'created_by_id'",
")",
"->",
"unsigned",
"(",
")",
"->",
"after",
"(",
"'created_at'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"this",
"->",
"string",
"(",
"'created_by_type'",
")",
"->",
"after",
"(",
"'created_at'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"this",
"->",
"integer",
"(",
"'updated_by_id'",
")",
"->",
"unsigned",
"(",
")",
"->",
"after",
"(",
"'updated_at'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"this",
"->",
"string",
"(",
"'updated_by_type'",
")",
"->",
"after",
"(",
"'updated_at'",
")",
"->",
"nullable",
"(",
")",
";",
"}",
")",
";",
"Blueprint",
"::",
"macro",
"(",
"'dropAuditable'",
",",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"dropForeign",
"(",
"$",
"this",
"->",
"createIndexName",
"(",
"'foreign'",
",",
"[",
"'updated_by_type'",
"]",
")",
")",
";",
"$",
"this",
"->",
"dropForeign",
"(",
"$",
"this",
"->",
"createIndexName",
"(",
"'foreign'",
",",
"[",
"'updated_by_id'",
"]",
")",
")",
";",
"$",
"this",
"->",
"dropForeign",
"(",
"$",
"this",
"->",
"createIndexName",
"(",
"'foreign'",
",",
"[",
"'created_by_type'",
"]",
")",
")",
";",
"$",
"this",
"->",
"dropForeign",
"(",
"$",
"this",
"->",
"createIndexName",
"(",
"'foreign'",
",",
"[",
"'created_by_id'",
"]",
")",
")",
";",
"$",
"this",
"->",
"dropColumn",
"(",
"[",
"'updated_by_type'",
",",
"'updated_by_id'",
",",
"'created_by_type'",
",",
"'created_by_id'",
"]",
")",
";",
"}",
")",
";",
"Blueprint",
"::",
"macro",
"(",
"'auditableAndTimestamps'",
",",
"function",
"(",
"$",
"precision",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"timestamp",
"(",
"'created_at'",
",",
"$",
"precision",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"this",
"->",
"integer",
"(",
"'created_by_id'",
")",
"->",
"unsigned",
"(",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"this",
"->",
"string",
"(",
"'created_by_type'",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"this",
"->",
"timestamp",
"(",
"'updated_at'",
",",
"$",
"precision",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"this",
"->",
"integer",
"(",
"'updated_by_id'",
")",
"->",
"unsigned",
"(",
")",
"->",
"nullable",
"(",
")",
";",
"$",
"this",
"->",
"string",
"(",
"'updated_by_type'",
")",
"->",
"nullable",
"(",
")",
";",
"}",
")",
";",
"Blueprint",
"::",
"macro",
"(",
"'dropauditableAndTimestamps'",
",",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"dropForeign",
"(",
"$",
"this",
"->",
"createIndexName",
"(",
"'foreign'",
",",
"[",
"'updated_by_type'",
"]",
")",
")",
";",
"$",
"this",
"->",
"dropForeign",
"(",
"$",
"this",
"->",
"createIndexName",
"(",
"'foreign'",
",",
"[",
"'updated_by_id'",
"]",
")",
")",
";",
"$",
"this",
"->",
"dropForeign",
"(",
"$",
"this",
"->",
"createIndexName",
"(",
"'foreign'",
",",
"[",
"'updated_at'",
"]",
")",
")",
";",
"$",
"this",
"->",
"dropForeign",
"(",
"$",
"this",
"->",
"createIndexName",
"(",
"'foreign'",
",",
"[",
"'created_by_type'",
"]",
")",
")",
";",
"$",
"this",
"->",
"dropForeign",
"(",
"$",
"this",
"->",
"createIndexName",
"(",
"'foreign'",
",",
"[",
"'created_by_id'",
"]",
")",
")",
";",
"$",
"this",
"->",
"dropForeign",
"(",
"$",
"this",
"->",
"createIndexName",
"(",
"'foreign'",
",",
"[",
"'created_at'",
"]",
")",
")",
";",
"$",
"this",
"->",
"dropColumn",
"(",
"[",
"'updated_by_type'",
",",
"'updated_by_id'",
",",
"'updated_at'",
",",
"'created_by_type'",
",",
"'created_by_id'",
",",
"'created_at'",
"]",
")",
";",
"}",
")",
";",
"}"
] |
Bind blueprint macro.
@return void
|
[
"Bind",
"blueprint",
"macro",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Providers/FoundationServiceProvider.php#L349-L384
|
26,166
|
rinvex/cortex-foundation
|
src/Console/Commands/DataTableMakeCommand.php
|
DataTableMakeCommand.replaceClasses
|
protected function replaceClasses($stub, $model, $transformer = null): string
{
if ($transformer) {
$transformer = str_replace('/', '\\', $transformer);
$namespaceTransformer = $this->rootNamespace().'\Transformers\\'.$transformer;
if (starts_with($transformer, '\\')) {
$stub = str_replace('NamespacedDummyTransformer', trim($transformer, '\\'), $stub);
} else {
$stub = str_replace('NamespacedDummyTransformer', $namespaceTransformer, $stub);
}
$stub = str_replace(
"use {$namespaceTransformer};\nuse {$namespaceTransformer};", "use {$namespaceTransformer};", $stub
);
$transformer = class_basename(trim($transformer, '\\'));
$stub = str_replace('DummyTransformer', $transformer, $stub);
$stub = str_replace('dummyTransformer', camel_case($transformer), $stub);
}
$model = str_replace('/', '\\', $model);
$namespaceModel = $this->rootNamespace().'\Models\\'.$model;
if (starts_with($model, '\\')) {
$stub = str_replace('NamespacedDummyModel', trim($model, '\\'), $stub);
} else {
$stub = str_replace('NamespacedDummyModel', $namespaceModel, $stub);
}
$stub = str_replace(
"use {$namespaceModel};\nuse {$namespaceModel};", "use {$namespaceModel};", $stub
);
$model = class_basename(trim($model, '\\'));
$stub = str_replace('DummyModel', $model, $stub);
return str_replace('dummyModel', camel_case($model), $stub);
}
|
php
|
protected function replaceClasses($stub, $model, $transformer = null): string
{
if ($transformer) {
$transformer = str_replace('/', '\\', $transformer);
$namespaceTransformer = $this->rootNamespace().'\Transformers\\'.$transformer;
if (starts_with($transformer, '\\')) {
$stub = str_replace('NamespacedDummyTransformer', trim($transformer, '\\'), $stub);
} else {
$stub = str_replace('NamespacedDummyTransformer', $namespaceTransformer, $stub);
}
$stub = str_replace(
"use {$namespaceTransformer};\nuse {$namespaceTransformer};", "use {$namespaceTransformer};", $stub
);
$transformer = class_basename(trim($transformer, '\\'));
$stub = str_replace('DummyTransformer', $transformer, $stub);
$stub = str_replace('dummyTransformer', camel_case($transformer), $stub);
}
$model = str_replace('/', '\\', $model);
$namespaceModel = $this->rootNamespace().'\Models\\'.$model;
if (starts_with($model, '\\')) {
$stub = str_replace('NamespacedDummyModel', trim($model, '\\'), $stub);
} else {
$stub = str_replace('NamespacedDummyModel', $namespaceModel, $stub);
}
$stub = str_replace(
"use {$namespaceModel};\nuse {$namespaceModel};", "use {$namespaceModel};", $stub
);
$model = class_basename(trim($model, '\\'));
$stub = str_replace('DummyModel', $model, $stub);
return str_replace('dummyModel', camel_case($model), $stub);
}
|
[
"protected",
"function",
"replaceClasses",
"(",
"$",
"stub",
",",
"$",
"model",
",",
"$",
"transformer",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"$",
"transformer",
")",
"{",
"$",
"transformer",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"transformer",
")",
";",
"$",
"namespaceTransformer",
"=",
"$",
"this",
"->",
"rootNamespace",
"(",
")",
".",
"'\\Transformers\\\\'",
".",
"$",
"transformer",
";",
"if",
"(",
"starts_with",
"(",
"$",
"transformer",
",",
"'\\\\'",
")",
")",
"{",
"$",
"stub",
"=",
"str_replace",
"(",
"'NamespacedDummyTransformer'",
",",
"trim",
"(",
"$",
"transformer",
",",
"'\\\\'",
")",
",",
"$",
"stub",
")",
";",
"}",
"else",
"{",
"$",
"stub",
"=",
"str_replace",
"(",
"'NamespacedDummyTransformer'",
",",
"$",
"namespaceTransformer",
",",
"$",
"stub",
")",
";",
"}",
"$",
"stub",
"=",
"str_replace",
"(",
"\"use {$namespaceTransformer};\\nuse {$namespaceTransformer};\"",
",",
"\"use {$namespaceTransformer};\"",
",",
"$",
"stub",
")",
";",
"$",
"transformer",
"=",
"class_basename",
"(",
"trim",
"(",
"$",
"transformer",
",",
"'\\\\'",
")",
")",
";",
"$",
"stub",
"=",
"str_replace",
"(",
"'DummyTransformer'",
",",
"$",
"transformer",
",",
"$",
"stub",
")",
";",
"$",
"stub",
"=",
"str_replace",
"(",
"'dummyTransformer'",
",",
"camel_case",
"(",
"$",
"transformer",
")",
",",
"$",
"stub",
")",
";",
"}",
"$",
"model",
"=",
"str_replace",
"(",
"'/'",
",",
"'\\\\'",
",",
"$",
"model",
")",
";",
"$",
"namespaceModel",
"=",
"$",
"this",
"->",
"rootNamespace",
"(",
")",
".",
"'\\Models\\\\'",
".",
"$",
"model",
";",
"if",
"(",
"starts_with",
"(",
"$",
"model",
",",
"'\\\\'",
")",
")",
"{",
"$",
"stub",
"=",
"str_replace",
"(",
"'NamespacedDummyModel'",
",",
"trim",
"(",
"$",
"model",
",",
"'\\\\'",
")",
",",
"$",
"stub",
")",
";",
"}",
"else",
"{",
"$",
"stub",
"=",
"str_replace",
"(",
"'NamespacedDummyModel'",
",",
"$",
"namespaceModel",
",",
"$",
"stub",
")",
";",
"}",
"$",
"stub",
"=",
"str_replace",
"(",
"\"use {$namespaceModel};\\nuse {$namespaceModel};\"",
",",
"\"use {$namespaceModel};\"",
",",
"$",
"stub",
")",
";",
"$",
"model",
"=",
"class_basename",
"(",
"trim",
"(",
"$",
"model",
",",
"'\\\\'",
")",
")",
";",
"$",
"stub",
"=",
"str_replace",
"(",
"'DummyModel'",
",",
"$",
"model",
",",
"$",
"stub",
")",
";",
"return",
"str_replace",
"(",
"'dummyModel'",
",",
"camel_case",
"(",
"$",
"model",
")",
",",
"$",
"stub",
")",
";",
"}"
] |
Replace the model and transformer for the given stub.
@param string $stub
@param string $model
@param string $transformer
@return string
|
[
"Replace",
"the",
"model",
"and",
"transformer",
"for",
"the",
"given",
"stub",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/Console/Commands/DataTableMakeCommand.php#L80-L123
|
26,167
|
spiral/orm
|
source/Spiral/ORM/Helpers/RelationOptions.php
|
RelationOptions.define
|
public function define(string $option)
{
if (!array_key_exists($option, $this->options)) {
throw new OptionsException("Undefined relation option '{$option}'");
}
return $this->options[$option];
}
|
php
|
public function define(string $option)
{
if (!array_key_exists($option, $this->options)) {
throw new OptionsException("Undefined relation option '{$option}'");
}
return $this->options[$option];
}
|
[
"public",
"function",
"define",
"(",
"string",
"$",
"option",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"option",
",",
"$",
"this",
"->",
"options",
")",
")",
"{",
"throw",
"new",
"OptionsException",
"(",
"\"Undefined relation option '{$option}'\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"options",
"[",
"$",
"option",
"]",
";",
"}"
] |
Get value for a specific option. Attention, option MUST exist in template in order to
be retrievable.
@param string $option
@return mixed
@throws OptionsException
|
[
"Get",
"value",
"for",
"a",
"specific",
"option",
".",
"Attention",
"option",
"MUST",
"exist",
"in",
"template",
"in",
"order",
"to",
"be",
"retrievable",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Helpers/RelationOptions.php#L73-L80
|
26,168
|
spiral/orm
|
source/Spiral/ORM/Helpers/RelationOptions.php
|
RelationOptions.calculateOptions
|
protected function calculateOptions(array $userOptions): array
{
foreach ($this->template as $property => $pattern) {
if (isset($userOptions[$property])) {
//Specified by user
continue;
}
if (!is_string($pattern)) {
//Some options are actually array of options
$userOptions[$property] = $pattern;
continue;
}
//Let's create option value using default proposer values
$userOptions[$property] = \Spiral\interpolate(
$pattern,
$this->proposedOptions($userOptions)
);
}
return $userOptions;
}
|
php
|
protected function calculateOptions(array $userOptions): array
{
foreach ($this->template as $property => $pattern) {
if (isset($userOptions[$property])) {
//Specified by user
continue;
}
if (!is_string($pattern)) {
//Some options are actually array of options
$userOptions[$property] = $pattern;
continue;
}
//Let's create option value using default proposer values
$userOptions[$property] = \Spiral\interpolate(
$pattern,
$this->proposedOptions($userOptions)
);
}
return $userOptions;
}
|
[
"protected",
"function",
"calculateOptions",
"(",
"array",
"$",
"userOptions",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"this",
"->",
"template",
"as",
"$",
"property",
"=>",
"$",
"pattern",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"userOptions",
"[",
"$",
"property",
"]",
")",
")",
"{",
"//Specified by user",
"continue",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"pattern",
")",
")",
"{",
"//Some options are actually array of options",
"$",
"userOptions",
"[",
"$",
"property",
"]",
"=",
"$",
"pattern",
";",
"continue",
";",
"}",
"//Let's create option value using default proposer values",
"$",
"userOptions",
"[",
"$",
"property",
"]",
"=",
"\\",
"Spiral",
"\\",
"interpolate",
"(",
"$",
"pattern",
",",
"$",
"this",
"->",
"proposedOptions",
"(",
"$",
"userOptions",
")",
")",
";",
"}",
"return",
"$",
"userOptions",
";",
"}"
] |
Calculate options based on given template
@param array $userOptions Options provided by user.
@return array Calculated options.
|
[
"Calculate",
"options",
"based",
"on",
"given",
"template"
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Helpers/RelationOptions.php#L101-L123
|
26,169
|
spiral/orm
|
source/Spiral/ORM/Helpers/RelationOptions.php
|
RelationOptions.proposedOptions
|
protected function proposedOptions(array $userOptions): array
{
$source = $this->definition->sourceContext();
$proposed = [
//Relation name
'relation:name' => $this->definition->getName(),
//Relation name in plural form
'relation:plural' => Inflector::pluralize($this->definition->getName()),
//Relation name in singular form
'relation:singular' => Inflector::singularize($this->definition->getName()),
//Parent record role name
'source:role' => $source->getRole(),
//Parent record table name
'source:table' => $source->getTable(),
//Parent record primary key
'source:primaryKey' => $source->getPrimary()->getName(),
];
//Some options may use values declared in other definition fields
$aliases = [
Record::OUTER_KEY => 'outerKey',
Record::INNER_KEY => 'innerKey',
Record::PIVOT_TABLE => 'pivotTable',
];
foreach ($aliases as $property => $alias) {
if (isset($userOptions[$property])) {
//Let's create some default options based on user specified values
$proposed['option:' . $alias] = $userOptions[$property];
}
}
if (!empty($this->definition->targetContext())) {
$target = $this->definition->targetContext();
$proposed = $proposed + [
//Outer role name
'target:role' => $target->getRole(),
//Outer record table
'target:table' => $target->getTable(),
//Outer record primary key
'target:primaryKey' => !empty($target->getPrimary()) ? $target->getPrimary()->getName() : '',
];
}
return $proposed;
}
|
php
|
protected function proposedOptions(array $userOptions): array
{
$source = $this->definition->sourceContext();
$proposed = [
//Relation name
'relation:name' => $this->definition->getName(),
//Relation name in plural form
'relation:plural' => Inflector::pluralize($this->definition->getName()),
//Relation name in singular form
'relation:singular' => Inflector::singularize($this->definition->getName()),
//Parent record role name
'source:role' => $source->getRole(),
//Parent record table name
'source:table' => $source->getTable(),
//Parent record primary key
'source:primaryKey' => $source->getPrimary()->getName(),
];
//Some options may use values declared in other definition fields
$aliases = [
Record::OUTER_KEY => 'outerKey',
Record::INNER_KEY => 'innerKey',
Record::PIVOT_TABLE => 'pivotTable',
];
foreach ($aliases as $property => $alias) {
if (isset($userOptions[$property])) {
//Let's create some default options based on user specified values
$proposed['option:' . $alias] = $userOptions[$property];
}
}
if (!empty($this->definition->targetContext())) {
$target = $this->definition->targetContext();
$proposed = $proposed + [
//Outer role name
'target:role' => $target->getRole(),
//Outer record table
'target:table' => $target->getTable(),
//Outer record primary key
'target:primaryKey' => !empty($target->getPrimary()) ? $target->getPrimary()->getName() : '',
];
}
return $proposed;
}
|
[
"protected",
"function",
"proposedOptions",
"(",
"array",
"$",
"userOptions",
")",
":",
"array",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"definition",
"->",
"sourceContext",
"(",
")",
";",
"$",
"proposed",
"=",
"[",
"//Relation name",
"'relation:name'",
"=>",
"$",
"this",
"->",
"definition",
"->",
"getName",
"(",
")",
",",
"//Relation name in plural form",
"'relation:plural'",
"=>",
"Inflector",
"::",
"pluralize",
"(",
"$",
"this",
"->",
"definition",
"->",
"getName",
"(",
")",
")",
",",
"//Relation name in singular form",
"'relation:singular'",
"=>",
"Inflector",
"::",
"singularize",
"(",
"$",
"this",
"->",
"definition",
"->",
"getName",
"(",
")",
")",
",",
"//Parent record role name",
"'source:role'",
"=>",
"$",
"source",
"->",
"getRole",
"(",
")",
",",
"//Parent record table name",
"'source:table'",
"=>",
"$",
"source",
"->",
"getTable",
"(",
")",
",",
"//Parent record primary key",
"'source:primaryKey'",
"=>",
"$",
"source",
"->",
"getPrimary",
"(",
")",
"->",
"getName",
"(",
")",
",",
"]",
";",
"//Some options may use values declared in other definition fields",
"$",
"aliases",
"=",
"[",
"Record",
"::",
"OUTER_KEY",
"=>",
"'outerKey'",
",",
"Record",
"::",
"INNER_KEY",
"=>",
"'innerKey'",
",",
"Record",
"::",
"PIVOT_TABLE",
"=>",
"'pivotTable'",
",",
"]",
";",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"property",
"=>",
"$",
"alias",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"userOptions",
"[",
"$",
"property",
"]",
")",
")",
"{",
"//Let's create some default options based on user specified values",
"$",
"proposed",
"[",
"'option:'",
".",
"$",
"alias",
"]",
"=",
"$",
"userOptions",
"[",
"$",
"property",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"definition",
"->",
"targetContext",
"(",
")",
")",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"definition",
"->",
"targetContext",
"(",
")",
";",
"$",
"proposed",
"=",
"$",
"proposed",
"+",
"[",
"//Outer role name",
"'target:role'",
"=>",
"$",
"target",
"->",
"getRole",
"(",
")",
",",
"//Outer record table",
"'target:table'",
"=>",
"$",
"target",
"->",
"getTable",
"(",
")",
",",
"//Outer record primary key",
"'target:primaryKey'",
"=>",
"!",
"empty",
"(",
"$",
"target",
"->",
"getPrimary",
"(",
")",
")",
"?",
"$",
"target",
"->",
"getPrimary",
"(",
")",
"->",
"getName",
"(",
")",
":",
"''",
",",
"]",
";",
"}",
"return",
"$",
"proposed",
";",
"}"
] |
Create set of options to specify missing relation definition fields.
@param array $userOptions User options.
@return array
|
[
"Create",
"set",
"of",
"options",
"to",
"specify",
"missing",
"relation",
"definition",
"fields",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Helpers/RelationOptions.php#L132-L186
|
26,170
|
spiral/orm
|
source/Spiral/ORM/Entities/RecordSelector.php
|
RecordSelector.withColumns
|
public function withColumns(array $columns): self
{
$selector = clone $this;
$selector->loader = $selector->loader->withColumns($columns);
return $selector;
}
|
php
|
public function withColumns(array $columns): self
{
$selector = clone $this;
$selector->loader = $selector->loader->withColumns($columns);
return $selector;
}
|
[
"public",
"function",
"withColumns",
"(",
"array",
"$",
"columns",
")",
":",
"self",
"{",
"$",
"selector",
"=",
"clone",
"$",
"this",
";",
"$",
"selector",
"->",
"loader",
"=",
"$",
"selector",
"->",
"loader",
"->",
"withColumns",
"(",
"$",
"columns",
")",
";",
"return",
"$",
"selector",
";",
"}"
] |
Columns to be selected, please note, primary will always be included, DO not include
column aliases in here, aliases will be added automatically. Creates selector as response.
@param array $columns
@return RecordSelector
|
[
"Columns",
"to",
"be",
"selected",
"please",
"note",
"primary",
"will",
"always",
"be",
"included",
"DO",
"not",
"include",
"column",
"aliases",
"in",
"here",
"aliases",
"will",
"be",
"added",
"automatically",
".",
"Creates",
"selector",
"as",
"response",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RecordSelector.php#L122-L128
|
26,171
|
spiral/orm
|
source/Spiral/ORM/Entities/RecordSelector.php
|
RecordSelector.load
|
public function load($relation, array $options = []): self
{
if (is_array($relation)) {
foreach ($relation as $name => $subOption) {
if (is_string($subOption)) {
//Array of relation names
$this->load($subOption, $options);
} else {
//Multiple relations or relation with addition load options
$this->load($name, $subOption + $options);
}
}
return $this;
}
//We are requesting primary loaded to pre-load nested relation
$this->loader->loadRelation($relation, $options);
return $this;
}
|
php
|
public function load($relation, array $options = []): self
{
if (is_array($relation)) {
foreach ($relation as $name => $subOption) {
if (is_string($subOption)) {
//Array of relation names
$this->load($subOption, $options);
} else {
//Multiple relations or relation with addition load options
$this->load($name, $subOption + $options);
}
}
return $this;
}
//We are requesting primary loaded to pre-load nested relation
$this->loader->loadRelation($relation, $options);
return $this;
}
|
[
"public",
"function",
"load",
"(",
"$",
"relation",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
":",
"self",
"{",
"if",
"(",
"is_array",
"(",
"$",
"relation",
")",
")",
"{",
"foreach",
"(",
"$",
"relation",
"as",
"$",
"name",
"=>",
"$",
"subOption",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"subOption",
")",
")",
"{",
"//Array of relation names",
"$",
"this",
"->",
"load",
"(",
"$",
"subOption",
",",
"$",
"options",
")",
";",
"}",
"else",
"{",
"//Multiple relations or relation with addition load options",
"$",
"this",
"->",
"load",
"(",
"$",
"name",
",",
"$",
"subOption",
"+",
"$",
"options",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}",
"//We are requesting primary loaded to pre-load nested relation",
"$",
"this",
"->",
"loader",
"->",
"loadRelation",
"(",
"$",
"relation",
",",
"$",
"options",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Request primary selector loader to pre-load relation name. Any type of loader can be used
for
data preloading. ORM loaders by default will select the most efficient way to load related
data which might include additional select query or left join. Loaded data will
automatically pre-populate record relations. You can specify nested relations using "."
separator.
Examples:
//Select users and load their comments (will cast 2 queries, HAS_MANY comments)
User::find()->with('comments');
//You can load chain of relations - select user and load their comments and post related to
//comment
User::find()->with('comments.post');
//We can also specify custom where conditions on data loading, let's load only public
comments. User::find()->load('comments', [
'where' => ['{@}.status' => 'public']
]);
Please note using "{@}" column name, this placeholder is required to prevent collisions and
it will be automatically replaced with valid table alias of pre-loaded comments table.
//In case where your loaded relation is MANY_TO_MANY you can also specify pivot table
conditions,
//let's pre-load all approved user tags, we can use same placeholder for pivot table alias
User::find()->load('tags', [
'wherePivot' => ['{@}.approved' => true]
]);
//In most of cases you don't need to worry about how data was loaded, using external query
or
//left join, however if you want to change such behaviour you can force load method to
INLOAD
User::find()->load('tags', [
'method' => Loader::INLOAD,
'wherePivot' => ['{@}.approved' => true]
]);
Attention, you will not be able to correctly paginate in this case and only ORM loaders
support different loading types.
You can specify multiple loaders using array as first argument.
Example:
User::find()->load(['posts', 'comments', 'profile']);
Attention, consider disabling entity map if you want to use recursive loading (i.e.
post.tags.posts), but first think why you even need recursive relation loading.
@see with()
@param string|array $relation
@param array $options
@return $this|RecordSelector
|
[
"Request",
"primary",
"selector",
"loader",
"to",
"pre",
"-",
"load",
"relation",
"name",
".",
"Any",
"type",
"of",
"loader",
"can",
"be",
"used",
"for",
"data",
"preloading",
".",
"ORM",
"loaders",
"by",
"default",
"will",
"select",
"the",
"most",
"efficient",
"way",
"to",
"load",
"related",
"data",
"which",
"might",
"include",
"additional",
"select",
"query",
"or",
"left",
"join",
".",
"Loaded",
"data",
"will",
"automatically",
"pre",
"-",
"populate",
"record",
"relations",
".",
"You",
"can",
"specify",
"nested",
"relations",
"using",
".",
"separator",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RecordSelector.php#L189-L209
|
26,172
|
spiral/orm
|
source/Spiral/ORM/Entities/RecordSelector.php
|
RecordSelector.wherePK
|
public function wherePK($id): self
{
if (empty($this->loader->primaryKey())) {
//This MUST never happen due ORM requires PK now for every entity
throw new SelectorException("Unable to set wherePK condition, no proper PK were defined");
}
//Adding condition to initial query
$this->loader->initialQuery()->where([
//Must be already aliased
$this->loader->primaryKey() => $id
]);
return $this;
}
|
php
|
public function wherePK($id): self
{
if (empty($this->loader->primaryKey())) {
//This MUST never happen due ORM requires PK now for every entity
throw new SelectorException("Unable to set wherePK condition, no proper PK were defined");
}
//Adding condition to initial query
$this->loader->initialQuery()->where([
//Must be already aliased
$this->loader->primaryKey() => $id
]);
return $this;
}
|
[
"public",
"function",
"wherePK",
"(",
"$",
"id",
")",
":",
"self",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"loader",
"->",
"primaryKey",
"(",
")",
")",
")",
"{",
"//This MUST never happen due ORM requires PK now for every entity",
"throw",
"new",
"SelectorException",
"(",
"\"Unable to set wherePK condition, no proper PK were defined\"",
")",
";",
"}",
"//Adding condition to initial query",
"$",
"this",
"->",
"loader",
"->",
"initialQuery",
"(",
")",
"->",
"where",
"(",
"[",
"//Must be already aliased",
"$",
"this",
"->",
"loader",
"->",
"primaryKey",
"(",
")",
"=>",
"$",
"id",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Shortcut to where method to set AND condition for parent record primary key.
@param string|int $id
@return RecordSelector
@throws SelectorException
|
[
"Shortcut",
"to",
"where",
"method",
"to",
"set",
"AND",
"condition",
"for",
"parent",
"record",
"primary",
"key",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RecordSelector.php#L319-L333
|
26,173
|
spiral/orm
|
source/Spiral/ORM/Entities/RecordSelector.php
|
RecordSelector.findOne
|
public function findOne(array $query = null)
{
$data = (clone $this)->where($query)->fetchData();
if (empty($data[0])) {
return null;
}
return $this->orm->make($this->class, $data[0], ORMInterface::STATE_LOADED, true);
}
|
php
|
public function findOne(array $query = null)
{
$data = (clone $this)->where($query)->fetchData();
if (empty($data[0])) {
return null;
}
return $this->orm->make($this->class, $data[0], ORMInterface::STATE_LOADED, true);
}
|
[
"public",
"function",
"findOne",
"(",
"array",
"$",
"query",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"(",
"clone",
"$",
"this",
")",
"->",
"where",
"(",
"$",
"query",
")",
"->",
"fetchData",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
"[",
"0",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"orm",
"->",
"make",
"(",
"$",
"this",
"->",
"class",
",",
"$",
"data",
"[",
"0",
"]",
",",
"ORMInterface",
"::",
"STATE_LOADED",
",",
"true",
")",
";",
"}"
] |
Find one entity or return null.
@param array|null $query
@return EntityInterface|null
|
[
"Find",
"one",
"entity",
"or",
"return",
"null",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RecordSelector.php#L342-L351
|
26,174
|
spiral/orm
|
source/Spiral/ORM/Entities/RecordSelector.php
|
RecordSelector.fetchAll
|
public function fetchAll(
string $cacheKey = '',
$ttl = 0,
CacheInterface $cache = null
): array {
return iterator_to_array($this->getIterator($cacheKey, $ttl, $cache));
}
|
php
|
public function fetchAll(
string $cacheKey = '',
$ttl = 0,
CacheInterface $cache = null
): array {
return iterator_to_array($this->getIterator($cacheKey, $ttl, $cache));
}
|
[
"public",
"function",
"fetchAll",
"(",
"string",
"$",
"cacheKey",
"=",
"''",
",",
"$",
"ttl",
"=",
"0",
",",
"CacheInterface",
"$",
"cache",
"=",
"null",
")",
":",
"array",
"{",
"return",
"iterator_to_array",
"(",
"$",
"this",
"->",
"getIterator",
"(",
"$",
"cacheKey",
",",
"$",
"ttl",
",",
"$",
"cache",
")",
")",
";",
"}"
] |
Fetch all records in a form of array.
@param string $cacheKey
@param int|\DateInterval $ttl
@param CacheInterface|null $cache Can be automatically resoled via ORM container scope.
@return RecordInterface[]
|
[
"Fetch",
"all",
"records",
"in",
"a",
"form",
"of",
"array",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RecordSelector.php#L362-L368
|
26,175
|
spiral/orm
|
source/Spiral/ORM/Entities/RecordSelector.php
|
RecordSelector.count
|
public function count(string $column = null): int
{
if (is_null($column)) {
if (!empty($this->loader->primaryKey())) {
//@tuneyourserver solves the issue with counting on queries with joins.
$column = "DISTINCT({$this->loader->primaryKey()})";
} else {
$column = '*';
}
}
return $this->compiledQuery()->count($column);
}
|
php
|
public function count(string $column = null): int
{
if (is_null($column)) {
if (!empty($this->loader->primaryKey())) {
//@tuneyourserver solves the issue with counting on queries with joins.
$column = "DISTINCT({$this->loader->primaryKey()})";
} else {
$column = '*';
}
}
return $this->compiledQuery()->count($column);
}
|
[
"public",
"function",
"count",
"(",
"string",
"$",
"column",
"=",
"null",
")",
":",
"int",
"{",
"if",
"(",
"is_null",
"(",
"$",
"column",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"loader",
"->",
"primaryKey",
"(",
")",
")",
")",
"{",
"//@tuneyourserver solves the issue with counting on queries with joins.",
"$",
"column",
"=",
"\"DISTINCT({$this->loader->primaryKey()})\"",
";",
"}",
"else",
"{",
"$",
"column",
"=",
"'*'",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"compiledQuery",
"(",
")",
"->",
"count",
"(",
"$",
"column",
")",
";",
"}"
] |
Attention, column will be quoted by driver!
@param string|null $column When column is null DISTINCT(PK) will be generated.
@return int
|
[
"Attention",
"column",
"will",
"be",
"quoted",
"by",
"driver!"
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RecordSelector.php#L413-L425
|
26,176
|
spiral/orm
|
source/Spiral/ORM/Entities/RecordSelector.php
|
RecordSelector.fetchData
|
public function fetchData(OutputNode $node = null): array
{
/** @var OutputNode $node */
$node = $node ?? $this->loader->createNode();
//Working with parser defined by loader itself
$this->loader->loadData($node);
return $node->getResult();
}
|
php
|
public function fetchData(OutputNode $node = null): array
{
/** @var OutputNode $node */
$node = $node ?? $this->loader->createNode();
//Working with parser defined by loader itself
$this->loader->loadData($node);
return $node->getResult();
}
|
[
"public",
"function",
"fetchData",
"(",
"OutputNode",
"$",
"node",
"=",
"null",
")",
":",
"array",
"{",
"/** @var OutputNode $node */",
"$",
"node",
"=",
"$",
"node",
"??",
"$",
"this",
"->",
"loader",
"->",
"createNode",
"(",
")",
";",
"//Working with parser defined by loader itself",
"$",
"this",
"->",
"loader",
"->",
"loadData",
"(",
"$",
"node",
")",
";",
"return",
"$",
"node",
"->",
"getResult",
"(",
")",
";",
"}"
] |
Load data tree from databases and linked loaders in a form of array.
@param OutputNode $node When empty node will be created automatically by root relation
loader.
@return array
|
[
"Load",
"data",
"tree",
"from",
"databases",
"and",
"linked",
"loaders",
"in",
"a",
"form",
"of",
"array",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Entities/RecordSelector.php#L465-L474
|
26,177
|
spiral/orm
|
source/Spiral/ORM/Configs/MutatorsConfig.php
|
MutatorsConfig.getMutators
|
public function getMutators(string $type): array
{
$type = $this->resolveAlias($type);
$mutators = $this->config['mutators'];
return isset($mutators[$type]) ? $mutators[$type] : [];
}
|
php
|
public function getMutators(string $type): array
{
$type = $this->resolveAlias($type);
$mutators = $this->config['mutators'];
return isset($mutators[$type]) ? $mutators[$type] : [];
}
|
[
"public",
"function",
"getMutators",
"(",
"string",
"$",
"type",
")",
":",
"array",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"resolveAlias",
"(",
"$",
"type",
")",
";",
"$",
"mutators",
"=",
"$",
"this",
"->",
"config",
"[",
"'mutators'",
"]",
";",
"return",
"isset",
"(",
"$",
"mutators",
"[",
"$",
"type",
"]",
")",
"?",
"$",
"mutators",
"[",
"$",
"type",
"]",
":",
"[",
"]",
";",
"}"
] |
Get list of mutators associated with given field type.
@param string $type
@return array
|
[
"Get",
"list",
"of",
"mutators",
"associated",
"with",
"given",
"field",
"type",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Configs/MutatorsConfig.php#L41-L47
|
26,178
|
spiral/orm
|
source/Spiral/ORM/Helpers/ColumnRenderer.php
|
ColumnRenderer.renderColumns
|
public function renderColumns(
array $fields,
array $defaults,
AbstractTable $table
): AbstractTable {
foreach ($fields as $name => $definition) {
$column = $table->column($name);
//Declaring our column
$this->declareColumn(
$column,
$definition,
array_key_exists($name, $defaults),
$defaults[$name] ?? null
);
}
return clone $table;
}
|
php
|
public function renderColumns(
array $fields,
array $defaults,
AbstractTable $table
): AbstractTable {
foreach ($fields as $name => $definition) {
$column = $table->column($name);
//Declaring our column
$this->declareColumn(
$column,
$definition,
array_key_exists($name, $defaults),
$defaults[$name] ?? null
);
}
return clone $table;
}
|
[
"public",
"function",
"renderColumns",
"(",
"array",
"$",
"fields",
",",
"array",
"$",
"defaults",
",",
"AbstractTable",
"$",
"table",
")",
":",
"AbstractTable",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"name",
"=>",
"$",
"definition",
")",
"{",
"$",
"column",
"=",
"$",
"table",
"->",
"column",
"(",
"$",
"name",
")",
";",
"//Declaring our column",
"$",
"this",
"->",
"declareColumn",
"(",
"$",
"column",
",",
"$",
"definition",
",",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"defaults",
")",
",",
"$",
"defaults",
"[",
"$",
"name",
"]",
"??",
"null",
")",
";",
"}",
"return",
"clone",
"$",
"table",
";",
"}"
] |
Render columns in table based on string definition.
Example:
renderColumns([
'id' => 'primary',
'time' => 'datetime, nullable',
'status' => 'enum(active, disabled)'
], [
'status' => 'active',
'time' => null, //idential as if define column as null
], $table);
Attention, new table instance will be returned!
@param array $fields
@param array $defaults
@param AbstractTable $table
@return AbstractTable
@throws ColumnRenderException
|
[
"Render",
"columns",
"in",
"table",
"based",
"on",
"string",
"definition",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Helpers/ColumnRenderer.php#L48-L66
|
26,179
|
spiral/orm
|
source/Spiral/ORM/Helpers/ColumnRenderer.php
|
ColumnRenderer.castDefault
|
public function castDefault(AbstractColumn $column)
{
if (in_array($column->abstractType(), ['timestamp', 'datetime', 'time', 'date'])) {
return 0;
}
if ($column->abstractType() == 'enum') {
//We can use first enum value as default
return $column->getEnumValues()[0];
}
switch ($column->phpType()) {
case 'int':
return 0;
case 'float':
return 0.0;
case 'bool':
return false;
}
return '';
}
|
php
|
public function castDefault(AbstractColumn $column)
{
if (in_array($column->abstractType(), ['timestamp', 'datetime', 'time', 'date'])) {
return 0;
}
if ($column->abstractType() == 'enum') {
//We can use first enum value as default
return $column->getEnumValues()[0];
}
switch ($column->phpType()) {
case 'int':
return 0;
case 'float':
return 0.0;
case 'bool':
return false;
}
return '';
}
|
[
"public",
"function",
"castDefault",
"(",
"AbstractColumn",
"$",
"column",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"column",
"->",
"abstractType",
"(",
")",
",",
"[",
"'timestamp'",
",",
"'datetime'",
",",
"'time'",
",",
"'date'",
"]",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"column",
"->",
"abstractType",
"(",
")",
"==",
"'enum'",
")",
"{",
"//We can use first enum value as default",
"return",
"$",
"column",
"->",
"getEnumValues",
"(",
")",
"[",
"0",
"]",
";",
"}",
"switch",
"(",
"$",
"column",
"->",
"phpType",
"(",
")",
")",
"{",
"case",
"'int'",
":",
"return",
"0",
";",
"case",
"'float'",
":",
"return",
"0.0",
";",
"case",
"'bool'",
":",
"return",
"false",
";",
"}",
"return",
"''",
";",
"}"
] |
Cast default value based on column type. Required to prevent conflicts when not nullable
column added to existed table with data in.
@param AbstractColumn $column
@return mixed
|
[
"Cast",
"default",
"value",
"based",
"on",
"column",
"type",
".",
"Required",
"to",
"prevent",
"conflicts",
"when",
"not",
"nullable",
"column",
"added",
"to",
"existed",
"table",
"with",
"data",
"in",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Helpers/ColumnRenderer.php#L177-L198
|
26,180
|
spiral/orm
|
source/Spiral/ORM/Schemas/SchemaBuilder.php
|
SchemaBuilder.addSchema
|
public function addSchema(SchemaInterface $schema): SchemaBuilder
{
$this->schemas[$schema->getClass()] = $schema;
return $this;
}
|
php
|
public function addSchema(SchemaInterface $schema): SchemaBuilder
{
$this->schemas[$schema->getClass()] = $schema;
return $this;
}
|
[
"public",
"function",
"addSchema",
"(",
"SchemaInterface",
"$",
"schema",
")",
":",
"SchemaBuilder",
"{",
"$",
"this",
"->",
"schemas",
"[",
"$",
"schema",
"->",
"getClass",
"(",
")",
"]",
"=",
"$",
"schema",
";",
"return",
"$",
"this",
";",
"}"
] |
Add new model schema into pool.
@param SchemaInterface $schema
@return self|$this
|
[
"Add",
"new",
"model",
"schema",
"into",
"pool",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/SchemaBuilder.php#L69-L74
|
26,181
|
spiral/orm
|
source/Spiral/ORM/Schemas/SchemaBuilder.php
|
SchemaBuilder.hasChanges
|
public function hasChanges(): bool
{
foreach ($this->getTables() as $table) {
if ($table->getComparator()->hasChanges()) {
return true;
}
}
return false;
}
|
php
|
public function hasChanges(): bool
{
foreach ($this->getTables() as $table) {
if ($table->getComparator()->hasChanges()) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"hasChanges",
"(",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getTables",
"(",
")",
"as",
"$",
"table",
")",
"{",
"if",
"(",
"$",
"table",
"->",
"getComparator",
"(",
")",
"->",
"hasChanges",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Indication that tables in database require syncing before being matched with ORM models.
@return bool
|
[
"Indication",
"that",
"tables",
"in",
"database",
"require",
"syncing",
"before",
"being",
"matched",
"with",
"ORM",
"models",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/SchemaBuilder.php#L297-L306
|
26,182
|
spiral/orm
|
source/Spiral/ORM/Schemas/SchemaBuilder.php
|
SchemaBuilder.renderModels
|
protected function renderModels()
{
foreach ($this->schemas as $schema) {
/**
* Attention, this method will request table schema from DBAL and will empty it's state
* so schema can define it from ground zero!
*/
$table = $this->requestTable(
$schema->getTable(),
$schema->getDatabase(),
true,
true
);
//Render table schema
$table = $schema->declareTable($table);
//Working with indexes
foreach ($schema->getIndexes() as $index) {
$table->index($index->getColumns())->unique($index->isUnique());
$table->index($index->getColumns())->setName($index->getName());
}
/*
* Attention, this is critical section:
*
* In order to work efficiently (like for real), ORM does require every table
* to have 1 and only 1 primary key, this is crucial for things like in memory
* cache, transaction command priority pipeline, multiple queue commands for one entity
* and etc.
*
* It is planned to support user defined PKs in a future using unique indexes and record
* schema.
*
* You are free to select any name for PK field.
*/
if (count($table->getPrimaryKeys()) !== 1) {
throw new SchemaException(
"Every record must have singular primary key (primary, bigPrimary types)"
);
}
//And put it back :)
$this->pushTable($table);
}
}
|
php
|
protected function renderModels()
{
foreach ($this->schemas as $schema) {
/**
* Attention, this method will request table schema from DBAL and will empty it's state
* so schema can define it from ground zero!
*/
$table = $this->requestTable(
$schema->getTable(),
$schema->getDatabase(),
true,
true
);
//Render table schema
$table = $schema->declareTable($table);
//Working with indexes
foreach ($schema->getIndexes() as $index) {
$table->index($index->getColumns())->unique($index->isUnique());
$table->index($index->getColumns())->setName($index->getName());
}
/*
* Attention, this is critical section:
*
* In order to work efficiently (like for real), ORM does require every table
* to have 1 and only 1 primary key, this is crucial for things like in memory
* cache, transaction command priority pipeline, multiple queue commands for one entity
* and etc.
*
* It is planned to support user defined PKs in a future using unique indexes and record
* schema.
*
* You are free to select any name for PK field.
*/
if (count($table->getPrimaryKeys()) !== 1) {
throw new SchemaException(
"Every record must have singular primary key (primary, bigPrimary types)"
);
}
//And put it back :)
$this->pushTable($table);
}
}
|
[
"protected",
"function",
"renderModels",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"schemas",
"as",
"$",
"schema",
")",
"{",
"/**\n * Attention, this method will request table schema from DBAL and will empty it's state\n * so schema can define it from ground zero!\n */",
"$",
"table",
"=",
"$",
"this",
"->",
"requestTable",
"(",
"$",
"schema",
"->",
"getTable",
"(",
")",
",",
"$",
"schema",
"->",
"getDatabase",
"(",
")",
",",
"true",
",",
"true",
")",
";",
"//Render table schema",
"$",
"table",
"=",
"$",
"schema",
"->",
"declareTable",
"(",
"$",
"table",
")",
";",
"//Working with indexes",
"foreach",
"(",
"$",
"schema",
"->",
"getIndexes",
"(",
")",
"as",
"$",
"index",
")",
"{",
"$",
"table",
"->",
"index",
"(",
"$",
"index",
"->",
"getColumns",
"(",
")",
")",
"->",
"unique",
"(",
"$",
"index",
"->",
"isUnique",
"(",
")",
")",
";",
"$",
"table",
"->",
"index",
"(",
"$",
"index",
"->",
"getColumns",
"(",
")",
")",
"->",
"setName",
"(",
"$",
"index",
"->",
"getName",
"(",
")",
")",
";",
"}",
"/*\n * Attention, this is critical section:\n *\n * In order to work efficiently (like for real), ORM does require every table\n * to have 1 and only 1 primary key, this is crucial for things like in memory\n * cache, transaction command priority pipeline, multiple queue commands for one entity\n * and etc.\n *\n * It is planned to support user defined PKs in a future using unique indexes and record\n * schema.\n *\n * You are free to select any name for PK field.\n */",
"if",
"(",
"count",
"(",
"$",
"table",
"->",
"getPrimaryKeys",
"(",
")",
")",
"!==",
"1",
")",
"{",
"throw",
"new",
"SchemaException",
"(",
"\"Every record must have singular primary key (primary, bigPrimary types)\"",
")",
";",
"}",
"//And put it back :)",
"$",
"this",
"->",
"pushTable",
"(",
"$",
"table",
")",
";",
"}",
"}"
] |
Walk thought schemas and define structure of associated tables.
@throws SchemaException
@throws DBALException
|
[
"Walk",
"thought",
"schemas",
"and",
"define",
"structure",
"of",
"associated",
"tables",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/SchemaBuilder.php#L379-L424
|
26,183
|
spiral/orm
|
source/Spiral/ORM/Schemas/SchemaBuilder.php
|
SchemaBuilder.renderRelations
|
protected function renderRelations()
{
foreach ($this->schemas as $schema) {
foreach ($schema->getRelations() as $name => $relation) {
//Source context defines where relation comes from
$sourceContext = RelationContext::createContent(
$schema,
$this->requestTable($schema->getTable(), $schema->getDatabase())
);
//Target context might only exist if relation points to another record in ORM,
//in some cases it might point outside of ORM scope
$targetContext = null;
if ($this->hasSchema($relation->getTarget())) {
$target = $this->getSchema($relation->getTarget());
$targetContext = RelationContext::createContent(
$target,
$this->requestTable($target->getTable(), $target->getDatabase())
);
}
$this->relations->registerRelation(
$this,
$relation->withContext($sourceContext, $targetContext)
);
}
}
}
|
php
|
protected function renderRelations()
{
foreach ($this->schemas as $schema) {
foreach ($schema->getRelations() as $name => $relation) {
//Source context defines where relation comes from
$sourceContext = RelationContext::createContent(
$schema,
$this->requestTable($schema->getTable(), $schema->getDatabase())
);
//Target context might only exist if relation points to another record in ORM,
//in some cases it might point outside of ORM scope
$targetContext = null;
if ($this->hasSchema($relation->getTarget())) {
$target = $this->getSchema($relation->getTarget());
$targetContext = RelationContext::createContent(
$target,
$this->requestTable($target->getTable(), $target->getDatabase())
);
}
$this->relations->registerRelation(
$this,
$relation->withContext($sourceContext, $targetContext)
);
}
}
}
|
[
"protected",
"function",
"renderRelations",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"schemas",
"as",
"$",
"schema",
")",
"{",
"foreach",
"(",
"$",
"schema",
"->",
"getRelations",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"relation",
")",
"{",
"//Source context defines where relation comes from",
"$",
"sourceContext",
"=",
"RelationContext",
"::",
"createContent",
"(",
"$",
"schema",
",",
"$",
"this",
"->",
"requestTable",
"(",
"$",
"schema",
"->",
"getTable",
"(",
")",
",",
"$",
"schema",
"->",
"getDatabase",
"(",
")",
")",
")",
";",
"//Target context might only exist if relation points to another record in ORM,",
"//in some cases it might point outside of ORM scope",
"$",
"targetContext",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"hasSchema",
"(",
"$",
"relation",
"->",
"getTarget",
"(",
")",
")",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"getSchema",
"(",
"$",
"relation",
"->",
"getTarget",
"(",
")",
")",
";",
"$",
"targetContext",
"=",
"RelationContext",
"::",
"createContent",
"(",
"$",
"target",
",",
"$",
"this",
"->",
"requestTable",
"(",
"$",
"target",
"->",
"getTable",
"(",
")",
",",
"$",
"target",
"->",
"getDatabase",
"(",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"relations",
"->",
"registerRelation",
"(",
"$",
"this",
",",
"$",
"relation",
"->",
"withContext",
"(",
"$",
"sourceContext",
",",
"$",
"targetContext",
")",
")",
";",
"}",
"}",
"}"
] |
Walk thought all record schemas, fetch and declare needed relations using relation manager.
@throws SchemaException
@throws DefinitionException
|
[
"Walk",
"thought",
"all",
"record",
"schemas",
"fetch",
"and",
"declare",
"needed",
"relations",
"using",
"relation",
"manager",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/SchemaBuilder.php#L432-L462
|
26,184
|
spiral/orm
|
source/Spiral/ORM/Schemas/SchemaBuilder.php
|
SchemaBuilder.pushTable
|
protected function pushTable(AbstractTable $schema)
{
//We have to make sure that local table name is used
$table = substr($schema->getName(), strlen($schema->getPrefix()));
if (empty($this->tables[$schema->getDriver()->getName() . '.' . $table])) {
throw new SchemaException("AbstractTable must be requested before pushing back");
}
$this->tables[$schema->getDriver()->getName() . '.' . $table] = $schema;
}
|
php
|
protected function pushTable(AbstractTable $schema)
{
//We have to make sure that local table name is used
$table = substr($schema->getName(), strlen($schema->getPrefix()));
if (empty($this->tables[$schema->getDriver()->getName() . '.' . $table])) {
throw new SchemaException("AbstractTable must be requested before pushing back");
}
$this->tables[$schema->getDriver()->getName() . '.' . $table] = $schema;
}
|
[
"protected",
"function",
"pushTable",
"(",
"AbstractTable",
"$",
"schema",
")",
"{",
"//We have to make sure that local table name is used",
"$",
"table",
"=",
"substr",
"(",
"$",
"schema",
"->",
"getName",
"(",
")",
",",
"strlen",
"(",
"$",
"schema",
"->",
"getPrefix",
"(",
")",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"tables",
"[",
"$",
"schema",
"->",
"getDriver",
"(",
")",
"->",
"getName",
"(",
")",
".",
"'.'",
".",
"$",
"table",
"]",
")",
")",
"{",
"throw",
"new",
"SchemaException",
"(",
"\"AbstractTable must be requested before pushing back\"",
")",
";",
"}",
"$",
"this",
"->",
"tables",
"[",
"$",
"schema",
"->",
"getDriver",
"(",
")",
"->",
"getName",
"(",
")",
".",
"'.'",
".",
"$",
"table",
"]",
"=",
"$",
"schema",
";",
"}"
] |
Update table state.
@param AbstractTable $schema
@throws SchemaException
|
[
"Update",
"table",
"state",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/SchemaBuilder.php#L471-L481
|
26,185
|
spiral/orm
|
source/Spiral/ORM/Schemas/Relations/Traits/TablesTrait.php
|
TablesTrait.sourceTable
|
protected function sourceTable(SchemaBuilder $builder): AbstractTable
{
$source = $this->getDefinition()->sourceContext();
return $builder->requestTable($source->getTable(), $source->getDatabase());
}
|
php
|
protected function sourceTable(SchemaBuilder $builder): AbstractTable
{
$source = $this->getDefinition()->sourceContext();
return $builder->requestTable($source->getTable(), $source->getDatabase());
}
|
[
"protected",
"function",
"sourceTable",
"(",
"SchemaBuilder",
"$",
"builder",
")",
":",
"AbstractTable",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"getDefinition",
"(",
")",
"->",
"sourceContext",
"(",
")",
";",
"return",
"$",
"builder",
"->",
"requestTable",
"(",
"$",
"source",
"->",
"getTable",
"(",
")",
",",
"$",
"source",
"->",
"getDatabase",
"(",
")",
")",
";",
"}"
] |
Get table linked with source relation model.
@param SchemaBuilder $builder
@return AbstractTable
@throws RelationSchemaException
|
[
"Get",
"table",
"linked",
"with",
"source",
"relation",
"model",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/Relations/Traits/TablesTrait.php#L26-L31
|
26,186
|
spiral/orm
|
source/Spiral/ORM/Schemas/Relations/Traits/TablesTrait.php
|
TablesTrait.targetTable
|
protected function targetTable(SchemaBuilder $builder): AbstractTable
{
$target = $this->getDefinition()->targetContext();
if (empty($target)) {
throw new RelationSchemaException(sprintf(
"Unable to get target context '%s' in '%s'.'%s'",
$this->getDefinition()->getTarget(),
$this->getDefinition()->sourceContext()->getClass(),
$this->getDefinition()->getName()
));
}
return $builder->requestTable($target->getTable(), $target->getDatabase());
}
|
php
|
protected function targetTable(SchemaBuilder $builder): AbstractTable
{
$target = $this->getDefinition()->targetContext();
if (empty($target)) {
throw new RelationSchemaException(sprintf(
"Unable to get target context '%s' in '%s'.'%s'",
$this->getDefinition()->getTarget(),
$this->getDefinition()->sourceContext()->getClass(),
$this->getDefinition()->getName()
));
}
return $builder->requestTable($target->getTable(), $target->getDatabase());
}
|
[
"protected",
"function",
"targetTable",
"(",
"SchemaBuilder",
"$",
"builder",
")",
":",
"AbstractTable",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"getDefinition",
"(",
")",
"->",
"targetContext",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"target",
")",
")",
"{",
"throw",
"new",
"RelationSchemaException",
"(",
"sprintf",
"(",
"\"Unable to get target context '%s' in '%s'.'%s'\"",
",",
"$",
"this",
"->",
"getDefinition",
"(",
")",
"->",
"getTarget",
"(",
")",
",",
"$",
"this",
"->",
"getDefinition",
"(",
")",
"->",
"sourceContext",
"(",
")",
"->",
"getClass",
"(",
")",
",",
"$",
"this",
"->",
"getDefinition",
"(",
")",
"->",
"getName",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"builder",
"->",
"requestTable",
"(",
"$",
"target",
"->",
"getTable",
"(",
")",
",",
"$",
"target",
"->",
"getDatabase",
"(",
")",
")",
";",
"}"
] |
Get table linked with target relation model.
@param SchemaBuilder $builder
@return AbstractTable
@throws RelationSchemaException
|
[
"Get",
"table",
"linked",
"with",
"target",
"relation",
"model",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Schemas/Relations/Traits/TablesTrait.php#L42-L55
|
26,187
|
spiral/orm
|
source/Spiral/ORM/Record.php
|
Record.save
|
public function save(TransactionInterface $transaction = null, bool $queueRelations = true): int
{
/*
* First, per interface agreement calculate entity state after save command being called.
*/
if (!$this->isLoaded()) {
$state = self::CREATED;
} elseif (!$this->hasChanges()) {
$state = self::UPDATED;
} else {
$state = self::UNCHANGED;
}
if (empty($transaction)) {
/*
* When no transaction is given we will create our own and run it immediately.
*/
$transaction = $transaction ?? new Transaction();
$transaction->store($this, $queueRelations);
$transaction->run();
} else {
$transaction->addCommand($this->queueStore($queueRelations));
}
return $state;
}
|
php
|
public function save(TransactionInterface $transaction = null, bool $queueRelations = true): int
{
/*
* First, per interface agreement calculate entity state after save command being called.
*/
if (!$this->isLoaded()) {
$state = self::CREATED;
} elseif (!$this->hasChanges()) {
$state = self::UPDATED;
} else {
$state = self::UNCHANGED;
}
if (empty($transaction)) {
/*
* When no transaction is given we will create our own and run it immediately.
*/
$transaction = $transaction ?? new Transaction();
$transaction->store($this, $queueRelations);
$transaction->run();
} else {
$transaction->addCommand($this->queueStore($queueRelations));
}
return $state;
}
|
[
"public",
"function",
"save",
"(",
"TransactionInterface",
"$",
"transaction",
"=",
"null",
",",
"bool",
"$",
"queueRelations",
"=",
"true",
")",
":",
"int",
"{",
"/*\n * First, per interface agreement calculate entity state after save command being called.\n */",
"if",
"(",
"!",
"$",
"this",
"->",
"isLoaded",
"(",
")",
")",
"{",
"$",
"state",
"=",
"self",
"::",
"CREATED",
";",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"hasChanges",
"(",
")",
")",
"{",
"$",
"state",
"=",
"self",
"::",
"UPDATED",
";",
"}",
"else",
"{",
"$",
"state",
"=",
"self",
"::",
"UNCHANGED",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"transaction",
")",
")",
"{",
"/*\n * When no transaction is given we will create our own and run it immediately.\n */",
"$",
"transaction",
"=",
"$",
"transaction",
"??",
"new",
"Transaction",
"(",
")",
";",
"$",
"transaction",
"->",
"store",
"(",
"$",
"this",
",",
"$",
"queueRelations",
")",
";",
"$",
"transaction",
"->",
"run",
"(",
")",
";",
"}",
"else",
"{",
"$",
"transaction",
"->",
"addCommand",
"(",
"$",
"this",
"->",
"queueStore",
"(",
"$",
"queueRelations",
")",
")",
";",
"}",
"return",
"$",
"state",
";",
"}"
] |
Sync entity with database, when no transaction is given ActiveRecord will create and run it
automatically.
@param TransactionInterface|null $transaction
@param bool $queueRelations
@return int
|
[
"Sync",
"entity",
"with",
"database",
"when",
"no",
"transaction",
"is",
"given",
"ActiveRecord",
"will",
"create",
"and",
"run",
"it",
"automatically",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Record.php#L26-L51
|
26,188
|
spiral/orm
|
source/Spiral/ORM/Record.php
|
Record.delete
|
public function delete(TransactionInterface $transaction = null)
{
if (empty($transaction)) {
/*
* When no transaction is given we will create our own and run it immediately.
*/
$transaction = $transaction ?? new Transaction();
$transaction->delete($this);
$transaction->run();
} else {
$transaction->addCommand($this->queueDelete());
}
}
|
php
|
public function delete(TransactionInterface $transaction = null)
{
if (empty($transaction)) {
/*
* When no transaction is given we will create our own and run it immediately.
*/
$transaction = $transaction ?? new Transaction();
$transaction->delete($this);
$transaction->run();
} else {
$transaction->addCommand($this->queueDelete());
}
}
|
[
"public",
"function",
"delete",
"(",
"TransactionInterface",
"$",
"transaction",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"transaction",
")",
")",
"{",
"/*\n * When no transaction is given we will create our own and run it immediately.\n */",
"$",
"transaction",
"=",
"$",
"transaction",
"??",
"new",
"Transaction",
"(",
")",
";",
"$",
"transaction",
"->",
"delete",
"(",
"$",
"this",
")",
";",
"$",
"transaction",
"->",
"run",
"(",
")",
";",
"}",
"else",
"{",
"$",
"transaction",
"->",
"addCommand",
"(",
"$",
"this",
"->",
"queueDelete",
"(",
")",
")",
";",
"}",
"}"
] |
Delete entity in database, when no transaction is given ActiveRecord will create and run it
automatically.
@param TransactionInterface|null $transaction
|
[
"Delete",
"entity",
"in",
"database",
"when",
"no",
"transaction",
"is",
"given",
"ActiveRecord",
"will",
"create",
"and",
"run",
"it",
"automatically",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Record.php#L59-L71
|
26,189
|
rinvex/cortex-foundation
|
src/DataTables/AbstractDataTable.php
|
AbstractDataTable.filename
|
protected function filename(): string
{
$model = $this->model ?? trim(str_replace('DataTable', '', mb_strrchr(static::class, '\\')), " \t\n\r\0\x0B\\");
$resource = str_plural(mb_strtolower(array_last(explode(class_exists($model) ? '\\' : '.', $model))));
return $resource.'-export-'.date('Y-m-d').'-'.time();
}
|
php
|
protected function filename(): string
{
$model = $this->model ?? trim(str_replace('DataTable', '', mb_strrchr(static::class, '\\')), " \t\n\r\0\x0B\\");
$resource = str_plural(mb_strtolower(array_last(explode(class_exists($model) ? '\\' : '.', $model))));
return $resource.'-export-'.date('Y-m-d').'-'.time();
}
|
[
"protected",
"function",
"filename",
"(",
")",
":",
"string",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
"??",
"trim",
"(",
"str_replace",
"(",
"'DataTable'",
",",
"''",
",",
"mb_strrchr",
"(",
"static",
"::",
"class",
",",
"'\\\\'",
")",
")",
",",
"\" \\t\\n\\r\\0\\x0B\\\\\"",
")",
";",
"$",
"resource",
"=",
"str_plural",
"(",
"mb_strtolower",
"(",
"array_last",
"(",
"explode",
"(",
"class_exists",
"(",
"$",
"model",
")",
"?",
"'\\\\'",
":",
"'.'",
",",
"$",
"model",
")",
")",
")",
")",
";",
"return",
"$",
"resource",
".",
"'-export-'",
".",
"date",
"(",
"'Y-m-d'",
")",
".",
"'-'",
".",
"time",
"(",
")",
";",
"}"
] |
Get filename for export.
@return string
|
[
"Get",
"filename",
"for",
"export",
"."
] |
230c100d98131c76f777e5036b3e7cd83af49e6e
|
https://github.com/rinvex/cortex-foundation/blob/230c100d98131c76f777e5036b3e7cd83af49e6e/src/DataTables/AbstractDataTable.php#L197-L204
|
26,190
|
swoft-cloud/swoft-rpc-server
|
src/Command/RpcCommand.php
|
RpcCommand.start
|
public function start()
{
$rpcServer = $this->getRpcServer();
// 是否正在运行
if ($rpcServer->isRunning()) {
$serverStatus = $rpcServer->getServerSetting();
\output()->writeln("<error>The server have been running!(PID: {$serverStatus['masterPid']})</error>", true, true);
}
// 选项参数解析
$this->setStartArgs($rpcServer);
$tcpStatus = $rpcServer->getTcpSetting();
// tcp启动参数
$tcpHost = $tcpStatus['host'];
$tcpPort = $tcpStatus['port'];
$tcpType = $tcpStatus['type'];
$tcpMode = $tcpStatus['mode'];
// 信息面板
$lines = [
' Information Panel ',
'*************************************************************',
"* tcp | Host: <note>$tcpHost</note>, port: <note>$tcpPort</note>, mode: <note>$tcpMode</note>, type: <note>$tcpType</note>",
'*************************************************************',
];
\output()->writeln(implode("\n", $lines));
// 启动
$rpcServer->start();
}
|
php
|
public function start()
{
$rpcServer = $this->getRpcServer();
// 是否正在运行
if ($rpcServer->isRunning()) {
$serverStatus = $rpcServer->getServerSetting();
\output()->writeln("<error>The server have been running!(PID: {$serverStatus['masterPid']})</error>", true, true);
}
// 选项参数解析
$this->setStartArgs($rpcServer);
$tcpStatus = $rpcServer->getTcpSetting();
// tcp启动参数
$tcpHost = $tcpStatus['host'];
$tcpPort = $tcpStatus['port'];
$tcpType = $tcpStatus['type'];
$tcpMode = $tcpStatus['mode'];
// 信息面板
$lines = [
' Information Panel ',
'*************************************************************',
"* tcp | Host: <note>$tcpHost</note>, port: <note>$tcpPort</note>, mode: <note>$tcpMode</note>, type: <note>$tcpType</note>",
'*************************************************************',
];
\output()->writeln(implode("\n", $lines));
// 启动
$rpcServer->start();
}
|
[
"public",
"function",
"start",
"(",
")",
"{",
"$",
"rpcServer",
"=",
"$",
"this",
"->",
"getRpcServer",
"(",
")",
";",
"// 是否正在运行",
"if",
"(",
"$",
"rpcServer",
"->",
"isRunning",
"(",
")",
")",
"{",
"$",
"serverStatus",
"=",
"$",
"rpcServer",
"->",
"getServerSetting",
"(",
")",
";",
"\\",
"output",
"(",
")",
"->",
"writeln",
"(",
"\"<error>The server have been running!(PID: {$serverStatus['masterPid']})</error>\"",
",",
"true",
",",
"true",
")",
";",
"}",
"// 选项参数解析",
"$",
"this",
"->",
"setStartArgs",
"(",
"$",
"rpcServer",
")",
";",
"$",
"tcpStatus",
"=",
"$",
"rpcServer",
"->",
"getTcpSetting",
"(",
")",
";",
"// tcp启动参数",
"$",
"tcpHost",
"=",
"$",
"tcpStatus",
"[",
"'host'",
"]",
";",
"$",
"tcpPort",
"=",
"$",
"tcpStatus",
"[",
"'port'",
"]",
";",
"$",
"tcpType",
"=",
"$",
"tcpStatus",
"[",
"'type'",
"]",
";",
"$",
"tcpMode",
"=",
"$",
"tcpStatus",
"[",
"'mode'",
"]",
";",
"// 信息面板",
"$",
"lines",
"=",
"[",
"' Information Panel '",
",",
"'*************************************************************'",
",",
"\"* tcp | Host: <note>$tcpHost</note>, port: <note>$tcpPort</note>, mode: <note>$tcpMode</note>, type: <note>$tcpType</note>\"",
",",
"'*************************************************************'",
",",
"]",
";",
"\\",
"output",
"(",
")",
"->",
"writeln",
"(",
"implode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
")",
";",
"// 启动",
"$",
"rpcServer",
"->",
"start",
"(",
")",
";",
"}"
] |
start rpc server
@Usage {fullCommand} [-d|--daemon]
@Options
-d, --daemon Run server on the background
@Example
{fullCommand}
{fullCommand} -d
|
[
"start",
"rpc",
"server"
] |
527ce20421ad46919b16ebdcc12658f0e3807a07
|
https://github.com/swoft-cloud/swoft-rpc-server/blob/527ce20421ad46919b16ebdcc12658f0e3807a07/src/Command/RpcCommand.php#L24-L55
|
26,191
|
swoft-cloud/swoft-rpc-server
|
src/Command/RpcCommand.php
|
RpcCommand.reload
|
public function reload()
{
$rpcServer = $this->getRpcServer();
// 是否已启动
if (! $rpcServer->isRunning()) {
output()->writeln('<error>The server is not running! cannot reload</error>', true, true);
}
// 打印信息
output()->writeln(sprintf('<info>Server %s is reloading ...</info>', input()->getFullScript()));
// 重载
$reloadTask = input()->hasOpt('t');
$rpcServer->reload($reloadTask);
output()->writeln(sprintf('<success>Server %s is reload success</success>', input()->getFullScript()));
}
|
php
|
public function reload()
{
$rpcServer = $this->getRpcServer();
// 是否已启动
if (! $rpcServer->isRunning()) {
output()->writeln('<error>The server is not running! cannot reload</error>', true, true);
}
// 打印信息
output()->writeln(sprintf('<info>Server %s is reloading ...</info>', input()->getFullScript()));
// 重载
$reloadTask = input()->hasOpt('t');
$rpcServer->reload($reloadTask);
output()->writeln(sprintf('<success>Server %s is reload success</success>', input()->getFullScript()));
}
|
[
"public",
"function",
"reload",
"(",
")",
"{",
"$",
"rpcServer",
"=",
"$",
"this",
"->",
"getRpcServer",
"(",
")",
";",
"// 是否已启动",
"if",
"(",
"!",
"$",
"rpcServer",
"->",
"isRunning",
"(",
")",
")",
"{",
"output",
"(",
")",
"->",
"writeln",
"(",
"'<error>The server is not running! cannot reload</error>'",
",",
"true",
",",
"true",
")",
";",
"}",
"// 打印信息",
"output",
"(",
")",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<info>Server %s is reloading ...</info>'",
",",
"input",
"(",
")",
"->",
"getFullScript",
"(",
")",
")",
")",
";",
"// 重载",
"$",
"reloadTask",
"=",
"input",
"(",
")",
"->",
"hasOpt",
"(",
"'t'",
")",
";",
"$",
"rpcServer",
"->",
"reload",
"(",
"$",
"reloadTask",
")",
";",
"output",
"(",
")",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<success>Server %s is reload success</success>'",
",",
"input",
"(",
")",
"->",
"getFullScript",
"(",
")",
")",
")",
";",
"}"
] |
reload worker process
@Usage
{fullCommand} [arguments] [options]
@Options
-t Only to reload task processes, default to reload worker and task
@Example
php swoft.php rpc:reload
|
[
"reload",
"worker",
"process"
] |
527ce20421ad46919b16ebdcc12658f0e3807a07
|
https://github.com/swoft-cloud/swoft-rpc-server/blob/527ce20421ad46919b16ebdcc12658f0e3807a07/src/Command/RpcCommand.php#L67-L83
|
26,192
|
swoft-cloud/swoft-rpc-server
|
src/Command/RpcCommand.php
|
RpcCommand.stop
|
public function stop()
{
$rpcServer = $this->getRpcServer();
// 是否已启动
if (! $rpcServer->isRunning()) {
\output()->writeln('<error>The server is not running! cannot stop</error>', true, true);
}
// pid文件
$serverStatus = $rpcServer->getServerSetting();
$pidFile = $serverStatus['pfile'];
\output()->writeln(sprintf('<info>Swoft %s is stopping ...</info>', input()->getFullScript()));
$result = $rpcServer->stop();
// 停止失败
if (! $result) {
\output()->writeln(sprintf('<error>Swoft %s stop fail</error>', input()->getFullScript()));
}
//删除pid文件
@unlink($pidFile);
\output()->writeln(sprintf('<success>Swoft %s stop success</success>', input()->getFullScript()));
}
|
php
|
public function stop()
{
$rpcServer = $this->getRpcServer();
// 是否已启动
if (! $rpcServer->isRunning()) {
\output()->writeln('<error>The server is not running! cannot stop</error>', true, true);
}
// pid文件
$serverStatus = $rpcServer->getServerSetting();
$pidFile = $serverStatus['pfile'];
\output()->writeln(sprintf('<info>Swoft %s is stopping ...</info>', input()->getFullScript()));
$result = $rpcServer->stop();
// 停止失败
if (! $result) {
\output()->writeln(sprintf('<error>Swoft %s stop fail</error>', input()->getFullScript()));
}
//删除pid文件
@unlink($pidFile);
\output()->writeln(sprintf('<success>Swoft %s stop success</success>', input()->getFullScript()));
}
|
[
"public",
"function",
"stop",
"(",
")",
"{",
"$",
"rpcServer",
"=",
"$",
"this",
"->",
"getRpcServer",
"(",
")",
";",
"// 是否已启动",
"if",
"(",
"!",
"$",
"rpcServer",
"->",
"isRunning",
"(",
")",
")",
"{",
"\\",
"output",
"(",
")",
"->",
"writeln",
"(",
"'<error>The server is not running! cannot stop</error>'",
",",
"true",
",",
"true",
")",
";",
"}",
"// pid文件",
"$",
"serverStatus",
"=",
"$",
"rpcServer",
"->",
"getServerSetting",
"(",
")",
";",
"$",
"pidFile",
"=",
"$",
"serverStatus",
"[",
"'pfile'",
"]",
";",
"\\",
"output",
"(",
")",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<info>Swoft %s is stopping ...</info>'",
",",
"input",
"(",
")",
"->",
"getFullScript",
"(",
")",
")",
")",
";",
"$",
"result",
"=",
"$",
"rpcServer",
"->",
"stop",
"(",
")",
";",
"// 停止失败",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"\\",
"output",
"(",
")",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<error>Swoft %s stop fail</error>'",
",",
"input",
"(",
")",
"->",
"getFullScript",
"(",
")",
")",
")",
";",
"}",
"//删除pid文件",
"@",
"unlink",
"(",
"$",
"pidFile",
")",
";",
"\\",
"output",
"(",
")",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<success>Swoft %s stop success</success>'",
",",
"input",
"(",
")",
"->",
"getFullScript",
"(",
")",
")",
")",
";",
"}"
] |
stop rpc server
@Usage {fullCommand}
@Example {fullCommand}
|
[
"stop",
"rpc",
"server"
] |
527ce20421ad46919b16ebdcc12658f0e3807a07
|
https://github.com/swoft-cloud/swoft-rpc-server/blob/527ce20421ad46919b16ebdcc12658f0e3807a07/src/Command/RpcCommand.php#L91-L116
|
26,193
|
swoft-cloud/swoft-rpc-server
|
src/Command/RpcCommand.php
|
RpcCommand.restart
|
public function restart()
{
$rpcServer = $this->getRpcServer();
// 是否已启动
if ($rpcServer->isRunning()) {
$this->stop();
}
// 重启默认是守护进程
$rpcServer->setDaemonize();
$this->start();
}
|
php
|
public function restart()
{
$rpcServer = $this->getRpcServer();
// 是否已启动
if ($rpcServer->isRunning()) {
$this->stop();
}
// 重启默认是守护进程
$rpcServer->setDaemonize();
$this->start();
}
|
[
"public",
"function",
"restart",
"(",
")",
"{",
"$",
"rpcServer",
"=",
"$",
"this",
"->",
"getRpcServer",
"(",
")",
";",
"// 是否已启动",
"if",
"(",
"$",
"rpcServer",
"->",
"isRunning",
"(",
")",
")",
"{",
"$",
"this",
"->",
"stop",
"(",
")",
";",
"}",
"// 重启默认是守护进程",
"$",
"rpcServer",
"->",
"setDaemonize",
"(",
")",
";",
"$",
"this",
"->",
"start",
"(",
")",
";",
"}"
] |
restart rpc server
@Usage {fullCommand}
@Options
-d, --daemon Run server on the background
@Example
{fullCommand}
{fullCommand} -d
|
[
"restart",
"rpc",
"server"
] |
527ce20421ad46919b16ebdcc12658f0e3807a07
|
https://github.com/swoft-cloud/swoft-rpc-server/blob/527ce20421ad46919b16ebdcc12658f0e3807a07/src/Command/RpcCommand.php#L128-L140
|
26,194
|
spiral/orm
|
source/Spiral/ORM/Traits/SourceTrait.php
|
SourceTrait.source
|
public static function source(): RecordSource
{
/**
* Container to be received via global scope.
*
* @var ContainerInterface $container
*/
//Via global scope
$container = self::staticContainer();
if (empty($container)) {
//Via global scope
throw new ScopeException(sprintf(
"Unable to get '%s' source, no container scope is available",
static::class
));
}
return $container->get(ORMInterface::class)->source(static::class);
}
|
php
|
public static function source(): RecordSource
{
/**
* Container to be received via global scope.
*
* @var ContainerInterface $container
*/
//Via global scope
$container = self::staticContainer();
if (empty($container)) {
//Via global scope
throw new ScopeException(sprintf(
"Unable to get '%s' source, no container scope is available",
static::class
));
}
return $container->get(ORMInterface::class)->source(static::class);
}
|
[
"public",
"static",
"function",
"source",
"(",
")",
":",
"RecordSource",
"{",
"/**\n * Container to be received via global scope.\n *\n * @var ContainerInterface $container\n */",
"//Via global scope",
"$",
"container",
"=",
"self",
"::",
"staticContainer",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"container",
")",
")",
"{",
"//Via global scope",
"throw",
"new",
"ScopeException",
"(",
"sprintf",
"(",
"\"Unable to get '%s' source, no container scope is available\"",
",",
"static",
"::",
"class",
")",
")",
";",
"}",
"return",
"$",
"container",
"->",
"get",
"(",
"ORMInterface",
"::",
"class",
")",
"->",
"source",
"(",
"static",
"::",
"class",
")",
";",
"}"
] |
Instance of RecordSource associated with specific model.
@see Component::staticContainer()
*
@return RecordSource
@throws ScopeException
|
[
"Instance",
"of",
"RecordSource",
"associated",
"with",
"specific",
"model",
"."
] |
a301cd1b664e65496dab648d77ee92bf4fb6949b
|
https://github.com/spiral/orm/blob/a301cd1b664e65496dab648d77ee92bf4fb6949b/source/Spiral/ORM/Traits/SourceTrait.php#L87-L106
|
26,195
|
swoft-cloud/swoft-rpc-server
|
src/Validator/ServiceValidator.php
|
ServiceValidator.getServiceArgs
|
private function getServiceArgs(array $serviceHandler, array $serviceData): array
{
list($className, $method) = $serviceHandler;
$rc = new \ReflectionClass($className);
$rm = $rc->getMethod($method);
$mps = $rm->getParameters();
$params = $serviceData['params'] ?? [];
if (empty($params)) {
return [];
}
$index = 0;
$args = [];
foreach ($mps as $mp) {
$name = $mp->getName();
if (! isset($params[$index])) {
break;
}
$args[$name] = $params[$index];
$index++;
}
return $args;
}
|
php
|
private function getServiceArgs(array $serviceHandler, array $serviceData): array
{
list($className, $method) = $serviceHandler;
$rc = new \ReflectionClass($className);
$rm = $rc->getMethod($method);
$mps = $rm->getParameters();
$params = $serviceData['params'] ?? [];
if (empty($params)) {
return [];
}
$index = 0;
$args = [];
foreach ($mps as $mp) {
$name = $mp->getName();
if (! isset($params[$index])) {
break;
}
$args[$name] = $params[$index];
$index++;
}
return $args;
}
|
[
"private",
"function",
"getServiceArgs",
"(",
"array",
"$",
"serviceHandler",
",",
"array",
"$",
"serviceData",
")",
":",
"array",
"{",
"list",
"(",
"$",
"className",
",",
"$",
"method",
")",
"=",
"$",
"serviceHandler",
";",
"$",
"rc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"rm",
"=",
"$",
"rc",
"->",
"getMethod",
"(",
"$",
"method",
")",
";",
"$",
"mps",
"=",
"$",
"rm",
"->",
"getParameters",
"(",
")",
";",
"$",
"params",
"=",
"$",
"serviceData",
"[",
"'params'",
"]",
"??",
"[",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"index",
"=",
"0",
";",
"$",
"args",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"mps",
"as",
"$",
"mp",
")",
"{",
"$",
"name",
"=",
"$",
"mp",
"->",
"getName",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"$",
"index",
"]",
")",
")",
"{",
"break",
";",
"}",
"$",
"args",
"[",
"$",
"name",
"]",
"=",
"$",
"params",
"[",
"$",
"index",
"]",
";",
"$",
"index",
"++",
";",
"}",
"return",
"$",
"args",
";",
"}"
] |
get args of called function
@param array $serviceHandler
@param array $serviceData
@return array
@throws \ReflectionException
|
[
"get",
"args",
"of",
"called",
"function"
] |
527ce20421ad46919b16ebdcc12658f0e3807a07
|
https://github.com/swoft-cloud/swoft-rpc-server/blob/527ce20421ad46919b16ebdcc12658f0e3807a07/src/Validator/ServiceValidator.php#L56-L80
|
26,196
|
mirko-pagliai/cakephp-assets
|
src/Utility/AssetsCreator.php
|
AssetsCreator.resolveAssetPath
|
protected function resolveAssetPath()
{
$basename = md5(serialize(array_map(function ($path) {
return [$path, filemtime($path)];
}, $this->paths)));
return Configure::read('Assets.target') . DS . $basename . '.' . $this->type;
}
|
php
|
protected function resolveAssetPath()
{
$basename = md5(serialize(array_map(function ($path) {
return [$path, filemtime($path)];
}, $this->paths)));
return Configure::read('Assets.target') . DS . $basename . '.' . $this->type;
}
|
[
"protected",
"function",
"resolveAssetPath",
"(",
")",
"{",
"$",
"basename",
"=",
"md5",
"(",
"serialize",
"(",
"array_map",
"(",
"function",
"(",
"$",
"path",
")",
"{",
"return",
"[",
"$",
"path",
",",
"filemtime",
"(",
"$",
"path",
")",
"]",
";",
"}",
",",
"$",
"this",
"->",
"paths",
")",
")",
")",
";",
"return",
"Configure",
"::",
"read",
"(",
"'Assets.target'",
")",
".",
"DS",
".",
"$",
"basename",
".",
"'.'",
".",
"$",
"this",
"->",
"type",
";",
"}"
] |
Internal method to resolve the asset path
@return string Asset full path
@use $paths
@use $type
|
[
"Internal",
"method",
"to",
"resolve",
"the",
"asset",
"path"
] |
5bbe4963e177bfbd4c152e92edaa5eeeb0c6d64b
|
https://github.com/mirko-pagliai/cakephp-assets/blob/5bbe4963e177bfbd4c152e92edaa5eeeb0c6d64b/src/Utility/AssetsCreator.php#L73-L80
|
26,197
|
mirko-pagliai/cakephp-assets
|
src/Utility/AssetsCreator.php
|
AssetsCreator.resolveFilePaths
|
protected function resolveFilePaths($paths)
{
$loadedPlugins = Plugin::loaded();
return array_map(function ($path) use ($loadedPlugins) {
$pluginSplit = pluginSplit($path);
//Note that using `pluginSplit()` is not sufficient, because
// `$path` may still contain a dot
if (!empty($pluginSplit[0]) && in_array($pluginSplit[0], $loadedPlugins)) {
list($plugin, $path) = $pluginSplit;
}
$path = string_starts_with($path, '/') ? substr($path, 1) : $this->type . DS . $path;
$path = DS === '/' ? $path : $path = str_replace('/', DS, $path);
$path = empty($plugin) ? WWW_ROOT . $path : Plugin::path($plugin) . 'webroot' . DS . $path;
//Appends the file extension, if not already present
$path = pathinfo($path, PATHINFO_EXTENSION) == $this->type ? $path : sprintf('%s.%s', $path, $this->type);
is_readable_or_fail($path);
return $path;
}, (array)$paths);
}
|
php
|
protected function resolveFilePaths($paths)
{
$loadedPlugins = Plugin::loaded();
return array_map(function ($path) use ($loadedPlugins) {
$pluginSplit = pluginSplit($path);
//Note that using `pluginSplit()` is not sufficient, because
// `$path` may still contain a dot
if (!empty($pluginSplit[0]) && in_array($pluginSplit[0], $loadedPlugins)) {
list($plugin, $path) = $pluginSplit;
}
$path = string_starts_with($path, '/') ? substr($path, 1) : $this->type . DS . $path;
$path = DS === '/' ? $path : $path = str_replace('/', DS, $path);
$path = empty($plugin) ? WWW_ROOT . $path : Plugin::path($plugin) . 'webroot' . DS . $path;
//Appends the file extension, if not already present
$path = pathinfo($path, PATHINFO_EXTENSION) == $this->type ? $path : sprintf('%s.%s', $path, $this->type);
is_readable_or_fail($path);
return $path;
}, (array)$paths);
}
|
[
"protected",
"function",
"resolveFilePaths",
"(",
"$",
"paths",
")",
"{",
"$",
"loadedPlugins",
"=",
"Plugin",
"::",
"loaded",
"(",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"path",
")",
"use",
"(",
"$",
"loadedPlugins",
")",
"{",
"$",
"pluginSplit",
"=",
"pluginSplit",
"(",
"$",
"path",
")",
";",
"//Note that using `pluginSplit()` is not sufficient, because",
"// `$path` may still contain a dot",
"if",
"(",
"!",
"empty",
"(",
"$",
"pluginSplit",
"[",
"0",
"]",
")",
"&&",
"in_array",
"(",
"$",
"pluginSplit",
"[",
"0",
"]",
",",
"$",
"loadedPlugins",
")",
")",
"{",
"list",
"(",
"$",
"plugin",
",",
"$",
"path",
")",
"=",
"$",
"pluginSplit",
";",
"}",
"$",
"path",
"=",
"string_starts_with",
"(",
"$",
"path",
",",
"'/'",
")",
"?",
"substr",
"(",
"$",
"path",
",",
"1",
")",
":",
"$",
"this",
"->",
"type",
".",
"DS",
".",
"$",
"path",
";",
"$",
"path",
"=",
"DS",
"===",
"'/'",
"?",
"$",
"path",
":",
"$",
"path",
"=",
"str_replace",
"(",
"'/'",
",",
"DS",
",",
"$",
"path",
")",
";",
"$",
"path",
"=",
"empty",
"(",
"$",
"plugin",
")",
"?",
"WWW_ROOT",
".",
"$",
"path",
":",
"Plugin",
"::",
"path",
"(",
"$",
"plugin",
")",
".",
"'webroot'",
".",
"DS",
".",
"$",
"path",
";",
"//Appends the file extension, if not already present",
"$",
"path",
"=",
"pathinfo",
"(",
"$",
"path",
",",
"PATHINFO_EXTENSION",
")",
"==",
"$",
"this",
"->",
"type",
"?",
"$",
"path",
":",
"sprintf",
"(",
"'%s.%s'",
",",
"$",
"path",
",",
"$",
"this",
"->",
"type",
")",
";",
"is_readable_or_fail",
"(",
"$",
"path",
")",
";",
"return",
"$",
"path",
";",
"}",
",",
"(",
"array",
")",
"$",
"paths",
")",
";",
"}"
] |
Internal method to resolve partial file paths and return full paths
@param string|array $paths Partial file paths
@return array Full file paths
@use $type
|
[
"Internal",
"method",
"to",
"resolve",
"partial",
"file",
"paths",
"and",
"return",
"full",
"paths"
] |
5bbe4963e177bfbd4c152e92edaa5eeeb0c6d64b
|
https://github.com/mirko-pagliai/cakephp-assets/blob/5bbe4963e177bfbd4c152e92edaa5eeeb0c6d64b/src/Utility/AssetsCreator.php#L88-L111
|
26,198
|
mirko-pagliai/cakephp-assets
|
src/Utility/AssetsCreator.php
|
AssetsCreator.create
|
public function create()
{
$File = new File($this->path());
if (!$File->readable()) {
$minifier = $this->type === 'css' ? new Minify\CSS() : new Minify\JS();
array_map([$minifier, 'add'], $this->paths);
//Writes the file
$success = $File->write($minifier->minify());
is_true_or_fail($success, __d('assets', 'Failed to create file {0}', rtr($this->path())));
}
return $this->filename();
}
|
php
|
public function create()
{
$File = new File($this->path());
if (!$File->readable()) {
$minifier = $this->type === 'css' ? new Minify\CSS() : new Minify\JS();
array_map([$minifier, 'add'], $this->paths);
//Writes the file
$success = $File->write($minifier->minify());
is_true_or_fail($success, __d('assets', 'Failed to create file {0}', rtr($this->path())));
}
return $this->filename();
}
|
[
"public",
"function",
"create",
"(",
")",
"{",
"$",
"File",
"=",
"new",
"File",
"(",
"$",
"this",
"->",
"path",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"File",
"->",
"readable",
"(",
")",
")",
"{",
"$",
"minifier",
"=",
"$",
"this",
"->",
"type",
"===",
"'css'",
"?",
"new",
"Minify",
"\\",
"CSS",
"(",
")",
":",
"new",
"Minify",
"\\",
"JS",
"(",
")",
";",
"array_map",
"(",
"[",
"$",
"minifier",
",",
"'add'",
"]",
",",
"$",
"this",
"->",
"paths",
")",
";",
"//Writes the file",
"$",
"success",
"=",
"$",
"File",
"->",
"write",
"(",
"$",
"minifier",
"->",
"minify",
"(",
")",
")",
";",
"is_true_or_fail",
"(",
"$",
"success",
",",
"__d",
"(",
"'assets'",
",",
"'Failed to create file {0}'",
",",
"rtr",
"(",
"$",
"this",
"->",
"path",
"(",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filename",
"(",
")",
";",
"}"
] |
Creates the asset
@return string
@throws RuntimeException
@uses filename()
@uses path()
@uses $paths
@uses $type
|
[
"Creates",
"the",
"asset"
] |
5bbe4963e177bfbd4c152e92edaa5eeeb0c6d64b
|
https://github.com/mirko-pagliai/cakephp-assets/blob/5bbe4963e177bfbd4c152e92edaa5eeeb0c6d64b/src/Utility/AssetsCreator.php#L122-L136
|
26,199
|
spiral/security
|
src/Matcher.php
|
Matcher.matches
|
public function matches(string $string, string $pattern): bool
{
if ($string === $pattern) {
return true;
}
if (!$this->isPattern($pattern)) {
return false;
}
return (bool)preg_match($this->getRegex($pattern), $string);
}
|
php
|
public function matches(string $string, string $pattern): bool
{
if ($string === $pattern) {
return true;
}
if (!$this->isPattern($pattern)) {
return false;
}
return (bool)preg_match($this->getRegex($pattern), $string);
}
|
[
"public",
"function",
"matches",
"(",
"string",
"$",
"string",
",",
"string",
"$",
"pattern",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"string",
"===",
"$",
"pattern",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isPattern",
"(",
"$",
"pattern",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"bool",
")",
"preg_match",
"(",
"$",
"this",
"->",
"getRegex",
"(",
"$",
"pattern",
")",
",",
"$",
"string",
")",
";",
"}"
] |
Checks if string matches given pattent.
@param string $string
@param string $pattern
@return bool
|
[
"Checks",
"if",
"string",
"matches",
"given",
"pattent",
"."
] |
a36decbf237460e1e2059bb12b41c69a1cd59ec3
|
https://github.com/spiral/security/blob/a36decbf237460e1e2059bb12b41c69a1cd59ec3/src/Matcher.php#L39-L48
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.