Bake\Shell\Task\ModelTask::getBehaviors PHP Метод

getBehaviors() публичный Метод

Get behaviors
public getBehaviors ( Table $model ) : array
$model Cake\ORM\Table The model to generate behaviors for.
Результат array Behaviors
    public function getBehaviors($model)
    {
        $behaviors = [];
        $schema = $model->schema();
        $fields = $schema->columns();
        if (empty($fields)) {
            return [];
        }
        if (in_array('created', $fields) || in_array('modified', $fields)) {
            $behaviors['Timestamp'] = [];
        }
        if (in_array('lft', $fields) && $schema->columnType('lft') === 'integer' && in_array('rght', $fields) && $schema->columnType('rght') === 'integer' && in_array('parent_id', $fields)) {
            $behaviors['Tree'] = [];
        }
        $counterCache = $this->getCounterCache($model);
        if (!empty($counterCache)) {
            $behaviors['CounterCache'] = $counterCache;
        }
        return $behaviors;
    }

Usage Example

Пример #1
0
 /**
  * test non interactive doActsAs
  *
  * @return void
  */
 public function testGetBehaviors()
 {
     $model = TableRegistry::get('NumberTrees');
     $result = $this->Task->getBehaviors($model);
     $this->assertEquals(['Tree' => []], $result);
     $model = TableRegistry::get('BakeArticles');
     $result = $this->Task->getBehaviors($model);
     $this->assertEquals(['Timestamp' => []], $result);
     TableRegistry::clear();
     TableRegistry::get('Users', ['table' => 'counter_cache_users']);
     $model = TableRegistry::get('Posts', ['table' => 'counter_cache_posts']);
     $result = $this->Task->getBehaviors($model);
     $expected = ['CounterCache' => ["'Users' => ['post_count']"]];
     $this->assertEquals($expected, $result);
 }