Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added an abstract factory for configs

  • Loading branch information...
commit c48bf8164c955ecfdea67dae25d290fae3d8e75b 1 parent f98ab0b
Chris Raidler authored
Showing with 60 additions and 0 deletions.
  1. +60 −0 library/Zend/Config/AbstractConfigFactory.php
View
60 library/Zend/Config/AbstractConfigFactory.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Zend Framework (http://framework.zend.com/)
+ *
+ * @link http://github.com/zendframework/zf2 for the canonical source repository
+ * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+
+namespace Zend\Config;
+
+use Zend\ServiceManager;
+
+/**
+ * Class AbstractConfigFactory
+ */
+class AbstractConfigFactory implements ServiceManager\AbstractFactoryInterface
+{
+ /**
+ * @var string
+ */
+ protected $pattern = '#^(.*)\\\\Config$#i';
+
+ /**
+ * Determine if we can create a service with name
+ *
+ * @param ServiceManager\ServiceLocatorInterface $serviceLocator
+ * @param string $name
+ * @param string $requestedName
+ * @return bool
+ */
+ public function canCreateServiceWithName(ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
+ {
+ if (!preg_match($this->pattern, $requestedName, $matches)) {
+ return false;
+ }
+
+ $config = $serviceLocator->get('Config');
+ if (!isset($config[$matches[1]])) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Create service with name
+ *
+ * @param ServiceManager\ServiceLocatorInterface $serviceLocator
+ * @param string $name
+ * @param string $requestedName
+ * @return mixed
+ */
+ public function createServiceWithName(ServiceManager\ServiceLocatorInterface $serviceLocator, $name, $requestedName)
+ {
+ preg_match($this->pattern, $requestedName, $matches);
+ $config = $serviceLocator->get('Config');
+ return new Config($config[$matches[1]]);
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.