Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.

[WIP] Improvements / Refactoring #159

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
155 changes: 155 additions & 0 deletions src/Doctrine/ODM/OrientDB/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php

namespace Doctrine\ODM\OrientDB;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\CachedReader;
use Doctrine\Common\Annotations\SimpleAnnotationReader;
use Doctrine\Common\Cache\ArrayCache;
use Doctrine\Common\Persistence\Mapping\Driver\MappingDriver;
use Doctrine\OrientDB\Binding\BindingInterface;

class Configuration
{
/**
* @var BindingInterface
*/
protected $binding;

/**
* @var string
*/
protected $classMetadataFactoryName = 'Doctrine\ODM\OrientDB\Mapper\ClassMetadata\Factory';

/**
* @var string
*/
protected $defaultRepositoryClassName = 'Doctrine\ODM\OrientDB\Repository';

/**
* @var MappingDriver
*/
protected $metadataDriver;

/**
* Set the metadata driver
*
* @param MappingDriver $mappingDriver
* @return void
*
* @todo Force parameter to be a Closure to ensure lazy evaluation
* (as soon as a metadata cache is in effect, the driver never needs to initialize).
*/
public function setMetadataDriver(MappingDriver $mappingDriver)
{
$this->metadataDriver = $mappingDriver;
}

/**
* Get the metadata driver
*
* @return MappingDriver
*/
public function getMetadataDriver()
{
return $this->metadataDriver;
}

/**
* Set binding
*
* @param BindingInterface $binding
*/
public function setBinding(BindingInterface $binding)
{
$this->binding = $binding;
}

/**
* Get bindung
*
* @return BindingInterface
*/
public function getBinding()
{
return $this->binding;
}

/**
* Adds a new default annotation driver with a correctly configured annotation reader. If $useSimpleAnnotationReader
* is true, the notation `@Entity` will work, otherwise, the notation `@ODM\Entity` will be supported.
*
* @param array $paths
* @param bool $useSimpleAnnotationReader
*
* @return AnnotationDriver
*/
public function newDefaultAnnotationDriver($paths = array(), $useSimpleAnnotationReader = true)
{
/** @todo update this */
AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');

if ($useSimpleAnnotationReader) {
// Register the ORM Annotations in the AnnotationRegistry
$reader = new SimpleAnnotationReader();
$reader->addNamespace('Doctrine\ODM\OrientDB\Mapper'); /* @todo rename directory to Mapping */
$cachedReader = new CachedReader($reader, new ArrayCache());

return new AnnotationDriver($cachedReader, (array) $paths); /* @todo write class */
}

return new AnnotationDriver(
new CachedReader(new AnnotationReader(), new ArrayCache()),
(array) $paths
);
}

/**
* Sets a class metadata factory.
*
* @param string $cmfName
* @return void
*/
public function setClassMetadataFactoryName($classMetadataFactoryName)
{
$this->classMetadataFactoryName = $classMetadataFactoryName;
}

/**
* Get class metadata factory name
*
* @return string
*/
public function getClassMetadataFactoryName()
{
return $this->classMetadataFactoryName;
}

/**
* Set default repository class
*
* @param string $className
* @return void
* @throws ODMException If not is a \Doctrine\Common\Persistence\ObjectRepository
*/
public function setDefaultRepositoryClassName($className)
{
$reflectionClass = new \ReflectionClass($className);

if ( ! $reflectionClass->implementsInterface('Doctrine\Common\Persistence\ObjectRepository')) {
throw ODMException::invalidDocumentRepository($className);
}
$this->defaultRepositoryClassName = $className;
}

/**
* Get default repository class.
*
* @return string
*/
public function getDefaultRepositoryClassName()
{
return $this->defaultRepositoryClassName;
}
}
145 changes: 145 additions & 0 deletions src/Doctrine/ODM/OrientDB/Events.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php

namespace Doctrine\ODM\OrientDB;

/**
* Container for all ODM events.
*
* This class cannot be instantiated.
*/
final class Events
{
private function __construct() {}

/**
* The preRemove event occurs for a given document before the respective
* Manager remove operation for that document is executed.
*
* This is an document lifecycle event.
*
* @var string
*/
const preRemove = 'preRemove';

/**
* The postRemove event occurs for an document after the document has
* been deleted. It will be invoked after the database delete operations.
*
* This is an document lifecycle event.
*
* @var string
*/
const postRemove = 'postRemove';

/**
* The prePersist event occurs for a given document before the respective
* Manager persist operation for that document is executed.
*
* This is an document lifecycle event.
*
* @var string
*/
const prePersist = 'prePersist';

/**
* The postPersist event occurs for an document after the document has
* been made persistent. It will be invoked after the database insert operations.
* Generated primary key values are available in the postPersist event.
*
* This is an document lifecycle event.
*
* @var string
*/
const postPersist = 'postPersist';

/**
* The preUpdate event occurs before the database update operations to
* document data.
*
* This is an document lifecycle event.
*
* @var string
*/
const preUpdate = 'preUpdate';

/**
* The postUpdate event occurs after the database update operations to
* document data.
*
* This is an document lifecycle event.
*
* @var string
*/
const postUpdate = 'postUpdate';

/**
* The preLoad event occurs for a document before the document has been loaded
* into the current Manager from the database or before the refresh operation
* has been applied to it.
*
* This is a document lifecycle event.
*
* @var string
*/
const preLoad = 'preLoad';

/**
* The postLoad event occurs for a document after the document has been loaded
* into the current Manager from the database or after the refresh operation
* has been applied to it.
*
* Note that the postLoad event occurs for an document before any associations have been
* initialized. Therefore it is not safe to access associations in a postLoad callback
* or event handler.
*
* This is a document lifecycle event.
*
* @var string
*/
const postLoad = 'postLoad';

/**
* The loadClassMetadata event occurs after the mapping metadata for a class
* has been loaded from a mapping source (annotations/xml/yaml).
*
* @var string
*/
const loadClassMetadata = 'loadClassMetadata';

/**
* The preFlush event occurs when the Manager#flush() operation is invoked,
* but before any changes to managed documents have been calculated. This event is
* always raised right after Manager#flush() call.
*/
const preFlush = 'preFlush';

/**
* The onFlush event occurs when the Manager#flush() operation is invoked,
* after any changes to managed documents have been determined but before any
* actual database operations are executed. The event is only raised if there is
* actually something to do for the underlying UnitOfWork. If nothing needs to be done,
* the onFlush event is not raised.
*
* @var string
*/
const onFlush = 'onFlush';

/**
* The postFlush event occurs when the Manager#flush() operation is invoked and
* after all actual database operations are executed successfully. The event is only raised if there is
* actually something to do for the underlying UnitOfWork. If nothing needs to be done,
* the postFlush event is not raised. The event won't be raised if an error occurs during the
* flush operation.
*
* @var string
*/
const postFlush = 'postFlush';

/**
* The onClear event occurs when the Manager#clear() operation is invoked,
* after all references to documents have been removed from the unit of work.
*
* @var string
*/
const onClear = 'onClear';
}
Loading