mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 12:03:14 +00:00
Refactor Appbox
This commit is contained in:
@@ -64,6 +64,8 @@ class Core extends \Pimple
|
|||||||
|
|
||||||
$this->configuration = new Core\Configuration($handler, $environement);
|
$this->configuration = new Core\Configuration($handler, $environement);
|
||||||
|
|
||||||
|
$core = $this;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache Autoload if it's not debug mode
|
* Cache Autoload if it's not debug mode
|
||||||
*/
|
*/
|
||||||
@@ -81,9 +83,9 @@ class Core extends \Pimple
|
|||||||
|
|
||||||
if ($this->configuration->isInstalled())
|
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();
|
\phrasea::start();
|
||||||
@@ -100,26 +102,46 @@ class Core extends \Pimple
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$core = $this;
|
$this['CacheService'] = $this->share(function() use ($core)
|
||||||
$cacheManager = $this->getCacheManager();
|
{
|
||||||
|
|
||||||
|
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
|
* Set Entity Manager using configuration
|
||||||
*/
|
*/
|
||||||
$this['EM'] = $this->share(function() use ($core, $cacheManager)
|
$this['EM'] = $this->share(function() use ($core)
|
||||||
{
|
{
|
||||||
$serviceName = $core->getConfiguration()->getOrm();
|
$serviceName = $core->getConfiguration()->getOrm();
|
||||||
$configuration = $core->getConfiguration()->getService($serviceName);
|
$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)
|
$this["Twig"] = $this->share(function() use ($core)
|
||||||
{
|
{
|
||||||
$serviceName = $core->getConfiguration()->getTemplating();
|
$serviceName = $core->getConfiguration()->getTemplating();
|
||||||
|
|
||||||
$configuration = $core->getConfiguration()->getService($serviceName);
|
$configuration = $core->getConfiguration()->getService($serviceName);
|
||||||
|
|
||||||
$serviceBuilder = new Core\ServiceBuilder\TemplateEngine(
|
$Service = Core\Service\Builder::create($core, $serviceName, $configuration);
|
||||||
$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
|
* Getter
|
||||||
*
|
*
|
||||||
@@ -222,16 +215,16 @@ class Core extends \Pimple
|
|||||||
return $this['Registry'];
|
return $this['Registry'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Getter
|
|
||||||
*
|
|
||||||
* @return \Registry
|
|
||||||
*/
|
|
||||||
public function getCache()
|
public function getCache()
|
||||||
{
|
{
|
||||||
return $this['Cache'];
|
return $this['Cache'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getOpcodeCache()
|
||||||
|
{
|
||||||
|
return $this['OpcodeCache'];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Getter
|
* Getter
|
||||||
*
|
*
|
||||||
@@ -279,7 +272,7 @@ class Core extends \Pimple
|
|||||||
*/
|
*/
|
||||||
public function isAuthenticated()
|
public function isAuthenticated()
|
||||||
{
|
{
|
||||||
$session = \Session_Handler::getInstance(\appbox::get_instance());
|
$session = \Session_Handler::getInstance(\appbox::get_instance($this));
|
||||||
|
|
||||||
return $session->is_authenticated();
|
return $session->is_authenticated();
|
||||||
}
|
}
|
||||||
@@ -291,7 +284,7 @@ class Core extends \Pimple
|
|||||||
*/
|
*/
|
||||||
public function getAuthenticatedUser()
|
public function getAuthenticatedUser()
|
||||||
{
|
{
|
||||||
$appbox = \appbox::get_instance();
|
$appbox = \appbox::get_instance($this);
|
||||||
$session = \Session_Handler::getInstance($appbox);
|
$session = \Session_Handler::getInstance($appbox);
|
||||||
|
|
||||||
return \User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
return \User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||||
@@ -338,9 +331,14 @@ class Core extends \Pimple
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getLocale()
|
||||||
|
{
|
||||||
|
return $this->getRequest()->getLocale();
|
||||||
|
}
|
||||||
|
|
||||||
protected function enableEvents()
|
protected function enableEvents()
|
||||||
{
|
{
|
||||||
$events = \eventsmanager_broker::getInstance(\appbox::get_instance(), $this);
|
$events = \eventsmanager_broker::getInstance(\appbox::get_instance($this), $this);
|
||||||
$events->start();
|
$events->start();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@@ -134,7 +134,8 @@ class PDF
|
|||||||
|
|
||||||
protected function print_thumbnailGrid($links=false)
|
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);
|
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||||
|
|
||||||
$NDiapoW = 3;
|
$NDiapoW = 3;
|
||||||
@@ -331,7 +332,8 @@ class PDF
|
|||||||
|
|
||||||
protected function print_preview($withtdm)
|
protected function print_preview($withtdm)
|
||||||
{
|
{
|
||||||
$appbox = \appbox::get_instance();
|
$core = \bootstrap::getCore();
|
||||||
|
$appbox = \appbox::get_instance($core);
|
||||||
$registry = \registry::get_instance();
|
$registry = \registry::get_instance();
|
||||||
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
|
||||||
|
|
||||||
|
@@ -49,7 +49,9 @@ class UserProvider implements ControlProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function find($query, \User_Adapter $for_user, \databox $on_databox = null)
|
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
|
$users = $user_query
|
||||||
->like(\User_Query::LIKE_EMAIL, $query)
|
->like(\User_Query::LIKE_EMAIL, $query)
|
||||||
@@ -81,9 +83,11 @@ class UserProvider implements ControlProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function validate($id)
|
public function validate($id)
|
||||||
{
|
{
|
||||||
|
$Core = \bootstrap::getCore();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
\User_Adapter::getInstance($id, \appbox::get_instance());
|
\User_Adapter::getInstance($id, \appbox::get_instance($Core));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -102,7 +106,9 @@ class UserProvider implements ControlProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function getValue($id)
|
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();
|
return $user->get_display_name();
|
||||||
}
|
}
|
||||||
@@ -114,7 +120,9 @@ class UserProvider implements ControlProviderInterface
|
|||||||
*/
|
*/
|
||||||
public function getRessource($id)
|
public function getRessource($id)
|
||||||
{
|
{
|
||||||
return \User_Adapter::getInstance($id, \appbox::get_instance());
|
$Core = \bootstrap::getCore();
|
||||||
|
|
||||||
|
return \User_Adapter::getInstance($id, \appbox::get_instance($Core));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user