Ejemplo n.º 1
0
 /**
  * Builds the type map
  *
  * @param \Cake\Database\TypeMap $typeMap Contains the types to use for converting results
  * @param \Cake\Database\Driver $driver The driver to use for the type conversion
  */
 public function __construct(TypeMap $typeMap, Driver $driver)
 {
     $this->_driver = $driver;
     $map = $typeMap->toArray();
     $types = Type::buildAll();
     $result = [];
     foreach ($types as $k => $type) {
         if ($type instanceof OptionalConvertInterface && !$type->requiresToPhpCast()) {
             unset($types[$k]);
         }
     }
     foreach ($map as $field => $type) {
         if (isset($types[$type])) {
             $result[$field] = $types[$type];
         }
     }
     $this->_typeMap = $result;
 }
Ejemplo n.º 2
0
 /**
  * Used to recursively add contained association column types to
  * the query.
  *
  * @param \Cake\ORM\Table $table The table instance to pluck associations from.
  * @param \Cake\Database\TypeMap $typeMap The typemap to check for columns in.
  *   This typemap is indirectly mutated via Cake\ORM\Query::addDefaultTypes()
  * @param array $associations The nested tree of associations to walk.
  * @return void
  */
 protected function _addAssociationsToTypeMap($table, $typeMap, $associations)
 {
     foreach ($associations as $name => $nested) {
         $association = $table->association($name);
         if (!$association) {
             continue;
         }
         $target = $association->target();
         $primary = (array) $target->primaryKey();
         if (empty($primary) || $typeMap->type($target->aliasField($primary[0])) === null) {
             $this->addDefaultTypes($target);
         }
         if (!empty($nested)) {
             $this->_addAssociationsToTypeMap($target, $typeMap, $nested);
         }
     }
 }