Skip to content

Commit

Permalink
Add demo application + custom extension example
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlundrigan committed Jun 27, 2014
1 parent 1034fbc commit 83321b7
Show file tree
Hide file tree
Showing 13 changed files with 550 additions and 0 deletions.
1 change: 1 addition & 0 deletions demo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ZendSkeletonApplication
39 changes: 39 additions & 0 deletions demo/ExtensionModule/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* LdcUserProfile
*
* @link http://github.com/adamlundrigan/LdcUserProfile for the canonical source repository
* @copyright Copyright (c) 2014 Adam Lundrigan & Contributors
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ExtensionModule;

use Zend\ModuleManager\Feature\AutoloaderProviderInterface;

class Module implements AutoloaderProviderInterface
{
public function onBootstrap(\Zend\Mvc\MvcEvent $e)
{
$sm = $e->getApplication()->getServiceManager();
$sm->get('ldc-user-profile_service')->registerExtension(
$sm->get('extension-module_extension')
);
}

public function getAutoloaderConfig()
{
return array(
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . str_replace('\\', '/' , __NAMESPACE__),
),
),
);
}

public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}
}
21 changes: 21 additions & 0 deletions demo/ExtensionModule/config/module.config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* LdcUserProfile
*
* @link http://github.com/adamlundrigan/LdcUserProfile for the canonical source repository
* @copyright Copyright (c) 2014 Adam Lundrigan & Contributors
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

return array(
'service_manager' => array(
'factories' => array(
'extension-module_extension' => 'ExtensionModule\ExtensionFactory',
),
),
'view_manager' => array(
'template_path_stack' => array(
'ExtensionModule' => __DIR__ . '/../view',
),
),
);
53 changes: 53 additions & 0 deletions demo/ExtensionModule/src/ExtensionModule/Extension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* LdcUserProfile
*
* @link http://github.com/adamlundrigan/LdcUserProfile for the canonical source repository
* @copyright Copyright (c) 2014 Adam Lundrigan & Contributors
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ExtensionModule;

use LdcUserProfile\Extensions\AbstractExtension;

class Extension extends AbstractExtension
{

public function getName()
{
return 'modext';
}

public function getObjectForUser(\ZfcUser\Entity\UserInterface $user)
{
if ( ! $this->getSession()->offsetExists("U{$user->getId()}") ) {
return new \stdClass();
}
return $this->getSession()->offsetGet("U{$user->getId()}");
}

public function save($entity)
{
if ( !isset($entity->modext) ) {
return false;
}
$this->getSession()->offsetSet("U{$entity->zfcuser->getId()}", $entity->modext);
return true;
}

public function getSession()
{
if ( is_null($this->session) ) {
$this->setSession(new \Zend\Session\Container('ExtensionModule'));
}
return $this->session;
}

public function setSession(\Zend\Session\Container $c)
{
$this->session = $c;
return $this;
}

}
32 changes: 32 additions & 0 deletions demo/ExtensionModule/src/ExtensionModule/ExtensionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* LdcUserProfile
*
* @link http://github.com/adamlundrigan/LdcUserProfile for the canonical source repository
* @copyright Copyright (c) 2014 Adam Lundrigan & Contributors
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ExtensionModule;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class ExtensionFactory implements FactoryInterface
{
/**
* {@inheritDoc}
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
$service = new Extension();
$service->setFieldset(new Pieces\ExtensionFieldset());
$service->setInputFilter(new Pieces\ExtensionInputFilter());

$service->getFieldset()
->setHydrator(new \Zend\Stdlib\Hydrator\ObjectProperty())
->setObject(new \stdClass());

return $service;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* LdcUserProfile
*
* @link http://github.com/adamlundrigan/LdcUserProfile for the canonical source repository
* @copyright Copyright (c) 2014 Adam Lundrigan & Contributors
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ExtensionModule\Pieces;

use Zend\Form\Fieldset;

class ExtensionFieldset extends Fieldset
{
public function __construct()
{
parent::__construct('modext');

$this->add(array(
'name' => 'twitter',
'type' => 'Text',
'options' => array(
'label' => 'Twitter'
)
));

$this->add(array(
'name' => 'github',
'type' => 'Text',
'options' => array(
'label' => 'GitHub'
)
));

$this->add(array(
'name' => 'homepage',
'type' => 'Url',
'options' => array(
'label' => 'Homepage'
)
));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* LdcUserProfile
*
* @link http://github.com/adamlundrigan/LdcUserProfile for the canonical source repository
* @copyright Copyright (c) 2014 Adam Lundrigan & Contributors
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ExtensionModule\Pieces;

use Zend\InputFilter\InputFilter;

class ExtensionInputFilter extends InputFilter
{
public function __construct()
{
$this->add(array(
'name' => 'twitter',
'required' => true,
'filters' => array(array('name' => 'StringTrim')),
'validators' => array(array('name' => 'Alnum')),
));

$this->add(array(
'name' => 'github',
'required' => true,
'filters' => array(array('name' => 'StringTrim')),
'validators' => array(array('name' => 'Alnum')),
));

$this->add(array(
'name' => 'homepage',
'required' => false,
'filters' => array(array('name' => 'StringTrim')),
'validators' => array(array('name' => 'Uri')),
));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<br />
<div class="panel panel-default">
<div class="panel-heading">Example Profile Extension</div>
<div class="panel-body">

<?php foreach ($fieldset as $element): ?>
<?php if (!$element instanceof Zend\Form\Element\Button && !$element instanceof Zend\Form\Element\Hidden): ?>
<dt><?php echo $this->formLabel($element) ?></dt>
<?php endif ?>
<?php if ($element instanceof Zend\Form\Element\Button): ?>
<dd><?php echo $this->formButton($element) ?></dd>
<?php elseif ($element instanceof Zend\Form\Element\Captcha): ?>
<dd><?php echo $this->formCaptcha($element) . $this->formElementErrors($element) ?></dd>
<?php else: ?>
<dd><?php echo $this->formInput($element) . $this->formElementErrors($element) ?></dd>
<?php endif ?>
<?php endforeach ?>

</div>
</div>
5 changes: 5 additions & 0 deletions demo/ExtensionModule/view/zfc-user/user/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div style="float:left; padding-right:16px;"><?php echo $this->gravatar($this->zfcUserIdentity()->getEmail()) ?></div>
<h3><?php echo $this->translate('Hello'); ?>, <?php echo $this->zfcUserDisplayName() ?>!</h3>
<a href="<?php echo $this->url('ldc-user-profile') ?>">[<?php echo $this->translate('Update Profile'); ?>]</a>&nbsp;
<a href="<?php echo $this->url('zfcuser/logout') ?>">[<?php echo $this->translate('Sign Out'); ?>]</a>
<div style="clear:both;"></div>
19 changes: 19 additions & 0 deletions demo/files/application.config.php.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
return array(
'modules' => array(
'Application',
'ZfcBase',
'ZfcUser',
'LdcUserProfile',
'ExtensionModule',
),
'module_listener_options' => array(
'module_paths' => array(
'./module',
'./vendor',
),
'config_glob_paths' => array(
'config/autoload/{,*.}{global,local}.php'
)
)
);
12 changes: 12 additions & 0 deletions demo/files/database.local.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
return array(
'db' => array(
'driver' => 'Pdo_Sqlite',
'database' => getcwd().'/data/users.db',
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
);
Loading

0 comments on commit 83321b7

Please sign in to comment.