Home >Backend Development >PHP Tutorial >Rapid Enterprise App Development with Zend Expressive
This tutorial demonstrates rapid enterprise application development using Zend Expressive, a lightweight and flexible micro-framework. We'll bypass the traditionally lengthy quick-start process by leveraging Composer's create-project command and focusing on a streamlined, robust setup. This guide assumes a pre-configured development environment (e.g., Homestead Improved).
Key Advantages:
composer create-project
command streamlines project setup, pre-configuring dependency injection, routing, and templating.Project Setup:
Navigate to your project directory and execute:
<code class="language-bash">composer create-project zendframework/zend-expressive-skeleton expressive</code>
Choose the following options during the installation wizard:
ZendValidatorConfigProvider
injection: config/config.phpInitialize Git and set up the project:
<code class="language-bash">cd expressive && git init && git config color.ui true && git add . && git commit -m "Initial commit" && chmod -R +w data</code>
Start the development server:
<code class="language-bash">composer serve</code>
Access your application at http://localhost:8080
or your VM's IP/virtual host.
Understanding the Structure:
Expressive's directory structure is intuitive:
<code>bin/ config/ data/ cache/ public/ index.php src/ App test/ AppTest vendor/</code>
The src/App
directory houses your application code. Expressive provides helpful commands via ./vendor/bin/expressive
, composer serve
, composer cs-check
, composer cs-fix
, composer test
, and composer check
. The Whoops error handler facilitates debugging.
Essential Enhancements:
1. Reflection-Based Abstract Factory:
To simplify dependency injection, add the following to config/autoload/dependencies.global.php
within the dependencies
array:
<code class="language-bash">composer create-project zendframework/zend-expressive-skeleton expressive</code>
This eliminates the need for manual factory creation for most classes.
2. Doctrine ORM Integration:
Install Doctrine and Symfony YAML:
<code class="language-bash">cd expressive && git init && git config color.ui true && git add . && git commit -m "Initial commit" && chmod -R +w data</code>
Create config/cli-config.php
:
<code class="language-bash">composer serve</code>
Replace the contents of config/autoload/dependencies.global.php
with the updated configuration (provided in the original response). Create config/autoload/doctrine.global.php
and config/autoload/doctrine.local.php
with the database configuration (also provided in the original response). Test Doctrine by running ./vendor/bin/doctrine
.
3. Gulp for Frontend Workflow:
Create package.json
(content provided in the original response) and run npm install
. Create gulpfile.js
(content provided in the original response). Run gulp
to compile Sass, minify CSS and JS, and optimize images. Use gulp watch
for automatic processing of changes.
4. Symfony Console for Commands:
Create bin/console
(content provided in the original response) and config/autoload/console.global.php
(content provided in the original response). Create a sample command (e.g., AppCommandHelloWorldCommand
) and register it in config/autoload/console.global.php
. Run commands using php bin/console
. Add logging capabilities using Monolog (as shown in the original response).
Conclusion:
This enhanced setup provides a solid foundation for building robust, enterprise-grade applications with Zend Expressive. The FAQs section in the original response provides additional details and explanations.
The above is the detailed content of Rapid Enterprise App Development with Zend Expressive. For more information, please follow other related articles on the PHP Chinese website!