This repository has been archived by the owner on Nov 11, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve find/update events and use MutableEventArgs for post listeners
With the addition of FindEventArgs, find events will not receive the field projection in addition to the query. UpdateEventArgs now has options. A new MutableEventArgs class was created to allow Collection query/command results to be modified by the post event listeners (as requested in #94). Finally, CollectionEventsTest was created to test all pre/post events dispatched by Collection methods.
- Loading branch information
Showing
10 changed files
with
630 additions
and
87 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\MongoDB\Event; | ||
|
||
use Doctrine\Common\EventArgs as BaseEventArgs; | ||
|
||
/** | ||
* Event args for find queries. | ||
* | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT | ||
* @link www.doctrine-project.com | ||
* @since 1.1 | ||
* @author Jeremy Mikola <[email protected]> | ||
*/ | ||
class FindEventArgs extends BaseEventArgs | ||
{ | ||
private $invoker; | ||
private $query; | ||
private $fields; | ||
|
||
public function __construct($invoker, array $query, array $fields) | ||
{ | ||
$this->invoker = $invoker; | ||
$this->query = $query; | ||
$this->fields = $fields; | ||
} | ||
|
||
public function getInvoker() | ||
{ | ||
return $this->invoker; | ||
} | ||
|
||
public function getQuery() | ||
{ | ||
return $this->query; | ||
} | ||
|
||
public function getFields() | ||
{ | ||
return $this->fields; | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\MongoDB\Event; | ||
|
||
/** | ||
* Mutable event args for query and command results. | ||
* | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT | ||
* @link www.doctrine-project.com | ||
* @since 1.1 | ||
* @author Jeremy Mikola <[email protected]> | ||
*/ | ||
class MutableEventArgs extends EventArgs | ||
{ | ||
private $changedData; | ||
private $isDataChanged = false; | ||
|
||
public function getData() | ||
{ | ||
return $this->isDataChanged ? $this->changedData : parent::getData(); | ||
} | ||
|
||
public function setData($data) | ||
{ | ||
$this->isDataChanged = parent::getData() !== $data; | ||
$this->changedData = $this->isDataChanged ? $data : null; | ||
} | ||
|
||
public function isDataChanged() | ||
{ | ||
return $this->isDataChanged; | ||
} | ||
} |
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
Oops, something went wrong.