Issues

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

Issue Type: Performance Improvement Created: 2010-04-27T11:46:03.000+0000 Last Updated: 2013-02-18T11:48:11.000+0000 Status: Resolved Fix version(s): - 1.12.2 (25/Feb/13)

Reporter: bullfrogblues (gerardroche) Assignee: Frank Brückner (frosch) Tags: - Zend_Layout

Related issues: - ZF-8410

Attachments:

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

<pre class="highlight">
    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

Posted by bullfrogblues (gerardroche) on 2013-02-17T17:08:34.000+0000

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

Before

lines 173-186: Zend_Layout

<pre class="highlight">
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;
}


After

<pre class="highlight">
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;
}

Posted by Frank Brückner (frosch) on 2013-02-18T11:48:11.000+0000

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

Thanks to Gerard!

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts