Objects and class fallback
You can use a custom class for any types, by specifying the wanted class name.
<?php
$config = [
'acme' => [ // Package
Core_Page::TYPE => [ // Type
'contact' => [ // Identifier
'class' => Acme_Page_Contact::class,
],
],
Core_Block::TYPE => [ // Type
'banner' => [ // Identifier
'class' => Acme_Block_Banner::class,
],
],
Core_Model::TYPE => [ // Type
'customer' => [ // Identifier
'class' => Acme_Model_Customer::class,
],
],
],
];
To create an instance of an object, you need to use the App::getSingleton
or App::getObject
methods:
App::getSingleton({identifier}, {type}, {package})
(Create a single instance)
App::getObject({identifier}, {type}, {package})
(Create a new instance)
<?php
/** @var Acme_Model_Customer $model */
$model = App::getSingleton('customer', Core_Model::TYPE);
// packages/acme/app/Acme/Model/Customer.php
/** @var Admin_Model_Customer $model */
$model = App::getSingleton('customer', Core_Model::TYPE, 'admin');
// packages/admin/app/Admin/Model/Customer.php
Class fallback priorities:
If the class is missing, the system will automatically attempt to load a class based on the following priorities:
- {package}_{type}_{identifier}
- Core_{type}_{identifier}
- {package}_{type}
- Core_{type}
- DataObject
Examples:
For a block type, with banner identifier, in the acme package:
- Acme_Block_Banner
- Core_Block_Banner
- Acme_Block
- Core_Block
- DataObject
For a model type, with customer identifier, in the acme package:
- Acme_Model_Customer
- Core_Model_Customer
- Acme_Customer
- Core_Customer
- DataObject