pggns/cakephp-cleaner-bake

CakePHP 插件,添加一些清理 Bake 模板

安装: 89

依赖项: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

语言:Twig

类型:cakephp-plugin

1.7.0 2024-01-26 21:02 UTC

This package is auto-updated.

Last update: 2024-09-26 22:32:42 UTC


README

安装

您可以使用 composer 将此插件安装到您的 CakePHP 应用程序中。

安装 composer 包的推荐方式是

composer require --dev pggns/cakephp-cleaner-bake

然后将以下行添加到 src/Application.php

$this->addPlugin('Pggns/CleanerBake');

如何使用这些模板?

要自动在每次 bake 命令中使用模板,请将以下行添加到您的 config/bootstrap.php

Configure::write('Bake.theme', 'Pggns/CleanerBake');

要在某些 bake 命令中手动使用它们,只需添加 --theme Pggns/CleanerBake

这些模板有哪些改变?

这些模板在功能上不会改变输出,只是进行了一些外观上的改变

  • 将 4 个空格替换为制表符
  • 将开括号 { 移到行尾
  • 对齐数组
  • 添加一些新行以使文件更有组织
  • 一些其他小改动

之前

<?php
declare(strict_types=1);

namespace App\Model\Entity;

use Cake\ORM\Entity;

/**
 * User Entity
 *
 * @property int $id
 * @property string $username
 * @property string $mail
 * @property string $password
 * @property string $register_status
 * @property string|null $register_hash
 * @property \Cake\I18n\FrozenTime|null $register_datetime
 * @property string|null $reset_password_hash
 * @property \Cake\I18n\FrozenTime|null $reset_password_datetime
 * @property \Cake\I18n\FrozenTime $created
 * @property \Cake\I18n\FrozenTime $modified
 *
 * @property \App\Model\Entity\SpotifyUser $spotify_user
 * @property \App\Model\Entity\TwitchUser $twitch_user
 */
class User extends Entity
{
    /**
     * Fields that can be mass assigned using newEntity() or patchEntity().
     *
     * Note that when '*' is set to true, this allows all unspecified fields to
     * be mass assigned. For security purposes, it is advised to set '*' to false
     * (or remove it), and explicitly make individual fields accessible as needed.
     *
     * @var array
     */
    protected $_accessible = [
        'username' => true,
        'mail' => true,
        'password' => true,
        'register_status' => true,
        'register_hash' => true,
        'register_datetime' => true,
        'reset_password_hash' => true,
        'reset_password_datetime' => true,
        'created' => true,
        'modified' => true,
        'spotify_user' => true,
        'twitch_user' => true,
    ];

    /**
     * Fields that are excluded from JSON versions of the entity.
     *
     * @var array
     */
    protected $_hidden = [
        'password',
    ];
}

之后

<?php
declare(strict_types=1);

namespace App\Model\Entity;

use Cake\ORM\Entity;

/**
 * User Entity
 *
 * @property int $id
 * @property string $username
 * @property string $mail
 * @property string $password
 * @property string $register_status
 * @property string|null $register_hash
 * @property \Cake\I18n\FrozenTime|null $register_datetime
 * @property string|null $reset_password_hash
 * @property \Cake\I18n\FrozenTime|null $reset_password_datetime
 * @property \Cake\I18n\FrozenTime $created
 * @property \Cake\I18n\FrozenTime $modified
 *
 * @property \App\Model\Entity\SpotifyUser $spotify_user
 * @property \App\Model\Entity\TwitchUser $twitch_user
 */
class User extends Entity {
    /**
     * Fields that can be mass assigned using newEntity() or patchEntity().
     *
     * Note that when '*' is set to true, this allows all unspecified fields to
     * be mass assigned. For security purposes, it is advised to set '*' to false
     * (or remove it), and explicitly make individual fields accessible as needed.
     *
     * @var array
     */
    protected $_accessible  =   [
        'username'                  =>  true,
        'mail'                      =>  true,
        'password'                  =>  true,
        'register_status'           =>  true,
        'register_hash'             =>  true,
        'register_datetime'         =>  true,
        'reset_password_hash'       =>  true,
        'reset_password_datetime'   =>  true,
        'created'                   =>  true,
        'modified'                  =>  true,
        'spotify_user'              =>  true,
        'twitch_user'               =>  true,
    ];
    
    /**
     * Fields that are excluded from JSON versions of the entity.
     *
     * @var array
     */
    protected $_hidden  =   [
        'password',
    ];
}