/** * {@inheritdoc} * * Schema can generate accessors and filters based on field type. */ public function getMutators() { $mutators = parent::getMutators(); //Trying to resolve mutators based on field type foreach ($this->tableSchema->getColumns() as $column) { //Resolved filters $resolved = []; if (!empty($filter = $this->builder->getMutators($column->abstractType()))) { //Mutator associated with type directly $resolved += $filter; } elseif (!empty($filter = $this->builder->getMutators('php:' . $column->phpType()))) { //Mutator associated with php type $resolved += $filter; } //Merging mutators and default mutators foreach ($resolved as $mutator => $filter) { if (!array_key_exists($column->getName(), $mutators[$mutator])) { $mutators[$mutator][$column->getName()] = $filter; } } } foreach ($mutators as $mutator => &$filters) { foreach ($filters as $field => $filter) { //Some mutators may be described using aliases (for shortness) $filters[$field] = $this->builder->mutatorAlias($filter); } unset($filters); } return $mutators; }
/** * {@inheritdoc} * * Schema can generate accessors and filters based on field type. */ public function getMutators() { $mutators = parent::getMutators(); //Trying to resolve mutators based on field type foreach ($this->getFields() as $field => $type) { //Resolved filters $resolved = []; if (is_array($type) && is_scalar($type[0]) && ($filter = $this->builder->getMutators('array::' . $type[0]))) { //Mutator associated to array with specified type $resolved += $filter; } elseif (is_array($type) && ($filter = $this->builder->getMutators('array'))) { //Default array mutator $resolved += $filter; } elseif (!is_array($type) && ($filter = $this->builder->getMutators($type))) { //Mutator associated with type directly $resolved += $filter; } if (isset($resolved[self::MUTATOR_ACCESSOR])) { //Accessor options include field type, this is ODM specific behaviour $resolved[self::MUTATOR_ACCESSOR] = [$resolved[self::MUTATOR_ACCESSOR], is_array($type) ? $type[0] : $type]; } //Merging mutators and default mutators foreach ($resolved as $mutator => $filter) { if (!array_key_exists($field, $mutators[$mutator])) { $mutators[$mutator][$field] = $filter; } } } //Some mutators may be described using aliases (for shortness) $mutators = $this->normalizeMutators($mutators); //Every composition is counted as field accessor :) foreach ($this->getCompositions() as $field => $composition) { $mutators[self::MUTATOR_ACCESSOR][$field] = [$composition['type'] == ODM::CMP_MANY ? Compositor::class : ODM::CMP_ONE, $composition['class']]; } return $mutators; }