repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
analogueorm/analogue | src/EntityMap.php | EntityMap.getCompiledAttributes | public function getCompiledAttributes(): array
{
$key = $this->getKeyName();
$embeddables = array_keys($this->getEmbeddables());
$relationships = $this->getRelationships();
$attributes = $this->getAttributes();
return array_merge([$key], $embeddables, $relationships, $attributes);
} | php | public function getCompiledAttributes(): array
{
$key = $this->getKeyName();
$embeddables = array_keys($this->getEmbeddables());
$relationships = $this->getRelationships();
$attributes = $this->getAttributes();
return array_merge([$key], $embeddables, $relationships, $attributes);
} | [
"public",
"function",
"getCompiledAttributes",
"(",
")",
":",
"array",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getKeyName",
"(",
")",
";",
"$",
"embeddables",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"getEmbeddables",
"(",
")",
")",
";",
"$",
"relationships",
"=",
"$",
"this",
"->",
"getRelationships",
"(",
")",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
")",
";",
"return",
"array_merge",
"(",
"[",
"$",
"key",
"]",
",",
"$",
"embeddables",
",",
"$",
"relationships",
",",
"$",
"attributes",
")",
";",
"}"
] | Get all the attribute names for the class, including relationships, embeddables and primary key.
@return array | [
"Get",
"all",
"the",
"attribute",
"names",
"for",
"the",
"class",
"including",
"relationships",
"embeddables",
"and",
"primary",
"key",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L356-L367 |
analogueorm/analogue | src/EntityMap.php | EntityMap.getProperties | public function getProperties(): array
{
return get_parent_class(__CLASS__) !== false
? array_unique(array_merge($this->properties, parent::getProperties()))
: $this->properties;
} | php | public function getProperties(): array
{
return get_parent_class(__CLASS__) !== false
? array_unique(array_merge($this->properties, parent::getProperties()))
: $this->properties;
} | [
"public",
"function",
"getProperties",
"(",
")",
":",
"array",
"{",
"return",
"get_parent_class",
"(",
"__CLASS__",
")",
"!==",
"false",
"?",
"array_unique",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"properties",
",",
"parent",
"::",
"getProperties",
"(",
")",
")",
")",
":",
"$",
"this",
"->",
"properties",
";",
"}"
] | Return attributes that should be mapped to class properties.
@return array | [
"Return",
"attributes",
"that",
"should",
"be",
"mapped",
"to",
"class",
"properties",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L490-L495 |
analogueorm/analogue | src/EntityMap.php | EntityMap.getEmptyValueForRelationship | public function getEmptyValueForRelationship(string $relation)
{
if ($this->isSingleRelationship($relation)) {
return;
}
if ($this->isManyRelationship($relation)) {
return new Collection();
}
throw new MappingException("Cannot determine default value of $relation");
} | php | public function getEmptyValueForRelationship(string $relation)
{
if ($this->isSingleRelationship($relation)) {
return;
}
if ($this->isManyRelationship($relation)) {
return new Collection();
}
throw new MappingException("Cannot determine default value of $relation");
} | [
"public",
"function",
"getEmptyValueForRelationship",
"(",
"string",
"$",
"relation",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isSingleRelationship",
"(",
"$",
"relation",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isManyRelationship",
"(",
"$",
"relation",
")",
")",
"{",
"return",
"new",
"Collection",
"(",
")",
";",
"}",
"throw",
"new",
"MappingException",
"(",
"\"Cannot determine default value of $relation\"",
")",
";",
"}"
] | Return empty value for a given relationship.
@param string $relation
@throws MappingException
@return mixed | [
"Return",
"empty",
"value",
"for",
"a",
"given",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L614-L625 |
analogueorm/analogue | src/EntityMap.php | EntityMap.getEmptyValueForLocalKey | public function getEmptyValueForLocalKey(string $relation)
{
if ($this->isPolymorphic($relation)) {
$key = $this->localForeignKeys[$relation];
return [
$key['type'] => null,
$key['id'] => null,
];
}
if ($this->isManyRelationship($relation)) {
return [];
}
} | php | public function getEmptyValueForLocalKey(string $relation)
{
if ($this->isPolymorphic($relation)) {
$key = $this->localForeignKeys[$relation];
return [
$key['type'] => null,
$key['id'] => null,
];
}
if ($this->isManyRelationship($relation)) {
return [];
}
} | [
"public",
"function",
"getEmptyValueForLocalKey",
"(",
"string",
"$",
"relation",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isPolymorphic",
"(",
"$",
"relation",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"localForeignKeys",
"[",
"$",
"relation",
"]",
";",
"return",
"[",
"$",
"key",
"[",
"'type'",
"]",
"=>",
"null",
",",
"$",
"key",
"[",
"'id'",
"]",
"=>",
"null",
",",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isManyRelationship",
"(",
"$",
"relation",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"}"
] | Return empty value for a local foreign key.
@param string $relation
@return mixed | [
"Return",
"empty",
"value",
"for",
"a",
"local",
"foreign",
"key",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L634-L648 |
analogueorm/analogue | src/EntityMap.php | EntityMap.getLocalKeys | public function getLocalKeys($relation)
{
return isset($this->localForeignKeys[$relation]) ? $this->localForeignKeys[$relation] : null;
} | php | public function getLocalKeys($relation)
{
return isset($this->localForeignKeys[$relation]) ? $this->localForeignKeys[$relation] : null;
} | [
"public",
"function",
"getLocalKeys",
"(",
"$",
"relation",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"localForeignKeys",
"[",
"$",
"relation",
"]",
")",
"?",
"$",
"this",
"->",
"localForeignKeys",
"[",
"$",
"relation",
"]",
":",
"null",
";",
"}"
] | Return the local keys associated to the relationship.
@param string $relation
@return string|array|null | [
"Return",
"the",
"local",
"keys",
"associated",
"to",
"the",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L667-L670 |
analogueorm/analogue | src/EntityMap.php | EntityMap.addSingleRelation | protected function addSingleRelation(string $relation)
{
if (!in_array($relation, $this->singleRelations)) {
$this->singleRelations[] = $relation;
}
} | php | protected function addSingleRelation(string $relation)
{
if (!in_array($relation, $this->singleRelations)) {
$this->singleRelations[] = $relation;
}
} | [
"protected",
"function",
"addSingleRelation",
"(",
"string",
"$",
"relation",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"singleRelations",
")",
")",
"{",
"$",
"this",
"->",
"singleRelations",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"}"
] | Add a single relation method name once.
@param string $relation | [
"Add",
"a",
"single",
"relation",
"method",
"name",
"once",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L925-L930 |
analogueorm/analogue | src/EntityMap.php | EntityMap.addForeignRelation | protected function addForeignRelation(string $relation)
{
if (!in_array($relation, $this->foreignRelations)) {
$this->foreignRelations[] = $relation;
}
} | php | protected function addForeignRelation(string $relation)
{
if (!in_array($relation, $this->foreignRelations)) {
$this->foreignRelations[] = $relation;
}
} | [
"protected",
"function",
"addForeignRelation",
"(",
"string",
"$",
"relation",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"foreignRelations",
")",
")",
"{",
"$",
"this",
"->",
"foreignRelations",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"}"
] | Add a foreign relation method name once.
@param string $relation | [
"Add",
"a",
"foreign",
"relation",
"method",
"name",
"once",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L937-L942 |
analogueorm/analogue | src/EntityMap.php | EntityMap.addPolymorphicRelation | protected function addPolymorphicRelation(string $relation)
{
if (!in_array($relation, $this->polymorphicRelations)) {
$this->polymorphicRelations[] = $relation;
}
} | php | protected function addPolymorphicRelation(string $relation)
{
if (!in_array($relation, $this->polymorphicRelations)) {
$this->polymorphicRelations[] = $relation;
}
} | [
"protected",
"function",
"addPolymorphicRelation",
"(",
"string",
"$",
"relation",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"polymorphicRelations",
")",
")",
"{",
"$",
"this",
"->",
"polymorphicRelations",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"}"
] | Add a polymorphic relation method name once.
@param string $relation | [
"Add",
"a",
"polymorphic",
"relation",
"method",
"name",
"once",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L949-L954 |
analogueorm/analogue | src/EntityMap.php | EntityMap.addNonProxyRelation | protected function addNonProxyRelation(string $relation)
{
if (!in_array($relation, $this->nonProxyRelationships)) {
$this->nonProxyRelationships[] = $relation;
}
} | php | protected function addNonProxyRelation(string $relation)
{
if (!in_array($relation, $this->nonProxyRelationships)) {
$this->nonProxyRelationships[] = $relation;
}
} | [
"protected",
"function",
"addNonProxyRelation",
"(",
"string",
"$",
"relation",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"nonProxyRelationships",
")",
")",
"{",
"$",
"this",
"->",
"nonProxyRelationships",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"}"
] | Add a non proxy relation method name once.
@param string $relation | [
"Add",
"a",
"non",
"proxy",
"relation",
"method",
"name",
"once",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L961-L966 |
analogueorm/analogue | src/EntityMap.php | EntityMap.addLocalRelation | protected function addLocalRelation(string $relation)
{
if (!in_array($relation, $this->localRelations)) {
$this->localRelations[] = $relation;
}
} | php | protected function addLocalRelation(string $relation)
{
if (!in_array($relation, $this->localRelations)) {
$this->localRelations[] = $relation;
}
} | [
"protected",
"function",
"addLocalRelation",
"(",
"string",
"$",
"relation",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"localRelations",
")",
")",
"{",
"$",
"this",
"->",
"localRelations",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"}"
] | Add a local relation method name once.
@param string $relation | [
"Add",
"a",
"local",
"relation",
"method",
"name",
"once",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L973-L978 |
analogueorm/analogue | src/EntityMap.php | EntityMap.addManyRelation | protected function addManyRelation(string $relation)
{
if (!in_array($relation, $this->manyRelations)) {
$this->manyRelations[] = $relation;
}
} | php | protected function addManyRelation(string $relation)
{
if (!in_array($relation, $this->manyRelations)) {
$this->manyRelations[] = $relation;
}
} | [
"protected",
"function",
"addManyRelation",
"(",
"string",
"$",
"relation",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"manyRelations",
")",
")",
"{",
"$",
"this",
"->",
"manyRelations",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"}"
] | Add a many relation method name once.
@param string $relation | [
"Add",
"a",
"many",
"relation",
"method",
"name",
"once",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L985-L990 |
analogueorm/analogue | src/EntityMap.php | EntityMap.addPivotRelation | protected function addPivotRelation(string $relation)
{
if (!in_array($relation, $this->pivotRelations)) {
$this->pivotRelations[] = $relation;
}
} | php | protected function addPivotRelation(string $relation)
{
if (!in_array($relation, $this->pivotRelations)) {
$this->pivotRelations[] = $relation;
}
} | [
"protected",
"function",
"addPivotRelation",
"(",
"string",
"$",
"relation",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"pivotRelations",
")",
")",
"{",
"$",
"this",
"->",
"pivotRelations",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"}"
] | Add a pivot relation method name once.
@param string $relation | [
"Add",
"a",
"pivot",
"relation",
"method",
"name",
"once",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L997-L1002 |
analogueorm/analogue | src/EntityMap.php | EntityMap.addEmbeddedRelation | protected function addEmbeddedRelation(string $relation)
{
if (!in_array($relation, $this->embeddedRelations)) {
$this->embeddedRelations[] = $relation;
}
} | php | protected function addEmbeddedRelation(string $relation)
{
if (!in_array($relation, $this->embeddedRelations)) {
$this->embeddedRelations[] = $relation;
}
} | [
"protected",
"function",
"addEmbeddedRelation",
"(",
"string",
"$",
"relation",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"embeddedRelations",
")",
")",
"{",
"$",
"this",
"->",
"embeddedRelations",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"}"
] | Add an embedded relation.
@param string $relation | [
"Add",
"an",
"embedded",
"relation",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1009-L1014 |
analogueorm/analogue | src/EntityMap.php | EntityMap.embedsOne | public function embedsOne($parent, string $relatedClass, string $relation = null): EmbedsOne
{
if (is_null($relation)) {
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
}
$this->addEmbeddedRelation($relation);
$this->addNonProxyRelation($relation);
return new EmbedsOne($parent, $relatedClass, $relation);
} | php | public function embedsOne($parent, string $relatedClass, string $relation = null): EmbedsOne
{
if (is_null($relation)) {
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
}
$this->addEmbeddedRelation($relation);
$this->addNonProxyRelation($relation);
return new EmbedsOne($parent, $relatedClass, $relation);
} | [
"public",
"function",
"embedsOne",
"(",
"$",
"parent",
",",
"string",
"$",
"relatedClass",
",",
"string",
"$",
"relation",
"=",
"null",
")",
":",
"EmbedsOne",
"{",
"if",
"(",
"is_null",
"(",
"$",
"relation",
")",
")",
"{",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"}",
"$",
"this",
"->",
"addEmbeddedRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addNonProxyRelation",
"(",
"$",
"relation",
")",
";",
"return",
"new",
"EmbedsOne",
"(",
"$",
"parent",
",",
"$",
"relatedClass",
",",
"$",
"relation",
")",
";",
"}"
] | Define an Embedded Object.
@param mixed $parent
@param string $relatedClass
@param string $relation
@return EmbedsOne | [
"Define",
"an",
"Embedded",
"Object",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1025-L1036 |
analogueorm/analogue | src/EntityMap.php | EntityMap.embedsMany | public function embedsMany($parent, string $relatedClass, string $relation = null): EmbedsMany
{
if (is_null($relation)) {
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
}
$this->addEmbeddedRelation($relation);
$this->addNonProxyRelation($relation);
return new EmbedsMany($parent, $relatedClass, $relation);
} | php | public function embedsMany($parent, string $relatedClass, string $relation = null): EmbedsMany
{
if (is_null($relation)) {
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
}
$this->addEmbeddedRelation($relation);
$this->addNonProxyRelation($relation);
return new EmbedsMany($parent, $relatedClass, $relation);
} | [
"public",
"function",
"embedsMany",
"(",
"$",
"parent",
",",
"string",
"$",
"relatedClass",
",",
"string",
"$",
"relation",
"=",
"null",
")",
":",
"EmbedsMany",
"{",
"if",
"(",
"is_null",
"(",
"$",
"relation",
")",
")",
"{",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"}",
"$",
"this",
"->",
"addEmbeddedRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addNonProxyRelation",
"(",
"$",
"relation",
")",
";",
"return",
"new",
"EmbedsMany",
"(",
"$",
"parent",
",",
"$",
"relatedClass",
",",
"$",
"relation",
")",
";",
"}"
] | Define an Embedded Collection.
@param mixed $parent
@param string $relatedClass
@param string $relation
@return EmbedsMany | [
"Define",
"an",
"Embedded",
"Collection",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1047-L1058 |
analogueorm/analogue | src/EntityMap.php | EntityMap.hasOne | public function hasOne($entity, string $related, string $foreignKey = null, string $localKey = null): HasOne
{
$foreignKey = $foreignKey ?: $this->getForeignKey();
$relatedMapper = Manager::getInstance()->mapper($related);
$relatedMap = $relatedMapper->getEntityMap();
$localKey = $localKey ?: $this->getKeyName();
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addSingleRelation($relation);
$this->addForeignRelation($relation);
$this->addNonProxyRelation($relation);
// This relationship will always be eager loaded, as proxying it would
// mean having an object that doesn't actually exists.
if (!in_array($relation, $this->with)) {
$this->with[] = $relation;
}
return new HasOne($relatedMapper, $entity, /*$relatedMap->getTable().'.'*/$foreignKey, $localKey);
} | php | public function hasOne($entity, string $related, string $foreignKey = null, string $localKey = null): HasOne
{
$foreignKey = $foreignKey ?: $this->getForeignKey();
$relatedMapper = Manager::getInstance()->mapper($related);
$relatedMap = $relatedMapper->getEntityMap();
$localKey = $localKey ?: $this->getKeyName();
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addSingleRelation($relation);
$this->addForeignRelation($relation);
$this->addNonProxyRelation($relation);
// This relationship will always be eager loaded, as proxying it would
// mean having an object that doesn't actually exists.
if (!in_array($relation, $this->with)) {
$this->with[] = $relation;
}
return new HasOne($relatedMapper, $entity, /*$relatedMap->getTable().'.'*/$foreignKey, $localKey);
} | [
"public",
"function",
"hasOne",
"(",
"$",
"entity",
",",
"string",
"$",
"related",
",",
"string",
"$",
"foreignKey",
"=",
"null",
",",
"string",
"$",
"localKey",
"=",
"null",
")",
":",
"HasOne",
"{",
"$",
"foreignKey",
"=",
"$",
"foreignKey",
"?",
":",
"$",
"this",
"->",
"getForeignKey",
"(",
")",
";",
"$",
"relatedMapper",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"mapper",
"(",
"$",
"related",
")",
";",
"$",
"relatedMap",
"=",
"$",
"relatedMapper",
"->",
"getEntityMap",
"(",
")",
";",
"$",
"localKey",
"=",
"$",
"localKey",
"?",
":",
"$",
"this",
"->",
"getKeyName",
"(",
")",
";",
"// Add the relation to the definition in map",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"$",
"this",
"->",
"relatedClasses",
"[",
"$",
"relation",
"]",
"=",
"$",
"related",
";",
"$",
"this",
"->",
"addSingleRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addForeignRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addNonProxyRelation",
"(",
"$",
"relation",
")",
";",
"// This relationship will always be eager loaded, as proxying it would",
"// mean having an object that doesn't actually exists.",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"with",
")",
")",
"{",
"$",
"this",
"->",
"with",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"return",
"new",
"HasOne",
"(",
"$",
"relatedMapper",
",",
"$",
"entity",
",",
"/*$relatedMap->getTable().'.'*/",
"$",
"foreignKey",
",",
"$",
"localKey",
")",
";",
"}"
] | Define a one-to-one relationship.
@param mixed $entity
@param string $related entity class
@param string $foreignKey
@param string $localKey
@throws MappingException
@return \Analogue\ORM\Relationships\HasOne | [
"Define",
"a",
"one",
"-",
"to",
"-",
"one",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1072-L1098 |
analogueorm/analogue | src/EntityMap.php | EntityMap.morphOne | public function morphOne(
$entity,
string $related,
string $name,
string $type = null,
string $id = null,
string $localKey = null
): MorphOne {
list($type, $id) = $this->getMorphs($name, $type, $id);
$localKey = $localKey ?: $this->getKeyName();
$relatedMapper = Manager::getInstance()->mapper($related);
//$table = $relatedMapper->getEntityMap()->getTable();
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addSingleRelation($relation);
$this->addForeignRelation($relation);
$this->addNonProxyRelation($relation);
// This relationship will always be eager loaded, as proxying it would
// mean having an object that doesn't actually exists.
if (!in_array($relation, $this->with)) {
$this->with[] = $relation;
}
return new MorphOne($relatedMapper, $entity, /*$table.'.'.*/$type, /*$table.'.'.*/$id, $localKey);
} | php | public function morphOne(
$entity,
string $related,
string $name,
string $type = null,
string $id = null,
string $localKey = null
): MorphOne {
list($type, $id) = $this->getMorphs($name, $type, $id);
$localKey = $localKey ?: $this->getKeyName();
$relatedMapper = Manager::getInstance()->mapper($related);
//$table = $relatedMapper->getEntityMap()->getTable();
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addSingleRelation($relation);
$this->addForeignRelation($relation);
$this->addNonProxyRelation($relation);
// This relationship will always be eager loaded, as proxying it would
// mean having an object that doesn't actually exists.
if (!in_array($relation, $this->with)) {
$this->with[] = $relation;
}
return new MorphOne($relatedMapper, $entity, /*$table.'.'.*/$type, /*$table.'.'.*/$id, $localKey);
} | [
"public",
"function",
"morphOne",
"(",
"$",
"entity",
",",
"string",
"$",
"related",
",",
"string",
"$",
"name",
",",
"string",
"$",
"type",
"=",
"null",
",",
"string",
"$",
"id",
"=",
"null",
",",
"string",
"$",
"localKey",
"=",
"null",
")",
":",
"MorphOne",
"{",
"list",
"(",
"$",
"type",
",",
"$",
"id",
")",
"=",
"$",
"this",
"->",
"getMorphs",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"id",
")",
";",
"$",
"localKey",
"=",
"$",
"localKey",
"?",
":",
"$",
"this",
"->",
"getKeyName",
"(",
")",
";",
"$",
"relatedMapper",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"mapper",
"(",
"$",
"related",
")",
";",
"//$table = $relatedMapper->getEntityMap()->getTable();",
"// Add the relation to the definition in map",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"$",
"this",
"->",
"relatedClasses",
"[",
"$",
"relation",
"]",
"=",
"$",
"related",
";",
"$",
"this",
"->",
"addSingleRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addForeignRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addNonProxyRelation",
"(",
"$",
"relation",
")",
";",
"// This relationship will always be eager loaded, as proxying it would",
"// mean having an object that doesn't actually exists.",
"if",
"(",
"!",
"in_array",
"(",
"$",
"relation",
",",
"$",
"this",
"->",
"with",
")",
")",
"{",
"$",
"this",
"->",
"with",
"[",
"]",
"=",
"$",
"relation",
";",
"}",
"return",
"new",
"MorphOne",
"(",
"$",
"relatedMapper",
",",
"$",
"entity",
",",
"/*$table.'.'.*/",
"$",
"type",
",",
"/*$table.'.'.*/",
"$",
"id",
",",
"$",
"localKey",
")",
";",
"}"
] | Define a polymorphic one-to-one relationship.
@param mixed $entity
@param string $related
@param string $name
@param string|null $type
@param string|null $id
@param string|null $localKey
@throws MappingException
@return \Analogue\ORM\Relationships\MorphOne | [
"Define",
"a",
"polymorphic",
"one",
"-",
"to",
"-",
"one",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1114-L1146 |
analogueorm/analogue | src/EntityMap.php | EntityMap.belongsTo | public function belongsTo($entity, string $related, string $foreignKey = null, string $otherKey = null): BelongsTo
{
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addSingleRelation($relation);
$this->addLocalRelation($relation);
// If no foreign key was supplied, we can use a backtrace to guess the proper
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
if (is_null($foreignKey)) {
$foreignKey = snake_case($relation).'_id';
}
$this->localForeignKeys[$relation] = $foreignKey;
$relatedMapper = Manager::getInstance()->mapper($related);
$otherKey = $otherKey ?: $relatedMapper->getEntityMap()->getKeyName();
return new BelongsTo($relatedMapper, $entity, $foreignKey, $otherKey, $relation);
} | php | public function belongsTo($entity, string $related, string $foreignKey = null, string $otherKey = null): BelongsTo
{
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addSingleRelation($relation);
$this->addLocalRelation($relation);
// If no foreign key was supplied, we can use a backtrace to guess the proper
// foreign key name by using the name of the relationship function, which
// when combined with an "_id" should conventionally match the columns.
if (is_null($foreignKey)) {
$foreignKey = snake_case($relation).'_id';
}
$this->localForeignKeys[$relation] = $foreignKey;
$relatedMapper = Manager::getInstance()->mapper($related);
$otherKey = $otherKey ?: $relatedMapper->getEntityMap()->getKeyName();
return new BelongsTo($relatedMapper, $entity, $foreignKey, $otherKey, $relation);
} | [
"public",
"function",
"belongsTo",
"(",
"$",
"entity",
",",
"string",
"$",
"related",
",",
"string",
"$",
"foreignKey",
"=",
"null",
",",
"string",
"$",
"otherKey",
"=",
"null",
")",
":",
"BelongsTo",
"{",
"// Add the relation to the definition in map",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"$",
"this",
"->",
"relatedClasses",
"[",
"$",
"relation",
"]",
"=",
"$",
"related",
";",
"$",
"this",
"->",
"addSingleRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addLocalRelation",
"(",
"$",
"relation",
")",
";",
"// If no foreign key was supplied, we can use a backtrace to guess the proper",
"// foreign key name by using the name of the relationship function, which",
"// when combined with an \"_id\" should conventionally match the columns.",
"if",
"(",
"is_null",
"(",
"$",
"foreignKey",
")",
")",
"{",
"$",
"foreignKey",
"=",
"snake_case",
"(",
"$",
"relation",
")",
".",
"'_id'",
";",
"}",
"$",
"this",
"->",
"localForeignKeys",
"[",
"$",
"relation",
"]",
"=",
"$",
"foreignKey",
";",
"$",
"relatedMapper",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"mapper",
"(",
"$",
"related",
")",
";",
"$",
"otherKey",
"=",
"$",
"otherKey",
"?",
":",
"$",
"relatedMapper",
"->",
"getEntityMap",
"(",
")",
"->",
"getKeyName",
"(",
")",
";",
"return",
"new",
"BelongsTo",
"(",
"$",
"relatedMapper",
",",
"$",
"entity",
",",
"$",
"foreignKey",
",",
"$",
"otherKey",
",",
"$",
"relation",
")",
";",
"}"
] | Define an inverse one-to-one or many relationship.
@param mixed $entity
@param string $related
@param string|null $foreignKey
@param string|null $otherKey
@throws MappingException
@return \Analogue\ORM\Relationships\BelongsTo | [
"Define",
"an",
"inverse",
"one",
"-",
"to",
"-",
"one",
"or",
"many",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1160-L1184 |
analogueorm/analogue | src/EntityMap.php | EntityMap.morphTo | public function morphTo($entity, string $name = null, string $type = null, string $id = null): MorphTo
{
// If no name is provided, we will use the backtrace to get the function name
// since that is most likely the name of the polymorphic interface. We can
// use that to get both the class and foreign key that will be utilized.
if (is_null($name)) {
list(, $caller) = debug_backtrace(false);
$name = snake_case($caller['function']);
}
$this->addSingleRelation($name);
$this->addLocalRelation($name);
$this->addPolymorphicRelation($name);
$this->relatedClass[$name] = null;
list($type, $id) = $this->getMorphs($name, $type, $id);
// Store the foreign key in the entity map.
// We might want to store the (key, type) as we might need it
// to build a MorphTo proxy
$this->localForeignKeys[$name] = [
'id' => $id,
'type' => $type,
];
$mapper = Manager::getInstance()->mapper(get_class($entity));
// If the type value is null it is probably safe to assume we're eager loading
// the relationship. When that is the case we will pass in a dummy query as
// there are multiple types in the morph and we can't use single queries.
$factory = new Factory();
$wrapper = $factory->make($entity);
if (is_null($class = $wrapper->getEntityAttribute($type))) {
return new MorphTo(
$mapper,
$entity,
$id,
null,
$type,
$name
);
} else {
// If we are not eager loading the relationship we will essentially treat this
// as a belongs-to style relationship since morph-to extends that class and
// we will pass in the appropriate values so that it behaves as expected.
$class = Manager::getInstance()->getInverseMorphMap($class);
$relatedMapper = Manager::getInstance()->mapper($class);
$foreignKey = $relatedMapper->getEntityMap()->getKeyName();
return new MorphTo(
$relatedMapper,
$entity,
$id,
$foreignKey,
$type,
$name
);
}
} | php | public function morphTo($entity, string $name = null, string $type = null, string $id = null): MorphTo
{
// If no name is provided, we will use the backtrace to get the function name
// since that is most likely the name of the polymorphic interface. We can
// use that to get both the class and foreign key that will be utilized.
if (is_null($name)) {
list(, $caller) = debug_backtrace(false);
$name = snake_case($caller['function']);
}
$this->addSingleRelation($name);
$this->addLocalRelation($name);
$this->addPolymorphicRelation($name);
$this->relatedClass[$name] = null;
list($type, $id) = $this->getMorphs($name, $type, $id);
// Store the foreign key in the entity map.
// We might want to store the (key, type) as we might need it
// to build a MorphTo proxy
$this->localForeignKeys[$name] = [
'id' => $id,
'type' => $type,
];
$mapper = Manager::getInstance()->mapper(get_class($entity));
// If the type value is null it is probably safe to assume we're eager loading
// the relationship. When that is the case we will pass in a dummy query as
// there are multiple types in the morph and we can't use single queries.
$factory = new Factory();
$wrapper = $factory->make($entity);
if (is_null($class = $wrapper->getEntityAttribute($type))) {
return new MorphTo(
$mapper,
$entity,
$id,
null,
$type,
$name
);
} else {
// If we are not eager loading the relationship we will essentially treat this
// as a belongs-to style relationship since morph-to extends that class and
// we will pass in the appropriate values so that it behaves as expected.
$class = Manager::getInstance()->getInverseMorphMap($class);
$relatedMapper = Manager::getInstance()->mapper($class);
$foreignKey = $relatedMapper->getEntityMap()->getKeyName();
return new MorphTo(
$relatedMapper,
$entity,
$id,
$foreignKey,
$type,
$name
);
}
} | [
"public",
"function",
"morphTo",
"(",
"$",
"entity",
",",
"string",
"$",
"name",
"=",
"null",
",",
"string",
"$",
"type",
"=",
"null",
",",
"string",
"$",
"id",
"=",
"null",
")",
":",
"MorphTo",
"{",
"// If no name is provided, we will use the backtrace to get the function name",
"// since that is most likely the name of the polymorphic interface. We can",
"// use that to get both the class and foreign key that will be utilized.",
"if",
"(",
"is_null",
"(",
"$",
"name",
")",
")",
"{",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"name",
"=",
"snake_case",
"(",
"$",
"caller",
"[",
"'function'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"addSingleRelation",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"addLocalRelation",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"addPolymorphicRelation",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"relatedClass",
"[",
"$",
"name",
"]",
"=",
"null",
";",
"list",
"(",
"$",
"type",
",",
"$",
"id",
")",
"=",
"$",
"this",
"->",
"getMorphs",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"id",
")",
";",
"// Store the foreign key in the entity map.",
"// We might want to store the (key, type) as we might need it",
"// to build a MorphTo proxy",
"$",
"this",
"->",
"localForeignKeys",
"[",
"$",
"name",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"id",
",",
"'type'",
"=>",
"$",
"type",
",",
"]",
";",
"$",
"mapper",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"mapper",
"(",
"get_class",
"(",
"$",
"entity",
")",
")",
";",
"// If the type value is null it is probably safe to assume we're eager loading",
"// the relationship. When that is the case we will pass in a dummy query as",
"// there are multiple types in the morph and we can't use single queries.",
"$",
"factory",
"=",
"new",
"Factory",
"(",
")",
";",
"$",
"wrapper",
"=",
"$",
"factory",
"->",
"make",
"(",
"$",
"entity",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"class",
"=",
"$",
"wrapper",
"->",
"getEntityAttribute",
"(",
"$",
"type",
")",
")",
")",
"{",
"return",
"new",
"MorphTo",
"(",
"$",
"mapper",
",",
"$",
"entity",
",",
"$",
"id",
",",
"null",
",",
"$",
"type",
",",
"$",
"name",
")",
";",
"}",
"else",
"{",
"// If we are not eager loading the relationship we will essentially treat this",
"// as a belongs-to style relationship since morph-to extends that class and",
"// we will pass in the appropriate values so that it behaves as expected.",
"$",
"class",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"getInverseMorphMap",
"(",
"$",
"class",
")",
";",
"$",
"relatedMapper",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"mapper",
"(",
"$",
"class",
")",
";",
"$",
"foreignKey",
"=",
"$",
"relatedMapper",
"->",
"getEntityMap",
"(",
")",
"->",
"getKeyName",
"(",
")",
";",
"return",
"new",
"MorphTo",
"(",
"$",
"relatedMapper",
",",
"$",
"entity",
",",
"$",
"id",
",",
"$",
"foreignKey",
",",
"$",
"type",
",",
"$",
"name",
")",
";",
"}",
"}"
] | Define a polymorphic, inverse one-to-one or many relationship.
@param mixed $entity
@param string|null $name
@param string|null $type
@param string|null $id
@throws MappingException
@return \Analogue\ORM\Relationships\MorphTo | [
"Define",
"a",
"polymorphic",
"inverse",
"one",
"-",
"to",
"-",
"one",
"or",
"many",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1198-L1259 |
analogueorm/analogue | src/EntityMap.php | EntityMap.hasMany | public function hasMany($entity, string $related, string $foreignKey = null, string $localKey = null): HasMany
{
$foreignKey = $foreignKey ?: $this->getForeignKey();
$relatedMapper = Manager::getInstance()->mapper($related);
$localKey = $localKey ?: $this->getKeyName();
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
return new HasMany($relatedMapper, $entity, $foreignKey, $localKey);
} | php | public function hasMany($entity, string $related, string $foreignKey = null, string $localKey = null): HasMany
{
$foreignKey = $foreignKey ?: $this->getForeignKey();
$relatedMapper = Manager::getInstance()->mapper($related);
$localKey = $localKey ?: $this->getKeyName();
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
return new HasMany($relatedMapper, $entity, $foreignKey, $localKey);
} | [
"public",
"function",
"hasMany",
"(",
"$",
"entity",
",",
"string",
"$",
"related",
",",
"string",
"$",
"foreignKey",
"=",
"null",
",",
"string",
"$",
"localKey",
"=",
"null",
")",
":",
"HasMany",
"{",
"$",
"foreignKey",
"=",
"$",
"foreignKey",
"?",
":",
"$",
"this",
"->",
"getForeignKey",
"(",
")",
";",
"$",
"relatedMapper",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"mapper",
"(",
"$",
"related",
")",
";",
"$",
"localKey",
"=",
"$",
"localKey",
"?",
":",
"$",
"this",
"->",
"getKeyName",
"(",
")",
";",
"// Add the relation to the definition in map",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"$",
"this",
"->",
"relatedClasses",
"[",
"$",
"relation",
"]",
"=",
"$",
"related",
";",
"$",
"this",
"->",
"addManyRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addForeignRelation",
"(",
"$",
"relation",
")",
";",
"return",
"new",
"HasMany",
"(",
"$",
"relatedMapper",
",",
"$",
"entity",
",",
"$",
"foreignKey",
",",
"$",
"localKey",
")",
";",
"}"
] | Define a one-to-many relationship.
@param mixed $entity
@param string $related
@param string|null $foreignKey
@param string|null $localKey
@throws MappingException
@return \Analogue\ORM\Relationships\HasMany | [
"Define",
"a",
"one",
"-",
"to",
"-",
"many",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1273-L1290 |
analogueorm/analogue | src/EntityMap.php | EntityMap.hasManyThrough | public function hasManyThrough(
$entity,
string $related,
string $through,
string $firstKey = null,
string $secondKey = null
): HasManyThrough {
$relatedMapper = Manager::getInstance()->mapper($related);
$throughMapper = Manager::getInstance()->mapper($through);
$firstKey = $firstKey ?: $this->getForeignKey();
$throughMap = $throughMapper->getEntityMap();
$secondKey = $secondKey ?: $throughMap->getForeignKey();
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
return new HasManyThrough($relatedMapper, $entity, $throughMap, $firstKey, $secondKey);
} | php | public function hasManyThrough(
$entity,
string $related,
string $through,
string $firstKey = null,
string $secondKey = null
): HasManyThrough {
$relatedMapper = Manager::getInstance()->mapper($related);
$throughMapper = Manager::getInstance()->mapper($through);
$firstKey = $firstKey ?: $this->getForeignKey();
$throughMap = $throughMapper->getEntityMap();
$secondKey = $secondKey ?: $throughMap->getForeignKey();
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
return new HasManyThrough($relatedMapper, $entity, $throughMap, $firstKey, $secondKey);
} | [
"public",
"function",
"hasManyThrough",
"(",
"$",
"entity",
",",
"string",
"$",
"related",
",",
"string",
"$",
"through",
",",
"string",
"$",
"firstKey",
"=",
"null",
",",
"string",
"$",
"secondKey",
"=",
"null",
")",
":",
"HasManyThrough",
"{",
"$",
"relatedMapper",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"mapper",
"(",
"$",
"related",
")",
";",
"$",
"throughMapper",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"mapper",
"(",
"$",
"through",
")",
";",
"$",
"firstKey",
"=",
"$",
"firstKey",
"?",
":",
"$",
"this",
"->",
"getForeignKey",
"(",
")",
";",
"$",
"throughMap",
"=",
"$",
"throughMapper",
"->",
"getEntityMap",
"(",
")",
";",
"$",
"secondKey",
"=",
"$",
"secondKey",
"?",
":",
"$",
"throughMap",
"->",
"getForeignKey",
"(",
")",
";",
"// Add the relation to the definition in map",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"$",
"this",
"->",
"relatedClasses",
"[",
"$",
"relation",
"]",
"=",
"$",
"related",
";",
"$",
"this",
"->",
"addManyRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addForeignRelation",
"(",
"$",
"relation",
")",
";",
"return",
"new",
"HasManyThrough",
"(",
"$",
"relatedMapper",
",",
"$",
"entity",
",",
"$",
"throughMap",
",",
"$",
"firstKey",
",",
"$",
"secondKey",
")",
";",
"}"
] | Define a has-many-through relationship.
@param mixed $entity
@param string $related
@param string $through
@param string|null $firstKey
@param string|null $secondKey
@throws MappingException
@return \Analogue\ORM\Relationships\HasManyThrough | [
"Define",
"a",
"has",
"-",
"many",
"-",
"through",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1305-L1330 |
analogueorm/analogue | src/EntityMap.php | EntityMap.morphMany | public function morphMany(
$entity,
string $related,
string $name,
string $type = null,
string $id = null,
string $localKey = null
): MorphMany {
// Here we will gather up the morph type and ID for the relationship so that we
// can properly query the intermediate table of a relation. Finally, we will
// get the table and create the relationship instances for the developers.
list($type, $id) = $this->getMorphs($name, $type, $id);
$relatedMapper = Manager::getInstance()->mapper($related);
$table = $relatedMapper->getEntityMap()->getTable();
$localKey = $localKey ?: $this->getKeyName();
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
return new MorphMany($relatedMapper, $entity, /*$table.'.'.*/$type, /*$table.'.'.*/$id, $localKey);
} | php | public function morphMany(
$entity,
string $related,
string $name,
string $type = null,
string $id = null,
string $localKey = null
): MorphMany {
// Here we will gather up the morph type and ID for the relationship so that we
// can properly query the intermediate table of a relation. Finally, we will
// get the table and create the relationship instances for the developers.
list($type, $id) = $this->getMorphs($name, $type, $id);
$relatedMapper = Manager::getInstance()->mapper($related);
$table = $relatedMapper->getEntityMap()->getTable();
$localKey = $localKey ?: $this->getKeyName();
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
return new MorphMany($relatedMapper, $entity, /*$table.'.'.*/$type, /*$table.'.'.*/$id, $localKey);
} | [
"public",
"function",
"morphMany",
"(",
"$",
"entity",
",",
"string",
"$",
"related",
",",
"string",
"$",
"name",
",",
"string",
"$",
"type",
"=",
"null",
",",
"string",
"$",
"id",
"=",
"null",
",",
"string",
"$",
"localKey",
"=",
"null",
")",
":",
"MorphMany",
"{",
"// Here we will gather up the morph type and ID for the relationship so that we",
"// can properly query the intermediate table of a relation. Finally, we will",
"// get the table and create the relationship instances for the developers.",
"list",
"(",
"$",
"type",
",",
"$",
"id",
")",
"=",
"$",
"this",
"->",
"getMorphs",
"(",
"$",
"name",
",",
"$",
"type",
",",
"$",
"id",
")",
";",
"$",
"relatedMapper",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"mapper",
"(",
"$",
"related",
")",
";",
"$",
"table",
"=",
"$",
"relatedMapper",
"->",
"getEntityMap",
"(",
")",
"->",
"getTable",
"(",
")",
";",
"$",
"localKey",
"=",
"$",
"localKey",
"?",
":",
"$",
"this",
"->",
"getKeyName",
"(",
")",
";",
"// Add the relation to the definition in map",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"$",
"this",
"->",
"relatedClasses",
"[",
"$",
"relation",
"]",
"=",
"$",
"related",
";",
"$",
"this",
"->",
"addManyRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addForeignRelation",
"(",
"$",
"relation",
")",
";",
"return",
"new",
"MorphMany",
"(",
"$",
"relatedMapper",
",",
"$",
"entity",
",",
"/*$table.'.'.*/",
"$",
"type",
",",
"/*$table.'.'.*/",
"$",
"id",
",",
"$",
"localKey",
")",
";",
"}"
] | Define a polymorphic one-to-many relationship.
@param mixed $entity
@param string $related
@param string $name
@param string|null $type
@param string|null $id
@param string|null $localKey
@return \Analogue\ORM\Relationships\MorphMany | [
"Define",
"a",
"polymorphic",
"one",
"-",
"to",
"-",
"many",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1344-L1372 |
analogueorm/analogue | src/EntityMap.php | EntityMap.belongsToMany | public function belongsToMany(
$entity,
string $related,
string $table = null,
string $foreignKey = null,
string $otherKey = null
): BelongsToMany {
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
$this->addPivotRelation($relation);
// First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query
// instances as well as the relationship instances we need for this.
$foreignKey = $foreignKey ?: $this->getForeignKey();
$relatedMapper = Manager::getInstance()->mapper($related);
$relatedMap = $relatedMapper->getEntityMap();
$otherKey = $otherKey ?: $relatedMap->getForeignKey();
// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
// are transformed to snake case from their default CamelCase also.
if (is_null($table)) {
$table = $this->joiningTable($relatedMap);
}
return new BelongsToMany($relatedMapper, $entity, $table, $foreignKey, $otherKey, $relation);
} | php | public function belongsToMany(
$entity,
string $related,
string $table = null,
string $foreignKey = null,
string $otherKey = null
): BelongsToMany {
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
$this->addPivotRelation($relation);
// First, we'll need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we'll make the query
// instances as well as the relationship instances we need for this.
$foreignKey = $foreignKey ?: $this->getForeignKey();
$relatedMapper = Manager::getInstance()->mapper($related);
$relatedMap = $relatedMapper->getEntityMap();
$otherKey = $otherKey ?: $relatedMap->getForeignKey();
// If no table name was provided, we can guess it by concatenating the two
// models using underscores in alphabetical order. The two model names
// are transformed to snake case from their default CamelCase also.
if (is_null($table)) {
$table = $this->joiningTable($relatedMap);
}
return new BelongsToMany($relatedMapper, $entity, $table, $foreignKey, $otherKey, $relation);
} | [
"public",
"function",
"belongsToMany",
"(",
"$",
"entity",
",",
"string",
"$",
"related",
",",
"string",
"$",
"table",
"=",
"null",
",",
"string",
"$",
"foreignKey",
"=",
"null",
",",
"string",
"$",
"otherKey",
"=",
"null",
")",
":",
"BelongsToMany",
"{",
"// Add the relation to the definition in map",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"$",
"this",
"->",
"relatedClasses",
"[",
"$",
"relation",
"]",
"=",
"$",
"related",
";",
"$",
"this",
"->",
"addManyRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addForeignRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addPivotRelation",
"(",
"$",
"relation",
")",
";",
"// First, we'll need to determine the foreign key and \"other key\" for the",
"// relationship. Once we have determined the keys we'll make the query",
"// instances as well as the relationship instances we need for this.",
"$",
"foreignKey",
"=",
"$",
"foreignKey",
"?",
":",
"$",
"this",
"->",
"getForeignKey",
"(",
")",
";",
"$",
"relatedMapper",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"mapper",
"(",
"$",
"related",
")",
";",
"$",
"relatedMap",
"=",
"$",
"relatedMapper",
"->",
"getEntityMap",
"(",
")",
";",
"$",
"otherKey",
"=",
"$",
"otherKey",
"?",
":",
"$",
"relatedMap",
"->",
"getForeignKey",
"(",
")",
";",
"// If no table name was provided, we can guess it by concatenating the two",
"// models using underscores in alphabetical order. The two model names",
"// are transformed to snake case from their default CamelCase also.",
"if",
"(",
"is_null",
"(",
"$",
"table",
")",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"joiningTable",
"(",
"$",
"relatedMap",
")",
";",
"}",
"return",
"new",
"BelongsToMany",
"(",
"$",
"relatedMapper",
",",
"$",
"entity",
",",
"$",
"table",
",",
"$",
"foreignKey",
",",
"$",
"otherKey",
",",
"$",
"relation",
")",
";",
"}"
] | Define a many-to-many relationship.
@param mixed $entity
@param string $related
@param string|null $table
@param string|null $foreignKey
@param string|null $otherKey
@throws MappingException
@return \Analogue\ORM\Relationships\BelongsToMany | [
"Define",
"a",
"many",
"-",
"to",
"-",
"many",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1387-L1422 |
analogueorm/analogue | src/EntityMap.php | EntityMap.morphToMany | public function morphToMany(
$entity,
string $related,
string $name,
string $table = null,
string $foreignKey = null,
string $otherKey = null,
bool $inverse = false
): MorphToMany {
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
$this->addPivotRelation($relation);
// First, we will need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we will make the query
// instances, as well as the relationship instances we need for these.
$foreignKey = $foreignKey ?: $name.'_id';
$relatedMapper = Manager::getInstance()->mapper($related);
$otherKey = $otherKey ?: $relatedMapper->getEntityMap()->getForeignKey();
$table = $table ?: str_plural($name);
return new MorphToMany($relatedMapper, $entity, $name, $table, $foreignKey, $otherKey, $caller, $inverse);
} | php | public function morphToMany(
$entity,
string $related,
string $name,
string $table = null,
string $foreignKey = null,
string $otherKey = null,
bool $inverse = false
): MorphToMany {
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
$this->addPivotRelation($relation);
// First, we will need to determine the foreign key and "other key" for the
// relationship. Once we have determined the keys we will make the query
// instances, as well as the relationship instances we need for these.
$foreignKey = $foreignKey ?: $name.'_id';
$relatedMapper = Manager::getInstance()->mapper($related);
$otherKey = $otherKey ?: $relatedMapper->getEntityMap()->getForeignKey();
$table = $table ?: str_plural($name);
return new MorphToMany($relatedMapper, $entity, $name, $table, $foreignKey, $otherKey, $caller, $inverse);
} | [
"public",
"function",
"morphToMany",
"(",
"$",
"entity",
",",
"string",
"$",
"related",
",",
"string",
"$",
"name",
",",
"string",
"$",
"table",
"=",
"null",
",",
"string",
"$",
"foreignKey",
"=",
"null",
",",
"string",
"$",
"otherKey",
"=",
"null",
",",
"bool",
"$",
"inverse",
"=",
"false",
")",
":",
"MorphToMany",
"{",
"// Add the relation to the definition in map",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"$",
"this",
"->",
"relatedClasses",
"[",
"$",
"relation",
"]",
"=",
"$",
"related",
";",
"$",
"this",
"->",
"addManyRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addForeignRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addPivotRelation",
"(",
"$",
"relation",
")",
";",
"// First, we will need to determine the foreign key and \"other key\" for the",
"// relationship. Once we have determined the keys we will make the query",
"// instances, as well as the relationship instances we need for these.",
"$",
"foreignKey",
"=",
"$",
"foreignKey",
"?",
":",
"$",
"name",
".",
"'_id'",
";",
"$",
"relatedMapper",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"mapper",
"(",
"$",
"related",
")",
";",
"$",
"otherKey",
"=",
"$",
"otherKey",
"?",
":",
"$",
"relatedMapper",
"->",
"getEntityMap",
"(",
")",
"->",
"getForeignKey",
"(",
")",
";",
"$",
"table",
"=",
"$",
"table",
"?",
":",
"str_plural",
"(",
"$",
"name",
")",
";",
"return",
"new",
"MorphToMany",
"(",
"$",
"relatedMapper",
",",
"$",
"entity",
",",
"$",
"name",
",",
"$",
"table",
",",
"$",
"foreignKey",
",",
"$",
"otherKey",
",",
"$",
"caller",
",",
"$",
"inverse",
")",
";",
"}"
] | Define a polymorphic many-to-many relationship.
@param mixed $entity
@param string $related
@param string $name
@param string|null $table
@param string|null $foreignKey
@param string|null $otherKey
@param bool $inverse
@throws MappingException
@return \Analogue\ORM\Relationships\MorphToMany | [
"Define",
"a",
"polymorphic",
"many",
"-",
"to",
"-",
"many",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1439-L1469 |
analogueorm/analogue | src/EntityMap.php | EntityMap.morphedByMany | public function morphedByMany(
$entity,
string $related,
string $name,
string $table = null,
string $foreignKey = null,
string $otherKey = null
): MorphToMany {
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
$foreignKey = $foreignKey ?: $this->getForeignKey();
// For the inverse of the polymorphic many-to-many relations, we will change
// the way we determine the foreign and other keys, as it is the opposite
// of the morph-to-many method since we're figuring out these inverses.
$otherKey = $otherKey ?: $name.'_id';
return $this->morphToMany($entity, $related, $name, $table, $foreignKey, $otherKey, true);
} | php | public function morphedByMany(
$entity,
string $related,
string $name,
string $table = null,
string $foreignKey = null,
string $otherKey = null
): MorphToMany {
// Add the relation to the definition in map
list(, $caller) = debug_backtrace(false);
$relation = $caller['function'];
$this->relatedClasses[$relation] = $related;
$this->addManyRelation($relation);
$this->addForeignRelation($relation);
$foreignKey = $foreignKey ?: $this->getForeignKey();
// For the inverse of the polymorphic many-to-many relations, we will change
// the way we determine the foreign and other keys, as it is the opposite
// of the morph-to-many method since we're figuring out these inverses.
$otherKey = $otherKey ?: $name.'_id';
return $this->morphToMany($entity, $related, $name, $table, $foreignKey, $otherKey, true);
} | [
"public",
"function",
"morphedByMany",
"(",
"$",
"entity",
",",
"string",
"$",
"related",
",",
"string",
"$",
"name",
",",
"string",
"$",
"table",
"=",
"null",
",",
"string",
"$",
"foreignKey",
"=",
"null",
",",
"string",
"$",
"otherKey",
"=",
"null",
")",
":",
"MorphToMany",
"{",
"// Add the relation to the definition in map",
"list",
"(",
",",
"$",
"caller",
")",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"$",
"relation",
"=",
"$",
"caller",
"[",
"'function'",
"]",
";",
"$",
"this",
"->",
"relatedClasses",
"[",
"$",
"relation",
"]",
"=",
"$",
"related",
";",
"$",
"this",
"->",
"addManyRelation",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"addForeignRelation",
"(",
"$",
"relation",
")",
";",
"$",
"foreignKey",
"=",
"$",
"foreignKey",
"?",
":",
"$",
"this",
"->",
"getForeignKey",
"(",
")",
";",
"// For the inverse of the polymorphic many-to-many relations, we will change",
"// the way we determine the foreign and other keys, as it is the opposite",
"// of the morph-to-many method since we're figuring out these inverses.",
"$",
"otherKey",
"=",
"$",
"otherKey",
"?",
":",
"$",
"name",
".",
"'_id'",
";",
"return",
"$",
"this",
"->",
"morphToMany",
"(",
"$",
"entity",
",",
"$",
"related",
",",
"$",
"name",
",",
"$",
"table",
",",
"$",
"foreignKey",
",",
"$",
"otherKey",
",",
"true",
")",
";",
"}"
] | Define a polymorphic, inverse many-to-many relationship.
@param mixed $entity
@param string $related
@param string $name
@param string|null $table
@param string|null $foreignKey
@param string|null $otherKey
@throws MappingException
@return \Analogue\ORM\Relationships\MorphToMany | [
"Define",
"a",
"polymorphic",
"inverse",
"many",
"-",
"to",
"-",
"many",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1485-L1509 |
analogueorm/analogue | src/EntityMap.php | EntityMap.joiningTable | public function joiningTable(self $relatedMap): string
{
// The joining table name, by convention, is simply the snake cased models
// sorted alphabetically and concatenated with an underscore, so we can
// just sort the models and join them together to get the table name.
$base = $this->getTable();
$related = $relatedMap->getTable();
$tables = [$related, $base];
// Now that we have the model names in an array we can just sort them and
// use the implode function to join them together with an underscores,
// which is typically used by convention within the database system.
sort($tables);
return strtolower(implode('_', $tables));
} | php | public function joiningTable(self $relatedMap): string
{
// The joining table name, by convention, is simply the snake cased models
// sorted alphabetically and concatenated with an underscore, so we can
// just sort the models and join them together to get the table name.
$base = $this->getTable();
$related = $relatedMap->getTable();
$tables = [$related, $base];
// Now that we have the model names in an array we can just sort them and
// use the implode function to join them together with an underscores,
// which is typically used by convention within the database system.
sort($tables);
return strtolower(implode('_', $tables));
} | [
"public",
"function",
"joiningTable",
"(",
"self",
"$",
"relatedMap",
")",
":",
"string",
"{",
"// The joining table name, by convention, is simply the snake cased models",
"// sorted alphabetically and concatenated with an underscore, so we can",
"// just sort the models and join them together to get the table name.",
"$",
"base",
"=",
"$",
"this",
"->",
"getTable",
"(",
")",
";",
"$",
"related",
"=",
"$",
"relatedMap",
"->",
"getTable",
"(",
")",
";",
"$",
"tables",
"=",
"[",
"$",
"related",
",",
"$",
"base",
"]",
";",
"// Now that we have the model names in an array we can just sort them and",
"// use the implode function to join them together with an underscores,",
"// which is typically used by convention within the database system.",
"sort",
"(",
"$",
"tables",
")",
";",
"return",
"strtolower",
"(",
"implode",
"(",
"'_'",
",",
"$",
"tables",
")",
")",
";",
"}"
] | Get the joining table name for a many-to-many relation.
@param EntityMap $relatedMap
@return string | [
"Get",
"the",
"joining",
"table",
"name",
"for",
"a",
"many",
"-",
"to",
"-",
"many",
"relation",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1518-L1535 |
analogueorm/analogue | src/EntityMap.php | EntityMap.getMorphs | protected function getMorphs(string $name, string $type = null, string $id = null): array
{
return [
$type ?: $name.'_type',
$id ?: $name.'_id',
];
} | php | protected function getMorphs(string $name, string $type = null, string $id = null): array
{
return [
$type ?: $name.'_type',
$id ?: $name.'_id',
];
} | [
"protected",
"function",
"getMorphs",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"type",
"=",
"null",
",",
"string",
"$",
"id",
"=",
"null",
")",
":",
"array",
"{",
"return",
"[",
"$",
"type",
"?",
":",
"$",
"name",
".",
"'_type'",
",",
"$",
"id",
"?",
":",
"$",
"name",
".",
"'_id'",
",",
"]",
";",
"}"
] | Get the polymorphic relationship columns.
@param string $name
@param string $type
@param string $id
@return string[] | [
"Get",
"the",
"polymorphic",
"relationship",
"columns",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1546-L1552 |
analogueorm/analogue | src/EntityMap.php | EntityMap.getMorphClass | public function getMorphClass(): string
{
$morphClass = Manager::getInstance()->getMorphMap($this->getClass());
return $this->morphClass ?: $morphClass;
} | php | public function getMorphClass(): string
{
$morphClass = Manager::getInstance()->getMorphMap($this->getClass());
return $this->morphClass ?: $morphClass;
} | [
"public",
"function",
"getMorphClass",
"(",
")",
":",
"string",
"{",
"$",
"morphClass",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
"->",
"getMorphMap",
"(",
"$",
"this",
"->",
"getClass",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"morphClass",
"?",
":",
"$",
"morphClass",
";",
"}"
] | Get the class name for polymorphic relations.
@return string | [
"Get",
"the",
"class",
"name",
"for",
"polymorphic",
"relations",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1559-L1564 |
analogueorm/analogue | src/EntityMap.php | EntityMap.initialize | public function initialize()
{
$userMethods = $this->getCustomMethods();
// Parse EntityMap for method based relationship
if (count($userMethods) > 0) {
$this->relationships = $this->parseMethodsForRelationship($userMethods);
}
// Parse EntityMap for dynamic relationships
if (count($this->dynamicRelationships) > 0) {
$this->relationships = $this->relationships + $this->getDynamicRelationships();
}
} | php | public function initialize()
{
$userMethods = $this->getCustomMethods();
// Parse EntityMap for method based relationship
if (count($userMethods) > 0) {
$this->relationships = $this->parseMethodsForRelationship($userMethods);
}
// Parse EntityMap for dynamic relationships
if (count($this->dynamicRelationships) > 0) {
$this->relationships = $this->relationships + $this->getDynamicRelationships();
}
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"$",
"userMethods",
"=",
"$",
"this",
"->",
"getCustomMethods",
"(",
")",
";",
"// Parse EntityMap for method based relationship",
"if",
"(",
"count",
"(",
"$",
"userMethods",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"relationships",
"=",
"$",
"this",
"->",
"parseMethodsForRelationship",
"(",
"$",
"userMethods",
")",
";",
"}",
"// Parse EntityMap for dynamic relationships",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"dynamicRelationships",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"relationships",
"=",
"$",
"this",
"->",
"relationships",
"+",
"$",
"this",
"->",
"getDynamicRelationships",
"(",
")",
";",
"}",
"}"
] | Process EntityMap parsing at initialization time.
@return void | [
"Process",
"EntityMap",
"parsing",
"at",
"initialization",
"time",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1583-L1596 |
analogueorm/analogue | src/EntityMap.php | EntityMap.parseMethodsForRelationship | protected function parseMethodsForRelationship(array $customMethods): array
{
$relationships = [];
$class = new ReflectionClass(get_class($this));
// Get the mapped Entity class, as we will detect relationships
// methods by testing that the first argument is type-hinted to
// the same class as the mapped Entity.
$entityClass = $this->getClass();
foreach ($customMethods as $methodName) {
$method = $class->getMethod($methodName);
if ($method->getNumberOfParameters() > 0) {
$params = $method->getParameters();
if ($params[0]->getClass() && ($params[0]->getClass()->name == $entityClass || is_subclass_of($entityClass, $params[0]->getClass()->name))) {
$relationships[] = $methodName;
}
}
}
return $relationships;
} | php | protected function parseMethodsForRelationship(array $customMethods): array
{
$relationships = [];
$class = new ReflectionClass(get_class($this));
// Get the mapped Entity class, as we will detect relationships
// methods by testing that the first argument is type-hinted to
// the same class as the mapped Entity.
$entityClass = $this->getClass();
foreach ($customMethods as $methodName) {
$method = $class->getMethod($methodName);
if ($method->getNumberOfParameters() > 0) {
$params = $method->getParameters();
if ($params[0]->getClass() && ($params[0]->getClass()->name == $entityClass || is_subclass_of($entityClass, $params[0]->getClass()->name))) {
$relationships[] = $methodName;
}
}
}
return $relationships;
} | [
"protected",
"function",
"parseMethodsForRelationship",
"(",
"array",
"$",
"customMethods",
")",
":",
"array",
"{",
"$",
"relationships",
"=",
"[",
"]",
";",
"$",
"class",
"=",
"new",
"ReflectionClass",
"(",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"// Get the mapped Entity class, as we will detect relationships",
"// methods by testing that the first argument is type-hinted to",
"// the same class as the mapped Entity.",
"$",
"entityClass",
"=",
"$",
"this",
"->",
"getClass",
"(",
")",
";",
"foreach",
"(",
"$",
"customMethods",
"as",
"$",
"methodName",
")",
"{",
"$",
"method",
"=",
"$",
"class",
"->",
"getMethod",
"(",
"$",
"methodName",
")",
";",
"if",
"(",
"$",
"method",
"->",
"getNumberOfParameters",
"(",
")",
">",
"0",
")",
"{",
"$",
"params",
"=",
"$",
"method",
"->",
"getParameters",
"(",
")",
";",
"if",
"(",
"$",
"params",
"[",
"0",
"]",
"->",
"getClass",
"(",
")",
"&&",
"(",
"$",
"params",
"[",
"0",
"]",
"->",
"getClass",
"(",
")",
"->",
"name",
"==",
"$",
"entityClass",
"||",
"is_subclass_of",
"(",
"$",
"entityClass",
",",
"$",
"params",
"[",
"0",
"]",
"->",
"getClass",
"(",
")",
"->",
"name",
")",
")",
")",
"{",
"$",
"relationships",
"[",
"]",
"=",
"$",
"methodName",
";",
"}",
"}",
"}",
"return",
"$",
"relationships",
";",
"}"
] | Parse user's class methods for relationships.
@param array $customMethods
@return array | [
"Parse",
"user",
"s",
"class",
"methods",
"for",
"relationships",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1644-L1668 |
analogueorm/analogue | src/EntityMap.php | EntityMap.sortRelationshipsByType | protected function sortRelationshipsByType()
{
$entityClass = $this->getClass();
// Instantiate a dummy entity which we will pass to relationship methods.
$entity = unserialize(sprintf('O:%d:"%s":0:{}', strlen($entityClass), $entityClass));
foreach ($this->relationships as $relation) {
$this->$relation($entity);
}
} | php | protected function sortRelationshipsByType()
{
$entityClass = $this->getClass();
// Instantiate a dummy entity which we will pass to relationship methods.
$entity = unserialize(sprintf('O:%d:"%s":0:{}', strlen($entityClass), $entityClass));
foreach ($this->relationships as $relation) {
$this->$relation($entity);
}
} | [
"protected",
"function",
"sortRelationshipsByType",
"(",
")",
"{",
"$",
"entityClass",
"=",
"$",
"this",
"->",
"getClass",
"(",
")",
";",
"// Instantiate a dummy entity which we will pass to relationship methods.",
"$",
"entity",
"=",
"unserialize",
"(",
"sprintf",
"(",
"'O:%d:\"%s\":0:{}'",
",",
"strlen",
"(",
"$",
"entityClass",
")",
",",
"$",
"entityClass",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"relationships",
"as",
"$",
"relation",
")",
"{",
"$",
"this",
"->",
"$",
"relation",
"(",
"$",
"entity",
")",
";",
"}",
"}"
] | Sort Relationships methods by type.
TODO : replace this by directly setting these value
in the corresponding methods, so we won't need
the correspondency table
@return void | [
"Sort",
"Relationships",
"methods",
"by",
"type",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1679-L1689 |
analogueorm/analogue | src/EntityMap.php | EntityMap.getAttributeNamesFromColumns | public function getAttributeNamesFromColumns($array)
{
if (!empty($this->mappings)) {
$newArray = [];
foreach ($array as $key => $value) {
$attributeName = isset($this->mappings[$key]) ? $this->mappings[$key] : $key;
$newArray[$attributeName] = $value;
}
return $newArray;
}
if ($this->camelCaseHydratation) {
$newArray = [];
foreach ($array as $key => $value) {
$attributeName = camel_case($key);
$newArray[$attributeName] = $value;
}
return $newArray;
}
return $array;
} | php | public function getAttributeNamesFromColumns($array)
{
if (!empty($this->mappings)) {
$newArray = [];
foreach ($array as $key => $value) {
$attributeName = isset($this->mappings[$key]) ? $this->mappings[$key] : $key;
$newArray[$attributeName] = $value;
}
return $newArray;
}
if ($this->camelCaseHydratation) {
$newArray = [];
foreach ($array as $key => $value) {
$attributeName = camel_case($key);
$newArray[$attributeName] = $value;
}
return $newArray;
}
return $array;
} | [
"public",
"function",
"getAttributeNamesFromColumns",
"(",
"$",
"array",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"mappings",
")",
")",
"{",
"$",
"newArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"attributeName",
"=",
"isset",
"(",
"$",
"this",
"->",
"mappings",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"this",
"->",
"mappings",
"[",
"$",
"key",
"]",
":",
"$",
"key",
";",
"$",
"newArray",
"[",
"$",
"attributeName",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"newArray",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"camelCaseHydratation",
")",
"{",
"$",
"newArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"attributeName",
"=",
"camel_case",
"(",
"$",
"key",
")",
";",
"$",
"newArray",
"[",
"$",
"attributeName",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"newArray",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Maps the names of the column names to the appropriate attributes
of an entity if the $attributes property of an EntityMap is an
associative array.
@param array $array
@return array | [
"Maps",
"the",
"names",
"of",
"the",
"column",
"names",
"to",
"the",
"appropriate",
"attributes",
"of",
"an",
"entity",
"if",
"the",
"$attributes",
"property",
"of",
"an",
"EntityMap",
"is",
"an",
"associative",
"array",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1733-L1755 |
analogueorm/analogue | src/EntityMap.php | EntityMap.getColumnNamesFromAttributes | public function getColumnNamesFromAttributes($array)
{
if (!empty($this->mappings)) {
$newArray = [];
$flipped = array_flip($this->mappings);
foreach ($array as $key => $value) {
$attributeName = isset($flipped[$key]) ? $flipped[$key] : $key;
$newArray[$attributeName] = $value;
}
return $newArray;
}
if ($this->camelCaseHydratation) {
$newArray = [];
foreach ($array as $key => $value) {
$attributeName = snake_case($key);
$newArray[$attributeName] = $value;
}
return $newArray;
}
return $array;
} | php | public function getColumnNamesFromAttributes($array)
{
if (!empty($this->mappings)) {
$newArray = [];
$flipped = array_flip($this->mappings);
foreach ($array as $key => $value) {
$attributeName = isset($flipped[$key]) ? $flipped[$key] : $key;
$newArray[$attributeName] = $value;
}
return $newArray;
}
if ($this->camelCaseHydratation) {
$newArray = [];
foreach ($array as $key => $value) {
$attributeName = snake_case($key);
$newArray[$attributeName] = $value;
}
return $newArray;
}
return $array;
} | [
"public",
"function",
"getColumnNamesFromAttributes",
"(",
"$",
"array",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"mappings",
")",
")",
"{",
"$",
"newArray",
"=",
"[",
"]",
";",
"$",
"flipped",
"=",
"array_flip",
"(",
"$",
"this",
"->",
"mappings",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"attributeName",
"=",
"isset",
"(",
"$",
"flipped",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"flipped",
"[",
"$",
"key",
"]",
":",
"$",
"key",
";",
"$",
"newArray",
"[",
"$",
"attributeName",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"newArray",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"camelCaseHydratation",
")",
"{",
"$",
"newArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"attributeName",
"=",
"snake_case",
"(",
"$",
"key",
")",
";",
"$",
"newArray",
"[",
"$",
"attributeName",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"newArray",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Maps the attribute names of an entity to the appropriate
column names in the database if the $attributes property of
an EntityMap is an associative array.
@param array $array
@return array | [
"Maps",
"the",
"attribute",
"names",
"of",
"an",
"entity",
"to",
"the",
"appropriate",
"column",
"names",
"in",
"the",
"database",
"if",
"the",
"$attributes",
"property",
"of",
"an",
"EntityMap",
"is",
"an",
"associative",
"array",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L1784-L1807 |
analogueorm/analogue | src/Relationships/HasOneOrMany.php | HasOneOrMany.detachExcept | protected function detachExcept($entities)
{
$query = $this->query->getQuery()->from($this->relatedMap->getTable());
if (count($entities) > 0) {
$keys = $this->getKeys($entities);
$query->whereNotIn($this->relatedMap->getKeyName(), $keys);
}
$parentKey = $this->parentMap->getKeyName();
$query->where($this->getPlainForeignKey(), '=', $this->parent->getEntityAttribute($parentKey))
->update([$this->getPlainForeignKey() => null]);
} | php | protected function detachExcept($entities)
{
$query = $this->query->getQuery()->from($this->relatedMap->getTable());
if (count($entities) > 0) {
$keys = $this->getKeys($entities);
$query->whereNotIn($this->relatedMap->getKeyName(), $keys);
}
$parentKey = $this->parentMap->getKeyName();
$query->where($this->getPlainForeignKey(), '=', $this->parent->getEntityAttribute($parentKey))
->update([$this->getPlainForeignKey() => null]);
} | [
"protected",
"function",
"detachExcept",
"(",
"$",
"entities",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"query",
"->",
"getQuery",
"(",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"relatedMap",
"->",
"getTable",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"entities",
")",
">",
"0",
")",
"{",
"$",
"keys",
"=",
"$",
"this",
"->",
"getKeys",
"(",
"$",
"entities",
")",
";",
"$",
"query",
"->",
"whereNotIn",
"(",
"$",
"this",
"->",
"relatedMap",
"->",
"getKeyName",
"(",
")",
",",
"$",
"keys",
")",
";",
"}",
"$",
"parentKey",
"=",
"$",
"this",
"->",
"parentMap",
"->",
"getKeyName",
"(",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"getPlainForeignKey",
"(",
")",
",",
"'='",
",",
"$",
"this",
"->",
"parent",
"->",
"getEntityAttribute",
"(",
"$",
"parentKey",
")",
")",
"->",
"update",
"(",
"[",
"$",
"this",
"->",
"getPlainForeignKey",
"(",
")",
"=>",
"null",
"]",
")",
";",
"}"
] | @param $entities
@throws \InvalidArgumentException | [
"@param",
"$entities"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/HasOneOrMany.php#L91-L104 |
analogueorm/analogue | src/Relationships/HasOneOrMany.php | HasOneOrMany.addEagerConstraints | public function addEagerConstraints(array $results)
{
$this->query->whereIn($this->foreignKey, $this->getKeysFromResults($results, $this->localKey));
} | php | public function addEagerConstraints(array $results)
{
$this->query->whereIn($this->foreignKey, $this->getKeysFromResults($results, $this->localKey));
} | [
"public",
"function",
"addEagerConstraints",
"(",
"array",
"$",
"results",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"whereIn",
"(",
"$",
"this",
"->",
"foreignKey",
",",
"$",
"this",
"->",
"getKeysFromResults",
"(",
"$",
"results",
",",
"$",
"this",
"->",
"localKey",
")",
")",
";",
"}"
] | Set the constraints for an eager load of the relation.
@param array $results
@return void | [
"Set",
"the",
"constraints",
"for",
"an",
"eager",
"load",
"of",
"the",
"relation",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/HasOneOrMany.php#L143-L146 |
analogueorm/analogue | src/Relationships/HasOneOrMany.php | HasOneOrMany.matchOneOrMany | protected function matchOneOrMany(array $results, $relation, $type)
{
$entities = $this->getEager();
$dictionary = $this->buildDictionary($entities);
$cache = $this->parentMapper->getEntityCache();
$host = $this;
// Once we have the dictionary we can simply spin through the parent models to
// link them up with their children using the keyed dictionary to make the
// matching very convenient and easy work. Then we'll just return them.
return array_map(function ($result) use ($dictionary, $cache, $type, $relation, $host) {
$key = $result[$host->localKey];
if (isset($dictionary[$key])) {
$value = $host->getRelationValue($dictionary, $key, $type);
$result[$relation] = $value;
// TODO : Refactor This
$cache->cacheLoadedRelationResult($key, $relation, $value, $this);
} else {
$result[$relation] = $type === 'many' ? $this->relatedMap->newCollection() : null;
}
return $result;
}, $results);
} | php | protected function matchOneOrMany(array $results, $relation, $type)
{
$entities = $this->getEager();
$dictionary = $this->buildDictionary($entities);
$cache = $this->parentMapper->getEntityCache();
$host = $this;
// Once we have the dictionary we can simply spin through the parent models to
// link them up with their children using the keyed dictionary to make the
// matching very convenient and easy work. Then we'll just return them.
return array_map(function ($result) use ($dictionary, $cache, $type, $relation, $host) {
$key = $result[$host->localKey];
if (isset($dictionary[$key])) {
$value = $host->getRelationValue($dictionary, $key, $type);
$result[$relation] = $value;
// TODO : Refactor This
$cache->cacheLoadedRelationResult($key, $relation, $value, $this);
} else {
$result[$relation] = $type === 'many' ? $this->relatedMap->newCollection() : null;
}
return $result;
}, $results);
} | [
"protected",
"function",
"matchOneOrMany",
"(",
"array",
"$",
"results",
",",
"$",
"relation",
",",
"$",
"type",
")",
"{",
"$",
"entities",
"=",
"$",
"this",
"->",
"getEager",
"(",
")",
";",
"$",
"dictionary",
"=",
"$",
"this",
"->",
"buildDictionary",
"(",
"$",
"entities",
")",
";",
"$",
"cache",
"=",
"$",
"this",
"->",
"parentMapper",
"->",
"getEntityCache",
"(",
")",
";",
"$",
"host",
"=",
"$",
"this",
";",
"// Once we have the dictionary we can simply spin through the parent models to",
"// link them up with their children using the keyed dictionary to make the",
"// matching very convenient and easy work. Then we'll just return them.",
"return",
"array_map",
"(",
"function",
"(",
"$",
"result",
")",
"use",
"(",
"$",
"dictionary",
",",
"$",
"cache",
",",
"$",
"type",
",",
"$",
"relation",
",",
"$",
"host",
")",
"{",
"$",
"key",
"=",
"$",
"result",
"[",
"$",
"host",
"->",
"localKey",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"dictionary",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"host",
"->",
"getRelationValue",
"(",
"$",
"dictionary",
",",
"$",
"key",
",",
"$",
"type",
")",
";",
"$",
"result",
"[",
"$",
"relation",
"]",
"=",
"$",
"value",
";",
"// TODO : Refactor This",
"$",
"cache",
"->",
"cacheLoadedRelationResult",
"(",
"$",
"key",
",",
"$",
"relation",
",",
"$",
"value",
",",
"$",
"this",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"relation",
"]",
"=",
"$",
"type",
"===",
"'many'",
"?",
"$",
"this",
"->",
"relatedMap",
"->",
"newCollection",
"(",
")",
":",
"null",
";",
"}",
"return",
"$",
"result",
";",
"}",
",",
"$",
"results",
")",
";",
"}"
] | Match the eagerly loaded results to their many parents.
@param array $results
@param string $relation
@param string $type
@return array | [
"Match",
"the",
"eagerly",
"loaded",
"results",
"to",
"their",
"many",
"parents",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/HasOneOrMany.php#L183-L212 |
analogueorm/analogue | src/Relationships/HasOneOrMany.php | HasOneOrMany.getRelationValue | protected function getRelationValue(array $dictionary, $key, $type)
{
$value = $dictionary[$key];
return $type == 'one' ? reset($value) : $this->relatedMap->newCollection($value);
} | php | protected function getRelationValue(array $dictionary, $key, $type)
{
$value = $dictionary[$key];
return $type == 'one' ? reset($value) : $this->relatedMap->newCollection($value);
} | [
"protected",
"function",
"getRelationValue",
"(",
"array",
"$",
"dictionary",
",",
"$",
"key",
",",
"$",
"type",
")",
"{",
"$",
"value",
"=",
"$",
"dictionary",
"[",
"$",
"key",
"]",
";",
"return",
"$",
"type",
"==",
"'one'",
"?",
"reset",
"(",
"$",
"value",
")",
":",
"$",
"this",
"->",
"relatedMap",
"->",
"newCollection",
"(",
"$",
"value",
")",
";",
"}"
] | Get the value of a relationship by one or many type.
@param array $dictionary
@param string $key
@param string $type
@return mixed | [
"Get",
"the",
"value",
"of",
"a",
"relationship",
"by",
"one",
"or",
"many",
"type",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/HasOneOrMany.php#L223-L228 |
analogueorm/analogue | src/Relationships/HasOneOrMany.php | HasOneOrMany.buildDictionary | protected function buildDictionary(EntityCollection $results)
{
$dictionary = [];
$foreign = $this->getPlainForeignKey();
// First we will create a dictionary of models keyed by the foreign key of the
// relationship as this will allow us to quickly access all of the related
// models without having to do nested looping which will be quite slow.
foreach ($results as $result) {
$dictionary[$result->{$foreign}][] = $result;
}
return $dictionary;
} | php | protected function buildDictionary(EntityCollection $results)
{
$dictionary = [];
$foreign = $this->getPlainForeignKey();
// First we will create a dictionary of models keyed by the foreign key of the
// relationship as this will allow us to quickly access all of the related
// models without having to do nested looping which will be quite slow.
foreach ($results as $result) {
$dictionary[$result->{$foreign}][] = $result;
}
return $dictionary;
} | [
"protected",
"function",
"buildDictionary",
"(",
"EntityCollection",
"$",
"results",
")",
"{",
"$",
"dictionary",
"=",
"[",
"]",
";",
"$",
"foreign",
"=",
"$",
"this",
"->",
"getPlainForeignKey",
"(",
")",
";",
"// First we will create a dictionary of models keyed by the foreign key of the",
"// relationship as this will allow us to quickly access all of the related",
"// models without having to do nested looping which will be quite slow.",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"$",
"dictionary",
"[",
"$",
"result",
"->",
"{",
"$",
"foreign",
"}",
"]",
"[",
"]",
"=",
"$",
"result",
";",
"}",
"return",
"$",
"dictionary",
";",
"}"
] | Build model dictionary keyed by the relation's foreign key.
@param EntityCollection $results
@return array | [
"Build",
"model",
"dictionary",
"keyed",
"by",
"the",
"relation",
"s",
"foreign",
"key",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/HasOneOrMany.php#L237-L251 |
analogueorm/analogue | src/Relationships/MorphPivot.php | MorphPivot.setKeysForSaveQuery | protected function setKeysForSaveQuery(Query $query)
{
$query->where($this->morphType, $this->morphClass);
return parent::setKeysForSaveQuery($query);
} | php | protected function setKeysForSaveQuery(Query $query)
{
$query->where($this->morphType, $this->morphClass);
return parent::setKeysForSaveQuery($query);
} | [
"protected",
"function",
"setKeysForSaveQuery",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"morphType",
",",
"$",
"this",
"->",
"morphClass",
")",
";",
"return",
"parent",
"::",
"setKeysForSaveQuery",
"(",
"$",
"query",
")",
";",
"}"
] | Set the keys for a save update query.
@param Query $query
@return Query | [
"Set",
"the",
"keys",
"for",
"a",
"save",
"update",
"query",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/MorphPivot.php#L34-L39 |
analogueorm/analogue | src/Drivers/Manager.php | Manager.getAdapter | public function getAdapter(string $driver, string $connection = null)
{
if (array_key_exists($driver, $this->drivers)) {
return $this->drivers[$driver]->getAdapter($connection);
}
} | php | public function getAdapter(string $driver, string $connection = null)
{
if (array_key_exists($driver, $this->drivers)) {
return $this->drivers[$driver]->getAdapter($connection);
}
} | [
"public",
"function",
"getAdapter",
"(",
"string",
"$",
"driver",
",",
"string",
"$",
"connection",
"=",
"null",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"driver",
",",
"$",
"this",
"->",
"drivers",
")",
")",
"{",
"return",
"$",
"this",
"->",
"drivers",
"[",
"$",
"driver",
"]",
"->",
"getAdapter",
"(",
"$",
"connection",
")",
";",
"}",
"}"
] | Get the DBAdapter.
@param string $driver
@param string $connection connection name for drivers supporting multiple connection.
@return DBAdapter | [
"Get",
"the",
"DBAdapter",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Drivers/Manager.php#L34-L39 |
analogueorm/analogue | src/AnalogueServiceProvider.php | AnalogueServiceProvider.register | public function register()
{
// Experimenting autoloading proxies
$this->app->singleton('analogue', function ($app) {
$db = $app['db'];
$connectionProvider = new IlluminateConnectionProvider($db);
$illuminate = new IlluminateDriver($connectionProvider);
$driverManager = new DriverManager();
$driverManager->addDriver($illuminate);
$event = $app->make('events');
$manager = new Manager($driverManager, $event);
$manager->registerPlugin(\Analogue\ORM\Plugins\Timestamps\TimestampsPlugin::class);
$manager->registerPlugin(\Analogue\ORM\Plugins\SoftDeletes\SoftDeletesPlugin::class);
// If the cache is pre laravel 5.5, it doesn't implements PSR-16, so we'll skip it.
$cache = $app->make(CacheRepository::class);
if ($cache instanceof CacheInterface) {
$manager->setCache($cache);
}
$proxyPath = storage_path('framework/analogue/proxies');
if (!file_exists($proxyPath)) {
mkdir($proxyPath, 0777, true);
}
$proxyConfig = new \ProxyManager\Configuration();
$proxyConfig->setProxiesTargetDir($proxyPath);
spl_autoload_register($proxyConfig->getProxyAutoloader());
$manager->setProxyPath($proxyPath);
return $manager;
});
$this->app->bind(Manager::class, function ($app) {
return $app->make('analogue');
});
} | php | public function register()
{
// Experimenting autoloading proxies
$this->app->singleton('analogue', function ($app) {
$db = $app['db'];
$connectionProvider = new IlluminateConnectionProvider($db);
$illuminate = new IlluminateDriver($connectionProvider);
$driverManager = new DriverManager();
$driverManager->addDriver($illuminate);
$event = $app->make('events');
$manager = new Manager($driverManager, $event);
$manager->registerPlugin(\Analogue\ORM\Plugins\Timestamps\TimestampsPlugin::class);
$manager->registerPlugin(\Analogue\ORM\Plugins\SoftDeletes\SoftDeletesPlugin::class);
// If the cache is pre laravel 5.5, it doesn't implements PSR-16, so we'll skip it.
$cache = $app->make(CacheRepository::class);
if ($cache instanceof CacheInterface) {
$manager->setCache($cache);
}
$proxyPath = storage_path('framework/analogue/proxies');
if (!file_exists($proxyPath)) {
mkdir($proxyPath, 0777, true);
}
$proxyConfig = new \ProxyManager\Configuration();
$proxyConfig->setProxiesTargetDir($proxyPath);
spl_autoload_register($proxyConfig->getProxyAutoloader());
$manager->setProxyPath($proxyPath);
return $manager;
});
$this->app->bind(Manager::class, function ($app) {
return $app->make('analogue');
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"// Experimenting autoloading proxies",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'analogue'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"db",
"=",
"$",
"app",
"[",
"'db'",
"]",
";",
"$",
"connectionProvider",
"=",
"new",
"IlluminateConnectionProvider",
"(",
"$",
"db",
")",
";",
"$",
"illuminate",
"=",
"new",
"IlluminateDriver",
"(",
"$",
"connectionProvider",
")",
";",
"$",
"driverManager",
"=",
"new",
"DriverManager",
"(",
")",
";",
"$",
"driverManager",
"->",
"addDriver",
"(",
"$",
"illuminate",
")",
";",
"$",
"event",
"=",
"$",
"app",
"->",
"make",
"(",
"'events'",
")",
";",
"$",
"manager",
"=",
"new",
"Manager",
"(",
"$",
"driverManager",
",",
"$",
"event",
")",
";",
"$",
"manager",
"->",
"registerPlugin",
"(",
"\\",
"Analogue",
"\\",
"ORM",
"\\",
"Plugins",
"\\",
"Timestamps",
"\\",
"TimestampsPlugin",
"::",
"class",
")",
";",
"$",
"manager",
"->",
"registerPlugin",
"(",
"\\",
"Analogue",
"\\",
"ORM",
"\\",
"Plugins",
"\\",
"SoftDeletes",
"\\",
"SoftDeletesPlugin",
"::",
"class",
")",
";",
"// If the cache is pre laravel 5.5, it doesn't implements PSR-16, so we'll skip it.",
"$",
"cache",
"=",
"$",
"app",
"->",
"make",
"(",
"CacheRepository",
"::",
"class",
")",
";",
"if",
"(",
"$",
"cache",
"instanceof",
"CacheInterface",
")",
"{",
"$",
"manager",
"->",
"setCache",
"(",
"$",
"cache",
")",
";",
"}",
"$",
"proxyPath",
"=",
"storage_path",
"(",
"'framework/analogue/proxies'",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"proxyPath",
")",
")",
"{",
"mkdir",
"(",
"$",
"proxyPath",
",",
"0777",
",",
"true",
")",
";",
"}",
"$",
"proxyConfig",
"=",
"new",
"\\",
"ProxyManager",
"\\",
"Configuration",
"(",
")",
";",
"$",
"proxyConfig",
"->",
"setProxiesTargetDir",
"(",
"$",
"proxyPath",
")",
";",
"spl_autoload_register",
"(",
"$",
"proxyConfig",
"->",
"getProxyAutoloader",
"(",
")",
")",
";",
"$",
"manager",
"->",
"setProxyPath",
"(",
"$",
"proxyPath",
")",
";",
"return",
"$",
"manager",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"Manager",
"::",
"class",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"->",
"make",
"(",
"'analogue'",
")",
";",
"}",
")",
";",
"}"
] | Register the service provider.
@return void | [
"Register",
"the",
"service",
"provider",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/AnalogueServiceProvider.php#L35-L82 |
analogueorm/analogue | src/System/Wrappers/Factory.php | Factory.make | public function make($object)
{
$manager = Manager::getInstance();
// Instantiate hydrator
// TODO: We'll need to optimize this and allow pre-generation
// of these hydrators, and get it, ideally, from the entityMap or
// the Mapper class, so it's only instantiated once
$config = new Configuration(get_class($object));
$hydratorClass = $config->createFactory()->getHydratorClass();
$hydrator = new $hydratorClass();
if ($manager->isValueObject($object)) {
$entityMap = $manager->getValueMap($object);
} else {
$entityMap = $manager->mapper($object)->getEntityMap();
}
// Build Wrapper
return new ObjectWrapper($object, $entityMap, $hydrator);
} | php | public function make($object)
{
$manager = Manager::getInstance();
// Instantiate hydrator
// TODO: We'll need to optimize this and allow pre-generation
// of these hydrators, and get it, ideally, from the entityMap or
// the Mapper class, so it's only instantiated once
$config = new Configuration(get_class($object));
$hydratorClass = $config->createFactory()->getHydratorClass();
$hydrator = new $hydratorClass();
if ($manager->isValueObject($object)) {
$entityMap = $manager->getValueMap($object);
} else {
$entityMap = $manager->mapper($object)->getEntityMap();
}
// Build Wrapper
return new ObjectWrapper($object, $entityMap, $hydrator);
} | [
"public",
"function",
"make",
"(",
"$",
"object",
")",
"{",
"$",
"manager",
"=",
"Manager",
"::",
"getInstance",
"(",
")",
";",
"// Instantiate hydrator",
"// TODO: We'll need to optimize this and allow pre-generation",
"// of these hydrators, and get it, ideally, from the entityMap or",
"// the Mapper class, so it's only instantiated once",
"$",
"config",
"=",
"new",
"Configuration",
"(",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"$",
"hydratorClass",
"=",
"$",
"config",
"->",
"createFactory",
"(",
")",
"->",
"getHydratorClass",
"(",
")",
";",
"$",
"hydrator",
"=",
"new",
"$",
"hydratorClass",
"(",
")",
";",
"if",
"(",
"$",
"manager",
"->",
"isValueObject",
"(",
"$",
"object",
")",
")",
"{",
"$",
"entityMap",
"=",
"$",
"manager",
"->",
"getValueMap",
"(",
"$",
"object",
")",
";",
"}",
"else",
"{",
"$",
"entityMap",
"=",
"$",
"manager",
"->",
"mapper",
"(",
"$",
"object",
")",
"->",
"getEntityMap",
"(",
")",
";",
"}",
"// Build Wrapper",
"return",
"new",
"ObjectWrapper",
"(",
"$",
"object",
",",
"$",
"entityMap",
",",
"$",
"hydrator",
")",
";",
"}"
] | Build the wrapper corresponding to the object's type.
@param mixed $object
@throws \Analogue\ORM\Exceptions\MappingException
@return ObjectWrapper | [
"Build",
"the",
"wrapper",
"corresponding",
"to",
"the",
"object",
"s",
"type",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Wrappers/Factory.php#L19-L40 |
analogueorm/analogue | src/System/Builders/PolymorphicResultBuilder.php | PolymorphicResultBuilder.build | public function build(array $results, array $eagerLoads)
{
// Make a list of all primary key of the current result set. This will
// allow us to group all polymorphic operations by type, then put
// back every object in the intended order.
$primaryKeyColumn = $this->entityMap->getKeyName();
$ids = array_map(function ($row) use ($primaryKeyColumn) {
return $row[$primaryKeyColumn];
}, $results);
$results = array_combine($ids, $results);
// Make a list of types appearing within this result set.
$discriminatorColumn = $this->entityMap->getDiscriminatorColumn();
$types = array_unique(array_pluck($results, $discriminatorColumn));
// We'll split the result set by type that will make it easier to deal
// with.
$entities = [];
foreach ($types as $type) {
$this->mappers[$type] = $this->getMapperForType($type);
$resultsByType[$type] = array_filter($results, function (array $row) use ($type, $discriminatorColumn) {
return $row[$discriminatorColumn] === $type;
});
$entities = $entities + $this->buildResultsForType($resultsByType[$type], $type, $eagerLoads);
}
return array_map(function ($id) use ($entities) {
return $entities[$id];
}, $ids);
} | php | public function build(array $results, array $eagerLoads)
{
// Make a list of all primary key of the current result set. This will
// allow us to group all polymorphic operations by type, then put
// back every object in the intended order.
$primaryKeyColumn = $this->entityMap->getKeyName();
$ids = array_map(function ($row) use ($primaryKeyColumn) {
return $row[$primaryKeyColumn];
}, $results);
$results = array_combine($ids, $results);
// Make a list of types appearing within this result set.
$discriminatorColumn = $this->entityMap->getDiscriminatorColumn();
$types = array_unique(array_pluck($results, $discriminatorColumn));
// We'll split the result set by type that will make it easier to deal
// with.
$entities = [];
foreach ($types as $type) {
$this->mappers[$type] = $this->getMapperForType($type);
$resultsByType[$type] = array_filter($results, function (array $row) use ($type, $discriminatorColumn) {
return $row[$discriminatorColumn] === $type;
});
$entities = $entities + $this->buildResultsForType($resultsByType[$type], $type, $eagerLoads);
}
return array_map(function ($id) use ($entities) {
return $entities[$id];
}, $ids);
} | [
"public",
"function",
"build",
"(",
"array",
"$",
"results",
",",
"array",
"$",
"eagerLoads",
")",
"{",
"// Make a list of all primary key of the current result set. This will",
"// allow us to group all polymorphic operations by type, then put",
"// back every object in the intended order.",
"$",
"primaryKeyColumn",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getKeyName",
"(",
")",
";",
"$",
"ids",
"=",
"array_map",
"(",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"primaryKeyColumn",
")",
"{",
"return",
"$",
"row",
"[",
"$",
"primaryKeyColumn",
"]",
";",
"}",
",",
"$",
"results",
")",
";",
"$",
"results",
"=",
"array_combine",
"(",
"$",
"ids",
",",
"$",
"results",
")",
";",
"// Make a list of types appearing within this result set.",
"$",
"discriminatorColumn",
"=",
"$",
"this",
"->",
"entityMap",
"->",
"getDiscriminatorColumn",
"(",
")",
";",
"$",
"types",
"=",
"array_unique",
"(",
"array_pluck",
"(",
"$",
"results",
",",
"$",
"discriminatorColumn",
")",
")",
";",
"// We'll split the result set by type that will make it easier to deal",
"// with.",
"$",
"entities",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"mappers",
"[",
"$",
"type",
"]",
"=",
"$",
"this",
"->",
"getMapperForType",
"(",
"$",
"type",
")",
";",
"$",
"resultsByType",
"[",
"$",
"type",
"]",
"=",
"array_filter",
"(",
"$",
"results",
",",
"function",
"(",
"array",
"$",
"row",
")",
"use",
"(",
"$",
"type",
",",
"$",
"discriminatorColumn",
")",
"{",
"return",
"$",
"row",
"[",
"$",
"discriminatorColumn",
"]",
"===",
"$",
"type",
";",
"}",
")",
";",
"$",
"entities",
"=",
"$",
"entities",
"+",
"$",
"this",
"->",
"buildResultsForType",
"(",
"$",
"resultsByType",
"[",
"$",
"type",
"]",
",",
"$",
"type",
",",
"$",
"eagerLoads",
")",
";",
"}",
"return",
"array_map",
"(",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"entities",
")",
"{",
"return",
"$",
"entities",
"[",
"$",
"id",
"]",
";",
"}",
",",
"$",
"ids",
")",
";",
"}"
] | Convert a result set into an array of entities.
@param array $results
@param array $eagerLoads name of the relation(s) to be eager loaded on the Entities
@return array | [
"Convert",
"a",
"result",
"set",
"into",
"an",
"array",
"of",
"entities",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Builders/PolymorphicResultBuilder.php#L65-L98 |
analogueorm/analogue | src/Drivers/IlluminateDBAdapter.php | IlluminateDBAdapter.getQuery | public function getQuery()
{
$connection = $this->connection;
$grammar = $connection->getQueryGrammar();
return new IlluminateQueryBuilder($connection, $grammar, $connection->getPostProcessor());
} | php | public function getQuery()
{
$connection = $this->connection;
$grammar = $connection->getQueryGrammar();
return new IlluminateQueryBuilder($connection, $grammar, $connection->getPostProcessor());
} | [
"public",
"function",
"getQuery",
"(",
")",
"{",
"$",
"connection",
"=",
"$",
"this",
"->",
"connection",
";",
"$",
"grammar",
"=",
"$",
"connection",
"->",
"getQueryGrammar",
"(",
")",
";",
"return",
"new",
"IlluminateQueryBuilder",
"(",
"$",
"connection",
",",
"$",
"grammar",
",",
"$",
"connection",
"->",
"getPostProcessor",
"(",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Drivers/IlluminateDBAdapter.php#L33-L40 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.getIdsFromHashes | protected function getIdsFromHashes(array $hashes)
{
$ids = [];
foreach ($hashes as $hash) {
$split = explode('.', $hash);
$ids[] = $split[1];
}
return $ids;
} | php | protected function getIdsFromHashes(array $hashes)
{
$ids = [];
foreach ($hashes as $hash) {
$split = explode('.', $hash);
$ids[] = $split[1];
}
return $ids;
} | [
"protected",
"function",
"getIdsFromHashes",
"(",
"array",
"$",
"hashes",
")",
"{",
"$",
"ids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"hashes",
"as",
"$",
"hash",
")",
"{",
"$",
"split",
"=",
"explode",
"(",
"'.'",
",",
"$",
"hash",
")",
";",
"$",
"ids",
"[",
"]",
"=",
"$",
"split",
"[",
"1",
"]",
";",
"}",
"return",
"$",
"ids",
";",
"}"
] | @param array $hashes
@return array | [
"@param",
"array",
"$hashes"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L93-L103 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.wherePivot | public function wherePivot($column, $operator = null, $value = null, $boolean = 'and')
{
return $this->where($this->table.'.'.$column, $operator, $value, $boolean);
} | php | public function wherePivot($column, $operator = null, $value = null, $boolean = 'and')
{
return $this->where($this->table.'.'.$column, $operator, $value, $boolean);
} | [
"public",
"function",
"wherePivot",
"(",
"$",
"column",
",",
"$",
"operator",
"=",
"null",
",",
"$",
"value",
"=",
"null",
",",
"$",
"boolean",
"=",
"'and'",
")",
"{",
"return",
"$",
"this",
"->",
"where",
"(",
"$",
"this",
"->",
"table",
".",
"'.'",
".",
"$",
"column",
",",
"$",
"operator",
",",
"$",
"value",
",",
"$",
"boolean",
")",
";",
"}"
] | Set a where clause for a pivot table column.
@param string $column
@param string $operator
@param mixed $value
@param string $boolean
@return self | [
"Set",
"a",
"where",
"clause",
"for",
"a",
"pivot",
"table",
"column",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L131-L134 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.get | public function get($columns = ['*']) : Collection
{
// First we'll add the proper select columns onto the query so it is run with
// the proper columns. Then, we will get the results and hydrate out pivot
// models with the result of those columns as a separate model relation.
$columns = $this->query->getQuery()->columns ? [] : $columns;
$select = $this->getSelectColumns($columns);
$entities = $this->query->addSelect($select)->disableCache()->get()->all();
$entities = $this->hydratePivotRelation($entities);
return $this->relatedMap->newCollection($entities);
} | php | public function get($columns = ['*']) : Collection
{
// First we'll add the proper select columns onto the query so it is run with
// the proper columns. Then, we will get the results and hydrate out pivot
// models with the result of those columns as a separate model relation.
$columns = $this->query->getQuery()->columns ? [] : $columns;
$select = $this->getSelectColumns($columns);
$entities = $this->query->addSelect($select)->disableCache()->get()->all();
$entities = $this->hydratePivotRelation($entities);
return $this->relatedMap->newCollection($entities);
} | [
"public",
"function",
"get",
"(",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
":",
"Collection",
"{",
"// First we'll add the proper select columns onto the query so it is run with",
"// the proper columns. Then, we will get the results and hydrate out pivot",
"// models with the result of those columns as a separate model relation.",
"$",
"columns",
"=",
"$",
"this",
"->",
"query",
"->",
"getQuery",
"(",
")",
"->",
"columns",
"?",
"[",
"]",
":",
"$",
"columns",
";",
"$",
"select",
"=",
"$",
"this",
"->",
"getSelectColumns",
"(",
"$",
"columns",
")",
";",
"$",
"entities",
"=",
"$",
"this",
"->",
"query",
"->",
"addSelect",
"(",
"$",
"select",
")",
"->",
"disableCache",
"(",
")",
"->",
"get",
"(",
")",
"->",
"all",
"(",
")",
";",
"$",
"entities",
"=",
"$",
"this",
"->",
"hydratePivotRelation",
"(",
"$",
"entities",
")",
";",
"return",
"$",
"this",
"->",
"relatedMap",
"->",
"newCollection",
"(",
"$",
"entities",
")",
";",
"}"
] | Execute the query as a "select" statement.
@param array $columns
@return \Illuminate\Support\Collection | [
"Execute",
"the",
"query",
"as",
"a",
"select",
"statement",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L199-L213 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.hydratePivotRelation | protected function hydratePivotRelation(array $entities)
{
// TODO (note) We should definitely get rid of the pivot in a next
// release, as this is not quite relevant in a datamapper context.
return array_map(function ($entity) {
$entityWrapper = $this->factory->make($entity);
$pivotAttributes = $this->cleanPivotAttributes($entityWrapper);
$pivot = $this->newExistingPivot($pivotAttributes);
$entityWrapper->setEntityAttribute('pivot', $pivot);
$object = $entityWrapper->unwrap();
return $object;
}, $entities);
} | php | protected function hydratePivotRelation(array $entities)
{
// TODO (note) We should definitely get rid of the pivot in a next
// release, as this is not quite relevant in a datamapper context.
return array_map(function ($entity) {
$entityWrapper = $this->factory->make($entity);
$pivotAttributes = $this->cleanPivotAttributes($entityWrapper);
$pivot = $this->newExistingPivot($pivotAttributes);
$entityWrapper->setEntityAttribute('pivot', $pivot);
$object = $entityWrapper->unwrap();
return $object;
}, $entities);
} | [
"protected",
"function",
"hydratePivotRelation",
"(",
"array",
"$",
"entities",
")",
"{",
"// TODO (note) We should definitely get rid of the pivot in a next",
"// release, as this is not quite relevant in a datamapper context.",
"return",
"array_map",
"(",
"function",
"(",
"$",
"entity",
")",
"{",
"$",
"entityWrapper",
"=",
"$",
"this",
"->",
"factory",
"->",
"make",
"(",
"$",
"entity",
")",
";",
"$",
"pivotAttributes",
"=",
"$",
"this",
"->",
"cleanPivotAttributes",
"(",
"$",
"entityWrapper",
")",
";",
"$",
"pivot",
"=",
"$",
"this",
"->",
"newExistingPivot",
"(",
"$",
"pivotAttributes",
")",
";",
"$",
"entityWrapper",
"->",
"setEntityAttribute",
"(",
"'pivot'",
",",
"$",
"pivot",
")",
";",
"$",
"object",
"=",
"$",
"entityWrapper",
"->",
"unwrap",
"(",
")",
";",
"return",
"$",
"object",
";",
"}",
",",
"$",
"entities",
")",
";",
"}"
] | Hydrate the pivot table relationship on the models.
@param array $entities
@return array | [
"Hydrate",
"the",
"pivot",
"table",
"relationship",
"on",
"the",
"models",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L222-L237 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.cleanPivotAttributes | protected function cleanPivotAttributes(InternallyMappable $entity)
{
$values = [];
$attributes = $entity->getEntityAttributes();
foreach ($attributes as $key => $value) {
// To get the pivots attributes we will just take any of the attributes which
// begin with "pivot_" and add those to this arrays, as well as unsetting
// them from the parent's models since they exist in a different table.
if (strpos($key, 'pivot_') === 0) {
$values[substr($key, 6)] = $value;
unset($attributes[$key]);
}
}
// Rehydrate Entity with cleaned array.
$entity->setEntityAttributes($attributes);
return $values;
} | php | protected function cleanPivotAttributes(InternallyMappable $entity)
{
$values = [];
$attributes = $entity->getEntityAttributes();
foreach ($attributes as $key => $value) {
// To get the pivots attributes we will just take any of the attributes which
// begin with "pivot_" and add those to this arrays, as well as unsetting
// them from the parent's models since they exist in a different table.
if (strpos($key, 'pivot_') === 0) {
$values[substr($key, 6)] = $value;
unset($attributes[$key]);
}
}
// Rehydrate Entity with cleaned array.
$entity->setEntityAttributes($attributes);
return $values;
} | [
"protected",
"function",
"cleanPivotAttributes",
"(",
"InternallyMappable",
"$",
"entity",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"$",
"attributes",
"=",
"$",
"entity",
"->",
"getEntityAttributes",
"(",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// To get the pivots attributes we will just take any of the attributes which",
"// begin with \"pivot_\" and add those to this arrays, as well as unsetting",
"// them from the parent's models since they exist in a different table.",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'pivot_'",
")",
"===",
"0",
")",
"{",
"$",
"values",
"[",
"substr",
"(",
"$",
"key",
",",
"6",
")",
"]",
"=",
"$",
"value",
";",
"unset",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"// Rehydrate Entity with cleaned array.",
"$",
"entity",
"->",
"setEntityAttributes",
"(",
"$",
"attributes",
")",
";",
"return",
"$",
"values",
";",
"}"
] | Get the pivot attributes from a model.
@param InternallyMappable $entity
@return array | [
"Get",
"the",
"pivot",
"attributes",
"from",
"a",
"model",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L246-L267 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.getRelationCountQuery | public function getRelationCountQuery(Query $query, Query $parent)
{
if ($parent->getQuery()->from == $query->getQuery()->from) {
return $this->getRelationCountQueryForSelfJoin($query, $parent);
}
$this->setJoin($query);
return parent::getRelationCountQuery($query, $parent);
} | php | public function getRelationCountQuery(Query $query, Query $parent)
{
if ($parent->getQuery()->from == $query->getQuery()->from) {
return $this->getRelationCountQueryForSelfJoin($query, $parent);
}
$this->setJoin($query);
return parent::getRelationCountQuery($query, $parent);
} | [
"public",
"function",
"getRelationCountQuery",
"(",
"Query",
"$",
"query",
",",
"Query",
"$",
"parent",
")",
"{",
"if",
"(",
"$",
"parent",
"->",
"getQuery",
"(",
")",
"->",
"from",
"==",
"$",
"query",
"->",
"getQuery",
"(",
")",
"->",
"from",
")",
"{",
"return",
"$",
"this",
"->",
"getRelationCountQueryForSelfJoin",
"(",
"$",
"query",
",",
"$",
"parent",
")",
";",
"}",
"$",
"this",
"->",
"setJoin",
"(",
"$",
"query",
")",
";",
"return",
"parent",
"::",
"getRelationCountQuery",
"(",
"$",
"query",
",",
"$",
"parent",
")",
";",
"}"
] | Add the constraints for a relationship count query.
@param Query $query
@param Query $parent
@return Query | [
"Add",
"the",
"constraints",
"for",
"a",
"relationship",
"count",
"query",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L291-L300 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.getSelectColumns | protected function getSelectColumns(array $columns = ['*'])
{
if ($columns == ['*']) {
$columns = [$this->relatedMap->getTable().'.*'];
}
return array_merge($columns, $this->getAliasedPivotColumns());
} | php | protected function getSelectColumns(array $columns = ['*'])
{
if ($columns == ['*']) {
$columns = [$this->relatedMap->getTable().'.*'];
}
return array_merge($columns, $this->getAliasedPivotColumns());
} | [
"protected",
"function",
"getSelectColumns",
"(",
"array",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"if",
"(",
"$",
"columns",
"==",
"[",
"'*'",
"]",
")",
"{",
"$",
"columns",
"=",
"[",
"$",
"this",
"->",
"relatedMap",
"->",
"getTable",
"(",
")",
".",
"'.*'",
"]",
";",
"}",
"return",
"array_merge",
"(",
"$",
"columns",
",",
"$",
"this",
"->",
"getAliasedPivotColumns",
"(",
")",
")",
";",
"}"
] | Set the select clause for the relation query.
@param array $columns
@return \Analogue\ORM\Relationships\BelongsToMany | [
"Set",
"the",
"select",
"clause",
"for",
"the",
"relation",
"query",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L340-L347 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.setWhere | protected function setWhere()
{
$foreign = $this->getForeignKey();
$parentKey = $this->parentMap->getKeyName();
$this->query->where($foreign, '=', $this->parent->getEntityAttribute($parentKey));
return $this;
} | php | protected function setWhere()
{
$foreign = $this->getForeignKey();
$parentKey = $this->parentMap->getKeyName();
$this->query->where($foreign, '=', $this->parent->getEntityAttribute($parentKey));
return $this;
} | [
"protected",
"function",
"setWhere",
"(",
")",
"{",
"$",
"foreign",
"=",
"$",
"this",
"->",
"getForeignKey",
"(",
")",
";",
"$",
"parentKey",
"=",
"$",
"this",
"->",
"parentMap",
"->",
"getKeyName",
"(",
")",
";",
"$",
"this",
"->",
"query",
"->",
"where",
"(",
"$",
"foreign",
",",
"'='",
",",
"$",
"this",
"->",
"parent",
"->",
"getEntityAttribute",
"(",
"$",
"parentKey",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the where clause for the relation query.
@return $this | [
"Set",
"the",
"where",
"clause",
"for",
"the",
"relation",
"query",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L398-L407 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.addEagerConstraints | public function addEagerConstraints(array $results)
{
$this->query->whereIn($this->getForeignKey(), $this->getKeysFromResults($results));
} | php | public function addEagerConstraints(array $results)
{
$this->query->whereIn($this->getForeignKey(), $this->getKeysFromResults($results));
} | [
"public",
"function",
"addEagerConstraints",
"(",
"array",
"$",
"results",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"whereIn",
"(",
"$",
"this",
"->",
"getForeignKey",
"(",
")",
",",
"$",
"this",
"->",
"getKeysFromResults",
"(",
"$",
"results",
")",
")",
";",
"}"
] | Set the constraints for an eager load of the relation.
@param array $results
@return void | [
"Set",
"the",
"constraints",
"for",
"an",
"eager",
"load",
"of",
"the",
"relation",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L416-L419 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.match | public function match(array $results, $relation)
{
$entities = $this->getEager();
// TODO; optimize this operation
$dictionary = $this->buildDictionary($entities);
$keyName = $this->parentMap->getKeyName();
$cache = $this->parentMapper->getEntityCache();
$host = $this;
// Once we have an array dictionary of child objects we can easily match the
// children back to their parent using the dictionary and the keys on the
// the parent models. Then we will return the hydrated models back out.
return array_map(function ($result) use ($dictionary, $keyName, $cache, $relation, $host) {
$key = $result[$keyName];
if (isset($dictionary[$key])) {
$collection = $host->relatedMap->newCollection($dictionary[$key]);
$result[$relation] = $collection;
// TODO Refactor this
$cache->cacheLoadedRelationResult($key, $relation, $collection, $this);
} else {
$result[$relation] = $host->relatedMap->newCollection();
}
return $result;
}, $results);
} | php | public function match(array $results, $relation)
{
$entities = $this->getEager();
// TODO; optimize this operation
$dictionary = $this->buildDictionary($entities);
$keyName = $this->parentMap->getKeyName();
$cache = $this->parentMapper->getEntityCache();
$host = $this;
// Once we have an array dictionary of child objects we can easily match the
// children back to their parent using the dictionary and the keys on the
// the parent models. Then we will return the hydrated models back out.
return array_map(function ($result) use ($dictionary, $keyName, $cache, $relation, $host) {
$key = $result[$keyName];
if (isset($dictionary[$key])) {
$collection = $host->relatedMap->newCollection($dictionary[$key]);
$result[$relation] = $collection;
// TODO Refactor this
$cache->cacheLoadedRelationResult($key, $relation, $collection, $this);
} else {
$result[$relation] = $host->relatedMap->newCollection();
}
return $result;
}, $results);
} | [
"public",
"function",
"match",
"(",
"array",
"$",
"results",
",",
"$",
"relation",
")",
"{",
"$",
"entities",
"=",
"$",
"this",
"->",
"getEager",
"(",
")",
";",
"// TODO; optimize this operation",
"$",
"dictionary",
"=",
"$",
"this",
"->",
"buildDictionary",
"(",
"$",
"entities",
")",
";",
"$",
"keyName",
"=",
"$",
"this",
"->",
"parentMap",
"->",
"getKeyName",
"(",
")",
";",
"$",
"cache",
"=",
"$",
"this",
"->",
"parentMapper",
"->",
"getEntityCache",
"(",
")",
";",
"$",
"host",
"=",
"$",
"this",
";",
"// Once we have an array dictionary of child objects we can easily match the",
"// children back to their parent using the dictionary and the keys on the",
"// the parent models. Then we will return the hydrated models back out.",
"return",
"array_map",
"(",
"function",
"(",
"$",
"result",
")",
"use",
"(",
"$",
"dictionary",
",",
"$",
"keyName",
",",
"$",
"cache",
",",
"$",
"relation",
",",
"$",
"host",
")",
"{",
"$",
"key",
"=",
"$",
"result",
"[",
"$",
"keyName",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"dictionary",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"collection",
"=",
"$",
"host",
"->",
"relatedMap",
"->",
"newCollection",
"(",
"$",
"dictionary",
"[",
"$",
"key",
"]",
")",
";",
"$",
"result",
"[",
"$",
"relation",
"]",
"=",
"$",
"collection",
";",
"// TODO Refactor this",
"$",
"cache",
"->",
"cacheLoadedRelationResult",
"(",
"$",
"key",
",",
"$",
"relation",
",",
"$",
"collection",
",",
"$",
"this",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"relation",
"]",
"=",
"$",
"host",
"->",
"relatedMap",
"->",
"newCollection",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
",",
"$",
"results",
")",
";",
"}"
] | Match Eagerly loaded relation to result.
@param array $results
@param string $relation
@return array | [
"Match",
"Eagerly",
"loaded",
"relation",
"to",
"result",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L429-L461 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.buildDictionary | protected function buildDictionary(EntityCollection $results)
{
$foreign = $this->foreignKey;
// First we will build a dictionary of child models keyed by the foreign key
// of the relation so that we will easily and quickly match them to their
// parents without having a possibly slow inner loops for every models.
$dictionary = [];
foreach ($results as $entity) {
$wrapper = $this->factory->make($entity);
$foreignKey = $wrapper->getEntityAttribute('pivot')->$foreign;
$dictionary[$foreignKey][] = $entity;
}
return $dictionary;
} | php | protected function buildDictionary(EntityCollection $results)
{
$foreign = $this->foreignKey;
// First we will build a dictionary of child models keyed by the foreign key
// of the relation so that we will easily and quickly match them to their
// parents without having a possibly slow inner loops for every models.
$dictionary = [];
foreach ($results as $entity) {
$wrapper = $this->factory->make($entity);
$foreignKey = $wrapper->getEntityAttribute('pivot')->$foreign;
$dictionary[$foreignKey][] = $entity;
}
return $dictionary;
} | [
"protected",
"function",
"buildDictionary",
"(",
"EntityCollection",
"$",
"results",
")",
"{",
"$",
"foreign",
"=",
"$",
"this",
"->",
"foreignKey",
";",
"// First we will build a dictionary of child models keyed by the foreign key",
"// of the relation so that we will easily and quickly match them to their",
"// parents without having a possibly slow inner loops for every models.",
"$",
"dictionary",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"entity",
")",
"{",
"$",
"wrapper",
"=",
"$",
"this",
"->",
"factory",
"->",
"make",
"(",
"$",
"entity",
")",
";",
"$",
"foreignKey",
"=",
"$",
"wrapper",
"->",
"getEntityAttribute",
"(",
"'pivot'",
")",
"->",
"$",
"foreign",
";",
"$",
"dictionary",
"[",
"$",
"foreignKey",
"]",
"[",
"]",
"=",
"$",
"entity",
";",
"}",
"return",
"$",
"dictionary",
";",
"}"
] | Build model dictionary keyed by the relation's foreign key.
@param EntityCollection $results
@return array | [
"Build",
"model",
"dictionary",
"keyed",
"by",
"the",
"relation",
"s",
"foreign",
"key",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L470-L488 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.getRelatedIds | public function getRelatedIds()
{
$fullKey = $this->relatedMap->getQualifiedKeyName();
return $this->getQuery()->select($fullKey)->lists($this->relatedMap->getKeyName());
} | php | public function getRelatedIds()
{
$fullKey = $this->relatedMap->getQualifiedKeyName();
return $this->getQuery()->select($fullKey)->lists($this->relatedMap->getKeyName());
} | [
"public",
"function",
"getRelatedIds",
"(",
")",
"{",
"$",
"fullKey",
"=",
"$",
"this",
"->",
"relatedMap",
"->",
"getQualifiedKeyName",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getQuery",
"(",
")",
"->",
"select",
"(",
"$",
"fullKey",
")",
"->",
"lists",
"(",
"$",
"this",
"->",
"relatedMap",
"->",
"getKeyName",
"(",
")",
")",
";",
"}"
] | Get all of the IDs for the related models.
@return array | [
"Get",
"all",
"of",
"the",
"IDs",
"for",
"the",
"related",
"models",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L495-L500 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.updatePivot | public function updatePivot($entity)
{
$keyName = $this->relatedMap->getKeyName();
$this->updateExistingPivot(
$entity->getEntityAttribute($keyName),
$entity->getEntityAttribute('pivot')->getEntityAttributes()
);
} | php | public function updatePivot($entity)
{
$keyName = $this->relatedMap->getKeyName();
$this->updateExistingPivot(
$entity->getEntityAttribute($keyName),
$entity->getEntityAttribute('pivot')->getEntityAttributes()
);
} | [
"public",
"function",
"updatePivot",
"(",
"$",
"entity",
")",
"{",
"$",
"keyName",
"=",
"$",
"this",
"->",
"relatedMap",
"->",
"getKeyName",
"(",
")",
";",
"$",
"this",
"->",
"updateExistingPivot",
"(",
"$",
"entity",
"->",
"getEntityAttribute",
"(",
"$",
"keyName",
")",
",",
"$",
"entity",
"->",
"getEntityAttribute",
"(",
"'pivot'",
")",
"->",
"getEntityAttributes",
"(",
")",
")",
";",
"}"
] | Update Pivot.
@param \Analogue\ORM\Entity $entity
@return void | [
"Update",
"Pivot",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L509-L517 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.createPivots | public function createPivots($relatedEntities)
{
$keys = [];
$attributes = [];
$keyName = $this->relatedMap->getKeyName();
foreach ($relatedEntities as $entity) {
$keys[] = $entity->getEntityAttribute($keyName);
}
$records = $this->createAttachRecords($keys, $attributes);
$this->query->getQuery()->from($this->table)->insert($records);
} | php | public function createPivots($relatedEntities)
{
$keys = [];
$attributes = [];
$keyName = $this->relatedMap->getKeyName();
foreach ($relatedEntities as $entity) {
$keys[] = $entity->getEntityAttribute($keyName);
}
$records = $this->createAttachRecords($keys, $attributes);
$this->query->getQuery()->from($this->table)->insert($records);
} | [
"public",
"function",
"createPivots",
"(",
"$",
"relatedEntities",
")",
"{",
"$",
"keys",
"=",
"[",
"]",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"$",
"keyName",
"=",
"$",
"this",
"->",
"relatedMap",
"->",
"getKeyName",
"(",
")",
";",
"foreach",
"(",
"$",
"relatedEntities",
"as",
"$",
"entity",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"$",
"entity",
"->",
"getEntityAttribute",
"(",
"$",
"keyName",
")",
";",
"}",
"$",
"records",
"=",
"$",
"this",
"->",
"createAttachRecords",
"(",
"$",
"keys",
",",
"$",
"attributes",
")",
";",
"$",
"this",
"->",
"query",
"->",
"getQuery",
"(",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"table",
")",
"->",
"insert",
"(",
"$",
"records",
")",
";",
"}"
] | Create Pivot Records.
@param \Analogue\ORM\Entity[] $relatedEntities
@return void | [
"Create",
"Pivot",
"Records",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L540-L554 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.attach | public function attach($id, array $attributes = [])
{
$query = $this->newPivotStatement();
$query->insert($this->createAttachRecords((array) $id, $attributes));
} | php | public function attach($id, array $attributes = [])
{
$query = $this->newPivotStatement();
$query->insert($this->createAttachRecords((array) $id, $attributes));
} | [
"public",
"function",
"attach",
"(",
"$",
"id",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"newPivotStatement",
"(",
")",
";",
"$",
"query",
"->",
"insert",
"(",
"$",
"this",
"->",
"createAttachRecords",
"(",
"(",
"array",
")",
"$",
"id",
",",
"$",
"attributes",
")",
")",
";",
"}"
] | Attach a model to the parent.
@param mixed $id
@param array $attributes
@return void | [
"Attach",
"a",
"model",
"to",
"the",
"parent",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L583-L588 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.detachExcept | protected function detachExcept(array $entities = [])
{
$query = $this->newPivotQuery();
if (count($entities) > 0) {
$keys = $this->getKeys($entities);
$query->whereNotIn($this->otherKey, $keys);
}
$parentKey = $this->parentMap->getKeyName();
$query->where($this->foreignKey, '=', $this->parent->getEntityAttribute($parentKey));
$query->delete();
} | php | protected function detachExcept(array $entities = [])
{
$query = $this->newPivotQuery();
if (count($entities) > 0) {
$keys = $this->getKeys($entities);
$query->whereNotIn($this->otherKey, $keys);
}
$parentKey = $this->parentMap->getKeyName();
$query->where($this->foreignKey, '=', $this->parent->getEntityAttribute($parentKey));
$query->delete();
} | [
"protected",
"function",
"detachExcept",
"(",
"array",
"$",
"entities",
"=",
"[",
"]",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"newPivotQuery",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"entities",
")",
">",
"0",
")",
"{",
"$",
"keys",
"=",
"$",
"this",
"->",
"getKeys",
"(",
"$",
"entities",
")",
";",
"$",
"query",
"->",
"whereNotIn",
"(",
"$",
"this",
"->",
"otherKey",
",",
"$",
"keys",
")",
";",
"}",
"$",
"parentKey",
"=",
"$",
"this",
"->",
"parentMap",
"->",
"getKeyName",
"(",
")",
";",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"foreignKey",
",",
"'='",
",",
"$",
"this",
"->",
"parent",
"->",
"getEntityAttribute",
"(",
"$",
"parentKey",
")",
")",
";",
"$",
"query",
"->",
"delete",
"(",
")",
";",
"}"
] | Detach related entities that are not in $id.
@param array $entities
@throws \InvalidArgumentException
@return void | [
"Detach",
"related",
"entities",
"that",
"are",
"not",
"in",
"$id",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L609-L623 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.createAttachRecords | protected function createAttachRecords($ids, array $attributes)
{
$records = [];
$timed = in_array($this->createdAt(), $this->pivotColumns);
// To create the attachment records, we will simply spin through the IDs given
// and create a new record to insert for each ID. Each ID may actually be a
// key in the array, with extra attributes to be placed in other columns.
foreach ($ids as $key => $value) {
$records[] = $this->attacher($key, $value, $attributes, $timed);
}
return $records;
} | php | protected function createAttachRecords($ids, array $attributes)
{
$records = [];
$timed = in_array($this->createdAt(), $this->pivotColumns);
// To create the attachment records, we will simply spin through the IDs given
// and create a new record to insert for each ID. Each ID may actually be a
// key in the array, with extra attributes to be placed in other columns.
foreach ($ids as $key => $value) {
$records[] = $this->attacher($key, $value, $attributes, $timed);
}
return $records;
} | [
"protected",
"function",
"createAttachRecords",
"(",
"$",
"ids",
",",
"array",
"$",
"attributes",
")",
"{",
"$",
"records",
"=",
"[",
"]",
";",
"$",
"timed",
"=",
"in_array",
"(",
"$",
"this",
"->",
"createdAt",
"(",
")",
",",
"$",
"this",
"->",
"pivotColumns",
")",
";",
"// To create the attachment records, we will simply spin through the IDs given",
"// and create a new record to insert for each ID. Each ID may actually be a",
"// key in the array, with extra attributes to be placed in other columns.",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"records",
"[",
"]",
"=",
"$",
"this",
"->",
"attacher",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"attributes",
",",
"$",
"timed",
")",
";",
"}",
"return",
"$",
"records",
";",
"}"
] | Create an array of records to insert into the pivot table.
@param array $ids
@param array $attributes
@return array | [
"Create",
"an",
"array",
"of",
"records",
"to",
"insert",
"into",
"the",
"pivot",
"table",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L633-L647 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.attacher | protected function attacher($key, $value, $attributes, $timed)
{
list($id, $extra) = $this->getAttachId($key, $value, $attributes);
// To create the attachment records, we will simply spin through the IDs given
// and create a new record to insert for each ID. Each ID may actually be a
// key in the array, with extra attributes to be placed in other columns.
$record = $this->createAttachRecord($id, $timed);
return array_merge($record, $extra);
} | php | protected function attacher($key, $value, $attributes, $timed)
{
list($id, $extra) = $this->getAttachId($key, $value, $attributes);
// To create the attachment records, we will simply spin through the IDs given
// and create a new record to insert for each ID. Each ID may actually be a
// key in the array, with extra attributes to be placed in other columns.
$record = $this->createAttachRecord($id, $timed);
return array_merge($record, $extra);
} | [
"protected",
"function",
"attacher",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"attributes",
",",
"$",
"timed",
")",
"{",
"list",
"(",
"$",
"id",
",",
"$",
"extra",
")",
"=",
"$",
"this",
"->",
"getAttachId",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"attributes",
")",
";",
"// To create the attachment records, we will simply spin through the IDs given",
"// and create a new record to insert for each ID. Each ID may actually be a",
"// key in the array, with extra attributes to be placed in other columns.",
"$",
"record",
"=",
"$",
"this",
"->",
"createAttachRecord",
"(",
"$",
"id",
",",
"$",
"timed",
")",
";",
"return",
"array_merge",
"(",
"$",
"record",
",",
"$",
"extra",
")",
";",
"}"
] | Create a full attachment record payload.
@param int $key
@param mixed $value
@param array $attributes
@param bool $timed
@return array | [
"Create",
"a",
"full",
"attachment",
"record",
"payload",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L659-L669 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.createAttachRecord | protected function createAttachRecord($id, $timed)
{
$parentKey = $this->parentMap->getKeyName();
$record = [];
$record[$this->foreignKey] = $this->parent->getEntityAttribute($parentKey);
$record[$this->otherKey] = $id;
// If the record needs to have creation and update timestamps, we will make
// them by calling the parent model's "freshTimestamp" method which will
// provide us with a fresh timestamp in this model's preferred format.
if ($timed) {
$record = $this->setTimestampsOnAttach($record);
}
return $record;
} | php | protected function createAttachRecord($id, $timed)
{
$parentKey = $this->parentMap->getKeyName();
$record = [];
$record[$this->foreignKey] = $this->parent->getEntityAttribute($parentKey);
$record[$this->otherKey] = $id;
// If the record needs to have creation and update timestamps, we will make
// them by calling the parent model's "freshTimestamp" method which will
// provide us with a fresh timestamp in this model's preferred format.
if ($timed) {
$record = $this->setTimestampsOnAttach($record);
}
return $record;
} | [
"protected",
"function",
"createAttachRecord",
"(",
"$",
"id",
",",
"$",
"timed",
")",
"{",
"$",
"parentKey",
"=",
"$",
"this",
"->",
"parentMap",
"->",
"getKeyName",
"(",
")",
";",
"$",
"record",
"=",
"[",
"]",
";",
"$",
"record",
"[",
"$",
"this",
"->",
"foreignKey",
"]",
"=",
"$",
"this",
"->",
"parent",
"->",
"getEntityAttribute",
"(",
"$",
"parentKey",
")",
";",
"$",
"record",
"[",
"$",
"this",
"->",
"otherKey",
"]",
"=",
"$",
"id",
";",
"// If the record needs to have creation and update timestamps, we will make",
"// them by calling the parent model's \"freshTimestamp\" method which will",
"// provide us with a fresh timestamp in this model's preferred format.",
"if",
"(",
"$",
"timed",
")",
"{",
"$",
"record",
"=",
"$",
"this",
"->",
"setTimestampsOnAttach",
"(",
"$",
"record",
")",
";",
"}",
"return",
"$",
"record",
";",
"}"
] | Create a new pivot attachment record.
@param int $id
@param bool $timed
@return array | [
"Create",
"a",
"new",
"pivot",
"attachment",
"record",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L697-L715 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.getModelKeysFromCollection | protected function getModelKeysFromCollection(EntityCollection $entities)
{
$keyName = $this->relatedMap->getKeyName();
return array_map(function ($m) use ($keyName) {
return $m->$keyName;
}, $entities);
} | php | protected function getModelKeysFromCollection(EntityCollection $entities)
{
$keyName = $this->relatedMap->getKeyName();
return array_map(function ($m) use ($keyName) {
return $m->$keyName;
}, $entities);
} | [
"protected",
"function",
"getModelKeysFromCollection",
"(",
"EntityCollection",
"$",
"entities",
")",
"{",
"$",
"keyName",
"=",
"$",
"this",
"->",
"relatedMap",
"->",
"getKeyName",
"(",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"m",
")",
"use",
"(",
"$",
"keyName",
")",
"{",
"return",
"$",
"m",
"->",
"$",
"keyName",
";",
"}",
",",
"$",
"entities",
")",
";",
"}"
] | @param EntityCollection $entities
@return array | [
"@param",
"EntityCollection",
"$entities"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L743-L750 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.detach | public function detach($ids = [])
{
if ($ids instanceof EntityCollection) {
$ids = (array) $ids->modelKeys();
}
$query = $this->newPivotQuery();
// If associated IDs were passed to the method we will only delete those
// associations, otherwise all of the association ties will be broken.
// We'll return the numbers of affected rows when we do the deletes.
$ids = (array) $ids;
if (count($ids) > 0) {
$query->whereIn($this->otherKey, (array) $ids);
}
// Once we have all of the conditions set on the statement, we are ready
// to run the delete on the pivot table. Then, if the touch parameter
// is true, we will go ahead and touch all related models to sync.
return $query->delete();
} | php | public function detach($ids = [])
{
if ($ids instanceof EntityCollection) {
$ids = (array) $ids->modelKeys();
}
$query = $this->newPivotQuery();
// If associated IDs were passed to the method we will only delete those
// associations, otherwise all of the association ties will be broken.
// We'll return the numbers of affected rows when we do the deletes.
$ids = (array) $ids;
if (count($ids) > 0) {
$query->whereIn($this->otherKey, (array) $ids);
}
// Once we have all of the conditions set on the statement, we are ready
// to run the delete on the pivot table. Then, if the touch parameter
// is true, we will go ahead and touch all related models to sync.
return $query->delete();
} | [
"public",
"function",
"detach",
"(",
"$",
"ids",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"ids",
"instanceof",
"EntityCollection",
")",
"{",
"$",
"ids",
"=",
"(",
"array",
")",
"$",
"ids",
"->",
"modelKeys",
"(",
")",
";",
"}",
"$",
"query",
"=",
"$",
"this",
"->",
"newPivotQuery",
"(",
")",
";",
"// If associated IDs were passed to the method we will only delete those",
"// associations, otherwise all of the association ties will be broken.",
"// We'll return the numbers of affected rows when we do the deletes.",
"$",
"ids",
"=",
"(",
"array",
")",
"$",
"ids",
";",
"if",
"(",
"count",
"(",
"$",
"ids",
")",
">",
"0",
")",
"{",
"$",
"query",
"->",
"whereIn",
"(",
"$",
"this",
"->",
"otherKey",
",",
"(",
"array",
")",
"$",
"ids",
")",
";",
"}",
"// Once we have all of the conditions set on the statement, we are ready",
"// to run the delete on the pivot table. Then, if the touch parameter",
"// is true, we will go ahead and touch all related models to sync.",
"return",
"$",
"query",
"->",
"delete",
"(",
")",
";",
"}"
] | Detach models from the relationship.
@param int|array $ids
@throws \InvalidArgumentException
@return int | [
"Detach",
"models",
"from",
"the",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L761-L782 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.newPivotQuery | protected function newPivotQuery()
{
$query = $this->newPivotStatement();
$parentKey = $this->parentMap->getKeyName();
return $query->where($this->foreignKey, $this->parent->getEntityAttribute($parentKey));
} | php | protected function newPivotQuery()
{
$query = $this->newPivotStatement();
$parentKey = $this->parentMap->getKeyName();
return $query->where($this->foreignKey, $this->parent->getEntityAttribute($parentKey));
} | [
"protected",
"function",
"newPivotQuery",
"(",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"newPivotStatement",
"(",
")",
";",
"$",
"parentKey",
"=",
"$",
"this",
"->",
"parentMap",
"->",
"getKeyName",
"(",
")",
";",
"return",
"$",
"query",
"->",
"where",
"(",
"$",
"this",
"->",
"foreignKey",
",",
"$",
"this",
"->",
"parent",
"->",
"getEntityAttribute",
"(",
"$",
"parentKey",
")",
")",
";",
"}"
] | Create a new query builder for the pivot table.
@throws \InvalidArgumentException
@return \Illuminate\Database\Query\Builder | [
"Create",
"a",
"new",
"query",
"builder",
"for",
"the",
"pivot",
"table",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L791-L798 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.newPivotStatementForId | public function newPivotStatementForId($id)
{
$pivot = $this->newPivotStatement();
$parentKeyName = $this->parentMap->getKeyName();
$key = $this->parent->getEntityAttribute($parentKeyName);
return $pivot->where($this->foreignKey, $key)->where($this->otherKey, $id);
} | php | public function newPivotStatementForId($id)
{
$pivot = $this->newPivotStatement();
$parentKeyName = $this->parentMap->getKeyName();
$key = $this->parent->getEntityAttribute($parentKeyName);
return $pivot->where($this->foreignKey, $key)->where($this->otherKey, $id);
} | [
"public",
"function",
"newPivotStatementForId",
"(",
"$",
"id",
")",
"{",
"$",
"pivot",
"=",
"$",
"this",
"->",
"newPivotStatement",
"(",
")",
";",
"$",
"parentKeyName",
"=",
"$",
"this",
"->",
"parentMap",
"->",
"getKeyName",
"(",
")",
";",
"$",
"key",
"=",
"$",
"this",
"->",
"parent",
"->",
"getEntityAttribute",
"(",
"$",
"parentKeyName",
")",
";",
"return",
"$",
"pivot",
"->",
"where",
"(",
"$",
"this",
"->",
"foreignKey",
",",
"$",
"key",
")",
"->",
"where",
"(",
"$",
"this",
"->",
"otherKey",
",",
"$",
"id",
")",
";",
"}"
] | Get a new pivot statement for a given "other" ID.
@param mixed $id
@throws \InvalidArgumentException
@return \Illuminate\Database\Query\Builder | [
"Get",
"a",
"new",
"pivot",
"statement",
"for",
"a",
"given",
"other",
"ID",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L819-L828 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.newPivot | public function newPivot(array $attributes = [], $exists = false)
{
$pivot = new Pivot($this->parent, $this->parentMap, $attributes, $this->table, $exists);
return $pivot->setPivotKeys($this->foreignKey, $this->otherKey);
} | php | public function newPivot(array $attributes = [], $exists = false)
{
$pivot = new Pivot($this->parent, $this->parentMap, $attributes, $this->table, $exists);
return $pivot->setPivotKeys($this->foreignKey, $this->otherKey);
} | [
"public",
"function",
"newPivot",
"(",
"array",
"$",
"attributes",
"=",
"[",
"]",
",",
"$",
"exists",
"=",
"false",
")",
"{",
"$",
"pivot",
"=",
"new",
"Pivot",
"(",
"$",
"this",
"->",
"parent",
",",
"$",
"this",
"->",
"parentMap",
",",
"$",
"attributes",
",",
"$",
"this",
"->",
"table",
",",
"$",
"exists",
")",
";",
"return",
"$",
"pivot",
"->",
"setPivotKeys",
"(",
"$",
"this",
"->",
"foreignKey",
",",
"$",
"this",
"->",
"otherKey",
")",
";",
"}"
] | Create a new pivot model instance.
@param array $attributes
@param bool $exists
@return \Analogue\ORM\Relationships\Pivot | [
"Create",
"a",
"new",
"pivot",
"model",
"instance",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L838-L843 |
analogueorm/analogue | src/Relationships/BelongsToMany.php | BelongsToMany.withTimestamps | public function withTimestamps($createdAt = null, $updatedAt = null)
{
return $this->withPivot($createdAt ?: $this->createdAt(), $updatedAt ?: $this->updatedAt());
} | php | public function withTimestamps($createdAt = null, $updatedAt = null)
{
return $this->withPivot($createdAt ?: $this->createdAt(), $updatedAt ?: $this->updatedAt());
} | [
"public",
"function",
"withTimestamps",
"(",
"$",
"createdAt",
"=",
"null",
",",
"$",
"updatedAt",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"withPivot",
"(",
"$",
"createdAt",
"?",
":",
"$",
"this",
"->",
"createdAt",
"(",
")",
",",
"$",
"updatedAt",
"?",
":",
"$",
"this",
"->",
"updatedAt",
"(",
")",
")",
";",
"}"
] | Specify that the pivot table has creation and update timestamps.
@param mixed $createdAt
@param mixed $updatedAt
@return \Analogue\ORM\Relationships\BelongsToMany | [
"Specify",
"that",
"the",
"pivot",
"table",
"has",
"creation",
"and",
"update",
"timestamps",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsToMany.php#L881-L884 |
analogueorm/analogue | src/Relationships/EmbedsOne.php | EmbedsOne.matchSingleResult | public function matchSingleResult(array $attributes) : array
{
return $this->asArray ? $this->matchAsArray($attributes) : $this->matchAsAttributes($attributes);
} | php | public function matchSingleResult(array $attributes) : array
{
return $this->asArray ? $this->matchAsArray($attributes) : $this->matchAsAttributes($attributes);
} | [
"public",
"function",
"matchSingleResult",
"(",
"array",
"$",
"attributes",
")",
":",
"array",
"{",
"return",
"$",
"this",
"->",
"asArray",
"?",
"$",
"this",
"->",
"matchAsArray",
"(",
"$",
"attributes",
")",
":",
"$",
"this",
"->",
"matchAsAttributes",
"(",
"$",
"attributes",
")",
";",
"}"
] | Match a single database row's attributes to a single
object, and return the updated attributes.
@param array $attributes
@return array | [
"Match",
"a",
"single",
"database",
"row",
"s",
"attributes",
"to",
"a",
"single",
"object",
"and",
"return",
"the",
"updated",
"attributes",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbedsOne.php#L37-L40 |
analogueorm/analogue | src/Relationships/EmbedsOne.php | EmbedsOne.matchAsArray | protected function matchAsArray(array $attributes) : array
{
// Extract the attributes with the key of the relation,
// which should be an array.
$key = $this->relation;
if (!array_key_exists($key, $attributes) && !is_array($key)) {
throw new MappingException("'$key' column should be an array");
}
if ($this->asJson) {
$attributes[$key] = json_decode($attributes[$key], true);
}
$attributes[$key] = $this->buildEmbeddedObject($attributes[$key]);
return $attributes;
} | php | protected function matchAsArray(array $attributes) : array
{
// Extract the attributes with the key of the relation,
// which should be an array.
$key = $this->relation;
if (!array_key_exists($key, $attributes) && !is_array($key)) {
throw new MappingException("'$key' column should be an array");
}
if ($this->asJson) {
$attributes[$key] = json_decode($attributes[$key], true);
}
$attributes[$key] = $this->buildEmbeddedObject($attributes[$key]);
return $attributes;
} | [
"protected",
"function",
"matchAsArray",
"(",
"array",
"$",
"attributes",
")",
":",
"array",
"{",
"// Extract the attributes with the key of the relation,",
"// which should be an array.",
"$",
"key",
"=",
"$",
"this",
"->",
"relation",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"attributes",
")",
"&&",
"!",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"MappingException",
"(",
"\"'$key' column should be an array\"",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"asJson",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"json_decode",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
",",
"true",
")",
";",
"}",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"buildEmbeddedObject",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
")",
";",
"return",
"$",
"attributes",
";",
"}"
] | Match array attribute from parent to an embedded object,
and return the updated attributes.
@param array $attributes
@throws MappingException
@return array | [
"Match",
"array",
"attribute",
"from",
"parent",
"to",
"an",
"embedded",
"object",
"and",
"return",
"the",
"updated",
"attributes",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbedsOne.php#L52-L69 |
analogueorm/analogue | src/Relationships/EmbedsOne.php | EmbedsOne.matchAsAttributes | protected function matchAsAttributes(array $attributes) : array
{
$attributesMap = $this->getAttributesDictionnary();
// Get the subset that only the embedded object is concerned with and, convert it back
// to embedded object attributes keys
$originalAttributes = array_only($attributes, $attributesMap);
$embeddedAttributes = [];
foreach ($originalAttributes as $key => $value) {
$embeddedKey = array_search($key, $attributesMap);
$embeddedAttributes[$embeddedKey] = $value;
}
// Unset original attributes before, just in case one of the keys of the
// original attributes is equals the relation name.
foreach (array_keys($originalAttributes) as $key) {
unset($attributes[$key]);
}
// Build object
$attributes[$this->relation] = $this->buildEmbeddedObject($embeddedAttributes);
return $attributes;
} | php | protected function matchAsAttributes(array $attributes) : array
{
$attributesMap = $this->getAttributesDictionnary();
// Get the subset that only the embedded object is concerned with and, convert it back
// to embedded object attributes keys
$originalAttributes = array_only($attributes, $attributesMap);
$embeddedAttributes = [];
foreach ($originalAttributes as $key => $value) {
$embeddedKey = array_search($key, $attributesMap);
$embeddedAttributes[$embeddedKey] = $value;
}
// Unset original attributes before, just in case one of the keys of the
// original attributes is equals the relation name.
foreach (array_keys($originalAttributes) as $key) {
unset($attributes[$key]);
}
// Build object
$attributes[$this->relation] = $this->buildEmbeddedObject($embeddedAttributes);
return $attributes;
} | [
"protected",
"function",
"matchAsAttributes",
"(",
"array",
"$",
"attributes",
")",
":",
"array",
"{",
"$",
"attributesMap",
"=",
"$",
"this",
"->",
"getAttributesDictionnary",
"(",
")",
";",
"// Get the subset that only the embedded object is concerned with and, convert it back",
"// to embedded object attributes keys",
"$",
"originalAttributes",
"=",
"array_only",
"(",
"$",
"attributes",
",",
"$",
"attributesMap",
")",
";",
"$",
"embeddedAttributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"originalAttributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"embeddedKey",
"=",
"array_search",
"(",
"$",
"key",
",",
"$",
"attributesMap",
")",
";",
"$",
"embeddedAttributes",
"[",
"$",
"embeddedKey",
"]",
"=",
"$",
"value",
";",
"}",
"// Unset original attributes before, just in case one of the keys of the",
"// original attributes is equals the relation name.",
"foreach",
"(",
"array_keys",
"(",
"$",
"originalAttributes",
")",
"as",
"$",
"key",
")",
"{",
"unset",
"(",
"$",
"attributes",
"[",
"$",
"key",
"]",
")",
";",
"}",
"// Build object",
"$",
"attributes",
"[",
"$",
"this",
"->",
"relation",
"]",
"=",
"$",
"this",
"->",
"buildEmbeddedObject",
"(",
"$",
"embeddedAttributes",
")",
";",
"return",
"$",
"attributes",
";",
"}"
] | Transform attributes from the parent entity result into
an embedded object, and return the updated attributes.
@param array $attributes
@return array | [
"Transform",
"attributes",
"from",
"the",
"parent",
"entity",
"result",
"into",
"an",
"embedded",
"object",
"and",
"return",
"the",
"updated",
"attributes",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbedsOne.php#L79-L104 |
analogueorm/analogue | src/Relationships/EmbedsOne.php | EmbedsOne.getAttributesDictionnary | protected function getAttributesDictionnary() : array
{
// Get attributes that belongs to the embedded object
$embeddedAttributeKeys = $this->getEmbeddedObjectAttributes();
$attributesMap = [];
// Build a dictionary for corresponding object attributes => parent attributes
foreach ($embeddedAttributeKeys as $key) {
$attributesMap[$key] = $this->getParentAttributeKey($key);
}
return $attributesMap;
} | php | protected function getAttributesDictionnary() : array
{
// Get attributes that belongs to the embedded object
$embeddedAttributeKeys = $this->getEmbeddedObjectAttributes();
$attributesMap = [];
// Build a dictionary for corresponding object attributes => parent attributes
foreach ($embeddedAttributeKeys as $key) {
$attributesMap[$key] = $this->getParentAttributeKey($key);
}
return $attributesMap;
} | [
"protected",
"function",
"getAttributesDictionnary",
"(",
")",
":",
"array",
"{",
"// Get attributes that belongs to the embedded object",
"$",
"embeddedAttributeKeys",
"=",
"$",
"this",
"->",
"getEmbeddedObjectAttributes",
"(",
")",
";",
"$",
"attributesMap",
"=",
"[",
"]",
";",
"// Build a dictionary for corresponding object attributes => parent attributes",
"foreach",
"(",
"$",
"embeddedAttributeKeys",
"as",
"$",
"key",
")",
"{",
"$",
"attributesMap",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getParentAttributeKey",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"attributesMap",
";",
"}"
] | Return a dictionary of attributes key on parent Entity.
@return array | [
"Return",
"a",
"dictionary",
"of",
"attributes",
"key",
"on",
"parent",
"Entity",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbedsOne.php#L111-L124 |
analogueorm/analogue | src/Relationships/EmbedsOne.php | EmbedsOne.normalize | public function normalize($object) : array
{
return $this->asArray ? $this->normalizeAsArray($object) : $this->normalizeAsAttributes($object);
} | php | public function normalize($object) : array
{
return $this->asArray ? $this->normalizeAsArray($object) : $this->normalizeAsAttributes($object);
} | [
"public",
"function",
"normalize",
"(",
"$",
"object",
")",
":",
"array",
"{",
"return",
"$",
"this",
"->",
"asArray",
"?",
"$",
"this",
"->",
"normalizeAsArray",
"(",
"$",
"object",
")",
":",
"$",
"this",
"->",
"normalizeAsAttributes",
"(",
"$",
"object",
")",
";",
"}"
] | Transform embedded object into DB column(s).
@param mixed $object
@return array $columns | [
"Transform",
"embedded",
"object",
"into",
"DB",
"column",
"(",
"s",
")",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbedsOne.php#L133-L136 |
analogueorm/analogue | src/Relationships/EmbedsOne.php | EmbedsOne.normalizeAsArray | protected function normalizeAsArray($object) : array
{
$wrapper = $this->factory->make($object);
$value = $wrapper->getEntityAttributes();
if ($this->asJson) {
$value = json_encode($value);
}
return [$this->relation => $value];
} | php | protected function normalizeAsArray($object) : array
{
$wrapper = $this->factory->make($object);
$value = $wrapper->getEntityAttributes();
if ($this->asJson) {
$value = json_encode($value);
}
return [$this->relation => $value];
} | [
"protected",
"function",
"normalizeAsArray",
"(",
"$",
"object",
")",
":",
"array",
"{",
"$",
"wrapper",
"=",
"$",
"this",
"->",
"factory",
"->",
"make",
"(",
"$",
"object",
")",
";",
"$",
"value",
"=",
"$",
"wrapper",
"->",
"getEntityAttributes",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"asJson",
")",
"{",
"$",
"value",
"=",
"json_encode",
"(",
"$",
"value",
")",
";",
"}",
"return",
"[",
"$",
"this",
"->",
"relation",
"=>",
"$",
"value",
"]",
";",
"}"
] | Normalize object an array containing raw attributes.
@param mixed $object
@return array | [
"Normalize",
"object",
"an",
"array",
"containing",
"raw",
"attributes",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbedsOne.php#L145-L156 |
analogueorm/analogue | src/Relationships/EmbedsOne.php | EmbedsOne.normalizeAsAttributes | protected function normalizeAsAttributes($object) : array
{
if (is_null($object)) {
return $this->nullObjectAttributes();
}
$attributesMap = $this->getAttributesDictionnary();
$wrapper = $this->factory->make($object);
$normalizedAttributes = [];
foreach ($attributesMap as $embedKey => $parentKey) {
$normalizedAttributes[$parentKey] = $wrapper->getEntityAttribute($embedKey);
}
return $normalizedAttributes;
} | php | protected function normalizeAsAttributes($object) : array
{
if (is_null($object)) {
return $this->nullObjectAttributes();
}
$attributesMap = $this->getAttributesDictionnary();
$wrapper = $this->factory->make($object);
$normalizedAttributes = [];
foreach ($attributesMap as $embedKey => $parentKey) {
$normalizedAttributes[$parentKey] = $wrapper->getEntityAttribute($embedKey);
}
return $normalizedAttributes;
} | [
"protected",
"function",
"normalizeAsAttributes",
"(",
"$",
"object",
")",
":",
"array",
"{",
"if",
"(",
"is_null",
"(",
"$",
"object",
")",
")",
"{",
"return",
"$",
"this",
"->",
"nullObjectAttributes",
"(",
")",
";",
"}",
"$",
"attributesMap",
"=",
"$",
"this",
"->",
"getAttributesDictionnary",
"(",
")",
";",
"$",
"wrapper",
"=",
"$",
"this",
"->",
"factory",
"->",
"make",
"(",
"$",
"object",
")",
";",
"$",
"normalizedAttributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"attributesMap",
"as",
"$",
"embedKey",
"=>",
"$",
"parentKey",
")",
"{",
"$",
"normalizedAttributes",
"[",
"$",
"parentKey",
"]",
"=",
"$",
"wrapper",
"->",
"getEntityAttribute",
"(",
"$",
"embedKey",
")",
";",
"}",
"return",
"$",
"normalizedAttributes",
";",
"}"
] | Normalize object as parent's attributes.
@param mixed $object
@return array | [
"Normalize",
"object",
"as",
"parent",
"s",
"attributes",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbedsOne.php#L165-L182 |
analogueorm/analogue | src/Relationships/EmbedsOne.php | EmbedsOne.nullObjectAttributes | protected function nullObjectAttributes() : array
{
$attributesMap = $this->getAttributesDictionnary();
$normalizedAttributes = [];
foreach ($attributesMap as $embedKey => $parentKey) {
$normalizedAttributes[$parentKey] = null;
}
return $normalizedAttributes;
} | php | protected function nullObjectAttributes() : array
{
$attributesMap = $this->getAttributesDictionnary();
$normalizedAttributes = [];
foreach ($attributesMap as $embedKey => $parentKey) {
$normalizedAttributes[$parentKey] = null;
}
return $normalizedAttributes;
} | [
"protected",
"function",
"nullObjectAttributes",
"(",
")",
":",
"array",
"{",
"$",
"attributesMap",
"=",
"$",
"this",
"->",
"getAttributesDictionnary",
"(",
")",
";",
"$",
"normalizedAttributes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"attributesMap",
"as",
"$",
"embedKey",
"=>",
"$",
"parentKey",
")",
"{",
"$",
"normalizedAttributes",
"[",
"$",
"parentKey",
"]",
"=",
"null",
";",
"}",
"return",
"$",
"normalizedAttributes",
";",
"}"
] | Set all object attributes to null.
@return array | [
"Set",
"all",
"object",
"attributes",
"to",
"null",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbedsOne.php#L189-L200 |
analogueorm/analogue | src/Commands/Store.php | Store.execute | public function execute()
{
$entity = $this->aggregate->getEntityObject();
$wrappedEntity = $this->aggregate->getWrappedEntity();
$mapper = $this->aggregate->getMapper();
if ($mapper->fireEvent('storing', $wrappedEntity) === false) {
return false;
}
$this->preStoreProcess();
/*
* We will test the entity for existence
* and run a creation if it doesn't exists
*/
if (!$this->aggregate->exists()) {
if ($mapper->fireEvent('creating', $wrappedEntity) === false) {
return false;
}
$this->insert();
$mapper->fireEvent('created', $wrappedEntity, false);
} elseif ($this->aggregate->isDirty()) {
if ($mapper->fireEvent('updating', $wrappedEntity) === false) {
return false;
}
$this->update();
$mapper->fireEvent('updated', $wrappedEntity, false);
}
$this->postStoreProcess();
$mapper->fireEvent('stored', $wrappedEntity, false);
// Once the object is stored, add it to the Instance cache
$key = $this->aggregate->getEntityKeyValue();
if (!$mapper->getInstanceCache()->has($key)) {
$mapper->getInstanceCache()->add($entity, $key);
}
$this->syncForeignKeyAttributes();
$wrappedEntity->unwrap();
return $entity;
} | php | public function execute()
{
$entity = $this->aggregate->getEntityObject();
$wrappedEntity = $this->aggregate->getWrappedEntity();
$mapper = $this->aggregate->getMapper();
if ($mapper->fireEvent('storing', $wrappedEntity) === false) {
return false;
}
$this->preStoreProcess();
/*
* We will test the entity for existence
* and run a creation if it doesn't exists
*/
if (!$this->aggregate->exists()) {
if ($mapper->fireEvent('creating', $wrappedEntity) === false) {
return false;
}
$this->insert();
$mapper->fireEvent('created', $wrappedEntity, false);
} elseif ($this->aggregate->isDirty()) {
if ($mapper->fireEvent('updating', $wrappedEntity) === false) {
return false;
}
$this->update();
$mapper->fireEvent('updated', $wrappedEntity, false);
}
$this->postStoreProcess();
$mapper->fireEvent('stored', $wrappedEntity, false);
// Once the object is stored, add it to the Instance cache
$key = $this->aggregate->getEntityKeyValue();
if (!$mapper->getInstanceCache()->has($key)) {
$mapper->getInstanceCache()->add($entity, $key);
}
$this->syncForeignKeyAttributes();
$wrappedEntity->unwrap();
return $entity;
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"aggregate",
"->",
"getEntityObject",
"(",
")",
";",
"$",
"wrappedEntity",
"=",
"$",
"this",
"->",
"aggregate",
"->",
"getWrappedEntity",
"(",
")",
";",
"$",
"mapper",
"=",
"$",
"this",
"->",
"aggregate",
"->",
"getMapper",
"(",
")",
";",
"if",
"(",
"$",
"mapper",
"->",
"fireEvent",
"(",
"'storing'",
",",
"$",
"wrappedEntity",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"preStoreProcess",
"(",
")",
";",
"/*\n * We will test the entity for existence\n * and run a creation if it doesn't exists\n */",
"if",
"(",
"!",
"$",
"this",
"->",
"aggregate",
"->",
"exists",
"(",
")",
")",
"{",
"if",
"(",
"$",
"mapper",
"->",
"fireEvent",
"(",
"'creating'",
",",
"$",
"wrappedEntity",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"insert",
"(",
")",
";",
"$",
"mapper",
"->",
"fireEvent",
"(",
"'created'",
",",
"$",
"wrappedEntity",
",",
"false",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"aggregate",
"->",
"isDirty",
"(",
")",
")",
"{",
"if",
"(",
"$",
"mapper",
"->",
"fireEvent",
"(",
"'updating'",
",",
"$",
"wrappedEntity",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"update",
"(",
")",
";",
"$",
"mapper",
"->",
"fireEvent",
"(",
"'updated'",
",",
"$",
"wrappedEntity",
",",
"false",
")",
";",
"}",
"$",
"this",
"->",
"postStoreProcess",
"(",
")",
";",
"$",
"mapper",
"->",
"fireEvent",
"(",
"'stored'",
",",
"$",
"wrappedEntity",
",",
"false",
")",
";",
"// Once the object is stored, add it to the Instance cache",
"$",
"key",
"=",
"$",
"this",
"->",
"aggregate",
"->",
"getEntityKeyValue",
"(",
")",
";",
"if",
"(",
"!",
"$",
"mapper",
"->",
"getInstanceCache",
"(",
")",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"$",
"mapper",
"->",
"getInstanceCache",
"(",
")",
"->",
"add",
"(",
"$",
"entity",
",",
"$",
"key",
")",
";",
"}",
"$",
"this",
"->",
"syncForeignKeyAttributes",
"(",
")",
";",
"$",
"wrappedEntity",
"->",
"unwrap",
"(",
")",
";",
"return",
"$",
"entity",
";",
"}"
] | Persist the entity in the database.
@throws \InvalidArgumentException
@return false|mixed | [
"Persist",
"the",
"entity",
"in",
"the",
"database",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Commands/Store.php#L20-L69 |
analogueorm/analogue | src/Commands/Store.php | Store.preStoreProcess | protected function preStoreProcess()
{
// Create any related object that doesn't exist in the database.
$localRelationships = $this->aggregate->getEntityMap()->getLocalRelationships();
$this->createRelatedEntities($localRelationships);
// Now we can sync the related collections
$this->aggregate->syncRelationships($localRelationships);
} | php | protected function preStoreProcess()
{
// Create any related object that doesn't exist in the database.
$localRelationships = $this->aggregate->getEntityMap()->getLocalRelationships();
$this->createRelatedEntities($localRelationships);
// Now we can sync the related collections
$this->aggregate->syncRelationships($localRelationships);
} | [
"protected",
"function",
"preStoreProcess",
"(",
")",
"{",
"// Create any related object that doesn't exist in the database.",
"$",
"localRelationships",
"=",
"$",
"this",
"->",
"aggregate",
"->",
"getEntityMap",
"(",
")",
"->",
"getLocalRelationships",
"(",
")",
";",
"$",
"this",
"->",
"createRelatedEntities",
"(",
"$",
"localRelationships",
")",
";",
"// Now we can sync the related collections",
"$",
"this",
"->",
"aggregate",
"->",
"syncRelationships",
"(",
"$",
"localRelationships",
")",
";",
"}"
] | Run all operations that have to occur before actually
storing the entity.
@throws \InvalidArgumentException
@return void | [
"Run",
"all",
"operations",
"that",
"have",
"to",
"occur",
"before",
"actually",
"storing",
"the",
"entity",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Commands/Store.php#L79-L88 |
analogueorm/analogue | src/Commands/Store.php | Store.createRelatedEntities | protected function createRelatedEntities($relations)
{
$entitiesToCreate = $this->aggregate->getNonExistingRelated($relations);
foreach ($entitiesToCreate as $aggregate) {
$this->createStoreCommand($aggregate)->execute();
}
} | php | protected function createRelatedEntities($relations)
{
$entitiesToCreate = $this->aggregate->getNonExistingRelated($relations);
foreach ($entitiesToCreate as $aggregate) {
$this->createStoreCommand($aggregate)->execute();
}
} | [
"protected",
"function",
"createRelatedEntities",
"(",
"$",
"relations",
")",
"{",
"$",
"entitiesToCreate",
"=",
"$",
"this",
"->",
"aggregate",
"->",
"getNonExistingRelated",
"(",
"$",
"relations",
")",
";",
"foreach",
"(",
"$",
"entitiesToCreate",
"as",
"$",
"aggregate",
")",
"{",
"$",
"this",
"->",
"createStoreCommand",
"(",
"$",
"aggregate",
")",
"->",
"execute",
"(",
")",
";",
"}",
"}"
] | Check for existence and create non-existing related entities.
@param array
@throws \InvalidArgumentException
@return void | [
"Check",
"for",
"existence",
"and",
"create",
"non",
"-",
"existing",
"related",
"entities",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Commands/Store.php#L99-L106 |
analogueorm/analogue | src/Commands/Store.php | Store.createStoreCommand | protected function createStoreCommand(Aggregate $aggregate): self
{
// We gotta retrieve the corresponding query adapter to use.
$mapper = $aggregate->getMapper();
return new self($aggregate, $mapper->newQueryBuilder());
} | php | protected function createStoreCommand(Aggregate $aggregate): self
{
// We gotta retrieve the corresponding query adapter to use.
$mapper = $aggregate->getMapper();
return new self($aggregate, $mapper->newQueryBuilder());
} | [
"protected",
"function",
"createStoreCommand",
"(",
"Aggregate",
"$",
"aggregate",
")",
":",
"self",
"{",
"// We gotta retrieve the corresponding query adapter to use.",
"$",
"mapper",
"=",
"$",
"aggregate",
"->",
"getMapper",
"(",
")",
";",
"return",
"new",
"self",
"(",
"$",
"aggregate",
",",
"$",
"mapper",
"->",
"newQueryBuilder",
"(",
")",
")",
";",
"}"
] | Create a new store command.
@param Aggregate $aggregate
@return Store | [
"Create",
"a",
"new",
"store",
"command",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Commands/Store.php#L115-L121 |
analogueorm/analogue | src/Commands/Store.php | Store.postStoreProcess | protected function postStoreProcess()
{
$aggregate = $this->aggregate;
// Create any related object that doesn't exist in the database.
$foreignRelationships = $aggregate->getEntityMap()->getForeignRelationships();
$this->createRelatedEntities($foreignRelationships);
// Update any pivot tables that has been modified.
$aggregate->updatePivotRecords();
// Update any dirty relationship. This include relationships that already exists, have
// dirty attributes / newly created related entities / dirty related entities.
$dirtyRelatedAggregates = $aggregate->getDirtyRelationships();
foreach ($dirtyRelatedAggregates as $related) {
$this->createStoreCommand($related)->execute();
}
// Now we can sync the related collections
//
// TODO (note) : not sure this check is needed, as we can assume
// the aggregate exists in the Post Store Process
if ($this->aggregate->exists()) {
$this->aggregate->syncRelationships($foreignRelationships);
}
// TODO be move it to the wrapper class
// so it's the same code for the entity builder
$aggregate->setProxies();
// Update Entity Cache
$aggregate->getMapper()->getEntityCache()->refresh($aggregate);
} | php | protected function postStoreProcess()
{
$aggregate = $this->aggregate;
// Create any related object that doesn't exist in the database.
$foreignRelationships = $aggregate->getEntityMap()->getForeignRelationships();
$this->createRelatedEntities($foreignRelationships);
// Update any pivot tables that has been modified.
$aggregate->updatePivotRecords();
// Update any dirty relationship. This include relationships that already exists, have
// dirty attributes / newly created related entities / dirty related entities.
$dirtyRelatedAggregates = $aggregate->getDirtyRelationships();
foreach ($dirtyRelatedAggregates as $related) {
$this->createStoreCommand($related)->execute();
}
// Now we can sync the related collections
//
// TODO (note) : not sure this check is needed, as we can assume
// the aggregate exists in the Post Store Process
if ($this->aggregate->exists()) {
$this->aggregate->syncRelationships($foreignRelationships);
}
// TODO be move it to the wrapper class
// so it's the same code for the entity builder
$aggregate->setProxies();
// Update Entity Cache
$aggregate->getMapper()->getEntityCache()->refresh($aggregate);
} | [
"protected",
"function",
"postStoreProcess",
"(",
")",
"{",
"$",
"aggregate",
"=",
"$",
"this",
"->",
"aggregate",
";",
"// Create any related object that doesn't exist in the database.",
"$",
"foreignRelationships",
"=",
"$",
"aggregate",
"->",
"getEntityMap",
"(",
")",
"->",
"getForeignRelationships",
"(",
")",
";",
"$",
"this",
"->",
"createRelatedEntities",
"(",
"$",
"foreignRelationships",
")",
";",
"// Update any pivot tables that has been modified.",
"$",
"aggregate",
"->",
"updatePivotRecords",
"(",
")",
";",
"// Update any dirty relationship. This include relationships that already exists, have",
"// dirty attributes / newly created related entities / dirty related entities.",
"$",
"dirtyRelatedAggregates",
"=",
"$",
"aggregate",
"->",
"getDirtyRelationships",
"(",
")",
";",
"foreach",
"(",
"$",
"dirtyRelatedAggregates",
"as",
"$",
"related",
")",
"{",
"$",
"this",
"->",
"createStoreCommand",
"(",
"$",
"related",
")",
"->",
"execute",
"(",
")",
";",
"}",
"// Now we can sync the related collections",
"//",
"// TODO (note) : not sure this check is needed, as we can assume",
"// the aggregate exists in the Post Store Process",
"if",
"(",
"$",
"this",
"->",
"aggregate",
"->",
"exists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"aggregate",
"->",
"syncRelationships",
"(",
"$",
"foreignRelationships",
")",
";",
"}",
"// TODO be move it to the wrapper class",
"// so it's the same code for the entity builder",
"$",
"aggregate",
"->",
"setProxies",
"(",
")",
";",
"// Update Entity Cache",
"$",
"aggregate",
"->",
"getMapper",
"(",
")",
"->",
"getEntityCache",
"(",
")",
"->",
"refresh",
"(",
"$",
"aggregate",
")",
";",
"}"
] | Run all operations that have to occur after the entity
is stored.
@throws \InvalidArgumentException
@return void | [
"Run",
"all",
"operations",
"that",
"have",
"to",
"occur",
"after",
"the",
"entity",
"is",
"stored",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Commands/Store.php#L131-L165 |
analogueorm/analogue | src/Commands/Store.php | Store.insert | protected function insert()
{
$aggregate = $this->aggregate;
$attributes = $aggregate->getRawAttributes();
$keyName = $aggregate->getEntityMap()->getKeyName();
// Check if the primary key is defined in the attributes
if (array_key_exists($keyName, $attributes) && $attributes[$keyName] != null) {
$this->query->insert($attributes);
} else {
// Prevent inserting with a null ID
if (array_key_exists($keyName, $attributes)) {
unset($attributes[$keyName]);
}
if (isset($attributes['attributes'])) {
unset($attributes['attributes']);
}
$id = $this->query->insertGetId($attributes, $keyName);
$aggregate->setEntityAttribute($keyName, $id);
}
} | php | protected function insert()
{
$aggregate = $this->aggregate;
$attributes = $aggregate->getRawAttributes();
$keyName = $aggregate->getEntityMap()->getKeyName();
// Check if the primary key is defined in the attributes
if (array_key_exists($keyName, $attributes) && $attributes[$keyName] != null) {
$this->query->insert($attributes);
} else {
// Prevent inserting with a null ID
if (array_key_exists($keyName, $attributes)) {
unset($attributes[$keyName]);
}
if (isset($attributes['attributes'])) {
unset($attributes['attributes']);
}
$id = $this->query->insertGetId($attributes, $keyName);
$aggregate->setEntityAttribute($keyName, $id);
}
} | [
"protected",
"function",
"insert",
"(",
")",
"{",
"$",
"aggregate",
"=",
"$",
"this",
"->",
"aggregate",
";",
"$",
"attributes",
"=",
"$",
"aggregate",
"->",
"getRawAttributes",
"(",
")",
";",
"$",
"keyName",
"=",
"$",
"aggregate",
"->",
"getEntityMap",
"(",
")",
"->",
"getKeyName",
"(",
")",
";",
"// Check if the primary key is defined in the attributes",
"if",
"(",
"array_key_exists",
"(",
"$",
"keyName",
",",
"$",
"attributes",
")",
"&&",
"$",
"attributes",
"[",
"$",
"keyName",
"]",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"insert",
"(",
"$",
"attributes",
")",
";",
"}",
"else",
"{",
"// Prevent inserting with a null ID",
"if",
"(",
"array_key_exists",
"(",
"$",
"keyName",
",",
"$",
"attributes",
")",
")",
"{",
"unset",
"(",
"$",
"attributes",
"[",
"$",
"keyName",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"attributes",
"[",
"'attributes'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"attributes",
"[",
"'attributes'",
"]",
")",
";",
"}",
"$",
"id",
"=",
"$",
"this",
"->",
"query",
"->",
"insertGetId",
"(",
"$",
"attributes",
",",
"$",
"keyName",
")",
";",
"$",
"aggregate",
"->",
"setEntityAttribute",
"(",
"$",
"keyName",
",",
"$",
"id",
")",
";",
"}",
"}"
] | Execute an insert statement on the database.
@return void | [
"Execute",
"an",
"insert",
"statement",
"on",
"the",
"database",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Commands/Store.php#L172-L197 |
analogueorm/analogue | src/Commands/Store.php | Store.syncForeignKeyAttributes | protected function syncForeignKeyAttributes()
{
$attributes = $this->aggregate->getForeignKeyAttributes();
foreach ($attributes as $key => $value) {
$this->aggregate->setEntityAttribute($key, $value);
}
} | php | protected function syncForeignKeyAttributes()
{
$attributes = $this->aggregate->getForeignKeyAttributes();
foreach ($attributes as $key => $value) {
$this->aggregate->setEntityAttribute($key, $value);
}
} | [
"protected",
"function",
"syncForeignKeyAttributes",
"(",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"aggregate",
"->",
"getForeignKeyAttributes",
"(",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"aggregate",
"->",
"setEntityAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Update attributes on actual entity.
@param array $attributes
@return void | [
"Update",
"attributes",
"on",
"actual",
"entity",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Commands/Store.php#L206-L213 |
analogueorm/analogue | src/Commands/Store.php | Store.update | protected function update()
{
$key = $this->aggregate->getEntityKeyName();
$value = $this->aggregate->getEntityKeyValue();
$this->query->where($key, $value);
$dirtyAttributes = $this->aggregate->getDirtyRawAttributes();
if (count($dirtyAttributes) > 0) {
$this->query->update($dirtyAttributes);
}
} | php | protected function update()
{
$key = $this->aggregate->getEntityKeyName();
$value = $this->aggregate->getEntityKeyValue();
$this->query->where($key, $value);
$dirtyAttributes = $this->aggregate->getDirtyRawAttributes();
if (count($dirtyAttributes) > 0) {
$this->query->update($dirtyAttributes);
}
} | [
"protected",
"function",
"update",
"(",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"aggregate",
"->",
"getEntityKeyName",
"(",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"aggregate",
"->",
"getEntityKeyValue",
"(",
")",
";",
"$",
"this",
"->",
"query",
"->",
"where",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"$",
"dirtyAttributes",
"=",
"$",
"this",
"->",
"aggregate",
"->",
"getDirtyRawAttributes",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"dirtyAttributes",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"query",
"->",
"update",
"(",
"$",
"dirtyAttributes",
")",
";",
"}",
"}"
] | Run an update statement on the entity.
@throws \InvalidArgumentException
@return void | [
"Run",
"an",
"update",
"statement",
"on",
"the",
"entity",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Commands/Store.php#L222-L234 |
analogueorm/analogue | src/System/Cache/InstanceCache.php | InstanceCache.add | public function add($entity, string $id)
{
$entityClass = get_class($entity);
if ($entityClass !== $this->class) {
throw new CacheException('Tried to cache an instance with a wrong type : expected '.$this->class.", got $entityClass");
}
// Cache once and ignore subsequent caching
// attempts if the entity is already stored
if (!$this->has($id)) {
$this->instances[$id] = $entity;
}
} | php | public function add($entity, string $id)
{
$entityClass = get_class($entity);
if ($entityClass !== $this->class) {
throw new CacheException('Tried to cache an instance with a wrong type : expected '.$this->class.", got $entityClass");
}
// Cache once and ignore subsequent caching
// attempts if the entity is already stored
if (!$this->has($id)) {
$this->instances[$id] = $entity;
}
} | [
"public",
"function",
"add",
"(",
"$",
"entity",
",",
"string",
"$",
"id",
")",
"{",
"$",
"entityClass",
"=",
"get_class",
"(",
"$",
"entity",
")",
";",
"if",
"(",
"$",
"entityClass",
"!==",
"$",
"this",
"->",
"class",
")",
"{",
"throw",
"new",
"CacheException",
"(",
"'Tried to cache an instance with a wrong type : expected '",
".",
"$",
"this",
"->",
"class",
".",
"\", got $entityClass\"",
")",
";",
"}",
"// Cache once and ignore subsequent caching",
"// attempts if the entity is already stored",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"instances",
"[",
"$",
"id",
"]",
"=",
"$",
"entity",
";",
"}",
"}"
] | Add an entity to the cache.
@param mixed $entity
@param string $id
@throws CacheException
@return void | [
"Add",
"an",
"entity",
"to",
"the",
"cache",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/InstanceCache.php#L43-L56 |
analogueorm/analogue | src/Plugins/SoftDeletes/SoftDeletesPlugin.php | SoftDeletesPlugin.register | public function register()
{
// Hook any mapper init and check the mapping include soft deletes.
$this->manager->registerGlobalEvent('initialized', function ($event, $payload = null) {
// Cross Compatible Event handling with 5.3
// TODO : find a replacement event handler
if (is_null($payload)) {
$mapper = $event;
} else {
$mapper = $payload[0]->mapper;
}
$entityMap = $mapper->getEntityMap();
if ($entityMap->usesSoftDeletes()) {
$this->registerSoftDelete($mapper);
foreach ($this->getCustomEvents() as $name => $class) {
$mapper->addCustomEvent($name, $class);
}
}
});
} | php | public function register()
{
// Hook any mapper init and check the mapping include soft deletes.
$this->manager->registerGlobalEvent('initialized', function ($event, $payload = null) {
// Cross Compatible Event handling with 5.3
// TODO : find a replacement event handler
if (is_null($payload)) {
$mapper = $event;
} else {
$mapper = $payload[0]->mapper;
}
$entityMap = $mapper->getEntityMap();
if ($entityMap->usesSoftDeletes()) {
$this->registerSoftDelete($mapper);
foreach ($this->getCustomEvents() as $name => $class) {
$mapper->addCustomEvent($name, $class);
}
}
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"// Hook any mapper init and check the mapping include soft deletes.",
"$",
"this",
"->",
"manager",
"->",
"registerGlobalEvent",
"(",
"'initialized'",
",",
"function",
"(",
"$",
"event",
",",
"$",
"payload",
"=",
"null",
")",
"{",
"// Cross Compatible Event handling with 5.3",
"// TODO : find a replacement event handler",
"if",
"(",
"is_null",
"(",
"$",
"payload",
")",
")",
"{",
"$",
"mapper",
"=",
"$",
"event",
";",
"}",
"else",
"{",
"$",
"mapper",
"=",
"$",
"payload",
"[",
"0",
"]",
"->",
"mapper",
";",
"}",
"$",
"entityMap",
"=",
"$",
"mapper",
"->",
"getEntityMap",
"(",
")",
";",
"if",
"(",
"$",
"entityMap",
"->",
"usesSoftDeletes",
"(",
")",
")",
"{",
"$",
"this",
"->",
"registerSoftDelete",
"(",
"$",
"mapper",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getCustomEvents",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"class",
")",
"{",
"$",
"mapper",
"->",
"addCustomEvent",
"(",
"$",
"name",
",",
"$",
"class",
")",
";",
"}",
"}",
"}",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Plugins/SoftDeletes/SoftDeletesPlugin.php#L20-L43 |
analogueorm/analogue | src/Plugins/SoftDeletes/SoftDeletesPlugin.php | SoftDeletesPlugin.registerSoftDelete | protected function registerSoftDelete(Mapper $mapper)
{
$entityMap = $mapper->getEntityMap();
// Add Scopes
$mapper->addGlobalScope(new SoftDeletingScope());
// Register 'deleting' events
$mapper->registerEvent('deleting', function ($event) use ($entityMap) {
$entity = $event->entity;
$wrappedEntity = $this->getMappable($entity);
$deletedAtField = $entityMap->getQualifiedDeletedAtColumn();
if (!is_null($wrappedEntity->getEntityAttribute($deletedAtField))) {
return true;
}
$time = new Carbon();
$wrappedEntity->setEntityAttribute($deletedAtField, $time);
$plainObject = $wrappedEntity->getObject();
$this->manager->mapper(get_class($plainObject))->store($plainObject);
return false;
});
// Register RestoreCommand
$mapper->addCustomCommand(Restore::class);
} | php | protected function registerSoftDelete(Mapper $mapper)
{
$entityMap = $mapper->getEntityMap();
// Add Scopes
$mapper->addGlobalScope(new SoftDeletingScope());
// Register 'deleting' events
$mapper->registerEvent('deleting', function ($event) use ($entityMap) {
$entity = $event->entity;
$wrappedEntity = $this->getMappable($entity);
$deletedAtField = $entityMap->getQualifiedDeletedAtColumn();
if (!is_null($wrappedEntity->getEntityAttribute($deletedAtField))) {
return true;
}
$time = new Carbon();
$wrappedEntity->setEntityAttribute($deletedAtField, $time);
$plainObject = $wrappedEntity->getObject();
$this->manager->mapper(get_class($plainObject))->store($plainObject);
return false;
});
// Register RestoreCommand
$mapper->addCustomCommand(Restore::class);
} | [
"protected",
"function",
"registerSoftDelete",
"(",
"Mapper",
"$",
"mapper",
")",
"{",
"$",
"entityMap",
"=",
"$",
"mapper",
"->",
"getEntityMap",
"(",
")",
";",
"// Add Scopes",
"$",
"mapper",
"->",
"addGlobalScope",
"(",
"new",
"SoftDeletingScope",
"(",
")",
")",
";",
"// Register 'deleting' events",
"$",
"mapper",
"->",
"registerEvent",
"(",
"'deleting'",
",",
"function",
"(",
"$",
"event",
")",
"use",
"(",
"$",
"entityMap",
")",
"{",
"$",
"entity",
"=",
"$",
"event",
"->",
"entity",
";",
"$",
"wrappedEntity",
"=",
"$",
"this",
"->",
"getMappable",
"(",
"$",
"entity",
")",
";",
"$",
"deletedAtField",
"=",
"$",
"entityMap",
"->",
"getQualifiedDeletedAtColumn",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"wrappedEntity",
"->",
"getEntityAttribute",
"(",
"$",
"deletedAtField",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"time",
"=",
"new",
"Carbon",
"(",
")",
";",
"$",
"wrappedEntity",
"->",
"setEntityAttribute",
"(",
"$",
"deletedAtField",
",",
"$",
"time",
")",
";",
"$",
"plainObject",
"=",
"$",
"wrappedEntity",
"->",
"getObject",
"(",
")",
";",
"$",
"this",
"->",
"manager",
"->",
"mapper",
"(",
"get_class",
"(",
"$",
"plainObject",
")",
")",
"->",
"store",
"(",
"$",
"plainObject",
")",
";",
"return",
"false",
";",
"}",
")",
";",
"// Register RestoreCommand",
"$",
"mapper",
"->",
"addCustomCommand",
"(",
"Restore",
"::",
"class",
")",
";",
"}"
] | By hooking to the mapper initialization event, we can extend it
with the softDelete capacity.
@param \Analogue\ORM\System\Mapper $mapper
@throws \Analogue\ORM\Exceptions\MappingException
@return bool|void | [
"By",
"hooking",
"to",
"the",
"mapper",
"initialization",
"event",
"we",
"can",
"extend",
"it",
"with",
"the",
"softDelete",
"capacity",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Plugins/SoftDeletes/SoftDeletesPlugin.php#L55-L85 |
analogueorm/analogue | src/Commands/Delete.php | Delete.execute | public function execute()
{
$aggregate = $this->aggregate;
$entity = $aggregate->getEntityObject();
$wrappedEntity = $aggregate->getWrappedEntity();
$mapper = $aggregate->getMapper();
if ($mapper->fireEvent('deleting', $wrappedEntity) === false) {
return false;
}
$keyName = $aggregate->getEntityMap()->getKeyName();
$id = $this->aggregate->getEntityKeyValue();
if (is_null($id)) {
throw new MappingException('Executed a delete command on an entity with "null" as primary key');
}
$this->query->where($keyName, '=', $id)->delete();
$mapper->fireEvent('deleted', $wrappedEntity, false);
} | php | public function execute()
{
$aggregate = $this->aggregate;
$entity = $aggregate->getEntityObject();
$wrappedEntity = $aggregate->getWrappedEntity();
$mapper = $aggregate->getMapper();
if ($mapper->fireEvent('deleting', $wrappedEntity) === false) {
return false;
}
$keyName = $aggregate->getEntityMap()->getKeyName();
$id = $this->aggregate->getEntityKeyValue();
if (is_null($id)) {
throw new MappingException('Executed a delete command on an entity with "null" as primary key');
}
$this->query->where($keyName, '=', $id)->delete();
$mapper->fireEvent('deleted', $wrappedEntity, false);
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"aggregate",
"=",
"$",
"this",
"->",
"aggregate",
";",
"$",
"entity",
"=",
"$",
"aggregate",
"->",
"getEntityObject",
"(",
")",
";",
"$",
"wrappedEntity",
"=",
"$",
"aggregate",
"->",
"getWrappedEntity",
"(",
")",
";",
"$",
"mapper",
"=",
"$",
"aggregate",
"->",
"getMapper",
"(",
")",
";",
"if",
"(",
"$",
"mapper",
"->",
"fireEvent",
"(",
"'deleting'",
",",
"$",
"wrappedEntity",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"keyName",
"=",
"$",
"aggregate",
"->",
"getEntityMap",
"(",
")",
"->",
"getKeyName",
"(",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"aggregate",
"->",
"getEntityKeyValue",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"MappingException",
"(",
"'Executed a delete command on an entity with \"null\" as primary key'",
")",
";",
"}",
"$",
"this",
"->",
"query",
"->",
"where",
"(",
"$",
"keyName",
",",
"'='",
",",
"$",
"id",
")",
"->",
"delete",
"(",
")",
";",
"$",
"mapper",
"->",
"fireEvent",
"(",
"'deleted'",
",",
"$",
"wrappedEntity",
",",
"false",
")",
";",
"}"
] | Execute the Delete Statement.
@throws MappingException
@throws \InvalidArgumentException
@return false|void | [
"Execute",
"the",
"Delete",
"Statement",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Commands/Delete.php#L17-L40 |
analogueorm/analogue | src/System/Proxies/CollectionProxy.php | CollectionProxy.initializeProxy | public function initializeProxy() : bool
{
if ($this->isProxyInitialized()) {
return true;
}
$this->items = $this->prependedItems + $this->getRelationshipInstance()
->getResults($this->relationshipMethod)->all() + $this->pushedItems;
$this->relationshipLoaded = true;
return true;
} | php | public function initializeProxy() : bool
{
if ($this->isProxyInitialized()) {
return true;
}
$this->items = $this->prependedItems + $this->getRelationshipInstance()
->getResults($this->relationshipMethod)->all() + $this->pushedItems;
$this->relationshipLoaded = true;
return true;
} | [
"public",
"function",
"initializeProxy",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"isProxyInitialized",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"items",
"=",
"$",
"this",
"->",
"prependedItems",
"+",
"$",
"this",
"->",
"getRelationshipInstance",
"(",
")",
"->",
"getResults",
"(",
"$",
"this",
"->",
"relationshipMethod",
")",
"->",
"all",
"(",
")",
"+",
"$",
"this",
"->",
"pushedItems",
";",
"$",
"this",
"->",
"relationshipLoaded",
"=",
"true",
";",
"return",
"true",
";",
"}"
] | Force initialization of the proxy.
@return bool true if the proxy could be initialized | [
"Force",
"initialization",
"of",
"the",
"proxy",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/CollectionProxy.php#L78-L90 |
analogueorm/analogue | src/System/Proxies/CollectionProxy.php | CollectionProxy.getRelationshipInstance | protected function getRelationshipInstance() : Relationship
{
$relation = $this->relationshipMethod;
$entity = $this->parentEntity;
$entityMap = Manager::getMapper($entity)->getEntityMap();
return $entityMap->$relation($entity);
} | php | protected function getRelationshipInstance() : Relationship
{
$relation = $this->relationshipMethod;
$entity = $this->parentEntity;
$entityMap = Manager::getMapper($entity)->getEntityMap();
return $entityMap->$relation($entity);
} | [
"protected",
"function",
"getRelationshipInstance",
"(",
")",
":",
"Relationship",
"{",
"$",
"relation",
"=",
"$",
"this",
"->",
"relationshipMethod",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"parentEntity",
";",
"$",
"entityMap",
"=",
"Manager",
"::",
"getMapper",
"(",
"$",
"entity",
")",
"->",
"getEntityMap",
"(",
")",
";",
"return",
"$",
"entityMap",
"->",
"$",
"relation",
"(",
"$",
"entity",
")",
";",
"}"
] | Return instance of the underlying relationship.
@return Relationship | [
"Return",
"instance",
"of",
"the",
"underlying",
"relationship",
"."
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/CollectionProxy.php#L97-L104 |
analogueorm/analogue | src/System/Proxies/CollectionProxy.php | CollectionProxy.contains | public function contains($key, $operator = null, $value = null)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
switch (func_num_args()) {
case 1:
return $parent->contains($key);
case 2:
return $parent->contains($key, $operator);
case 3:
return $parent->contains($key, $operator, $value);
}
} | php | public function contains($key, $operator = null, $value = null)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
switch (func_num_args()) {
case 1:
return $parent->contains($key);
case 2:
return $parent->contains($key, $operator);
case 3:
return $parent->contains($key, $operator, $value);
}
} | [
"public",
"function",
"contains",
"(",
"$",
"key",
",",
"$",
"operator",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"initializeProxy",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"toBaseCollection",
"(",
")",
";",
"switch",
"(",
"func_num_args",
"(",
")",
")",
"{",
"case",
"1",
":",
"return",
"$",
"parent",
"->",
"contains",
"(",
"$",
"key",
")",
";",
"case",
"2",
":",
"return",
"$",
"parent",
"->",
"contains",
"(",
"$",
"key",
",",
"$",
"operator",
")",
";",
"case",
"3",
":",
"return",
"$",
"parent",
"->",
"contains",
"(",
"$",
"key",
",",
"$",
"operator",
",",
"$",
"value",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/CollectionProxy.php#L177-L191 |
analogueorm/analogue | src/System/Proxies/CollectionProxy.php | CollectionProxy.containsStrict | public function containsStrict($key, $value = null)
{
$this->initializeProxy();
switch (func_num_args()) {
case 1:
return parent::containsStrict($key);
case 2:
return parent::containsStrict($key, $value);
}
} | php | public function containsStrict($key, $value = null)
{
$this->initializeProxy();
switch (func_num_args()) {
case 1:
return parent::containsStrict($key);
case 2:
return parent::containsStrict($key, $value);
}
} | [
"public",
"function",
"containsStrict",
"(",
"$",
"key",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"initializeProxy",
"(",
")",
";",
"switch",
"(",
"func_num_args",
"(",
")",
")",
"{",
"case",
"1",
":",
"return",
"parent",
"::",
"containsStrict",
"(",
"$",
"key",
")",
";",
"case",
"2",
":",
"return",
"parent",
"::",
"containsStrict",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/CollectionProxy.php#L196-L206 |
analogueorm/analogue | src/System/Proxies/CollectionProxy.php | CollectionProxy.diff | public function diff($items)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->diff($items);
} | php | public function diff($items)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->diff($items);
} | [
"public",
"function",
"diff",
"(",
"$",
"items",
")",
"{",
"$",
"this",
"->",
"initializeProxy",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"toBaseCollection",
"(",
")",
";",
"return",
"$",
"parent",
"->",
"diff",
"(",
"$",
"items",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/CollectionProxy.php#L211-L218 |
analogueorm/analogue | src/System/Proxies/CollectionProxy.php | CollectionProxy.diffUsing | public function diffUsing($items, callable $callback)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->diffUsing($items, $callback);
} | php | public function diffUsing($items, callable $callback)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->diffUsing($items, $callback);
} | [
"public",
"function",
"diffUsing",
"(",
"$",
"items",
",",
"callable",
"$",
"callback",
")",
"{",
"$",
"this",
"->",
"initializeProxy",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"toBaseCollection",
"(",
")",
";",
"return",
"$",
"parent",
"->",
"diffUsing",
"(",
"$",
"items",
",",
"$",
"callback",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/CollectionProxy.php#L223-L230 |
analogueorm/analogue | src/System/Proxies/CollectionProxy.php | CollectionProxy.diffAssocUsing | public function diffAssocUsing($items, callable $callback)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->diffAssocUsing($items, $callback);
} | php | public function diffAssocUsing($items, callable $callback)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->diffAssocUsing($items, $callback);
} | [
"public",
"function",
"diffAssocUsing",
"(",
"$",
"items",
",",
"callable",
"$",
"callback",
")",
"{",
"$",
"this",
"->",
"initializeProxy",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"toBaseCollection",
"(",
")",
";",
"return",
"$",
"parent",
"->",
"diffAssocUsing",
"(",
"$",
"items",
",",
"$",
"callback",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/CollectionProxy.php#L235-L242 |
analogueorm/analogue | src/System/Proxies/CollectionProxy.php | CollectionProxy.diffKeys | public function diffKeys($items)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->diffKeys($items);
} | php | public function diffKeys($items)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->diffKeys($items);
} | [
"public",
"function",
"diffKeys",
"(",
"$",
"items",
")",
"{",
"$",
"this",
"->",
"initializeProxy",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"toBaseCollection",
"(",
")",
";",
"return",
"$",
"parent",
"->",
"diffKeys",
"(",
"$",
"items",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/CollectionProxy.php#L247-L254 |
analogueorm/analogue | src/System/Proxies/CollectionProxy.php | CollectionProxy.diffKeysUsing | public function diffKeysUsing($items, callable $callback)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->diffKeysUsing($items);
} | php | public function diffKeysUsing($items, callable $callback)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->diffKeysUsing($items);
} | [
"public",
"function",
"diffKeysUsing",
"(",
"$",
"items",
",",
"callable",
"$",
"callback",
")",
"{",
"$",
"this",
"->",
"initializeProxy",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"toBaseCollection",
"(",
")",
";",
"return",
"$",
"parent",
"->",
"diffKeysUsing",
"(",
"$",
"items",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/CollectionProxy.php#L259-L266 |
analogueorm/analogue | src/System/Proxies/CollectionProxy.php | CollectionProxy.except | public function except($keys)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->except($keys);
} | php | public function except($keys)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->except($keys);
} | [
"public",
"function",
"except",
"(",
"$",
"keys",
")",
"{",
"$",
"this",
"->",
"initializeProxy",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"toBaseCollection",
"(",
")",
";",
"return",
"$",
"parent",
"->",
"except",
"(",
"$",
"keys",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/CollectionProxy.php#L300-L307 |
analogueorm/analogue | src/System/Proxies/CollectionProxy.php | CollectionProxy.filter | public function filter(callable $callback = null)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->filter($callback);
} | php | public function filter(callable $callback = null)
{
$this->initializeProxy();
$parent = $this->toBaseCollection();
return $parent->filter($callback);
} | [
"public",
"function",
"filter",
"(",
"callable",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"initializeProxy",
"(",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"toBaseCollection",
"(",
")",
";",
"return",
"$",
"parent",
"->",
"filter",
"(",
"$",
"callback",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Proxies/CollectionProxy.php#L312-L319 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.