| 1 | <?php |
||
| 9 | abstract class AbstractResourceType extends BaseAbstractResourceType |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $name; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var ObjectManager |
||
| 18 | */ |
||
| 19 | protected $manager; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var ObjectRepository |
||
| 23 | */ |
||
| 24 | protected $repository; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param ObjectManager|null $manager |
||
| 28 | */ |
||
| 29 | public function setObjectManager(ObjectManager $manager = null) |
||
| 30 | { |
||
| 31 | $this->manager = $manager; |
||
| 32 | $this->repository = $manager->getRepository($this->dataClass); |
||
|
|
|||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * {@inheritdoc} |
||
| 37 | */ |
||
| 38 | public function __construct($dataClass, array $validationGroups = array(), $name = null) |
||
| 39 | { |
||
| 40 | parent::__construct($dataClass, $validationGroups); |
||
| 41 | |||
| 42 | $this->name = $name; |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * {@inheritdoc} |
||
| 47 | */ |
||
| 48 | public function getName() |
||
| 52 | } |
||
| 53 |
If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe: