/**
  * Constructor.
  *
  * @param Registry $config    The config object.
  * @param string   $extension The extension name.
  */
 public function __construct(Registry $config = null, $extension = null)
 {
     $config = $config ?: new Registry();
     $this->extension = $extension;
     $this->resetCachePosition();
     $this->config->merge($config);
 }
 /**
  * Constructor.
  *
  * @param array    $config    The config object.
  * @param string   $extension The extension name.
  */
 public function __construct($config = array(), $extension = null)
 {
     $config = DecoratingRegistry::toWindwalkerRegistry($config);
     $this->extension = $extension;
     $this->resetCachePosition();
     $this->config->merge($config);
 }
 /**
  * Merge a Registry object into this one
  *
  * @param   Registry  $source     Source Registry object to merge.
  * @param   boolean   $recursive  True to support recursive merge the children values.
  *
  * @return  Registry  Return this object to support chaining.
  *
  * @since   1.0
  */
 public function merge($source, $recursive = false)
 {
     if ($source instanceof \Joomla\Registry\Registry) {
         $source = $source->toArray();
     }
     $this->registry->merge($source, $recursive);
     return $this;
 }
 /**
  * extractConfig
  *
  * @param string $template
  *
  * @return  string
  */
 public function prepareData($template)
 {
     $template = explode('---', $template, 3);
     if (!trim($template[0])) {
         array_shift($template);
         $template = implode('---', $template);
         $template = explode('---', $template, 2);
     }
     try {
         $config = Yaml::parse($template[0]);
         if ($config) {
             array_shift($template);
         }
         $this->config->loadArray($config);
         $this->config->merge(Ioc::getConfig());
         $this->getData()->bind(array('config' => $this->config->toArray()));
         // Target permalink
         if ($this->config['permalink']) {
             $this->target = rtrim($this->config['permalink'], '/');
             if (substr($this->target, -5) != '.html') {
                 $this->target .= '/index.html';
             }
             $this->data->uri['base'] = ProcessorHelper::getBackwards($this->target) ?: './';
             $this->data->uri['media'] = ProcessorHelper::getBackwards($this->target) . 'media/';
         } else {
             $this->target = $this->getTarget();
         }
         $template = implode('---', $template);
     } catch (ParseException $e) {
         $template = implode('---', $template);
     }
     $event = new Event('loadProvider');
     $event['data'] = $this->data;
     $event['processor'] = $this;
     $dispatcher = Ioc::getDispatcher();
     $dispatcher->triggerEvent($event);
     return $template;
 }
Exemple #5
0
 /**
  * Method to test merge().
  *
  * @return void
  *
  * @covers Windwalker\Registry\Registry::merge
  */
 public function testMerge()
 {
     $registry = new Registry(array('flower' => 'rose', 'honor' => 'Osmanthus month'));
     $registry->merge($this->instance, true);
     $this->assertEquals($registry->get('flower'), 'sakura');
     $this->assertEquals($registry->get('honor'), 'Osmanthus month');
 }
    /**
     * Method to test merge().
     *
     * @return void
     *
     * @covers Windwalker\Registry\Registry::merge
     */
    public function testMergeWithIgnoreValues()
    {
        // Test recursive merge
        $object1 = '{
			"foo" : "foo value",
			"bar" : {
				"bar1" : "bar value 1",
				"bar2" : "bar value 2",
				"bar3" : "bar value 3"
			}
		}';
        $object2 = '{
			"foo" : "foo value",
			"bar" : {
				"bar2" : "new bar value 2",
				"bar3" : ""
			}
		}';
        $registry1 = new Registry(json_decode($object1));
        $registry2 = new Registry(json_decode($object2));
        $registry1->setIgnoreValues(array(null, ''));
        $registry1->merge($registry2);
        $this->assertEquals('new bar value 2', $registry1->get('bar.bar2'), 'Line: ' . __LINE__ . '. bar.bar2 should be override.');
        $this->assertEquals('bar value 1', $registry1->get('bar.bar1'), 'Line: ' . __LINE__ . '. bar.bar1 should not be override.');
        $this->assertSame('bar value 3', $registry1->get('bar.bar3'), 'Line: ' . __LINE__ . '. bar.bar3 should not be override.');
        $registry = new Registry(array('flower' => 'rose', 'honor' => 'Osmanthus month'));
        $registry->merge($this->instance);
        $this->assertEquals($registry->get('flower'), 'sakura');
        $this->assertEquals($registry->get('honor'), 'Osmanthus month');
    }