Skip to content

Commit

Permalink
update for newest doctrine version
Browse files Browse the repository at this point in the history
  • Loading branch information
juzna committed Dec 4, 2011
1 parent ad8fad2 commit 81aa9ba
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
38 changes: 33 additions & 5 deletions Nella/Doctrine/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @author Patrik Votoček
*/
class Cache extends \Doctrine\Common\Cache\AbstractCache
class Cache implements \Doctrine\Common\Cache\Cache
{
/** @var \Nette\Caching\Cache */
private $data = array();
Expand All @@ -38,7 +38,7 @@ public function getIds()
/**
* {@inheritdoc}
*/
protected function _doFetch($id)
public function fetch($id)
{
$data = $this->data->load($id);
return $data ?: FALSE;
Expand All @@ -47,15 +47,15 @@ protected function _doFetch($id)
/**
* {@inheritdoc}
*/
protected function _doContains($id)
public function contains($id)
{
return $this->data->load($id) !== NULL;
}

/**
* {@inheritdoc}
*/
protected function _doSave($id, $data, $lifeTime = 0)
public function save($id, $data, $lifeTime = 0)
{
$files = array();
if ($data instanceof \Doctrine\ORM\Mapping\ClassMetadata) {
Expand All @@ -79,9 +79,37 @@ protected function _doSave($id, $data, $lifeTime = 0)
/**
* {@inheritdoc}
*/
protected function _doDelete($id)
public function delete($id)
{
$this->data->save($id, NULL);
return TRUE;
}

/**
* Retrieves cached information from data store
*
* The server's statistics array has the following values:
*
* - <b>hits</b>
* Number of keys that have been requested and found present.
*
* - <b>misses</b>
* Number of items that have been requested and not found.
*
* - <b>uptime</b>
* Time that the server is running.
*
* - <b>memory_usage</b>
* Memory used by this server to store items.
*
* - <b>memory_available</b>
* Memory allowed to use for storage.
*
* @since 2.2
* @var array Associative array with server's statistics if available, NULL otherwise.
*/
function getStats()
{
// TODO: Implement getStats() method.
}
}
24 changes: 13 additions & 11 deletions Nella/Doctrine/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,15 @@ public static function createServiceAnnotationDriver(DI\Container $context)
\Doctrine\Common\Annotations\AnnotationRegistry::registerFile(
$context->params['libsDir'] . '/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php'
);

\Doctrine\Common\Annotations\AnnotationReader::addGlobalIgnoredName('service');

$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
$reader->setIgnoreNotImportedAnnotations(true);
$reader->setEnableParsePhpImports(false);
$storage = $context->hasService('annotationCache') ? $context->annotationCache : new Cache($context->cacheStorage);
$reader = new \Doctrine\Common\Annotations\CachedReader(
new \Doctrine\Common\Annotations\IndexedReader($reader), $storage
);


$reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader();
$reader->addNamespace('Doctrine\ORM\Mapping');

$cache = $context->hasService('annotationCache') ? $context->annotationCache : new Cache($context->cacheStorage);
$reader = new \Doctrine\Common\Annotations\CachedReader($reader, $cache);

return new Mapping\Driver\AnnotationDriver($reader, $context->params['doctrine-config']['entityDirs']);
}

Expand Down Expand Up @@ -239,6 +236,10 @@ public static function createServiceEventManager(DI\Container $context)
*/
public static function createServiceEntityManager(DI\Container $context)
{
// Make sure doctrine container has been initialized
// UGLY: but nette doesn't support creating service from another service :(
$container = $context->doctrineContainer;

$evm = $context->eventManager;
if (key_exists('driver', $context->params['doctrine-config'])
&& $context->params['doctrine-config']['driver'] == "pdo_mysql"
Expand All @@ -248,6 +249,7 @@ public static function createServiceEntityManager(DI\Container $context)

$context->freeze();
$config = $context->params['doctrine-config'];

return \Doctrine\ORM\EntityManager::create($config, $context->configuration, $evm);
}

Expand Down

0 comments on commit 81aa9ba

Please sign in to comment.