Пример #1
0
 /**
  * Test if we get pack right config if a default config was
  * set before. It should merge the config together, but the
  * config, which was set by the request will overwrite the default
  * config
  *
  */
 function testMergingWithDefaultConfig()
 {
     $request = $this->createRequestMockWithConfig(['level1' => ['level2' => ['level3' => null, 'other' => 'otherValue']]]);
     $default = array('type' => 'defaultType', 'level1' => array('level2' => array('level3' => 'notWorth', 'type' => 'defaultLevel2Type')));
     /**
      * both array should be merged together to this
      *
      * array(
      *   'type' => 'defaultType',
      *   'level1' => array(
      *     'level2' => array(
      *       'level3' => null,
      *       'type' => 'defaultLevel2Type',
      *       'other' => 'otherValue'
      *     )
      *   )
      * );
      *
      */
     $configParser = new ConfigParser();
     $configParser->parse($request);
     $configParser->setDefault($default);
     $this->assertEquals('defaultType', $configParser->get('type'));
     $this->assertArraySubset(array('level3' => null, 'other' => 'otherValue', 'type' => 'defaultLevel2Type'), $configParser->get('level1.level2'));
 }
Пример #2
0
 public function getPreviewResponse($resource, ConfigParser $config)
 {
     $service = $config->get('service');
     if ($service === null) {
         throw new PreviewException('You choose the strategy service, but you didn\'t pass any service to call. Please use the service parameter with "service_id:functionName" notation');
     }
     $parts = preg_split('#:#', $service);
     if (count($parts) !== 2) {
         throw new PreviewException(sprintf('The service parameter need a notation like "service_id:functionName" but you got "%s"', $service));
     }
     $serviceName = $parts[0];
     $invokeService = null;
     try {
         $invokeService = $this->container->get($serviceName);
     } catch (ServiceNotFoundException $e) {
         throw new PreviewException(sprintf('The service parameter in preview route should be an existing service, got "%s"', $serviceName));
     }
     $invokeFunction = $parts[1];
     if (!method_exists($invokeService, $invokeFunction)) {
         throw new PreviewException(sprintf('The defined function "%s " in service "%s" for preview route does not exists, check your service config "%s"', $invokeFunction, $serviceName, $service));
     }
     return call_user_func(array($invokeService, $invokeFunction), $resource);
 }
Пример #3
0
 /**
  * @param mixed $config
  */
 public function setConfig($config)
 {
     $this->config = $config;
     $this->config->setDefault($this->getDefaultConfig());
 }