free as in freedom free software zend framework 2 console helper module
PHP
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/ZfConsoleHelper/Controller/Console
.gitignore
LICENSE
Module.php
README.md
autoload_classmap.php
autoload_function.php
autoload_register.php
composer.json

README.md

Console Helper Module for Zend Framework 2

Latest stable

This free as in freedom module should easy up implementing console commands supporting POSIX Signal Handling.

Furthermore, there are some simple but useful methods implemented:

  • getParameter($name)
  • getRequest()
  • hasBooleanParameter($shortName = '', $longName = '')
  • hasParameter($name)
  • throwExceptionIfNotCalledInsideAnCliEnvironment()

It is based on the skeleton zf2 module. Thanks also to the skeleton application.

Since it is an abstract Controller, there are no test available.

The versioneye status is: dependencies

Downloads: Downloads this Month

It is also available at openhub.net.

Check out the demo environment if you want to see it in action.

Backport for Zend Framework 2.2 / Debian 6

There is a backport available for debian 6 and its zend framework 2.2 limiting php version.

Example / Usage

<?php

namespace MyModule\Controller\Console;

use Exception;
use ZfConsoleHelper\Controller\Console\AbstractConsoleController;

class IndexController extends AbstractConsoleController
{
    public function indexAction()
    {
        try {
            $this->throwExceptionIfNotCalledInsideAnCliEnvironment();

            $this->attachSignalHandler($this);

            //some example items
            //  simple think about a lot of items that indicates longer
            //  processing runtime
            $items = array('one', 'two', 'three', 'four');

            //use implemented method to react on signal handling
            $this->processItems(
                $items,             //big list of items
                $this,              //current object
                'processItem',      //method that should be called for each item
                $arguments = array( //additional arguments for method 'processItem' (if needed)
                    'foo',
                    'bar'
                )
            );
        } catch (Exception $exception) {
            $this->handleException($exception);
        }
    }

    /**
     * must be protected since it will be called from the parent
     *
     * @param string $item
     * @param string $stringOne
     * @param string $stringTwo
     */
    protected function processItem($item, $stringOne, $stringTwo)
    {
        $console = $this->getConsole();
        $console->writeLine(
            'this is item "' . $item .
            '" with string one "' . $stringOne . '"' .
            '" and string two "' . $stringTwo . '"'
        );
    }

    /**
     * @return boolean
     */
    private function beVerbose()
    {
        return $this->hasBooleanParameter('v', 'verbose');
    }
}

Code like above will output something like that.

this is item "one" with string one "foo"" and string two "bar"
this is item "two" with string one "foo"" and string two "bar"
this is item "three" with string one "foo"" and string two "bar"
this is item "four" with string one "foo"" and string two "bar"

AbstractConsoleControllerFactory

The Factory is a good base for your controller factory. Use the method "transformIntoServiceManager" to transform your injected ControllerManager into ServiceManager.

Install

By Hand

mkdir -p vendor/net_bazzline/zf_console_helper
cd vendor/net_bazzline/zf_console_helper
git clone https://github.com/bazzline/zf_console_helper

With Packagist

"net_bazzline/zf_console_helper": "dev-master"

API

API available at bazzline.net

History

  • upcomming
    • @todo
  • 1.2.2 - released at 18.12.2015
    • updated dependency
  • 1.2.1 - released at 13.09.2015
    • updated dependency by setting zend framework version to minimum of 2.3
  • 1.2.0 - released at 01.08.2015
    • added protected method "stopExecution" to prevent manipulating the now private property
    • updated php documentation
  • 1.1.1 - released at 11.06.2015
  • 1.1.0 - released at 04.06.2015
  • 1.0.3 - released at 08.02.2015
    • removed apigen dependency
  • 1.0.2 - released at 08.02.2015
    • added use statement into example
    • added link to demo environment
    • added link to debian 6 / zend framework 2.2 backport
    • added minimum version of zend framework 2 to 2.3.* since AbstractConsoleController is mandatory
    • updated dependencies
  • 1.0.1 - released at 10.09.2014
    • added example code output
    • added apigen
    • moved to usage of "Zend\Mvc\Controller\AbstractConsoleController"
  • 1.0.0 - released at 09.09.2014
    • initial release