Source of file ServiceProvider.php

Size: 3,391 Bytes - Last Modified: 2016-05-18T03:08:27+02:00

buildproject/core/module_system/system/ServiceProvider.php

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
<?php

namespace Kajona\System\System;

use Kajona\System\Portal\ToolkitPortal;
use Pimple\Container;
use Pimple\ServiceProviderInterface;

/**
 * ServiceProvider
 *
 * @package Kajona\System\System
 * @author christoph.kappestein@gmail.com
 * @since 4.6
 */
class ServiceProvider implements ServiceProviderInterface
{
    const STR_DB = "system_db";
    const STR_RIGHTS = "system_rights";
    const STR_CONFIG = "system_config";
    const STR_SESSION = "system_session";
    const STR_ADMINTOOLKIT = "system_admintoolkit";
    const STR_PORTALTOOLKIT = "system_portaltoolkit";
    const STR_RESOURCE_LOADER = "system_resource_loader";
    const STR_CLASS_LOADER = "system_class_loader";
    const STR_TEMPLATE = "system_template";
    const STR_LANG = "system_lang";
    const STR_OBJECT_FACTORY = "system_object_factory";
    const STR_OBJECT_BUILDER = "system_object_builder";
    const STR_LOGGER = "system_logger";
    const STR_CACHE_MANAGER = "system_cache_manager";


    public function register(Container $objContainer)
    {
        $objContainer[self::STR_DB] = function ($c) {
            return Database::getInstance();
        };

        $objContainer[self::STR_RIGHTS] = function ($c) {
            return Rights::getInstance();
        };

        $objContainer[self::STR_CONFIG] = function ($c) {
            return Config::getInstance();
        };

        $objContainer[self::STR_SESSION] = function ($c) {
            return Session::getInstance();
        };

        $objContainer[self::STR_ADMINTOOLKIT] = function ($c) {
            // decide which class to load
            $strAdminToolkitClass = $c[self::STR_CONFIG]->getConfig("admintoolkit");
            if ($strAdminToolkitClass == "") {
                $strAdminToolkitClass = "ToolkitAdmin";
            }

            $strPath = Resourceloader::getInstance()->getPathForFile("/admin/".$strAdminToolkitClass.".php");
            return Classloader::getInstance()->getInstanceFromFilename($strPath);
        };

        $objContainer[self::STR_PORTALTOOLKIT] = function ($c) {
            $strPath = Resourceloader::getInstance()->getPathForFile("/portal/ToolkitPortal.php");
            include_once $strPath;

            return new ToolkitPortal();
        };

        $objContainer[self::STR_RESOURCE_LOADER] = function ($c) {
            return Resourceloader::getInstance();
        };

        $objContainer[self::STR_CLASS_LOADER] = function ($c) {
            return Classloader::getInstance();
        };

        $objContainer[self::STR_TEMPLATE] = function ($c) {
            return new Template(
                new TemplateFileParser(),
                new TemplateSectionParser(),
                new TemplatePlaceholderParser(),
                new TemplateBlocksParser()
            );
        };

        $objContainer[self::STR_LANG] = function ($c) {
            return Lang::getInstance();
        };

        $objContainer[self::STR_OBJECT_FACTORY] = function ($c) {
            return Objectfactory::getInstance();
        };

        $objContainer[self::STR_OBJECT_BUILDER] = function ($c) {
            return new ObjectBuilder($c);
        };

        $objContainer[self::STR_LOGGER] = function ($c) {
            return Logger::getInstance();
        };

        $objContainer[self::STR_CACHE_MANAGER] = function ($c) {
            return new CacheManager();
        };
    }
}