Generate Class-Map including PHPdoc from all classes within a directory - php

I have a php application build on top of the Laravel framework. All my application specific modules are placed in their own Modules directory Modules\[Modulname].
These modules are autoloaded via PSR-4 in my composer.json:
"autoload": {
"classmap": [
...
],
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
},
Is there a way to get an array or something containing all classes, traits and interfaces with all containing methods, attributes and PHPdoc-blocks from the Modules-directory ordered according to the namespace?
I want to build a documentation similar to the Laravel Api documentation.

Related

NetBeans does not see a returning types of custom helper functions (Laravel, PHP)

I added my custom helpers file to Laravel project using composer.json like this
"autoload": {
"psr-4": {
"App\\": "app/"
},
"files": [
"app/Helpers/helpers.php"
]
},
And I checked, the same way Laravel's helper file is added to the project. This one: \vendor\laravel\framework\src\Illuminate\Foundation\helpers.php
It is all working fine.
But
In my Netbeans type-hinting helper does not see returning type of the functions of my file. However it sees returning type of Laravel's helpers.
Why? How can I fix this?
I tried Netbeans 8 and 10 - same problems.

How can I create a folder in the root of Laravel directory?

Here is my current directory:
As you see, I've made a new folder named classes in the app folder. Also I have some .php files (contains some classes) in classes folder. But I cannot access those classes in my controller. Noted that I add them to my controller like this:
use app\classes\Myclassname;
But still My classname won't be recognized and Laravel trows this:
Class 'app\classes\Profile' not found
How can I fix mentioned problem?
Add namespace into your class file, created class file like app/classes/MyclassnameXXX.php
namespace App\classes;
class MyclassnameXXX {}
Now, you have a right to access this class by using the namespace within your classes like:
use App\classes\MyclassnameXXX;
Hope this work for you!
You can autoload classes using composer like this.
"autoload": {
"classmap": [
"database",
"app/classes"
],
"psr-4": {
"App\\": "app/"
}
},
Don't forget to run composer dump-autoload to reload classes.
Also, add namespaces to your classes.
namespace App\classes;
class MyClass {
}
Or, you could use fancy namespaces like Laravel using psr-4 autoloading like this
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"App\\": "app/",
"App\\Classes": "app/classes"
}
},

Laravel 5 - Change Models,Views,Controllers path

i have edited psr-4 on composer.json
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Marka\\Urun\\": "vendor/Marka/Urun/src/",
"App\\": "app/"
},
"files": [
"vendor/Marka/Urun/src/helpers.php"
]
},
I want to change file(routes.php, helpers.php and Models,Views,Controllers) pathes to :
Vendor/Marka/Urun/
How can I do it ?
You're trying to get some modular structure if I get it right.
If so, instead of trying to set a different namespacing from composer for each of your modules under vendor directory; i think you may try to use something like http://sky.pingpong-labs.com/docs/2.0/modules
Otherwise as you may know, by using PSR-4 and directory structure, if you coded your files properly all necessary files would be loaded automatically as you named (namespaced) them.
By the way, just in case you didn't know you may also need a ServiceProvider to boot everything up for Laravel on your package.
I also suggest you to read https://laravel.com/docs/5.2/packages if you need any help about development structure/functionality.

Laravel 5 assets and lang folder in separate modules

I am trying to split my application out into seperate "modules".
I am not sure whether to leave the assets folder where it is and put everything in there for every module or how I would go about giving each module their own assets folder.
What is the best approach and what would I have to do in order to access the assets folders from each module?
Here is my directory structure so far:
Also am I right to put a Requests folder in each module?
Here is there relevant composer.json section:
"autoload": {
"classmap": [
"database",
"app/Modules"
],
"psr-4": {
"App\\": "app/",
"Modules\\": "Modules/"
}
},
Take a look at the Packages section in the official Laravel documentation. It has sections on keeping things like translation files and other assets in your package, and publishing them when including your package in your applications.

Thin Controllers in Laravel 4

I am trying to work out the 'best' way of structuring my controllers/models in a new Laravel 4 app.
Obviously I want to keep the controllers thin and lightweight. So I want to work with Repos/Services to separate things, however I don't really know how to implement this in Laravel 4. Laravel 3 gave us some idea of how this should work, but no samples.
Has any one figured out the neatest way to do this, or have any sample code I could take a peek at?
I agree on the fact that it isn't very clear where to store these classes in Laravel 4.
A simple solution would be creating repositories/services folders in your main app/ folder and updating your main composer.json file to have them autoloaded:
{
"require": {
"laravel/framework": "4.0.*"
},
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/tests/TestCase.php",
"app/repositories",
"app/services"
]
},
"minimum-stability": "dev"
}
Note: everytime you create a new class you have to run composer dump-autoload.
In case of repositories, you can have Laravel inject them into your controllers automatically. I find this a good screencast on this subject.
I found this collection of tutorials to be a great introduction on the proper place to store your custom service providers and other files that you want to inject into your project:
http://fideloper.com/laravel-4-application-setup-app-library-autoloading
http://fideloper.com/laravel-4-where-to-put-bindings
http://fideloper.com/error-handling-with-content-negotiation
These tutorials come from this collection:
http://fideloper.com/tag/laravel-4
The first thing that I do when I get a fresh install of Laravel is:
Remove the "models" folder
Create a src folder
Under the src, create a Application folder (or the name of the app)
On Application folder, create Entities, Repositories, Services and Tests
So, in this case your namespace will be Application\Entities, Application\Repositories and Application\Services
In composer.json:
{
"require": {
"laravel/framework": "4.0.*"
},
"autoload": {
"psr-0": {
"Application": "app/src/"
},
"classmap": [
"app/commands",
"app/controllers",
"app/database/migrations",
]
},
"minimum-stability": "dev"
}
To each one of those you'll need to create the classes and a service provider to bind a repository to an entity.
Here is a tutorial explaining how to create the repositories:
http://culttt.com/2013/07/08/creating-flexible-controllers-in-laravel-4-using-repositories/
Anyway, I'm still looking for the best architecture. If anyone has a better idea, I'll be glad to hear it!

Categories