Dependencies and extensions are handled by a dependency container, using Pimple, which can be defined via service providers (Pimple\ServiceProviderInterface
).
The Charcoal App comes with several providers out of the box. All of these are within the Charcoal\App\ServiceProvider
namespace:
The Charcoal App requires a few providers from independent components. The following use their own namespace and are automatically injected via the AppServiceProvider
:
Most providers expect the container to provide the config
entry, which should hold the application's main configuration.
Dependencies are handled with a Pimple
dependency Container.
Basic "App" services are:
cache
- A cache storage service for the Stash Cache Library.
- Configured by
config['cache']
- Provided by charcoal/cache
config
- A
\Charcoal\App\AppConfig
instance.
- A
database
- The default PDO database.
- From a pool of database, available through
databases
. - Configured by
config['databases']
andconfig['default_database']
.
filesystems
- A (pimple) container of
\League\Flysystem\Filesystem
- Configured by
config['filesystem]
- Also provide a
\League\Flysystem\MountManager
asfilesystem/manager
.
- A (pimple) container of
logger
- A
\Psr\Log\Logger
instance. - Provided by Monolog.
- Configured by
config['logger']
- A
translator
- A
Charcoal\Translator\Translation
object for multilingual strings. - A
Charcoal\Translator\Translator
service based on Symfony's Translator. - A
Charcoal\Translator\LocalesManager
for managing available languages. - Configured by
config['translator']
andconfig['locales']
- Provided by charcoal/translator
- A
view
- A
Charcoal\View\ViewInterface
instance - Typically a
\Charcoal\View\GenericView
object. - Configured by
config['view']
- Provided by charcoal/view
- A
The AppServiceProvider
, or charcoal/app/service-provider/app
provides the following services:
Service | Type | Description |
---|---|---|
notFoundHandler | callback |
For 404 (Not Found) URLs. Slim requirement. |
errorHandler | callback |
For 500 (Error) URLs. Slim requirement. |
action/factory | ActionFactory 1 |
To create actions. |
script/factory | ScriptFactory 2 |
To create templates. |
template/factory | TemplateFactory 3 |
To create templates. |
widget/factory | WidgetFactory 4 |
To create widgets. |
\Charcoal\App\Action\ActionFactory
\Charcoal\App\Script\ScriptFactory
\Charcoal\App\Template\TemplateFatory
\Charcoal\App\Widget\WidgetFactory
All factories are implementations of \Charcoal\Factory\FactoryInterface
External Provider
See the charcoal/cache for more information on using the cache service.
The CacheServiceProvider
, or charcoal/app/service-provider/cache
provides the following servicers:
Service | Type | Description |
---|---|---|
cache | \Stash\Pool |
The default PSR-6 cache pool. |
Also available are the following helpers:
Helper Service | Type | Description |
---|---|---|
cache/config | CacheConfig 1 |
Cache configuration. |
cache/builder | CacheBuilder 2 |
Cache pool builder. |
cache/available-drivers | array 3 |
Available drivers on the system. |
cache/drivers | \Pimple\Contianer |
Map of all the available Stash driver instances. |
cache/driver | DriverInterface 4 |
The Stash driver used by the default pool, cache . |
\Charcoal\Cache\CacheConfig
\Charcoal\Cache\CacheBuilder
\Stash\DriverList
\Stash\Interfaces\DriverInterface
Key | Type | Default | Description |
---|---|---|---|
types | array |
[ 'memory' ] |
The cache types to attempt to use, in order. |
default_ttl | int |
0 |
Default time-to-live, in seconds. |
prefix | string |
charcoal |
The cache prefix, or namespace. |
A full example, in JSON format:
{
"cache": {
"types": [ "memcache", "memory" ],
"default_ttl": 0,
"prefix": "charcoal"
}
}
The DatabaseServiceProvider
, or charcoal/app/service-provider/database
provides the following services:
Service | Type | Description |
---|---|---|
database | \PDO |
The default database PDO object. |
databases | \Pimple\Container |
A map (container) of all the available PDO instances. |
Also available are the following helpers:
Helper Service | Type | Description |
---|---|---|
database/config | DatabaseConfig 1 |
Default database config container. |
databases/config | \Pimple\Container |
A map (container) of all the available PDO instances. |
\Charcoal\App\Config\DatabaseConfig
The databases are configured with the following options:
Key | Type | Default | Description |
---|---|---|---|
databases | array |
||
default_database | string |
The database config is as follow:
Key | Type | Default | Description |
---|---|---|---|
type | string |
mysql |
The database driver type. |
hostname | string |
localhost |
The database hostname or IP address. |
username | string |
'' |
The username with access to this database / tables. |
password | string |
'' |
The password, for username. |
database | string |
'' |
The database name for this project. |
disable_utf8 | bool |
false |
Set to true to disable automatic utf-8. |
Or, in JSON format:
{
"databases": {
"foobar": {
"type": "mysql",
"hostname": "dbserver.example.com",
"username": "dbuser",
"password": "dbpassword",
"disable_utf8": false
}
},
"default_database": "foobar"
}
The FilesystemServiceProvider
, or charcoal/app/service-provider/filesystem
provides the following services:
Service | Type | Description |
---|---|---|
filesystems | \Pimple\Container |
A list of \League\Flysystem\Filesystem |
filesystem/manager | \League\Flysystem\MountManager |
A mount manager. |
Also available are the following helpers:
Helper Service | Type | Description |
---|---|---|
filesystem/config | FilesystemConfig 1 |
Default filesystem config container. |
\Charcoal\App\Config\FilesystemConfig
Key | Type | Default | Description |
---|---|---|---|
connections | array |
... |
|
default_connection | string |
'public' |
There are 2 connections alway available: private
and public
.
By default, the public
connection represents a local filesystem with the the web-visible root path of the project (the www
folder) set as the path.
By default, the private
connection represents a local filesystem with the base path of the project set as the path.
The LoggerServiceProvider
, or charcoal/app/service-provider/logger
provides the following services:
Service | Type | Description |
---|---|---|
logger | \Psr\Log\LoggerInterface |
A PSR-3 compliant logger. |
A \Monolog\Logger
is actually provided by default in the App package.
Also available are the following helpers:
logger/config
- A
\Charcoal\App\Config\LoggerConfig
instance holding the logger configuration.
- A
Key | Type | Default | Description |
---|---|---|---|
active | bool |
true |
|
handlers | array |
||
processors | array |
Possible handlers are stream
and console
.
Possible processors are memory-usage
and uid
.
{
"logger": {
"active": true,
"handlers": {
"stream": {},
"console": {}
},
"processors": {
"memory_usage": {},
"uid": {}
}
}
}
External Provider
See the charcoal/translator for more information on using the translator service.
The TranslatorServiceProvider
, or charcoal/translator/service-provider/translator
provides the following services:
translator
Also available are the following helpers:
locales/config
Key | Type | Default | Description |
---|---|---|---|
locales | array |
||
translator | array |
Or, in JSON format:
"locales": {
"languages": {
"de": {},
"en": {},
"es": {
"active": false
},
"fr": {}
},
"default_language": "fr",
"fallback_languages": [
"en",
"fr"
],
"auto_detect": true
},
"translator": {
"loaders": [
"xliff",
"json",
"php"
],
"paths": [
"translations/",
"vendor/charcoal/app/translations/"
],
"debug": false,
"cache_dir": "cache/translator",
"translations": {
"messages": {
"de": {
"hello": "Hallo {{ name }}",
"goodbye": "Auf Wiedersehen!"
},
"en": {
"hello": "Hello {{ name }}",
"goodbye": "Goodbye!"
},
"es": {
"hello": "Hallo {{ name }}",
"goodbye": "Adios!"
},
"fr": {
"hello": "Bonjour {{ name }}",
"goodbye": "Au revoir!"
}
},
"admin": {
"fr": {
"Save": "Enregistrer"
}
}
}
}
External Provider
See the charcoal/view for more information on using the view service.
The ViewServiceProvider
, or charcoal/view/service-provider/view
provides the following services:
Service | Type | Description |
---|---|---|
view | ViewInterface 1 |
A Charcoal view instance. |
view/renderer | Renderer 2 |
A PSR-7 view / renderer. |
\Charcoal\View\ViewInterface
, typically a\Charcoal\View\GenericView
\Charcoal\View\Renderer
Also available are the following helpers:
view/config
- The main View configuration
\Charcoal\View\ViewConfig
- The main View configuration
view/engine
- The default View engine (
\Charcoal\View\EngineInterface
)
- The default View engine (
Unlike the other services, the view config is not defined inside this module but in the charcoal/view module.
Key | Type | Default | Description |
---|---|---|---|
paths | array |
[] |
The list of paths where to serach for templates. |
engines | array |
[] |
|
default_engine | string |
mustache |
Or, in JSON format:
{
"view": {
"paths": [
"templates/",
"vendor/charcoal/admin/templates/"
],
"engines": {
"mustache": {}
},
"default_engine": "mustache"
}
}