2017 © Pedro Peláez
 

library laravel-config-class-gate

Enables loading classes (or objects) via config files in Laravel

image

pionl/laravel-config-class-gate

Enables loading classes (or objects) via config files in Laravel

  • Thursday, October 27, 2016
  • by pionl
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

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., (*1)

In default tries to load classes from the classes.php config file., (*2)

Example

Example config (classes.php in config folder):, (*3)

<?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, (*4)

// will call User::all()
$users = ClassGate::gate("user")->all();

Create instance

$userGate = ClassGate::gate("user");
$user = $userGate->newInstance();

or shortcut, (*5)

$user = ClassGate::instance("user");
$user = $userGate->theClass();

Class string:

$userGate = ClassGate::gate("user");

or shortcut, (*6)

$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., (*7)

Example config (models.php in config folder):, (*8)

<?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 ClassGate instance
  • 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")

The Versions

27/10 2016

dev-master

9999999-dev

Enables loading classes (or objects) via config files in Laravel

  Sources   Download

MIT

The Requires

 

27/10 2016

v0.1

0.1.0.0

Enables loading classes (or objects) via config files in Laravel

  Sources   Download

MIT

The Requires