Skip to content

Commit

Permalink
Updated Events to extend commons
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Mar 1, 2013
1 parent 5708443 commit ba27e25
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 110 deletions.
43 changes: 9 additions & 34 deletions lib/Doctrine/ODM/PHPCR/Event/LifecycleEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,50 +19,25 @@

namespace Doctrine\ODM\PHPCR\Event;

class LifecycleEventArgs extends \Doctrine\Common\EventArgs
{
private $document;

/**
* @var \Doctrine\ODM\PHPCR\DocumentManager
*/
private $dm;

public function __construct($document, $dm)
{
$this->document = $document;
$this->dm = $dm;
}
use Doctrine\Common\Persistence\Event\LifecycleEventArgs as BaseLifecycleEventArgs;

class LifecycleEventArgs extends BaseLifecycleEventArgs
{
/**
* @return object
* @deprecated Will be dropped in favor of getObject in 1.0
* @return object
*/
public function getDocument()
{
return $this->document;
return $this->getEntity();
}

/**
* @return \Doctrine\ODM\PHPCR\DocumentManager
* @deprecated Will be dropped in favor of getObjectManager in 1.0
* @return \Doctrine\ODM\PHPCR\DocumentManager
*/
public function getDocumentManager()
{
return $this->dm;
}

/**
* @return object
*/
public function getObject()
{
return $this->object;
}

/**
* @return \Doctrine\ODM\PHPCR\DocumentManager
*/
public function getObjectManager()
{
return $this->dm;
return $this->getObjectManager();
}
}
53 changes: 5 additions & 48 deletions lib/Doctrine/ODM/PHPCR/Event/LoadClassMetadataEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,18 @@

namespace Doctrine\ODM\PHPCR\Event;

use Doctrine\Common\EventArgs;
use Doctrine\Common\Persistence\Event\LoadClassMetadataEventArgs as BaseLoadClassMetadataEventArgs;
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
use Doctrine\ODM\PHPCR\DocumentManager;

class LoadClassMetadataEventArgs extends EventArgs
class LoadClassMetadataEventArgs extends BaseLoadClassMetadataEventArgs
{
/**
* @var \Doctrine\PHPCR\ODM\Mapping\ClassMetadata
*/
private $classMetadata;

/**
* @var \Doctrine\PHPCR\ODM\DocumentManager
*/
private $dm;

/**
* Constructor.
*
* @param \Doctrine\PHPCR\ODM\Mapping\ClassMetadataInfo $classMetadata
* @param \Doctrine\PHPCR\ODM\DocumentManager $dm
*/
public function __construct(ClassMetadata $classMetadata, DocumentManager $dm)
{
$this->classMetadata = $classMetadata;
$this->dm = $dm;
}

/**
* Retrieve associated ClassMetadata.
*
* @return \Doctrine\PHPCR\ODM\Mapping\ClassMetadataInfo
*/
public function getClassMetadata()
{
return $this->classMetadata;
}

/**
* Retrieve associated DocumentManager.
*
* @return \Doctrine\PHPCR\ODM\DocumentManager
* @deprecated Will be dropped in favor of getObjectManager in 1.0
* @return \Doctrine\ODM\PHPCR\DocumentManager
*/
public function getDocumentManager()
{
return $this->dm;
}

/**
* Retrieve associated ObjectManager.
*
* @return \Doctrine\PHPCR\ODM\ObjectManager
*/
public function getObjectManager()
{
return $this->dm;
return $this->getObjectManager();
}
}
35 changes: 35 additions & 0 deletions lib/Doctrine/ODM/PHPCR/Event/ManagerEventArgs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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\Event;

use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Persistence\Event\ManagerEventArgs as BaseManagerEventArgs;

class ManagerEventArgs extends BaseManagerEventArgs
{
/**
* @deprecated Will be dropped in favor of getObjectManager in 1.0
* @return \Doctrine\ODM\PHPCR\DocumentManager
*/
public function getDocumentManager()
{
return $this->getObjectManager();
}
}
36 changes: 11 additions & 25 deletions lib/Doctrine/ODM/PHPCR/Event/MoveEventArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,10 @@

namespace Doctrine\ODM\PHPCR\Event;

/**
* MoveEventArgs
*/
class MoveEventArgs extends \Doctrine\Common\EventArgs
{
/**
* @var object
*/
private $document;

/**
* @var \Doctrine\ODM\PHPCR\DocumentManager
*/
private $dm;
use Doctrine\Common\Persistence\ObjectManager;

class MoveEventArgs extends LifecycleEventArgs
{
/**
* @var string
*/
Expand All @@ -53,32 +42,29 @@ class MoveEventArgs extends \Doctrine\Common\EventArgs
* @param string $sourcePath The source path
* @param string $targetPath The target path
*/
public function __construct($document, $dm, $sourcePath, $targetPath)
public function __construct($document, ObjectManager $om, $sourcePath, $targetPath)
{
$this->document = $document;
$this->dm = $dm;
parent::__construct($document, $om);
$this->sourcePath = $sourcePath;
$this->targetPath = $targetPath;
}

/**
* Get the document
*
* @return object
* @deprecated Will be dropped in favor of getObject in 1.0
* @return object
*/
public function getDocument()
{
return $this->document;
return $this->getEntity();
}

/**
* Get the document manager
*
* @return \Doctrine\ODM\PHPCR\DocumentManager
* @deprecated Will be dropped in favor of getObjectManager in 1.0
* @return \Doctrine\ODM\PHPCR\DocumentManager
*/
public function getDocumentManager()
{
return $this->dm;
return $this->getObjectManager();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/PHPCR/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use Doctrine\ODM\PHPCR\Event\PreFlushEventArgs;
use Doctrine\ODM\PHPCR\Event\PostFlushEventArgs;
use Doctrine\ODM\PHPCR\Event\MoveEventArgs;
use Doctrine\ODM\PHPCR\Event\ManagerEventArgs;
use Doctrine\ODM\PHPCR\Proxy\Proxy;

use Jackalope\Session as JackalopeSession;
Expand All @@ -44,7 +45,6 @@
use PHPCR\UnsupportedRepositoryOperationException;
use PHPCR\RepositoryException;
use PHPCR\Util\UUIDHelper;
use Doctrine\ODM\PHPCR\Event\ManagerEventArgs;

/**
* Unit of work class
Expand Down
32 changes: 32 additions & 0 deletions tests/Doctrine/Tests/ODM/PHPCR/Event/LifecycleEventArgsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Doctrine\ODM\PHPCR\Event\LifecycleEventArgs;

class LifecycleEventArgsTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager')
->disableOriginalConstructor()
->getMock();
$this->object = new \stdClass;

$this->eventArgs = new LifecycleEventArgs(
$this->object,
$this->dm
);
}

public function testGetDocumentManager()
{
$res = $this->eventArgs->getDocumentManager();
$this->assertSame($this->dm, $res);
}

public function testGetDocument()
{
$res = $this->eventArgs->getDocument();
$this->assertSame($this->object, $res);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Doctrine\ODM\PHPCR\Event\LoadClassMetadataEventArgs;


class LoadClassMetadataEventArgsTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Doctrine\ODM\PHPCR\Event\ManagerEventArgs;


class ManagerEventArgsTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
Expand Down
46 changes: 46 additions & 0 deletions tests/Doctrine/Tests/ODM/PHPCR/Event/MoveEventArgsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

use Doctrine\ODM\PHPCR\Event\MoveEventArgs;

class MoveEventArgsTest extends \PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->dm = $this->getMockBuilder('Doctrine\ODM\PHPCR\DocumentManager')
->disableOriginalConstructor()
->getMock();
$this->object = new \stdClass;

$this->eventArgs = new MoveEventArgs(
$this->object,
$this->dm,
'source/path',
'target/path'
);
}

public function testGetDocumentManager()
{
$res = $this->eventArgs->getDocumentManager();
$this->assertSame($this->dm, $res);
}

public function testGetDocument()
{
$res = $this->eventArgs->getDocument();
$this->assertSame($this->object, $res);
}

public function testGetSourcePath()
{
$path = $this->eventArgs->getSourcePath();
$this->assertEquals('source/path', $path);
}

public function testGetTargetPath()
{
$path = $this->eventArgs->getTargetPath();
$this->assertEquals('target/path', $path);
}
}

0 comments on commit ba27e25

Please sign in to comment.