This repository has been archived on 2026-07-19. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
espocrm-base/application/Espo/Core/Container.php
T
Taras Machyshyn 9eaad382ff changed log class
2014-02-24 18:21:42 +02:00

192 lines
3.6 KiB
PHP

<?php
namespace Espo\Core;
class Container
{
private $data = array();
/**
* Constructor
*/
public function __construct()
{
}
public function get($name)
{
if (empty($this->data[$name])) {
$this->load($name);
}
return $this->data[$name];
}
private function load($name)
{
$loadMethod = 'load' . ucfirst($name);
if (method_exists($this, $loadMethod)) {
$obj = $this->$loadMethod();
$this->data[$name] = $obj;
} else {
//external loader class \Espo\Core\Loaders\<className> or \Custom\Espo\Core\Loaders\<className> with load() method
$className = '\Espo\Custom\Core\Loaders\\'.ucfirst($name);
if (!class_exists($className)) {
$className = '\Espo\Core\Loaders\\'.ucfirst($name);
}
if (class_exists($className)) {
$loadClass = new $className($this);
$this->data[$name] = $loadClass->load();
}
}
// TODO throw an exception
return null;
}
private function loadSlim()
{
//return new \Slim\Slim();
return new \Espo\Core\Utils\Api\Slim();
}
private function loadFileManager()
{
return new \Espo\Core\Utils\File\Manager(
array(
'defaultPermissions' =>
array (
'dir' => '0775',
'file' => '0664',
'user' => '',
'group' => '',
),
)
);
}
private function loadPreferences()
{
return $this->get('entityManager')->getEntity('Preferences', $this->get('user')->id);
}
private function loadConfig()
{
return new \Espo\Core\Utils\Config(
$this->get('fileManager')
);
}
private function loadHookManager()
{
return new \Espo\Core\HookManager(
$this
);
}
/*private function loadLogOld()
{
return new \Espo\Core\Utils\LogOld(
$this->get('fileManager'),
$this->get('output'),
array(
'options' => $this->get('config')->get('logger'),
)
);
}*/
private function loadOutput()
{
return new \Espo\Core\Utils\Api\Output(
$this->get('slim')
);
}
private function loadMailSender()
{
return new \Espo\Core\Mail\Sender(
$this->get('config')
);
}
private function loadServiceFactory()
{
return new \Espo\Core\ServiceFactory(
$this
);
}
private function loadSelectManagerFactory()
{
return new \Espo\Core\SelectManagerFactory(
$this->get('entityManager'),
$this->get('user'),
$this->get('acl'),
$this->get('metadata')
);
}
private function loadMetadata()
{
return new \Espo\Core\Utils\Metadata(
$this->get('config'),
$this->get('fileManager')
);
}
private function loadLayout()
{
return new \Espo\Core\Utils\Layout(
$this->get('fileManager'),
$this->get('metadata')
);
}
private function loadAcl()
{
return new \Espo\Core\Acl(
$this->get('user'),
$this->get('config'),
$this->get('fileManager')
);
}
private function loadSchema()
{
return new \Espo\Core\Utils\Database\Schema\Schema(
$this->get('config'),
$this->get('metadata'),
$this->get('fileManager'),
$this->get('entityManager'),
$this->get('classParser')
);
}
private function loadClassParser()
{
return new \Espo\Core\Utils\File\ClassParser(
$this->get('fileManager'),
$this->get('config'),
$this->get('metadata')
);
}
private function loadI18n()
{
return new \Espo\Core\Utils\I18n(
$this->get('fileManager'),
$this->get('config'),
$this->get('preferences')
);
}
public function setUser($user)
{
$this->data['user'] = $user;
}
}