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/ValueMap.php
ValueMap.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; } 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; } 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", ";", "}", "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/ValueMap.php#L128-L141
analogueorm/analogue
src/ValueMap.php
ValueMap.getAttributeNameForColumn
public function getAttributeNameForColumn($columnName) { if (!empty($this->mappings)) { if (isset($this->mappings[$columnName])) { return $this->mappings[$columnName]; } } return $columnName; }
php
public function getAttributeNameForColumn($columnName) { if (!empty($this->mappings)) { if (isset($this->mappings[$columnName])) { return $this->mappings[$columnName]; } } return $columnName; }
[ "public", "function", "getAttributeNameForColumn", "(", "$", "columnName", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "mappings", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "mappings", "[", "$", "columnName", "]", ")", ")", "{", "return", "$", "this", "->", "mappings", "[", "$", "columnName", "]", ";", "}", "}", "return", "$", "columnName", ";", "}" ]
Gets the entity attribute name of a given column in a table. @param string $columnName @return string
[ "Gets", "the", "entity", "attribute", "name", "of", "a", "given", "column", "in", "a", "table", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/ValueMap.php#L150-L159
analogueorm/analogue
src/ValueMap.php
ValueMap.getColumnNameForAttribute
public function getColumnNameForAttribute($attributeName) { if (!empty($this->mappings)) { $flipped = array_flip($this->mappings); if (isset($flipped[$attributeName])) { return $flipped[$attributeName]; } } return $attributeName; }
php
public function getColumnNameForAttribute($attributeName) { if (!empty($this->mappings)) { $flipped = array_flip($this->mappings); if (isset($flipped[$attributeName])) { return $flipped[$attributeName]; } } return $attributeName; }
[ "public", "function", "getColumnNameForAttribute", "(", "$", "attributeName", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "mappings", ")", ")", "{", "$", "flipped", "=", "array_flip", "(", "$", "this", "->", "mappings", ")", ";", "if", "(", "isset", "(", "$", "flipped", "[", "$", "attributeName", "]", ")", ")", "{", "return", "$", "flipped", "[", "$", "attributeName", "]", ";", "}", "}", "return", "$", "attributeName", ";", "}" ]
Gets the column name of a given entity attribute. @param string $attributeName @return string
[ "Gets", "the", "column", "name", "of", "a", "given", "entity", "attribute", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/ValueMap.php#L168-L178
analogueorm/analogue
src/ValueMap.php
ValueMap.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; } 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; } 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", ";", "}", "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/ValueMap.php#L189-L203
analogueorm/analogue
src/System/Builders/ResultBuilder.php
ResultBuilder.build
public function build(array $results, array $eagerLoads) { // First, we'll cache the raw result set $this->cacheResults($results); // Parse embedded relations and build corresponding entities using the default // mapper. $results = $this->buildEmbeddedRelationships($results); // Launch the queries related to eager loads, and match the // current result set to these loaded relationships. $results = $this->queryEagerLoadedRelationships($results, $eagerLoads); return $this->buildResultSet($results); }
php
public function build(array $results, array $eagerLoads) { // First, we'll cache the raw result set $this->cacheResults($results); // Parse embedded relations and build corresponding entities using the default // mapper. $results = $this->buildEmbeddedRelationships($results); // Launch the queries related to eager loads, and match the // current result set to these loaded relationships. $results = $this->queryEagerLoadedRelationships($results, $eagerLoads); return $this->buildResultSet($results); }
[ "public", "function", "build", "(", "array", "$", "results", ",", "array", "$", "eagerLoads", ")", "{", "// First, we'll cache the raw result set", "$", "this", "->", "cacheResults", "(", "$", "results", ")", ";", "// Parse embedded relations and build corresponding entities using the default", "// mapper.", "$", "results", "=", "$", "this", "->", "buildEmbeddedRelationships", "(", "$", "results", ")", ";", "// Launch the queries related to eager loads, and match the", "// current result set to these loaded relationships.", "$", "results", "=", "$", "this", "->", "queryEagerLoadedRelationships", "(", "$", "results", ",", "$", "eagerLoads", ")", ";", "return", "$", "this", "->", "buildResultSet", "(", "$", "results", ")", ";", "}" ]
Convert a result set into an array of entities. @param array $results The results to convert into entities. @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/ResultBuilder.php#L68-L82
analogueorm/analogue
src/System/Builders/ResultBuilder.php
ResultBuilder.cacheResults
protected function cacheResults(array $results) { $mapper = $this->mapper; // When hydrating EmbeddedValue object, they'll likely won't // have a primary key set. if ($mapper->getEntityMap()->getKeyName() !== null) { $mapper->getEntityCache()->add($results); } }
php
protected function cacheResults(array $results) { $mapper = $this->mapper; // When hydrating EmbeddedValue object, they'll likely won't // have a primary key set. if ($mapper->getEntityMap()->getKeyName() !== null) { $mapper->getEntityCache()->add($results); } }
[ "protected", "function", "cacheResults", "(", "array", "$", "results", ")", "{", "$", "mapper", "=", "$", "this", "->", "mapper", ";", "// When hydrating EmbeddedValue object, they'll likely won't", "// have a primary key set.", "if", "(", "$", "mapper", "->", "getEntityMap", "(", ")", "->", "getKeyName", "(", ")", "!==", "null", ")", "{", "$", "mapper", "->", "getEntityCache", "(", ")", "->", "add", "(", "$", "results", ")", ";", "}", "}" ]
Cache result set. @param array $results @return void
[ "Cache", "result", "set", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Builders/ResultBuilder.php#L91-L100
analogueorm/analogue
src/System/Builders/ResultBuilder.php
ResultBuilder.buildEmbeddedRelationships
protected function buildEmbeddedRelationships(array $results) : array { $entityMap = $this->entityMap; $instance = $this->mapper->newInstance(); $embeddeds = $entityMap->getEmbeddedRelationships(); foreach ($embeddeds as $embedded) { $results = $entityMap->$embedded($instance)->match($results, $embedded); } return $results; }
php
protected function buildEmbeddedRelationships(array $results) : array { $entityMap = $this->entityMap; $instance = $this->mapper->newInstance(); $embeddeds = $entityMap->getEmbeddedRelationships(); foreach ($embeddeds as $embedded) { $results = $entityMap->$embedded($instance)->match($results, $embedded); } return $results; }
[ "protected", "function", "buildEmbeddedRelationships", "(", "array", "$", "results", ")", ":", "array", "{", "$", "entityMap", "=", "$", "this", "->", "entityMap", ";", "$", "instance", "=", "$", "this", "->", "mapper", "->", "newInstance", "(", ")", ";", "$", "embeddeds", "=", "$", "entityMap", "->", "getEmbeddedRelationships", "(", ")", ";", "foreach", "(", "$", "embeddeds", "as", "$", "embedded", ")", "{", "$", "results", "=", "$", "entityMap", "->", "$", "embedded", "(", "$", "instance", ")", "->", "match", "(", "$", "results", ",", "$", "embedded", ")", ";", "}", "return", "$", "results", ";", "}" ]
Build embedded objects and match them to the result set. @param array $results @return array
[ "Build", "embedded", "objects", "and", "match", "them", "to", "the", "result", "set", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Builders/ResultBuilder.php#L109-L120
analogueorm/analogue
src/System/Builders/ResultBuilder.php
ResultBuilder.queryEagerLoadedRelationships
protected function queryEagerLoadedRelationships(array $results, array $eagerLoads) : array { $this->eagerLoads = $this->parseRelations($eagerLoads); return $this->eagerLoadRelations($results); }
php
protected function queryEagerLoadedRelationships(array $results, array $eagerLoads) : array { $this->eagerLoads = $this->parseRelations($eagerLoads); return $this->eagerLoadRelations($results); }
[ "protected", "function", "queryEagerLoadedRelationships", "(", "array", "$", "results", ",", "array", "$", "eagerLoads", ")", ":", "array", "{", "$", "this", "->", "eagerLoads", "=", "$", "this", "->", "parseRelations", "(", "$", "eagerLoads", ")", ";", "return", "$", "this", "->", "eagerLoadRelations", "(", "$", "results", ")", ";", "}" ]
Launch queries on eager loaded relationships. @param array $results @param array $eagerLoads @return array
[ "Launch", "queries", "on", "eager", "loaded", "relationships", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Builders/ResultBuilder.php#L130-L135
analogueorm/analogue
src/System/Builders/ResultBuilder.php
ResultBuilder.eagerLoadRelations
public function eagerLoadRelations(array $results): array { foreach ($this->eagerLoads as $name => $constraints) { // First, we'll check if the entity map has a relation and just pass if it // is not the case if (!in_array($name, $this->entityMap->getRelationships())) { continue; } // For nested eager loads we'll skip loading them here and they will be set as an // eager load on the query to retrieve the relation so that they will be eager // loaded on that query, because that is where they get hydrated as models. if (strpos($name, '.') === false) { $results = $this->loadRelation($results, $name, $constraints); } } return $results; }
php
public function eagerLoadRelations(array $results): array { foreach ($this->eagerLoads as $name => $constraints) { // First, we'll check if the entity map has a relation and just pass if it // is not the case if (!in_array($name, $this->entityMap->getRelationships())) { continue; } // For nested eager loads we'll skip loading them here and they will be set as an // eager load on the query to retrieve the relation so that they will be eager // loaded on that query, because that is where they get hydrated as models. if (strpos($name, '.') === false) { $results = $this->loadRelation($results, $name, $constraints); } } return $results; }
[ "public", "function", "eagerLoadRelations", "(", "array", "$", "results", ")", ":", "array", "{", "foreach", "(", "$", "this", "->", "eagerLoads", "as", "$", "name", "=>", "$", "constraints", ")", "{", "// First, we'll check if the entity map has a relation and just pass if it", "// is not the case", "if", "(", "!", "in_array", "(", "$", "name", ",", "$", "this", "->", "entityMap", "->", "getRelationships", "(", ")", ")", ")", "{", "continue", ";", "}", "// For nested eager loads we'll skip loading them here and they will be set as an", "// eager load on the query to retrieve the relation so that they will be eager", "// loaded on that query, because that is where they get hydrated as models.", "if", "(", "strpos", "(", "$", "name", ",", "'.'", ")", "===", "false", ")", "{", "$", "results", "=", "$", "this", "->", "loadRelation", "(", "$", "results", ",", "$", "name", ",", "$", "constraints", ")", ";", "}", "}", "return", "$", "results", ";", "}" ]
Eager load the relationships on a result set. @param array $results @return array
[ "Eager", "load", "the", "relationships", "on", "a", "result", "set", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Builders/ResultBuilder.php#L204-L223
analogueorm/analogue
src/System/Builders/ResultBuilder.php
ResultBuilder.loadRelation
protected function loadRelation(array $results, string $name, Closure $constraints) : array { // First we will "back up" the existing where conditions on the query so we can // add our eager constraints. Then we will merge the wheres that were on the // query back to it in order that any where conditions might be specified. $relation = $this->getRelation($name); $relation->addEagerConstraints($results); call_user_func($constraints, $relation); // Once we have the results, we just match those back up to their parent models // using the relationship instance. Then we just return the finished arrays // of models which have been eagerly hydrated and are readied for return. return $relation->match($results, $name); }
php
protected function loadRelation(array $results, string $name, Closure $constraints) : array { // First we will "back up" the existing where conditions on the query so we can // add our eager constraints. Then we will merge the wheres that were on the // query back to it in order that any where conditions might be specified. $relation = $this->getRelation($name); $relation->addEagerConstraints($results); call_user_func($constraints, $relation); // Once we have the results, we just match those back up to their parent models // using the relationship instance. Then we just return the finished arrays // of models which have been eagerly hydrated and are readied for return. return $relation->match($results, $name); }
[ "protected", "function", "loadRelation", "(", "array", "$", "results", ",", "string", "$", "name", ",", "Closure", "$", "constraints", ")", ":", "array", "{", "// First we will \"back up\" the existing where conditions on the query so we can", "// add our eager constraints. Then we will merge the wheres that were on the", "// query back to it in order that any where conditions might be specified.", "$", "relation", "=", "$", "this", "->", "getRelation", "(", "$", "name", ")", ";", "$", "relation", "->", "addEagerConstraints", "(", "$", "results", ")", ";", "call_user_func", "(", "$", "constraints", ",", "$", "relation", ")", ";", "// Once we have the results, we just match those back up to their parent models", "// using the relationship instance. Then we just return the finished arrays", "// of models which have been eagerly hydrated and are readied for return.", "return", "$", "relation", "->", "match", "(", "$", "results", ",", "$", "name", ")", ";", "}" ]
Eagerly load the relationship on a set of entities. @param array $results @param string $name @param \Closure $constraints @return array
[ "Eagerly", "load", "the", "relationship", "on", "a", "set", "of", "entities", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Builders/ResultBuilder.php#L234-L249
analogueorm/analogue
src/System/Builders/ResultBuilder.php
ResultBuilder.getRelation
public function getRelation(string $relation) : Relationship { // We want to run a relationship query without any constrains so that we will // not have to remove these where clauses manually which gets really hacky // and is error prone while we remove the developer's own where clauses. $query = Relationship::noConstraints(function () use ($relation) { return $this->entityMap->$relation($this->mapper->newInstance()); }); $nested = $this->nestedRelations($relation); // If there are nested relationships set on the query, we will put those onto // the query instances so that they can be handled after this relationship // is loaded. In this way they will all trickle down as they are loaded. if (count($nested) > 0) { $query->getQuery()->with($nested); } return $query; }
php
public function getRelation(string $relation) : Relationship { // We want to run a relationship query without any constrains so that we will // not have to remove these where clauses manually which gets really hacky // and is error prone while we remove the developer's own where clauses. $query = Relationship::noConstraints(function () use ($relation) { return $this->entityMap->$relation($this->mapper->newInstance()); }); $nested = $this->nestedRelations($relation); // If there are nested relationships set on the query, we will put those onto // the query instances so that they can be handled after this relationship // is loaded. In this way they will all trickle down as they are loaded. if (count($nested) > 0) { $query->getQuery()->with($nested); } return $query; }
[ "public", "function", "getRelation", "(", "string", "$", "relation", ")", ":", "Relationship", "{", "// We want to run a relationship query without any constrains so that we will", "// not have to remove these where clauses manually which gets really hacky", "// and is error prone while we remove the developer's own where clauses.", "$", "query", "=", "Relationship", "::", "noConstraints", "(", "function", "(", ")", "use", "(", "$", "relation", ")", "{", "return", "$", "this", "->", "entityMap", "->", "$", "relation", "(", "$", "this", "->", "mapper", "->", "newInstance", "(", ")", ")", ";", "}", ")", ";", "$", "nested", "=", "$", "this", "->", "nestedRelations", "(", "$", "relation", ")", ";", "// If there are nested relationships set on the query, we will put those onto", "// the query instances so that they can be handled after this relationship", "// is loaded. In this way they will all trickle down as they are loaded.", "if", "(", "count", "(", "$", "nested", ")", ">", "0", ")", "{", "$", "query", "->", "getQuery", "(", ")", "->", "with", "(", "$", "nested", ")", ";", "}", "return", "$", "query", ";", "}" ]
Get the relation instance for the given relation name. @param string $relation @return \Analogue\ORM\Relationships\Relationship
[ "Get", "the", "relation", "instance", "for", "the", "given", "relation", "name", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Builders/ResultBuilder.php#L258-L277
analogueorm/analogue
src/System/Builders/ResultBuilder.php
ResultBuilder.nestedRelations
protected function nestedRelations(string $relation): array { $nested = []; // We are basically looking for any relationships that are nested deeper than // the given top-level relationship. We will just check for any relations // that start with the given top relations and adds them to our arrays. foreach ($this->eagerLoads as $name => $constraints) { if ($this->isNested($name, $relation)) { $nested[substr($name, strlen($relation.'.'))] = $constraints; } } return $nested; }
php
protected function nestedRelations(string $relation): array { $nested = []; // We are basically looking for any relationships that are nested deeper than // the given top-level relationship. We will just check for any relations // that start with the given top relations and adds them to our arrays. foreach ($this->eagerLoads as $name => $constraints) { if ($this->isNested($name, $relation)) { $nested[substr($name, strlen($relation.'.'))] = $constraints; } } return $nested; }
[ "protected", "function", "nestedRelations", "(", "string", "$", "relation", ")", ":", "array", "{", "$", "nested", "=", "[", "]", ";", "// We are basically looking for any relationships that are nested deeper than", "// the given top-level relationship. We will just check for any relations", "// that start with the given top relations and adds them to our arrays.", "foreach", "(", "$", "this", "->", "eagerLoads", "as", "$", "name", "=>", "$", "constraints", ")", "{", "if", "(", "$", "this", "->", "isNested", "(", "$", "name", ",", "$", "relation", ")", ")", "{", "$", "nested", "[", "substr", "(", "$", "name", ",", "strlen", "(", "$", "relation", ".", "'.'", ")", ")", "]", "=", "$", "constraints", ";", "}", "}", "return", "$", "nested", ";", "}" ]
Get the deeply nested relations for a given top-level relation. @param string $relation @return array
[ "Get", "the", "deeply", "nested", "relations", "for", "a", "given", "top", "-", "level", "relation", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Builders/ResultBuilder.php#L286-L300
analogueorm/analogue
src/System/Builders/ResultBuilder.php
ResultBuilder.isNested
protected function isNested(string $name, string $relation): bool { $dots = str_contains($name, '.'); return $dots && starts_with($name, $relation.'.'); }
php
protected function isNested(string $name, string $relation): bool { $dots = str_contains($name, '.'); return $dots && starts_with($name, $relation.'.'); }
[ "protected", "function", "isNested", "(", "string", "$", "name", ",", "string", "$", "relation", ")", ":", "bool", "{", "$", "dots", "=", "str_contains", "(", "$", "name", ",", "'.'", ")", ";", "return", "$", "dots", "&&", "starts_with", "(", "$", "name", ",", "$", "relation", ".", "'.'", ")", ";", "}" ]
Determine if the relationship is nested. @param string $name @param string $relation @return bool
[ "Determine", "if", "the", "relationship", "is", "nested", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Builders/ResultBuilder.php#L310-L315
analogueorm/analogue
src/System/Builders/ResultBuilder.php
ResultBuilder.buildUnkeyedResultSet
protected function buildUnkeyedResultSet(array $results) : array { $builder = new EntityBuilder($this->mapper, array_keys($this->eagerLoads), $this->useCache); return array_map(function ($item) use ($builder) { return $builder->build($item); }, $results); }
php
protected function buildUnkeyedResultSet(array $results) : array { $builder = new EntityBuilder($this->mapper, array_keys($this->eagerLoads), $this->useCache); return array_map(function ($item) use ($builder) { return $builder->build($item); }, $results); }
[ "protected", "function", "buildUnkeyedResultSet", "(", "array", "$", "results", ")", ":", "array", "{", "$", "builder", "=", "new", "EntityBuilder", "(", "$", "this", "->", "mapper", ",", "array_keys", "(", "$", "this", "->", "eagerLoads", ")", ",", "$", "this", "->", "useCache", ")", ";", "return", "array_map", "(", "function", "(", "$", "item", ")", "use", "(", "$", "builder", ")", "{", "return", "$", "builder", "->", "build", "(", "$", "item", ")", ";", "}", ",", "$", "results", ")", ";", "}" ]
Build a result set. @param array $results @return array
[ "Build", "a", "result", "set", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Builders/ResultBuilder.php#L336-L343
analogueorm/analogue
src/System/Builders/ResultBuilder.php
ResultBuilder.buildKeyedResultSet
protected function buildKeyedResultSet(array $results, string $primaryKey) : array { $builder = new EntityBuilder($this->mapper, array_keys($this->eagerLoads), $this->useCache); $keys = array_map(function ($item) use ($primaryKey) { return $item[$primaryKey]; }, $results); return array_combine($keys, array_map(function ($item) use ($builder) { return $builder->build($item); }, $results)); }
php
protected function buildKeyedResultSet(array $results, string $primaryKey) : array { $builder = new EntityBuilder($this->mapper, array_keys($this->eagerLoads), $this->useCache); $keys = array_map(function ($item) use ($primaryKey) { return $item[$primaryKey]; }, $results); return array_combine($keys, array_map(function ($item) use ($builder) { return $builder->build($item); }, $results)); }
[ "protected", "function", "buildKeyedResultSet", "(", "array", "$", "results", ",", "string", "$", "primaryKey", ")", ":", "array", "{", "$", "builder", "=", "new", "EntityBuilder", "(", "$", "this", "->", "mapper", ",", "array_keys", "(", "$", "this", "->", "eagerLoads", ")", ",", "$", "this", "->", "useCache", ")", ";", "$", "keys", "=", "array_map", "(", "function", "(", "$", "item", ")", "use", "(", "$", "primaryKey", ")", "{", "return", "$", "item", "[", "$", "primaryKey", "]", ";", "}", ",", "$", "results", ")", ";", "return", "array_combine", "(", "$", "keys", ",", "array_map", "(", "function", "(", "$", "item", ")", "use", "(", "$", "builder", ")", "{", "return", "$", "builder", "->", "build", "(", "$", "item", ")", ";", "}", ",", "$", "results", ")", ")", ";", "}" ]
Build a result set keyed by PK. @param array $results @param string. $primaryKey @return array
[ "Build", "a", "result", "set", "keyed", "by", "PK", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Builders/ResultBuilder.php#L353-L364
analogueorm/analogue
src/System/Cache/AttributeCache.php
AttributeCache.add
public function add(array $results) { $cachedResults = []; $keyColumn = $this->entityMap->getKeyName(); foreach ($results as $result) { $id = $result[$keyColumn]; // Forget the ID field from the cache attributes // to prevent any side effect. // TODO : remove primary key check from dirty attributes parsing //unset($result[$keyColumn]); $cachedResults[$id] = $this->rawResult($result); } if (empty($this->cache)) { $this->cache = $cachedResults; } else { $this->mergeCacheResults($cachedResults); } }
php
public function add(array $results) { $cachedResults = []; $keyColumn = $this->entityMap->getKeyName(); foreach ($results as $result) { $id = $result[$keyColumn]; // Forget the ID field from the cache attributes // to prevent any side effect. // TODO : remove primary key check from dirty attributes parsing //unset($result[$keyColumn]); $cachedResults[$id] = $this->rawResult($result); } if (empty($this->cache)) { $this->cache = $cachedResults; } else { $this->mergeCacheResults($cachedResults); } }
[ "public", "function", "add", "(", "array", "$", "results", ")", "{", "$", "cachedResults", "=", "[", "]", ";", "$", "keyColumn", "=", "$", "this", "->", "entityMap", "->", "getKeyName", "(", ")", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "id", "=", "$", "result", "[", "$", "keyColumn", "]", ";", "// Forget the ID field from the cache attributes", "// to prevent any side effect.", "// TODO : remove primary key check from dirty attributes parsing", "//unset($result[$keyColumn]);", "$", "cachedResults", "[", "$", "id", "]", "=", "$", "this", "->", "rawResult", "(", "$", "result", ")", ";", "}", "if", "(", "empty", "(", "$", "this", "->", "cache", ")", ")", "{", "$", "this", "->", "cache", "=", "$", "cachedResults", ";", "}", "else", "{", "$", "this", "->", "mergeCacheResults", "(", "$", "cachedResults", ")", ";", "}", "}" ]
Add an array of key=>attributes representing the initial state of loaded entities. @param array $results
[ "Add", "an", "array", "of", "key", "=", ">", "attributes", "representing", "the", "initial", "state", "of", "loaded", "entities", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/AttributeCache.php#L74-L95
analogueorm/analogue
src/System/Cache/AttributeCache.php
AttributeCache.get
public function get(string $id = null): array { if ($this->has($id)) { return $this->cache[$id]; } return []; }
php
public function get(string $id = null): array { if ($this->has($id)) { return $this->cache[$id]; } return []; }
[ "public", "function", "get", "(", "string", "$", "id", "=", "null", ")", ":", "array", "{", "if", "(", "$", "this", "->", "has", "(", "$", "id", ")", ")", "{", "return", "$", "this", "->", "cache", "[", "$", "id", "]", ";", "}", "return", "[", "]", ";", "}" ]
Retrieve initial attributes for a single entity. @param string $id @return array
[ "Retrieve", "initial", "attributes", "for", "a", "single", "entity", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/AttributeCache.php#L120-L127
analogueorm/analogue
src/System/Cache/AttributeCache.php
AttributeCache.mergeCacheResults
protected function mergeCacheResults(array $results) { foreach ($results as $key => $entity) { $this->cache[$key] = $entity; } }
php
protected function mergeCacheResults(array $results) { foreach ($results as $key => $entity) { $this->cache[$key] = $entity; } }
[ "protected", "function", "mergeCacheResults", "(", "array", "$", "results", ")", "{", "foreach", "(", "$", "results", "as", "$", "key", "=>", "$", "entity", ")", "{", "$", "this", "->", "cache", "[", "$", "key", "]", "=", "$", "entity", ";", "}", "}" ]
Combine new result set with existing attributes in cache. @param array $results @return void
[ "Combine", "new", "result", "set", "with", "existing", "attributes", "in", "cache", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/AttributeCache.php#L149-L154
analogueorm/analogue
src/System/Cache/AttributeCache.php
AttributeCache.cacheLoadedRelationResult
public function cacheLoadedRelationResult(string $key, string $relation, $results, Relationship $relationship) { if ($results instanceof EntityCollection) { $this->cacheManyRelationResults($key, $relation, $results, $relationship); } // TODO : As we support popo Entities, Maybe this check isn't needed anymore, // or we have to check that $result is an object instead if ($results instanceof Mappable) { $this->cacheSingleRelationResult($key, $relation, $results, $relationship); } }
php
public function cacheLoadedRelationResult(string $key, string $relation, $results, Relationship $relationship) { if ($results instanceof EntityCollection) { $this->cacheManyRelationResults($key, $relation, $results, $relationship); } // TODO : As we support popo Entities, Maybe this check isn't needed anymore, // or we have to check that $result is an object instead if ($results instanceof Mappable) { $this->cacheSingleRelationResult($key, $relation, $results, $relationship); } }
[ "public", "function", "cacheLoadedRelationResult", "(", "string", "$", "key", ",", "string", "$", "relation", ",", "$", "results", ",", "Relationship", "$", "relationship", ")", "{", "if", "(", "$", "results", "instanceof", "EntityCollection", ")", "{", "$", "this", "->", "cacheManyRelationResults", "(", "$", "key", ",", "$", "relation", ",", "$", "results", ",", "$", "relationship", ")", ";", "}", "// TODO : As we support popo Entities, Maybe this check isn't needed anymore,", "// or we have to check that $result is an object instead", "if", "(", "$", "results", "instanceof", "Mappable", ")", "{", "$", "this", "->", "cacheSingleRelationResult", "(", "$", "key", ",", "$", "relation", ",", "$", "results", ",", "$", "relationship", ")", ";", "}", "}" ]
Cache Relation's query result for an entity. @param string $key primary key of the cached entity @param string $relation name of the relation @param mixed $results results of the relationship's query @param Relationship $relationship @throws MappingException @return void
[ "Cache", "Relation", "s", "query", "result", "for", "an", "entity", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/AttributeCache.php#L168-L179
analogueorm/analogue
src/System/Cache/AttributeCache.php
AttributeCache.getCachedRelationship
protected function getCachedRelationship(string $relation, $result, Relationship $relationship) { $pivotColumns = $relationship->getPivotAttributes(); if (!array_key_exists($relation, $this->pivotAttributes)) { $this->pivotAttributes[$relation] = $pivotColumns; } $wrapper = $this->factory->make($result); $hash = $wrapper->getEntityHash(); if (count($pivotColumns) > 0) { $pivotAttributes = []; foreach ($pivotColumns as $column) { $pivot = $wrapper->getEntityAttribute('pivot'); $pivotWrapper = $this->factory->make($pivot); $pivotAttributes[$column] = $pivotWrapper->getEntityAttribute($column); } $cachedRelationship = new CachedRelationship($hash, $pivotAttributes); } else { $cachedRelationship = new CachedRelationship($hash); } return $cachedRelationship; }
php
protected function getCachedRelationship(string $relation, $result, Relationship $relationship) { $pivotColumns = $relationship->getPivotAttributes(); if (!array_key_exists($relation, $this->pivotAttributes)) { $this->pivotAttributes[$relation] = $pivotColumns; } $wrapper = $this->factory->make($result); $hash = $wrapper->getEntityHash(); if (count($pivotColumns) > 0) { $pivotAttributes = []; foreach ($pivotColumns as $column) { $pivot = $wrapper->getEntityAttribute('pivot'); $pivotWrapper = $this->factory->make($pivot); $pivotAttributes[$column] = $pivotWrapper->getEntityAttribute($column); } $cachedRelationship = new CachedRelationship($hash, $pivotAttributes); } else { $cachedRelationship = new CachedRelationship($hash); } return $cachedRelationship; }
[ "protected", "function", "getCachedRelationship", "(", "string", "$", "relation", ",", "$", "result", ",", "Relationship", "$", "relationship", ")", "{", "$", "pivotColumns", "=", "$", "relationship", "->", "getPivotAttributes", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "relation", ",", "$", "this", "->", "pivotAttributes", ")", ")", "{", "$", "this", "->", "pivotAttributes", "[", "$", "relation", "]", "=", "$", "pivotColumns", ";", "}", "$", "wrapper", "=", "$", "this", "->", "factory", "->", "make", "(", "$", "result", ")", ";", "$", "hash", "=", "$", "wrapper", "->", "getEntityHash", "(", ")", ";", "if", "(", "count", "(", "$", "pivotColumns", ")", ">", "0", ")", "{", "$", "pivotAttributes", "=", "[", "]", ";", "foreach", "(", "$", "pivotColumns", "as", "$", "column", ")", "{", "$", "pivot", "=", "$", "wrapper", "->", "getEntityAttribute", "(", "'pivot'", ")", ";", "$", "pivotWrapper", "=", "$", "this", "->", "factory", "->", "make", "(", "$", "pivot", ")", ";", "$", "pivotAttributes", "[", "$", "column", "]", "=", "$", "pivotWrapper", "->", "getEntityAttribute", "(", "$", "column", ")", ";", "}", "$", "cachedRelationship", "=", "new", "CachedRelationship", "(", "$", "hash", ",", "$", "pivotAttributes", ")", ";", "}", "else", "{", "$", "cachedRelationship", "=", "new", "CachedRelationship", "(", "$", "hash", ")", ";", "}", "return", "$", "cachedRelationship", ";", "}" ]
Create a cachedRelationship instance which will hold related entity's hash and pivot attributes, if any. @param string $relation @param array $result @param Relationship $relationship @throws MappingException @return CachedRelationship
[ "Create", "a", "cachedRelationship", "instance", "which", "will", "hold", "related", "entity", "s", "hash", "and", "pivot", "attributes", "if", "any", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/AttributeCache.php#L192-L220
analogueorm/analogue
src/System/Cache/AttributeCache.php
AttributeCache.cacheManyRelationResults
protected function cacheManyRelationResults(string $parentKey, string $relation, $results, Relationship $relationship) { $this->cache[$parentKey][$relation] = []; foreach ($results as $result) { $cachedRelationship = $this->getCachedRelationship($relation, $result, $relationship); $relatedHash = $cachedRelationship->getHash(); $this->cache[$parentKey][$relation][$relatedHash] = $cachedRelationship; } }
php
protected function cacheManyRelationResults(string $parentKey, string $relation, $results, Relationship $relationship) { $this->cache[$parentKey][$relation] = []; foreach ($results as $result) { $cachedRelationship = $this->getCachedRelationship($relation, $result, $relationship); $relatedHash = $cachedRelationship->getHash(); $this->cache[$parentKey][$relation][$relatedHash] = $cachedRelationship; } }
[ "protected", "function", "cacheManyRelationResults", "(", "string", "$", "parentKey", ",", "string", "$", "relation", ",", "$", "results", ",", "Relationship", "$", "relationship", ")", "{", "$", "this", "->", "cache", "[", "$", "parentKey", "]", "[", "$", "relation", "]", "=", "[", "]", ";", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "$", "cachedRelationship", "=", "$", "this", "->", "getCachedRelationship", "(", "$", "relation", ",", "$", "result", ",", "$", "relationship", ")", ";", "$", "relatedHash", "=", "$", "cachedRelationship", "->", "getHash", "(", ")", ";", "$", "this", "->", "cache", "[", "$", "parentKey", "]", "[", "$", "relation", "]", "[", "$", "relatedHash", "]", "=", "$", "cachedRelationship", ";", "}", "}" ]
Cache a many relationship. @param string $parentKey @param string $relation @param EntityCollection $results @param Relationship $relationship @throws MappingException
[ "Cache", "a", "many", "relationship", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/AttributeCache.php#L232-L243
analogueorm/analogue
src/System/Cache/AttributeCache.php
AttributeCache.cacheSingleRelationResult
protected function cacheSingleRelationResult(string $parentKey, string $relation, $result, Relationship $relationship) { $this->cache[$parentKey][$relation] = $this->getCachedRelationship($relation, $result, $relationship); }
php
protected function cacheSingleRelationResult(string $parentKey, string $relation, $result, Relationship $relationship) { $this->cache[$parentKey][$relation] = $this->getCachedRelationship($relation, $result, $relationship); }
[ "protected", "function", "cacheSingleRelationResult", "(", "string", "$", "parentKey", ",", "string", "$", "relation", ",", "$", "result", ",", "Relationship", "$", "relationship", ")", "{", "$", "this", "->", "cache", "[", "$", "parentKey", "]", "[", "$", "relation", "]", "=", "$", "this", "->", "getCachedRelationship", "(", "$", "relation", ",", "$", "result", ",", "$", "relationship", ")", ";", "}" ]
Cache a single relationship. @param string $parentKey @param string $relation @param Mappable $result @param Relationship $relationship @throws MappingException
[ "Cache", "a", "single", "relationship", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/AttributeCache.php#L255-L258
analogueorm/analogue
src/System/Cache/AttributeCache.php
AttributeCache.getEntityHash
protected function getEntityHash(InternallyMappable $entity): string { $class = $entity->getEntityClass(); $mapper = Manager::getMapper($class); $keyName = $mapper->getEntityMap()->getKeyName(); return $class.'.'.$entity->getEntityAttribute($keyName); }
php
protected function getEntityHash(InternallyMappable $entity): string { $class = $entity->getEntityClass(); $mapper = Manager::getMapper($class); $keyName = $mapper->getEntityMap()->getKeyName(); return $class.'.'.$entity->getEntityAttribute($keyName); }
[ "protected", "function", "getEntityHash", "(", "InternallyMappable", "$", "entity", ")", ":", "string", "{", "$", "class", "=", "$", "entity", "->", "getEntityClass", "(", ")", ";", "$", "mapper", "=", "Manager", "::", "getMapper", "(", "$", "class", ")", ";", "$", "keyName", "=", "$", "mapper", "->", "getEntityMap", "(", ")", "->", "getKeyName", "(", ")", ";", "return", "$", "class", ".", "'.'", ".", "$", "entity", "->", "getEntityAttribute", "(", "$", "keyName", ")", ";", "}" ]
Get Entity's Hash. @param $entity @throws MappingException @return string
[ "Get", "Entity", "s", "Hash", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/AttributeCache.php#L269-L278
analogueorm/analogue
src/System/Cache/AttributeCache.php
AttributeCache.refresh
public function refresh(Aggregate $entity) { $this->cache[$entity->getEntityKeyValue()] = $this->transform($entity); }
php
public function refresh(Aggregate $entity) { $this->cache[$entity->getEntityKeyValue()] = $this->transform($entity); }
[ "public", "function", "refresh", "(", "Aggregate", "$", "entity", ")", "{", "$", "this", "->", "cache", "[", "$", "entity", "->", "getEntityKeyValue", "(", ")", "]", "=", "$", "this", "->", "transform", "(", "$", "entity", ")", ";", "}" ]
Refresh the cache record for an aggregated entity after a write operation. @param Aggregate $entity
[ "Refresh", "the", "cache", "record", "for", "an", "aggregated", "entity", "after", "a", "write", "operation", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/AttributeCache.php#L285-L288
analogueorm/analogue
src/System/Cache/AttributeCache.php
AttributeCache.transform
protected function transform(Aggregate $aggregatedEntity): array { $baseAttributes = $aggregatedEntity->getRawAttributes(); $relationAttributes = []; // First we'll handle each relationships that are a one to one // relation, and which will be saved as a CachedRelationship // object inside the cache. // NOTE : storing localRelationships maybe useless has we store // the foreign key in the attributes already. foreach ($this->entityMap->getSingleRelationships() as $relation) { $aggregates = $aggregatedEntity->getRelationship($relation); if (count($aggregates) == 1) { $related = $aggregates[0]; $relationAttributes[$relation] = new CachedRelationship($related->getEntityHash()); } if (count($aggregates) > 1) { throw new MappingException("Single Relationship '$relation' contains several related entities"); } } // Then we'll handle the 'many' relationships and store them as // an array of CachedRelationship objects. foreach ($this->entityMap->getManyRelationships() as $relation) { $aggregates = $aggregatedEntity->getRelationship($relation); $relationAttributes[$relation] = []; foreach ($aggregates as $aggregate) { $relationAttributes[$relation][] = new CachedRelationship( $aggregate->getEntityHash(), $aggregate->getPivotAttributes() ); } } return $baseAttributes + $relationAttributes; }
php
protected function transform(Aggregate $aggregatedEntity): array { $baseAttributes = $aggregatedEntity->getRawAttributes(); $relationAttributes = []; // First we'll handle each relationships that are a one to one // relation, and which will be saved as a CachedRelationship // object inside the cache. // NOTE : storing localRelationships maybe useless has we store // the foreign key in the attributes already. foreach ($this->entityMap->getSingleRelationships() as $relation) { $aggregates = $aggregatedEntity->getRelationship($relation); if (count($aggregates) == 1) { $related = $aggregates[0]; $relationAttributes[$relation] = new CachedRelationship($related->getEntityHash()); } if (count($aggregates) > 1) { throw new MappingException("Single Relationship '$relation' contains several related entities"); } } // Then we'll handle the 'many' relationships and store them as // an array of CachedRelationship objects. foreach ($this->entityMap->getManyRelationships() as $relation) { $aggregates = $aggregatedEntity->getRelationship($relation); $relationAttributes[$relation] = []; foreach ($aggregates as $aggregate) { $relationAttributes[$relation][] = new CachedRelationship( $aggregate->getEntityHash(), $aggregate->getPivotAttributes() ); } } return $baseAttributes + $relationAttributes; }
[ "protected", "function", "transform", "(", "Aggregate", "$", "aggregatedEntity", ")", ":", "array", "{", "$", "baseAttributes", "=", "$", "aggregatedEntity", "->", "getRawAttributes", "(", ")", ";", "$", "relationAttributes", "=", "[", "]", ";", "// First we'll handle each relationships that are a one to one", "// relation, and which will be saved as a CachedRelationship", "// object inside the cache.", "// NOTE : storing localRelationships maybe useless has we store", "// the foreign key in the attributes already.", "foreach", "(", "$", "this", "->", "entityMap", "->", "getSingleRelationships", "(", ")", "as", "$", "relation", ")", "{", "$", "aggregates", "=", "$", "aggregatedEntity", "->", "getRelationship", "(", "$", "relation", ")", ";", "if", "(", "count", "(", "$", "aggregates", ")", "==", "1", ")", "{", "$", "related", "=", "$", "aggregates", "[", "0", "]", ";", "$", "relationAttributes", "[", "$", "relation", "]", "=", "new", "CachedRelationship", "(", "$", "related", "->", "getEntityHash", "(", ")", ")", ";", "}", "if", "(", "count", "(", "$", "aggregates", ")", ">", "1", ")", "{", "throw", "new", "MappingException", "(", "\"Single Relationship '$relation' contains several related entities\"", ")", ";", "}", "}", "// Then we'll handle the 'many' relationships and store them as", "// an array of CachedRelationship objects.", "foreach", "(", "$", "this", "->", "entityMap", "->", "getManyRelationships", "(", ")", "as", "$", "relation", ")", "{", "$", "aggregates", "=", "$", "aggregatedEntity", "->", "getRelationship", "(", "$", "relation", ")", ";", "$", "relationAttributes", "[", "$", "relation", "]", "=", "[", "]", ";", "foreach", "(", "$", "aggregates", "as", "$", "aggregate", ")", "{", "$", "relationAttributes", "[", "$", "relation", "]", "[", "]", "=", "new", "CachedRelationship", "(", "$", "aggregate", "->", "getEntityHash", "(", ")", ",", "$", "aggregate", "->", "getPivotAttributes", "(", ")", ")", ";", "}", "}", "return", "$", "baseAttributes", "+", "$", "relationAttributes", ";", "}" ]
Transform an Aggregated Entity into a cache record. @param Aggregate $aggregatedEntity @throws MappingException @return array
[ "Transform", "an", "Aggregated", "Entity", "into", "a", "cache", "record", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/AttributeCache.php#L299-L341
analogueorm/analogue
src/System/Cache/AttributeCache.php
AttributeCache.getPivotValues
protected function getPivotValues(string $relation, InternallyMappable $entity): array { $values = []; $entityAttributes = $entity->getEntityAttributes(); if (array_key_exists($relation, $this->pivotAttributes)) { foreach ($this->pivotAttributes[$relation] as $attribute) { if (array_key_exists($attribute, $entityAttributes)) { $values[$attribute] = $entity->getEntityAttribute('pivot')->$attribute; } } } return $values; }
php
protected function getPivotValues(string $relation, InternallyMappable $entity): array { $values = []; $entityAttributes = $entity->getEntityAttributes(); if (array_key_exists($relation, $this->pivotAttributes)) { foreach ($this->pivotAttributes[$relation] as $attribute) { if (array_key_exists($attribute, $entityAttributes)) { $values[$attribute] = $entity->getEntityAttribute('pivot')->$attribute; } } } return $values; }
[ "protected", "function", "getPivotValues", "(", "string", "$", "relation", ",", "InternallyMappable", "$", "entity", ")", ":", "array", "{", "$", "values", "=", "[", "]", ";", "$", "entityAttributes", "=", "$", "entity", "->", "getEntityAttributes", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "relation", ",", "$", "this", "->", "pivotAttributes", ")", ")", "{", "foreach", "(", "$", "this", "->", "pivotAttributes", "[", "$", "relation", "]", "as", "$", "attribute", ")", "{", "if", "(", "array_key_exists", "(", "$", "attribute", ",", "$", "entityAttributes", ")", ")", "{", "$", "values", "[", "$", "attribute", "]", "=", "$", "entity", "->", "getEntityAttribute", "(", "'pivot'", ")", "->", "$", "attribute", ";", "}", "}", "}", "return", "$", "values", ";", "}" ]
Get pivot attributes for a relation. @param string $relation @param InternallyMappable $entity @return array
[ "Get", "pivot", "attributes", "for", "a", "relation", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Cache/AttributeCache.php#L351-L366
analogueorm/analogue
src/Relationships/BelongsTo.php
BelongsTo.getResults
public function getResults($relation) { $result = $this->query->first(); $this->cacheRelation($result, $relation); return $result; }
php
public function getResults($relation) { $result = $this->query->first(); $this->cacheRelation($result, $relation); return $result; }
[ "public", "function", "getResults", "(", "$", "relation", ")", "{", "$", "result", "=", "$", "this", "->", "query", "->", "first", "(", ")", ";", "$", "this", "->", "cacheRelation", "(", "$", "result", ",", "$", "relation", ")", ";", "return", "$", "result", ";", "}" ]
Get the results of the relationship. @param $relation @return \Analogue\ORM\Entity
[ "Get", "the", "results", "of", "the", "relationship", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsTo.php#L59-L66
analogueorm/analogue
src/Relationships/BelongsTo.php
BelongsTo.getRelationCountQuery
public function getRelationCountQuery(Query $query, Query $parent) { $query->select(new Expression('count(*)')); $otherKey = $this->wrap($query->getTable().'.'.$this->otherKey); return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey)); }
php
public function getRelationCountQuery(Query $query, Query $parent) { $query->select(new Expression('count(*)')); $otherKey = $this->wrap($query->getTable().'.'.$this->otherKey); return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey)); }
[ "public", "function", "getRelationCountQuery", "(", "Query", "$", "query", ",", "Query", "$", "parent", ")", "{", "$", "query", "->", "select", "(", "new", "Expression", "(", "'count(*)'", ")", ")", ";", "$", "otherKey", "=", "$", "this", "->", "wrap", "(", "$", "query", "->", "getTable", "(", ")", ".", "'.'", ".", "$", "this", "->", "otherKey", ")", ";", "return", "$", "query", "->", "where", "(", "$", "this", "->", "getQualifiedForeignKey", "(", ")", ",", "'='", ",", "new", "Expression", "(", "$", "otherKey", ")", ")", ";", "}" ]
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/BelongsTo.php#L91-L98
analogueorm/analogue
src/Relationships/BelongsTo.php
BelongsTo.addEagerConstraints
public function addEagerConstraints(array $results) { // We'll grab the primary key name of the related models since it could be set to // a non-standard name and not "id". We will then construct the constraint for // our eagerly loading query so it returns the proper models from execution. $key = $this->otherKey; $this->query->whereIn($key, $this->getEagerModelKeys($results)); }
php
public function addEagerConstraints(array $results) { // We'll grab the primary key name of the related models since it could be set to // a non-standard name and not "id". We will then construct the constraint for // our eagerly loading query so it returns the proper models from execution. $key = $this->otherKey; $this->query->whereIn($key, $this->getEagerModelKeys($results)); }
[ "public", "function", "addEagerConstraints", "(", "array", "$", "results", ")", "{", "// We'll grab the primary key name of the related models since it could be set to", "// a non-standard name and not \"id\". We will then construct the constraint for", "// our eagerly loading query so it returns the proper models from execution.", "$", "key", "=", "$", "this", "->", "otherKey", ";", "$", "this", "->", "query", "->", "whereIn", "(", "$", "key", ",", "$", "this", "->", "getEagerModelKeys", "(", "$", "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/BelongsTo.php#L107-L115
analogueorm/analogue
src/Relationships/BelongsTo.php
BelongsTo.getEagerModelKeys
protected function getEagerModelKeys(array $results) { $keys = []; // First we need to gather all of the keys from the result set so we know what // to query for via the eager loading query. We will add them to an array then // execute a "where in" statement to gather up all of those related records. foreach ($results as $result) { if (array_key_exists($this->foreignKey, $result) && !is_null($value = $result[$this->foreignKey])) { $keys[] = $value; } } // If there are no keys that were not null we will just return an array with 0 in // it so the query doesn't fail, but will not return any results, which should // be what this developer is expecting in a case where this happens to them. if (count($keys) == 0) { return [0]; } return array_values(array_unique($keys)); }
php
protected function getEagerModelKeys(array $results) { $keys = []; // First we need to gather all of the keys from the result set so we know what // to query for via the eager loading query. We will add them to an array then // execute a "where in" statement to gather up all of those related records. foreach ($results as $result) { if (array_key_exists($this->foreignKey, $result) && !is_null($value = $result[$this->foreignKey])) { $keys[] = $value; } } // If there are no keys that were not null we will just return an array with 0 in // it so the query doesn't fail, but will not return any results, which should // be what this developer is expecting in a case where this happens to them. if (count($keys) == 0) { return [0]; } return array_values(array_unique($keys)); }
[ "protected", "function", "getEagerModelKeys", "(", "array", "$", "results", ")", "{", "$", "keys", "=", "[", "]", ";", "// First we need to gather all of the keys from the result set so we know what", "// to query for via the eager loading query. We will add them to an array then", "// execute a \"where in\" statement to gather up all of those related records.", "foreach", "(", "$", "results", "as", "$", "result", ")", "{", "if", "(", "array_key_exists", "(", "$", "this", "->", "foreignKey", ",", "$", "result", ")", "&&", "!", "is_null", "(", "$", "value", "=", "$", "result", "[", "$", "this", "->", "foreignKey", "]", ")", ")", "{", "$", "keys", "[", "]", "=", "$", "value", ";", "}", "}", "// If there are no keys that were not null we will just return an array with 0 in", "// it so the query doesn't fail, but will not return any results, which should", "// be what this developer is expecting in a case where this happens to them.", "if", "(", "count", "(", "$", "keys", ")", "==", "0", ")", "{", "return", "[", "0", "]", ";", "}", "return", "array_values", "(", "array_unique", "(", "$", "keys", ")", ")", ";", "}" ]
Gather the keys from an array of related models. @param array $results @return array
[ "Gather", "the", "keys", "from", "an", "array", "of", "related", "models", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsTo.php#L124-L145
analogueorm/analogue
src/Relationships/BelongsTo.php
BelongsTo.match
public function match(array $results, $relation) { $foreign = $this->foreignKey; $other = $this->otherKey; // Execute the relationship and get related entities as an EntityCollection $entities = $this->getEager(); // First we will get to build a dictionary of the child models by their primary // key of the relationship, then we can easily match the children back onto // the parents using that dictionary and the primary key of the children. $dictionary = []; // TODO ; see if otherKey is the primary key of the related entity, we can // simply use the EntityCollection key to match entities to results, which // will be much more efficient, and use this method as a fallback if the // otherKey is not the same as the primary Key. foreach ($entities as $entity) { $entity = $this->factory->make($entity); $dictionary[$entity->getEntityAttribute($other)] = $entity->getObject(); } // Once we have the dictionary constructed, we can loop through all the parents // and match back onto their children using these keys of the dictionary and // the primary key of the children to map them onto the correct instances. return array_map(function ($result) use ($dictionary, $foreign, $relation) { if (array_key_exists($foreign, $result) && isset($dictionary[$result[$foreign]])) { $result[$relation] = $dictionary[$result[$foreign]]; } else { $result[$relation] = null; } return $result; }, $results); }
php
public function match(array $results, $relation) { $foreign = $this->foreignKey; $other = $this->otherKey; // Execute the relationship and get related entities as an EntityCollection $entities = $this->getEager(); // First we will get to build a dictionary of the child models by their primary // key of the relationship, then we can easily match the children back onto // the parents using that dictionary and the primary key of the children. $dictionary = []; // TODO ; see if otherKey is the primary key of the related entity, we can // simply use the EntityCollection key to match entities to results, which // will be much more efficient, and use this method as a fallback if the // otherKey is not the same as the primary Key. foreach ($entities as $entity) { $entity = $this->factory->make($entity); $dictionary[$entity->getEntityAttribute($other)] = $entity->getObject(); } // Once we have the dictionary constructed, we can loop through all the parents // and match back onto their children using these keys of the dictionary and // the primary key of the children to map them onto the correct instances. return array_map(function ($result) use ($dictionary, $foreign, $relation) { if (array_key_exists($foreign, $result) && isset($dictionary[$result[$foreign]])) { $result[$relation] = $dictionary[$result[$foreign]]; } else { $result[$relation] = null; } return $result; }, $results); }
[ "public", "function", "match", "(", "array", "$", "results", ",", "$", "relation", ")", "{", "$", "foreign", "=", "$", "this", "->", "foreignKey", ";", "$", "other", "=", "$", "this", "->", "otherKey", ";", "// Execute the relationship and get related entities as an EntityCollection", "$", "entities", "=", "$", "this", "->", "getEager", "(", ")", ";", "// First we will get to build a dictionary of the child models by their primary", "// key of the relationship, then we can easily match the children back onto", "// the parents using that dictionary and the primary key of the children.", "$", "dictionary", "=", "[", "]", ";", "// TODO ; see if otherKey is the primary key of the related entity, we can", "// simply use the EntityCollection key to match entities to results, which", "// will be much more efficient, and use this method as a fallback if the", "// otherKey is not the same as the primary Key.", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "$", "entity", "=", "$", "this", "->", "factory", "->", "make", "(", "$", "entity", ")", ";", "$", "dictionary", "[", "$", "entity", "->", "getEntityAttribute", "(", "$", "other", ")", "]", "=", "$", "entity", "->", "getObject", "(", ")", ";", "}", "// Once we have the dictionary constructed, we can loop through all the parents", "// and match back onto their children using these keys of the dictionary and", "// the primary key of the children to map them onto the correct instances.", "return", "array_map", "(", "function", "(", "$", "result", ")", "use", "(", "$", "dictionary", ",", "$", "foreign", ",", "$", "relation", ")", "{", "if", "(", "array_key_exists", "(", "$", "foreign", ",", "$", "result", ")", "&&", "isset", "(", "$", "dictionary", "[", "$", "result", "[", "$", "foreign", "]", "]", ")", ")", "{", "$", "result", "[", "$", "relation", "]", "=", "$", "dictionary", "[", "$", "result", "[", "$", "foreign", "]", "]", ";", "}", "else", "{", "$", "result", "[", "$", "relation", "]", "=", "null", ";", "}", "return", "$", "result", ";", "}", ",", "$", "results", ")", ";", "}" ]
Match the Results array to an eagerly loaded relation. @param array $results @param string $relation @return array
[ "Match", "the", "Results", "array", "to", "an", "eagerly", "loaded", "relation", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsTo.php#L155-L190
analogueorm/analogue
src/Relationships/BelongsTo.php
BelongsTo.associate
public function associate($entity) { $this->parent->setEntityAttribute($this->foreignKey, $entity->getEntityAttribute($this->otherKey)); }
php
public function associate($entity) { $this->parent->setEntityAttribute($this->foreignKey, $entity->getEntityAttribute($this->otherKey)); }
[ "public", "function", "associate", "(", "$", "entity", ")", "{", "$", "this", "->", "parent", "->", "setEntityAttribute", "(", "$", "this", "->", "foreignKey", ",", "$", "entity", "->", "getEntityAttribute", "(", "$", "this", "->", "otherKey", ")", ")", ";", "}" ]
Associate the model instance to the given parent. @param mixed $entity @return void
[ "Associate", "the", "model", "instance", "to", "the", "given", "parent", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/BelongsTo.php#L212-L215
analogueorm/analogue
src/MagicCasting.php
MagicCasting.attributesToArray
protected function attributesToArray(array $sourceAttributes) { $attributes = []; foreach ($sourceAttributes as $key => $attribute) { // If the attribute is a proxy, and hasn't be loaded, we discard // it from the returned set. if ($attribute instanceof ProxyInterface && !$attribute->isProxyInitialized()) { continue; } if ($attribute instanceof Carbon) { $attributes[$key] = $attribute->__toString(); continue; } if ($attribute instanceof Arrayable) { $attributes[$key] = $attribute->toArray(); } else { $attributes[$key] = $attribute; } } return $attributes; }
php
protected function attributesToArray(array $sourceAttributes) { $attributes = []; foreach ($sourceAttributes as $key => $attribute) { // If the attribute is a proxy, and hasn't be loaded, we discard // it from the returned set. if ($attribute instanceof ProxyInterface && !$attribute->isProxyInitialized()) { continue; } if ($attribute instanceof Carbon) { $attributes[$key] = $attribute->__toString(); continue; } if ($attribute instanceof Arrayable) { $attributes[$key] = $attribute->toArray(); } else { $attributes[$key] = $attribute; } } return $attributes; }
[ "protected", "function", "attributesToArray", "(", "array", "$", "sourceAttributes", ")", "{", "$", "attributes", "=", "[", "]", ";", "foreach", "(", "$", "sourceAttributes", "as", "$", "key", "=>", "$", "attribute", ")", "{", "// If the attribute is a proxy, and hasn't be loaded, we discard", "// it from the returned set.", "if", "(", "$", "attribute", "instanceof", "ProxyInterface", "&&", "!", "$", "attribute", "->", "isProxyInitialized", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "attribute", "instanceof", "Carbon", ")", "{", "$", "attributes", "[", "$", "key", "]", "=", "$", "attribute", "->", "__toString", "(", ")", ";", "continue", ";", "}", "if", "(", "$", "attribute", "instanceof", "Arrayable", ")", "{", "$", "attributes", "[", "$", "key", "]", "=", "$", "attribute", "->", "toArray", "(", ")", ";", "}", "else", "{", "$", "attributes", "[", "$", "key", "]", "=", "$", "attribute", ";", "}", "}", "return", "$", "attributes", ";", "}" ]
Transform the Object to array/json,. @param array $sourceAttributes @return array
[ "Transform", "the", "Object", "to", "array", "/", "json", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/MagicCasting.php#L99-L123
analogueorm/analogue
src/System/Mapper.php
Mapper.map
public function map($results, array $eagerLoads = [], $useCache = false) : Collection { $builder = $this->newResultBuilder(!$useCache); if ($results instanceof Collection) { // Get underlying collection array $results = $results->all(); } if (!is_array($results)) { throw new InvalidArgumentException("Parameter 'results' should be an array or a collection."); } // First, we'll cast every single result to array $results = array_map(function ($item) { return (array) $item; }, $results); // Then, we'll pass the results to the Driver's provided transformer, so // any DB specific value can be casted before hydration $results = $this->adapter->fromDatabase($results); $entities = $builder->build($results, $eagerLoads); return $this->entityMap->newCollection($entities); }
php
public function map($results, array $eagerLoads = [], $useCache = false) : Collection { $builder = $this->newResultBuilder(!$useCache); if ($results instanceof Collection) { // Get underlying collection array $results = $results->all(); } if (!is_array($results)) { throw new InvalidArgumentException("Parameter 'results' should be an array or a collection."); } // First, we'll cast every single result to array $results = array_map(function ($item) { return (array) $item; }, $results); // Then, we'll pass the results to the Driver's provided transformer, so // any DB specific value can be casted before hydration $results = $this->adapter->fromDatabase($results); $entities = $builder->build($results, $eagerLoads); return $this->entityMap->newCollection($entities); }
[ "public", "function", "map", "(", "$", "results", ",", "array", "$", "eagerLoads", "=", "[", "]", ",", "$", "useCache", "=", "false", ")", ":", "Collection", "{", "$", "builder", "=", "$", "this", "->", "newResultBuilder", "(", "!", "$", "useCache", ")", ";", "if", "(", "$", "results", "instanceof", "Collection", ")", "{", "// Get underlying collection array", "$", "results", "=", "$", "results", "->", "all", "(", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "results", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Parameter 'results' should be an array or a collection.\"", ")", ";", "}", "// First, we'll cast every single result to array", "$", "results", "=", "array_map", "(", "function", "(", "$", "item", ")", "{", "return", "(", "array", ")", "$", "item", ";", "}", ",", "$", "results", ")", ";", "// Then, we'll pass the results to the Driver's provided transformer, so", "// any DB specific value can be casted before hydration", "$", "results", "=", "$", "this", "->", "adapter", "->", "fromDatabase", "(", "$", "results", ")", ";", "$", "entities", "=", "$", "builder", "->", "build", "(", "$", "results", ",", "$", "eagerLoads", ")", ";", "return", "$", "this", "->", "entityMap", "->", "newCollection", "(", "$", "entities", ")", ";", "}" ]
Map results to a Collection. @param array|Collection $results @param array $eagerLoads @param bool $useCache @return Collection
[ "Map", "results", "to", "a", "Collection", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L133-L158
analogueorm/analogue
src/System/Mapper.php
Mapper.newResultBuilder
protected function newResultBuilder(bool $skipCache = false) : ResultBuilderInterface { $factory = new ResultBuilderFactory(); return $factory->make($this, $skipCache); }
php
protected function newResultBuilder(bool $skipCache = false) : ResultBuilderInterface { $factory = new ResultBuilderFactory(); return $factory->make($this, $skipCache); }
[ "protected", "function", "newResultBuilder", "(", "bool", "$", "skipCache", "=", "false", ")", ":", "ResultBuilderInterface", "{", "$", "factory", "=", "new", "ResultBuilderFactory", "(", ")", ";", "return", "$", "factory", "->", "make", "(", "$", "this", ",", "$", "skipCache", ")", ";", "}" ]
Return result builder used by this mapper. @param bool $skipCache @return ResultBuilderInterface
[ "Return", "result", "builder", "used", "by", "this", "mapper", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L167-L172
analogueorm/analogue
src/System/Mapper.php
Mapper.store
public function store($entity) { if ($this->manager->isTraversable($entity)) { return $this->storeCollection($entity); } else { return $this->storeEntity($entity); } }
php
public function store($entity) { if ($this->manager->isTraversable($entity)) { return $this->storeCollection($entity); } else { return $this->storeEntity($entity); } }
[ "public", "function", "store", "(", "$", "entity", ")", "{", "if", "(", "$", "this", "->", "manager", "->", "isTraversable", "(", "$", "entity", ")", ")", "{", "return", "$", "this", "->", "storeCollection", "(", "$", "entity", ")", ";", "}", "else", "{", "return", "$", "this", "->", "storeEntity", "(", "$", "entity", ")", ";", "}", "}" ]
Persist an entity or an entity collection into the database. @param Mappable|\Traversable|array $entity @throws \InvalidArgumentException @throws MappingException @return Mappable|\Traversable|array
[ "Persist", "an", "entity", "or", "an", "entity", "collection", "into", "the", "database", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L194-L201
analogueorm/analogue
src/System/Mapper.php
Mapper.storeCollection
protected function storeCollection($entities) { $this->adapter->beginTransaction(); foreach ($entities as $entity) { $this->storeEntity($entity); } $this->adapter->commit(); return $entities; }
php
protected function storeCollection($entities) { $this->adapter->beginTransaction(); foreach ($entities as $entity) { $this->storeEntity($entity); } $this->adapter->commit(); return $entities; }
[ "protected", "function", "storeCollection", "(", "$", "entities", ")", "{", "$", "this", "->", "adapter", "->", "beginTransaction", "(", ")", ";", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "$", "this", "->", "storeEntity", "(", "$", "entity", ")", ";", "}", "$", "this", "->", "adapter", "->", "commit", "(", ")", ";", "return", "$", "entities", ";", "}" ]
Store an entity collection inside a single DB Transaction. @param \Traversable|array $entities @throws \InvalidArgumentException @throws MappingException @return \Traversable|array
[ "Store", "an", "entity", "collection", "inside", "a", "single", "DB", "Transaction", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L213-L224
analogueorm/analogue
src/System/Mapper.php
Mapper.storeEntity
protected function storeEntity($entity) { $this->checkEntityType($entity); $store = new Store($this->aggregate($entity), $this->newQueryBuilder()); return $store->execute(); }
php
protected function storeEntity($entity) { $this->checkEntityType($entity); $store = new Store($this->aggregate($entity), $this->newQueryBuilder()); return $store->execute(); }
[ "protected", "function", "storeEntity", "(", "$", "entity", ")", "{", "$", "this", "->", "checkEntityType", "(", "$", "entity", ")", ";", "$", "store", "=", "new", "Store", "(", "$", "this", "->", "aggregate", "(", "$", "entity", ")", ",", "$", "this", "->", "newQueryBuilder", "(", ")", ")", ";", "return", "$", "store", "->", "execute", "(", ")", ";", "}" ]
Store a single entity into the database. @param Mappable $entity @throws \InvalidArgumentException @throws MappingException @return \Analogue\ORM\Entity
[ "Store", "a", "single", "entity", "into", "the", "database", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L236-L243
analogueorm/analogue
src/System/Mapper.php
Mapper.checkEntityType
protected function checkEntityType($entity) { if (get_class($entity) != $this->entityMap->getClass() && !is_subclass_of($entity, $this->entityMap->getClass())) { $expected = $this->entityMap->getClass(); $actual = get_class($entity); throw new InvalidArgumentException("Expected : $expected, got $actual."); } }
php
protected function checkEntityType($entity) { if (get_class($entity) != $this->entityMap->getClass() && !is_subclass_of($entity, $this->entityMap->getClass())) { $expected = $this->entityMap->getClass(); $actual = get_class($entity); throw new InvalidArgumentException("Expected : $expected, got $actual."); } }
[ "protected", "function", "checkEntityType", "(", "$", "entity", ")", "{", "if", "(", "get_class", "(", "$", "entity", ")", "!=", "$", "this", "->", "entityMap", "->", "getClass", "(", ")", "&&", "!", "is_subclass_of", "(", "$", "entity", ",", "$", "this", "->", "entityMap", "->", "getClass", "(", ")", ")", ")", "{", "$", "expected", "=", "$", "this", "->", "entityMap", "->", "getClass", "(", ")", ";", "$", "actual", "=", "get_class", "(", "$", "entity", ")", ";", "throw", "new", "InvalidArgumentException", "(", "\"Expected : $expected, got $actual.\"", ")", ";", "}", "}" ]
Check that the entity correspond to the current mapper. @param mixed $entity @throws InvalidArgumentException @return void
[ "Check", "that", "the", "entity", "correspond", "to", "the", "current", "mapper", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L254-L262
analogueorm/analogue
src/System/Mapper.php
Mapper.delete
public function delete($entity) { if ($this->manager->isTraversable($entity)) { return $this->deleteCollection($entity); } else { $this->deleteEntity($entity); } }
php
public function delete($entity) { if ($this->manager->isTraversable($entity)) { return $this->deleteCollection($entity); } else { $this->deleteEntity($entity); } }
[ "public", "function", "delete", "(", "$", "entity", ")", "{", "if", "(", "$", "this", "->", "manager", "->", "isTraversable", "(", "$", "entity", ")", ")", "{", "return", "$", "this", "->", "deleteCollection", "(", "$", "entity", ")", ";", "}", "else", "{", "$", "this", "->", "deleteEntity", "(", "$", "entity", ")", ";", "}", "}" ]
Delete an entity or an entity collection from the database. @param Mappable|\Traversable|array @throws MappingException @throws \InvalidArgumentException @return \Traversable|array
[ "Delete", "an", "entity", "or", "an", "entity", "collection", "from", "the", "database", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L298-L305
analogueorm/analogue
src/System/Mapper.php
Mapper.deleteCollection
protected function deleteCollection($entities) { $this->adapter->beginTransaction(); foreach ($entities as $entity) { $this->deleteEntity($entity); } $this->adapter->commit(); return $entities; }
php
protected function deleteCollection($entities) { $this->adapter->beginTransaction(); foreach ($entities as $entity) { $this->deleteEntity($entity); } $this->adapter->commit(); return $entities; }
[ "protected", "function", "deleteCollection", "(", "$", "entities", ")", "{", "$", "this", "->", "adapter", "->", "beginTransaction", "(", ")", ";", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "$", "this", "->", "deleteEntity", "(", "$", "entity", ")", ";", "}", "$", "this", "->", "adapter", "->", "commit", "(", ")", ";", "return", "$", "entities", ";", "}" ]
Delete an Entity Collection inside a single db transaction. @param \Traversable|array $entities @throws \InvalidArgumentException @throws MappingException @return \Traversable|array
[ "Delete", "an", "Entity", "Collection", "inside", "a", "single", "db", "transaction", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L317-L328
analogueorm/analogue
src/System/Mapper.php
Mapper.deleteEntity
protected function deleteEntity($entity) { $this->checkEntityType($entity); $delete = new Delete($this->aggregate($entity), $this->newQueryBuilder()); $delete->execute(); }
php
protected function deleteEntity($entity) { $this->checkEntityType($entity); $delete = new Delete($this->aggregate($entity), $this->newQueryBuilder()); $delete->execute(); }
[ "protected", "function", "deleteEntity", "(", "$", "entity", ")", "{", "$", "this", "->", "checkEntityType", "(", "$", "entity", ")", ";", "$", "delete", "=", "new", "Delete", "(", "$", "this", "->", "aggregate", "(", "$", "entity", ")", ",", "$", "this", "->", "newQueryBuilder", "(", ")", ")", ";", "$", "delete", "->", "execute", "(", ")", ";", "}" ]
Delete a single entity from the database. @param Mappable $entity @throws \InvalidArgumentException @throws MappingException @return void
[ "Delete", "a", "single", "entity", "from", "the", "database", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L340-L347
analogueorm/analogue
src/System/Mapper.php
Mapper.fireEvent
public function fireEvent($event, $entity, $halt = true) { /*if ($entity instanceof Wrapper) { throw new InvalidArgumentException('Fired Event with invalid Entity Object'); }*/ $eventName = "analogue.{$event}.".$this->entityMap->getClass(); $method = $halt ? 'until' : 'fire'; if (!array_key_exists($event, $this->events)) { throw new \LogicException("Analogue : Event $event doesn't exist"); } $eventClass = $this->events[$event]; $event = new $eventClass($entity); return $this->dispatcher->$method($eventName, $event); }
php
public function fireEvent($event, $entity, $halt = true) { /*if ($entity instanceof Wrapper) { throw new InvalidArgumentException('Fired Event with invalid Entity Object'); }*/ $eventName = "analogue.{$event}.".$this->entityMap->getClass(); $method = $halt ? 'until' : 'fire'; if (!array_key_exists($event, $this->events)) { throw new \LogicException("Analogue : Event $event doesn't exist"); } $eventClass = $this->events[$event]; $event = new $eventClass($entity); return $this->dispatcher->$method($eventName, $event); }
[ "public", "function", "fireEvent", "(", "$", "event", ",", "$", "entity", ",", "$", "halt", "=", "true", ")", "{", "/*if ($entity instanceof Wrapper) {\n throw new InvalidArgumentException('Fired Event with invalid Entity Object');\n }*/", "$", "eventName", "=", "\"analogue.{$event}.\"", ".", "$", "this", "->", "entityMap", "->", "getClass", "(", ")", ";", "$", "method", "=", "$", "halt", "?", "'until'", ":", "'fire'", ";", "if", "(", "!", "array_key_exists", "(", "$", "event", ",", "$", "this", "->", "events", ")", ")", "{", "throw", "new", "\\", "LogicException", "(", "\"Analogue : Event $event doesn't exist\"", ")", ";", "}", "$", "eventClass", "=", "$", "this", "->", "events", "[", "$", "event", "]", ";", "$", "event", "=", "new", "$", "eventClass", "(", "$", "entity", ")", ";", "return", "$", "this", "->", "dispatcher", "->", "$", "method", "(", "$", "eventName", ",", "$", "event", ")", ";", "}" ]
Fire the given event for the entity. @param string $event @param \Analogue\ORM\Entity $entity @param bool $halt @throws InvalidArgumentException @return mixed
[ "Fire", "the", "given", "event", "for", "the", "entity", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L401-L419
analogueorm/analogue
src/System/Mapper.php
Mapper.registerEvent
public function registerEvent($event, $callback) { $name = $this->entityMap->getClass(); $this->dispatcher->listen("analogue.{$event}.{$name}", $callback); }
php
public function registerEvent($event, $callback) { $name = $this->entityMap->getClass(); $this->dispatcher->listen("analogue.{$event}.{$name}", $callback); }
[ "public", "function", "registerEvent", "(", "$", "event", ",", "$", "callback", ")", "{", "$", "name", "=", "$", "this", "->", "entityMap", "->", "getClass", "(", ")", ";", "$", "this", "->", "dispatcher", "->", "listen", "(", "\"analogue.{$event}.{$name}\"", ",", "$", "callback", ")", ";", "}" ]
Register an entity event with the dispatcher. @param string $event @param \Closure $callback @return void
[ "Register", "an", "entity", "event", "with", "the", "dispatcher", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L429-L434
analogueorm/analogue
src/System/Mapper.php
Mapper.getGlobalScope
public function getGlobalScope($scope) { return array_first($this->globalScopes, function ($key, $value) use ($scope) { return $scope instanceof $value; }); }
php
public function getGlobalScope($scope) { return array_first($this->globalScopes, function ($key, $value) use ($scope) { return $scope instanceof $value; }); }
[ "public", "function", "getGlobalScope", "(", "$", "scope", ")", "{", "return", "array_first", "(", "$", "this", "->", "globalScopes", ",", "function", "(", "$", "key", ",", "$", "value", ")", "use", "(", "$", "scope", ")", "{", "return", "$", "scope", "instanceof", "$", "value", ";", "}", ")", ";", "}" ]
Get a global scope registered with the modal. @param \Analogue\ORM\System\ScopeInterface $scope @return \Analogue\ORM\System\ScopeInterface|null
[ "Get", "a", "global", "scope", "registered", "with", "the", "modal", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L478-L483
analogueorm/analogue
src/System/Mapper.php
Mapper.newQueryWithoutScope
public function newQueryWithoutScope($scope) { $this->getGlobalScope($scope)->remove($query = $this->getQuery(), $this); return $query; }
php
public function newQueryWithoutScope($scope) { $this->getGlobalScope($scope)->remove($query = $this->getQuery(), $this); return $query; }
[ "public", "function", "newQueryWithoutScope", "(", "$", "scope", ")", "{", "$", "this", "->", "getGlobalScope", "(", "$", "scope", ")", "->", "remove", "(", "$", "query", "=", "$", "this", "->", "getQuery", "(", ")", ",", "$", "this", ")", ";", "return", "$", "query", ";", "}" ]
Get a new query instance without a given scope. @param \Analogue\ORM\System\ScopeInterface $scope @return \Analogue\ORM\System\Query
[ "Get", "a", "new", "query", "instance", "without", "a", "given", "scope", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L492-L497
analogueorm/analogue
src/System/Mapper.php
Mapper.applyGlobalScopes
public function applyGlobalScopes($query) { foreach ($this->getGlobalScopes() as $scope) { $scope->apply($query, $this); } return $query; }
php
public function applyGlobalScopes($query) { foreach ($this->getGlobalScopes() as $scope) { $scope->apply($query, $this); } return $query; }
[ "public", "function", "applyGlobalScopes", "(", "$", "query", ")", "{", "foreach", "(", "$", "this", "->", "getGlobalScopes", "(", ")", "as", "$", "scope", ")", "{", "$", "scope", "->", "apply", "(", "$", "query", ",", "$", "this", ")", ";", "}", "return", "$", "query", ";", "}" ]
Apply all of the global scopes to an Analogue Query builder. @param Query $query @return \Analogue\ORM\System\Query
[ "Apply", "all", "of", "the", "global", "scopes", "to", "an", "Analogue", "Query", "builder", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L518-L525
analogueorm/analogue
src/System/Mapper.php
Mapper.addCustomCommand
public function addCustomCommand($command) { $name = lcfirst(class_basename($command)); $this->customCommands[$name] = $command; }
php
public function addCustomCommand($command) { $name = lcfirst(class_basename($command)); $this->customCommands[$name] = $command; }
[ "public", "function", "addCustomCommand", "(", "$", "command", ")", "{", "$", "name", "=", "lcfirst", "(", "class_basename", "(", "$", "command", ")", ")", ";", "$", "this", "->", "customCommands", "[", "$", "name", "]", "=", "$", "command", ";", "}" ]
Add a dynamic method that extends the mapper/repository. @param string $command
[ "Add", "a", "dynamic", "method", "that", "extends", "the", "mapper", "/", "repository", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L542-L547
analogueorm/analogue
src/System/Mapper.php
Mapper.newInstance
public function newInstance() { $class = $this->entityMap->getClass(); if ($this->entityMap->useDependencyInjection()) { return $this->newInstanceUsingDependencyInjection($class); } return $this->newInstanceUsingInstantiator($class); }
php
public function newInstance() { $class = $this->entityMap->getClass(); if ($this->entityMap->useDependencyInjection()) { return $this->newInstanceUsingDependencyInjection($class); } return $this->newInstanceUsingInstantiator($class); }
[ "public", "function", "newInstance", "(", ")", "{", "$", "class", "=", "$", "this", "->", "entityMap", "->", "getClass", "(", ")", ";", "if", "(", "$", "this", "->", "entityMap", "->", "useDependencyInjection", "(", ")", ")", "{", "return", "$", "this", "->", "newInstanceUsingDependencyInjection", "(", "$", "class", ")", ";", "}", "return", "$", "this", "->", "newInstanceUsingInstantiator", "(", "$", "class", ")", ";", "}" ]
Create a new instance of the mapped entity class. @return mixed
[ "Create", "a", "new", "instance", "of", "the", "mapped", "entity", "class", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L554-L563
analogueorm/analogue
src/System/Mapper.php
Mapper.removeGlobalScopes
public function removeGlobalScopes($query) { foreach ($this->getGlobalScopes() as $scope) { $scope->remove($query, $this); } return $query; }
php
public function removeGlobalScopes($query) { foreach ($this->getGlobalScopes() as $scope) { $scope->remove($query, $this); } return $query; }
[ "public", "function", "removeGlobalScopes", "(", "$", "query", ")", "{", "foreach", "(", "$", "this", "->", "getGlobalScopes", "(", ")", "as", "$", "scope", ")", "{", "$", "scope", "->", "remove", "(", "$", "query", ",", "$", "this", ")", ";", "}", "return", "$", "query", ";", "}" ]
Remove all of the global scopes from an Analogue Query builder. @param Query $query @return \Analogue\ORM\System\Query
[ "Remove", "all", "of", "the", "global", "scopes", "from", "an", "Analogue", "Query", "builder", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L624-L631
analogueorm/analogue
src/System/Mapper.php
Mapper.executeCustomCommand
public function executeCustomCommand($command, $entity) { $commandClass = $this->customCommands[$command]; if ($this->manager->isTraversable($entity)) { foreach ($entity as $instance) { $this->executeSingleCustomCommand($commandClass, $instance); } } else { return $this->executeSingleCustomCommand($commandClass, $entity); } }
php
public function executeCustomCommand($command, $entity) { $commandClass = $this->customCommands[$command]; if ($this->manager->isTraversable($entity)) { foreach ($entity as $instance) { $this->executeSingleCustomCommand($commandClass, $instance); } } else { return $this->executeSingleCustomCommand($commandClass, $entity); } }
[ "public", "function", "executeCustomCommand", "(", "$", "command", ",", "$", "entity", ")", "{", "$", "commandClass", "=", "$", "this", "->", "customCommands", "[", "$", "command", "]", ";", "if", "(", "$", "this", "->", "manager", "->", "isTraversable", "(", "$", "entity", ")", ")", "{", "foreach", "(", "$", "entity", "as", "$", "instance", ")", "{", "$", "this", "->", "executeSingleCustomCommand", "(", "$", "commandClass", ",", "$", "instance", ")", ";", "}", "}", "else", "{", "return", "$", "this", "->", "executeSingleCustomCommand", "(", "$", "commandClass", ",", "$", "entity", ")", ";", "}", "}" ]
Execute a custom command on an Entity. @param string $command @param mixed|Collection|array $entity @throws \InvalidArgumentException @throws MappingException @return mixed
[ "Execute", "a", "custom", "command", "on", "an", "Entity", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L701-L712
analogueorm/analogue
src/System/Mapper.php
Mapper.executeSingleCustomCommand
protected function executeSingleCustomCommand($commandClass, $entity) { $this->checkEntityType($entity); $instance = new $commandClass($this->aggregate($entity), $this->newQueryBuilder()); return $instance->execute(); }
php
protected function executeSingleCustomCommand($commandClass, $entity) { $this->checkEntityType($entity); $instance = new $commandClass($this->aggregate($entity), $this->newQueryBuilder()); return $instance->execute(); }
[ "protected", "function", "executeSingleCustomCommand", "(", "$", "commandClass", ",", "$", "entity", ")", "{", "$", "this", "->", "checkEntityType", "(", "$", "entity", ")", ";", "$", "instance", "=", "new", "$", "commandClass", "(", "$", "this", "->", "aggregate", "(", "$", "entity", ")", ",", "$", "this", "->", "newQueryBuilder", "(", ")", ")", ";", "return", "$", "instance", "->", "execute", "(", ")", ";", "}" ]
Execute a single command instance. @param string $commandClass @param mixed $entity @throws \InvalidArgumentException @throws MappingException @return mixed
[ "Execute", "a", "single", "command", "instance", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Mapper.php#L725-L732
analogueorm/analogue
src/Relationships/MorphMany.php
MorphMany.getResults
public function getResults($relation) { $results = $this->query->get(); $this->cacheRelation($results, $relation); return $results; }
php
public function getResults($relation) { $results = $this->query->get(); $this->cacheRelation($results, $relation); return $results; }
[ "public", "function", "getResults", "(", "$", "relation", ")", "{", "$", "results", "=", "$", "this", "->", "query", "->", "get", "(", ")", ";", "$", "this", "->", "cacheRelation", "(", "$", "results", ",", "$", "relation", ")", ";", "return", "$", "results", ";", "}" ]
Get the results of the relationship. @param $relation @return mixed
[ "Get", "the", "results", "of", "the", "relationship", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/MorphMany.php#L14-L21
analogueorm/analogue
src/Analogue.php
Analogue.boot
public function boot() { if (static::$booted) { return $this; } $dispatcher = new Dispatcher(); $connectionProvider = new CapsuleConnectionProvider(static::$capsule); $illuminate = new IlluminateDriver($connectionProvider); $driverManager = new DriverManager(); $driverManager->addDriver($illuminate); static::$manager = new Manager($driverManager, $dispatcher); static::$instance = $this; static::$booted = true; return $this; }
php
public function boot() { if (static::$booted) { return $this; } $dispatcher = new Dispatcher(); $connectionProvider = new CapsuleConnectionProvider(static::$capsule); $illuminate = new IlluminateDriver($connectionProvider); $driverManager = new DriverManager(); $driverManager->addDriver($illuminate); static::$manager = new Manager($driverManager, $dispatcher); static::$instance = $this; static::$booted = true; return $this; }
[ "public", "function", "boot", "(", ")", "{", "if", "(", "static", "::", "$", "booted", ")", "{", "return", "$", "this", ";", "}", "$", "dispatcher", "=", "new", "Dispatcher", "(", ")", ";", "$", "connectionProvider", "=", "new", "CapsuleConnectionProvider", "(", "static", "::", "$", "capsule", ")", ";", "$", "illuminate", "=", "new", "IlluminateDriver", "(", "$", "connectionProvider", ")", ";", "$", "driverManager", "=", "new", "DriverManager", "(", ")", ";", "$", "driverManager", "->", "addDriver", "(", "$", "illuminate", ")", ";", "static", "::", "$", "manager", "=", "new", "Manager", "(", "$", "driverManager", ",", "$", "dispatcher", ")", ";", "static", "::", "$", "instance", "=", "$", "this", ";", "static", "::", "$", "booted", "=", "true", ";", "return", "$", "this", ";", "}" ]
Boot Analogue. @return Analogue
[ "Boot", "Analogue", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Analogue.php#L61-L84
analogueorm/analogue
src/Relationships/EmbedsMany.php
EmbedsMany.matchSingleResult
public function matchSingleResult(array $attributes) : array { $column = $this->relation; if (!$this->asArray) { throw new MappingException("column '$column' should be of type array or json"); } return $this->matchAsArray($attributes); }
php
public function matchSingleResult(array $attributes) : array { $column = $this->relation; if (!$this->asArray) { throw new MappingException("column '$column' should be of type array or json"); } return $this->matchAsArray($attributes); }
[ "public", "function", "matchSingleResult", "(", "array", "$", "attributes", ")", ":", "array", "{", "$", "column", "=", "$", "this", "->", "relation", ";", "if", "(", "!", "$", "this", "->", "asArray", ")", "{", "throw", "new", "MappingException", "(", "\"column '$column' should be of type array or json\"", ")", ";", "}", "return", "$", "this", "->", "matchAsArray", "(", "$", "attributes", ")", ";", "}" ]
Match a single database row's attributes to a single object, and return the updated attributes. @param array $attributes @throws MappingException @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/EmbedsMany.php#L20-L29
analogueorm/analogue
src/Relationships/EmbedsMany.php
EmbedsMany.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)) { $attributes[$key] = $this->asJson ? json_encode([]) : []; } if ($this->asJson) { $attributes[$key] = json_decode($attributes[$key], true); } if (!is_array($attributes[$key])) { throw new MappingException("'$key' column should be an array, actual :".$attributes[$key]); } $attributes[$key] = $this->buildEmbeddedCollection($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)) { $attributes[$key] = $this->asJson ? json_encode([]) : []; } if ($this->asJson) { $attributes[$key] = json_decode($attributes[$key], true); } if (!is_array($attributes[$key])) { throw new MappingException("'$key' column should be an array, actual :".$attributes[$key]); } $attributes[$key] = $this->buildEmbeddedCollection($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", ")", ")", "{", "$", "attributes", "[", "$", "key", "]", "=", "$", "this", "->", "asJson", "?", "json_encode", "(", "[", "]", ")", ":", "[", "]", ";", "}", "if", "(", "$", "this", "->", "asJson", ")", "{", "$", "attributes", "[", "$", "key", "]", "=", "json_decode", "(", "$", "attributes", "[", "$", "key", "]", ",", "true", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "attributes", "[", "$", "key", "]", ")", ")", "{", "throw", "new", "MappingException", "(", "\"'$key' column should be an array, actual :\"", ".", "$", "attributes", "[", "$", "key", "]", ")", ";", "}", "$", "attributes", "[", "$", "key", "]", "=", "$", "this", "->", "buildEmbeddedCollection", "(", "$", "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/EmbedsMany.php#L41-L62
analogueorm/analogue
src/Relationships/EmbedsMany.php
EmbedsMany.buildEmbeddedCollection
protected function buildEmbeddedCollection(array $rows): Collection { return collect($rows)->map(function ($attributes) { return $this->buildEmbeddedObject($attributes); }); }
php
protected function buildEmbeddedCollection(array $rows): Collection { return collect($rows)->map(function ($attributes) { return $this->buildEmbeddedObject($attributes); }); }
[ "protected", "function", "buildEmbeddedCollection", "(", "array", "$", "rows", ")", ":", "Collection", "{", "return", "collect", "(", "$", "rows", ")", "->", "map", "(", "function", "(", "$", "attributes", ")", "{", "return", "$", "this", "->", "buildEmbeddedObject", "(", "$", "attributes", ")", ";", "}", ")", ";", "}" ]
Build an embedded collection and returns it. @param array $rows @return Collection
[ "Build", "an", "embedded", "collection", "and", "returns", "it", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbedsMany.php#L71-L76
analogueorm/analogue
src/Relationships/EmbedsMany.php
EmbedsMany.normalizeAsArray
protected function normalizeAsArray($objects) : array { $key = $this->relation; if (!is_array($objects) && !$objects instanceof Collection) { throw new MappingException("column '$key' should be of type array or collection"); } if ($objects instanceof Collection) { $objects = $objects->all(); } $normalizedObjects = []; foreach ($objects as $object) { $wrapper = $this->factory->make($object); $normalizedObjects[] = $wrapper->getEntityAttributes(); } if ($this->asJson) { $normalizedObjects = json_encode($normalizedObjects); } return [$key => $normalizedObjects]; }
php
protected function normalizeAsArray($objects) : array { $key = $this->relation; if (!is_array($objects) && !$objects instanceof Collection) { throw new MappingException("column '$key' should be of type array or collection"); } if ($objects instanceof Collection) { $objects = $objects->all(); } $normalizedObjects = []; foreach ($objects as $object) { $wrapper = $this->factory->make($object); $normalizedObjects[] = $wrapper->getEntityAttributes(); } if ($this->asJson) { $normalizedObjects = json_encode($normalizedObjects); } return [$key => $normalizedObjects]; }
[ "protected", "function", "normalizeAsArray", "(", "$", "objects", ")", ":", "array", "{", "$", "key", "=", "$", "this", "->", "relation", ";", "if", "(", "!", "is_array", "(", "$", "objects", ")", "&&", "!", "$", "objects", "instanceof", "Collection", ")", "{", "throw", "new", "MappingException", "(", "\"column '$key' should be of type array or collection\"", ")", ";", "}", "if", "(", "$", "objects", "instanceof", "Collection", ")", "{", "$", "objects", "=", "$", "objects", "->", "all", "(", ")", ";", "}", "$", "normalizedObjects", "=", "[", "]", ";", "foreach", "(", "$", "objects", "as", "$", "object", ")", "{", "$", "wrapper", "=", "$", "this", "->", "factory", "->", "make", "(", "$", "object", ")", ";", "$", "normalizedObjects", "[", "]", "=", "$", "wrapper", "->", "getEntityAttributes", "(", ")", ";", "}", "if", "(", "$", "this", "->", "asJson", ")", "{", "$", "normalizedObjects", "=", "json_encode", "(", "$", "normalizedObjects", ")", ";", "}", "return", "[", "$", "key", "=>", "$", "normalizedObjects", "]", ";", "}" ]
Normalize object as array containing raw attributes. @param mixed $objects @throws MappingException @return array
[ "Normalize", "object", "as", "array", "containing", "raw", "attributes", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Relationships/EmbedsMany.php#L105-L129
analogueorm/analogue
src/Plugins/Timestamps/TimestampsPlugin.php
TimestampsPlugin.register
public function register() { $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->usesTimestamps()) { $mapper->registerEvent('creating', function ($event) use ($entityMap) { $entity = $event->entity; $wrappedEntity = $this->getMappable($entity); $createdAtField = $entityMap->getCreatedAtColumn(); $updatedAtField = $entityMap->getUpdatedAtColumn(); $time = new Carbon(); if (is_null($wrappedEntity->getEntityAttribute($createdAtField))) { $wrappedEntity->setEntityAttribute($createdAtField, $time); $wrappedEntity->setEntityAttribute($updatedAtField, $time); } }); $mapper->registerEvent('updating', function ($event) use ($entityMap) { $entity = $event->entity; $wrappedEntity = $this->getMappable($entity); $updatedAtField = $entityMap->getUpdatedAtColumn(); $time = new Carbon(); $wrappedEntity->setEntityAttribute($updatedAtField, $time); }); } }); }
php
public function register() { $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->usesTimestamps()) { $mapper->registerEvent('creating', function ($event) use ($entityMap) { $entity = $event->entity; $wrappedEntity = $this->getMappable($entity); $createdAtField = $entityMap->getCreatedAtColumn(); $updatedAtField = $entityMap->getUpdatedAtColumn(); $time = new Carbon(); if (is_null($wrappedEntity->getEntityAttribute($createdAtField))) { $wrappedEntity->setEntityAttribute($createdAtField, $time); $wrappedEntity->setEntityAttribute($updatedAtField, $time); } }); $mapper->registerEvent('updating', function ($event) use ($entityMap) { $entity = $event->entity; $wrappedEntity = $this->getMappable($entity); $updatedAtField = $entityMap->getUpdatedAtColumn(); $time = new Carbon(); $wrappedEntity->setEntityAttribute($updatedAtField, $time); }); } }); }
[ "public", "function", "register", "(", ")", "{", "$", "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", "->", "usesTimestamps", "(", ")", ")", "{", "$", "mapper", "->", "registerEvent", "(", "'creating'", ",", "function", "(", "$", "event", ")", "use", "(", "$", "entityMap", ")", "{", "$", "entity", "=", "$", "event", "->", "entity", ";", "$", "wrappedEntity", "=", "$", "this", "->", "getMappable", "(", "$", "entity", ")", ";", "$", "createdAtField", "=", "$", "entityMap", "->", "getCreatedAtColumn", "(", ")", ";", "$", "updatedAtField", "=", "$", "entityMap", "->", "getUpdatedAtColumn", "(", ")", ";", "$", "time", "=", "new", "Carbon", "(", ")", ";", "if", "(", "is_null", "(", "$", "wrappedEntity", "->", "getEntityAttribute", "(", "$", "createdAtField", ")", ")", ")", "{", "$", "wrappedEntity", "->", "setEntityAttribute", "(", "$", "createdAtField", ",", "$", "time", ")", ";", "$", "wrappedEntity", "->", "setEntityAttribute", "(", "$", "updatedAtField", ",", "$", "time", ")", ";", "}", "}", ")", ";", "$", "mapper", "->", "registerEvent", "(", "'updating'", ",", "function", "(", "$", "event", ")", "use", "(", "$", "entityMap", ")", "{", "$", "entity", "=", "$", "event", "->", "entity", ";", "$", "wrappedEntity", "=", "$", "this", "->", "getMappable", "(", "$", "entity", ")", ";", "$", "updatedAtField", "=", "$", "entityMap", "->", "getUpdatedAtColumn", "(", ")", ";", "$", "time", "=", "new", "Carbon", "(", ")", ";", "$", "wrappedEntity", "->", "setEntityAttribute", "(", "$", "updatedAtField", ",", "$", "time", ")", ";", "}", ")", ";", "}", "}", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Plugins/Timestamps/TimestampsPlugin.php#L18-L60
analogueorm/analogue
src/Plugins/Timestamps/TimestampsPlugin.php
TimestampsPlugin.getMappable
protected function getMappable($entity) : InternallyMappable { if ($entity instanceof InternallyMappable) { return $entity; } $factory = new Factory(); $wrappedEntity = $factory->make($entity); return $wrappedEntity; }
php
protected function getMappable($entity) : InternallyMappable { if ($entity instanceof InternallyMappable) { return $entity; } $factory = new Factory(); $wrappedEntity = $factory->make($entity); return $wrappedEntity; }
[ "protected", "function", "getMappable", "(", "$", "entity", ")", ":", "InternallyMappable", "{", "if", "(", "$", "entity", "instanceof", "InternallyMappable", ")", "{", "return", "$", "entity", ";", "}", "$", "factory", "=", "new", "Factory", "(", ")", ";", "$", "wrappedEntity", "=", "$", "factory", "->", "make", "(", "$", "entity", ")", ";", "return", "$", "wrappedEntity", ";", "}" ]
Return internally mappable if not mappable. @param mixed $entity @return InternallyMappable
[ "Return", "internally", "mappable", "if", "not", "mappable", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/Plugins/Timestamps/TimestampsPlugin.php#L69-L79
analogueorm/analogue
src/System/Aggregate.php
Aggregate.parseRelationships
protected function parseRelationships() { foreach ($this->entityMap->getSingleRelationships() as $relation) { $this->parseSingleRelationship($relation); } foreach ($this->entityMap->getManyRelationships() as $relation) { $this->parseManyRelationship($relation); } }
php
protected function parseRelationships() { foreach ($this->entityMap->getSingleRelationships() as $relation) { $this->parseSingleRelationship($relation); } foreach ($this->entityMap->getManyRelationships() as $relation) { $this->parseManyRelationship($relation); } }
[ "protected", "function", "parseRelationships", "(", ")", "{", "foreach", "(", "$", "this", "->", "entityMap", "->", "getSingleRelationships", "(", ")", "as", "$", "relation", ")", "{", "$", "this", "->", "parseSingleRelationship", "(", "$", "relation", ")", ";", "}", "foreach", "(", "$", "this", "->", "entityMap", "->", "getManyRelationships", "(", ")", "as", "$", "relation", ")", "{", "$", "this", "->", "parseManyRelationship", "(", "$", "relation", ")", ";", "}", "}" ]
Parse Every relationships defined on the entity. @throws MappingException @return void
[ "Parse", "Every", "relationships", "defined", "on", "the", "entity", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L124-L133
analogueorm/analogue
src/System/Aggregate.php
Aggregate.parseForCommonValues
protected function parseForCommonValues($relation) { if (!$this->hasAttribute($relation)) { // If no attribute exists for this relationships // we'll make it a simple empty array. This will // save us from constantly checking for the attributes // actual existence. $this->relationships[$relation] = []; return false; } $value = $this->getRelationshipValue($relation); if (is_null($value)) { $this->relationships[$relation] = []; // If the relationship's content is the null value // and the Entity's exist in DB, we'll interpret this // as the need to detach all related Entities, // therefore a sync operation is needed. $this->needSync[] = $relation; return false; } return $value; }
php
protected function parseForCommonValues($relation) { if (!$this->hasAttribute($relation)) { // If no attribute exists for this relationships // we'll make it a simple empty array. This will // save us from constantly checking for the attributes // actual existence. $this->relationships[$relation] = []; return false; } $value = $this->getRelationshipValue($relation); if (is_null($value)) { $this->relationships[$relation] = []; // If the relationship's content is the null value // and the Entity's exist in DB, we'll interpret this // as the need to detach all related Entities, // therefore a sync operation is needed. $this->needSync[] = $relation; return false; } return $value; }
[ "protected", "function", "parseForCommonValues", "(", "$", "relation", ")", "{", "if", "(", "!", "$", "this", "->", "hasAttribute", "(", "$", "relation", ")", ")", "{", "// If no attribute exists for this relationships", "// we'll make it a simple empty array. This will", "// save us from constantly checking for the attributes", "// actual existence.", "$", "this", "->", "relationships", "[", "$", "relation", "]", "=", "[", "]", ";", "return", "false", ";", "}", "$", "value", "=", "$", "this", "->", "getRelationshipValue", "(", "$", "relation", ")", ";", "if", "(", "is_null", "(", "$", "value", ")", ")", "{", "$", "this", "->", "relationships", "[", "$", "relation", "]", "=", "[", "]", ";", "// If the relationship's content is the null value", "// and the Entity's exist in DB, we'll interpret this", "// as the need to detach all related Entities,", "// therefore a sync operation is needed.", "$", "this", "->", "needSync", "[", "]", "=", "$", "relation", ";", "return", "false", ";", "}", "return", "$", "value", ";", "}" ]
Parse for values common to single & many relations. @param string $relation @throws MappingException @return mixed|bool
[ "Parse", "for", "values", "common", "to", "single", "&", "many", "relations", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L144-L171
analogueorm/analogue
src/System/Aggregate.php
Aggregate.parseSingleRelationship
protected function parseSingleRelationship(string $relation): bool { if (!$value = $this->parseForCommonValues($relation)) { return true; } if ($value instanceof Collection || is_array($value) || $value instanceof CollectionProxy) { throw new MappingException("Entity's attribute $relation should not be array, or collection"); } if ($value instanceof LazyLoadingInterface && !$value->isProxyInitialized()) { $this->relationships[$relation] = []; return true; } // If the attribute is a loaded proxy, swap it for its // loaded entity. if ($value instanceof LazyLoadingInterface && $value->isProxyInitialized()) { $value = $value->getWrappedValueHolderValue(); } if ($this->isParentOrRoot($value)) { $this->relationships[$relation] = []; return true; } // At this point, we can assume the attribute is an Entity instance // so we'll treat it as such. $subAggregate = $this->createSubAggregate($value, $relation); // Even if it's a single entity, we'll store it as an array // just for consistency with other relationships $this->relationships[$relation] = [$subAggregate]; // We always need to check a loaded relation is in sync // with its local key $this->needSync[] = $relation; return true; }
php
protected function parseSingleRelationship(string $relation): bool { if (!$value = $this->parseForCommonValues($relation)) { return true; } if ($value instanceof Collection || is_array($value) || $value instanceof CollectionProxy) { throw new MappingException("Entity's attribute $relation should not be array, or collection"); } if ($value instanceof LazyLoadingInterface && !$value->isProxyInitialized()) { $this->relationships[$relation] = []; return true; } // If the attribute is a loaded proxy, swap it for its // loaded entity. if ($value instanceof LazyLoadingInterface && $value->isProxyInitialized()) { $value = $value->getWrappedValueHolderValue(); } if ($this->isParentOrRoot($value)) { $this->relationships[$relation] = []; return true; } // At this point, we can assume the attribute is an Entity instance // so we'll treat it as such. $subAggregate = $this->createSubAggregate($value, $relation); // Even if it's a single entity, we'll store it as an array // just for consistency with other relationships $this->relationships[$relation] = [$subAggregate]; // We always need to check a loaded relation is in sync // with its local key $this->needSync[] = $relation; return true; }
[ "protected", "function", "parseSingleRelationship", "(", "string", "$", "relation", ")", ":", "bool", "{", "if", "(", "!", "$", "value", "=", "$", "this", "->", "parseForCommonValues", "(", "$", "relation", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "value", "instanceof", "Collection", "||", "is_array", "(", "$", "value", ")", "||", "$", "value", "instanceof", "CollectionProxy", ")", "{", "throw", "new", "MappingException", "(", "\"Entity's attribute $relation should not be array, or collection\"", ")", ";", "}", "if", "(", "$", "value", "instanceof", "LazyLoadingInterface", "&&", "!", "$", "value", "->", "isProxyInitialized", "(", ")", ")", "{", "$", "this", "->", "relationships", "[", "$", "relation", "]", "=", "[", "]", ";", "return", "true", ";", "}", "// If the attribute is a loaded proxy, swap it for its", "// loaded entity.", "if", "(", "$", "value", "instanceof", "LazyLoadingInterface", "&&", "$", "value", "->", "isProxyInitialized", "(", ")", ")", "{", "$", "value", "=", "$", "value", "->", "getWrappedValueHolderValue", "(", ")", ";", "}", "if", "(", "$", "this", "->", "isParentOrRoot", "(", "$", "value", ")", ")", "{", "$", "this", "->", "relationships", "[", "$", "relation", "]", "=", "[", "]", ";", "return", "true", ";", "}", "// At this point, we can assume the attribute is an Entity instance", "// so we'll treat it as such.", "$", "subAggregate", "=", "$", "this", "->", "createSubAggregate", "(", "$", "value", ",", "$", "relation", ")", ";", "// Even if it's a single entity, we'll store it as an array", "// just for consistency with other relationships", "$", "this", "->", "relationships", "[", "$", "relation", "]", "=", "[", "$", "subAggregate", "]", ";", "// We always need to check a loaded relation is in sync", "// with its local key", "$", "this", "->", "needSync", "[", "]", "=", "$", "relation", ";", "return", "true", ";", "}" ]
Parse a 'single' relationship. @param string $relation @throws MappingException @return bool
[ "Parse", "a", "single", "relationship", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L182-L223
analogueorm/analogue
src/System/Aggregate.php
Aggregate.isParentOrRoot
protected function isParentOrRoot($value): bool { $id = spl_object_hash($value); $root = $this->root ? $this->root->getWrappedEntity()->getObject() : null; $parent = $this->parent ? $this->parent->getWrappedEntity()->getObject() : null; if ($parent && (spl_object_hash($parent) == $id)) { return true; } if ($root && (spl_object_hash($root) == $id)) { return true; } return false; }
php
protected function isParentOrRoot($value): bool { $id = spl_object_hash($value); $root = $this->root ? $this->root->getWrappedEntity()->getObject() : null; $parent = $this->parent ? $this->parent->getWrappedEntity()->getObject() : null; if ($parent && (spl_object_hash($parent) == $id)) { return true; } if ($root && (spl_object_hash($root) == $id)) { return true; } return false; }
[ "protected", "function", "isParentOrRoot", "(", "$", "value", ")", ":", "bool", "{", "$", "id", "=", "spl_object_hash", "(", "$", "value", ")", ";", "$", "root", "=", "$", "this", "->", "root", "?", "$", "this", "->", "root", "->", "getWrappedEntity", "(", ")", "->", "getObject", "(", ")", ":", "null", ";", "$", "parent", "=", "$", "this", "->", "parent", "?", "$", "this", "->", "parent", "->", "getWrappedEntity", "(", ")", "->", "getObject", "(", ")", ":", "null", ";", "if", "(", "$", "parent", "&&", "(", "spl_object_hash", "(", "$", "parent", ")", "==", "$", "id", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "root", "&&", "(", "spl_object_hash", "(", "$", "root", ")", "==", "$", "id", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Check if value isn't parent or root in the aggregate. @param mixed @return bool
[ "Check", "if", "value", "isn", "t", "parent", "or", "root", "in", "the", "aggregate", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L232-L247
analogueorm/analogue
src/System/Aggregate.php
Aggregate.parseManyRelationship
protected function parseManyRelationship(string $relation): bool { if (!$value = $this->parseForCommonValues($relation)) { return true; } if (is_array($value) || (!$value instanceof CollectionProxy && $value instanceof Collection)) { $this->needSync[] = $relation; } // If the relation is a proxy, we test is the relation // has been lazy loaded, otherwise we'll just treat // the subset of newly added items. if ($value instanceof CollectionProxy && $value->isProxyInitialized()) { $this->needSync[] = $relation; //$value = $value->getUnderlyingCollection(); } if ($value instanceof CollectionProxy && !$value->isProxyInitialized()) { $value = $value->getAddedItems(); } // At this point $value should be either an array or an instance // of a collection class. if (!is_array($value) && !$value instanceof Collection) { throw new MappingException("'$relation' attribute should be array() or Collection"); } $this->relationships[$relation] = $this->createSubAggregates($value, $relation); return true; }
php
protected function parseManyRelationship(string $relation): bool { if (!$value = $this->parseForCommonValues($relation)) { return true; } if (is_array($value) || (!$value instanceof CollectionProxy && $value instanceof Collection)) { $this->needSync[] = $relation; } // If the relation is a proxy, we test is the relation // has been lazy loaded, otherwise we'll just treat // the subset of newly added items. if ($value instanceof CollectionProxy && $value->isProxyInitialized()) { $this->needSync[] = $relation; //$value = $value->getUnderlyingCollection(); } if ($value instanceof CollectionProxy && !$value->isProxyInitialized()) { $value = $value->getAddedItems(); } // At this point $value should be either an array or an instance // of a collection class. if (!is_array($value) && !$value instanceof Collection) { throw new MappingException("'$relation' attribute should be array() or Collection"); } $this->relationships[$relation] = $this->createSubAggregates($value, $relation); return true; }
[ "protected", "function", "parseManyRelationship", "(", "string", "$", "relation", ")", ":", "bool", "{", "if", "(", "!", "$", "value", "=", "$", "this", "->", "parseForCommonValues", "(", "$", "relation", ")", ")", "{", "return", "true", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", "||", "(", "!", "$", "value", "instanceof", "CollectionProxy", "&&", "$", "value", "instanceof", "Collection", ")", ")", "{", "$", "this", "->", "needSync", "[", "]", "=", "$", "relation", ";", "}", "// If the relation is a proxy, we test is the relation", "// has been lazy loaded, otherwise we'll just treat", "// the subset of newly added items.", "if", "(", "$", "value", "instanceof", "CollectionProxy", "&&", "$", "value", "->", "isProxyInitialized", "(", ")", ")", "{", "$", "this", "->", "needSync", "[", "]", "=", "$", "relation", ";", "//$value = $value->getUnderlyingCollection();", "}", "if", "(", "$", "value", "instanceof", "CollectionProxy", "&&", "!", "$", "value", "->", "isProxyInitialized", "(", ")", ")", "{", "$", "value", "=", "$", "value", "->", "getAddedItems", "(", ")", ";", "}", "// At this point $value should be either an array or an instance", "// of a collection class.", "if", "(", "!", "is_array", "(", "$", "value", ")", "&&", "!", "$", "value", "instanceof", "Collection", ")", "{", "throw", "new", "MappingException", "(", "\"'$relation' attribute should be array() or Collection\"", ")", ";", "}", "$", "this", "->", "relationships", "[", "$", "relation", "]", "=", "$", "this", "->", "createSubAggregates", "(", "$", "value", ",", "$", "relation", ")", ";", "return", "true", ";", "}" ]
Parse a 'many' relationship. @param string $relation @throws MappingException @return bool
[ "Parse", "a", "many", "relationship", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L258-L289
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getRelationshipValue
protected function getRelationshipValue(string $relation) { $value = $this->getEntityAttribute($relation); if (is_scalar($value)) { throw new MappingException("Entity's attribute $relation should be array, object, collection or null"); } return $value; }
php
protected function getRelationshipValue(string $relation) { $value = $this->getEntityAttribute($relation); if (is_scalar($value)) { throw new MappingException("Entity's attribute $relation should be array, object, collection or null"); } return $value; }
[ "protected", "function", "getRelationshipValue", "(", "string", "$", "relation", ")", "{", "$", "value", "=", "$", "this", "->", "getEntityAttribute", "(", "$", "relation", ")", ";", "if", "(", "is_scalar", "(", "$", "value", ")", ")", "{", "throw", "new", "MappingException", "(", "\"Entity's attribute $relation should be array, object, collection or null\"", ")", ";", "}", "return", "$", "value", ";", "}" ]
Return Entity's relationship attribute. @param string $relation @throws MappingException @return mixed
[ "Return", "Entity", "s", "relationship", "attribute", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L300-L309
analogueorm/analogue
src/System/Aggregate.php
Aggregate.createSubAggregates
protected function createSubAggregates($entities, string $relation): array { $aggregates = []; foreach ($entities as $entity) { $aggregates[] = $this->createSubAggregate($entity, $relation); } return $aggregates; }
php
protected function createSubAggregates($entities, string $relation): array { $aggregates = []; foreach ($entities as $entity) { $aggregates[] = $this->createSubAggregate($entity, $relation); } return $aggregates; }
[ "protected", "function", "createSubAggregates", "(", "$", "entities", ",", "string", "$", "relation", ")", ":", "array", "{", "$", "aggregates", "=", "[", "]", ";", "foreach", "(", "$", "entities", "as", "$", "entity", ")", "{", "$", "aggregates", "[", "]", "=", "$", "this", "->", "createSubAggregate", "(", "$", "entity", ",", "$", "relation", ")", ";", "}", "return", "$", "aggregates", ";", "}" ]
Create a child, aggregated entity. @param mixed $entities @param string $relation @return array
[ "Create", "a", "child", "aggregated", "entity", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L319-L328
analogueorm/analogue
src/System/Aggregate.php
Aggregate.createSubAggregate
protected function createSubAggregate($entity, string $relation): self { // If root isn't defined, then this is the Aggregate Root $root = is_null($this->root) ? $this : $this->root; return new self($entity, $this, $relation, $root); }
php
protected function createSubAggregate($entity, string $relation): self { // If root isn't defined, then this is the Aggregate Root $root = is_null($this->root) ? $this : $this->root; return new self($entity, $this, $relation, $root); }
[ "protected", "function", "createSubAggregate", "(", "$", "entity", ",", "string", "$", "relation", ")", ":", "self", "{", "// If root isn't defined, then this is the Aggregate Root", "$", "root", "=", "is_null", "(", "$", "this", "->", "root", ")", "?", "$", "this", ":", "$", "this", "->", "root", ";", "return", "new", "self", "(", "$", "entity", ",", "$", "this", ",", "$", "relation", ",", "$", "root", ")", ";", "}" ]
Create a related subAggregate. @param mixed $entity @param string $relation @throws MappingException @return Aggregate
[ "Create", "a", "related", "subAggregate", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L340-L346
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getEntityKeyValue
public function getEntityKeyValue() { $keyValue = $this->wrappedEntity->getEntityKeyValue(); if ($keyValue instanceof ObjectId) { $keyValue = (string) $keyValue; } return $keyValue; }
php
public function getEntityKeyValue() { $keyValue = $this->wrappedEntity->getEntityKeyValue(); if ($keyValue instanceof ObjectId) { $keyValue = (string) $keyValue; } return $keyValue; }
[ "public", "function", "getEntityKeyValue", "(", ")", "{", "$", "keyValue", "=", "$", "this", "->", "wrappedEntity", "->", "getEntityKeyValue", "(", ")", ";", "if", "(", "$", "keyValue", "instanceof", "ObjectId", ")", "{", "$", "keyValue", "=", "(", "string", ")", "$", "keyValue", ";", "}", "return", "$", "keyValue", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L377-L386
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getRelationship
public function getRelationship(string $name): array { if (array_key_exists($name, $this->relationships)) { return $this->relationships[$name]; } return []; }
php
public function getRelationship(string $name): array { if (array_key_exists($name, $this->relationships)) { return $this->relationships[$name]; } return []; }
[ "public", "function", "getRelationship", "(", "string", "$", "name", ")", ":", "array", "{", "if", "(", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "relationships", ")", ")", "{", "return", "$", "this", "->", "relationships", "[", "$", "name", "]", ";", "}", "return", "[", "]", ";", "}" ]
Get a relationship as an aggregated entities' array. @param string $name @return array
[ "Get", "a", "relationship", "as", "an", "aggregated", "entities", "array", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L413-L420
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getNonExistingRelated
public function getNonExistingRelated(array $relationships): array { $nonExisting = []; foreach ($relationships as $relation) { if ($this->hasAttribute($relation) && array_key_exists($relation, $this->relationships)) { $nonExisting = array_merge($nonExisting, $this->getNonExistingFromRelation($relation)); } } return $nonExisting; }
php
public function getNonExistingRelated(array $relationships): array { $nonExisting = []; foreach ($relationships as $relation) { if ($this->hasAttribute($relation) && array_key_exists($relation, $this->relationships)) { $nonExisting = array_merge($nonExisting, $this->getNonExistingFromRelation($relation)); } } return $nonExisting; }
[ "public", "function", "getNonExistingRelated", "(", "array", "$", "relationships", ")", ":", "array", "{", "$", "nonExisting", "=", "[", "]", ";", "foreach", "(", "$", "relationships", "as", "$", "relation", ")", "{", "if", "(", "$", "this", "->", "hasAttribute", "(", "$", "relation", ")", "&&", "array_key_exists", "(", "$", "relation", ",", "$", "this", "->", "relationships", ")", ")", "{", "$", "nonExisting", "=", "array_merge", "(", "$", "nonExisting", ",", "$", "this", "->", "getNonExistingFromRelation", "(", "$", "relation", ")", ")", ";", "}", "}", "return", "$", "nonExisting", ";", "}" ]
Get Non existing related entities from several relationships. @param array $relationships @return array
[ "Get", "Non", "existing", "related", "entities", "from", "several", "relationships", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L439-L450
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getNonExistingFromRelation
protected function getNonExistingFromRelation(string $relation): array { $nonExisting = []; foreach ($this->relationships[$relation] as $aggregate) { if (!$aggregate->exists()) { $nonExisting[] = $aggregate; } } return $nonExisting; }
php
protected function getNonExistingFromRelation(string $relation): array { $nonExisting = []; foreach ($this->relationships[$relation] as $aggregate) { if (!$aggregate->exists()) { $nonExisting[] = $aggregate; } } return $nonExisting; }
[ "protected", "function", "getNonExistingFromRelation", "(", "string", "$", "relation", ")", ":", "array", "{", "$", "nonExisting", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "relationships", "[", "$", "relation", "]", "as", "$", "aggregate", ")", "{", "if", "(", "!", "$", "aggregate", "->", "exists", "(", ")", ")", "{", "$", "nonExisting", "[", "]", "=", "$", "aggregate", ";", "}", "}", "return", "$", "nonExisting", ";", "}" ]
Get non-existing related entities from a single relation. @param string $relation @return array
[ "Get", "non", "-", "existing", "related", "entities", "from", "a", "single", "relation", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L459-L470
analogueorm/analogue
src/System/Aggregate.php
Aggregate.syncRelationships
public function syncRelationships(array $relationships) { foreach ($relationships as $relation) { if (in_array($relation, $this->needSync)) { $this->synchronize($relation); } } }
php
public function syncRelationships(array $relationships) { foreach ($relationships as $relation) { if (in_array($relation, $this->needSync)) { $this->synchronize($relation); } } }
[ "public", "function", "syncRelationships", "(", "array", "$", "relationships", ")", "{", "foreach", "(", "$", "relationships", "as", "$", "relation", ")", "{", "if", "(", "in_array", "(", "$", "relation", ",", "$", "this", "->", "needSync", ")", ")", "{", "$", "this", "->", "synchronize", "(", "$", "relation", ")", ";", "}", "}", "}" ]
Synchronize relationships if needed. @param array @return void
[ "Synchronize", "relationships", "if", "needed", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L479-L486
analogueorm/analogue
src/System/Aggregate.php
Aggregate.synchronize
protected function synchronize(string $relation) { $actualContent = $this->relationships[$relation]; $relationshipObject = $this->entityMap->$relation($this->getEntityObject()); $relationshipObject->setParent($this->wrappedEntity); $relationshipObject->sync($actualContent); }
php
protected function synchronize(string $relation) { $actualContent = $this->relationships[$relation]; $relationshipObject = $this->entityMap->$relation($this->getEntityObject()); $relationshipObject->setParent($this->wrappedEntity); $relationshipObject->sync($actualContent); }
[ "protected", "function", "synchronize", "(", "string", "$", "relation", ")", "{", "$", "actualContent", "=", "$", "this", "->", "relationships", "[", "$", "relation", "]", ";", "$", "relationshipObject", "=", "$", "this", "->", "entityMap", "->", "$", "relation", "(", "$", "this", "->", "getEntityObject", "(", ")", ")", ";", "$", "relationshipObject", "->", "setParent", "(", "$", "this", "->", "wrappedEntity", ")", ";", "$", "relationshipObject", "->", "sync", "(", "$", "actualContent", ")", ";", "}" ]
Synchronize a relationship attribute. @param string $relation @return void
[ "Synchronize", "a", "relationship", "attribute", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L495-L502
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getMissingEntities
public function getMissingEntities(string $relation): array { $cachedRelations = $this->getCachedAttribute($relation); if (is_null($cachedRelations)) { return []; } $missing = []; foreach ($cachedRelations as $hash) { if (!$this->getRelatedAggregateFromHash($hash, $relation)) { $missing[] = $hash; } } return $missing; }
php
public function getMissingEntities(string $relation): array { $cachedRelations = $this->getCachedAttribute($relation); if (is_null($cachedRelations)) { return []; } $missing = []; foreach ($cachedRelations as $hash) { if (!$this->getRelatedAggregateFromHash($hash, $relation)) { $missing[] = $hash; } } return $missing; }
[ "public", "function", "getMissingEntities", "(", "string", "$", "relation", ")", ":", "array", "{", "$", "cachedRelations", "=", "$", "this", "->", "getCachedAttribute", "(", "$", "relation", ")", ";", "if", "(", "is_null", "(", "$", "cachedRelations", ")", ")", "{", "return", "[", "]", ";", "}", "$", "missing", "=", "[", "]", ";", "foreach", "(", "$", "cachedRelations", "as", "$", "hash", ")", "{", "if", "(", "!", "$", "this", "->", "getRelatedAggregateFromHash", "(", "$", "hash", ",", "$", "relation", ")", ")", "{", "$", "missing", "[", "]", "=", "$", "hash", ";", "}", "}", "return", "$", "missing", ";", "}" ]
Returns an array of Missing related Entities for the given $relation. @param string $relation @return array
[ "Returns", "an", "array", "of", "Missing", "related", "Entities", "for", "the", "given", "$relation", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L512-L529
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getDirtyRelationships
public function getDirtyRelationships(): array { $dirtyAggregates = []; foreach ($this->relationships as $relation) { foreach ($relation as $aggregate) { if (!$aggregate->exists() || $aggregate->isDirty() || count($aggregate->getDirtyRelationships()) > 0) { $dirtyAggregates[] = $aggregate; } } } return $dirtyAggregates; }
php
public function getDirtyRelationships(): array { $dirtyAggregates = []; foreach ($this->relationships as $relation) { foreach ($relation as $aggregate) { if (!$aggregate->exists() || $aggregate->isDirty() || count($aggregate->getDirtyRelationships()) > 0) { $dirtyAggregates[] = $aggregate; } } } return $dirtyAggregates; }
[ "public", "function", "getDirtyRelationships", "(", ")", ":", "array", "{", "$", "dirtyAggregates", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "relationships", "as", "$", "relation", ")", "{", "foreach", "(", "$", "relation", "as", "$", "aggregate", ")", "{", "if", "(", "!", "$", "aggregate", "->", "exists", "(", ")", "||", "$", "aggregate", "->", "isDirty", "(", ")", "||", "count", "(", "$", "aggregate", "->", "getDirtyRelationships", "(", ")", ")", ">", "0", ")", "{", "$", "dirtyAggregates", "[", "]", "=", "$", "aggregate", ";", "}", "}", "}", "return", "$", "dirtyAggregates", ";", "}" ]
Get Relationships who have dirty attributes / dirty relationships. @return array
[ "Get", "Relationships", "who", "have", "dirty", "attributes", "/", "dirty", "relationships", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L536-L549
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getRawAttributes
public function getRawAttributes(): array { $attributes = $this->wrappedEntity->getEntityAttributes(); foreach ($this->entityMap->getNonEmbeddedRelationships() as $relation) { unset($attributes[$relation]); } if ($this->entityMap->getInheritanceType() == 'single_table') { $attributes = $this->addDiscriminatorColumn($attributes); } $attributes = $this->entityMap->getColumnNamesFromAttributes($attributes); $attributes = $this->flattenEmbeddables($attributes); $foreignKeys = $this->getForeignKeyAttributes(); return $this->mergeForeignKeysWithAttributes($foreignKeys, $attributes); }
php
public function getRawAttributes(): array { $attributes = $this->wrappedEntity->getEntityAttributes(); foreach ($this->entityMap->getNonEmbeddedRelationships() as $relation) { unset($attributes[$relation]); } if ($this->entityMap->getInheritanceType() == 'single_table') { $attributes = $this->addDiscriminatorColumn($attributes); } $attributes = $this->entityMap->getColumnNamesFromAttributes($attributes); $attributes = $this->flattenEmbeddables($attributes); $foreignKeys = $this->getForeignKeyAttributes(); return $this->mergeForeignKeysWithAttributes($foreignKeys, $attributes); }
[ "public", "function", "getRawAttributes", "(", ")", ":", "array", "{", "$", "attributes", "=", "$", "this", "->", "wrappedEntity", "->", "getEntityAttributes", "(", ")", ";", "foreach", "(", "$", "this", "->", "entityMap", "->", "getNonEmbeddedRelationships", "(", ")", "as", "$", "relation", ")", "{", "unset", "(", "$", "attributes", "[", "$", "relation", "]", ")", ";", "}", "if", "(", "$", "this", "->", "entityMap", "->", "getInheritanceType", "(", ")", "==", "'single_table'", ")", "{", "$", "attributes", "=", "$", "this", "->", "addDiscriminatorColumn", "(", "$", "attributes", ")", ";", "}", "$", "attributes", "=", "$", "this", "->", "entityMap", "->", "getColumnNamesFromAttributes", "(", "$", "attributes", ")", ";", "$", "attributes", "=", "$", "this", "->", "flattenEmbeddables", "(", "$", "attributes", ")", ";", "$", "foreignKeys", "=", "$", "this", "->", "getForeignKeyAttributes", "(", ")", ";", "return", "$", "this", "->", "mergeForeignKeysWithAttributes", "(", "$", "foreignKeys", ",", "$", "attributes", ")", ";", "}" ]
Get Raw Entity's attributes, as they are represented in the database, including value objects, foreign keys, and discriminator column. @return array
[ "Get", "Raw", "Entity", "s", "attributes", "as", "they", "are", "represented", "in", "the", "database", "including", "value", "objects", "foreign", "keys", "and", "discriminator", "column", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L568-L587
analogueorm/analogue
src/System/Aggregate.php
Aggregate.mergeForeignKeysWithAttributes
protected function mergeForeignKeysWithAttributes(array $foreignKeys, array $attributes): array { $cachedAttributes = $this->getCachedRawAttributes(); foreach ($foreignKeys as $fkAttributeKey => $fkAttributeValue) { // FK doesn't exist in attributes => we set it if (!array_key_exists($fkAttributeKey, $attributes)) { $attributes[$fkAttributeKey] = $fkAttributeValue; continue; } // FK does exists in attributes and is equal => we set it if ($attributes[$fkAttributeKey] === $fkAttributeValue) { $attributes[$fkAttributeKey] = $fkAttributeValue; continue; } // ForeignKey exists in attributes array, but the value is different that // the one fetched from the relationship itself. // Does it exist in cache if (array_key_exists($fkAttributeKey, $cachedAttributes)) { // attribute is different than cached value, we use it if ($attributes[$fkAttributeKey] !== $cachedAttributes[$fkAttributeKey]) { continue; } else { // if not, we use the foreign key value $attributes[$fkAttributeKey] = $fkAttributeValue; } } else { if (is_null($attributes[$fkAttributeKey])) { $attributes[$fkAttributeKey] = $fkAttributeValue; } } } return $attributes; }
php
protected function mergeForeignKeysWithAttributes(array $foreignKeys, array $attributes): array { $cachedAttributes = $this->getCachedRawAttributes(); foreach ($foreignKeys as $fkAttributeKey => $fkAttributeValue) { // FK doesn't exist in attributes => we set it if (!array_key_exists($fkAttributeKey, $attributes)) { $attributes[$fkAttributeKey] = $fkAttributeValue; continue; } // FK does exists in attributes and is equal => we set it if ($attributes[$fkAttributeKey] === $fkAttributeValue) { $attributes[$fkAttributeKey] = $fkAttributeValue; continue; } // ForeignKey exists in attributes array, but the value is different that // the one fetched from the relationship itself. // Does it exist in cache if (array_key_exists($fkAttributeKey, $cachedAttributes)) { // attribute is different than cached value, we use it if ($attributes[$fkAttributeKey] !== $cachedAttributes[$fkAttributeKey]) { continue; } else { // if not, we use the foreign key value $attributes[$fkAttributeKey] = $fkAttributeValue; } } else { if (is_null($attributes[$fkAttributeKey])) { $attributes[$fkAttributeKey] = $fkAttributeValue; } } } return $attributes; }
[ "protected", "function", "mergeForeignKeysWithAttributes", "(", "array", "$", "foreignKeys", ",", "array", "$", "attributes", ")", ":", "array", "{", "$", "cachedAttributes", "=", "$", "this", "->", "getCachedRawAttributes", "(", ")", ";", "foreach", "(", "$", "foreignKeys", "as", "$", "fkAttributeKey", "=>", "$", "fkAttributeValue", ")", "{", "// FK doesn't exist in attributes => we set it", "if", "(", "!", "array_key_exists", "(", "$", "fkAttributeKey", ",", "$", "attributes", ")", ")", "{", "$", "attributes", "[", "$", "fkAttributeKey", "]", "=", "$", "fkAttributeValue", ";", "continue", ";", "}", "// FK does exists in attributes and is equal => we set it", "if", "(", "$", "attributes", "[", "$", "fkAttributeKey", "]", "===", "$", "fkAttributeValue", ")", "{", "$", "attributes", "[", "$", "fkAttributeKey", "]", "=", "$", "fkAttributeValue", ";", "continue", ";", "}", "// ForeignKey exists in attributes array, but the value is different that", "// the one fetched from the relationship itself.", "// Does it exist in cache", "if", "(", "array_key_exists", "(", "$", "fkAttributeKey", ",", "$", "cachedAttributes", ")", ")", "{", "// attribute is different than cached value, we use it", "if", "(", "$", "attributes", "[", "$", "fkAttributeKey", "]", "!==", "$", "cachedAttributes", "[", "$", "fkAttributeKey", "]", ")", "{", "continue", ";", "}", "else", "{", "// if not, we use the foreign key value", "$", "attributes", "[", "$", "fkAttributeKey", "]", "=", "$", "fkAttributeValue", ";", "}", "}", "else", "{", "if", "(", "is_null", "(", "$", "attributes", "[", "$", "fkAttributeKey", "]", ")", ")", "{", "$", "attributes", "[", "$", "fkAttributeKey", "]", "=", "$", "fkAttributeValue", ";", "}", "}", "}", "return", "$", "attributes", ";", "}" ]
Merge foreign keys and attributes by comparing their current value to the cache, and guess the user intent. @param array $foreignKeys @param array $attributes @return array
[ "Merge", "foreign", "keys", "and", "attributes", "by", "comparing", "their", "current", "value", "to", "the", "cache", "and", "guess", "the", "user", "intent", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L598-L634
analogueorm/analogue
src/System/Aggregate.php
Aggregate.addDiscriminatorColumn
protected function addDiscriminatorColumn(array $attributes): array { $discriminatorColumn = $this->entityMap->getDiscriminatorColumn(); $entityClass = $this->entityMap->getClass(); if (!array_key_exists($discriminatorColumn, $attributes)) { // Use key if present in discriminatorMap $map = $this->entityMap->getDiscriminatorColumnMap(); $type = array_search($entityClass, $map); if ($type === false) { // Use entity FQCN if no corresponding key is set $attributes[$discriminatorColumn] = $entityClass; } else { $attributes[$discriminatorColumn] = $type; } } return $attributes; }
php
protected function addDiscriminatorColumn(array $attributes): array { $discriminatorColumn = $this->entityMap->getDiscriminatorColumn(); $entityClass = $this->entityMap->getClass(); if (!array_key_exists($discriminatorColumn, $attributes)) { // Use key if present in discriminatorMap $map = $this->entityMap->getDiscriminatorColumnMap(); $type = array_search($entityClass, $map); if ($type === false) { // Use entity FQCN if no corresponding key is set $attributes[$discriminatorColumn] = $entityClass; } else { $attributes[$discriminatorColumn] = $type; } } return $attributes; }
[ "protected", "function", "addDiscriminatorColumn", "(", "array", "$", "attributes", ")", ":", "array", "{", "$", "discriminatorColumn", "=", "$", "this", "->", "entityMap", "->", "getDiscriminatorColumn", "(", ")", ";", "$", "entityClass", "=", "$", "this", "->", "entityMap", "->", "getClass", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "discriminatorColumn", ",", "$", "attributes", ")", ")", "{", "// Use key if present in discriminatorMap", "$", "map", "=", "$", "this", "->", "entityMap", "->", "getDiscriminatorColumnMap", "(", ")", ";", "$", "type", "=", "array_search", "(", "$", "entityClass", ",", "$", "map", ")", ";", "if", "(", "$", "type", "===", "false", ")", "{", "// Use entity FQCN if no corresponding key is set", "$", "attributes", "[", "$", "discriminatorColumn", "]", "=", "$", "entityClass", ";", "}", "else", "{", "$", "attributes", "[", "$", "discriminatorColumn", "]", "=", "$", "type", ";", "}", "}", "return", "$", "attributes", ";", "}" ]
Add Discriminator Column if it doesn't exist on the actual entity. @param array $attributes @return array
[ "Add", "Discriminator", "Column", "if", "it", "doesn", "t", "exist", "on", "the", "actual", "entity", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L643-L663
analogueorm/analogue
src/System/Aggregate.php
Aggregate.flattenEmbeddables
protected function flattenEmbeddables(array $attributes): array { // TODO : deprecate old implementation $embeddables = $this->entityMap->getEmbeddables(); foreach ($embeddables as $localKey => $embed) { // Retrieve the value object from the entity's attributes $valueObject = $attributes[$localKey]; // Unset the corresponding key unset($attributes[$localKey]); // TODO Make wrapper object compatible with value objects $valueObjectAttributes = $valueObject->getEntityAttributes(); $voMap = $this->getMapper()->getManager()->getValueMap($embed); $valueObjectAttributes = $voMap->getColumnNamesFromAttributes($valueObjectAttributes); // Now (if setup in the entity map) we prefix the value object's // attributes with the snake_case name of the embedded class. $prefix = snake_case(class_basename($embed)); foreach ($valueObjectAttributes as $key => $value) { $valueObjectAttributes[$prefix.'_'.$key] = $value; unset($valueObjectAttributes[$key]); } $attributes = array_merge($attributes, $valueObjectAttributes); } //********************* // New implementation // *****************-> $embeddedRelations = $this->entityMap->getEmbeddedRelationships(); foreach ($embeddedRelations as $relation) { // Spawn a new instance we can pass to the relationship method $parentInstance = $this->getMapper()->newInstance(); $relationInstance = $this->entityMap->$relation($parentInstance); // Extract the object from the attributes $embeddedObject = $attributes[$relation]; unset($attributes[$relation]); $attributes = $relationInstance->normalize($embeddedObject) + $attributes; } return $attributes; }
php
protected function flattenEmbeddables(array $attributes): array { // TODO : deprecate old implementation $embeddables = $this->entityMap->getEmbeddables(); foreach ($embeddables as $localKey => $embed) { // Retrieve the value object from the entity's attributes $valueObject = $attributes[$localKey]; // Unset the corresponding key unset($attributes[$localKey]); // TODO Make wrapper object compatible with value objects $valueObjectAttributes = $valueObject->getEntityAttributes(); $voMap = $this->getMapper()->getManager()->getValueMap($embed); $valueObjectAttributes = $voMap->getColumnNamesFromAttributes($valueObjectAttributes); // Now (if setup in the entity map) we prefix the value object's // attributes with the snake_case name of the embedded class. $prefix = snake_case(class_basename($embed)); foreach ($valueObjectAttributes as $key => $value) { $valueObjectAttributes[$prefix.'_'.$key] = $value; unset($valueObjectAttributes[$key]); } $attributes = array_merge($attributes, $valueObjectAttributes); } //********************* // New implementation // *****************-> $embeddedRelations = $this->entityMap->getEmbeddedRelationships(); foreach ($embeddedRelations as $relation) { // Spawn a new instance we can pass to the relationship method $parentInstance = $this->getMapper()->newInstance(); $relationInstance = $this->entityMap->$relation($parentInstance); // Extract the object from the attributes $embeddedObject = $attributes[$relation]; unset($attributes[$relation]); $attributes = $relationInstance->normalize($embeddedObject) + $attributes; } return $attributes; }
[ "protected", "function", "flattenEmbeddables", "(", "array", "$", "attributes", ")", ":", "array", "{", "// TODO : deprecate old implementation", "$", "embeddables", "=", "$", "this", "->", "entityMap", "->", "getEmbeddables", "(", ")", ";", "foreach", "(", "$", "embeddables", "as", "$", "localKey", "=>", "$", "embed", ")", "{", "// Retrieve the value object from the entity's attributes", "$", "valueObject", "=", "$", "attributes", "[", "$", "localKey", "]", ";", "// Unset the corresponding key", "unset", "(", "$", "attributes", "[", "$", "localKey", "]", ")", ";", "// TODO Make wrapper object compatible with value objects", "$", "valueObjectAttributes", "=", "$", "valueObject", "->", "getEntityAttributes", "(", ")", ";", "$", "voMap", "=", "$", "this", "->", "getMapper", "(", ")", "->", "getManager", "(", ")", "->", "getValueMap", "(", "$", "embed", ")", ";", "$", "valueObjectAttributes", "=", "$", "voMap", "->", "getColumnNamesFromAttributes", "(", "$", "valueObjectAttributes", ")", ";", "// Now (if setup in the entity map) we prefix the value object's", "// attributes with the snake_case name of the embedded class.", "$", "prefix", "=", "snake_case", "(", "class_basename", "(", "$", "embed", ")", ")", ";", "foreach", "(", "$", "valueObjectAttributes", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "valueObjectAttributes", "[", "$", "prefix", ".", "'_'", ".", "$", "key", "]", "=", "$", "value", ";", "unset", "(", "$", "valueObjectAttributes", "[", "$", "key", "]", ")", ";", "}", "$", "attributes", "=", "array_merge", "(", "$", "attributes", ",", "$", "valueObjectAttributes", ")", ";", "}", "//*********************", "// New implementation", "// *****************->", "$", "embeddedRelations", "=", "$", "this", "->", "entityMap", "->", "getEmbeddedRelationships", "(", ")", ";", "foreach", "(", "$", "embeddedRelations", "as", "$", "relation", ")", "{", "// Spawn a new instance we can pass to the relationship method", "$", "parentInstance", "=", "$", "this", "->", "getMapper", "(", ")", "->", "newInstance", "(", ")", ";", "$", "relationInstance", "=", "$", "this", "->", "entityMap", "->", "$", "relation", "(", "$", "parentInstance", ")", ";", "// Extract the object from the attributes", "$", "embeddedObject", "=", "$", "attributes", "[", "$", "relation", "]", ";", "unset", "(", "$", "attributes", "[", "$", "relation", "]", ")", ";", "$", "attributes", "=", "$", "relationInstance", "->", "normalize", "(", "$", "embeddedObject", ")", "+", "$", "attributes", ";", "}", "return", "$", "attributes", ";", "}" ]
Convert Value Objects to raw db attributes. @param array $attributes @return array
[ "Convert", "Value", "Objects", "to", "raw", "db", "attributes", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L672-L722
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getCachedRawAttributes
protected function getCachedRawAttributes(array $columns = null): array { $cachedAttributes = $this->getCache()->get($this->getEntityKeyValue()); if (is_null($columns)) { return $cachedAttributes; } return array_only($cachedAttributes, $columns); }
php
protected function getCachedRawAttributes(array $columns = null): array { $cachedAttributes = $this->getCache()->get($this->getEntityKeyValue()); if (is_null($columns)) { return $cachedAttributes; } return array_only($cachedAttributes, $columns); }
[ "protected", "function", "getCachedRawAttributes", "(", "array", "$", "columns", "=", "null", ")", ":", "array", "{", "$", "cachedAttributes", "=", "$", "this", "->", "getCache", "(", ")", "->", "get", "(", "$", "this", "->", "getEntityKeyValue", "(", ")", ")", ";", "if", "(", "is_null", "(", "$", "columns", ")", ")", "{", "return", "$", "cachedAttributes", ";", "}", "return", "array_only", "(", "$", "cachedAttributes", ",", "$", "columns", ")", ";", "}" ]
Return's entity raw attributes in the state they were at last query. @param array|null $columns @return array
[ "Return", "s", "entity", "raw", "attributes", "in", "the", "state", "they", "were", "at", "last", "query", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L732-L741
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getCachedAttribute
protected function getCachedAttribute($key) { $cachedAttributes = $this->getCache()->get($this->getEntityKeyValue()); if (array_key_exists($key, $cachedAttributes)) { return $cachedAttributes[$key]; } }
php
protected function getCachedAttribute($key) { $cachedAttributes = $this->getCache()->get($this->getEntityKeyValue()); if (array_key_exists($key, $cachedAttributes)) { return $cachedAttributes[$key]; } }
[ "protected", "function", "getCachedAttribute", "(", "$", "key", ")", "{", "$", "cachedAttributes", "=", "$", "this", "->", "getCache", "(", ")", "->", "get", "(", "$", "this", "->", "getEntityKeyValue", "(", ")", ")", ";", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "cachedAttributes", ")", ")", "{", "return", "$", "cachedAttributes", "[", "$", "key", "]", ";", "}", "}" ]
Return a single attribute from the cache. @param string $key @return mixed|null
[ "Return", "a", "single", "attribute", "from", "the", "cache", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L750-L757
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getForeignKeyAttributes
public function getForeignKeyAttributes(): array { $foreignKeys = []; foreach ($this->entityMap->getLocalRelationships() as $relation) { // If the actual relationship is a non-loaded proxy, we'll simply retrieve // the foreign key pair without parsing the actual object. This will allow // user to modify the actual related ID's directly by updating the corresponding // attribute. if ($this->isNonLoadedProxy($relation)) { $foreignKeys = $foreignKeys + $this->getForeignKeyAttributesFromNonLoadedRelation($relation); continue; } // check if relationship has been parsed, meaning it has an actual object // in the entity's attributes if ($this->isActualRelationships($relation)) { $foreignKeys = $foreignKeys + $this->getForeignKeyAttributesFromRelation($relation); } else { $foreignKeys = $foreignKeys + $this->getNullForeignKeyFromRelation($relation); } } if (!is_null($this->parent)) { $foreignKeys = $this->getForeignKeyAttributesFromParent() + $foreignKeys; } return $foreignKeys; }
php
public function getForeignKeyAttributes(): array { $foreignKeys = []; foreach ($this->entityMap->getLocalRelationships() as $relation) { // If the actual relationship is a non-loaded proxy, we'll simply retrieve // the foreign key pair without parsing the actual object. This will allow // user to modify the actual related ID's directly by updating the corresponding // attribute. if ($this->isNonLoadedProxy($relation)) { $foreignKeys = $foreignKeys + $this->getForeignKeyAttributesFromNonLoadedRelation($relation); continue; } // check if relationship has been parsed, meaning it has an actual object // in the entity's attributes if ($this->isActualRelationships($relation)) { $foreignKeys = $foreignKeys + $this->getForeignKeyAttributesFromRelation($relation); } else { $foreignKeys = $foreignKeys + $this->getNullForeignKeyFromRelation($relation); } } if (!is_null($this->parent)) { $foreignKeys = $this->getForeignKeyAttributesFromParent() + $foreignKeys; } return $foreignKeys; }
[ "public", "function", "getForeignKeyAttributes", "(", ")", ":", "array", "{", "$", "foreignKeys", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "entityMap", "->", "getLocalRelationships", "(", ")", "as", "$", "relation", ")", "{", "// If the actual relationship is a non-loaded proxy, we'll simply retrieve", "// the foreign key pair without parsing the actual object. This will allow", "// user to modify the actual related ID's directly by updating the corresponding", "// attribute.", "if", "(", "$", "this", "->", "isNonLoadedProxy", "(", "$", "relation", ")", ")", "{", "$", "foreignKeys", "=", "$", "foreignKeys", "+", "$", "this", "->", "getForeignKeyAttributesFromNonLoadedRelation", "(", "$", "relation", ")", ";", "continue", ";", "}", "// check if relationship has been parsed, meaning it has an actual object", "// in the entity's attributes", "if", "(", "$", "this", "->", "isActualRelationships", "(", "$", "relation", ")", ")", "{", "$", "foreignKeys", "=", "$", "foreignKeys", "+", "$", "this", "->", "getForeignKeyAttributesFromRelation", "(", "$", "relation", ")", ";", "}", "else", "{", "$", "foreignKeys", "=", "$", "foreignKeys", "+", "$", "this", "->", "getNullForeignKeyFromRelation", "(", "$", "relation", ")", ";", "}", "}", "if", "(", "!", "is_null", "(", "$", "this", "->", "parent", ")", ")", "{", "$", "foreignKeys", "=", "$", "this", "->", "getForeignKeyAttributesFromParent", "(", ")", "+", "$", "foreignKeys", ";", "}", "return", "$", "foreignKeys", ";", "}" ]
Convert related Entity's attributes to foreign keys. @return array
[ "Convert", "related", "Entity", "s", "attributes", "to", "foreign", "keys", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L764-L792
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getNullForeignKeyFromRelation
protected function getNullForeignKeyFromRelation(string $relation): array { $key = $this->entityMap->getLocalKeys($relation); if (is_array($key)) { return $this->entityMap->getEmptyValueForLocalKey($relation); } if (is_null($key)) { throw new MappingException("Foreign key for relation $relation cannot be null"); } return [ $key => $this->entityMap->getEmptyValueForLocalKey($relation), ]; }
php
protected function getNullForeignKeyFromRelation(string $relation): array { $key = $this->entityMap->getLocalKeys($relation); if (is_array($key)) { return $this->entityMap->getEmptyValueForLocalKey($relation); } if (is_null($key)) { throw new MappingException("Foreign key for relation $relation cannot be null"); } return [ $key => $this->entityMap->getEmptyValueForLocalKey($relation), ]; }
[ "protected", "function", "getNullForeignKeyFromRelation", "(", "string", "$", "relation", ")", ":", "array", "{", "$", "key", "=", "$", "this", "->", "entityMap", "->", "getLocalKeys", "(", "$", "relation", ")", ";", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "return", "$", "this", "->", "entityMap", "->", "getEmptyValueForLocalKey", "(", "$", "relation", ")", ";", "}", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "throw", "new", "MappingException", "(", "\"Foreign key for relation $relation cannot be null\"", ")", ";", "}", "return", "[", "$", "key", "=>", "$", "this", "->", "entityMap", "->", "getEmptyValueForLocalKey", "(", "$", "relation", ")", ",", "]", ";", "}" ]
Get a null foreign key value pair for an empty relationship. @param string $relation @throws MappingException @return array
[ "Get", "a", "null", "foreign", "key", "value", "pair", "for", "an", "empty", "relationship", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L803-L818
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getForeignKeyAttributesFromRelation
protected function getForeignKeyAttributesFromRelation(string $relation): array { // Call Relationship's method $relationship = $this->entityMap->$relation($this->getEntityObject()); $relatedAggregate = $this->relationships[$relation][0]; return $relationship->getForeignKeyValuePair($relatedAggregate->getEntityObject()); }
php
protected function getForeignKeyAttributesFromRelation(string $relation): array { // Call Relationship's method $relationship = $this->entityMap->$relation($this->getEntityObject()); $relatedAggregate = $this->relationships[$relation][0]; return $relationship->getForeignKeyValuePair($relatedAggregate->getEntityObject()); }
[ "protected", "function", "getForeignKeyAttributesFromRelation", "(", "string", "$", "relation", ")", ":", "array", "{", "// Call Relationship's method", "$", "relationship", "=", "$", "this", "->", "entityMap", "->", "$", "relation", "(", "$", "this", "->", "getEntityObject", "(", ")", ")", ";", "$", "relatedAggregate", "=", "$", "this", "->", "relationships", "[", "$", "relation", "]", "[", "0", "]", ";", "return", "$", "relationship", "->", "getForeignKeyValuePair", "(", "$", "relatedAggregate", "->", "getEntityObject", "(", ")", ")", ";", "}" ]
Return an associative array containing the key-value pair(s) from the related entity. @param string $relation @return array
[ "Return", "an", "associative", "array", "containing", "the", "key", "-", "value", "pair", "(", "s", ")", "from", "the", "related", "entity", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L828-L836
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getForeignKeyAttributesFromNonLoadedRelation
protected function getForeignKeyAttributesFromNonLoadedRelation(string $relation): array { $keys = $this->entityMap->getLocalKeys($relation); // We'll treat single and composite keys (polymorphic) the same way. if (!is_array($keys)) { $keys = [$keys]; } $foreignKey = []; foreach ($keys as $key) { $foreignKey[$key] = $this->getEntityAttribute($key); } return $foreignKey; }
php
protected function getForeignKeyAttributesFromNonLoadedRelation(string $relation): array { $keys = $this->entityMap->getLocalKeys($relation); // We'll treat single and composite keys (polymorphic) the same way. if (!is_array($keys)) { $keys = [$keys]; } $foreignKey = []; foreach ($keys as $key) { $foreignKey[$key] = $this->getEntityAttribute($key); } return $foreignKey; }
[ "protected", "function", "getForeignKeyAttributesFromNonLoadedRelation", "(", "string", "$", "relation", ")", ":", "array", "{", "$", "keys", "=", "$", "this", "->", "entityMap", "->", "getLocalKeys", "(", "$", "relation", ")", ";", "// We'll treat single and composite keys (polymorphic) the same way.", "if", "(", "!", "is_array", "(", "$", "keys", ")", ")", "{", "$", "keys", "=", "[", "$", "keys", "]", ";", "}", "$", "foreignKey", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "foreignKey", "[", "$", "key", "]", "=", "$", "this", "->", "getEntityAttribute", "(", "$", "key", ")", ";", "}", "return", "$", "foreignKey", ";", "}" ]
Return an associative array containing the key-value pair(s) from the foreign key attribute. @param string $relation @return array
[ "Return", "an", "associative", "array", "containing", "the", "key", "-", "value", "pair", "(", "s", ")", "from", "the", "foreign", "key", "attribute", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L846-L862
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getForeignKeyAttributesFromParent
protected function getForeignKeyAttributesFromParent(): array { $parentMap = $this->parent->getEntityMap(); $parentForeignRelations = $parentMap->getForeignRelationships(); $parentPivotRelations = $parentMap->getPivotRelationships(); // The parentRelation is the name of the relationship // methods on the parent entity map $parentRelation = $this->parentRelationship; if (in_array($parentRelation, $parentForeignRelations) && !in_array($parentRelation, $parentPivotRelations) ) { $parentObject = $this->parent->getEntityObject(); // Call Relationship's method on parent map $relationship = $parentMap->$parentRelation($parentObject); return $relationship->getForeignKeyValuePair($parentObject); } return []; }
php
protected function getForeignKeyAttributesFromParent(): array { $parentMap = $this->parent->getEntityMap(); $parentForeignRelations = $parentMap->getForeignRelationships(); $parentPivotRelations = $parentMap->getPivotRelationships(); // The parentRelation is the name of the relationship // methods on the parent entity map $parentRelation = $this->parentRelationship; if (in_array($parentRelation, $parentForeignRelations) && !in_array($parentRelation, $parentPivotRelations) ) { $parentObject = $this->parent->getEntityObject(); // Call Relationship's method on parent map $relationship = $parentMap->$parentRelation($parentObject); return $relationship->getForeignKeyValuePair($parentObject); } return []; }
[ "protected", "function", "getForeignKeyAttributesFromParent", "(", ")", ":", "array", "{", "$", "parentMap", "=", "$", "this", "->", "parent", "->", "getEntityMap", "(", ")", ";", "$", "parentForeignRelations", "=", "$", "parentMap", "->", "getForeignRelationships", "(", ")", ";", "$", "parentPivotRelations", "=", "$", "parentMap", "->", "getPivotRelationships", "(", ")", ";", "// The parentRelation is the name of the relationship", "// methods on the parent entity map", "$", "parentRelation", "=", "$", "this", "->", "parentRelationship", ";", "if", "(", "in_array", "(", "$", "parentRelation", ",", "$", "parentForeignRelations", ")", "&&", "!", "in_array", "(", "$", "parentRelation", ",", "$", "parentPivotRelations", ")", ")", "{", "$", "parentObject", "=", "$", "this", "->", "parent", "->", "getEntityObject", "(", ")", ";", "// Call Relationship's method on parent map", "$", "relationship", "=", "$", "parentMap", "->", "$", "parentRelation", "(", "$", "parentObject", ")", ";", "return", "$", "relationship", "->", "getForeignKeyValuePair", "(", "$", "parentObject", ")", ";", "}", "return", "[", "]", ";", "}" ]
Get foreign key attribute(s) from a parent entity in this aggregate context. @return array
[ "Get", "foreign", "key", "attribute", "(", "s", ")", "from", "a", "parent", "entity", "in", "this", "aggregate", "context", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L870-L893
analogueorm/analogue
src/System/Aggregate.php
Aggregate.updatePivotRecords
public function updatePivotRecords() { $pivots = $this->entityMap->getPivotRelationships(); foreach ($pivots as $pivot) { if (array_key_exists($pivot, $this->relationships)) { $this->updatePivotRelation($pivot); } } }
php
public function updatePivotRecords() { $pivots = $this->entityMap->getPivotRelationships(); foreach ($pivots as $pivot) { if (array_key_exists($pivot, $this->relationships)) { $this->updatePivotRelation($pivot); } } }
[ "public", "function", "updatePivotRecords", "(", ")", "{", "$", "pivots", "=", "$", "this", "->", "entityMap", "->", "getPivotRelationships", "(", ")", ";", "foreach", "(", "$", "pivots", "as", "$", "pivot", ")", "{", "if", "(", "array_key_exists", "(", "$", "pivot", ",", "$", "this", "->", "relationships", ")", ")", "{", "$", "this", "->", "updatePivotRelation", "(", "$", "pivot", ")", ";", "}", "}", "}" ]
Update Pivot records on loaded relationships, by comparing the values from the Entity Cache to the actual relationship inside the aggregated entity. @return void
[ "Update", "Pivot", "records", "on", "loaded", "relationships", "by", "comparing", "the", "values", "from", "the", "Entity", "Cache", "to", "the", "actual", "relationship", "inside", "the", "aggregated", "entity", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L902-L911
analogueorm/analogue
src/System/Aggregate.php
Aggregate.updatePivotRelation
protected function updatePivotRelation(string $relation) { $hashes = $this->getEntityHashesFromRelation($relation); $cachedAttributes = $this->getCachedRawAttributes(); if (array_key_exists($relation, $cachedAttributes)) { // Compare the two array of hashes to find out existing // pivot records, and the ones to be created. $new = array_diff($hashes, array_keys($cachedAttributes[$relation])); $existing = array_intersect($hashes, array_keys($cachedAttributes[$relation])); } else { $existing = []; $new = $hashes; } if (count($new) > 0) { $pivots = $this->getRelatedAggregatesFromHashes($new, $relation); $this->entityMap->$relation($this->getEntityObject())->createPivots($pivots); } if (count($existing) > 0) { foreach ($existing as $pivotHash) { $this->updatePivotIfDirty($pivotHash, $relation); } } }
php
protected function updatePivotRelation(string $relation) { $hashes = $this->getEntityHashesFromRelation($relation); $cachedAttributes = $this->getCachedRawAttributes(); if (array_key_exists($relation, $cachedAttributes)) { // Compare the two array of hashes to find out existing // pivot records, and the ones to be created. $new = array_diff($hashes, array_keys($cachedAttributes[$relation])); $existing = array_intersect($hashes, array_keys($cachedAttributes[$relation])); } else { $existing = []; $new = $hashes; } if (count($new) > 0) { $pivots = $this->getRelatedAggregatesFromHashes($new, $relation); $this->entityMap->$relation($this->getEntityObject())->createPivots($pivots); } if (count($existing) > 0) { foreach ($existing as $pivotHash) { $this->updatePivotIfDirty($pivotHash, $relation); } } }
[ "protected", "function", "updatePivotRelation", "(", "string", "$", "relation", ")", "{", "$", "hashes", "=", "$", "this", "->", "getEntityHashesFromRelation", "(", "$", "relation", ")", ";", "$", "cachedAttributes", "=", "$", "this", "->", "getCachedRawAttributes", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "relation", ",", "$", "cachedAttributes", ")", ")", "{", "// Compare the two array of hashes to find out existing", "// pivot records, and the ones to be created.", "$", "new", "=", "array_diff", "(", "$", "hashes", ",", "array_keys", "(", "$", "cachedAttributes", "[", "$", "relation", "]", ")", ")", ";", "$", "existing", "=", "array_intersect", "(", "$", "hashes", ",", "array_keys", "(", "$", "cachedAttributes", "[", "$", "relation", "]", ")", ")", ";", "}", "else", "{", "$", "existing", "=", "[", "]", ";", "$", "new", "=", "$", "hashes", ";", "}", "if", "(", "count", "(", "$", "new", ")", ">", "0", ")", "{", "$", "pivots", "=", "$", "this", "->", "getRelatedAggregatesFromHashes", "(", "$", "new", ",", "$", "relation", ")", ";", "$", "this", "->", "entityMap", "->", "$", "relation", "(", "$", "this", "->", "getEntityObject", "(", ")", ")", "->", "createPivots", "(", "$", "pivots", ")", ";", "}", "if", "(", "count", "(", "$", "existing", ")", ">", "0", ")", "{", "foreach", "(", "$", "existing", "as", "$", "pivotHash", ")", "{", "$", "this", "->", "updatePivotIfDirty", "(", "$", "pivotHash", ",", "$", "relation", ")", ";", "}", "}", "}" ]
Update Single pivot relationship. @param string $relation @return void
[ "Update", "Single", "pivot", "relationship", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L920-L947
analogueorm/analogue
src/System/Aggregate.php
Aggregate.updatePivotIfDirty
protected function updatePivotIfDirty(string $pivotHash, string $relation) { $aggregate = $this->getRelatedAggregateFromHash($pivotHash, $relation); if ($aggregate->hasAttribute('pivot')) { $pivot = $aggregate->getEntityAttribute('pivot')->getEntityAttributes(); $cachedPivotAttributes = $this->getPivotAttributesFromCache($pivotHash, $relation); $actualPivotAttributes = array_only($pivot, array_keys($cachedPivotAttributes)); $dirty = $this->getDirtyAttributes($actualPivotAttributes, $cachedPivotAttributes); if (count($dirty) > 0) { $id = $aggregate->getEntityKeyValue(); $this->entityMap->$relation($this->getEntityObject())->updateExistingPivot($id, $dirty); } } }
php
protected function updatePivotIfDirty(string $pivotHash, string $relation) { $aggregate = $this->getRelatedAggregateFromHash($pivotHash, $relation); if ($aggregate->hasAttribute('pivot')) { $pivot = $aggregate->getEntityAttribute('pivot')->getEntityAttributes(); $cachedPivotAttributes = $this->getPivotAttributesFromCache($pivotHash, $relation); $actualPivotAttributes = array_only($pivot, array_keys($cachedPivotAttributes)); $dirty = $this->getDirtyAttributes($actualPivotAttributes, $cachedPivotAttributes); if (count($dirty) > 0) { $id = $aggregate->getEntityKeyValue(); $this->entityMap->$relation($this->getEntityObject())->updateExistingPivot($id, $dirty); } } }
[ "protected", "function", "updatePivotIfDirty", "(", "string", "$", "pivotHash", ",", "string", "$", "relation", ")", "{", "$", "aggregate", "=", "$", "this", "->", "getRelatedAggregateFromHash", "(", "$", "pivotHash", ",", "$", "relation", ")", ";", "if", "(", "$", "aggregate", "->", "hasAttribute", "(", "'pivot'", ")", ")", "{", "$", "pivot", "=", "$", "aggregate", "->", "getEntityAttribute", "(", "'pivot'", ")", "->", "getEntityAttributes", "(", ")", ";", "$", "cachedPivotAttributes", "=", "$", "this", "->", "getPivotAttributesFromCache", "(", "$", "pivotHash", ",", "$", "relation", ")", ";", "$", "actualPivotAttributes", "=", "array_only", "(", "$", "pivot", ",", "array_keys", "(", "$", "cachedPivotAttributes", ")", ")", ";", "$", "dirty", "=", "$", "this", "->", "getDirtyAttributes", "(", "$", "actualPivotAttributes", ",", "$", "cachedPivotAttributes", ")", ";", "if", "(", "count", "(", "$", "dirty", ")", ">", "0", ")", "{", "$", "id", "=", "$", "aggregate", "->", "getEntityKeyValue", "(", ")", ";", "$", "this", "->", "entityMap", "->", "$", "relation", "(", "$", "this", "->", "getEntityObject", "(", ")", ")", "->", "updateExistingPivot", "(", "$", "id", ",", "$", "dirty", ")", ";", "}", "}", "}" ]
Compare existing pivot record in cache and update it if the pivot attributes are dirty. @param string $pivotHash @param string $relation @return void
[ "Compare", "existing", "pivot", "record", "in", "cache", "and", "update", "it", "if", "the", "pivot", "attributes", "are", "dirty", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L958-L977
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getDirtyAttributes
protected function getDirtyAttributes(array $actual, array $cached): array { $dirty = []; foreach ($actual as $key => $value) { if (!$this->originalIsNumericallyEquivalent($value, $cached[$key])) { $dirty[$key] = $actual[$key]; } } return $dirty; }
php
protected function getDirtyAttributes(array $actual, array $cached): array { $dirty = []; foreach ($actual as $key => $value) { if (!$this->originalIsNumericallyEquivalent($value, $cached[$key])) { $dirty[$key] = $actual[$key]; } } return $dirty; }
[ "protected", "function", "getDirtyAttributes", "(", "array", "$", "actual", ",", "array", "$", "cached", ")", ":", "array", "{", "$", "dirty", "=", "[", "]", ";", "foreach", "(", "$", "actual", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "$", "this", "->", "originalIsNumericallyEquivalent", "(", "$", "value", ",", "$", "cached", "[", "$", "key", "]", ")", ")", "{", "$", "dirty", "[", "$", "key", "]", "=", "$", "actual", "[", "$", "key", "]", ";", "}", "}", "return", "$", "dirty", ";", "}" ]
Compare two attributes array and return dirty attributes. @param array $actual @param array $cached @return array
[ "Compare", "two", "attributes", "array", "and", "return", "dirty", "attributes", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L987-L998
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getPivotAttributesFromCache
protected function getPivotAttributesFromCache(string $pivotHash, string $relation) { $cachedAttributes = $this->getCachedRawAttributes(); $cachedRelations = $cachedAttributes[$relation]; foreach ($cachedRelations as $cachedRelation) { if ($cachedRelation == $pivotHash) { return $cachedRelation->getPivotAttributes(); } } }
php
protected function getPivotAttributesFromCache(string $pivotHash, string $relation) { $cachedAttributes = $this->getCachedRawAttributes(); $cachedRelations = $cachedAttributes[$relation]; foreach ($cachedRelations as $cachedRelation) { if ($cachedRelation == $pivotHash) { return $cachedRelation->getPivotAttributes(); } } }
[ "protected", "function", "getPivotAttributesFromCache", "(", "string", "$", "pivotHash", ",", "string", "$", "relation", ")", "{", "$", "cachedAttributes", "=", "$", "this", "->", "getCachedRawAttributes", "(", ")", ";", "$", "cachedRelations", "=", "$", "cachedAttributes", "[", "$", "relation", "]", ";", "foreach", "(", "$", "cachedRelations", "as", "$", "cachedRelation", ")", "{", "if", "(", "$", "cachedRelation", "==", "$", "pivotHash", ")", "{", "return", "$", "cachedRelation", "->", "getPivotAttributes", "(", ")", ";", "}", "}", "}" ]
@param string $pivotHash @param string $relation @return array|null
[ "@param", "string", "$pivotHash", "@param", "string", "$relation" ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L1006-L1017
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getRelatedAggregatesFromHashes
protected function getRelatedAggregatesFromHashes(array $hashes, string $relation): array { $related = []; foreach ($hashes as $hash) { $aggregate = $this->getRelatedAggregateFromHash($hash, $relation); if ($aggregate) { $related[] = $aggregate; } } return $related; }
php
protected function getRelatedAggregatesFromHashes(array $hashes, string $relation): array { $related = []; foreach ($hashes as $hash) { $aggregate = $this->getRelatedAggregateFromHash($hash, $relation); if ($aggregate) { $related[] = $aggregate; } } return $related; }
[ "protected", "function", "getRelatedAggregatesFromHashes", "(", "array", "$", "hashes", ",", "string", "$", "relation", ")", ":", "array", "{", "$", "related", "=", "[", "]", ";", "foreach", "(", "$", "hashes", "as", "$", "hash", ")", "{", "$", "aggregate", "=", "$", "this", "->", "getRelatedAggregateFromHash", "(", "$", "hash", ",", "$", "relation", ")", ";", "if", "(", "$", "aggregate", ")", "{", "$", "related", "[", "]", "=", "$", "aggregate", ";", "}", "}", "return", "$", "related", ";", "}" ]
Returns an array of related Aggregates from its entity hashes. @param array $hashes @param string $relation @return array
[ "Returns", "an", "array", "of", "related", "Aggregates", "from", "its", "entity", "hashes", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L1027-L1040
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getRelatedAggregateFromHash
protected function getRelatedAggregateFromHash(string $hash, string $relation) { foreach ($this->relationships[$relation] as $aggregate) { if ($aggregate->getEntityHash() == $hash) { return $aggregate; } } }
php
protected function getRelatedAggregateFromHash(string $hash, string $relation) { foreach ($this->relationships[$relation] as $aggregate) { if ($aggregate->getEntityHash() == $hash) { return $aggregate; } } }
[ "protected", "function", "getRelatedAggregateFromHash", "(", "string", "$", "hash", ",", "string", "$", "relation", ")", "{", "foreach", "(", "$", "this", "->", "relationships", "[", "$", "relation", "]", "as", "$", "aggregate", ")", "{", "if", "(", "$", "aggregate", "->", "getEntityHash", "(", ")", "==", "$", "hash", ")", "{", "return", "$", "aggregate", ";", "}", "}", "}" ]
Get related aggregate from its hash. @param string $hash @param string $relation @return \Analogue\ORM\System\Aggregate|null
[ "Get", "related", "aggregate", "from", "its", "hash", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L1050-L1057
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getEntityHashesFromRelation
protected function getEntityHashesFromRelation(string $relation): array { return array_map(function (Aggregate $aggregate) { return $aggregate->getEntityHash(); }, $this->relationships[$relation]); }
php
protected function getEntityHashesFromRelation(string $relation): array { return array_map(function (Aggregate $aggregate) { return $aggregate->getEntityHash(); }, $this->relationships[$relation]); }
[ "protected", "function", "getEntityHashesFromRelation", "(", "string", "$", "relation", ")", ":", "array", "{", "return", "array_map", "(", "function", "(", "Aggregate", "$", "aggregate", ")", "{", "return", "$", "aggregate", "->", "getEntityHash", "(", ")", ";", "}", ",", "$", "this", "->", "relationships", "[", "$", "relation", "]", ")", ";", "}" ]
Return an array of Entity Hashes from a specific relation. @param string $relation @return array
[ "Return", "an", "array", "of", "Entity", "Hashes", "from", "a", "specific", "relation", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L1066-L1071
analogueorm/analogue
src/System/Aggregate.php
Aggregate.isActualRelationships
protected function isActualRelationships(string $relation): bool { return array_key_exists($relation, $this->relationships) && count($this->relationships[$relation]) > 0; }
php
protected function isActualRelationships(string $relation): bool { return array_key_exists($relation, $this->relationships) && count($this->relationships[$relation]) > 0; }
[ "protected", "function", "isActualRelationships", "(", "string", "$", "relation", ")", ":", "bool", "{", "return", "array_key_exists", "(", "$", "relation", ",", "$", "this", "->", "relationships", ")", "&&", "count", "(", "$", "this", "->", "relationships", "[", "$", "relation", "]", ")", ">", "0", ";", "}" ]
Check the existence of an actual relationship. @param string $relation @return bool
[ "Check", "the", "existence", "of", "an", "actual", "relationship", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L1080-L1084
analogueorm/analogue
src/System/Aggregate.php
Aggregate.getDirtyRawAttributes
public function getDirtyRawAttributes(): array { $attributes = $this->getRawAttributes(); $cachedAttributes = $this->getCachedRawAttributes(array_keys($attributes)); $dirty = []; foreach ($attributes as $key => $value) { if ($this->isActualRelation($key) || $key == 'pivot') { continue; } if (!array_key_exists($key, $cachedAttributes) && !$value instanceof Pivot) { $dirty[$key] = $value; } elseif ($value !== $cachedAttributes[$key] && !$this->originalIsNumericallyEquivalent($value, $cachedAttributes[$key])) { $dirty[$key] = $value; } } return $dirty; }
php
public function getDirtyRawAttributes(): array { $attributes = $this->getRawAttributes(); $cachedAttributes = $this->getCachedRawAttributes(array_keys($attributes)); $dirty = []; foreach ($attributes as $key => $value) { if ($this->isActualRelation($key) || $key == 'pivot') { continue; } if (!array_key_exists($key, $cachedAttributes) && !$value instanceof Pivot) { $dirty[$key] = $value; } elseif ($value !== $cachedAttributes[$key] && !$this->originalIsNumericallyEquivalent($value, $cachedAttributes[$key])) { $dirty[$key] = $value; } } return $dirty; }
[ "public", "function", "getDirtyRawAttributes", "(", ")", ":", "array", "{", "$", "attributes", "=", "$", "this", "->", "getRawAttributes", "(", ")", ";", "$", "cachedAttributes", "=", "$", "this", "->", "getCachedRawAttributes", "(", "array_keys", "(", "$", "attributes", ")", ")", ";", "$", "dirty", "=", "[", "]", ";", "foreach", "(", "$", "attributes", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "this", "->", "isActualRelation", "(", "$", "key", ")", "||", "$", "key", "==", "'pivot'", ")", "{", "continue", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "cachedAttributes", ")", "&&", "!", "$", "value", "instanceof", "Pivot", ")", "{", "$", "dirty", "[", "$", "key", "]", "=", "$", "value", ";", "}", "elseif", "(", "$", "value", "!==", "$", "cachedAttributes", "[", "$", "key", "]", "&&", "!", "$", "this", "->", "originalIsNumericallyEquivalent", "(", "$", "value", ",", "$", "cachedAttributes", "[", "$", "key", "]", ")", ")", "{", "$", "dirty", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "return", "$", "dirty", ";", "}" ]
Get Only Raw Entity attributes which have been modified since last query. @return array
[ "Get", "Only", "Raw", "Entity", "attributes", "which", "have", "been", "modified", "since", "last", "query", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L1102-L1124
analogueorm/analogue
src/System/Aggregate.php
Aggregate.isNonLoadedProxy
protected function isNonLoadedProxy(string $key): bool { $relation = $this->getEntityAttribute($key); return $relation instanceof ProxyInterface && !$relation->isProxyInitialized(); }
php
protected function isNonLoadedProxy(string $key): bool { $relation = $this->getEntityAttribute($key); return $relation instanceof ProxyInterface && !$relation->isProxyInitialized(); }
[ "protected", "function", "isNonLoadedProxy", "(", "string", "$", "key", ")", ":", "bool", "{", "$", "relation", "=", "$", "this", "->", "getEntityAttribute", "(", "$", "key", ")", ";", "return", "$", "relation", "instanceof", "ProxyInterface", "&&", "!", "$", "relation", "->", "isProxyInitialized", "(", ")", ";", "}" ]
Return true if attribute is a non-loaded proxy. @param string $key @return bool
[ "Return", "true", "if", "attribute", "is", "a", "non", "-", "loaded", "proxy", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L1143-L1148
analogueorm/analogue
src/System/Aggregate.php
Aggregate.originalIsNumericallyEquivalent
protected function originalIsNumericallyEquivalent($current, $original): bool { return is_numeric($current) && is_numeric($original) && strcmp((string) $current, (string) $original) === 0; }
php
protected function originalIsNumericallyEquivalent($current, $original): bool { return is_numeric($current) && is_numeric($original) && strcmp((string) $current, (string) $original) === 0; }
[ "protected", "function", "originalIsNumericallyEquivalent", "(", "$", "current", ",", "$", "original", ")", ":", "bool", "{", "return", "is_numeric", "(", "$", "current", ")", "&&", "is_numeric", "(", "$", "original", ")", "&&", "strcmp", "(", "(", "string", ")", "$", "current", ",", "(", "string", ")", "$", "original", ")", "===", "0", ";", "}" ]
Determine if the new and old values for a given key are numerically equivalent. @param $current @param $original @return bool
[ "Determine", "if", "the", "new", "and", "old", "values", "for", "a", "given", "key", "are", "numerically", "equivalent", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/System/Aggregate.php#L1158-L1161
analogueorm/analogue
src/EntityMap.php
EntityMap.usesAttributesArray
public function usesAttributesArray(): bool { if ($this->arrayName === null) { return false; } if ($this->attributes === null) { return false; } return true; }
php
public function usesAttributesArray(): bool { if ($this->arrayName === null) { return false; } if ($this->attributes === null) { return false; } return true; }
[ "public", "function", "usesAttributesArray", "(", ")", ":", "bool", "{", "if", "(", "$", "this", "->", "arrayName", "===", "null", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "attributes", "===", "null", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Return true if the Entity has an 'attributes' array property. @return bool
[ "Return", "true", "if", "the", "Entity", "has", "an", "attributes", "array", "property", "." ]
train
https://github.com/analogueorm/analogue/blob/b12cdea1d78d33923b9986f5413ca6e133302c87/src/EntityMap.php#L328-L339