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

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

Bake an entity class.
public bakeEntity ( Table $model, array $data = [] ) : string | null
$model Cake\ORM\Table Model name or object
$data array An array to use to generate the Table
Результат string | null
    public function bakeEntity($model, array $data = [])
    {
        if (!empty($this->params['no-entity'])) {
            return null;
        }
        $name = $this->_entityName($model->alias());
        $namespace = Configure::read('App.namespace');
        $pluginPath = '';
        if ($this->plugin) {
            $namespace = $this->_pluginNamespace($this->plugin);
            $pluginPath = $this->plugin . '.';
        }
        $data += ['name' => $name, 'namespace' => $namespace, 'plugin' => $this->plugin, 'pluginPath' => $pluginPath, 'primaryKey' => []];
        $this->BakeTemplate->set($data);
        $out = $this->BakeTemplate->generate('Model/entity');
        $path = $this->getPath();
        $filename = $path . 'Entity' . DS . $name . '.php';
        $this->out("\n" . sprintf('Baking entity class for %s...', $name), 1, Shell::QUIET);
        $this->createFile($filename, $out);
        $emptyFile = $path . 'Entity' . DS . 'empty';
        $this->_deleteEmptyFile($emptyFile);
        return $out;
    }

Usage Example

Пример #1
0
 /**
  * test bake() with a -plugin param
  *
  * @return void
  */
 public function testBakeEntityWithPlugin()
 {
     $this->Task->plugin = 'ModelTest';
     // fake plugin path
     Plugin::load('ModelTest', ['path' => APP . 'Plugin' . DS . 'ModelTest' . DS]);
     $path = APP . 'Plugin' . DS . 'ModelTest' . DS . 'src' . DS . 'Model' . DS . 'Entity' . DS . 'BakeArticle.php';
     $path = $this->_normalizePath($path);
     $this->Task->expects($this->once())->method('createFile')->with($path);
     $model = TableRegistry::get('BakeArticles');
     $result = $this->Task->bakeEntity($model);
     $this->assertSameAsFile(__FUNCTION__ . '.php', $result);
 }