Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

命名規約 #6

Open
chihiro-adachi opened this issue Jul 3, 2018 · 5 comments
Open

命名規約 #6

chihiro-adachi opened this issue Jul 3, 2018 · 5 comments
Labels
Milestone

Comments

@chihiro-adachi
Copy link
Contributor

chihiro-adachi commented Jul 3, 2018

プラグインコード

重複を避けるため, [ベンダー名][プラグイン]の形式を推奨
キャメルケースで記述する

AcmeCategoryContent

テーブル名

※プラグイン固有のテーブルを作成する場合

plg_[プラグインコードのスネークケース]_xxx

use Doctrine\ORM\Mapping as ORM;

/**
 * Config
 *
 * @ORM\Table(name="plg_acme_category_content_config")
 * @ORM\Entity(repositoryClass="Plugin\AcmeCategoryContent\Repository\ConfigRepository")
 */
class Config

テーブルのカラム名およびgetter/setter

※traitを使用してカラムを追加する場合

[プラグインコードのスネークケース]_xxx
getter/setterはキャメルケースで記述する

use Eccube\Annotation\EntityExtension;
use Doctrine\ORM\Mapping as ORM;

/**
 * @EntityExtension("Eccube\Entity\Customer")
 */
trait CustomerTrait
{
    /**
     * @ORM\Column(name="acme_category_content_xxx" type="integer", nullable=true)
     */
    private $acme_category_content_xxx;

    public function getAcmeCategoryContentXxx()
    {
    }

    public function setAcmeCategoryContentXxx($xxx)
    {
    }
}

ルーティング

[プラグインコードのスネークケース]_xxx

class ConfigController extends AbstractController
{
    /**
     * @Route("/%eccube_admin_route%/acme_category_content/config", name="acme_category_content_admin_config")
     * @Template("@AcmeCategoryContent/admin/config.twig")
     */
    public function index(Request $request)

URL

/[プラグインコードのスネークケース]/xxx/xxx

class ConfigController extends AbstractController
{
    /**
     * @Route("/%eccube_admin_route%/acme_category_content/config", name="acme_category_content_admin_config")
     * @Template("@AcmeCategoryContent/admin/config.twig")
     */
    public function index(Request $request)

FormExtensionで追加するフィールド

[プラグインコードのスネークケース]_xxx

class XxxExtention extends AbstractTypeExtension
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('acme_category_content_name', TextType::class);

htmlで使用するID, class

[プラグインコードのスネークケース]_xxx

<div id="acme_category_content_info" class="card rounded border-0 mb-4">

コマンド名

[プラグインコードのスネークケース]:xxx:xxx

class XxxCommand extends Command
{
    protected static $defaultName = 'acme_category_content:xxx:yyy';

言語ファイル

[プラグインコードのスネークケース].xxx.xxx

# nav
acme_category_content.admin.nav.category: カテゴリコンテンツ一覧

# flash messages
acme_category_content.admin.save.success: 登録しました。
acme_category_content.admin.save.failed: 登録に失敗しました。

プラグインコード以降の命名規則はEC-CUBE本体の命名規則に従う
EC-CUBE/ec-cube#3593

パラメータ

[プラグインコードのスネークケース].xxx.xxx

parameters:
  acme_category_content.xxx: 1

services:
  acme_category_content.log.formatter.line:
      class: Monolog\Formatter\LineFormatter
      arguments: ...
@ryo-endo
Copy link
Contributor

@chihiro-adachi プラグインで定義するTwigBlock名についても追記してもらいたいです。

@okazy
Copy link
Contributor

okazy commented Jul 7, 2020

BlockPrefix は不要なため折りたたみました。

Form/Type BlockPrefix

[プラグインコードのスネークケース]_xxx_xxx

    public function getBlockPrefix()
    {
        return 'acme_category_content_admin_config';
    }

<\details>

@chihiro-adachi
Copy link
Contributor Author

@okazy
BlockPrefixは宣言しなければ自動で付与されるので不要でいいいんじゃないでしょうか。
BlockPrefixを直接利用するシーンもほとんどないかと思いますし。

本体でついてるのはsymfony2.7での名残ですね。

@okazy
Copy link
Contributor

okazy commented Jul 7, 2020

ありがとうございます、了解しました。
確かにあんまり使うところないなと思いながら書いていました。

@okazy
Copy link
Contributor

okazy commented Jul 21, 2020

ルーティングの命名規則はフロント画面と管理画面で分けた方がいいとおもいます。
管理画面は admin をさらに前につけるほうがいいのではないでしょうか?

フロント画面

[プラグインコードのスネークケース]_xxx

class PageController extends AbstractController
{
    /**
     * @Route("/acme_category_content/page", name="acme_category_content_page")
     * @Template("@AcmeCategoryContent/page.twig")
     */
    public function index(Request $request)

管理画面

admin_[プラグインコードのスネークケース]_xxx

class ConfigController extends AbstractController
{
    /**
     * @Route("/%eccube_admin_route%/acme_category_content/config", name="admin_acme_category_content_config")
     * @Template("@AcmeCategoryContent/admin/config.twig")
     */
    public function index(Request $request)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants