contao-community-alliance / dependency-container

Dependency container for Contao Open Source CMS based on the Pimple Dependency Injection Container
GNU Lesser General Public License v3.0
1 stars 4 forks source link

Error in ContainerInitializer.php #9

Closed cboelter closed 9 years ago

cboelter commented 9 years ago

I updated my MetaModels installation via composer, since I've done the update, I get the following error:

Warning: array_merge(): Argument #2 is not an array in composer/vendor/contao-community-alliance/dependency-container/src/DependencyInjection/Container/ContainerInitializer.php on line 289

#0 [internal function]: __error(2, 'array_merge(): ...', '/Applications/M...', 289, Array)
#1 composer/vendor/contao-community-alliance/dependency-container/src/DependencyInjection/Container/ContainerInitializer.php(289): array_merge(Array, NULL)
#2 composer/vendor/contao-community-alliance/dependency-container/src/DependencyInjection/Container/ContainerInitializer.php(333): DependencyInjection\Container\ContainerInitializer->provideSingletons(Object(Pimple))
#3 system/initialize.php(233): DependencyInjection\Container\ContainerInitializer->init()
#4 contao/main.php(24): require_once('/Applications/M...')
#5 {main}

I had a look on the requested line and it seems that the $GLOBALS['TL_HOOKS']['getPageLayout'] does not exist at every time. I think we need a condition to check if there is an array or not.

bytehead commented 9 years ago

same here...

cboelter commented 9 years ago

My quickfix solution is the following:

 if(is_array($GLOBALS['TL_HOOKS']['getPageLayout'])) {
                $container['page-provider'] = new PageProvider();

                $GLOBALS['TL_HOOKS']['getPageLayout'] = array_merge(
                    array(array('DependencyInjection\Container\PageProvider', 'setPage')),
                    $GLOBALS['TL_HOOKS']['getPageLayout']
                );
            }
bytehead commented 9 years ago

Thanks. I switched back to v1.6.1 (temporary).

bibib commented 9 years ago

Ich fürchte, ich habe diesen quickfix nicht richtig eingefügt. Fehler besteht weiterhin, bzw. ich komme nicht mehr ins Backend. Der betreffende Teil im Code sieht so aus:

    /**
     * Add the Contao singletons to the DIC.
     *
     * @param \Pimple $container The DIC to populate.
     *
     * @return void
     *
     * @SuppressWarnings(PHPMD.Superglobals)
     */
    protected function provideSingletons(\Pimple $container)
    {
        if (!isset($container['config'])) {
            $container['config'] = $container->share($this->getConfigProvider());
        }

        if (!isset($container['environment'])) {
            $container['environment'] = $container->share($this->getEnvironmentProvider());
        }

        if (!isset($container['database.connection'])) {
            $container['database.connection'] = $container->share($this->getDatabaseProvider());
        }

        if (!isset($container['input'])) {
            $container['input'] = $container->share($this->getInputProvider());
        }

        if (!isset($container['user'])) {
            $container['user'] = $container->share($this->getUserProvider());
        }

        if (!isset($container['session'])) {
            $container['session'] = $container->share($this->getSessionProvider());
        }

        if (!isset($container['page-provider'])) {
            $container['page-provider'] = new PageProvider();

            $GLOBALS['TL_HOOKS']['getPageLayout'] = array_merge(
                array(array('DependencyInjection\Container\PageProvider', 'setPage')),
                $GLOBALS['TL_HOOKS']['getPageLayout']
            );
        }

     if(is_array($GLOBALS['TL_HOOKS']['getPageLayout'])) {
                $container['page-provider'] = new PageProvider();

                $GLOBALS['TL_HOOKS']['getPageLayout'] = array_merge(
                    array(array('DependencyInjection\Container\PageProvider', 'setPage')),
                    $GLOBALS['TL_HOOKS']['getPageLayout']
                );
            }
    }

Ist das korrekt?

cboelter commented 9 years ago

nope leider nicht korrekt, du musst das hier ...

 $container['page-provider'] = new PageProvider();

            $GLOBALS['TL_HOOKS']['getPageLayout'] = array_merge(
                array(array('DependencyInjection\Container\PageProvider', 'setPage')),
                $GLOBALS['TL_HOOKS']['getPageLayout']
            );

Entfernen und durch den Code von mir erstzen. Die komplette funktion muss so aussehen:

/**
     * Add the Contao singletons to the DIC.
     *
     * @param \Pimple $container The DIC to populate.
     *
     * @return void
     *
     * @SuppressWarnings(PHPMD.Superglobals)
     */
    protected function provideSingletons(\Pimple $container)
    {
        if (!isset($container['config'])) {
            $container['config'] = $container->share($this->getConfigProvider());
        }

        if (!isset($container['environment'])) {
            $container['environment'] = $container->share($this->getEnvironmentProvider());
        }

        if (!isset($container['database.connection'])) {
            $container['database.connection'] = $container->share($this->getDatabaseProvider());
        }

        if (!isset($container['input'])) {
            $container['input'] = $container->share($this->getInputProvider());
        }

        if (!isset($container['user'])) {
            $container['user'] = $container->share($this->getUserProvider());
        }

        if (!isset($container['session'])) {
            $container['session'] = $container->share($this->getSessionProvider());
        }

        if (!isset($container['page-provider'])) {
            if(is_array($GLOBALS['TL_HOOKS']['getPageLayout'])) {
                $container['page-provider'] = new PageProvider();

                $GLOBALS['TL_HOOKS']['getPageLayout'] = array_merge(
                    array(array('DependencyInjection\Container\PageProvider', 'setPage')),
                    $GLOBALS['TL_HOOKS']['getPageLayout']
                );
            }
        }
    }
bibib commented 9 years ago

Das hat geklappt, danke!

discordier commented 9 years ago

Has been fixed in 842a8e0726f38b53e08fe977603843f9b05e1bbf

discordier commented 9 years ago

Released as https://github.com/contao-community-alliance/dependency-container/releases/tag/1.7.1