Пример #1
0
 public function initialise()
 {
     // Put a small marker to indicate that we run inside another CMS
     $this->container->segment->set('insideCMS', true);
     // Load the configuration
     $this->container->appConfig->loadConfiguration();
     // Attach the Joomla!-specific observer for Controller ACL checks
     $this->container->eventDispatcher->attach(new ControllerAcl($this->container->eventDispatcher));
     // Attach the Joomla!-specific observer for template override support
     $this->container->eventDispatcher->attach(new ViewAlternatePaths($this->container->eventDispatcher));
     // Set up the template (theme) to use – different for front-end and back-end
     if (empty($this->template) || $this->template == $this->container->application_name) {
         $template = Helper::isBackend() ? 'backend' : 'frontend';
         $this->setTemplate($template);
     }
     // Load the extra language files
     $appName = $this->container->application_name;
     if (Helper::isBackend() && substr($appName, -5) == 'Admin') {
         $appName = substr($appName, 0, -5);
     }
     $appNameLower = strtolower($appName);
     $languageTag = \JFactory::getLanguage()->getTag();
     Text::loadLanguage('en-GB', $appName, '.com_' . $appNameLower . '.ini', false, $this->container->languagePath);
     Text::loadLanguage($languageTag, $appName, '.com_' . $appNameLower . '.ini', true, $this->container->languagePath);
     // Load the framework's language file
     Text::loadLanguage('en-GB', 'lib_awf', '.ini', false, $this->container->languagePath);
     Text::loadLanguage($languageTag, 'lib_awf', '.ini', false, $this->container->languagePath);
     // In the back-end, also load front-end languages
     if (Helper::isBackend()) {
         Text::loadLanguage('en-GB', $appName, '.com_' . $appNameLower . '.ini', true, JPATH_SITE . '/language');
         Text::loadLanguage($languageTag, $appName, '.com_' . $appNameLower . '.ini', true, JPATH_SITE . '/language');
         Text::loadLanguage('en-GB', 'lib_awf', '.ini', true, JPATH_SITE . '/language');
         Text::loadLanguage($languageTag, 'lib_awf', '.ini', false, JPATH_SITE . '/language');
     }
 }
Пример #2
0
 public function __construct(array $values = array())
 {
     $appNameForPaths = $values['application_name'];
     if (Helper::isBackend() && substr($appNameForPaths, -5) == 'Admin') {
         $appNameForPaths = substr($appNameForPaths, 0, -5);
     }
     // Set up the filesystem path
     if (empty($values['filesystemBase'])) {
         $values['filesystemBase'] = JPATH_ROOT;
     }
     // Set up the base path
     if (empty($values['basePath'])) {
         $basePath = '/components/com_' . $appNameForPaths . '/' . $values['application_name'];
         $values['basePath'] = (Helper::isBackend() ? JPATH_ADMINISTRATOR : JPATH_ROOT) . $basePath;
     }
     // Set up the template path
     if (empty($values['templatePath'])) {
         $values['templatePath'] = __DIR__ . '/../templates';
     }
     // Set up the temporary path
     if (empty($values['temporaryPath'])) {
         $values['temporaryPath'] = \JFactory::getConfig()->get('tmp_path', sys_get_temp_dir());
     }
     // Set up the language path
     if (empty($values['languagePath'])) {
         $values['languagePath'] = (Helper::isBackend() ? JPATH_ADMINISTRATOR : JPATH_ROOT) . '/language';
     }
     // Set up the SQL files path
     if (empty($values['sqlPath'])) {
         $values['sqlPath'] = JPATH_ADMINISTRATOR . '/components/com_' . $appNameForPaths . '/sql/xml';
     }
     // Application service
     if (!isset($this['application'])) {
         $this['application'] = function (Container $c) {
             return Application::getInstance($c->application_name, $c);
         };
     }
     // Session Manager service
     if (!isset($this['session'])) {
         $this['session'] = function () {
             return new \Awf\Platform\Joomla\Session\Manager(new \Awf\Platform\Joomla\Session\SegmentFactory(), new \Awf\Platform\Joomla\Session\CsrfTokenFactory());
         };
     }
     // Application Session Segment service
     if (!isset($this['segment'])) {
         $this['segment'] = function (Container $c) {
             if (empty($c->session_segment_name)) {
                 $c->session_segment_name = $c->application_name;
             }
             return $c->session->newSegment($c->session_segment_name);
         };
     }
     // Database Driver service
     if (!isset($this['db'])) {
         $this['db'] = function (Container $c) {
             $db = \JFactory::getDbo();
             $options = array('connection' => $db->getConnection(), 'prefix' => $db->getPrefix(), 'driver' => 'mysqli');
             switch ($db->name) {
                 case 'mysql':
                     $options['driver'] = 'Mysql';
                     break;
                 default:
                 case 'mysqli':
                     $options['driver'] = 'Mysqli';
                     break;
                 case 'sqlsrv':
                 case 'mssql':
                 case 'sqlazure':
                     $options['driver'] = 'Sqlsrv';
                     break;
                 case 'postgresql':
                     $options['driver'] = 'Postgresql';
                     break;
                 case 'pdo':
                     $options['driver'] = 'Pdo';
                     break;
                 case 'sqlite':
                     $options['driver'] = 'Sqlite';
                     break;
             }
             return Driver::getInstance($options);
         };
     }
     // Application Event Dispatcher service
     if (!isset($this['eventDispatcher'])) {
         $this['eventDispatcher'] = function (Container $c) {
             return new Dispatcher($c);
         };
     }
     // Application Configuration service
     if (!isset($values['appConfig'])) {
         $values['appConfig'] = function (Container $c) {
             return new Configuration($c);
         };
     }
     // Application Router service
     if (!isset($values['router'])) {
         $values['router'] = function (Container $c) {
             return new Router($c);
         };
     }
     // User Manager service
     if (!isset($values['userManager'])) {
         $values['userManager'] = function (Container $c) {
             return new Manager($c);
         };
     }
     parent::__construct($values);
     // Mailer Object service – returns a Joomla! JMail object
     // IMPORTANT! It has to appear AFTER the parent __construct method
     $this['mailer'] = $this->factory(function (Container $c) {
         return \JFactory::getMailer();
     });
 }
Пример #3
0
}
// Include the autoloader
if (false == (include_once JPATH_LIBRARIES . '/awf/Autoloader/Autoloader.php')) {
    echo 'ERROR: Autoloader not found' . PHP_EOL;
    exit(1);
}
// Add our app to the autoloader, if it's not already set
$componentName = 'com_' . strtolower($appName);
$prefixes = Awf\Autoloader\Autoloader::getInstance()->getPrefixes();
if (!array_key_exists($appName . '\\', $prefixes)) {
    \Awf\Autoloader\Autoloader::getInstance()->addMap($appName . '\\', JPATH_SITE . '/components/' . $componentName)->addMap($appName . 'Admin\\', JPATH_ADMINISTRATOR . '/components/' . $componentName)->addMap($appName . '\\', JPATH_SITE . '/components/' . $componentName . '/' . $appName)->addMap($appName . 'Admin\\', JPATH_ADMINISTRATOR . '/components/' . $componentName . '/' . $appName . 'Admin');
}
// Load Joomla!-specific translation files
\Awf\Platform\Joomla\Helper\Helper::loadTranslations($componentName);
// Find the name of the DI container class suitable for this component
$appName = \Awf\Platform\Joomla\Helper\Helper::isBackend() ? $appName . 'Admin' : $appName;
$containerClass = "\\{$appName}\\Container\\Container";
if (!class_exists($containerClass, true)) {
    $containerClass = '\\Awf\\Platform\\Joomla\\Container\\Container';
}
if (!isset($containerOverrides)) {
    $containerOverrides = array();
}
if (!isset($containerOverrides['application_name'])) {
    $containerOverrides['application_name'] = $appName;
}
// Try to create a new DI container
try {
    /** @var \Awf\Platform\Joomla\Container\Container $container */
    $container = new $containerClass($containerOverrides);
} catch (Exception $exc) {
Пример #4
0
 public function __construct(Container $container)
 {
     \Awf\Router\Router::__construct($container);
     $this->isBackend = Helper::isBackend();
 }