/** * The constructor requires a resource manager object to perform checks against. * This should ideally be typehinted to Bolt\Configuration\ResourceManager. * * @param ResourceManager $config */ public function __construct($config = null) { parent::__construct($config); $this->addCheck('publicAssets'); $this->addCheck('database', true); $this->addCheck('config', true); }
/** * Constructor. * * @param Controller\Exception $exceptionController * @param Config $config * @param ResourceManager $resourceManager */ public function __construct(Controller\Exception $exceptionController, Config $config, ResourceManager $resourceManager) { parent::__construct($resourceManager); $this->exceptionController = $exceptionController; $this->configManager = $config; $this->resourceManager = $resourceManager; }
protected function getCleanChecker() { $config = new Standard(TEST_ROOT); $check = new LowlevelChecks($config); $check->removeCheck('cache'); $check->configChecks = []; return $check; }
/** * Initialize the database providers. */ public function initDatabase() { $dboptions = $this['config']->getDBOptions(); $this->register(new Silex\Provider\DoctrineServiceProvider(), array('db.options' => $dboptions)); // Do a dummy query, to check for a proper connection to the database. try { $this['db']->query("SELECT 1;"); } catch (\PDOException $e) { $error = "Bolt could not connect to the database. Make sure the database is configured correctly in\n <code>app/config/config.yml</code>, that the database engine is running."; if ($dboptions['driver'] != 'pdo_sqlite') { $error .= "<br><br>Since you're using " . $dboptions['driver'] . ", you should also make sure that the\n database <code>" . $dboptions['dbname'] . "</code> exists, and the configured user has access to it."; } $checker = new Configuration\LowlevelChecks($this['resources']); $checker->lowLevelError($error); } if ($dboptions['driver'] == 'pdo_sqlite') { $this['db']->query('PRAGMA synchronous = OFF'); } elseif ($dboptions['driver'] == 'pdo_mysql') { /** * @link https://groups.google.com/forum/?fromgroups=#!topic/silex-php/AR3lpouqsgs */ $this['db']->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); // set utf8 on names and connection as all tables has this charset $this['db']->query("SET NAMES 'utf8';"); $this['db']->query("SET CHARACTER SET 'utf8';"); $this['db']->query("SET CHARACTER_SET_CONNECTION = 'utf8';"); } $this->register(new Silex\Provider\HttpCacheServiceProvider(), array('http_cache.cache_dir' => $this['resources']->getPath('cache'))); }
/** * Load the configuration from the various YML files. */ public function getConfig() { $config = array(); // Read the config $config['general'] = array_merge($this->parseConfigYaml('config.yml'), $this->parseConfigYaml('config_local.yml')); $config['taxonomy'] = $this->parseConfigYaml('taxonomy.yml'); $tempContentTypes = $this->parseConfigYaml('contenttypes.yml'); $config['menu'] = $this->parseConfigYaml('menu.yml'); $config['routing'] = $this->parseConfigYaml('routing.yml'); $config['permissions'] = $this->parseConfigYaml('permissions.yml'); $config['extensions'] = array(); // fetch the theme config. requires special treatment due to the path $this->app['resources']->initializeConfig($config); $paths = $this->app['resources']->getPaths(); $themeConfigFile = $paths['themepath'] . '/config.yml'; $config['theme'] = $this->parseConfigYaml($themeConfigFile, array(), false); // @todo: If no config files can be found, get them from bolt.cm/files/default/ $this->paths = $this->app['resources']->getPaths(); $this->setDefaults(); // Make sure old settings for 'contentsCss' are still picked up correctly if (isset($config['general']['wysiwyg']['ck']['contentsCss'])) { $config['general']['wysiwyg']['ck']['contentsCss'] = array(1 => $config['general']['wysiwyg']['ck']['contentsCss']); } // Make sure old settings for 'accept_file_types' are not still picked up. Before 1.5.4 we used to store them // as a regex-like string, and we switched to an array. If we find the old style, fall back to the defaults. if (isset($config['general']['accept_file_types']) && !is_array($config['general']['accept_file_types'])) { unset($config['general']['accept_file_types']); } // Merge the array with the defaults. Setting the required values that aren't already set. $config['general'] = array_merge_recursive_distinct($this->defaultConfig, $config['general']); // Make sure the cookie_domain for the sessions is set properly. if (empty($config['general']['cookies_domain'])) { if (isset($_SERVER['HTTP_HOST'])) { $hostname = $_SERVER['HTTP_HOST']; } elseif (isset($_SERVER['SERVER_NAME'])) { $hostname = $_SERVER['SERVER_NAME']; } else { $hostname = ''; } // Don't set the domain for a cookie on a "TLD" - like 'localhost', or if the server_name is an IP-address if (strpos($hostname, '.') > 0 && preg_match("/[a-z0-9]/i", $hostname)) { if (preg_match("/^www[0-9]*./", $hostname)) { $config['general']['cookies_domain'] = '.' . preg_replace("/^www[0-9]*./", '', $hostname); } else { $config['general']['cookies_domain'] = '.' . $hostname; } // Make sure we don't have consecutive '.'-s in the cookies_domain.. $config['general']['cookies_domain'] = str_replace('..', '.', $config['general']['cookies_domain']); } else { $config['general']['cookies_domain'] = ''; } } // Make sure Bolt's mount point is OK: $config['general']['branding']['path'] = '/' . safeString($config['general']['branding']['path']); // Make sure $config['taxonomy'] is an array. (if the file is empty, YAML parses it as NULL) if (empty($config['taxonomy'])) { $config['taxonomy'] = array(); } // Clean up taxonomies foreach ($config['taxonomy'] as $key => $value) { if (!isset($config['taxonomy'][$key]['name'])) { $config['taxonomy'][$key]['name'] = ucwords($config['taxonomy'][$key]['slug']); } if (!isset($config['taxonomy'][$key]['singular_name'])) { if (isset($config['taxonomy'][$key]['singular_slug'])) { $config['taxonomy'][$key]['singular_name'] = ucwords($config['taxonomy'][$key]['singular_slug']); } else { $config['taxonomy'][$key]['singular_name'] = ucwords($config['taxonomy'][$key]['slug']); } } if (!isset($config['taxonomy'][$key]['slug'])) { $config['taxonomy'][$key]['slug'] = strtolower(safeString($config['taxonomy'][$key]['name'])); } if (!isset($config['taxonomy'][$key]['singular_slug'])) { $config['taxonomy'][$key]['singular_slug'] = strtolower(safeString($config['taxonomy'][$key]['singular_name'])); } if (!isset($config['taxonomy'][$key]['has_sortorder'])) { $config['taxonomy'][$key]['has_sortorder'] = false; } // Make sure the options are $key => $value pairs, and not have implied integers for keys. if (!empty($config['taxonomy'][$key]['options']) && is_array($config['taxonomy'][$key]['options'])) { $options = array(); // FIXME using $value variable seems bad idea because of outer loop uses too foreach ($config['taxonomy'][$key]['options'] as $optionkey => $value) { if (is_numeric($optionkey)) { $optionkey = makeSlug($value); // was: strtolower(safeString($value)); } $options[$optionkey] = $value; } $config['taxonomy'][$key]['options'] = $options; } // If taxonomy is like tags, set 'tagcloud' to true by default. if ($config['taxonomy'][$key]['behaves_like'] == 'tags' && !isset($config['taxonomy'][$key]['tagcloud'])) { $config['taxonomy'][$key]['tagcloud'] = true; } } // Clean up contenttypes $config['contenttypes'] = array(); foreach ($tempContentTypes as $key => $temp) { // If the slug isn't set, and the 'key' isn't numeric, use that as the slug. if (!isset($temp['slug']) && !is_numeric($key)) { $temp['slug'] = makeSlug($key); } // If neither 'name' nor 'slug' is set, we need to warn the user. Same goes for when // neither 'singular_name' nor 'singular_slug' is set. if (!isset($temp['name']) && !isset($temp['slug'])) { $error = sprintf("In contenttype <code>%s</code>, neither 'name' nor 'slug' is set. Please edit <code>contenttypes.yml</code>, and correct this.", $key); $llc = new Configuration\LowlevelChecks($this->app['resources']); $llc->lowlevelError($error); } if (!isset($temp['singular_name']) && !isset($temp['singular_slug'])) { $error = sprintf("In contenttype <code>%s</code>, neither 'singular_name' nor 'singular_slug' is set. Please edit <code>contenttypes.yml</code>, and correct this.", $key); $llc = new Configuration\LowlevelChecks($this->app['resources']); $llc->lowlevelError($error); } if (!isset($temp['slug'])) { $temp['slug'] = makeSlug($temp['name']); } if (!isset($temp['singular_slug'])) { $temp['singular_slug'] = makeSlug($temp['singular_name']); } if (!isset($temp['show_on_dashboard'])) { $temp['show_on_dashboard'] = true; } if (!isset($temp['show_in_menu'])) { $temp['show_in_menu'] = true; } if (!isset($temp['sort'])) { $temp['sort'] = ''; } if (!isset($temp['default_status'])) { $temp['default_status'] = 'draft'; } // Make sure all fields are lowercase and 'safe'. $tempfields = $temp['fields']; $temp['fields'] = array(); // Set a default group and groups array. $currentgroup = false; $temp['groups'] = array(); foreach ($tempfields as $key => $value) { // FIXME Fix name 'keys' for fields $key = str_replace('-', '_', strtolower(safeString($key, true))); $temp['fields'][$key] = $value; // If field is a "file" type, make sure the 'extensions' are set, and it's an array. if ($temp['fields'][$key]['type'] == 'file' || $temp['fields'][$key]['type'] == 'filelist') { if (empty($temp['fields'][$key]['extensions'])) { $temp['fields'][$key]['extensions'] = array_intersect(array('doc', 'docx', 'txt', 'md', 'pdf', 'xls', 'xlsx', 'ppt', 'pptx', 'csv'), $config['general']['accept_file_types']); } if (!is_array($temp['fields'][$key]['extensions'])) { $temp['fields'][$key]['extensions'] = array($temp['fields'][$key]['extensions']); } } // If field is an "image" type, make sure the 'extensions' are set, and it's an array. if ($temp['fields'][$key]['type'] == 'image' || $temp['fields'][$key]['type'] == 'imagelist') { if (empty($temp['fields'][$key]['extensions'])) { $temp['fields'][$key]['extensions'] = array_intersect(array('gif', 'jpg', 'jpeg', 'png'), $config['general']['accept_file_types']); } if (!is_array($temp['fields'][$key]['extensions'])) { $temp['fields'][$key]['extensions'] = array($temp['fields'][$key]['extensions']); } } // If the field has a 'group', make sure it's added to the 'groups' array, so we can turn // them into tabs while rendering. This also makes sure that once you started with a group, // all others have a group too. if (!empty($temp['fields'][$key]['group'])) { $currentgroup = $temp['fields'][$key]['group']; $temp['groups'][] = $currentgroup; } else { $temp['fields'][$key]['group'] = $currentgroup; } } // Make sure the 'uses' of the slug is an array. if (isset($temp['fields']['slug']) && isset($temp['fields']['slug']['uses']) && !is_array($temp['fields']['slug']['uses'])) { $temp['fields']['slug']['uses'] = array($temp['fields']['slug']['uses']); } // Make sure taxonomy is an array. if (isset($temp['taxonomy']) && !is_array($temp['taxonomy'])) { $temp['taxonomy'] = array($temp['taxonomy']); } // when adding relations, make sure they're added by their slug. Not their 'name' or 'singular name'. if (!empty($temp['relations']) && is_array($temp['relations'])) { // FIXME using variable $key seems a bad idea while outer loop uses the same foreach ($temp['relations'] as $key => $relation) { if ($key != makeSlug($key)) { $temp['relations'][makeSlug($key)] = $temp['relations'][$key]; unset($temp['relations'][$key]); } } } // Make sure the 'groups' has unique elements, if there are any. if (!empty($temp['groups'])) { $temp['groups'] = array_unique($temp['groups']); } else { unset($temp['groups']); } $config['contenttypes'][$temp['slug']] = $temp; } // Set all the distinctive arrays as part of our Config object. $this->data = $config; }