How can frameworks like Symfony or custom routing classes help streamline the use of OOP principles in PHP for website development?

Using frameworks like Symfony or custom routing classes can help streamline the use of OOP principles in PHP for website development by providing a structured way to organize code, separate concerns, and promote reusability. These tools allow developers to create classes for different components of a website (such as controllers, models, and views) and easily map URLs to specific methods within those classes, following the principles of encapsulation, inheritance, and polymorphism.

// Example of using Symfony routing component to define routes in a PHP application

use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Matcher\UrlMatcher;

$routes = new RouteCollection();
$routes->add('home', new Route('/', ['controller' => 'HomeController', 'method' => 'index']));
$routes->add('about', new Route('/about', ['controller' => 'AboutController', 'method' => 'index']));

$context = new RequestContext('/');
$matcher = new UrlMatcher($routes, $context);

// Match the current request URL to a route
$parameters = $matcher->match($_SERVER['REQUEST_URI']);

// Instantiate the controller and call the method
$controller = new $parameters['controller'];
$method = $parameters['method'];
$controller->$method();