Download the PHP package artinict/laravel-customs without Composer
On this page you can find all versions of the php package artinict/laravel-customs. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-customs
Laravel Customs
LaravelCustoms (LC) is a package that provides a cleaner way to import your classes and third-party packages. You can think of it this way: Composer manages your dependencies, Customs regulates your imports.
LC uses a concept known as IOCA (Import Once Call Anywhere).
If you don't want to use this concept, LC will automatically import the class on the fly. (See "Automatic Resolving" below)
Table of Contents
- Installation
- Usage
- Import Once Call Anywhere (IOCA)
- Customs Configuration
- Auto Resolve
- Credits
- License
Installation
If the installation was successful, a will be created in the Laravel's directory.
NB: If you don't find the in , copy the in the to
Or:
Import LaravelCustoms at the top of any of your classes and run the app. Now check directory for
Usage
Import as at the top of your class.
Then you can access the instance like so:
The general syntax is . Below is how you would use in a real project.
Typically, you would do this:
But now, with LaravelCustoms, you don't have to import mulitple classes anymore. Instead you would import a single class like so:
OK! So i'm sure you're probably wondering why we still had to write . Well, technically, we didn't write that line of code. Laravel did that for us when we ran the command, .
As a rule of thumb, LaravelCustoms should not replace the default class imports written by Laravel.
Ok! So what about ?! Unfortunately, LC cannot support Dependency Injection (DI) as at v2.1😬
General usage with examples:
-
For non-static methods:
LC::Prefix_Classname(['methodName'], [args]); -
For static methods, put at the front of the methodName:
LC::Prefix_Classname(['::methodName'], [args]); -
Calling a non-static method without "Prefix":
LC::Classname(['methodName'], [args]); -
To get a non-static property of a class:
$classInstance = LC::Classname();
$property = (new $classInstance)->propertyName; -
To get a static property of a class:
LC::Classname()::$staticProperty; - Finally, if you don't pass any argument, LaravelCustoms will return the class path.
Import Once Call Anywhere (IOCA)
One of the objectives of LaravelCustoms is to get rid of having to repeatedly import classes everytime you need them. LC provides a cleaner way to do this by using a new concept known as IOCA (Import Once Call Anywhere).
In the customs configuration file provided (See next section). Define your imports like so:
Import using Alias
Alias is a simple way to import classes. This is perfect for your Models and other classes that are likely not to have a classname clash.
For example, can be imported as:
And this would be called as .
Import using prefix
Prefix is a cleaner way to import classes. It groups a set of classes into a category (called Prefix). This helps to mitigate classname clashes.
For example, can be imported as:
And this would be called as .
Customs Configuration
When you install the LaravelCustoms package, a will be created in the Laravel's directory. This is where you would import your classes using aliases and prefixes (Ensure you read through the below to familiarize yourself with the convention).
Note: LC_APP_NAMESPACE is a reserved key name and MUST NOT be overwritten.
Auto Resolve
If you call a class that wasn't imported in the . LaravelCustoms will automatically scan through the directory to find the class and import it on the fly. An Exception will be thrown if the class doesn't exist.
This approach is not recommended especially on large projects.
Credits
Sadiq Lukman, Artinict.
https://twitter.com/28thsly
License
The LaravelCustoms library is open-sourced software licensed under the MIT license.
All versions of laravel-customs with dependencies
illuminate/auth Version 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*
illuminate/contracts Version 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*
illuminate/http Version 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*
illuminate/support Version 5.1.* || 5.2.* || 5.3.* || 5.4.* || 5.5.* || 5.6.* || 5.7.* || 5.8.*