-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Showing
7 changed files
with
356 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 |
---|---|---|
@@ -1,7 +1,30 @@ | ||
<?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\ODM\PHPCR\Queue; | ||
|
||
/** | ||
* Represents a horizontal tree operation, encompassing | ||
* MOVE, REMOVE and INSERT operations. | ||
* | ||
* @author Daniel Leech <[email protected]> | ||
*/ | ||
class TreeOperation | ||
{ | ||
const OP_MOVE = 'move'; | ||
|
@@ -13,33 +36,67 @@ class TreeOperation | |
private $args; | ||
private $valid = true; | ||
|
||
/** | ||
* @param mixed $type | ||
* @param mixed $oid | ||
* @param mixed $args | ||
*/ | ||
public function __construct($type, $oid, $args) | ||
{ | ||
$this->oid = $oid; | ||
$this->type = $type; | ||
$this->args = $args; | ||
} | ||
|
||
/** | ||
* Return the SPL object ID which maps | ||
* to the document on which the operaton should be | ||
* performed. | ||
* | ||
* @return string | ||
*/ | ||
public function getOid() | ||
{ | ||
return $this->oid; | ||
} | ||
|
||
/** | ||
* Return the type of operation, one of | ||
* the self::OP_* constants. | ||
* | ||
* @return string | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
/** | ||
* Return the arguments for the operation | ||
* | ||
* @return mixed | ||
*/ | ||
public function getArgs() | ||
{ | ||
return $this->args; | ||
} | ||
|
||
/** | ||
* Invalidate this item so that it will not be processed. | ||
* Invalidation is quicker than removing the item from the queue. | ||
* | ||
* @param boolean | ||
*/ | ||
public function invalidate() | ||
{ | ||
$this->valid = false; | ||
} | ||
|
||
/** | ||
* Return true if this item should be processed | ||
* | ||
* @return boolean | ||
*/ | ||
public function isValid() | ||
{ | ||
return $this->valid; | ||
|
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 |
---|---|---|
@@ -1,27 +1,73 @@ | ||
<?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\ODM\PHPCR\Queue; | ||
|
||
/** | ||
* Represents a batch of operations of the same type | ||
* | ||
* @author Daniel Leech <[email protected]> | ||
*/ | ||
class TreeOperationBatch | ||
{ | ||
private $type; | ||
private $schedule = array(); | ||
|
||
/** | ||
* @param mixed $type | ||
*/ | ||
public function __construct($type) | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
/** | ||
* Return the operation schedule, e.g. | ||
* | ||
* array( | ||
* $oid => $args | ||
* ) | ||
* | ||
* @return array | ||
*/ | ||
public function getSchedule() | ||
{ | ||
return $this->schedule; | ||
} | ||
|
||
/** | ||
* Schedule an operation | ||
* | ||
* @param string $oid | ||
* @param array $args | ||
*/ | ||
public function schedule($oid, $args) | ||
{ | ||
$this->schedule[$oid] = $args; | ||
} | ||
|
||
/** | ||
* Return the operation type, one of the | ||
* TreeOperation::OP_* constants. | ||
* | ||
* @return string | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
|
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 |
---|---|---|
@@ -1,21 +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\ODM\PHPCR\Queue; | ||
|
||
use Doctrine\ODM\PHPCR\Queue\TreeOperation; | ||
use Doctrine\ODM\PHPCR\Queue\TreeOperationBatch; | ||
|
||
/** | ||
* The tree operation queue | ||
* | ||
* @author Daniel Leech <[email protected]> | ||
*/ | ||
class TreeOperationQueue | ||
{ | ||
private $queue = array(); | ||
|
||
/** | ||
* Push a new operation onto the queue | ||
* | ||
* @param TreeOperation $operation | ||
*/ | ||
public function push(TreeOperation $operation) | ||
{ | ||
$this->queue[] = $operation; | ||
} | ||
|
||
/** | ||
* Partition into contiguous sets of operations | ||
* | ||
* @return TreeOperationBatch[] | ||
*/ | ||
public function getBatches() | ||
{ | ||
|
@@ -42,11 +71,21 @@ public function getBatches() | |
return $batches; | ||
} | ||
|
||
/** | ||
* Clear the queue | ||
*/ | ||
public function clear() | ||
{ | ||
$this->queue = array(); | ||
} | ||
|
||
/** | ||
* Return the entire schedule for the given operation type | ||
* | ||
* @param string $type | ||
* | ||
* @return array | ||
*/ | ||
public function getSchedule($type) | ||
{ | ||
$schedule = array(); | ||
|
@@ -62,6 +101,14 @@ public function getSchedule($type) | |
return $schedule; | ||
} | ||
|
||
/** | ||
* Return true if the spl object id is scheduled for the given type | ||
* | ||
* @param string $type | ||
* @param string $oid | ||
* | ||
* @return boolean | ||
*/ | ||
public function isQueued($type, $oid) | ||
{ | ||
foreach ($this->queue as $operation) { | ||
|
@@ -81,6 +128,12 @@ public function isQueued($type, $oid) | |
return false; | ||
} | ||
|
||
/** | ||
* Remove all operations with the given spl object ID and type | ||
* | ||
* @param string $type | ||
* @param string $oid | ||
*/ | ||
public function unqueue($type, $oid) | ||
{ | ||
foreach ($this->queue as $operation) { | ||
|
@@ -96,6 +149,11 @@ public function unqueue($type, $oid) | |
} | ||
} | ||
|
||
/** | ||
* Remove all references to the given spl object ID | ||
* | ||
* @param $oid string | ||
*/ | ||
public function unregister($oid) | ||
{ | ||
foreach ($this->queue as $operation) { | ||
|
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
33 changes: 33 additions & 0 deletions
33
tests/Doctrine/Tests/ODM/PHPCR/Queue/TreeOperationBatchTest.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,33 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\ODM\PHPCR\Queue; | ||
|
||
use Doctrine\ODM\PHPCR\Queue\TreeOperationBatch; | ||
use Doctrine\ODM\PHPCR\Queue\TreeOperation; | ||
|
||
class TreeOperationBatchTest extends \PHPUnit_Framework_Testcase | ||
{ | ||
private $batch; | ||
|
||
public function setUp() | ||
{ | ||
$this->batch = new TreeOperationBatch(TreeOperation::OP_MOVE); | ||
} | ||
|
||
public function testGetters() | ||
{ | ||
$this->assertEquals(TreeOperation::OP_MOVE, $this->batch->getType()); | ||
} | ||
|
||
public function testSchedule() | ||
{ | ||
$this->batch->schedule('1234', 'arg'); | ||
$this->batch->schedule('4321', 'arg'); | ||
|
||
$this->assertEquals(array( | ||
'1234' => 'arg', | ||
'4321' => 'arg', | ||
), $this->batch->getSchedule()); | ||
} | ||
} | ||
|
Oops, something went wrong.