fourcoders / latch-bundle
轻松将 Latch 集成到您的 symfony2 项目中。
Requires
- php: >=5.4.0
Requires (Dev)
- doctrine/orm: v2.4.7
- elevenpaths/latch-sdk-php: dev-master
- fourcoders/latch-sdk-php: dev-master
- phpspec/phpspec: ~2.0
- symfony/form: 2.7.*@dev
- symfony/framework-bundle: >=2.0.0
- symfony/security-http: v2.6.1
- symfony/validator: v2.6.0
This package is not auto-updated.
Last update: 2024-09-18 03:44:48 UTC
README
LatchBundle
轻松将 Latch 集成到您的 symfony2 项目中。您可以访问官方网站:http://fourcoders.github.io/LatchBundle/
先决条件
翻译
如果您想使用此套餐中提供的默认文本,您必须确保在您的配置中启用了翻译器。
# app/config/config.yml framework: translator: ~
有关翻译的更多信息,请参阅 Symfony 文档。
安装
- 使用 composer 下载 LatchBundle
- 启用 Bundle
- 更新您的用户类
- 配置 LatchBundle
- 导入 LatchBundle 路由
- 更新您的数据库模式
- 设置您的 latch 操作
步骤 1:使用 composer 下载 LatchBundle
在您的 composer.json 中添加 LatchBundle。
第一种选择:您可以安装 ElevenPaths 的官方 Latch PHP SDK。 Composer 不能递归地加载存储库。您需要在您的 composer.json 中添加此依赖项,或者您可以通过 satis 或 toran 代理来管理它。
{ "repositories": [ { "type": "package", "package": { "name": "elevenpaths/latch-sdk-php", "version": "dev-master", "source": { "url": "https://github.com/ElevenPaths/latch-sdk-php.git", "type": "git", "reference": "origin/master" }, "autoload": { "classmap": ["/"] } } } ], "require": { "elevenPaths/latch-sdk-php": "dev-master", "fourcoders/latch-bundle": "dev-master" } }
安装库后,您必须将 eleven_paths 作为您的 latch_driver 放在您的 config.yml 中
# app/config/config.yml fourcoders_latch: latch_app_id: PdHF10WnSDasSINHHZd0n latch_app_secret: kH1oqtVlWyWZLKQWIJCAKLodd4XUIgMMLQiwag latch_driver: eleven_paths latch_redirect: / latch_operations: ~
第二种选择:您可以安装非官方的 fourcoders/latch-sdk-php。它与 ElevenPaths 的官方 Latch PHP SDK 非常相似,但我们使用 composer 来管理依赖项,并使用 Guzzle 来执行 HTTP 请求。
{ "require": { "fourcoders/latch-sdk-php": "dev-master", "fourcoders/latch-bundle": "dev-master" } }
安装库后,您必须将 fourcorders 作为您的 latch_driver 放在您的 config.yml 中
# app/config/config.yml fourcoders_latch: latch_app_id: PdHF10WnSDasSINHHZd0n latch_app_secret: kH1oqtVlWyWZLKQWIJCAKLodd4XUIgMMLQiwag latch_driver: fourcoders latch_redirect: / latch_operations: ~
步骤 2:启用 Bundle
在 kernel 中启用 Bundle
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new Fourcoders\Bundle\LatchBundle\FourcodersLatchBundle(), ); }
步骤 3:更新您的用户类
在用户实体中插入一个新字段,或使用您与安全提供者一起使用的任何内容。
如果您正在使用 FOSUserBundle,这是一个示例
<?php // src/Acme/UserBundle/Entity/User.php namespace Acme\UserBundle\Entity; use FOS\UserBundle\Model\User as BaseUser; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @ORM\Table(name="user") */ class User extends BaseUser { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /* Start of the new field */ /** * @var string $latch * * @ORM\Column(name="latch", type="string", length=255, nullable=true) */ private $latch; /** * Set latch * * @param string $latch */ public function setLatch($latch) { $this->latch = $latch; } /** * Get latch * * @return string */ public function getlatch() { return $this->latch; } /* End of the new field */ public function __construct() { parent::__construct(); // your own logic } }
对于标准的注册,请参阅 Symfony 文档,之后您可以覆盖 User.php。
<?php // src/Acme/AccountBundle/Entity/User.php namespace Acme\AccountBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; /** * @ORM\Entity * @UniqueEntity(fields="email", message="Email already taken") */ class User { /** * @ORM\Id * @ORM\Column(type="integer") * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * @ORM\Column(type="string", length=255) * @Assert\NotBlank() * @Assert\Email() */ protected $email; /** * @ORM\Column(type="string", length=255) * @Assert\NotBlank() * @Assert\Length(max = 4096) */ protected $plainPassword; public function getId() { return $this->id; } public function getEmail() { return $this->email; } public function setEmail($email) { $this->email = $email; } public function getPlainPassword() { return $this->plainPassword; } public function setPlainPassword($password) { $this->plainPassword = $password; } /* Start of the new field */ /** * @ORM\Column(name="latch", type="string", length=255, nullable=true) */ private $latch; public function setLatch($latch) { $this->latch = $latch; } public function getlatch() { return $this->latch; } /* End of the new field */ }
步骤 4:配置 LatchBundle
如何设置 latch_driver
# app/config/config.yml fourcoders_latch: latch_app_id: PdHF10WnSDasSINHHZd0n latch_app_secret: kH1oqtVlWyWZLKQWIJCAKLodd4XUIgMMLQiwag latch_driver: eleven_paths latch_redirect: / latch_operations: ~
步骤 5:导入 LatchBundle 路由文件
# app/config/routing.yml fourcoders_latch: resource: "@FourcodersLatchBundle/Resources/config/routing.yml" prefix: /
步骤 6:更新您的数据库模式
对于 ORM,运行以下命令。
$ php app/console doctrine:schema:update --force
步骤 7:设置您的 latch 操作
您可以使用 Latch 操作来保护任何 http 资源。在 config.yml 中使用操作名称和模式开始操作设置的进程
# app/config/config.yml fourcoders_latch: latch_app_id: PdHF10WnSDasSINHHZd0n latch_app_secret: kH1oqtVlWyWZLKQWIJCAKLodd4XUIgMMLQiwag latch_driver: eleven_paths latch_redirect: / latch_operations: operation1: pattern: "/profile" latch_operation : "profile-operation" operation2: pattern: "/transfer" latch_operation: "transfer-operation"
最后,您的操作必须在访问控制参数中定义
# app/config/security.yml access_control: - { path: ^/transfer$, role: ROLE_USER } - { path: ^/profile$, role: ROLE_USER }
现在您已经完成了 LatchBundle 的基本安装和配置,您就可以了解有关该套餐的更多高级功能和用法了。
以下文档可供使用