Skip to content

Instantly share code, notes, and snippets.

View bakura10's full-sized avatar

Michaël Gallego bakura10

View GitHub Profile
@bakura10
bakura10 / gist:3131459
Created July 17, 2012 19:30
Common\Authentication\Storage\Db
<?php
namespace Common\Authentication\Storage;
use Doctrine\Common\Persistence\ObjectRepository;
use Zend\Authentication\Storage\StorageInterface;
/**
* This class implements StorageInterface and allow to save the result of an authentication against a database
*/
public function indexAction()
{
$filters = $this->request->getQuery();
// Activate the filter, giving it filters values
$students = $this->getStudentService()->getAll();
return array(
'students' => $students->setCurrentPageNumber(1)
// In controller :
/**
* Show all the students
*
* @return array
*/
public function indexAction()
{
$studentService = $this->getStudentService();
$this->add(array(
'type' => 'Zend\Form\Element\Collection',
'name' => 'properties',
'options' => array(
'label' => 'Please choose properties for this Asset',
'count' => 2,
'should_create_template' => true,
'allow_add' => true,
'target_element' => array(
'type' => 'DoctrineORMModule\Form\Element\DoctrineEntity',
$this->metadata->expects($this->exactly(2))
->method('hasAssociation')
->with($this->equalTo('country'))
->will($this->returnValue(true));
@bakura10
bakura10 / gist:3171588
Created July 24, 2012 18:12
Authentication factory
<?php
namespace Common\Authentication\Service;
use DoctrineModule\Authentication\Adapter\ObjectRepository as DoctrineAdapter;
use DoctrineModule\Authentication\Storage\ObjectRepository as DoctrineStorage;
use DoctrineModule\Options\Authentication as AuthenticationOptions;
use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Storage\Session as SessionStorage;
use Zend\ServiceManager\FactoryInterface;
@bakura10
bakura10 / gist:3175711
Created July 25, 2012 11:46
Authentication Factory
<?php
namespace Common\Authentication\Service;
use DoctrineModule\Authentication\Adapter\ObjectRepository as DoctrineAdapter;
use DoctrineModule\Authentication\Storage\ObjectRepository as DoctrineStorage;
use DoctrineModule\Options\Authentication as AuthenticationOptions;
use Zend\Authentication\AuthenticationService;
use Zend\Authentication\Storage\Session as SessionStorage;
use Zend\ServiceManager\FactoryInterface;
<?php
namespace Common\Service;
use Doctrine\ORM\EntityManager;
use Zend\Authentication\AuthenticationService;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\ServiceManagerAwareInterface;
/**
* @param Message $message
* @return Thread
*/
public function addMessage(Message $message)
{
if ($this->status === self::OPENED) {
foreach ($this->participants as $participant) {
if ($participant->getUser() === $message->getAuthor()) {
$participant->setFirstNotReadMessage(null);
class Thread extends AbstractService
{
/**
* @param ThreadEntity $thread
*/
public function create(ThreadEntity $thread)
{
// I'm in a module, it does not have idea of what the specific application needs... but in my application, I need to add // another specific participant...
$user = $this->getAuthenticationService()->getIdentity();
$thread->addParticipant($user);