承接 peytz/wizard 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

peytz/wizard

Composer 安装命令:

composer require peytz/wizard

包简介

Wizard Component for Symfony2.

README 文档

README

Build Status

This is a simple component mainly developed for usage with the Symfony2 framework. And because of that there is some references to that. Which easily can be changed.

License

See LICENSE for licensing terms.

Contributing

Everybody is welcome to send Pull Requests. But we reserve the right to reject any that is not in line with our goals for this component.

See https://github.com/Peytz/Wizard/contributors for a list of contributors

Installing

There is 3 ways to install this component. You can use Composer, Phar or just include the code directly in your application.

Using phar

Theres is a ready to use phar achive in build/peytz-wizard.phar which includes its own small autoloader that automatically registers with php when included.

<?php

require 'phar://build/peytz-wizard.phar';

var_dump(class_exists('Peytz\Wizard\Wizard'));

Using Composer

You can also install it via composer by using something like the following require.

{
    "require" : {
        "peytz/wizard" : "master-dev"
    }
}

Running tests

$ phpunit

Usage

The api is very simple. You create a Report which properly should be an Doctrine Entity. The Report holds your data and must implement ReportInterface

A Report is required as a contructor argument for a Wizard. A Wizard should be subclassed to add custom steps or use a DependencyInjection framework to inject them into a Wizard object.

A Wizard holds a n number of Steps that implements the StepInterface. There is a basic Step implementation of StepInterface availible.

<?php

namespace Vendor\Wizard;

use Peytz\Wizard\Step;
use Vendor\Wizard\Form\CustomFormType;

class CustomStep extends Step
{
    public function getFormType()
    {
        return new CustomFormType();
    }
}
<?php

namespace Vendor\Wizard;

use Peytz\Wizard\Wizard;
use Peytz\Wizard\ReportInterface;
use Vendor\Wizard\CustomStep;

class CustomWizard extends Wizard
{
    public function __construct(ReportInterface $report)
    {
        parent::__construct($report);
        $this->add(new CustomStep());
    }
}
<?php

namespace Vendor\Wizard;

use Peytz\Wizard\ReportInterface;

class Report implements ReportInterface
{
}

Controller action implementation using Symfony Validator component for validation. Validation Groups are extremely useful for this.

<?php

namespace Vendor\Wizard;

class Controller
{
    protected $validator;

    protected $wizard;

    public function myAction($stepIdentifier)
    {
        $step = $this->wizard->get($stepIdentifier);
        $form = $this->createForm($step->getFormType(), $this->wizard->getReport(), array(
            'validation_groups' => array($step->getName()),
        ));

        if ($_POST) {
            $form->bind($_POST);
            if ($form->isValid()) {
                $this->wizard->process($step);

                // You should proberly save some stuff here? And redirect
            }
        }

        return array(
            'form' => $form,
        );
    }
}

Sample Symfony2 DIC definition

I you want to use DependencyInjection with Symfony2 this is another way of having a Wizard and its steps associated.

The power of using a DIC is that each StepInterface implementation can have optional dependencies. Like building forms programmatically instead of having a FormType.

<container>
    <services>
        <service id="vendor.wizard.custom" class="Peytz\Wizard\Wizard">
            <argument type="service" id="vendor.wizard.custom.report" />
            <call method="add">
                <argument type="service" id="vendor.wizard.custom.my_step" />
            </call>
        </service>
    </services>
</container>

Updating gh-pages branch

$ ./apigen.sh
$ git push

统计信息

  • 总下载量: 4k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 36
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 36
  • Watchers: 13
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2011-12-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固