, (*1)
, (*2)
LatchBundle
Easy integration of Latch in your symfony2 project.
You can visit the official website: http://fourcoders.github.io/LatchBundle/, (*3)
Prerequisites
Translations
If you wish to use default texts provided in this bundle, you have to make
sure you have translator enabled in your config., (*4)
``` yaml, (*5)
app/config/config.yml
framework:
translator: ~, (*6)
For more information about translations, check [Symfony documentation](http://symfony.com/doc/current/book/translation.html).
## Installation
1. [Download LatchBundle using composer](#step-1-download-latchbundle-using-composer)
2. [Enable the Bundle](#step-2-enable-the-bundle)
3. [Update your User class](#step-3-update-your-user-class)
4. [Configure the LatchBundle](#step-4-configure-the-latchbundle)
5. [Import LatchBundle routing](#step-5-import-latchbundle-routing-files)
6. [Update your database schema](#step-6-update-your-database-schema)
7. [Setup your latch operations](#step-7-setup-your-latch-operations)
### Step 1: Download LatchBundle using composer
Add LatchBundle in your composer.json.
First option:
You can install the official [Latch PHP SDK by ElevenPaths](https://github.com/ElevenPaths/latch-sdk-php).
[Composer can not load repositories recursively](https://getcomposer.org/doc/faqs/why-can%27t-composer-load-repositories-recursively.md) .You need to add this dependency in your composer.json or You can manage it by satis or toran proxy.
```js
{
"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"
}
}
After install libraries, You must put eleven_paths as a your latch_driver in your config.yml:, (*7)
``` yaml, (*8)
app/config/config.yml
fourcoders_latch:
latch_app_id: PdHF10WnSDasSINHHZd0n
latch_app_secret: kH1oqtVlWyWZLKQWIJCAKLodd4XUIgMMLQiwag
latch_driver: eleven_paths
latch_redirect: /
latch_operations: ~, (*9)
Second Option:
You can install unofficial [fourcoders/latch-sdk-php](https://github.com/fourcoders/latch-sdk-php). Its very similar to the official Latch PHP SDK by ElevenPaths , however we use composer for managing the dependencies and Guzzle for the HTTP Request.
```js
{
"require": {
"fourcoders/latch-sdk-php": "dev-master",
"fourcoders/latch-bundle": "dev-master"
}
}
After install libraries, You must put fourcorders as a your latch_driver in your config.yml:, (*10)
``` yaml, (*11)
app/config/config.yml
fourcoders_latch:
latch_app_id: PdHF10WnSDasSINHHZd0n
latch_app_secret: kH1oqtVlWyWZLKQWIJCAKLodd4XUIgMMLQiwag
latch_driver: fourcoders
latch_redirect: /
latch_operations: ~, (*12)
### Step 2: Enable the bundle
Enable the bundle in the kernel:
``` php
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new Fourcoders\Bundle\LatchBundle\FourcodersLatchBundle(),
);
}
Step 3: Update your User class
Insert a new field in the User entity, or whatever you are using with your security provider., (*13)
If you are using FOSUserBundle this a example:, (*14)
``` php
<?php
// src/Acme/UserBundle/Entity/User.php
namespace Acme\UserBundle\Entity;, (*15)
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;, (*16)
/**
* @ORM\Entity
* @ORM\Table(name="user")
*/
class User extends BaseUser
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;, (*17)
/* 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
}
}, (*18)
For a stardard register, check [Symfony documentation](http://symfony.com/doc/current/cookbook/doctrine/registration_form.html), after you can override the User.php.
``` 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 */
}
How to setup latch_driver, (*19)
``` yaml, (*20)
app/config/config.yml
fourcoders_latch:
latch_app_id: PdHF10WnSDasSINHHZd0n
latch_app_secret: kH1oqtVlWyWZLKQWIJCAKLodd4XUIgMMLQiwag
latch_driver: eleven_paths
latch_redirect: /
latch_operations: ~, (*21)
### Step 5: Import LatchBundle routing files
``` yaml
# app/config/routing.yml
fourcoders_latch:
resource: "@FourcodersLatchBundle/Resources/config/routing.yml"
prefix: /
Step 6: Update your database schema
For ORM run the following command., (*22)
``` bash
$ php app/console doctrine:schema:update --force, (*23)
### Step 7: Setup your latch operations
You can securize any http resource with your Latch operations.
Begin the setup process of your operations with your operation name and pattern in the config.yml
``` yaml
# 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"
Finally your operations must be defined in the access control params:, (*24)
``` yaml, (*25)
app/config/security.yml
access_control:
- { path: ^/transfer$, role: ROLE_USER }
- { path: ^/profile$, role: ROLE_USER }
```, (*26)
Now that you have completed the basic installation and configuration of the
LatchBundle, you are ready to learn about more advanced features and usages
of the bundle., (*27)
The following documents are available:, (*28)