Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Migrated to dflydev/dot-access-configuration for handling configuration.

  • Loading branch information...
commit cddb0254cfe441fddd38dcd6a37a54d114064cda 1 parent a920612
@simensen simensen authored
View
1  composer.json
@@ -21,6 +21,7 @@
"php": ">=5.3.0",
"composer/composer": "1.*",
"dflydev/ant-path-matcher": "1.*",
+ "dflydev/dot-access-configuration": "1.*",
"dflydev/dot-access-data": "1.*",
"dflydev/markdown": "1.*",
"dflydev/placeholder-resolver": "1.*",
View
18 composer.lock
@@ -1,10 +1,10 @@
{
- "hash": "593259eb82b772560a0d42f2baf12827",
+ "hash": "274baba1679d41b1c6b17ff621910717",
"packages": [
{
"package": "composer/composer",
"version": "dev-master",
- "source-reference": "870d7454752098f57532a99627bf455548280414",
+ "source-reference": "903facd64fee3941c4abc3e945982395cfb166b4",
"alias": "1.0.9999999.9999999-dev"
},
{
@@ -12,9 +12,15 @@
"version": "v1.0.1"
},
{
+ "package": "dflydev/dot-access-configuration",
+ "version": "dev-master",
+ "source-reference": "5c357b5db69a467889bddf576823436a50dda7ea",
+ "alias": "1.0.9999999.9999999-dev"
+ },
+ {
"package": "dflydev/dot-access-data",
"version": "dev-master",
- "source-reference": "ffabf1caa83e17fee6de9fa7d9c40f53671baa00",
+ "source-reference": "aaf313232203ddd3e55eab1cce00d5b6cd1ffd36",
"alias": "1.0.9999999.9999999-dev"
},
{
@@ -40,7 +46,7 @@
{
"package": "symfony/console",
"version": "dev-master",
- "source-reference": "f354e1e5d59261ae03c0fc768bfa4043c0e6ab9c",
+ "source-reference": "8c69d3a3e26885cad132a38ab0d7f287fb975296",
"alias": "2.1.9999999.9999999-dev"
},
{
@@ -58,13 +64,13 @@
{
"package": "symfony/finder",
"version": "dev-master",
- "source-reference": "6a0f850cac8cac7a0b33f48d3d3d1514d7ed56f8",
+ "source-reference": "5b8658e52eaf424fe943a5857e2404ce95c3b90e",
"alias": "2.1.9999999.9999999-dev"
},
{
"package": "symfony/process",
"version": "dev-master",
- "source-reference": "9f49693318e1f7824a276da6c6556ff06cd3f25a",
+ "source-reference": "3f95a0126588f00d70e745c1ef96631fb10c3a8e",
"alias": "2.1.9999999.9999999-dev"
},
{
View
41 src/sculpin/configuration/AbstractConfigurationBuilder.php
@@ -0,0 +1,41 @@
+<?php
+
+/*
+ * This file is a part of Sculpin.
+ *
+ * (c) Dragonfly Development Inc.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace sculpin\configuration;
+
+use Dflydev\DotAccessConfiguration\ConfigurationBuilderInterface;
+
+abstract class AbstractConfigurationBuilder
+{
+ private $configurationBuilder;
+
+ /**
+ * Set Configuration Builder
+ *
+ * @param ConfigurationBuilderInterface $configurationBuilder
+ * @return AbstractConfigurationBuilder
+ */
+ protected function setConfigurationBuilder(ConfigurationBuilderInterface $configurationBuilder)
+ {
+ $this->configurationBuilder = $configurationBuilder;
+ $this->configurationBuilder->setConfigurationFactory(new ConfigurationFactory);
+ }
+
+ /**
+ * Build Configuration
+ *
+ * @return Configuration
+ */
+ public function build()
+ {
+ return $this->configurationBuilder->build();
+ }
+}
View
176 src/sculpin/configuration/Configuration.php
@@ -11,134 +11,15 @@
namespace sculpin\configuration;
-use Dflydev\DotAccessData\Data;
+use Dflydev\DotAccessConfiguration\Configuration as BaseConfiguration;
use Dflydev\DotAccessData\Util as DotAccessDataUtil;
-use Dflydev\PlaceholderResolver\PlaceholderResolverInterface;
-use Dflydev\PlaceholderResolver\RegexPlaceholderResolver;
-class Configuration
+class Configuration extends BaseConfiguration
{
- protected $data;
- protected $placeholderResolver;
- protected $exportIsDirty = true;
- protected $resolvedExport;
-
- /**
- * Resolve values
- *
- * For objects, do nothing. For strings, resolve placeholder.
- * For arrays, call resolveValues() on each item.
- */
- protected function resolveValues(&$input = null)
- {
- if (is_array($input)) {
- foreach ($input as $idx => $value) {
- $this->resolveValues($value);
- $input[$idx] = $value;
- }
- } else {
- if (!is_object($input)) {
- $input = $this->placeholderResolver->resolvePlaceholder($input);
- }
- }
- }
-
- /**
- * Constructor
- *
- * @param array|null $config
- */
- public function __construct(array $config = null, PlaceholderResolverInterface $placeholderResolver = null)
- {
- $this->data = new Data($config);
- $this->placeholderResolver = $placeholderResolver ?: new RegexPlaceholderResolver(new ConfigurationDataSource($this), '%', '%');
- }
-
- /**
- * Get a value (with placeholders unresolved)
- *
- * @param string $key
- * @return mixed
- */
- public function getRaw($key)
- {
- return $this->data->get($key);
- }
-
- /**
- * Get a value (with placeholders resolved)
- *
- * @param string $key
- * @return mixed
- */
- public function get($key)
- {
- $value = $this->getRaw($key);
- if (is_object($value)) {
- return $value;
- }
- $this->resolveValues($value);
-
- return $value;
- }
-
- /**
- * Set a value
- *
- * @param string $key
- * @param mixed $value
- */
- public function set($key, $value = null)
- {
- $this->exportIsDirty = true;
-
- return $this->data->set($key, $value);
- }
-
- /**
- * Append a value
- *
- * Will force key to be an array if it is only a string
- *
- * @param string $key
- * @param mixed $value
- */
- public function append($key, $value = null)
- {
- $this->exportIsDirty = true;
-
- return $this->data->append($key, $value);
- }
-
- /**
- * Export configuration data as an associtaive array (with placeholders unresolved)
- *
- * @return array
- */
- public function exportRaw()
- {
- return $this->data->export();
- }
-
- /**
- * Export configuration data as an associtaive array (with placeholders resolved)
- *
- * @return array
- */
- public function export()
- {
- if ($this->exportIsDirty) {
- $this->resolvedExport = $this->data->export();
- $this->resolveValues($this->resolvedExport);
- $this->exportIsDirty = false;
- }
-
- return $this->resolvedExport;
- }
-
/**
* Get a sub Configuration instance
*
+ * @param string $key
* @return Configuration
* @deprecated
*/
@@ -153,43 +34,9 @@ public function getConfiguration($key)
}
/**
- * Underlying Data representation
- *
- * Will have all placeholders resolved.
- *
- * @return Data
- */
- public function data()
- {
- return new Data($this->export());
- }
-
- /**
- * Import another Configuration
- *
- * @param Configuration $imported
- * @param bool $clobber
- */
- public function importRaw($imported, $clobber = true)
- {
- $this->exportIsDirty = true;
-
- $this->data->import($imported, $clobber);
- }
- /**
- * Import another Configuration
- *
- * @param Configuration $imported
- * @param bool $clobber
- */
- public function import(Configuration $imported, $clobber = true)
- {
- return $this->importRaw($imported->exportRaw(), $clobber);
- }
-
- /**
* Get a the configuration value as a pathname from project root
*
+ * @param string $key
* @return string
*/
public function getPath($key)
@@ -206,19 +53,4 @@ public function getPath($key)
return ($this->get('project_root') ?: getcwd()).'/'.$path;
}
-
- /**
- * Resolve placeholders in value from configuration
- *
- * @param string|null $value
- * @return string
- */
- public function resolve($value = null)
- {
- if (null === $value) {
- return null;
- }
-
- return $this->placeholderResolver->resolvePlaceholder($value);
- }
}
View
51 src/sculpin/configuration/ConfigurationDataSource.php
@@ -1,51 +0,0 @@
-<?php
-
-/*
- * This file is a part of Sculpin.
- *
- * (c) Dragonfly Development Inc.
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace sculpin\configuration;
-
-use Dflydev\PlaceholderResolver\DataSource\DataSourceInterface;
-
-class ConfigurationDataSource implements DataSourceInterface
-{
- /**
- * Constructor
- *
- * @param Configuration $configuration
- */
- public function __construct(Configuration $configuration)
- {
- $this->configuration = $configuration;
- }
-
- /**
- * {@inheritdoc}
- */
- public function exists($key, $system = false)
- {
- if ($system) {
- return false;
- }
-
- return null !== $this->configuration->getRaw($key);
- }
-
- /**
- * {@inheritdoc}
- */
- public function get($key, $system = false)
- {
- if ($system) {
- return false;
- }
-
- return $this->configuration->getRaw($key);
- }
-}
View
13 src/sculpin/configuration/IConfigurationBuilder.php → src/sculpin/configuration/ConfigurationFactory.php
@@ -11,12 +11,15 @@
namespace sculpin\configuration;
-interface IConfigurationBuilder {
+use Dflydev\DotAccessConfiguration\ConfigurationFactoryInterface;
+class ConfigurationFactory implements ConfigurationFactoryInterface
+{
/**
- * Build a configuration
- * @return array
+ * {@inheritdocs}
*/
- public function build();
-
+ public function create()
+ {
+ return new Configuration;
+ }
}
View
30 src/sculpin/configuration/YamlConfigurationBuilder.php
@@ -11,35 +11,17 @@
namespace sculpin\configuration;
-use Symfony\Component\Yaml\Yaml;
-
-class YamlConfigurationBuilder implements IConfigurationBuilder {
-
- /**
- * YAML input string
- * @var string
- */
- private $input;
+use Dflydev\DotAccessConfiguration\YamlConfigurationBuilder as BaseYamlConfigurationBuilder;
+class YamlConfigurationBuilder extends AbstractConfigurationBuilder
+{
/**
* Constructor
- * @param string $input
+ *
+ * @param array $yamlConfigurationFilenames
*/
public function __construct($input = null)
{
- $this->input = $input;
- }
-
- /**
- * (non-PHPdoc)
- * @see sculpin\configuration.IConfigurationBuilder::build()
- */
- public function build()
- {
- if ($this->input) {
- return new Configuration(Yaml::parse($this->input));
- }
- return new Configuration(array());
+ $this->setConfigurationBuilder(new BaseYamlConfigurationBuilder($input));
}
-
}
View
64 src/sculpin/configuration/YamlFileConfigurationBuilder.php
@@ -11,18 +11,10 @@
namespace sculpin\configuration;
-use Dflydev\DotAccessData\Util as DotAccessDataUtil;
-use Symfony\Component\Yaml\Yaml;
-
-class YamlFileConfigurationBuilder implements IConfigurationBuilder {
-
- /**
- * YAML Configuration Filenames
- *
- * @var array
- */
- private $yamlConfigurationFilenames;
+use Dflydev\DotAccessConfiguration\YamlFileConfigurationBuilder as BaseYamlFileConfigurationBuilder;
+class YamlFileConfigurationBuilder extends AbstractConfigurationBuilder
+{
/**
* Constructor
*
@@ -30,54 +22,6 @@ class YamlFileConfigurationBuilder implements IConfigurationBuilder {
*/
public function __construct(array $yamlConfigurationFilenames)
{
- $this->yamlConfigurationFilenames = $yamlConfigurationFilenames;
+ $this->setConfigurationBuilder(new BaseYamlFileConfigurationBuilder($yamlConfigurationFilenames));
}
-
- /**
- * {@inheritdocs}
- */
- public function build()
- {
- $config = array();
- $imports = array();
- foreach ($this->yamlConfigurationFilenames as $yamlConfigurationFilename) {
- if (file_exists($yamlConfigurationFilename)) {
- $config = DotAccessDataUtil::mergeAssocArray($config, Yaml::parse($yamlConfigurationFilename));
- if (isset($config['imports'])) {
- foreach ((array) $config['imports'] as $file) {
- if (0 === strpos($file, '/')) {
- // Absolute path
- $imports[] = $file;
- } else {
- if ($realpath = realpath(dirname($yamlConfigurationFilename).'/'.$file)) {
- $imports[] = $realpath;
- }
- }
- }
- }
- }
- }
-
- $configuration = new Configuration;
- if ($imports) {
- $importsBuilder = new static($imports);
-
- $configuration->import($importsBuilder->build());
-
- $internalImports = $configuration->get('imports');
- } else {
- $internalImports = null;
- }
-
- $configuration->importRaw($config);
-
- if ($internalImports) {
- foreach ((array) $internalImports as $import) {
- $configuration->append('imports', $import);
- }
- }
-
- return $configuration;
- }
-
}
Please sign in to comment.
Something went wrong with that request. Please try again.