net_bazzline/zf_console_helper

此软件包已被废弃,不再维护。未建议替代软件包。

自由免费,Zend Framework 2 控制台助手模块

1.2.2 2015-12-18 19:50 UTC

This package is auto-updated.

Last update: 2021-03-05 12:12:41 UTC


README

我仍然喜欢这个想法,但目前没有开发它的用例。

Zend Framework 2 控制台助手模块

Latest stable

这个自由模块应该可以简化实现支持 POSIX 信号处理的控制台命令。

此外,还实现了一些简单但实用的方法

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

它基于 skeleton zf2 模块。还要感谢 skeleton 应用程序

由于它是一个抽象控制器,没有可用的测试。

versioneye 状态: dependencies

下载量:Downloads this Month

它也可在 openhub.net 上找到。

如果您想看到它的实际效果,请查看 演示环境

Zend Framework 2.2 / Debian 6 的回溯

对于 Debian 6 及其 Zend Framework 2.2 限制的 PHP 版本,有可用的 回溯

示例/用法

<?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');
    }
}

如上代码将输出类似的内容。

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

该工厂是控制器工厂的良好基础。使用“transformIntoServiceManager”方法将注入的 ControllerManager 转换为 ServiceManager

安装

手动

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

使用 Packagist

"net_bazzline/zf_console_helper": "dev-master"

API

APIbazzline.net 上可用

历史

  • 即将推出
    • @待办
  • 1.2.2 - 于 2015年12月18日发布
    • 更新依赖
  • 1.2.1 - 于 2015年9月13日发布
    • 通过设置 Zend 框架版本为 2.3 的最小值来更新依赖
  • 1.2.0 - 于 2015年8月1日发布
    • 添加了受保护的 "stopExecution" 方法,以防止操作现在为私有的属性
    • 更新 PHP 文档
  • 1.1.1 - 于 2015年6月11日发布
  • 1.1.0 - 于 2015年6月4日发布
  • 1.0.3 - 于 2015年2月8日发布
    • 移除了 apigen 依赖
  • 1.0.2 - 于 2015年2月8日发布
    • 在示例中添加了 use 语句
    • 添加了指向演示环境的链接
    • 添加了指向 Debian 6 / Zend 框架 2.2 的回滚链接
    • 由于 AbstractConsoleController 是必需的,因此将 Zend 框架 2 的最低版本设置为 2.3.*
    • 更新依赖
  • 1.0.1 - 于 2014年9月10日发布
    • 添加了示例代码输出
    • 添加了 apigen
    • 转移到使用 "Zend\Mvc\Controller\AbstractConsoleController"
  • 1.0.0 - 于 2014年9月9日发布
    • 初始发布