Using the CLI Tool

Architecture

Registry

Because providers and manifests may come from anywhere in the include_path, a registry is provided to simplify access to the various pieces of the toolchain. This registry is injected into registry-aware components, which may then pull dependencies from them as necessary. Most dependencies registered with the registry will be sub-component-specific repositories.

The interface for the registry consists of the following definition:

  1.  

The various objects the registry manages will be discussed in their appropriate sections.

Classes that should be registry-aware should implement Zend_Tool_Framework_Registry_EnabledInterface. This interface merely allows initialization of the registry in the target class.

  1.  

Providers

Zend_Tool_Framework_Provider represents the functional or "capability" aspect of the framework. Fundamentally, Zend_Tool_Framework_Provider will provide the interfaces necessary to produce "providers", or bits of tooling functionality that can be called and used inside the Zend_Tool_Framework toolchain. The simplistic nature of implementing this provider interface allows the developer a "one-stop-shop" of adding functionality or capabilities to Zend_Tool_Framework.

The provider interface is an empty interface and enforces no methods (this is the Marker Interface pattern):

  1.  

Or, if you wish, you can implement the base (or abstract) Provider which will give you access to the Zend_Tool_Framework_Registry:

  1.  

Loaders

The purpose of a Loader is to find Providers and Manifest files that contain classes which implement either Zend_Tool_Framework_Provider_Interface or Zend_Tool_Framework_Manifest_Interface. Once these files are found by a loader, providers are loaded into the Provider Repository and manifest metadata is loaded into the Manifest Repository.

To implement a loader, one must extend the following abstract class:

  1. span style="color: #808080; font-style: italic;">/** ... */
  2.     }
  3. }

The _getFiles() method should return an array of files (absolute paths). The built-in loader supplied with Zend Framework is called the IncludePath loader. By default, the Tooling framework will use an include_path based loader to find files that might include Providers or Manifest Metadata objects. Zend_Tool_Framework_Loader_IncludePathLoader, without any other options, will search for files inside the include path that end in Mainfest.php, Tool.php or Provider.php. Once found, they will be tested (by the load() method of the Zend_Tool_Framework_Loader_Abstract) to determine if they implement any of the supported interfaces. If they do, an instance of the found class is instantiated, and it is appended to the proper repository.

  1. span style="color: #ff0000;">'.*(/|\\\\).svn''.*(?:Manifest|Provider)\.php$'/** ... */
  2.     }
  3. }

As you can see, the IncludePath loader will search all include_paths for the files that match the $_filterAcceptFilePattern and not match the $_filterDenyDirectoryPattern.

Manifests

In short, the Manifest shall contain specific or arbitrary metadata that is useful to any provider or client, as well as be responsible for loading any additional providers into the provider repository.

To introduce metadata into the manifest repository, all one must do is implement the empty Zend_Tool_Framework_Manifest_Interface, and provide a getMetadata() method which shall return an array of objects that implement Zend_Tool_Framework_Manifest_Metadata.

  1.  

Metadata objects are loaded (by a loader defined below) into the Manifest Repository (Zend_Tool_Framework_Manifest_Repository). Manifests will be processed after all Providers have been found to be loaded into the provider repository. This shall allow Manifests to create Metadata objects based on what is currently inside the provider repository.

There are a few different metadata classes that can be used to describe metadata. The Zend_Tool_Framework_Manifest_Metadata is the base metadata object. As you can see by the following code snippet, the base metadata class is fairly lightweight and abstract in nature:

  1. span style="color: #ff0000;">'Global'/** ... */
  2. }

There are other built in metadata classes as well for describing more specialized metadata: ActionMetadata and ProviderMetadata. These classes will help you describe in more detail metadata that is specific to either actions or providers, and the reference is expected to be a reference to an action or a provider respectively. These classes are described in the following code snippet.

  1. span style="color: #ff0000;">'Action'/** ... */'Provider'/** ... */
  2. }

'Type' in these classes is used to describe the type of metadata the object is responsible for. In the cases of the ActionMetadata, the type would be 'Action', and conversely in the case of the ProviderMetadata the type is 'Provider'. These metadata types will also include additional structured information about both the "thing" they are describing as well as the object (the getReference()) they are referencing with this new metadata.

In order to create your own metadata type, all one must do is extend the base Zend_Tool_Framework_Manifest_Metadata class and return these new metadata objects via a local Manifest class or object. These user based classes will live in the Manifest Repository

Once these metadata objects are in the repository, there are then two different methods that can be used in order to search for them in the repository.

  1. span style="color: #808080; font-style: italic;">/**
  2.      * To use this method to search, $searchProperties should contain the names
  3.      * and values of the key/value pairs you would like to match within the
  4.      * manifest.
  5.      *
  6.      * For Example:
  7.      *     $manifestRepository->findMetadatas(array(
  8.      *         'action' => 'Foo',
  9.      *         'name'   => 'cliActionName'
  10.      *         ));
  11.      *
  12.      * Will find any metadata objects that have a key with name 'action' value
  13.      * of 'Foo', AND a key named 'name' value of 'cliActionName'
  14.      *
  15.      * Note: to either exclude or include name/value pairs that exist in the
  16.      * search criteria but do not appear in the object, pass a bool value to
  17.      * $includeNonExistentProperties
  18.      *//**
  19.      * The following will return exactly one of the matching search criteria,
  20.      * regardless of how many have been returned. First one in the manifest is
  21.      * what will be returned.
  22.      */

Looking at the search methods above, the signatures allow for extremely flexible searching. In order to find a metadata object, simply pass in an array of matching constraints via an array. If the data is accessible through the Property accessor (the getSomething() methods implemented on the metadata object), then it will be passed back to the user as a "found" metadata object.

Clients

Clients are the interface which bridges a user or external tool into the Zend_Tool_Framework system. Clients can come in all shapes and sizes: RPC endpoints, Command Line Interface, or even a web interface. Zend_Tool has implemented the command line interface as the default interface for interacting with the Zend_Tool_Framework system.

To implement a client, one would need to extend the following abstract class:

  1. span style="color: #808080; font-style: italic;">/**
  2.      * This method should be implemented by the client implementation to
  3.      * construct and set custom loaders, request and response objects.
  4.      *
  5.      * (not required, but suggested)
  6.      *//**
  7.      * This method should be implemented by the client implementation to parse
  8.      * out and set up the request objects action, provider and parameter
  9.      * information.
  10.      *//**
  11.      * This method should be implemented by the client implementation to take
  12.      * the output of the response object and return it (in an client specific
  13.      * way) back to the Tooling Client.
  14.      *
  15.      * (not required, but suggested)
  16.      */

As you can see, there 1 method is required to fulfill the needs of a client (two others suggested), the initialization, prehandling and post handling. For a more in depth study of how the command line client works, please see the » source code.


Using the CLI Tool