{"id":13609607,"url":"https://github.com/yidas/codeigniter-psr4-autoload","last_synced_at":"2025-10-18T11:02:42.651Z","repository":{"id":57086799,"uuid":"117560196","full_name":"yidas/codeigniter-psr4-autoload","owner":"yidas","description":"CodeIgniter 3 PSR-4 Autoloader for Application","archived":false,"fork":false,"pushed_at":"2023-03-06T14:27:57.000Z","size":9,"stargazers_count":54,"open_issues_count":1,"forks_count":10,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-06-24T00:32:19.709Z","etag":null,"topics":["codeigniter","inheritance","interface","namespace","psr-4","trait"],"latest_commit_sha":null,"homepage":"https://codeigniter.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yidas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2018-01-15T15:09:09.000Z","updated_at":"2025-03-25T12:51:08.000Z","dependencies_parsed_at":"2023-10-11T13:14:19.277Z","dependency_job_id":null,"html_url":"https://github.com/yidas/codeigniter-psr4-autoload","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"7bf6254851f3aab4945b616ec597ccc160ead87b"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/yidas/codeigniter-psr4-autoload","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fcodeigniter-psr4-autoload","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fcodeigniter-psr4-autoload/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fcodeigniter-psr4-autoload/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fcodeigniter-psr4-autoload/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yidas","download_url":"https://codeload.github.com/yidas/codeigniter-psr4-autoload/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yidas%2Fcodeigniter-psr4-autoload/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266869422,"owners_count":23998041,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-24T02:00:09.469Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codeigniter","inheritance","interface","namespace","psr-4","trait"],"created_at":"2024-08-01T19:01:36.462Z","updated_at":"2025-10-18T11:02:42.573Z","avatar_url":"https://github.com/yidas.png","language":"PHP","readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://codeigniter.com/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://camo.githubusercontent.com/b1df5003f5bc21277aeb87c5d3558242b74eb54a61a253cc061a38c7a43bcac7/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f7a682f372f37632f436f646549676e697465722e706e67\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eCodeIgniter PSR-4 Autoload\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\nCodeIgniter 3 PSR-4 Autoloader for Application\n\n[![Latest Stable Version](https://poser.pugx.org/yidas/codeigniter-psr4-autoload/v/stable?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)\n[![License](https://poser.pugx.org/yidas/codeigniter-psr4-autoload/license?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)\n[![Total Downloads](https://poser.pugx.org/yidas/codeigniter-psr4-autoload/downloads?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)\n[![Monthly Downloads](https://poser.pugx.org/yidas/codeigniter-psr4-autoload/d/monthly?format=flat-square)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)\n\nThis PSR-4 extension is collected into [yidas/codeigniter-pack](https://github.com/yidas/codeigniter-pack) which is a complete solution for Codeigniter framework.\n\nFEATURES\n--------\n\n- ***PSR-4 Namespace** support as Yii2 \u0026 Laravel elegant patterns like*\n\n- *Easy way to use **Interface, Trait, Abstract and Extending Class***\n\n- ***Whole Codeigniter application** directory structure support*\n\n---\n\nOUTLINE\n-------\n\n- [Demonstration](#demonstration)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n  - [Extending Class](#extending-class)\n  - [Interface](#interface)\n  - [Trait](#trait)\n  - [Abstract](#abstract)\n- [Conception](#conception)\n- [Limitations](#limitations)\n  \n---\n\nDEMONSTRATION\n-------------\n\nBy default, all PSR-4 namespace with `app` prefix in Codeigniter would relates to application directory.\n\n- The class `/application/libraries/MemberService.php` could be called by:\n\n```php\nnew \\app\\libraries\\MemberService;\n```\n\n- The class `/application/services/Process.php` with `static run()` method could be called by:\n\n```php\n\\app\\services\\Process::run();\n```\n\n- Enable to extend or implement classes with standard way:\n\n```php\nclass Blog_model extends app\\models\\BaseModel {}\nclass Blog extends app\\components\\BaseController {}\nclass Car implements app\\contracts\\CarInterface {}\n```\n\n---\n\nREQUIREMENTS\n------------\n\nThis library requires the following:\n\n- PHP 5.3.0+\n- CodeIgniter 3.0.0+\n\n---\n\nINSTALLATION\n------------\n\nRun Composer in your Codeigniter project under the folder `\\application`:\n\n    composer require yidas/codeigniter-psr4-autoload\n    \nCheck Codeigniter `application/config/config.php`:\n\n```php\n$config['composer_autoload'] = TRUE;\n```\n    \n\u003e You could customize the vendor path into `$config['composer_autoload']`\n\n---\n\nUSAGE\n-----\n\nAfter installation, the namespace prefix `app` is used for the current Codeigniter application directory.\n\n\n### Static Class\n\n\nCreate a hepler with PSR-4 namespace with a new `helpers` folder under `application` directory, for eaxmple `\\application\\helpers\\`:\n\n```php\n\u003c?php\nnamespace app\\helpers;\n\nclass ArrayHelper\n{\n    public static function indexBy($input) {}\n}\n```\n\nThen call it in Controller action:\n\n```php\n\u003c?php\nuse app\\helpers\\ArrayHelper;\n...\nArrayHelper::indexBy($input);\n\\app\\helpers\\ArrayHelper::indexBy($input);\n```\n\n### Extending Class\n\nCreate a class with PSR-4 namespace under `application` directory, for eaxmple `application/model/BaseModel.php`:\n\n```php\n\u003c?php\nnamespace app\\models;\n\nclass BaseModel extends \\CI_Model {}\n```\n\nThen define a class to extend above class, for eaxmple `application/model/My_model.php`:\n\n```php\n\u003c?php\n\nclass My_model extends app\\models\\BaseModel {}\n```\n\n\u003e In this case, Codeigniter `My_model` could not use PSR-4 namespace.\n\n\n### Interface\n\nCreate a interface with a new `interface` folder under `application` directory, for eaxmple `application/interface/CarInterface.php`:\n\n```php\n\u003c?php\nnamespace app\\interfaces;\n\ninterface CarInterface {}\n```\n\nThen apply the interface to a class, for eaxmple `application/libraries/Car.php`:\n\n```php\n\u003c?php\nnamespace app\\libraries;\n\nclass Car implements \\app\\interfaces\\CarInterface {}\n```\n\n\u003e In this case, the `Car` lib could be called by using `new \\app\\libraries\\Car;`.\n\n\n### Trait\n\nCreate a trait under `application` directory, for eaxmple `application/libraries/LogTrait.php`:\n\n```php\n\u003c?php\nnamespace app\\components;\n\ntrait LogTrait {}\n```\n\nThen inject the trait into a class, for eaxmple `application/controller/Blog.php`:\n\n```php\nclass Blog extends CI_Controller\n{\n    use \\app\\components\\LogTrait;\n}\n```\n\n### Abstract\n\nCreate an abstract under `application` directory, for eaxmple `application/libraries/BaseController.php`:\n\n```php\n\u003c?php\nnamespace app\\components;\n\nabstract class BaseController extends \\CI_Controller {}\n```\n\nThen define a class to extend above abstract class, for eaxmple `application/libraries/BaseController.php`:\n\n```php\nclass Blog extends app\\components\\BaseController {}\n```\n\n---\n\nCONCEPTION\n----------\n\nCodeigniter 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.\n\nThus, 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.\n\n---\n\nLIMITATIONS\n-----------\n\n### Namespace Class No Longer Support CI_Loader\n\nThe called class need to define namespace to support PSR-4 Autoload only, which means it would not support Built-in CI_Loader anymore.\n","funding_links":[],"categories":["Core","PHP"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyidas%2Fcodeigniter-psr4-autoload","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyidas%2Fcodeigniter-psr4-autoload","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyidas%2Fcodeigniter-psr4-autoload/lists"}