Refactor Appbox

This commit is contained in:
Romain Neutron
2012-02-21 16:11:38 +01:00
parent e217a49f6a
commit a21d830f61
3 changed files with 113 additions and 105 deletions

View File

@@ -64,6 +64,8 @@ class Core extends \Pimple
$this->configuration = new Core\Configuration($handler, $environement);
$core = $this;
/**
* Cache Autoload if it's not debug mode
*/
@@ -81,9 +83,9 @@ class Core extends \Pimple
if ($this->configuration->isInstalled())
{
$this['Registry'] = $this->share(function()
$this['Registry'] = $this->share(function() use ($core)
{
return \registry::get_instance();
return \registry::get_instance($core);
});
\phrasea::start();
@@ -100,26 +102,46 @@ class Core extends \Pimple
}
$core = $this;
$cacheManager = $this->getCacheManager();
$this['CacheService'] = $this->share(function() use ($core)
{
if (!file_exists(__DIR__ . '/../../../tmp/cache_registry.yml'))
{
touch(__DIR__ . '/../../../tmp/cache_registry.yml');
}
$file = new \SplFileObject(__DIR__ . '/../../../tmp/cache_registry.yml');
$parser = new Core\Configuration\Parser\Yaml();
return new \Alchemy\Phrasea\Cache\Manager($core, $file, $parser);
});
/**
* Set Entity Manager using configuration
*/
$this['EM'] = $this->share(function() use ($core, $cacheManager)
$this['EM'] = $this->share(function() use ($core)
{
$serviceName = $core->getConfiguration()->getOrm();
$configuration = $core->getConfiguration()->getService($serviceName);
$serviceBuilder = new Core\ServiceBuilder\Orm($serviceName, $configuration);
$Service = Core\Service\Builder::create($core, $serviceName, $configuration);
$service = $serviceBuilder->buildService();
return $Service->getDriver();
});
foreach ($service->getCacheServices()->all() as $cacheKey => $cacheService)
$this['Cache'] = $this->share(function() use ($core)
{
$cacheManager($cacheKey, $cacheService);
}
$serviceName = $core->getConfiguration()->getCache();
return $service->getService();
return $core['CacheService']->get('MainCache', $serviceName)->getDriver();
});
$this['OpcodeCache'] = $this->share(function() use ($core)
{
$serviceName = $core->getConfiguration()->getOpcodeCache();
return $core['CacheService']->get('OpcodeCache', $serviceName)->getDriver();
});
@@ -127,14 +149,11 @@ class Core extends \Pimple
$this["Twig"] = $this->share(function() use ($core)
{
$serviceName = $core->getConfiguration()->getTemplating();
$configuration = $core->getConfiguration()->getService($serviceName);
$serviceBuilder = new Core\ServiceBuilder\TemplateEngine(
$serviceName, $configuration
);
$Service = Core\Service\Builder::create($core, $serviceName, $configuration);
return $serviceBuilder->buildService()->getService();
return $Service->getDriver();
});
@@ -186,32 +205,6 @@ class Core extends \Pimple
}
}
private function getCacheManager()
{
return function($cacheKey, $service)
{
$driverType = $service->getType();
$driver = $service->getService();
if(!file_exists(__DIR__ . '/../../../tmp/cache_registry.yml'))
{
touch(__DIR__ . '/../../../tmp/cache_registry.yml');
}
$file = new \SplFileObject(__DIR__ . '/../../../tmp/cache_registry.yml');
$parser = new Core\Configuration\Parser\Yaml();
$cacheManager = new \Alchemy\Phrasea\Cache\Manager($file, $parser);
if ($cacheManager->hasChange($cacheKey, $driverType))
{
$driver->flushAll();
$cacheManager->save($cacheKey, $driverType);
}
};
}
/**
* Getter
*
@@ -222,16 +215,16 @@ class Core extends \Pimple
return $this['Registry'];
}
/**
* Getter
*
* @return \Registry
*/
public function getCache()
{
return $this['Cache'];
}
public function getOpcodeCache()
{
return $this['OpcodeCache'];
}
/**
* Getter
*
@@ -279,7 +272,7 @@ class Core extends \Pimple
*/
public function isAuthenticated()
{
$session = \Session_Handler::getInstance(\appbox::get_instance());
$session = \Session_Handler::getInstance(\appbox::get_instance($this));
return $session->is_authenticated();
}
@@ -291,7 +284,7 @@ class Core extends \Pimple
*/
public function getAuthenticatedUser()
{
$appbox = \appbox::get_instance();
$appbox = \appbox::get_instance($this);
$session = \Session_Handler::getInstance($appbox);
return \User_Adapter::getInstance($session->get_usr_id(), $appbox);
@@ -338,9 +331,14 @@ class Core extends \Pimple
return;
}
public function getLocale()
{
return $this->getRequest()->getLocale();
}
protected function enableEvents()
{
$events = \eventsmanager_broker::getInstance(\appbox::get_instance(), $this);
$events = \eventsmanager_broker::getInstance(\appbox::get_instance($this), $this);
$events->start();
return;

View File

@@ -134,7 +134,8 @@ class PDF
protected function print_thumbnailGrid($links=false)
{
$appbox = \appbox::get_instance();
$core = \bootstrap::getCore();
$appbox = \appbox::get_instance($core);
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
$NDiapoW = 3;
@@ -331,7 +332,8 @@ class PDF
protected function print_preview($withtdm)
{
$appbox = \appbox::get_instance();
$core = \bootstrap::getCore();
$appbox = \appbox::get_instance($core);
$registry = \registry::get_instance();
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);

View File

@@ -49,7 +49,9 @@ class UserProvider implements ControlProviderInterface
*/
public function find($query, \User_Adapter $for_user, \databox $on_databox = null)
{
$user_query = new \User_Query(\appbox::get_instance());
$Core = \bootstrap::getCore();
$user_query = new \User_Query(\appbox::get_instance($Core));
$users = $user_query
->like(\User_Query::LIKE_EMAIL, $query)
@@ -81,9 +83,11 @@ class UserProvider implements ControlProviderInterface
*/
public function validate($id)
{
$Core = \bootstrap::getCore();
try
{
\User_Adapter::getInstance($id, \appbox::get_instance());
\User_Adapter::getInstance($id, \appbox::get_instance($Core));
return true;
}
@@ -102,7 +106,9 @@ class UserProvider implements ControlProviderInterface
*/
public function getValue($id)
{
$user = \User_Adapter::getInstance($id, \appbox::get_instance());
$Core = \bootstrap::getCore();
$user = \User_Adapter::getInstance($id, \appbox::get_instance($Core));
return $user->get_display_name();
}
@@ -114,7 +120,9 @@ class UserProvider implements ControlProviderInterface
*/
public function getRessource($id)
{
return \User_Adapter::getInstance($id, \appbox::get_instance());
$Core = \bootstrap::getCore();
return \User_Adapter::getInstance($id, \appbox::get_instance($Core));
}
}