/** * @see BackBee\Config\Persistor\PersistorInterface::persist */ public function persist(Config $config, array $configToPersist) { if (array_key_exists('override_site', $configToPersist)) { $configToPersist = array('override_site' => $configToPersist['override_site']); } $key = $this->application->getContainer()->get('bundle.loader')->getBundleIdByBaseDir($config->getBaseDir()); if (null === $key) { $key = 'application'; } $scope = $this->getScope($key); $registry = $this->application->getEntityManager()->getRepository('BackBee\\Bundle\\Registry')->findOneBy(array('key' => $key, 'scope' => $scope)); if (null === $registry) { $registry = new RegistryEntity(); $registry->setKey($key); $registry->setScope($scope); $this->application->getEntityManager()->persist($registry); } $registry->setValue(serialize($configToPersist)); $success = true; try { $this->application->getEntityManager()->flush($registry); } catch (\Exception $e) { $success = false; } return $success; }
/** * Load and override services into container; the load order is from the most global to the most specific * depends on context and environment. */ private function loadApplicationServices() { // setting default services $this->container->set('bbapp', $this->application); $this->container->set('container.builder', $this); $services_directory = $this->application->getBBDir() . '/Config/services'; foreach (scandir($services_directory) as $file) { if (1 === preg_match('#(\\w+)\\.(yml|xml)$#', $file, $matches)) { if ('yml' === $matches[2]) { ServiceLoader::loadServicesFromYamlFile($this->container, $services_directory, $matches[1]); } else { ServiceLoader::loadServicesFromXmlFile($this->container, $services_directory, $matches[1]); } } } // define in which directory we have to looking for services yml or xml $directories = ConfigDirectory::getDirectories(null, $this->repository_directory, $this->context, $this->environment); // Loop into every directory where we can potentially found a services.yml or services.xml foreach ($directories as $directory) { if (true === is_readable($directory . DIRECTORY_SEPARATOR . self::SERVICE_FILENAME . '.yml')) { ServiceLoader::loadServicesFromYamlFile($this->container, $directory); } if (true === is_readable($directory . DIRECTORY_SEPARATOR . self::SERVICE_FILENAME . '.xml')) { ServiceLoader::loadServicesFromXmlFile($this->container, $directory); } } $this->loadLoggerDefinition(); }
/** * @param string $controllerName * @param string $actionName */ protected function createController($controllerName, $actionName = null) { $controllerClass = null; if (null === $actionName) { // support for ControllerClass::methodName notation if (false !== strpos($controllerName, '::')) { list($controllerClass, $actionName) = explode('::', $controllerName, 2); } else { throw new \LogicException(sprintf('Unable to extract controller action from "%s".', $controllerName)); } } else { $controllerClass = $controllerName; } if (null === $controllerClass) { throw new \InvalidArgumentException(sprintf('Controller class couldn\'t be resolved for "%s".', $controllerName)); } if (class_exists($controllerClass)) { $controller = new $controllerClass(); if ($controller instanceof ContainerAwareInterface) { $controller->setContainer($this->bbapp->getContainer()); } } else { // support for service id $controller = $this->bbapp->getContainer()->get($controllerClass); } return array($controller, $actionName); }
/** * Reverts a content to a specific revision. * * @param AbstractClassContent $content The content to revert. * @param integer $revision The revision number. * * @return ClassContentManager The current class content manager. */ public function revertToRevision(AbstractClassContent $content, $revision) { // First remove existing draft for user if (null !== ($draft = $this->getDraft($content))) { $this->entityManager->remove($draft); } // If asked $revision is the last one, all is done. if ($content->getRevision() === (int) $revision) { return $this; } $source = $this->entityManager->getRepository('BackBee\\ClassContent\\Revision')->getRevision($content, (int) $revision); if (null === $source) { throw new \InvalidArgumentException(sprintf('Unknown revision %d for content %s.', $revision, $content->getObjectIdentifier())); } $token = $this->token ?: $this->app->getBBUserToken(); $draft = clone $source; $draft->setOwner($token->getUser()); $draft->setRevision($content->getRevision()); $draft->setState(Revision::STATE_MODIFIED); $draft->setComment(sprintf('Revert to revision %d.', $revision)); $draft->setCreated(); $draft->setModified(); $this->entityManager->persist($draft); $content->setDraft($draft); return $this; }
/** * Returns path to the right directory to dump and save config.yml file. * * @param string $baseDir config base directory * * @return string */ private function getConfigDumpRightDirectory($baseDir) { $configDumpDir = $this->app->getBaseRepository(); if ($this->persistPerContext && ApplicationInterface::DEFAULT_CONTEXT !== $this->app->getContext()) { $configDumpDir .= DIRECTORY_SEPARATOR . $this->app->getContext(); } $configDumpDir .= DIRECTORY_SEPARATOR . 'Config'; if ($this->persistPerEnvironment && ApplicationInterface::DEFAULT_ENVIRONMENT !== $this->app->getEnvironment()) { $configDumpDir .= DIRECTORY_SEPARATOR . $this->app->getEnvironment(); } $key = $this->app->getContainer()->get('bundle.loader')->getBundleIdByBaseDir($baseDir); if (null !== $key) { $configDumpDir .= DIRECTORY_SEPARATOR . 'bundle' . DIRECTORY_SEPARATOR . $key; } if (!is_dir($configDumpDir) && false === @mkdir($configDumpDir, 0755, true)) { throw new \Exception('Unable to create config dump directory'); } return $configDumpDir; }
/** * Returns the current site if defined. * * @param Site|null $site Optional, if provided, will be return. * * @return Site|null */ private function getCurrentSite(Site $site = null) { if (null !== $site) { return $site; } if (null !== $this->application) { return $this->application->getSite(); } return null; }
/** * Adds bundle's resources directory into application. * * @param Config $config * @param callable|null $recipe */ private function addResourcesDir(Config $config, callable $recipe = null) { if (false === $this->runRecipe($config, $recipe)) { $baseDir = dirname($config->getBaseDir()) . DIRECTORY_SEPARATOR; $directory = realpath($baseDir . DIRECTORY_SEPARATOR . 'Resources'); if (false === $directory) { $directory = realpath($baseDir . DIRECTORY_SEPARATOR . 'Ressources'); } if (false !== $directory) { $this->application->pushResourceDir($directory); } } }
/** * Getter of class content thumbnails folder paths * * @return array The class content thumbnails flder path if found, null otherwise. */ private function getThumbnailBaseFolderPaths() { if (is_array($this->thumbnailBaseDir)) { return $this->thumbnailBaseDir; } $this->thumbnailBaseDir = []; if (null !== ($baseFolder = $this->getBaseFolder())) { $thumbnailBaseDir = array_map(function ($directory) use($baseFolder) { return str_replace(DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, $directory . DIRECTORY_SEPARATOR . $baseFolder); }, $this->application->getResourceDir()); foreach (array_unique($thumbnailBaseDir) as $directory) { if (is_dir($directory)) { $this->thumbnailBaseDir[] = $directory; } } } return $this->thumbnailBaseDir; }
/** * Returns the registry entry for bundle's config storing. * * @param string $bundleId The id of the bundle we are looking for override config in registry. * @param boolean $scopePerContext If TRUE use context in registry scope. * @param boolean $scopePerEnvironment If TRUE use environment in regsitry scope. * * @return \BackBee\Bundle\Registry|NULL */ private function getRegistryConfig($bundleId, $scopePerContext, $scopePerEnvironment) { $registry = null; try { if (null !== ($em = $this->application->getEntityManager())) { $registry = $em->getRepository('BackBee\\Bundle\\Registry')->findOneBy(array('key' => $bundleId, 'scope' => $this->getRegistryScope('BUNDLE_CONFIG', $scopePerContext, $scopePerEnvironment))); } } catch (DBALException $e) { $expectedError = false; if (null !== $e->getPrevious() && $e->getPrevious() instanceof \PDOException) { // expected error is if we try to get overrided config in registry on application installation process // PDOException has two methods for retrieving information about an error // @see http://php.net/manual/en/class.pdoexception.php $expectedError = '42S02' === $e->getPrevious()->getCode() || false !== strpos($e->getPrevious()->getMessage(), 'SQLSTATE[42S02]'); } if (false === $expectedError) { throw $e; } } return $registry; }
/** * CategoryManager's constructor. * * @param ApplicationInterface $application application from where we will extract classcontent's categories */ public function __construct(ApplicationInterface $application) { $this->categories = []; $this->options = ['thumbnail_url_pattern' => $application->getRouting()->getUrlByRouteName('bb.classcontent_thumbnail', ['filename' => '%s.' . $application->getContainer()->getParameter('classcontent_thumbnail.extension')])]; $this->loadCategoriesFromClassContentDirectories($application->getClassContentDir()); }
/** * Returns current revision for the given $content * * @param AbstractClassContent $content The content we want to get the latest revision * @param boolean $checkoutOnMissing If TRUE, checkout a new revision for $content * * @return null|Revision */ public function getDraft(AbstractClassContent $content, $checkoutOnMissing = false) { return $this->entityManager->getRepository('BackBee\\ClassContent\\Revision')->getDraft($content, $this->token ?: $this->app->getBBUserToken(), $checkoutOnMissing); }
/** * ContainerBuilder's constructor;. * * @param BackBee\ApplicationInterface $application the application we want to build a container for */ public function __construct(ApplicationInterface $application) { $this->application = $application; $this->repository_directory = $application->getBaseRepository(); $this->context = $application->getContext(); $this->environment = $application->getEnvironment(); }
/** * Loads ToolbarBundle and BBCoreJs resources directories into application. * * @param BBApplication $application * @param Config $config */ public static function loadResources(ApplicationInterface $application, Config $config) { $baseDir = $application->getContainer()->get('bundle.theme')->getBaseDirectory(); $application->addResourceDir($baseDir . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'resources'); }
/** * @see BackBee\Bundle\BundleInterface::getEntityManager */ public function getEntityManager() { return $this->application->getEntityManager(); }
/** * Returns the validator service. * * @access public * * @return \Symfony\Component\Validator\ValidatorInterface */ public function getValidator() { return $this->application->getValidator(); }
/** * @param ApplicationInterface $application */ public function __construct(ApplicationInterface $application) { $this->application = $application; $this->container = $application->getContainer(); }
/** * {@inheritdoc} */ public function __construct(ApplicationInterface $application, $persistPerContext, $persistPerEnvironment) { $this->container = $application->getContainer(); }
/** * Instantiate a ClassContentManager. * * @param ApplicationInterface $application */ public function __construct(ApplicationInterface $application) { $this->application = $application; $this->em = $application->getEntityManager(); $this->categoryManager = $application->getContainer()->get('classcontent.category_manager'); }