pionl/laravel-config-class-gate
Class gateway from the laravel config
You can provide overriding of your classes via config file (a list of classes defined by config key - like custom Eloquent model). With this you can work with expected model but add a posibility to allow extending of your base classes.
In default tries to load classes from the classes.php config file.
Example
Example config (classes.php in config folder):
<?php
return [
"user" => App\\Models\\User::class
];
Call static method on class
$userGate = ClassGate::gate("user");
$users = $userGate->all() // will call User::all()
or shortcut
// will call User::all()
$users = ClassGate::gate("user")->all();
Create instance
$userGate = ClassGate::gate("user");
$user = $userGate->newInstance();
or shortcut
$user = ClassGate::instance("user");
$user = $userGate->theClass();
Class string:
$userGate = ClassGate::gate("user");
or shortcut
$userClass = ClassGate::objectClass("user");
Settings
Own config path
You can provide your own file or "array" path to the config via ClassGate::setConfigPath("models.list") which will find classes in models file and list array entry.
Example config (models.php in config folder):
<?php
return [
"othersKeys" : "...",
"list" => [
"user" => App\\Models\\User::class
]
];
Todo
- Own provider with default config file (optional)
- Gate that will convert method call to config key and will create the correct
ClassGateinstance - A command that will create file with docs of supported models (will support typehint on ClassGate static methods)
ClassGate proposal
ClassGate::user()that will call ClassGate::gate("user")
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Laravel Serializable Closure provides an easy and secure way to serialize closur...
Cli error handling for console/command-line PHP applications.
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| v0.1 | >=5.4.0 | ~5.1 | MIT |