Skip to content

Commit

Permalink
Update interface for now
Browse files Browse the repository at this point in the history
  • Loading branch information
josegonzalez committed May 17, 2015
1 parent afb4ab4 commit 4f0464c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
5 changes: 2 additions & 3 deletions config/bootstrap_cli.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
use Cake\Event\Event;
use Cake\Event\EventManager;
use Josegonzalez\Version\Event\Bake\TableEvent;
use Josegonzalez\Version\Event\VersionListener;

EventManager::instance()->attach(function (Event $event) {
$tableEvent = new TableEvent($event);
$tableEvent();
(new VersionListener($event))->execute();
}, 'Bake.beforeRender');
6 changes: 3 additions & 3 deletions src/Event/Bake/Event.php → src/Event/EventListener.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
namespace Josegonzalez\Version\Event\Bake;
namespace Josegonzalez\Version\Event;

use Cake\Event\Event as CakeEvent;
use Cake\Event\EventListenerInterface;
use Cake\Event\EventManagerTrait;

abstract class Event implements EventListenerInterface
abstract class EventListener implements EventListenerInterface
{
use EventManagerTrait;

Expand All @@ -32,7 +32,7 @@ public function __construct(CakeEvent $event)
*
* @return void
*/
public function __invoke()
public function execute()
{
$methods = array_values($this->implementedEvents());
foreach ($methods as $method) {
Expand Down
20 changes: 10 additions & 10 deletions src/Event/Bake/TableEvent.php → src/Event/VersionListener.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php
namespace Josegonzalez\Version\Event\Bake;
namespace Josegonzalez\Version\Event;

use Cake\Datasource\ConnectionManager;
use Cake\Event\Event as CakeEvent;
use Cake\Event\Event;
use Cake\ORM\TableRegistry;
use Cake\Utility\Hash;

class TableEvent extends Event
class VersionListener extends EventListener
{
/**
* Called before the entity template is rendered
*
* @param Event $event An Event instance
* @return void
*/
public function beforeRenderEntity(CakeEvent $event)
public function beforeRenderEntity(Event $event)
{
$this->_checkAssociation($event, 'versions');
}
Expand All @@ -25,7 +25,7 @@ public function beforeRenderEntity(CakeEvent $event)
* @param Event $event An Event instance
* @return void
*/
public function beforeRenderTestCase(CakeEvent $event)
public function beforeRenderTestCase(Event $event)
{
$name = $event->subject->viewVars['subject'];
$pattern = '/^' . preg_quote($name) . '_(\w+)_version$/';
Expand All @@ -42,7 +42,7 @@ public function beforeRenderTestCase(CakeEvent $event)
* @param Event $event An Event instance
* @return void
*/
public function beforeRenderTable(CakeEvent $event)
public function beforeRenderTable(Event $event)
{
$this->_checkAssociation($event, 'versions');
$this->_fixVersionTables($event);
Expand All @@ -54,7 +54,7 @@ public function beforeRenderTable(CakeEvent $event)
* @param Event $event An Event instance
* @return void
*/
protected function _fixVersionTables(CakeEvent $event)
protected function _fixVersionTables(Event $event)
{
if (!preg_match('/Versions$/', $event->subject->viewVars['name'])) {
return;
Expand All @@ -75,7 +75,7 @@ protected function _fixVersionTables(CakeEvent $event)
* @param string $tableSuffix a suffix for the primary table
* @return boolean true if modified, false otherwise
*/
protected function _checkAssociation(CakeEvent $event, $tableSuffix)
protected function _checkAssociation(Event $event, $tableSuffix)
{
$subject = $event->subject;
$connection = ConnectionManager::get($subject->viewVars['connection']);
Expand All @@ -102,7 +102,7 @@ protected function _checkAssociation(CakeEvent $event, $tableSuffix)
* @param Event $event An Event instance
* @return array
*/
protected function _modifyBelongsTo(CakeEvent $event)
protected function _modifyBelongsTo(Event $event)
{
$belongsTo = $event->subject->viewVars['associations']['belongsTo'];

Expand All @@ -122,7 +122,7 @@ protected function _modifyBelongsTo(CakeEvent $event)
* @param Event $event An Event instance
* @return array
*/
protected function _modifyRulesChecker(CakeEvent $event)
protected function _modifyRulesChecker(Event $event)
{
$rulesChecker = $event->subject->viewVars['rulesChecker'];

Expand Down

0 comments on commit 4f0464c

Please sign in to comment.