Zend Framework
Zend Framework is an open source, object-oriented web application framework implemented in PHP 7 and licensed under the New BSD License. The framework is basically a collection of professional PHP-based packages. The framework uses various packages by the use of Composer as part of its package dependency managers; some of them are PHPUnit for testing all packages, Travis CI for continuous Integration Services. Zend Framework provides to users a support of the Model View Controller in combination with Front Controller solution. MVC implementation in Zend Framework has five main areas. The router and dispatcher functions to decide which controller to run based on data from URL, and controller functions in combination with the model and view to develop and create the final web page.
On it was announced that the framework is transitioning into an open source project hosted by the Linux Foundation to be known as Laminas.
License
Zend Framework is licensed under the Open Source Initiative -approved New BSD License. For ZFv1 all code contributors must sign a Contributor License Agreement based on the Apache Software Foundation’s CLA. The licensing and contribution policies were established to prevent intellectual property issues for commercial ZF users, according to Zend's Andi Gutmans. ZF2 and later is CLA free. There is also a longterm support available for the framework for a total duration of 3 years.Zend Framework components and versioning
Starting with Zend Framework version 2.5, components are split into independently versioned packages and zendframework/zendframework is converted into a Composer meta-package. Framework components introduced after the split are not added to the meta-package.While zendframework/zendframework meta-package release version remains at 3.0.0, it will instruct Composer to install latest compatible versions of the framework components, as per the semantic versioning. Such that zend-mvc component will be installed at its current version 3.1.1, zend-servicemanager at version 3.3.0 and zend-form at version 2.10.2.
Zend Framework includes following components:
Authentication | Authenticate users via a variety of adapters, and provide the authenticated identity to your application. |
Barcode | Programmatically create and render barcodes as images or in PDFs. |
Cache | Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output. |
Captcha | Generate and validate CAPTCHAs using Figlets, images, ReCaptcha, and more. |
Code | Extensions to the PHP Reflection API, static code scanning, and code generation. |
Component Installer | Composer plugin for injecting modules and configuration providers into application configuration. |
Config | Read and write configuration files. |
Config Aggregator | Aggregate and merge configuration from a variety of sources. |
Console | Build console applications using getopt syntax or routing, complete with prompts |
Crypt | Strong cryptography tools and password hashing. |
DB | Database abstraction layer, SQL abstraction, result set abstraction, and RowDataGateway and TableDataGateway implementations. |
Debug | Safely dump debug information to HTML. |
DI | Automated dependency injection and instance manager. |
Diactoros | PSR-7 HTTP message implementations. |
DOM | Query HTML and XML documents using XPath or CSS selectors. |
Escaper | Securely and safely escape HTML, HTML attributes, JavaScript, CSS, and URLs. |
EventManager | Implement events, signal slots, aspects, and observers! |
Expressive | PSR-7 middleware in minutes. |
Feed | Consume and generate Atom and RSS feeds, and interact with Pubsubhubbub. |
File | Locate PHP classfiles. |
Filter | Programmatically filter and normalize data and files. |
Form | Validate and display simple and complex forms, casting forms to business objects and vice versa. |
HAL for PSR-7 | Hypertext Application Language for PSR-7. |
HTTP | HTTP message and header abstractions, and HTTP client implementation. |
Hydrator | Serialize objects to arrays, and vice versa. |
InputFilter | Normalize and validate input sets from the web, APIs, the CLI, and more, including files. |
Internationalization | Provide translations for your application, and filter and validate internationalized values. |
JSON | De/Serialize JSON in PHP, including JavaScript expressions. |
JSON-RPC Server | JSON-RPC implementation for PHP. |
LDAP | Perform LDAP operations, including binding, searching and modifying entries in an LDAP directory. |
Loader | Autoloading and plugin loading strategies. |
Log | Robust, composite logger with filtering, formatting, and PSR-3 support. |
Parse, create, store, and send email messages, using a variety of storage and transport protocols. | |
Math | Create cryptographically secure pseudo-random numbers, and manage big integers. |
Memory | Manage data in an environment with limited memory. |
MIME | Create and parse MIME messages and parts. |
Module Manager | Modular application system for zend-mvc applications. |
MVC | Zend Framework's event-driven MVC layer, including MVC Applications, Controllers, and Plugins. |
MVC-Console integration | Integration between zend-mvc and zend-console. |
MVC-i18n integration | Integration between zend-mvc and zend-i18n. |
fileprg plugin | Post/Redirect/Get plugin with file upload handling for zend-mvc controllers. |
flashmessenger plugin | Plugin for creating and exposing flash messages via zend-mvc controllers. |
identity plugin | Plugin for retrieving the current authenticated identity within zend-mvc controllers. |
prg plugin | Post/Redirect/Get plugin for zend-mvc controllers. |
Navigation | Manage trees of pointers to web pages in order to build navigation systems. |
Paginator | Paginate collections of data from arbitrary sources. |
ACL | Create, manage, and query access control lists. |
RBAC | Provide and query Role-Based Access Controls for your application. |
Problem Details | PSR-7 Problem Details for HTTP API responses and middleware. |
ProgressBar | Create and update progress bars in different environments. |
PSR-7 Bridge | PSR-7 <-> zend-http message conversions. |
Router | Flexible routing system for HTTP and console applications. |
Serializer | Serialize and deserialize PHP structures to a variety of representations. |
Server | Create Reflection-based RPC servers. |
ServiceManager | Factory-Driven Dependency Injection Container |
ServiceManager-Di integration | zend-di integration for zend-servicemanager |
Session | Object-oriented interface to PHP sessions and storage. |
SOAP | Create, serve, and access SOAP applications, and parse and generate WSDL. |
Stdlib | SPL extensions, array utilities, error handlers, and more. |
Stratigility | PSR-7 middleware foundation for building and dispatching middleware pipelines. |
Tag | Manipulate and weight taggable items, and create tag clouds. |
Test | Tools to facilitate unit testing of zend-mvc applications. |
Text | Create FIGlets and text-based tables. |
URI | Object oriented interface to URIs, with facilities for validation. |
Validator | Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria. |
View | Flexible view layer supporting and providing multiple view layers, helpers, and more. |
XML-RPC | Fully featured XML-RPC server and client implementations. |
XML2JSON | Convert XML documents to JSON. |
Installation
Officially supported install method is via Composer package manager.Zend Framework provides meta-package that includes 61 component but recommended way is to install required framework components individually. Composer will resolve and install all additional dependencies.
For instance, if you need MVC package, you can install with the following command:
$ composer require zendframework/zend-mvc
Anatomy of Zend Framework
Zend Framework follows configuration-over-convention approach and does not impose any particular application structure. Skeleton applications for zend-mvc and zend-expressive are available and provide everything necessary to run applications and to serve as a good starting point.Recommended MVC application directory structure
ZendSkeletonApplication, skeleton application using Zend Framework MVC layer and module systems, can be installed with:$ composer create-project zendframework/skeleton-application
├── config/
│ ├── autoload/
│ │ ├── global.php
│ │ └── local.php.dist
│ ├── application.config.php
│ └── modules.config.php
├── data/
│ └── cache/
├── module/
├── public/
│ └── index.php
├── vendor/
├── composer.json
├── composer.lock
└── phpunit.xml.dist
The config/ directory has application wide configurations. module/ directory contains local modules that are committed along with application. vendor/ contains vendor code and other modules managed independently from the application, content of the folder is normally managed by Composer.
Zend Framework module have only one requirement: Module class exists in a module namespace and is autoloadable. Module class provides configuration and initialization logic to application. Recommended module structure is as follows:
├── config/
│ └── module.config.php
├── src/
│ └── Module.php
├── test/
├── view/
├── composer.json
└── phpunit.xml.dist
Creating project structure
Zend framework supports command line input to create structure of directories. We will use command line interface to start creating the directory structure for our project. This will give you complete structural understanding of directories. The interface supports and provides Zend_Tool interface giving a whole host of command functionalities.- Open the command line interface, and change the hellozend directory.
- Windows users type: bin\zf\bat create project
- Linux/Mac users type: bin\zf.sh create project
Listen 8080
DocumentRoot /User/keithpope/Sites/hellozend/public
- Application-path: defines the path to application directory
- Application_Env: changes the application behavior depending on various factors such as how the application is used.
- getenv: checks system environment.
- Initialize Zend-Application application: includes Zend-Application and create an instance of it.
- Call bootstrap method coupled with run method starting MVC.
- Project directory structure
- Controllers
- Actions
- Views
- Bootstrap file
Controllers
Actions
Actions are important functionalities. Controllers do not function without Actions. For this purpose we create another method which has action appended in its name and automatically the front controller will recognize it as an action. The Action has init method which shows its private nature and not accessible by anyone. Following commands are run so that Zend_Tool can create action for us. Through the use of standard dispatcher all functions are named after the action's name and followed by word "Action" appended. This leads to controller action class containing methods like indexAction, viewAction, editAction, and deleteAction.Windows users:
bin\zf.bat create actions about index
Linux and Mac users:
bin/zf.sh create action about index
An example of forms and actions:
namespace Album\Form;
use Zend\Form\Form;
class AlbumForm extends Form
Standard router
Standard router is an important Front Controller tool. Here the main decisions are made in order what module, controller and action are being requested. These are all processed here. The following are defaults structure.- Module
- Controller
- Actions
The default router code example:
// Assuming the following:
$ctrl->setControllerDirectory;
Module only:
http://example/news
module news
Invalid module maps to controller name:
http://example/foo
controller foo
Module + controller:
http://example/blog/archive
module blog
controller archive
Module + controller + action:
http://example/blog/archive/list
module blog
controller archive
action list
Module + controller + action + params:
http://example/blog/archive/list/sort/alpha/date/desc
module blog
controller archive
action list
sort alpha
date desc
Utility methods
The Zend Framework also provides some utility methods. Following are some utility methods provided in the framework.; : it is used to call action
Another method is the redirect utility method. This is the opposite of aforementioned _forward method. _redirect performs HTTP in redirection in creation of a new request. _redirect methods accepts two arguments namely $url, and $options.
Furthermore, Action Helpers are also a way to provide extra functionalities within the framework. Action helpers are useful when there is a need to provide functionality between controllers.
//application/controllers/IndexController.php
public function init
View directories
Zend Framework provides the view framework to our project and controller and actions are automatically provided to our application. Inside the Zend Framework in view folder we observe the following folders.- View
- Helpers
- Scripts
- Contacts
- errors
- index
Hello Zend
Hello from Zend Framework
// https://framework.zend.com/manual/2.4/en/modules/zend.view.quick-start.html
namespace Foo\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
class BazBatController extends AbstractActionController
Sponsor and partners
, co-founded by PHP core contributors Andi Gutmans and Zeev Suraski, is the corporate sponsor of Zend Framework. Technology partners include IBM, Google, Microsoft, Adobe Systems, and StrikeIron.Features
Zend Framework features include:- All components are fully object-oriented PHP 5 and are E_STRICT compliant, which helps in the development of building tests and writing codes in a bug-free and crash-proof application manner.
- Use-at-will architecture with loosely coupled components and minimal interdependencies
- Extensible MVC implementation supporting layouts and PHP-based templates by default
- Support for multiple database systems and vendors, including MariaDB, MySQL, Oracle, IBM DB2, Microsoft SQL Server, PostgreSQL, SQLite, and Informix Dynamic Server
- Email composition and delivery, retrieval via mbox, Maildir, POP3 and IMAP4
- Flexible caching sub-system with support for many types of backends, such as memory or a file system.
- With the help of remote procedure call and REST services, Zend Apigility helps developers to create APIs, authentication of APIs, documentation of APIs, Easy Modification
Development of applications
Code, documentation, and test standards
Code contributions to Zend Framework are subject to rigorous code, documentation, and test standards. All code must meet ZF's coding standards and unit tests must reach 80% code coverage before the corresponding code may be moved to the release branch.Simple cloud API
On September 22, 2009, Zend Technologies announced that it would be working with technology partners including Microsoft, IBM, Rackspace, Nirvanix, and GoGrid along with the Zend Framework community to develop a common API to cloud application services called the Simple Cloud API. This project is part of Zend Framework and will be hosted on the Zend Framework website, but a separate site called simplecloud.org has been launched to discuss and download the most current versions of the API.The Simple Cloud API and several Cloud Services are included in Zend Framework. The adapters to popular cloud services have reached production quality.Hello World: file by file
In order to create Hello World program, there are multiple steps including:- First create four files within the directory structure. These files are bootstrap file, an Apache Control file, a controller file and a view controller for the view.
- Second a copy of Zend Framework need to be developed. With the growth of complexity, additional code is required which will provide the functionality and that is relative small and focuses on the benefits of MVC system. Regarding the process in more detail, the bootstrap file is initialization in one form or another.
- Zend_Loader::loadClass the main purpose here is to correct file for the supplied class name.
- Following this the underscores are converted into directory-specific structures. As a result, the code lines Zend_Loader::loadClass; and include_once 'Zend/Controller/Front.php'; show similar results.
- Zend_Debug::dump functions in terms of debugging information and is focused on formatted var_dump output. Finally the bootstrap runs the front controller and initializes it. The design pattern used by Zend_Controller_Front is the Singleton design and getInstance is used to get the single instance.
Current development