This application shows us how to implement PSR-4 standard in order to use a common "namespace" for all our classes in our application.


composer.json


{
"autoload": {
"psr-4": {
"Application\\": "src/Application/"
}
}
}

Any class located under src/Application/ folder or sub folders, will use Application namespace like shown below.


# src/Application/ClassOne.php

<?php

namespace Application;

class ClassOne
{
...
}

# src/Application/Service/ClassTwo.php

<?php

namespace Application\Service;

class ClassTwo
{
...
}

Our application structure looks like below.


| root/
| - src/
| - Application/ # namespace itself
| - Service/
| ClassOne.php # namespace Application\Service
| ClassTwo.php # namespace Application
| composer.json