Issues

ZF-9754: Zend_layout::startMvc needlessly sets options twice???

Description

Am i missing something or does Zend_Layout::startMvc set options twice???

Take a look Zend_Layout::startMvc(), if self::$_mvcInstance is null the param options are passed to the constructor and it sets the options accordingly.

It should be returned immediately.

Instead it continues and sets the options again.

lines 142 ~ 182 Zend_Layout


    public function __construct($options = null, $initMvc = false)
    {
        if (null !== $options) {
            if (is_string($options)) {
                $this->setLayoutPath($options);
            } elseif (is_array($options)) {
                $this->setOptions($options);
            } elseif ($options instanceof Zend_Config) {
                $this->setConfig($options);
            } else {
                require_once 'Zend/Layout/Exception.php';
                throw new Zend_Layout_Exception('Invalid option provided to constructor');
            }
        }

        $this->_initVarContainer();

        if ($initMvc) {
            $this->_setMvcEnabled(true);
            $this->_initMvc();
        } else {
            $this->_setMvcEnabled(false);
        }
    }

    public static function startMvc($options = null)
    {
        if (null === self::$_mvcInstance) {
            self::$_mvcInstance = new self($options, true);
        }

        if (is_string($options)) {
            self::$_mvcInstance->setLayoutPath($options);
        } elseif (is_array($options) || $options instanceof Zend_Config) {
            self::$_mvcInstance->setOptions($options);
        }

        return self::$_mvcInstance;
    }

Comments

Hi, to get this closed it's a minor edit, an "else" clause:

Before

lines 173-186: Zend_Layout

<pre class="highlight"><code>
public static function startMvc($options = null)
{
    if (null === self::$_mvcInstance) {
        self::$_mvcInstance = new self($options, true);
    }

    if (is_string($options)) {
        self::$_mvcInstance->setLayoutPath($options);
    } elseif (is_array($options) || $options instanceof Zend_Config) {
        self::$_mvcInstance->setOptions($options);
    }

    return self::$_mvcInstance;
}
</code></pre>

After

<pre class="highlight"><code>
public static function startMvc($options = null)
{
    if (null === self::$_mvcInstance) {
        self::$_mvcInstance = new self($options, true);
    } else {
        if (is_string($options)) {
            self::$_mvcInstance->setLayoutPath($options);
        } elseif (is_array($options) || $options instanceof Zend_Config) {
            self::$_mvcInstance->setOptions($options);
        }
    }

    return self::$_mvcInstance;
}
</code></pre>

Fixed on trunk (25262) and release-1.12 (25263)

Thanks to Gerard!