I use the following directory structure based on my understanding of how namespaces in PHP work:
project_root
app/
| lib/
| | MyCompany/
| | | Utility/
| | | | Logger.php
| | | Core/
| | | | User.php
vendor/
composer/
symfony/
guzzle/
bootstrap.php
composer.json
According to the PSR-4 specification, a fully qualified class name has the following form:
\<NamespaceName>(\<SubNamespaceNames>)*\<ClassName>
Question 1:
From my directory structure above, is the assumption below correct?
- NamespaceName = MyCompany
- SubNamespaceNames = Utility | Core
- ClassName = Logger | User
Question 2:
If my bootstrap.php file contains the following:
<?php
require 'vendor/autoload.php';
How would I configure the 'autoload' section of composer.json to autoload the classes in the MyCompany directory? Such that I would be able to create an instance of Logger in bootstrap.php
composer dump-autoload
once you've added this snippet in order for it to work. – Moyers