protected function execute(InputInterface $input, OutputInterface $output) { $rc = 0; $default_environment = \Config::getEnvironment(); $environment = $input->getOption('environment') ?: $default_environment; $file_system = new Filesystem(); $file_loader = new FileLoader($file_system); if ($input->getOption('generated-overrides')) { $file_saver = new FileSaver($file_system, $environment == $default_environment ? null : $environment); } else { $file_saver = new DirectFileSaver($file_system, $environment == $default_environment ? null : $environment); } $this->repository = new Repository($file_loader, $file_saver, $environment); try { $item = $input->getArgument('item'); switch ($input->getArgument('operation')) { case self::OPERATION_GET: $output->writeln($this->serialize($this->repository->get($item))); break; case self::OPERATION_SET: $value = $input->getArgument('value'); if (!isset($value)) { throw new Exception('Missing new configuration value'); } $this->repository->save($item, $this->unserialize($value)); break; default: throw new Exception('Invalid operation specified. Allowed operations: ' . implode(', ', $this->getAllowedOperations())); } } catch (Exception $x) { $output->writeln('<error>' . $x->getMessage() . '</error>'); $rc = 1; } return $rc; }
private function shouldTranslateBaseLocale() { // Backwards compatibility if ($this->config->get('concrete.misc.enable_translate_locale_en_us')) { return true; } return $this->config->get('concrete.misc.enable_translate_locale_base_locale'); }
public function testSaveNamespace() { $namespace = md5(uniqid()); $group = md5(uniqid()); $item = 'test.item'; $key = "{$namespace}::{$group}.{$item}"; $this->repository->save($key, $namespace); $this->assertEquals($namespace, $this->repository->get($key, false)); $this->files->deleteDirectory(DIR_APPLICATION . "/config/generated_overrides/{$namespace}/"); }
/** * @param \Concrete\Core\Http\Middleware\DelegateInterface $frame * @return Response */ public function process(Request $request, DelegateInterface $frame) { $response = $frame->next($request); if ($response->headers->has('X-Frame-Options') === false) { $x_frame_options = $this->config->get('concrete.security.misc.x_frame_options'); if ($this->stringValidator->notempty($x_frame_options)) { $response->headers->set('X-Frame-Options', $x_frame_options); } } return $response; }
public function testSaveMultiple() { $tests = array('namespace::group.test.key', 'namespace::group2.test.key', 'namespace2::group.test.key', 'namespace2::group2.test.key', 'group.test.key', 'group2.test.key', 'group.new.key', 'group2.new.key'); $values = array(); foreach ($tests as $test) { $this->repository->save($test, $values[] = uniqid($test)); } $this->repository->clearCache(); foreach ($tests as $test) { $this->assertEquals(array_shift($values), $this->repository->get($test), "Failed test verification for key '{$test}'."); } }
/** * Create a service object given a ServiceFactory object * * @param \OAuth\ServiceFactory $factory * @return \OAuth\Common\Service\ServiceInterface */ public function createService(ServiceFactory $factory) { $appId = $this->config->get('auth.community.appid'); $appSecret = $this->config->get('auth.community.secret'); // Get the callback url /** @var Url $callbackUrl */ $callbackUrl = $this->urlResolver->resolve(['/ccm/system/authentication/oauth2/community/callback/']); if ($callbackUrl->getHost() == '') { $callbackUrl = $callbackUrl->setHost($this->request->getHost()); $callbackUrl = $callbackUrl->setScheme($this->request->getScheme()); } // Create a credential object with our ID, Secret, and callback url $credentials = new Credentials($appId, $appSecret, (string) $callbackUrl); // Create a new session storage object and pass it the active session $storage = new SymfonySession($this->session, false); // Create the service using the oauth service factory return $factory->createService('community', $credentials, $storage); }
/** * Create a service object given a ServiceFactory object * * @return \OAuth\Common\Service\ServiceInterface */ public function createService() { $appId = $this->config->get('auth.twitter.appid'); $appSecret = $this->config->get('auth.twitter.secret'); $verifyPeer = $this->config->get('app.curl.verifyPeer'); /** @var ServiceFactory $factory */ $factory = $this->app->make('oauth/factory/service', array(CURLOPT_SSL_VERIFYPEER => $verifyPeer)); // Get the callback url $callbackUrl = $this->urlResolver->resolve(['/ccm/system/authentication/oauth2/twitter/callback/']); if ($callbackUrl->getHost() == '') { $callbackUrl = $callbackUrl->setHost($this->request->getHost()); $callbackUrl = $callbackUrl->setScheme($this->request->getScheme()); } // Create a credential object with our ID, Secret, and callback url $credentials = new Credentials($appId, $appSecret, (string) $callbackUrl); // Create a new session storage object and pass it the active session $storage = new SymfonySession($this->session, false); // Create the service using the oauth service factory return $factory->createService('twitter', $credentials, $storage); }
/** * @inheritdoc */ public function collection(Collection $collection, $code = Response::HTTP_OK, $headers = array()) { if (!$this->app) { throw new \RuntimeException('Cannot resolve collections without a reference to the application'); } $request = $this->request; if ($collection->isError() && $collection->getError() == COLLECTION_NOT_FOUND) { if ($response = $this->collectionNotFound($collection, $request, $headers)) { return $response; } } if ($collection->getCollectionPath() != '/page_not_found') { if (!isset($collection->cPathFetchIsCanonical) || !$collection->cPathFetchIsCanonical) { // Handle redirect URL (additional page paths) /** @var Url $url */ $url = $this->app->make('url/manager')->resolve([$collection]); $query = $url->getQuery(); $query->modify($request->getQueryString()); $url = $url->setQuery($query); return $this->redirect($url, Response::HTTP_MOVED_PERMANENTLY, $headers); } } // maintenance mode if ($collection->getCollectionPath() != '/login') { $smm = $this->config->get('concrete.maintenance_mode'); if ($smm == 1 && !Key::getByHandle('view_in_maintenance_mode')->validate() && ($_SERVER['REQUEST_METHOD'] != 'POST' || Loader::helper('validation/token')->validate() == false)) { $v = new View('/frontend/maintenance_mode'); $router = $this->app->make(RouterInterface::class); $tmpTheme = $router->getThemeByRoute('/frontend/maintenance_mode'); $v->setViewTheme($tmpTheme[0]); $v->addScopeItems(['c' => $collection]); $request->setCurrentPage($collection); if (isset($tmpTheme[1])) { $v->setViewTemplate($tmpTheme[1]); } return $this->view($v, $code, $headers); } } if ($collection->getCollectionPointerExternalLink() != '') { return $this->redirect($collection->getCollectionPointerExternalLink()); } $cp = new Checker($collection); if ($cp->isError() && $cp->getError() == COLLECTION_FORBIDDEN) { return $this->forbidden($request->getUri(), Response::HTTP_FORBIDDEN, $headers); } if (!$collection->isActive() && !$cp->canViewPageVersions()) { return $this->notFound('', Response::HTTP_NOT_FOUND, $headers); } $scheduledVersion = Version::get($collection, "SCHEDULED"); if ($publishDate = $scheduledVersion->cvPublishDate) { $datetime = $this->app->make('helper/date'); $now = $datetime->date('Y-m-d G:i:s'); if (strtotime($now) >= strtotime($publishDate)) { $scheduledVersion->approve(); $collection->loadVersionObject('ACTIVE'); } } if ($cp->canEditPageContents() || $cp->canEditPageProperties() || $cp->canViewPageVersions()) { $collection->loadVersionObject('RECENT'); } $vp = new Checker($collection->getVersionObject()); // returns the $vp object, which we then check if (is_object($vp) && $vp->isError()) { switch ($vp->getError()) { case COLLECTION_NOT_FOUND: return $this->notFound('', Response::HTTP_NOT_FOUND, $headers); break; case COLLECTION_FORBIDDEN: return $this->forbidden($request->getUri(), Response::HTTP_FORBIDDEN, $headers); break; } } // Now that we've passed all permissions checks, and we have a page, we check to see if we // ought to redirect based on base url or trailing slash settings $cms = $this->app; $site = $this->app['site']->getSite(); $response = $cms->handleCanonicalURLRedirection($request, $site); if (!$response) { $response = $cms->handleURLSlashes($request, $site); } if (isset($response)) { return $response; } $dl = $cms->make('multilingual/detector'); if ($dl->isEnabled()) { $dl->setupSiteInterfaceLocalization($collection); } if (!$request->getPath() && $request->isMethod('GET') && !$request->query->has('cID')) { // This is a request to the home page –http://www.mysite.com/ // First, we check to see if we need to redirect to a default multilingual section. if ($dl->isEnabled() && $site->getConfigRepository()->get('multilingual.redirect_home_to_default_locale')) { // Let's retrieve the default language $ms = $dl->getPreferredSection(); if (is_object($ms)) { return $this->redirect(\URL::to($ms)); } } // Otherwise, let's check to see if our home page, which we have loaded already, has a path (like /en) // If it does, we'll redirect to the path. if ($collection->getCollectionPath() != '') { return $this->redirect(\URL::to($collection)); } } $request->setCurrentPage($collection); $c = $collection; // process.php needs this require DIR_BASE_CORE . '/bootstrap/process.php'; $u = new User(); // On page view event. $pe = new Event($collection); $pe->setUser($u); $pe->setRequest($request); $this->app['director']->dispatch('on_page_view', $pe); // Core menu items $item = new RelationListItem(); $menu = $this->app->make('helper/concrete/ui/menu'); $menu->addMenuItem($item); $controller = $collection->getPageController(); // we update the current page with the one bound to this controller. $collection->setController($controller); return $this->controller($controller); }
/** * @param $key * @param null $default * * @return mixed */ public function get($key, $default = null) { return $this->repository->get($this->transformKey($key), $default); }
/** * @return bool */ private function shouldCompareAgent() { return $this->config->get('concrete.security.session.invalidate_on_user_agent_mismatch', true); }
/** * Does support legacy namespace with src * * @return bool */ private function isLegacy() { return $this->config->get('app.enable_legacy_src_namespace'); }
public function testGet() { $this->repository->set('default::test.get', $this); $this->assertEquals($this, $this->repository->get('default::test.get')); $this->assertEquals($this, $this->repository->get('default::test.cantget', $this)); }