Once you have installed and configured Symfony bundles, you can use them in your PHP code as you would use any other library or package. Symfony bundles follow the PSR-4 standard for autoloading, which means that you can use Composer's autoloader to load the classes and namespaces of the bundles. For example, if you want to use the SecurityBundle's UserInterface class, you can write: use Symfony\Component\Security\Core\User\UserInterface; Then, you can use the UserInterface methods and properties in your code. You can also use the Symfony DependencyInjection component, which provides a service container that allows you to register, configure, and access the services and parameters of the bundles. For example, if you want to use the SecurityBundle's UserPasswordEncoderInterface service, you can write:
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class SomeClass
{
private $container;
private $encoder;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
$this->encoder = $container->get(UserPasswordEncoderInterface::class);
}
public function someMethod(UserInterface $user, string $password)
{
// use the encoder service to encode the password
$encodedPassword = $this->encoder->encodePassword($user, $password);
// do something with the encoded password
}
}
You can find more information and examples on how to use the DependencyInjection component and the service container on the official Symfony website.