I am using Symfony 2.6
My main bundle is AppBundle, so all namespaces within bundle look like this:
AppBundle\DirectoryName
I would like to change all namespaces so that I end up with something like this:
MyCompanyName\ProjectName\AppBundle\DirectoryName
========================================================
Next text shows what I have tried and the errors I had.
I have class StringUtilities:
<?php
namespace MyCompanyName\ProjectName\AppBundle\Utility;
class StringUtilities {
}
I am using StringUtilities here:
<?php
namespace AppBundle\Auth;
use MyCompanyName\ProjectName\AppBundle\Utility\StringUtilities as SU;
class UserChecker extends \Symfony\Component\Security\Core\User\UserChecker {
}
When running the application, I am getting this error:
Attempted to load class "StringUtilities" from namespace "MyCompanyName\ProjectName\AppBundle\Utility". Did you forget a "use" statement for another namespace?
This is solved by adding this line in app/autoload.php
$loader->addPsr4('MyCompanyName\ProjectName\\', realpath(__DIR__.'/../src'));
Now I tried to change namespace of UseChecker class:
<?php
namespace MyCompanyName\ProjectName\AppBundle\Auth;
use MyCompanyName\ProjectName\AppBundle\Utility\StringUtilities as SU;
class UserChecker extends \Symfony\Component\Security\Core\User\UserChecker {
}
And when I try to clear cache via console (php app/console cache:clear), I get this error:
[RuntimeException]
The autoloader expected class "AppBundle\Auth\UserChecker" to be defined in file "/home/damjan/Temp/licence-management/src/AppBundle/Auth/UserChecker.php". The file was found but the class was not in it, the class name or namespace probably has a typo.
And when running the application in browser, I am getting this error:
FatalErrorException in UserChecker.php line 0: Compile Error: Cannot redeclare class MyCompanyName\ProjectName\AppBundle\Auth\UserChecker
Attempted to load class "StringUtilities" from namespace, you will be usingStringUtilitiesinside the class. And notSU. Search and change toSUother than for use statement. - Hari K TRuntimeExceptionerrors are self explanatory. I think. Look more carefully .. What do you need to change ? - Hari K T