/** * Shortcut for calling a controller method and printing the result * @param string $controllerName the name of the controller under which it is * stored in the DI container * @param string $methodName the method that you want to call * @param DIContainer $container an instance of a pimple container. * @param array $urlParams list of URL parameters (optional) */ public static function main($controllerName, $methodName, DIContainer $container, array $urlParams = null) { if (!is_null($urlParams)) { $container['urlParams'] = $urlParams; } $appName = $container['AppName']; // first try $controllerName then go for \OCA\AppName\Controller\$controllerName try { $controller = $container->query($controllerName); } catch (QueryException $e) { $appNameSpace = self::buildAppNamespace($appName); $controllerName = $appNameSpace . '\\Controller\\' . $controllerName; $controller = $container->query($controllerName); } // initialize the dispatcher and run all the middleware before the controller $dispatcher = $container['Dispatcher']; list($httpHeaders, $responseHeaders, $responseCookies, $output) = $dispatcher->dispatch($controller, $methodName); if (!is_null($httpHeaders)) { header($httpHeaders); } foreach ($responseHeaders as $name => $value) { header($name . ': ' . $value); } foreach ($responseCookies as $name => $value) { $expireDate = null; if ($value['expireDate'] instanceof \DateTime) { $expireDate = $value['expireDate']->getTimestamp(); } setcookie($name, $value['value'], $expireDate, $container->getServer()->getWebRoot(), null, $container->getServer()->getConfig()->getSystemValue('forcessl', false), true); } if (!is_null($output)) { header('Content-Length: ' . strlen($output)); print $output; } }
/** * Shortcut for calling a controller method and printing the result * @param string $controllerName the name of the controller under which it is * stored in the DI container * @param string $methodName the method that you want to call * @param DIContainer $container an instance of a pimple container. * @param array $urlParams list of URL parameters (optional) */ public static function main($controllerName, $methodName, DIContainer $container, array $urlParams = null) { if (!is_null($urlParams)) { $container['OCP\\IRequest']->setUrlParameters($urlParams); } else { if (isset($container['urlParams']) && !is_null($container['urlParams'])) { $container['OCP\\IRequest']->setUrlParameters($container['urlParams']); } } $appName = $container['AppName']; // first try $controllerName then go for \OCA\AppName\Controller\$controllerName try { $controller = $container->query($controllerName); } catch (QueryException $e) { $appNameSpace = self::buildAppNamespace($appName); $controllerName = $appNameSpace . '\\Controller\\' . $controllerName; $controller = $container->query($controllerName); } // initialize the dispatcher and run all the middleware before the controller $dispatcher = $container['Dispatcher']; list($httpHeaders, $responseHeaders, $responseCookies, $output, $response) = $dispatcher->dispatch($controller, $methodName); $io = $container['OCP\\AppFramework\\Http\\IOutput']; if (!is_null($httpHeaders)) { $io->setHeader($httpHeaders); } foreach ($responseHeaders as $name => $value) { $io->setHeader($name . ': ' . $value); } foreach ($responseCookies as $name => $value) { $expireDate = null; if ($value['expireDate'] instanceof \DateTime) { $expireDate = $value['expireDate']->getTimestamp(); } $io->setCookie($name, $value['value'], $expireDate, $container->getServer()->getWebRoot(), null, $container->getServer()->getRequest()->getServerProtocol() === 'https', true); } if ($response instanceof ICallbackResponse) { $response->callback($io); } else { if (!is_null($output)) { $io->setHeader('Content-Length: ' . strlen($output)); $io->setOutput($output); } } }
/** * @NoAdminRequired // This is necessary, because otherwise OC redirects endlessly * @NoCSRFRequired */ public function index() { if (!$this->container->isAdminUser()) { return $this->responseFactory->createTemplateResponse($this->appName, 'forbidden', array()); } if ($this->getStatusContainer()->getOverallStatus() == \OCA\EasyBackup\StatusContainer::OK) { if ($this->backupService->isLastBackupSuccessful()) { return $this->restore(); } return $this->backup(); } return $this->configuration(); }
/** * @param DIContainer $container * @param ChartConfig $chartConfig */ public function __construct(DIContainer $container, ChartConfig $chartConfig) { $this->chartConfig = $chartConfig; $this->repository = $container->query('StorageUsageRepository'); }