2017 © Pedro Peláez
 

library gzfextra

Zend framework 2 extra

image

moln/gzfextra

Zend framework 2 extra

  • Thursday, February 4, 2016
  • by Moln
  • Repository
  • 0 Watchers
  • 0 Stars
  • 76 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

gzfextra

Zend framework 2 extra, (*1)

Installation using Composer

{
    "require": {
        "moln/gzfextra": "~1.0"
    }
}

Db - 数据库抽象调用

ZF2 自建 TableGateway 方法比较麻烦, 每个Table 要在 service_manager 加配置. Gzfextra\Db\TableGateway\TableGatewayAbstractServiceFactory 为抽象常用 TableGateway 调用., (*2)

Example - 使用举例

module.config.php, (*3)

return array(
    'service_manager'    => array(
        'abstract_factories' => array(
            'Gzfextra\Db\TableGateway\TableGatewayAbstractServiceFactory',
        ),
    ),
    'tables' => array(
        'UserTable'  => array(
            'table'     => 'users',
            'invokable' => 'User\\Model\\UserTable',
            'primary'   => 'user_id',
        ),
        'RoleTable' => array(
            'table'     => 'roles',
            'invokable' => 'User\\Model\\RoleTable',
            'primary'   => 'role_id',
        ),
    ),
);

User\Model\UserTable.php, (*4)

namespace User\Model;
use Zend\Db\TableGateway\TableGateway as ZendTableGateway;

/**
 * UserTable
 *
 * 默认带有公共函数特性
 * @method int fetchCount($where)
 * @method \ArrayObject|\Zend\Db\RowGateway\RowGateway find($id)
 * @method \Zend\Paginator\Paginator fetchPaginator($where = null)
 * @method int deletePrimary($key)
 */
class UserTable extends ZendTableGateway
{
}

控制器调用, (*5)

public function indexAction()
{
    $users = $this->getServiceLocator()->get('UserTable');
    $row = $users->find(1);
}

Router - 公共路由

ZF2 自带的 Zend\Mvc\ModuleRouteListener 不方便, 每新的 Controller 都需要在 ControllerPlugin 配置下. Gzfextra\Router\GlobalModuleRouteListener, (*6)

Example - 使用举例

class Module
{
    public function onBootstrap(MvcEvent $e)
    {
        $eventManager = $e->getApplication()->getEventManager();

        $gListener = new GlobalModuleRouteListener();
        $eventManager->attach($gListener);
    }

    public function getConfig()
    {
        return GlobalModuleRouteListener::getDefaultRouterConfig();
    }
}

默认路由方式: /module/controller/action/param1/value1/param2/value2/..., (*7)

FileStorage - 文件存储抽象

文件存储模式 - Filesystem (存储文件系统 - Ftp (存储FTP - Sftp (存储sftp, (*8)

Example - 使用举例

module.config.php, (*9)

工厂方式, (*10)

return array(
    'service_manager' => array(
        'factories' => array(
            'FileStorage' => '\Gzfextra\FileStorage\StorageFactory'
        )
    ),
    'file_storage'    => array(
        'type'    => 'fileSystem',
        'options' => array(
            'default_path' => realpath('./public/uploads'),
            'validators'   => array(
                'Extension' => array('gif', 'jpg', 'jpeg', 'png'),
                'Size'      => array('max' => 1024 * 1024),
                'IsImage',
            ),
            'filters'      => array(
                'LowerCaseName',
                'RenameUpload' => array(
                    'target'               => 'shop',
                    'use_upload_extension' => true,
                    'randomize'            => true,
                ),
            ),
        ),
    ),
);

抽象工厂, (*11)

return array(
    'service_manager' => array(
        'abstract_factories' => array(
            '\Gzfextra\FileStorage\StorageAbstractFactory'
        ),
    ),
    'file_storage_configs' => array(
        'ImageFileStorage'    => array(
            'type'    => 'fileSystem',
            'options' => array(
                'default_path' => realpath('./public/uploads'),
                'validators'   => array(
                    'Extension' => array('gif', 'jpg', 'jpeg', 'png'),
                    'Size'      => array('max' => 1024 * 1024),
                    'IsImage',
                ),
                'filters'      => array(
                    'LowerCaseName',
                    'RenameUpload' => array(
                        'target'               => 'shop',
                        'use_upload_extension' => true,
                        'randomize'            => true,
                    ),
                ),
            ),
        ),
        'ZipFileStorage'    => array(
            'type'    => 'ftp',
            'options' => array(
                'ftp' => array(
                    'host' => 'localhost',
                    'username' => 'ftpuser',
                    'password' => '123456',
                    'pasv' => true,
                ),
                'default_path' => '/',
                'validators'   => array(
                    'Extension' => array('zip'),
                ),
                'filters'      => array(
                    'LowerCaseName',
                    'RenameUpload' => array(
                        'target'               => 'zipfile',
                        'use_upload_extension' => true,
                        'randomize'            => true,
                    ),
                ),
            ),
        ),
    ),
);

控制器调用, (*12)

public function indexAction()
{
    $fileStorage = $this->getServiceLocator()->get('ImageFileStorage');
    if ($fileStorage->isValid()) {
        $file = $fileStorage->upload($file);
        // var_dump($file);
    }
}

Tool - Gzfextra 工具

依赖 zendframework/zftool, (*13)

EasyMvc - (正在评估ZF2 框架流程是否能简化部分)

Mvc - 扩展Mvc模块

  • Gzfextra\Controller\Plugin\Params 类似 ZF1的 $this->getParam(), 默认取路由, 不存在取POST&GET

UiFramework

目前限 KendoUi - KendoUi 的控制器插件, (*14)

The Versions

04/02 2016

dev-master

9999999-dev

Zend framework 2 extra

  Sources   Download

MIT

The Requires

 

by Avatar Moln

zf2 zendframework zfextra

21/08 2015

1.4

1.4.0.0

Zend framework 2 extra

  Sources   Download

MIT

The Requires

 

by Avatar Moln

zf2 zendframework zfextra

26/06 2015

1.3

1.3.0.0

Zend framework 2 extra

  Sources   Download

MIT

The Requires

 

by Avatar Moln

zf2 zendframework zfextra

26/06 2015

dev-develop

dev-develop

Zend framework 2 extra

  Sources   Download

MIT

The Requires

 

by Avatar Moln

zf2 zendframework zfextra

03/06 2015

1.2

1.2.0.0

Zend framework 2 extra

  Sources   Download

MIT

The Requires

 

by Avatar Moln

zf2 zendframework zfextra

08/05 2015

1.1

1.1.0.0

Zend framework 2 extra

  Sources   Download

MIT

The Requires

 

by Avatar Moln

zf2 zendframework zfextra

17/03 2015

1.0

1.0.0.0

Zend framework 2 extra

  Sources   Download

MIT

The Requires

 

by Avatar Moln

zf2 zendframework zfextra

17/03 2015

1.0.x-dev

1.0.9999999.9999999-dev

Zend framework 2 extra

  Sources   Download

MIT

The Requires

 

by Avatar Moln

zf2 zendframework zfextra

11/03 2015

0.9-alpha

0.9.0.0-alpha

Global Zend framework 2 extra

  Sources   Download

MIT

The Requires

 

by Avatar Moln

zf2 zendframework zfextra