intracto / smartcode-bundle
此包提供了一种使用Symfony生成软件许可证的方法
v1.4
2019-09-03 11:57 UTC
Requires
- php: >=7.2
- doctrine/orm: ~2.4
- symfony/framework-bundle: ~4.3
- symfony/validator: ~4.3
Requires (Dev)
- phpunit/phpunit: 4.*
README
如果你使用此包,请联系@tvlooy关于所有权。
SmartCodeBundle

此包提供了一种为给定的有效负载生成软件许可证的方法。
它受到了Sylius的Promotion Bundle的启发。
如何安装?
通过composer安装包
composer require intracto/smartcode-bundle
启用包
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
// ...
public function registerBundles()
{
$bundles = array(
// ...,
new Intracto\SmartCodeBundle\SmartCodeBundle(),
);
// ...
}
}
如何运行测试?
php bin/phpunit
如何开始?
智能代码必须绑定到有效负载,这可以通过实现PayloadInterface来完成。
use Intracto\SmartCodeBundle\Entity\PayloadInterface;
use Intracto\SmartCodeBundle\Entity\SmartCodeInterface;
class Payload implements PayloadInterface
{
...
/**
* @ORM\OneToMany(targetEntity="Intracto\SmartCodeBundle\Entity\SmartCodeInterface", mappedBy="payload")
*
* @var SmartCodes[]|ArrayCollection
*/
protected $smartCodes;
...
}
现在你可以开始生成。要生成智能代码,你可以使用SmartCodeGenerator或通过实现SmartCodeGeneratorInterface创建自己的。
此服务将允许你调用函数
public function generate(PayloadInterface $payload, SmartCodeOptions $options)
正如你所见,这有两个参数,第一个是你创建的payload,第二个是包含所有选项的模型。
class SmartCodeOptions
{
protected $amount;
protected $usageLimit;
protected $expiresAt;
protected $startsAt;
protected $batch;
...
}
- 数量:你希望为给定的payload生成的智能代码数量。
- 使用限制:智能代码可以使用的次数。
- 过期时间:智能代码的过期日期。
- 开始时间:智能代码可以开始使用的日期。
- 批次:你想要为当前生成指定的名称或描述。
你可能还想使用你刚刚生成的这些智能代码。这可以通过SmartCodeAction服务来实现,你也可以通过实现SmartCodeActionInterface来覆盖它。
此类有两个必需的函数
public function register(SubjectInterface $subject, SmartCodeInterface $smartCode);
public function unregister(SubjectInterface $subject, SmartCodeInterface $smartCode);
要注册或注销某个智能代码,你需要一个将要使用此代码的主题。为了创建这样的主题,你可以实现SubjectInterface。
use Intracto\SmartCodeBundle\Entity\SmartCodeInterface;
use Intracto\SmartCodeBundle\Entity\SubjectInterface;
class User implements SubjectInterface
{
...
/**
* @ORM\ManyToMany(targetEntity="Intracto\SmartCodeBundle\Entity\SmartCodeInterface", inversedBy="subjects")
* @ORM\JoinTable(name="user_smartcode",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="smartcode_id", referencedColumnName="id")}
* )
*
* @var SmartCode[]|ArrayCollection
*/
protected $smartCodes;
...
}