Overview
This package contains a Module.php file and configuration file for configuring
the Laminas Framework 2 validator plugin manager
(Laminas/Validator/ValidatorPluginManager) to use the validators from the
jim-moser/zf2-validators-empty-or package. Use this package if you would like a
Laminas Framework application to be able to retrieve instances of the validators
provided by the jim-moser/zf2-validators-empty-or package from the Laminas
Framework validator plugin manager., (*1)
This package depends on the jim-moser/zf2-validators-empty-or package so you can
simply add this package to the application's composer.json file if you want both
this package and the jim-moser/zf2-validators-empty-or package., (*2)
This package was split from the jim-moser/zf2-validators-empty-or package in
order to reduce that package's dependencies to the minimum required to use the
provided validators., (*3)
Related packages:, (*4)
A brief description of the related packages listed above can be found in the
README.md file for the
jim-moser/zf2-validators-empty-or
package., (*5)
Dependencies
The code in this package depends directly on code and classes from the following
packages:
jim-moser/zf2-validators-empty-or
laminas/laminas-modulemanager, (*6)
However it appears that the code within laminas-modulemanager and/or its'
dependencies has several dependencies on code and classes within various Laminas
packages not specified as dependencies within the composer.json files of
laminas-modulemanager and its' dependencies. To prevent this issue from causing
problems, these missing dependencies have been added to the composer.json file
of this package. The additional dependencies added under the "requires" section
of the composer.json file are:
laminas/laminas-console
laminas/laminas-loader
laminas/laminas-mvc
laminas/laminas-servicemanager, (*7)
Installation
Alternative 1: Installation with Composer
-
For an existing Laminas Framework installation, move into the parent of the
vendor directory. This directory should contain an existing composer.json
file. For a new installation, move into the directory you would like to
contain the vendor directory., (*8)
$ cd <parent_path_of_vendor>
-
Run the following command which will update the composer.json file, install
the zf2-validators-empty-or-plugin package and its dependencies into their
respective directories under the vendor directory, and update the composer
autoloading files., (*9)
$ composer require jim-moser/zf2-validators-empty-or-plugin
Alternative 2: Manual Installation to Vendor Directory
Note that since this installation method does not setup Composer autoloading,
autoloading will need to be setup in some other manner. The installation
instructions below use the Module.php file in
jim-moser/zf2-validators-empty-or-plugin and the test\bootstrap.php file in
jim-moser/zf2-validators-empty-or-plugin-test to setup autoloading. The packages
will need to be installed into a complete Laminas Framework 2 installation for
this to work. Using a skeleton Laminas Framework application is recommended., (*10)
-
Create vendor directory., (*11)
$ mkdir vendor, (*12)
-
Download and install Laminas Framework 2., (*13)
Download Laminas Framework 2 archive from
http://framework.zend.com/downloads/archives., (*14)
$ curl http://packages.zendframework.com/releases/LaminasFramework-2.4.9/LaminasFramework-2.4.9.zip
Unpack archive., (*15)
$ unzip LaminasFramework-2.4.9.zip
Create a vendor/ZF2 directory., (*16)
$ mkdir ZF2
Move unpacked contents into the vendor/ZF2 directory., (*17)
$ mv LaminasFramework-2.4.9 ZF2
- Use git clone or other method to copy files from the git repositories to the
vendor// directories for each of the following
packages.
- jim-moser/zf2-validators-empty-or
- jim-moser/zf2-validators-empty-or-test
- jim-moser/zf2-validators-empty-or-plugin
-
jim-moser/zf2-validators-empty-or-plugin-test, (*18)
For example copy the files from the jim-moser/zf2-validators-empty-or
repository to the vendor/jim-moser/zf2-validators-empty-or/ directory., (*19)
-
Edit the application configuration file to notify the module manager about
the module., (*20)
The Module.php file provided with this package provides configuration to a
Laminas Framework autoloader to allow auto loading of the classes from the
jim-moser/zf2-validators-empty-or package without Composer autoloading.
The Laminas Framework module manager needs to be made aware that this
package is a Laminas Framework module for the Laminas autoloader to receive
this configuration. Follow the instructions in the Module Manager
Configuration section below to notify the module manager
of this module., (*21)
-
Setup unit testing., (*22)
The phpunit.xml file in the jim-moser\validators-empty-or-test package
depends on Composer autoloading which is not being used here. In order to
use the autoloading setup in the module file, rename the
phpunit.xml.no_composer.dist file to phpunit.xml., (*23)
Module Manager Configuration
The Laminas Framework module manager needs to be made aware that this package is
a Laminas Framework module in order for the validator plugin manager to receive
the configuration from this package. This is accomplished by adding the module
name to the ['modules'] array and the module name and path to the
['module_listener_options']['module_paths'] array of the array returned
by the application's config/application.config.php file., (*24)
<?php
// config/application.config.php
return array(
'modules' => array(
'Application',
'JimMoser\EmptyOrValidatorsModule', //Add this line.
...
),
'module_listener_options' => array(
'module_paths' => array(
'JimMoser\EmptyOrValidatorsModule' => './vendor/jim-moser/zf2-validators-empty-or' //Add this line.
),
),
);
Validator Plugin Manager Usage In Validator Chains
This package's Module.php file adds configuration (see the
config/module.config.php file) to allow the validator plugin manager to obtain
instances of the validators provided by the jim-moser/zf2-validators-empty-or
package from their names. The validator plugin manager must be obtained from the
service manager for it to receive this configuration., (*25)
Some classes such as Laminas/Validator/ValidatorChain,
JimMoser/Validator/OrChain, and JimMoser/Validator/VerboseOrChain by default
will directly instantiate new Laminas/Validator/ValidatorPluginManager instances
using the keyword "new" instead of obtaining an instance from the service
manager. ValidatorPluginManager instances created directly with the keyword
"new" will not receive the application configuration during construction and
thus will not be aware of the validators from the
jim-moser/zf2-validators-empty-or package. You should inject a validator plugin
manager pulled from the service manager into objects such as ValidatorChain
objects to ensure a fully configured validator plugin manager is used., (*26)
Beware that serializing and then deserializing an object such as a
Laminas/Validator/ValidatorChain will cause an injected validator plugin manager
to be replaced with one created with the keyword "new"., (*27)