Completed
Branch master (bff1a4)
by Filipe
02:53
created

CreatedCrudController::configureController()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
/**
4
 * This file is part of slick/mvc package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Mvc\Console\Command\Task;
11
12
use Slick\Mvc\Console\MetaDataGenerator\Controller;
13
use Slick\Mvc\Console\MetaDataGenerator\Entity;
14
use Slick\Mvc\Exception\Console\EntityClassNotFound;
15
16
/**
17
 * CreatedCrudController
18
 *
19
 * @package Slick\Mvc\Console\Command\Task
20
 * @author  Filipe Silva <[email protected]>
21
 *
22
 * @property string $entityName
23
 */
24
class CreatedCrudController extends CreateController
25
{
26
27
    /**
28
     * @readwrite
29
     * @var string
30
     */
31
    protected $entityName;
32
33
    /**
34
     * @var string
35
     */
36
    protected $template = 'crud-controller.twig';
37
38
    /**
39
     * Configures the controller generator
40
     *
41
     * @param Controller $controller
42
     */
43
    protected function configureController(Controller $controller)
44
    {
45
        parent::configureController($controller);
46
        $entity = new Entity($this->entityName);
47
        $controller->add($entity);
48
    }
49
50
    /**
51
     * Sets the entity class name
52
     *
53
     * @param string $entityName
54
     */
55 2
    public function setEntityName($entityName)
56
    {
57 2
        if (!class_exists($entityName)) {
58
            throw new EntityClassNotFound(
59
                "The entity class '{$entityName}' does not exist in your system."
60
            );
61
        }
62 2
        $this->entityName = $entityName;
63
    }
64
}