function test_getChildren_use_collection_children() { $coll = Collection::foo(Collection::bar(), Collection::baz()); list($foo_child, $bar_child) = $coll->getChildren(); $items = iterator_to_array(CollectionIterator::recursive($coll)); $this->assertContains($foo_child, $items); $this->assertContains($bar_child, $items); }
/** * @param Collection $collection * * @return array */ protected function parseConditions(Collection $collection) { $allCollections = CollectionIterator::recursive($collection); $allCollections = iterator_to_array($allCollections); $allCollections = array_slice($allCollections, 1); $condition = $this->getConditionArray($collection); foreach ($allCollections as $coll) { $condition += $this->getConditionArray($coll, true); } return $condition; }
protected function fetchMulti(Collection $collection, PDOStatement $statement) { $entityInstance = null; $entities = array(); $row = $statement->fetch(PDO::FETCH_NUM); if (!$row) { return false; } $entities = new SplObjectStorage(); $entitiesInstances = array(); foreach (CollectionIterator::recursive($collection) as $c) { $tableName = $c->getName(); $primaryName = $this->getStyle()->primaryFromTable($tableName); $entityName = $this->getStyle()->tableToEntity($tableName); $entityClass = $this->entityNamespace . $entityName; $entityClass = class_exists($entityClass) ? $entityClass : 'stdClass'; $entityInstance = new $entityClass(); $entities[$entityInstance] = array('name' => $tableName, 'table_name' => $tableName, 'entity_class' => $entityClass, 'primary_name' => $primaryName, 'cols' => array()); $entitiesInstances[] = $entityInstance; } $entityInstance = array_pop($entitiesInstances); //Reversely traverses the columns to avoid conflicting foreign key names foreach (array_reverse($row, true) as $col => $value) { $entityData = $entities[$entityInstance]; $columnMeta = $statement->getColumnMeta($col); $columnName = $columnMeta['name']; $primaryName = $entityData['primary_name']; $entityInstance->{$columnName} = $value; if ($primaryName == $columnName) { $entityInstance = array_pop($entitiesInstances); } } $entitiesClone = clone $entities; foreach ($entities as $instance) { foreach ($instance as $field => &$v) { if ($this->getStyle()->isForeignColumn($field)) { foreach ($entitiesClone as $sub) { $tableName = $entities[$sub]['table_name']; $primaryName = $entities[$sub]['primary_name']; if ($entities[$sub]['name'] === $this->getStyle()->tableFromForeignColumn($field) && $sub->{$primaryName} === $v) { $v = $sub; } } } } } return $entities; }
protected function buildEntitiesInstances(Collection $collection, SplObjectStorage $entities) { $entitiesInstances = []; foreach (CollectionIterator::recursive($collection) as $c) { if ($this->filterable($c) && !$this->getFilters($c)) { continue; } $entityInstance = $this->getNewEntityByName($c->getName()); if ($this->mixable($c)) { $mixins = $this->getMixins($c); foreach ($mixins as $mix) { $entitiesInstances[] = $entityInstance; } } $entities[$entityInstance] = $c; $entitiesInstances[] = $entityInstance; } return $entitiesInstances; }