-
Notifications
You must be signed in to change notification settings - Fork 90
[Suggestions] Enable zfcampus/zf-development-mode like in ZendSkeletonApp #104
Comments
I like the idea. If this would be implemented, the The reason I would be against this is that (as far as I can tell) the zf-development-mode command doesn't remove the possible cached configuration... yet. Also if this requires renaming I'm not sure how and if this would affect module support (#54). |
@xtreamwayz no changes for the directory structure for now, if this will be added. The changes will be on the files mentioned above. So, it still complies the current skeleton app. With regards to the modular approach, can be discussed in a different thread, it still uses the "mtymek/expressive-config-manager" package but I would suggest to create a separate repository for the core (common) expressive configuration (as Zend\Expressive\ConfigProvider) and add a specific framework-based configuration such as Zend components. Sample config/modules.config.php use Zend\Expressive\ConfigManager\ConfigManager;
/**
* Use Fully Qualified Namespace to enable the expressive configuration
*/
$modules = [
Zend\Expressive\ConfigProvider::class, // Minimal Components
Zend\Component\ConfigProvider::class, // Zend Components
App\ConfigProvider::class, //Application Settings or can be Album tutorial https://github.com/zendframework/zend-expressive/issues/176
];
return (new ConfigManager($modules))->getMergedConfig(); With this approach, we are eliminating the mis-configuration of the expressive skeleton and set this as a library (composer type) composer.json file (assuming we loaded the zend-component-installer in the skeleton composer.json) "require": {
"php": "^7.0",
"roave/security-advisories": "dev-master",
"zendframework/zend-expressive": "^1.0",
"zendframework/zend-expressive-helpers": "^2.0"
},
"autoload": {
"psr-4": {
"Zend\\Expressive\\": "src/"
}
},
"extra": {
"zf": {
"config-provider": "Zend\\Expressive\\ConfigProvider"
}
},
"autoload-dev": {
"psr-4": {
"ZendTest\\Expressive\\": "test/"
}
} The only file in the repo. (src/ConfigProvider.php) namespace Zend\Expressive;
final class ConfigProvider
{
public function __invoke()
{
return [
"dependencies" => $this->getServiceConfig(),
"middleware_pipeline" => $this->getMiddlewareConfig()
];
}
/**
* Return dependencies mapping for this module.
* We recommend using fully-qualified class names whenever possible as service names.
*
* @return array
*/
public function getServiceConfig()
{
return [
// Use 'invokables' for constructor-less services,
// or services that do not require arguments to the constructor.
//
// Map a service name to the class name.
// Fully\Qualified\InterfaceName::class => Fully\Qualified\ClassName::class,
'invokables' => [
Helper\ServerUrlHelper::class => Helper\ServerUrlHelper::class,
],
// Use 'factories' for services provided by callbacks/factory classes.
'factories' => [
// Application
Application::class => Container\ApplicationFactory::class,
Helper\UrlHelper::class => Helper\UrlHelperFactory::class,
// Middlewares
Helper\ServerUrlMiddleware::class => Helper\ServerUrlMiddlewareFactory::class,
Helper\UrlHelperMiddleware::class => Helper\UrlHelperMiddlewareFactory::class,
]
];
}
/**
* An array of middleware to register. Each item is of the following specification:
*
* <code>
* [
* Required:
* 'middleware' => 'Name or array of names of middleware services and/or callables',
* Optional:
* 'path' => '/path/to/match', // string; literal path prefix to match
* // middleware will not execute if path does not match!
* 'error' => true, // boolean; true for error middleware
* 'priority' => 1, // int; higher values == register early;
* // lower/negative == register last;
* // default is 1, if none is provided.
* ]
* </code>
*
* While the ApplicationFactory ignores the keys associated with specifications, they can be used to allow merging
* related values defined in multiple configuration files/locations.
*
* This defines some conventional keys for middleware to execute early, routing middleware, and error middleware.
*
* @return array
*/
public function getMiddlewareConfig()
{
return [
/**
* Add more middleware here that you want to execute on every request:
* - bootstrapping
* - pre-conditions
* - modifications to outgoing responses
*/
'always' => [
'middleware' => [
Helper\ServerUrlMiddleware::class,
],
'priority' => 10000,
],
/**
* Add more middleware here that needs to introspect the routing results; this might include:
* - route-based authentication
* - route-based validation
* - etc.
*/
'routing' => [
'middleware' => [
Container\ApplicationFactory::ROUTING_MIDDLEWARE,
Helper\UrlHelperMiddleware::class,
// Append here
Container\ApplicationFactory::DISPATCH_MIDDLEWARE,
],
'priority' => 1,
],
'error' => [
'middleware' => [
//Add more error handler middleware
],
'error' => true,
'priority' => -10000,
]
];
}
} See the initial implementation (without test) https://github.com/CodingMatters/zend-expressive-config-provider |
@gabbydgab Thanx for the suggestion. This feature is included in #54. |
Looking into zf-development-mode configuration it only needs a distribution file with an array and is initially executed during composer create-project command along with this is to enable Whoops Error Handling.
For reference, kindly check my ZfExpressiveModularApp implementation
Here is the proposed development.config.php.dist file content:
The following configuration is allowing the default
It needs to update also the config.php file with the following:
Lastly, for the composer.json file:
Any thoughts?
The text was updated successfully, but these errors were encountered: