-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add demo application + custom extension example
- Loading branch information
1 parent
1034fbc
commit 83321b7
Showing
13 changed files
with
550 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ZendSkeletonApplication |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
), | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
32
demo/ExtensionModule/src/ExtensionModule/ExtensionFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
demo/ExtensionModule/src/ExtensionModule/Pieces/ExtensionFieldset.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
) | ||
)); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
demo/ExtensionModule/src/ExtensionModule/Pieces/ExtensionInputFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')), | ||
)); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
demo/ExtensionModule/view/ldc-user-profile/profile/extension/modext.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
<a href="<?php echo $this->url('zfcuser/logout') ?>">[<?php echo $this->translate('Sign Out'); ?>]</a> | ||
<div style="clear:both;"></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
) | ||
) | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
), | ||
), | ||
); |
Oops, something went wrong.