Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/41'
Browse files Browse the repository at this point in the history
Close #41
  • Loading branch information
akrabat committed Sep 22, 2015
2 parents 7901238 + 22a0c94 commit c2b54ad
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#41](https://github.com/zendframework/zend-db/pull/41) removes hard dependency
on EventManager in AbstractTableGateway.
- [#17](https://github.com/zendframework/zend-db/pull/17) removes an executable
bit on a regular file.
- [#3](https://github.com/zendframework/zend-db/pull/3) updates the code to use
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/Driver/Oci8/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Result implements Iterator, ResultInterface
* @var bool
*/
protected $currentComplete = false;

/**
* @var bool
*/
Expand Down
25 changes: 12 additions & 13 deletions src/TableGateway/AbstractTableGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Zend\Db\Sql\TableIdentifier;
use Zend\Db\Sql\Update;
use Zend\Db\Sql\Where;
use Zend\Db\TableGateway\Feature\EventFeature;
use Zend\Db\TableGateway\Feature\EventFeatureEventsInterface;

/**
*
Expand Down Expand Up @@ -95,7 +95,7 @@ public function initialize()
}

$this->featureSet->setTableGateway($this);
$this->featureSet->apply(EventFeature::EVENT_PRE_INITIALIZE, []);
$this->featureSet->apply(EventFeatureEventsInterface::EVENT_PRE_INITIALIZE, []);

if (!$this->adapter instanceof AdapterInterface) {
throw new Exception\RuntimeException('This table does not have an Adapter setup');
Expand All @@ -113,7 +113,7 @@ public function initialize()
$this->sql = new Sql($this->adapter, $this->table);
}

$this->featureSet->apply(EventFeature::EVENT_POST_INITIALIZE, []);
$this->featureSet->apply(EventFeatureEventsInterface::EVENT_POST_INITIALIZE, []);

$this->isInitialized = true;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ protected function executeSelect(Select $select)
}

// apply preSelect features
$this->featureSet->apply(EventFeature::EVENT_PRE_SELECT, [$select]);
$this->featureSet->apply(EventFeatureEventsInterface::EVENT_PRE_SELECT, [$select]);

// prepare and execute
$statement = $this->sql->prepareStatementForSqlObject($select);
Expand All @@ -242,7 +242,7 @@ protected function executeSelect(Select $select)
$resultSet->initialize($result);

// apply postSelect features
$this->featureSet->apply(EventFeature::EVENT_POST_SELECT, [$statement, $result, $resultSet]);
$this->featureSet->apply(EventFeatureEventsInterface::EVENT_POST_SELECT, [$statement, $result, $resultSet]);

return $resultSet;
}
Expand Down Expand Up @@ -292,7 +292,7 @@ protected function executeInsert(Insert $insert)
}

// apply preInsert features
$this->featureSet->apply(EventFeature::EVENT_PRE_INSERT, [$insert]);
$this->featureSet->apply(EventFeatureEventsInterface::EVENT_PRE_INSERT, [$insert]);

// Most RDBMS solutions do not allow using table aliases in INSERTs
// See https://github.com/zendframework/zf2/issues/7311
Expand All @@ -308,7 +308,7 @@ protected function executeInsert(Insert $insert)
$this->lastInsertValue = $this->adapter->getDriver()->getConnection()->getLastGeneratedValue();

// apply postInsert features
$this->featureSet->apply(EventFeature::EVENT_POST_INSERT, [$statement, $result]);
$this->featureSet->apply(EventFeatureEventsInterface::EVENT_POST_INSERT, [$statement, $result]);

// Reset original table information in Insert instance, if necessary
if ($unaliasedTable) {
Expand Down Expand Up @@ -369,13 +369,13 @@ protected function executeUpdate(Update $update)
}

// apply preUpdate features
$this->featureSet->apply(EventFeature::EVENT_PRE_UPDATE, [$update]);
$this->featureSet->apply(EventFeatureEventsInterface::EVENT_PRE_UPDATE, [$update]);

$statement = $this->sql->prepareStatementForSqlObject($update);
$result = $statement->execute();

// apply postUpdate features
$this->featureSet->apply(EventFeature::EVENT_POST_UPDATE, [$statement, $result]);
$this->featureSet->apply(EventFeatureEventsInterface::EVENT_POST_UPDATE, [$statement, $result]);

return $result->getAffectedRows();
}
Expand Down Expand Up @@ -427,13 +427,13 @@ protected function executeDelete(Delete $delete)
}

// pre delete update
$this->featureSet->apply(EventFeature::EVENT_PRE_DELETE, [$delete]);
$this->featureSet->apply(EventFeatureEventsInterface::EVENT_PRE_DELETE, [$delete]);

$statement = $this->sql->prepareStatementForSqlObject($delete);
$result = $statement->execute();

// apply postDelete features
$this->featureSet->apply(EventFeature::EVENT_POST_DELETE, [$statement, $result]);
$this->featureSet->apply(EventFeatureEventsInterface::EVENT_POST_DELETE, [$statement, $result]);

return $result->getAffectedRows();
}
Expand Down Expand Up @@ -512,8 +512,7 @@ public function __clone()
$this->sql = clone $this->sql;
if (is_object($this->table)) {
$this->table = clone $this->table;
} elseif (
is_array($this->table)
} elseif (is_array($this->table)
&& count($this->table) == 1
&& is_object(reset($this->table))
) {
Expand Down
19 changes: 3 additions & 16 deletions src/TableGateway/Feature/EventFeature.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,10 @@
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\EventsCapableInterface;

class EventFeature extends AbstractFeature implements EventsCapableInterface
class EventFeature extends AbstractFeature implements
EventFeatureEventsInterface,
EventsCapableInterface
{
const EVENT_PRE_INITIALIZE = 'preInitialize';
const EVENT_POST_INITIALIZE = 'postInitialize';

const EVENT_PRE_SELECT = 'preSelect';
const EVENT_POST_SELECT = 'postSelect';

const EVENT_PRE_INSERT = 'preInsert';
const EVENT_POST_INSERT = 'postInsert';

const EVENT_PRE_DELETE = 'preDelete';
const EVENT_POST_DELETE = 'postDelete';

const EVENT_PRE_UPDATE = 'preUpdate';
const EVENT_POST_UPDATE = 'postUpdate';

/**
* @var EventManagerInterface
*/
Expand Down
36 changes: 36 additions & 0 deletions src/TableGateway/Feature/EventFeatureEventsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Db\TableGateway\Feature;

/**
* EventFeature event constants.
*
* This moves the constants introduced in {@link https://github.com/zendframework/zf2/pull/7066}
* into a separate interface that EventFeature implements; the change keeps
* backwards compatibility, while simultaneously removing the need to add
* another hard dependency to the component.
*/
interface EventFeatureEventsInterface
{
const EVENT_PRE_INITIALIZE = 'preInitialize';
const EVENT_POST_INITIALIZE = 'postInitialize';

const EVENT_PRE_SELECT = 'preSelect';
const EVENT_POST_SELECT = 'postSelect';

const EVENT_PRE_INSERT = 'preInsert';
const EVENT_POST_INSERT = 'postInsert';

const EVENT_PRE_DELETE = 'preDelete';
const EVENT_POST_DELETE = 'postDelete';

const EVENT_PRE_UPDATE = 'preUpdate';
const EVENT_POST_UPDATE = 'postUpdate';
}

0 comments on commit c2b54ad

Please sign in to comment.