heavenproject / user-command-line
通过命令行使用 Symfony Console 和 Doctrine ORM 管理用户
v1.1.0
2017-03-09 22:07 UTC
Requires
- heavenproject/utils: ^1.0
- kdyby/console: ^2.4
- kdyby/doctrine: ^2.3 | ^3.0
- nette/di: ^2.3
- tracy/tracy: ^2.3
Requires (Dev)
- kdyby/annotations: ^2.2
- kdyby/events: ^2.4 | ^3.0
- mockery/mockery: ~0.9.0
- nette/bootstrap: ^2.3
- nette/tester: *
This package is not auto-updated.
Last update: 2024-09-15 00:52:52 UTC
README
通过命令行使用 Symfony Console 和 Doctrine ORM 管理用户。
安装
composer require heavenproject/user-command-line
要求
文档
为了使 hproj:create-user
(或作为别名 hproj:create:user
)命令正确运行,您需要在应用程序代码中进行一些小的更新。
因为我们在这里处理用户,所以您的应用程序中必须有某个用户实体。此实体必须实现 UserEntityInterface
。就是这样。
您有很多选择来实现这一点。如果需要一些自定义逻辑,您可以直接实现整个接口,但此库包含一些代码片段,其中包括 UserMethods
和 UserProperties
,这两个都组合在一个单一的 UserTrait
中。这些可能会帮助您实现。
如果您需要有关如何使用上述命令的更多信息,请使用您在命令行中习惯的 Symfony Console(在 Nette 中是 php www/index.php
),并输入 help hproj:create-user
(例如:php www/index.php help hproj:create-user
)。
示例 1
namespace App\Model\Entities;
use Doctrine\ORM\Mapping as ORM;
use HeavenProject\UserCommandLine\UserTrait;
use HeavenProject\UserCommandLine\UserEntityInterface;
/**
* @ORM\Entity
* @ORM\Table(name="`user`")
*/
class UserEntity implements UserEntityInterface
{
use UserTrait;
}
示例 2
namespace App\Model\Entities;
use Doctrine\ORM\Mapping as ORM;
use HeavenProject\UserCommandLine\UserMethods;
use HeavenProject\UserCommandLine\UserEntityInterface;
/**
* @ORM\Entity
* @ORM\Table(name="`user`")
*/
class UserEntity implements UserEntityInterface
{
use UserMethods;
// Your properties
}
示例 3
namespace App\Model\Entities;
use Doctrine\ORM\Mapping as ORM;
use HeavenProject\UserCommandLine\UserProperties;
use HeavenProject\UserCommandLine\UserEntityInterface;
/**
* @ORM\Entity
* @ORM\Table(name="`user`")
*/
class UserEntity implements UserEntityInterface
{
use UserProperties;
// Your methods
}
示例 4
namespace App\Model\Entities;
use Doctrine\ORM\Mapping as ORM;
use HeavenProject\UserCommandLine\UserEntityInterface;
/**
* @ORM\Entity
* @ORM\Table(name="`user`")
*/
class UserEntity implements UserEntityInterface
{
// Your entire own implementation of properties and methods
}
当然,如果您愿意,可以在实体中添加更多属性和方法。
配置
在您的应用程序 neon 配置中注册 UserCommandLineExtension
,并向此扩展提供 targetEntity
,即您的更新后的用户实体(类名及其命名空间)。
extensions:
userCommandLine: HeavenProject\UserCommandLine\UserCommandLineExtension
userCommandLine:
targetEntity: App\Model\Entities\UserEntity