All Projects → yidas → Codeigniter Psr4 Autoload

yidas / Codeigniter Psr4 Autoload

Licence: mit
CodeIgniter 3 PSR-4 Autoloader for Application

Projects that are alternatives of or similar to Codeigniter Psr4 Autoload

Crab
JavaScript library for building user interfaces with Custom Elements, Shadow DOM and React like API
Stars: ✭ 22 (-45%)
Mutual labels:  interface
Ph2date
💕 Powerful & lightweight PHP Dating Script built with CodeIgniter 2.X and Bootstrap + jQuery 💖
Stars: ✭ 20 (-50%)
Mutual labels:  codeigniter
Codeigniter Restserver Test
A temporary repository for testing https://github.com/chriskacerguis/codeigniter-restserver
Stars: ✭ 35 (-12.5%)
Mutual labels:  codeigniter
Codeigniter 3d Sanalpos
Codeigniter Tüm Bankalar İçin 3D Sanal Pos Entegrasyonu
Stars: ✭ 27 (-32.5%)
Mutual labels:  codeigniter
Typescript Type Generator
Generate interfaces on the go! Network request? Then generate interfaces for response!
Stars: ✭ 11 (-72.5%)
Mutual labels:  interface
Binarytraits.jl
Can do or not? It's easy. See https://tk3369.github.io/BinaryTraits.jl/dev/
Stars: ✭ 30 (-25%)
Mutual labels:  interface
Upboard ros
ROS nodes for upboard usage
Stars: ✭ 22 (-45%)
Mutual labels:  interface
Thedev.id
🎉 An identity for developers on the web.
Stars: ✭ 37 (-7.5%)
Mutual labels:  namespace
Tui
A text-based user interface library for golang based on termbox
Stars: ✭ 12 (-70%)
Mutual labels:  interface
Laravel Guided Image
Simplified and ready image manipulation for Laravel through intervention image.
Stars: ✭ 32 (-20%)
Mutual labels:  trait
React Planner
✏️ A React Component for plans design. Draw a 2D floorplan and navigate it in 3D mode.
Stars: ✭ 846 (+2015%)
Mutual labels:  interface
Element
Programmatic UI for macOS
Stars: ✭ 855 (+2037.5%)
Mutual labels:  interface
Grocery Crud
Grocery CRUD is a PHP Codeigniter Framework library that creates a full functional CRUD system without the requirement of extra customisation to the JavaScripts or the CSS to do it so.
Stars: ✭ 962 (+2305%)
Mutual labels:  codeigniter
Codeigniter Authit
CodeIgniter 3 User Authentication Library thats Lightweight, flexible, and Secure
Stars: ✭ 23 (-42.5%)
Mutual labels:  codeigniter
Tygit
A basic terminal interface for git, written on Node.js [Project not maintained]
Stars: ✭ 36 (-10%)
Mutual labels:  interface
Eloquent Sortable
Sortable behaviour for Eloquent models
Stars: ✭ 914 (+2185%)
Mutual labels:  trait
Gwasrapidd
gwasrapidd: an R package to query, download and wrangle GWAS Catalog data
Stars: ✭ 28 (-30%)
Mutual labels:  trait
Plant
Trait-Driven Models of Ecology and Evolution 🌲
Stars: ✭ 39 (-2.5%)
Mutual labels:  trait
Opensourcetest
OpenSourceTest由自动化测试-夜行者社区维护,提供的是更多地灵活性和可配置性
Stars: ✭ 37 (-7.5%)
Mutual labels:  interface
Plugins
Plugins for SmartHomeNG - The device integration platform for your smart home
Stars: ✭ 32 (-20%)
Mutual labels:  interface

CodeIgniter PSR-4 Autoload


CodeIgniter 3 PSR-4 Autoloader for Application

Latest Stable Version License Total Downloads Monthly Downloads

This PSR-4 extension is collected into yidas/codeigniter-pack which is a complete solution for Codeigniter framework.

FEATURES

  • PSR-4 Namespace support as Yii2 & Laravel elegant patterns like

  • Easy way to use Interface, Trait, Abstract and Extending Class

  • Whole Codeigniter application directory structure support


OUTLINE


DEMONSTRATION

By default, all PSR-4 namespace with app prefix in Codeigniter would relates to application directory.

  • The class /application/libraries/MemberService.php could be called by:
new \app\libraries\MemberService;
  • The class /application/services/Process.php with static run() method could be called by:
\app\services\Process::run();
  • Enable to extend or implement classes with standard way:
class Blog_model extends app\models\BaseModel {}
class Blog extends app\components\BaseController {}
class Car implements app\contracts\CarInterface {}

REQUIREMENTS

This library requires the following:

  • PHP 5.3.0+
  • CodeIgniter 3.0.0+

INSTALLATION

Run Composer in your Codeigniter project under the folder \application:

composer require yidas/codeigniter-psr4-autoload

Check Codeigniter application/config/config.php:

$config['composer_autoload'] = TRUE;

You could customize the vendor path into $config['composer_autoload']


USAGE

After installation, the namespace prefix app is used for the current Codeigniter application directory.

Static Class

Create a hepler with PSR-4 namespace with a new helpers folder under application directory, for eaxmple \application\helpers\:

<?php
namespace app\helpers;

class ArrayHelper
{
    public static function indexBy($input) {}
}

Then call it in Controller action:

<?php
use app\helpers\ArrayHelper;
...
ArrayHelper::indexBy($input);
\app\helpers\ArrayHelper::indexBy($input);

Extending Class

Create a class with PSR-4 namespace under application directory, for eaxmple application/model/BaseModel.php:

<?php
namespace app\models;

class BaseModel extends \CI_Model {}

Then define a class to extend above class, for eaxmple application/model/My_model.php:

<?php

class My_model extends app\models\BaseModel {}

In this case, Codeigniter My_model could not use PSR-4 namespace.

Interface

Create a interface with a new interface folder under application directory, for eaxmple application/interface/CarInterface.php:

<?php
namespace app\interfaces;

interface CarInterface {}

Then apply the interface to a class, for eaxmple application/libraries/Car.php:

<?php
namespace app\libraries;

class Car implements \app\interfaces\CarInterface {}

In this case, the Car lib could be called by using new \app\libraries\Car;.

Trait

Create a trait under application directory, for eaxmple application/libraries/LogTrait.php:

<?php
namespace app\components;

trait LogTrait {}

Then inject the trait into a class, for eaxmple application/controller/Blog.php:

class Blog extends CI_Controller
{
    use \app\components\LogTrait;
}

Abstract

Create an abstract under application directory, for eaxmple application/libraries/BaseController.php:

<?php
namespace app\components;

abstract class BaseController extends \CI_Controller {}

Then define a class to extend above abstract class, for eaxmple application/libraries/BaseController.php:

class Blog extends app\components\BaseController {}

CONCEPTION

Codeigniter Loader is a good practice for loading one time instantiated component just like Yii2 Application Components, but it's lacking of Class mapping, which makes inconvenience to load classes including interfaces, traits, abstracts or extending classes.

Thus, You could defind classes with PSR-4 Namespace while these classes are not component kind, even Helpers which you may want use static method and customized class name.


LIMITATIONS

Namespace Class No Longer Support CI_Loader

The called class need to define namespace to support PSR-4 Autoload only, which means it would not support Built-in CI_Loader anymore.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].