I use the following directory structure based on my understanding of how namespaces work in PHP:
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, the fully qualified class name is as follows:
\<NamespaceName>(\<SubNamespaceNames>)*\<ClassName>
Question 1:
From my directory structure above, is the assumption below the correct one?
- NamespaceName = MyCompany
- SubNamespaceNames = Utility | Core
- ClassName = Logger | User
Question 2:
If the bootstrap.php file contains the following:
<?php require 'vendor/autoload.php';
How do I configure the 'autoload' section in the composer.json file to autoload classes in the MyCompany directory? That way I could create a Logger instance in bootstrap.php
source share