Friday 10 May 2019

Zend 3 Interview Questions and Answers - Page 2

Zend 3 Interview Questions and Answers

Question: What is Hydrators?
Hydrators are used to create objects from different PHP array formats.
The main feature of each hydrator is a link between two separate layers, so that they are not cluttered up with unnecessary mappings, validations or filters in the classes, models etc.

Question: How to add filter in Zend3?
You can use Zend's HtmlEntities for filter the user data.
For Example:
$filter = new Zend\Filter\HtmlEntities();
print $filter->filter('<');

Question: How to set the UTC timezone for Zend?
Put the following code in public/index.php

Question: What is Service Locator Pattern?
The service locator design pattern is used "Encapsulate the processes involved in obtaining a service with a strong abstraction layer".
It return the instances of services when they are requested for by the service consumers.

Following are the Design components of Service Locator Pattern.
Service Locator: It lookup services,dependencies,business object provides a simple interface to clients.
InitialContext: The InitialContext object is the start point in the lookup and creation process.
ServiceFactory: It provides the required BusinessService objects.
BusinessService: It the main object that fullfill your requirements.

Question: What is Service Manager?
Service Manager are heavely used in zend and it is based on Service Locator design Pattern.
It is used to register a service and get the server.

Question: How to install a Service Manager component?
composer require zendframework/zend-servicemanager

Question: How to register a service in Service manager?
use Zend\ServiceManager\ServiceManager; 
use Zend\ServiceManager\Factory\InvokableFactory; 
use stdClass;  
$serviceManager = new ServiceManager([ 
   'factories' => [stdClass::class => InvokableFactory::class,], 

Question: How to get the object from Service Manager?
use Zend\ServiceManager\ServiceManager;  
$object = $serviceManager->get(stdClass::class);

Question: What is eventmanager?
The zend-eventmanager helps to design "High level architecture" and supports "subject/observer pattern".

It has two importants points
Event: Its event.
Listener: Listener are attached to the events and gets called when the event is triggered.
EventInterface Class: Used to specify the event itself.
EventManager class The instance of the EventManager tracks all the defined events in an application and its corresponding listeners.