Coding Style in EC-CUBE

Rules

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Acme;

/**
 * Coding standards demonstration.
 */
class FooBar
{
    const SOME_CONST = 42;

    /**
     * @var string
     */
    private $fooBar;

    /**
     * @param string $dummy Some argument description
     */
    public function __construct($dummy)
    {
        $this->fooBar = $this->transformText($dummy);
    }

    /**
     * @return string
     *
     * @deprecated
     */
    public function someDeprecatedMethod()
    {
        @trigger_error(sprintf('The %s() method is deprecated since version 2.8 and will be removed in 3.0. Use Acme\Baz::someMethod() instead.', __METHOD__), E_USER_DEPRECATED);

        return Baz::someMethod();
    }

    /**
     * Transforms the input given as first argument.
     *
     * @param bool|string $dummy   Some argument description
     * @param array       $options An options collection to be used within the transformation
     *
     * @return string|null The transformed input
     *
     * @throws \RuntimeException When an invalid option is provided
     */
    private function transformText($dummy, array $options = array())
    {
        $defaultOptions = array(
            'some_default' => 'values',
            'another_default' => 'more values',
        );

        foreach ($options as $option) {
            if (!in_array($option, $defaultOptions)) {
                throw new \RuntimeException(sprintf('Unrecognized option "%s"', $option));
            }
        }

        $mergedOptions = array_merge(
            $defaultOptions,
            $options
        );

        if (true === $dummy) {
            return;
        }

        if ('string' === $dummy) {
            if ('values' === $mergedOptions['some_default']) {
                return substr($dummy, 0, 5);
            }

            return ucwords($dummy);
        }
    }

    /**
     * Performs some basic check for a given value.
     *
     * @param mixed $value     Some value to check against
     * @param bool  $theSwitch Some switch to control the method's flow
     *
     * @return bool|null The resultant check if $theSwitch isn't false, null otherwise
     */
    private function reverseBoolean($value = null, $theSwitch = false)
    {
        if (!$theSwitch) {
            return;
        }

        return !$value;
    }
}

// HogeController

class HogeController
{
    protected $title;

    protected $subTitle;

    public function index(Application $app, $id)
    {
        $Product = $app['eccube.repository.product']->find($id);

        $totalCount = 1;

        // ...

        $app->render('path/to/hoge.twig', array(
            'form' => $form->createView(),
            'Product' => $Product,
            'total_count' => $totalCount,
        ))
    }
}

// hoge.twig









$builder
  ->add('name')
  ->add('age'); // here
$array = array(
  'name' => 'shinichi',
  'age' => '26',
); // here
    form_widget(form.name)
    form_errors(form.name)

Giải thích về các thành phần chính của EC-CUBE

Code EC-CUBE thì toàn bộ nằm trong thư mục src/Eccube

Where What in 2.13 version 
ControllerProvider Định nghĩa Routing. Truyền request đến controller html/Các trang php ở dưới thư mục này
Controller Nhận request, xử lý và trả lại response cho view LC_Page_Xxx
Service Tầng Business logic. Đảm nhận những xử lý logic SC_Xxx
ServiceProvider Đăng ký những biến toàn cục của hệ thông SC_Initial hoặc là Require_base
Resource/doctrine Nơi đặt file định nghĩa của doctrine. Viết bằng yaml Không có
Entity Thực thể để map với các doctrine tương ứng Không có
Repository Định nghĩa các hàm tương tác với bảng dữ liệu trong Entity SC_Query
Form/Type Định nghĩa Form, Validator… SC_FormParam
View View viết bằng Twig Xxx.tpl

Để Controller không qúa phức tạp

Ngoài những xử lý dưới đây thì không được phép viết trong Controller

Controller

Repository

FormType

Service

Unit test