Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yidas/codeigniter-psr4-autoload

CodeIgniter 3 PSR-4 Autoloader for Application
https://github.com/yidas/codeigniter-psr4-autoload

codeigniter inheritance interface namespace psr-4 trait

Last synced: about 2 months ago
JSON representation

CodeIgniter 3 PSR-4 Autoloader for Application

Awesome Lists containing this project

README

        





CodeIgniter PSR-4 Autoload



CodeIgniter 3 PSR-4 Autoloader for Application

[![Latest Stable Version](https://poser.pugx.org/yidas/codeigniter-psr4-autoload/v/stable?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)
[![License](https://poser.pugx.org/yidas/codeigniter-psr4-autoload/license?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)
[![Total Downloads](https://poser.pugx.org/yidas/codeigniter-psr4-autoload/downloads?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)
[![Monthly Downloads](https://poser.pugx.org/yidas/codeigniter-psr4-autoload/d/monthly?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)

This PSR-4 extension is collected into [yidas/codeigniter-pack](https://github.com/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](#demonstration)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
- [Extending Class](#extending-class)
- [Interface](#interface)
- [Trait](#trait)
- [Abstract](#abstract)
- [Conception](#conception)
- [Limitations](#limitations)
 
---

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:

```php
new \app\libraries\MemberService;
```

- The class `/application/services/Process.php` with `static run()` method could be called by:

```php
\app\services\Process::run();
```

- Enable to extend or implement classes with standard way:

```php
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`:

```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
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
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