Search code examples
nginxphp-7pimcorebundlespimcore-v5

Pimcore doesn't create a service of my installer class


I'm trying to create my own pimcore bundle. But now I have a problem with my installer class. When I try to install my bundle this error message appears:

Message: You have requested a non-existent service "Pimcore\Bundle\TestBundle\Tools\Installer". Did you mean this: "Pimcore\Bundle\EcommerceFrameworkBundle\Tools\Installer"?

This is my code:

TestBundle

<?php

namespace Pimcore\Bundle\TestBundle;

use Pimcore\Bundle\TestBundle\Tools\Installer;
use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
 * Class TestBundle
 * @package Pimcore\Bundle\TestBundle
 */
class TestBundle extends AbstractPimcoreBundle
{

    const BUNDLE_NAME = "TestBundle";
    const BUNDLE_DESCRIPTION = "Just a test!";
    const BUNDLE_VERSION = "1.0";

    /**
     * @inheritDoc
     */
    public function getNiceName()
    {
        return self::BUNDLE_NAME;
    }

    /**
     * @inheritDoc
     */
    public function getDescription()
    {
        return self::BUNDLE_DESCRIPTION;
    }

    /**
     * @inheritDoc
     */
    public function build(ContainerBuilder $container)
    {

    }

    /**
     * @inheritDoc
     */
    public function getVersion()
    {
        return self::BUNDLE_VERSION;
    }

    /**
     * @return array
     */
    public function getCssPaths()
    {
        return [
            '/bundles/' . strtolower(self::BUNDLE_NAME) . '/css/pricing.css'
        ];
    }

    /**
     * @return array
     */
    public function getJsPaths()
    {
        return [];
    }


    /**
     * @return Installer
     */
    public function getInstaller()
    {
         return $this->container->get(Installer::class);
    }
}

Installer

<?php

namespace Pimcore\Bundle\TestBundle\Tools;

use Pimcore\Extension\Bundle\Installer\AbstractInstaller;
use Psr\Log\LoggerInterface;

class Installer extends AbstractInstaller
{

    public function __construct(LoggerInterface $logger)
    {

    }

    /**
     * installs e-commerce framework
     *
     * @throws \Exception
     */
    public function install()
    {


    }

    /**
     * @return bool
     */
    public function canBeInstalled()
    {

    }

    /**
     * checks, if install is possible. otherwise throws exception
     *
     * @throws \Exception
     */
    protected function checkCanBeInstalled()
    {

    }

    public function canBeUninstalled()
    {
        return true;
    }

    /**
     * uninstalls e-commerce framework
     */
    public function uninstall()
    {

    }

    /**
     *
     * @return bool
     */
    public function needsReloadAfterInstall()
    {
        return true;
    }

    /**
     *  indicates if this bundle is currently installed
     *
     * @return bool
     */
    public function isInstalled()
    {

    }
}

Services.yml (Under /Resources/config)

services:
    _defaults:
        public: true
        autowire: true
        autoconfigure: true


    #
    # INSTALLER
    #

    pimcore.testbundle.installer: '@Pimcore\Bundle\TestBundle\Tools\Installer'
    Pimcore\Bundle\TestBundle\Tools\Installer:
        tags:
            - { name: monolog.logger, channel: pimcore_testbundle.installer }

    #
    # CONTROLLERS
    #

    # auto-register all controllers as services
    Pimcore\Bundle\TestBundle\Controller\:
        resource: '../../Controller'
        public: true
        tags: ['controller.service_arguments']

I'm trying to do this for such a long time but it still doesn't work. Unfortunately I can't find something documented in the official pimcore docs.

Thank you very much!


Solution

  • For me, it seems that you tried to copy manually the E-commerce Bundle. Theoretically, it SHOULD work, but for sure it is not the best idea to integrate into a pimcore directory.

    To generate new bundle you SHOULD use bin/console pimcore:generate:bundle in the CLI (more info here: https://pimcore.com/docs/5.0.x/Extending_Pimcore/Bundle_Developers_Guide/index.html)

    (!) Please be aware that this command is available only for dev and test environments (see https://github.com/pimcore/pimcore/blob/master/pimcore/lib/Pimcore/Kernel.php#L212)