/**
  * Create Doctrine adapter configuration
  *
  * @param $name
  * @param array $adapterConfig
  * @return DoctrineAdapterEntity
  */
 public function create($name, array $adapterConfig)
 {
     $key = "doctrine.connection.{$name}";
     $this->globalConfig->patchKey($key, []);
     $this->localConfig->patchKey($key, $adapterConfig);
     return new DoctrineAdapterEntity($name, $adapterConfig);
 }
 /**
  * Create DB adapter configuration
  *
  * @param  mixed $name
  * @param  array $adapterConfig
  * @return DbAdapterEntity
  */
 public function create($name, array $adapterConfig)
 {
     $key = 'db.adapters.' . $name;
     if (strstr($adapterConfig['driver'], 'Pgsql') && isset($adapterConfig['charset'])) {
         unset($adapterConfig['charset']);
     }
     if (empty($adapterConfig['dsn'])) {
         unset($adapterConfig['dsn']);
     }
     $this->globalConfig->patchKey($key, []);
     $this->localConfig->patchKey($key, $adapterConfig);
     return new DbAdapterEntity($name, $adapterConfig);
 }
Ejemplo n.º 3
0
    /**
     * Remove a url from OAuth2 route
     *
     * Since Apigility 1.1
     *
     * @param  string $url
     * @return boolean
     */
    protected function removeOAuth2Route($url)
    {
        $config = $this->globalConfig->fetch(true);

        if (! isset($config['router']['routes']['oauth']['options']['regex'])) {
            return false;
        }

        $routes = $this->fromOAuth2RegexToArray($config);
        $index = array_search($url, $routes);
        if (false === $index) {
            return false;
        }

        unset($routes[$index]);

        if (count($routes)>0) {
            usort($routes, function ($a, $b) {
                return strlen($b) - strlen($a);
            });
            $options = array(
                'spec'  => '%oauth%',
                'regex' => '(?P<oauth>(' . implode('|', $routes) . '))'
            );
            $this->globalConfig->patchKey('router.routes.oauth.options', $options);
            $this->globalConfig->patchKey('router.routes.oauth.type', 'regex');
            return true;
        }

        $this->globalConfig->deleteKey('router.routes.oauth');
        return true;
    }
Ejemplo n.º 4
0
    /**
     * Delete any versionin configuration for a service
     *
     * Only for version 1; later versions will do nothing
     *
     * @param  string $routeName
     * @param  string $serviceName
     */
    public function deleteVersioningConfig($routeName, $serviceName)
    {
        if (false === strstr($serviceName, '\\V1\\')) {
            // > V1; nothing to do
            return;
        }

        $config = $this->configResource->fetch(true);
        if (! isset($config['zf-versioning']['uri'])) {
            return;
        }

        if (! in_array($routeName, $config['zf-versioning']['uri'], true)) {
            return;
        }

        $versioning = array_filter($config['zf-versioning']['uri'], function ($value) use ($routeName) {
            if ($routeName === $value) {
                return false;
            }
            return true;
        });

        $key = array('zf-versioning', 'uri');
        $this->configResource->patchKey($key, $versioning);
    }
Ejemplo n.º 5
0
    /**
     * Delete versioning configuration for a service
     *
     * Removes the route name from zf-versioning.
     *
     * @param  RestServiceEntity $entity
     */
    public function deleteVersioningConfig(RestServiceEntity $entity)
    {
        $serviceName = $entity->controllerServiceName;
        if (false === strstr($serviceName, '\\V1\\')) {
            // service > v1; do not delete route
            return;
        }

        $config = $this->configResource->fetch(true);
        if (! isset($config['zf-versioning']['uri'])) {
            return;
        }

        $route = $entity->routeName;
        if (! in_array($route, $config['zf-versioning']['uri'], true)) {
            return;
        }

        $versioning = array_filter($config['zf-versioning']['uri'], function ($value) use ($route) {
            if ($route === $value) {
                return false;
            }
            return true;
        });

        $key = array('zf-versioning', 'uri');
        $this->configResource->patchKey($key, $versioning);
    }
 /**
  * Update Doctrine configuration
  *
  * @param DoctrineRestServiceEntity $original
  * @param DoctrineRestServiceEntity $update
  */
 public function updateDoctrineConfig(DoctrineRestServiceEntity $original, DoctrineRestServiceEntity $update)
 {
     $patch = [];
     $patch['object_manager'] = $update->objectManager;
     $patch['hydrator'] = $update->hydratorName;
     $basekey = 'zf-apigility.doctrine-connected.';
     $resource = $update->resourceClass;
     $this->configResource->patchKey($basekey . $resource, $patch);
 }
 /**
  * Patch the OAuth2 configuration
  *
  * @param AuthenticationEntity $entity
  * @param array $global
  * @param array $local
  * @return void
  */
 protected function patchOAuth2Config(AuthenticationEntity $entity, array $global, array $local)
 {
     if (isset($global['route_match']) && $global['route_match']) {
         $this->globalConfig->patchKey('router.routes.oauth.options.route', $global['route_match']);
     }
     switch ($entity->getDsnType()) {
         case AuthenticationEntity::DSN_MONGO:
             $toSet = array('storage' => 'ZF\\OAuth2\\Adapter\\MongoAdapter', 'mongo' => $local);
             break;
         case AuthenticationEntity::DSN_PDO:
         default:
             $toSet = array('storage' => 'ZF\\OAuth2\\Adapter\\PdoAdapter', 'db' => $local);
             break;
     }
     $key = 'zf-oauth2';
     $this->localConfig->patchKey($key, $toSet);
 }
Ejemplo n.º 8
0
 /**
  * Create Content Negotiation configuration
  *
  * @param  mixed $name
  * @param  array $contentConfig
  * @return ContentNegotiationEntity
  */
 public function create($name, array $contentConfig)
 {
     $key = 'zf-content-negotiation.selectors.' . $name;
     $this->globalConfig->patchKey($key, $contentConfig);
     return new ContentNegotiationEntity($name, $contentConfig);
 }