AtroCore is an API-first framework built on the principle of Convention over Configuration (CoC). This approach speeds up development by using sensible defaults (for entities, providers, services, controllers,...) instead of requiring extensive configuration. The framework's modular architecture simplifies adding or modifying features. It supports both event-driven architecture and dependency injection** for extending and customizing behavior.
The core of the framework is the \Atro\Core\Application
class response to run the app. When a request is received,
AtroCore automatically detects its type and either serves the client-side view of a single-page application (SPA) or
processes it as an API request.
Service Container
The service container, implemented in the \Atro\Core\Application
class, acts as a central registry for core
services. It also supports custom services defined within modules.
Key Features
- Centralized Access: All core and custom services are registered in the container and accessed using the
get()
method by providing an alias or a class name. - Automatic Dependency Injection: The container automatically resolves and injects service dependencies.
- Extensibility: Create custom services in a module and access them through the
get()
method.
Example Usage
class MyCustomClass {
public function __construction(protected readonly Container $container){
}
}
// somewhere in your code
$myService = $container->get(MyCustomClass::class);
Common Services
The following services are frequently used to build features in AtroCore.
Service | Description |
---|---|
entityManager |
Use to manage entities, learn more... |
Metadata |
Used to get app data, learn more... |
dataManager |
Used to cache data in a file (data/cache ) to reduce database queries. |
memoryStorage |
Caches data in memory during a request. Data is lost after the request ends. |
config |
Access system configuration, learn more... |
language |
Used to localize text, learn more... |
acl |
Checks access control for actions on any system entity. |
serviceFactory |
Creates an entity service for any existing entity. |
connection |
Get access to the doctrine connection, it can be used to make any query in the database |
For a full list of available services, see
Container.php
.
dataManager
/** @var \Atro\Core\DataManager $dataManager**/
$dataManager = $container->get('dataManager');
$dataManager->setCacheData('my_data', ['message' => 'Hello World']);
$myData = $dataManager->getCacheData('my_data');
memoryStorage
/** @var \Atro\Core\KeyValueStorages\MemoryStorage $memoryStorage **/
$memoryStorage = $container->get('memoryStorage');
$memoryStorage->set('my_key', 'my_value');
$myData = $memoryStorage->get('my_key');
config
/** @var \Atro\Core\Utils\Config $config */
$config = $container->get('config');
$database = $config->get('database');
Most configurations available are describe here.
acl
/** @var \Espo\Core\Acl $acl */
$acl = $container->get('acl');
$canReadUser = $acl->check('User', 'read');
$canCreateUser = $acl->check('User', 'create');
$canEditUser = $acl->check('User', 'edit');
$canDeleteUser = $acl->check('User', 'delete');
serviceFactory
To run a method on an entity service, the user must be authenticated with the container providing the service factory.
/** @var \Espo\Core\ServiceFactory $serviceFactory **/
$serviceFactory = $container->get('serviceFactory');
$userService = $serviceFactory->create('User');
$user = $userService->readEntity($id);
connection
To run a method on an Entity service, the user must be authenticated with the container providing the service factory.
/** @var \Doctrine\DBAL\Connection $connection **/
$connection = $container->get('connection');
$usersData = $connection->createQueryBuilder()
->from($connection->quoteIdentifier('user'))
->select('id, name')
->where('deleted = :false')
->setParameter('false', false, \Doctrine\DBAL\ParameterType::BOOLEAN)
->fetchAllAssociative();
For more information on how to make query with $connection, refer to the Doctrine QueryBuilder documentation.