Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05c0923
commit 65afe15
Showing
6 changed files
with
190 additions
and
18 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,96 @@ | ||
<?php | ||
/** | ||
* Phanbook : Delightfully simple forum software | ||
* | ||
* Licensed under The GNU License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @link http://phanbook.com Phanbook Project | ||
* @since 1.0.0 | ||
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt | ||
*/ | ||
namespace Phanbook\Common; | ||
|
||
use Phalcon\DiInterface; | ||
use Phalcon\Events\Manager; | ||
use Phalcon\Events\ManagerInterface; | ||
|
||
/** | ||
* \Phanbook\Common\Module | ||
* | ||
* @package Phanbook\Common | ||
*/ | ||
abstract class Module implements ModuleInterface | ||
{ | ||
/** | ||
* @var DiInterface | ||
*/ | ||
protected $di; | ||
|
||
/** | ||
* @var Manager | ||
*/ | ||
protected $eventsManager; | ||
|
||
/** | ||
* Module constructor. | ||
* | ||
* @param DiInterface $di | ||
* @param Manager|null $manager | ||
*/ | ||
public function __construct(DiInterface $di = null, Manager $manager = null) | ||
{ | ||
$this->di = $di ?: container(); | ||
$this->eventsManager = $manager; | ||
} | ||
|
||
/** | ||
* Initialize module. | ||
*/ | ||
public function initialize() | ||
{ | ||
$this->registerAutoloaders($this->di); | ||
$this->registerServices($this->di); | ||
} | ||
|
||
/** | ||
* Returns the internal event manager. | ||
* | ||
* @return ManagerInterface | ||
*/ | ||
public function getEventsManager() | ||
{ | ||
$eventsManager = $this->eventsManager; | ||
|
||
if ($eventsManager instanceof ManagerInterface) { | ||
return $eventsManager; | ||
} | ||
|
||
if ($this->di->has('eventsManager')) { | ||
$eventsManager = $this->di->getShared('eventsManager'); | ||
} else { | ||
$eventsManager = new Manager(); | ||
$eventsManager->enablePriorities(true); | ||
|
||
$this->di->setShared('eventsManager', $eventsManager); | ||
} | ||
|
||
$this->setEventsManager($eventsManager); | ||
|
||
return $eventsManager; | ||
} | ||
|
||
/** | ||
* Sets the events manager. | ||
* | ||
* @param ManagerInterface $eventsManager | ||
* @return $this | ||
*/ | ||
public function setEventsManager(ManagerInterface $eventsManager) | ||
{ | ||
$this->eventsManager = $eventsManager; | ||
|
||
return $this; | ||
} | ||
} |
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,36 @@ | ||
<?php | ||
/** | ||
* Phanbook : Delightfully simple forum software | ||
* | ||
* Licensed under The GNU License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @link http://phanbook.com Phanbook Project | ||
* @since 1.0.0 | ||
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt | ||
*/ | ||
namespace Phanbook\Common; | ||
|
||
use Phalcon\Events\EventsAwareInterface; | ||
use Phalcon\Mvc\ModuleDefinitionInterface; | ||
|
||
/** | ||
* \Phanbook\Common\ModuleInterface | ||
* | ||
* @package Phanbook\Common | ||
*/ | ||
interface ModuleInterface extends ModuleDefinitionInterface, EventsAwareInterface | ||
{ | ||
/** | ||
* Initialize the module. | ||
*/ | ||
public function initialize(); | ||
|
||
/** | ||
* Gets controllers/tasks namespace. | ||
* | ||
* @return string | ||
*/ | ||
public function getHandlersNamespace(); | ||
} |
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
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
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
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