Reputation: 1590
Ok, So I am pretty new to OOP and in functional PHP we could include files to use the functions within it.
I am attempting to build my first package, a simple API wrapper, the API I am using has multiple sections for different areas of interest. As an example:
GENRES
EVENTS
TICKETS
Currently, I have my package working with a file structure similar to this:
MYNAME
- MYPACKAGE
- SRC
- MyPackageSeviceProvider.php
- MyPackage.php
Now, This all works, I am using MyPackage.php for some simple set up, like setting the API URL's etc. However, I don't really want to put all the sections of the API into the one file, i.e. getGenres(), getEvents().
I want to break it down into sub folders so I have a structure like the following:
MYNAME
- MYPACKAGE
- SRC
- MyPackageSeviceProvider.php
- MyPackage.php
- GENRES
- Genres.php
- EVENTS
- Events.php
- TICKETS
- Tickets.php
I have a Facade set up so I can call on methods pretty (i.e MyPackage::getWhatever();).
What is best practice to achieve what I am trying to do?
How would I almost include the classes methods so I can call something like MyPackage::getGenres(); and it would route to the method in the GENRES -> Genres.php file?
Upvotes: 0
Views: 95
Reputation: 25721
This question is off-topic so should probably be closed, but I can't stand to see you do it that wrongly.
The namespace + class filenames should be contiguous, not with an extra src directory between them. And you you should only UPPER CASE EVERYTHING IF YOU WANT PEOPLE TO GO BLIND.
src/
- MyName/
- MyPackage/
- MyPackageSeviceProvider.php
- MyPackage.php
- Genres/
- Genres.php
- Events
- Events.php
- Tickets
- Tickets.php
Also, you probably don't want plurals on your class or namespaces.
How would I almost include the classes methods so I
You would use the composer autoloader, and get it to load all your class files for you.
Upvotes: 2