Overview

Namespaces

  • Autarky
    • Config
      • Loaders
    • Console
    • Container
      • Exception
      • Factory
      • Proxy
    • Database
    • Errors
    • Events
    • Files
    • Http
    • Logging
    • Providers
    • Routing
      • Events
    • Testing
    • TwigTemplating
      • Extensions
    • Utils

Classes

  • Autarky\Application
  • Autarky\Config\ConfigProvider
  • Autarky\Config\FileStore
  • Autarky\Config\LoaderFactory
  • Autarky\Config\Loaders\CachingYamlFileLoader
  • Autarky\Config\Loaders\PhpFileLoader
  • Autarky\Config\Loaders\YamlFileLoader
  • Autarky\Console\Application
  • Autarky\Console\Command
  • Autarky\Console\RouteDispatchCommand
  • Autarky\Console\RouteListCommand
  • Autarky\Container\Container
  • Autarky\Container\ContainerProvider
  • Autarky\Container\Factory\AbstractArgument
  • Autarky\Container\Factory\ClassArgument
  • Autarky\Container\Factory\Definition
  • Autarky\Container\Factory\Factory
  • Autarky\Container\Factory\ScalarArgument
  • Autarky\Container\Proxy\AbstractProxy
  • Autarky\Container\Proxy\ProxyProvider
  • Autarky\Database\ConnectionManager
  • Autarky\Database\DatabaseProvider
  • Autarky\Errors\ErrorHandlerManager
  • Autarky\Errors\ErrorHandlerProvider
  • Autarky\Errors\StubErrorHandler
  • Autarky\Events\EventDispatcher
  • Autarky\Events\EventDispatcherProvider
  • Autarky\Files\LockingFilesystem
  • Autarky\Files\PathResolver
  • Autarky\Http\CookieMiddleware
  • Autarky\Http\CookieProvider
  • Autarky\Http\CookieQueue
  • Autarky\Http\SessionMiddleware
  • Autarky\Http\SessionProvider
  • Autarky\Logging\ChannelManager
  • Autarky\Logging\DefaultLogConfigurator
  • Autarky\Logging\LoggingErrorHandler
  • Autarky\Logging\LoggingProvider
  • Autarky\Provider
  • Autarky\Providers\AbstractDependantProvider
  • Autarky\Providers\AbstractProvider
  • Autarky\Routing\Configuration
  • Autarky\Routing\Controller
  • Autarky\Routing\DefaultRouteConfigurator
  • Autarky\Routing\Events\AbstractRouteEvent
  • Autarky\Routing\Events\AfterEvent
  • Autarky\Routing\Events\BeforeEvent
  • Autarky\Routing\Events\RouteMatchedEvent
  • Autarky\Routing\Route
  • Autarky\Routing\RoutePathGenerator
  • Autarky\Routing\Router
  • Autarky\Routing\RoutingProvider
  • Autarky\Routing\UrlGenerator
  • Autarky\Testing\TestCase
  • Autarky\Testing\WebTestCase
  • Autarky\TwigTemplating\Extensions\PartialExtension
  • Autarky\TwigTemplating\Extensions\SessionExtension
  • Autarky\TwigTemplating\Extensions\UrlGenerationExtension
  • Autarky\TwigTemplating\Template
  • Autarky\TwigTemplating\TemplateContext
  • Autarky\TwigTemplating\TemplateEvent
  • Autarky\TwigTemplating\TemplatingEngine
  • Autarky\TwigTemplating\TwigEnvironment
  • Autarky\TwigTemplating\TwigTemplate
  • Autarky\TwigTemplating\TwigTemplatingProvider
  • Autarky\Utils\ArrayUtil

Interfaces

  • Autarky\Config\ConfigInterface
  • Autarky\Config\LoaderInterface
  • Autarky\ConfiguratorInterface
  • Autarky\Container\CallableInvokerInterface
  • Autarky\Container\ClassResolverInterface
  • Autarky\Container\ContainerAwareInterface
  • Autarky\Container\ContainerInterface
  • Autarky\Container\Factory\ArgumentInterface
  • Autarky\Container\Factory\FactoryInterface
  • Autarky\Database\ConnectionFactoryInterface
  • Autarky\Errors\ErrorHandlerInterface
  • Autarky\Errors\ErrorHandlerManagerInterface
  • Autarky\Events\EventDispatcherAwareInterface
  • Autarky\Providers\ConsoleProviderInterface
  • Autarky\Providers\DependantProviderInterface
  • Autarky\Providers\ProviderInterface
  • Autarky\Routing\InvokerInterface
  • Autarky\Routing\RoutePathGeneratorInterface
  • Autarky\Routing\RouterInterface

Traits

  • Autarky\Container\ContainerAwareTrait
  • Autarky\Events\EventDispatcherAwareTrait
  • Autarky\Routing\ControllerTrait

Exceptions

  • Autarky\Config\LoadException
  • Autarky\Container\Exception\ContainerException
  • Autarky\Container\Exception\NotInstantiableException
  • Autarky\Container\Exception\ResolvingException
  • Autarky\Container\Exception\ResolvingInternalException
  • Autarky\Container\Exception\UnresolvableArgumentException
  • Autarky\Database\CannotConnectException
  • Autarky\Files\IOException
  • Autarky\Providers\ProviderException
  • Overview
  • Namespace
  • Class
  1: <?php
  2: /**
  3:  * This file is part of the Autarky package.
  4:  *
  5:  * (c) Andreas Lutro <anlutro@gmail.com>
  6:  *
  7:  * For the full copyright and license information, please view the LICENSE
  8:  * file that was distributed with this source code.
  9:  */
 10: 
 11: namespace Autarky\Config;
 12: 
 13: use Autarky\Utils\ArrayUtil;
 14: use Autarky\Files\PathResolver;
 15: 
 16: /**
 17:  * File-based config implementation.
 18:  *
 19:  * Reads files from one or multiple directories, with the possibility of
 20:  * cascading for different environments and overriding of namespaces.
 21:  */
 22: class FileStore implements ConfigInterface
 23: {
 24:     /**
 25:      * The path resolver instance.
 26:      *
 27:      * @var PathResolver
 28:      */
 29:     protected $pathResolver;
 30: 
 31:     /**
 32:      * The loader factory instance.
 33:      *
 34:      * @var LoaderFactory
 35:      */
 36:     protected $loaderFactory;
 37: 
 38:     /**
 39:      * The current environment.
 40:      *
 41:      * @var string
 42:      */
 43:     protected $environment;
 44: 
 45:     /**
 46:      * The loaded config data.
 47:      *
 48:      * @var array
 49:      */
 50:     protected $data = [];
 51: 
 52:     /**
 53:      * Constructor.
 54:      *
 55:      * @param PathResolver  $pathResolver
 56:      * @param LoaderFactory $loaderFactory
 57:      * @param string|null   $environment
 58:      */
 59:     public function __construct(
 60:         PathResolver $pathResolver,
 61:         LoaderFactory $loaderFactory,
 62:         $environment = null
 63:     ) {
 64:         $this->pathResolver = $pathResolver;
 65:         $this->loaderFactory = $loaderFactory;
 66:         $this->environment = $environment;
 67:     }
 68: 
 69:     /**
 70:      * Get the loader factory instance.
 71:      *
 72:      * @return LoaderFactory
 73:      */
 74:     public function getLoaderFactory()
 75:     {
 76:         return $this->loaderFactory;
 77:     }
 78: 
 79:     /**
 80:      * {@inheritdoc}
 81:      */
 82:     public function mount($location, $path)
 83:     {
 84:         $this->pathResolver->mount($location, $path);
 85:     }
 86: 
 87:     /**
 88:      * {@inheritdoc}
 89:      */
 90:     public function setEnvironment($environment)
 91:     {
 92:         $this->environment = $environment;
 93:     }
 94: 
 95:     /**
 96:      * {@inheritdoc}
 97:      */
 98:     public function has($key)
 99:     {
100:         $this->loadData($key);
101: 
102:         return ArrayUtil::has($this->data, $key);
103:     }
104: 
105:     /**
106:      * {@inheritdoc}
107:      */
108:     public function get($key, $default = null)
109:     {
110:         $this->loadData($key);
111: 
112:         return ArrayUtil::get($this->data, $key, $default);
113:     }
114: 
115:     /**
116:      * {@inheritdoc}
117:      */
118:     public function set($key, $value)
119:     {
120:         $this->loadData($key);
121: 
122:         ArrayUtil::set($this->data, $key, $value);
123:     }
124: 
125:     protected function loadData($key)
126:     {
127:         $basename = $this->getBasename($key);
128: 
129:         if (array_key_exists($basename, $this->data)) {
130:             return;
131:         }
132: 
133:         $paths = $this->getPaths($basename);
134: 
135:         foreach ($paths as $path) {
136:             $data = $this->getDataFromFile($path);
137: 
138:             if (isset($this->data[$basename])) {
139:                 $this->data[$basename] = array_replace(
140:                     $this->data[$basename], $data);
141:             } else {
142:                 $this->data[$basename] = $data;
143:             }
144:         }
145:     }
146: 
147:     protected function getBasename($key)
148:     {
149:         return current(explode('.', $key));
150:     }
151: 
152:     protected function getPaths($basename)
153:     {
154:         $basenames = $this->pathResolver->resolve($basename);
155: 
156:         if ($this->environment) {
157:             $envBasenames = array_map(function($basename) {
158:                 return $basename.'.'.$this->environment;
159:             }, $basenames);
160: 
161:             $basenames = array_merge($basenames, $envBasenames);
162:         }
163: 
164:         $extensions = $this->loaderFactory->getExtensions();
165: 
166:         return $this->pathResolver->locate($basenames, $extensions);
167:     }
168: 
169:     protected function getDataFromFile($path)
170:     {
171:         if (!is_readable($path)) {
172:             throw new LoadException("File is not readable: $path");
173:         }
174: 
175:         $loader = $this->loaderFactory->getForPath($path);
176: 
177:         return $loader->load($path);
178:     }
179: }
180: 
Autarky Framework API documentation generated by ApiGen