/**
  * Renders a form in frontend (or backend maybe later)
  * Usage:
  *	$options			=	array(	$baseClass->_getPagingParamName( 'basket' )			=> $this->id,
  *									$baseClass->_getPagingParamName( 'bck' )			=> $this->checkHashUser()
  *									);
  *
  * @param  string              $actionType
  * @param  string              $action
  * @param  cbpaidTable         $dataModel
  * @param  array               $options
  * @param  int                 $user_id
  * @param  ParamsInterface     $input
  * @return string
  */
 public static function render($actionType, $action, $dataModel, $options = array(), $user_id = null, ParamsInterface $input = null)
 {
     global $_CB_framework;
     if ($options === null) {
         $options = array();
     }
     $di = Application::DI();
     if ($input === null) {
         $input = new Input(array());
     }
     $output = Output::createNew('html', array());
     $getParams = array('option' => 'com_comprofiler', 'view' => 'pluginclass', 'plugin' => 'cbpaidsubscriptions', 'user' => $user_id);
     if ($_CB_framework->getUi() == 1) {
         $itemid = getCBprofileItemid(0);
         if ($itemid) {
             $getParams['Itemid'] = $itemid;
         }
     }
     $route = array('option' => 'com_comprofiler', 'view' => $action, 'action' => $actionType, 'method' => 'edit');
     if ($route['view'] == '') {
         $route['view'] = 'pluginclass';
     }
     /** @var \CBLib\AhaWow\Controller\Controller $ahaWowController */
     $ahaWowController = $di->get('CBLib\\AhaWow\\Controller\\Controller', array('input' => $input, 'output' => $output, 'options' => $options, 'getParams' => $getParams, 'data' => $dataModel));
     self::registerXml($action, $actionType);
     $ahaWowController->dispatchRoute($route);
     return (string) $output;
 }
Example #2
0
 /**
  * Create CBLib Application if not already created, and returns it for chaining
  *
  * @param  string                            $type    [optional] 'Web' or 'Cli'
  * @param  array|object|InputInterface|null  $input   (array_merge(get, post) or argv if cli)
  * @param  Config|callable|null              $config  The Config to use (or a closure returning it)
  * @return Application
  */
 public static function createApplication($type = 'Web', $input = null, $config = null)
 {
     if (!static::$application) {
         // Define $app Containers 'Application' and 'Cms':
         $application = Application::createApplication($type);
         static::$application = $application;
         // Define $app Container 'Config':
         $application->set('Config', function () use($config, $application) {
             return Config::setMainConfig($config, $application);
         }, true, true);
         // Define $app Container 'DatabaseDriverInterface':
         $application->set('CBLib\\Database\\DatabaseDriverInterface', function (ApplicationContainerInterface $di) {
             return Database::createDatabaseDriver($di->getCms());
         }, true)->alias('CBLib\\Database\\DatabaseDriverInterface', 'Database');
         // Define $app Container 'Input':
         $application->set('CBLib\\Input\\InputInterface', function (ApplicationContainerInterface $di) use($type, $input) {
             // return static::getMainInput( static::$app, $type, $input );
             return $di->getCms()->getInput($di, $type, $input);
         }, true)->alias('CBLib\\Input\\InputInterface', 'Input');
         // Define $app Container 'Output':
         /** @noinspection PhpUnusedParameterInspection */
         $application->set('CBLib\\Output\\OutputInterface', function (ApplicationContainerInterface $di, array $parameters) {
             return Output::createNew('html', $parameters);
             //TODO json+xml
         }, true)->alias('CBLib\\Output\\OutputInterface', 'Output');
         // 'Router' and CBLib\Controller\RouterInterface service providers are defined in specific Cms constructor.
         // Define $app Container 'Session':
         $application->set('CBLib\\Session\\SessionInterface', '\\CBLib\\Session\\Session')->alias('CBLib\\Session\\SessionInterface', 'Session');
         // Define $app Container 'SessionState':
         $application->set('CBLib\\Session\\SessionStateInterface', '\\CBLib\\Session\\SessionState')->alias('CBLib\\Session\\SessionStateInterface', 'SessionState');
         // Define $app Container 'User':
         $application->set('CBLib\\Entity\\User\\User', function (ApplicationContainerInterface $di, array $parameters) {
             if (count($parameters) === 0) {
                 throw new \UnexpectedValueException('Application::MyUser() called without a parameter');
             }
             return User::getInstanceForContainerOnly($parameters[0], $di->getCms(), $di->getConfig());
         })->alias('CBLib\\Entity\\User\\User', 'User');
         $application->set('MyUser', function (ApplicationContainerInterface $di, array $parameters) {
             if (count($parameters) !== 0) {
                 throw new \UnexpectedValueException('Application::User() called with a parameter');
             }
             return User::getInstanceForContainerOnly(null, $di->getCms(), $di->getConfig());
         });
         // Define Language and translations, as well as the translations logger interface:
         $application->set('Language', 'CBLib\\Language\\CBTxt', true);
         $application->set('CBLib\\Language\\TranslationsLoggerInterface', function (ApplicationContainerInterface $di) {
             // Creates the logger:
             $translationsLogger = new TranslationsLogger();
             // Registers after-render event to add the translations log at the end of the html body:
             $di->getCms()->registerOnAfterRenderBodyFilter(function ($body) use($translationsLogger) {
                 return $translationsLogger->appendToBodyUsedStrings($body);
             });
             return $translationsLogger;
         }, true);
     }
     return static::$application;
 }