Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error: Cannot declare class because the name is already in use #29

Open
4n70w4 opened this issue Feb 12, 2019 · 4 comments
Open

Comments

@4n70w4
Copy link

4n70w4 commented Feb 12, 2019

I conducted an experiment with a clean project and nothing works.

curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
chmod a+x /usr/local/bin/symfony

symfony new aop 3.4

cd aop

composer require goaop/goaop-symfony-bundle

sed -i '/$bundles = \[/ a \ \ new Go\\Symfony\\GoAopBundle\\GoAopBundle(),' app/AppKernel.php

cat >> app/config/config.yml << 'END'
go_aop:
    # This setting enables or disables an automatic AOP cache warming in the application.
    # By default, cache_warmer is enabled (true), disable it only if you have serious issues with 
    # cache warming process.
    cache_warmer: true

    # This setting enables or disables workaround for weaving of Doctrine ORM entities. By default,
    # it is disabled. If you are using Doctrine ORM and you are using AOP to weave Doctrine entities,
    # enable this feature. For details about this known issue, see https://github.com/goaop/framework/issues/327
    doctrine_support: false

    # Additional settings for the Go! AOP kernel initialization
    options:
        # Debug mode for the AOP, enable it for debugging and switch off for production mode to have a
        # better runtime performance for your application
        debug: %kernel.debug%
        
        # Application root directory, AOP will be applied ONLY to the files in this directory, by default it's
        # src/ directory of your application.
        app_dir: "%kernel.root_dir%/../src"

        # AOP cache directory where all transformed files will be stored.
        cache_dir: %kernel.cache_dir%/aspect

        # Whitelist is array of directories where AOP should be enabled, leave it empty to process all files
        include_paths: []
        
        # Exclude list is array of directories where AOP should NOT be enabled, leave it empty to process all files
        exclude_paths: []
        
        # AOP container class name can be used for extending AOP engine or services adjustment
        container_class: ~
        
        # List of enabled features for AOP kernel, this allows to enable function interception, support for
        # read-only file systems, etc. Each item should be a name of constant from the `Go\Aop\Features` class.
        features: []
END
cat >>  src/AppBundle/LoggingAspect.php << 'END'
<?php

namespace AppBundle;

use Go\Aop\Aspect;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Before;
use Psr\Log\LoggerInterface;

/**
 * Application logging aspect
 */
class LoggingAspect implements Aspect
{
    /**
     * @var LoggerInterface
     */
    private $logger;

    public function __construct(LoggerInterface $logger)
    {
        $this->logger = $logger;
    }

    /**
     * Writes a log info before method execution
     *
     * @param MethodInvocation $invocation
     * @Before("execution(public **->*(*))")
     */
    public function beforeMethod(MethodInvocation $invocation)
    {
        $this->logger->info($invocation, $invocation->getArguments());
    }
}
END
cat >> app/config/services.yml << 'END'
    logging.aspect:
        class: AppBundle\LoggingAspect
        arguments: ["@logger"]
        tags:
            - { name: goaop.aspect }
END

composer dumpautoload

After request to app:

Fatal error: Uncaught Error: Class name must be a valid object or a string in /var/www/app/aop/vendor/goaop/framework/src/Core/AspectKernel.php on line 108

Make crutch bugfix:

sed -i 's/container_class: ~/container_class: Go\\Core\\GoAspectContainer/' app/config/config.yml

php bin/console cache:clear --env=prod

Opps:

PHP Fatal error: Uncaught Error: Class name must be a valid object or a string in /var/www/app/aop/vendor/goaop/framework/src/Core/AspectKernel.php:108

Hard lifehack:

rm -rf var/cache/prod/

New oops:

Fatal error: Cannot declare class AppBundle\Controller\DefaultController, because the name is already in use in /var/www/app/aop/src/AppBundle/Controller/DefaultController.php on line 0

php bin/console cache:warmup:aop --env=prod

Total 3 files to process.

[OK]: /var/www/app/aop/src/AppBundle/AppBundle.php
[OK]: /var/www/app/aop/src/AppBundle/Controller/DefaultController.php
[OK]: /var/www/app/aop/src/AppBundle/LoggingAspect.php

[DONE]: Total processed 3, 0 errors.

Any ideas? Any tips? Start guide?

@4n70w4 4n70w4 changed the title Nothing works Fatal error: Cannot declare class because the name is already Feb 12, 2019
@4n70w4 4n70w4 changed the title Fatal error: Cannot declare class because the name is already Fatal error: Cannot declare class because the name is already in use Feb 12, 2019
@lisachenko
Copy link
Member

This related to the #22. Unfortunately, this bundle could not work with SF>=3.4 at the moment.

@4n70w4
Copy link
Author

4n70w4 commented Feb 12, 2019

@lisachenko probably should declare version dependency in the composer.json file.
That during installation there was a notification.

@srosato
Copy link

srosato commented Feb 13, 2019

There are no workarounds? Trying to make it work too with Sf4 and it seems my aspect never gets called. Seems like everything registers itself well when I use console debug:aspect, debug:advisor, etc.

I was able to fix the containerClass option being null because I would pass in container_class: ~ in the options, so I commented that line and the registration of aspect could work, but they never seem invoked.

@lisachenko
Copy link
Member

I'm sorry that I haven't time to work on this right now (

Symfony has a lot of major changes that break the AOP engine logic. It's unclear now how to do this in right way, because all generated stuff do not use Composer in SF>=3.4. I have a vision that this should be done during code generation phase.

Need to put a restriction into composer.json for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants