Skip to content

Commit

Permalink
Added PeepForm view helper
Browse files Browse the repository at this point in the history
- Checks for authenticated user before displaying form
  • Loading branch information
weierophinney committed Jun 1, 2012
1 parent fca61a5 commit 942a301
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config/module.config.php
Expand Up @@ -66,8 +66,9 @@
),
'service_manager' => array(
'factories' => array(
'phly-peep-table' => 'PhlyPeep\Service\PeepTableFactory',
'peepform' => 'PhlyPeep\Service\PeepViewFormFactory',
'phly-peep-service' => 'PhlyPeep\Service\PeepServiceFactory',
'phly-peep-table' => 'PhlyPeep\Service\PeepTableFactory',
),
),
);
18 changes: 18 additions & 0 deletions src/PhlyPeep/Service/PeepViewFormFactory.php
@@ -0,0 +1,18 @@
<?php

namespace PhlyPeep\Service;

use PhlyPeep\View\PeepForm;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class PeepViewFormFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $services)
{
$authService = $services->get('zfcuser_auth_service');
$helper = new PeepForm();
$helper->setAuthService($authService);
return $helper;
}
}
24 changes: 24 additions & 0 deletions src/PhlyPeep/View/PeepForm.phtml
@@ -0,0 +1,24 @@
<?php

namespace PhlyPeep\View;

use Zend\View\Helper\AbstractHelper;

class PeepForm extends AbstractHelper
{
protected $auth;

public function setAuthService(AuthenticationService $auth)
{
$this->auth = $auth;
}

public function __invoke($form, $template = 'phly-peep/peep/form')
{
if (!$this->auth || $this->auth->hasIdentity()) {
return '';
}

return $this->view->render($template, array('form' => $form));
}
}

0 comments on commit 942a301

Please sign in to comment.