FuelPHP Framework - Class and Namespace alias library

Related tags

Miscellaneous alias
Overview

Fuel Alias

Build Status Code Coverage Quality Score HHVM Status

Library for lazy class aliasing.

Install

Via Composer

$ composer require fuelphp/alias

Usage

Within FuelPHP class aliases are used to provide easy access to namespaced classes and facilitate class inheritance injection.

The package exposes an alias manager which lets you create 3 types of aliases:

  • Literal
    A one-to-one translation. Class "Namespaced\Classname" translates to "Another\Classname".
  • Namespace
    Namespace aliases allow you to alias an entire namespace with one call.
  • Replacement
    A pattern is matched an through replacements a new class is generated. "Namespace\*" maps to "Alias\$1".

When registering the alias manager append or prepends itself to the autoload stack to act as a pre-processor or fallback. Depending on the amount of aliases and it could be beneficial to alternate between pre- or appending.

By default the manager will prepend itself to the autoloader stack.

Basic Usage

// Create a new alias manager
$manager = new Fuel\Alias\Manager;

// Register the manager
$manager->register();

// Alias one class
$manager->alias('Alias\Me', 'To\This');

// Or alias many
$manager->alias([
	'Alias\This' => 'To\Me',
	'AndAlias\This' => 'To\SomethingElse',
]);

//

Namespace usage

// alias to a less deep namespace
$manager->aliasNamespace('Less\Deep', 'Some\Super\Deep\Name\Space');


// alias a namespace to global
$manager->aliasNamespace('Some\Space', '');

Pattern Usage

$manager = new Fuel\Alias\Manager;

// Alias with wildcards
$manager->aliasPattern('Namespaced\*', 'Other\\$1');

$otherThing = new Namespaced\Thing;

This can result into class resolving that doesn't exists. Luckily the package is smart enough the check wether the class exists and will continue to look for the correct class if the resolved class does not exist. This is also taken into account when it comes to caching. Only resolved classes that exist will be cached.

Contributing

Thank you for considering contribution to FuelPHP framework. Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

You might also like...
Utilities to scan PHP code and generate class maps.

composer/class-map-generator Utilities to generate class maps and scan PHP code. Installation Install the latest version with: $ composer require comp

WooCommerce function and class declaration stubs for static analysis.

WooCommerce Stubs This package provides stub declarations for WooCommerce functions, classes and interfaces. These stubs can help plugin and theme dev

Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files.
Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files.

Class Preloader for PHP This tool is used to generate a single PHP script containing all of the classes required for a specific use case. Using a sing

A class to help convert bytes into other units (kb, mb, etc).

A class to help convert bytes into other units (kb, mb, etc). This package can be used to convert int|float values from bytes to KB, MB and GB as well

A small package to add computed properties to any PHP class. 🐘

Computed Properties This package provides a trait and attribute that can provide computed property support. Installation This package can be installed

COP4331 Class Project 1 - "ConnectUs" virtual contact manager/Rolodex

ConnectUs COP4331 Class Project 1 - "ConnectUs" virtual contact manager/Rolodex Team Members Orion (Project Manager) Eric (Database) Rafael (API/Backe

Class for manage directly leds on raspberry pi in PHP

led_raspberry Class for manage directly leds on raspberry pi in PHP We can access GPIO ports directly with fwrite() for power on|off leds, without use

A class for easy connection to the zarinpal port
A class for easy connection to the zarinpal port

Payment class with ZarinPal A class to simplify payment operations and confirm payment of ZarrinPal payment gateway service ( به فارسی بخوانید ) Insta

Music website developed as a final group project for our Webpage Development class.

double-drummer Music listening website developed as final group project for our Webpage Development course. All parts that disclosed any information r

Comments
  • Convert tests to use vfs

    Convert tests to use vfs

    Update the cache tests to use vfs to make them cleaner and simplify the build script.

    Ultimately remove the cache class once the fuelphp/cache package is finished.

    opened by emlynwest 0
  • Recursive resolve based on aliases

    Recursive resolve based on aliases

    It would be a good feature to be able to resolve aliases which are also defined as aliases in the manager.

    So AliasedClass->OneMoreAliasedClass->RealClass could work.

    Real life example: Fuel v1 legacy support

    Namespace\OldClassName->New\Name\Space\NewClassName Namespace -> ''

    This way OldClassName is available from the global namespace.

    Temporary workaround is to use as many managers as the required levels, but that is ugly.

    opened by sagikazarmark 4
Releases(2.0.0)
Owner
fuelphp-storage
fuelphp-storage
Exploiting and fixing security vulnerabilities of an old version of E-Class. Project implemented as part of the class YS13 Cyber-Security.

Open eClass 2.3 Development of XSS, CSRF, SQLi, RFI attacks/defences of an older,vulnerable version of eclass. Project implemented as part of the clas

Aristi_Papastavrou 11 Apr 23, 2022
A simple, standalone, modern PHP class inspector and mapper library, wrapping PHPs native reflection in a fluent interface

A simple, standalone, modern PHP class inspector and mapper library, wrapping PHPs native reflection in a fluent interface.

smpl 9 Sep 1, 2022
Basic class library to read, write and view files using PHP.

File Basic class library to read, write and view files using PHP. Supported PHP Versions Build Status (dev) Main Aim of The Library The main aim of th

WebFiori 2 May 13, 2022
Allows generate class files parse from json and map json to php object, including multi-level and complex objects;

nixihz/php-object Allows generate class files parse from json and map json to php object, including multi-level and complex objects; Installation You

zhixin 2 Sep 9, 2022
CRUD Build a system to insert student name information, grade the class name, and edit and delete this information

CRUD Build a system to insert student name information, grade the class name, and edit and delete this information

Sajjad 2 Aug 14, 2022
A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.

A lightweight php class for formatting sql statements. Handles automatic indentation and syntax highlighting.

Doctrine 1.4k Dec 29, 2022
Demonstration of OOP concepts and usage of Abstract class & Interfaces

Learn OOP Demonstration of OOP concepts and usage of Abstract class & Interfaces Usage clone this repo run composer install run php index.php Code str

M N Islam Shihan 3 Sep 14, 2021
Polonium is a world class old school ✍️ blog website made with Php and Tailwind 🌀

Polonium Polonium is a world class old school ✍️ blog website made with Php and Tailwind ?? to write dump articles about... Yeah I know, you should pr

Youness Idbakkasse 2 Jan 10, 2022
This PHP class uploads files and manipulates images very easily

This PHP class uploads files and manipulates images very easily. It is in fact as much as an image processing class than it is an upload class. Compatible with PHP4, 5 and 7. Supports processing of local files, uploaded files, files sent through XMLHttpRequest.

Colin Verot 795 Dec 21, 2022
PHP class for convert KA letters to LAT and back

Kautilities PHP class for convert KA letters to LAT and back Installation Install this package through Composer. Edit your project's composer.json fil

Avtandil Kikabidze 4 Jan 11, 2018