Home
+91 99674 50288
info@appmonks.net
×

Zend Framework

                              

Zend is open source PHP framework. It is object-oriented and built in the MVC design pattern.

Zend framework contain collection of PHP package which is used to develop web applications and services.

Zend framework installation steps:

Zend Framework can be installed in two ways. They are as follows −

1)Manual installation

2)Composer based installation

1) Manual Installation

Download the latest version of Zend Framework by visiting the following link – https://framework.zend.com/downloads/archives

Extract content of the downloaded archive file to the folder we would like to keep it. Once we have a copy of Zend Framework  in our local machine, then Zend Framework based web application can access the framework classes.  there are multiple way to achieve this, PHP include path needs to contain the path to the Zend Framework classes under the /library directory in the distribution.

2) Composer Based Installation

To easily install Zend Framework using the Composer tool. To install all the components of the Zend Framework, use the below command –

-$ composer require zend framework/zend framework

Each Zend Framework component can be installed individually as well. For example, to install the MVC component of the Zend Framework, use the following command –

-$ composer require zend framework/ zend-mvc

Zend Framework is a collection of components. They are connected with each other. They can be used both stand-alone component as well as a group of components working as a single unit.

Zend Framework has three most important components, which are −

1)zend-service manager

2)zend-event manager

3)zend-module manager.

  1) zend-service manager

Zend Framework include service locator pattern implementation called zend-service manager

Zend framework use the service manager for all functionalities

The Service Manager provide high-level abstraction for the Zend Framework. It also integrate nicely with all the other component of the Zend Framework.

Install Service Manager

The Service Manager component installed using the composer tool.

Composer require zend framework/zend service manager

Example:-

First all services need to be registered into the service manager. Once the service are registered into the server manager it can be accessed at any time. The service manager provide a lots of options to register the service.

The above code register stdClass into system using the Factory option. we can get instance of the stdClass at any time using the get() method of the service manager as shown below.

Use Zend\ServiceManager\ServiceManager;

$object=$serviceManager->get(stdClass::class);

The get() method  retrieved object and  the object returned by calling the get() method multiple times is one and the same instance. To get a different instance every time, the service manager provide another method, which is the build() method.

 Use Zend\ServiceManager\ServiceManager;

$a=$serviceManager->build (stdclass::class);

$b==$serviceManager->build(stdclass::class);

 Service Manager Registration:-

The service manager includes a set of methods to register a component.

The most methods are given below −

  • Factory method
  • Abstract factory method
  • Initializer method
  • Delegator factory method
  • Factory Method:-

A Factory is a class that implements factory interface.

 The Factory Interface has a method −

 The argument details of the Factory Interface is as follow –

Public function __invoke(container Interface $container,$requestName,array $options=null)

  • container (Container Interface) − It is interface of the Service Manager. It provide option to get other services.
  • requestedName − It is the service name.
  • options − It gives additional option needed for the service.
  • Below is simple class implementing the Factory Interface

Class test: -object retrieved

Use stdClass;

Class Test{

Public function __construct(stdClass $sc){

//use $sc

}

}

The Test class depends on the stdClass.

The service manager provides a special factory called Invokable Factory to retrieve any class which has no dependency. For example, the stdClass can be configured using the Invokable Factory since the stdClass does not depend on any other class.

  • Abstract factory Method:-

Some time we need to create objects, which we come to know only at runtime. This situation can be handled using the Abstract Factory Interface, which is derived from the Factory Interface.

The Abstract Factory Interface defines a method to check whether the object can be created at the requested instance or not. If object creation is possible, it will create the object using the __invoke method of the Factory Interface and return it.

  • Intializer Method:-

The Initializer Method is special option to inject additional dependency for already created service. It implements the Initializer Interface 

In the above example, the method check whether the instance is of type Event Manager Aware Interface. If it is of type Event Manager Aware Interface, it sets the event manager object, otherwise not.

  • Delegator Factory Method:-

Zend Framework supports delegators pattern through delegator factory interface it can be used to decorate the service.

 2) zend-event manager:-

Zend Framework provides zend-event manager component. The zend-event manager helps to design high level architecture and supports subject/observer pattern and aspect oriented programming.

Install Event Manager:-

    The event manager installed using the Composer –

    Composer required zend framework/zend-event manager event manager .

 3) zend-module manager:-

The Zend Framework provides module system. The module system has three components. They are as follows −

  • Module Autoloader − A Module Autoloader is for locating and loading of modules from variety of sources. It can load module packaged.
  • Module Manager − Once the Module Autoloader locates the module, the module manager fires a sequence of events for each module.
  • Module Manager Listeners − They can be attached to the event fired by the Module Manager.
 

Mail
casino