fourcoders / latch-bundle
Easy integration of Latch in your symfony2 project.
Installs: 240
Dependents: 0
Suggesters: 0
Security: 0
Stars: 10
Watchers: 6
Forks: 0
Open Issues: 0
Type:symfony-bundle
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-12-11 04:39:20 UTC
README
LatchBundle
Easy integration of Latch in your symfony2 project. You can visit the official website: http://fourcoders.github.io/LatchBundle/
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.
# app/config/config.yml framework: translator: ~
For more information about translations, check Symfony documentation.
Installation
- Download LatchBundle using composer
- Enable the Bundle
- Update your User class
- Configure the LatchBundle
- Import LatchBundle routing
- Update your database schema
- 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. Composer can not load repositories recursively .You need to add this dependency in your composer.json or You can manage it by satis or toran proxy.
{ "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:
# app/config/config.yml fourcoders_latch: latch_app_id: PdHF10WnSDasSINHHZd0n latch_app_secret: kH1oqtVlWyWZLKQWIJCAKLodd4XUIgMMLQiwag latch_driver: eleven_paths latch_redirect: / latch_operations: ~
Second Option: You can install unofficial 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.
{ "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:
# app/config/config.yml fourcoders_latch: latch_app_id: PdHF10WnSDasSINHHZd0n latch_app_secret: kH1oqtVlWyWZLKQWIJCAKLodd4XUIgMMLQiwag latch_driver: fourcoders latch_redirect: / latch_operations: ~
Step 2: Enable the bundle
Enable the bundle in the kernel:
<?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.
If you are using FOSUserBundle this a example:
<?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 } }
For a stardard register, check Symfony documentation, after you can override the 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 */ }
Step 4: Configure the LatchBundle
How to setup latch_driver
# app/config/config.yml fourcoders_latch: latch_app_id: PdHF10WnSDasSINHHZd0n latch_app_secret: kH1oqtVlWyWZLKQWIJCAKLodd4XUIgMMLQiwag latch_driver: eleven_paths latch_redirect: / latch_operations: ~
Step 5: Import LatchBundle routing files
# 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.
$ php app/console doctrine:schema:update --force
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
# 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:
# app/config/security.yml access_control: - { path: ^/transfer$, role: ROLE_USER } - { path: ^/profile$, role: ROLE_USER }
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.
The following documents are available: