├── .editorconfig ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── composer.json ├── phpcs.xml ├── phpunit.xml.dist ├── src └── autoload.php └── tests ├── bootstrap.php ├── cases └── autoload-test.php └── fixtures ├── class-plugin.php ├── extra └── trait-length.php ├── interface-say.php └── trait-name.php /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*.php] 5 | charset = utf-8 6 | end_of_line = lf 7 | indent_size = 4 8 | indent_style = tab 9 | insert_final_newline = true 10 | tab_width = 4 11 | trim_trailing_whitespace = true 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | composer.lock 2 | vendor 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | sudo: false 4 | 5 | php: 6 | - 5.4 7 | - 5.5 8 | - 5.6 9 | - 7.0 10 | - hhvm 11 | 12 | install: 13 | - travis_retry composer install --no-interaction --prefer-source 14 | 15 | script: 16 | - phpunit 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Fredrik Forsmo 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | 'Software'), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 17 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 18 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 19 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 20 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WordPress Autoload 2 | 3 | [![Build Status](https://travis-ci.org/wpup/autoload.svg?branch=master)](https://travis-ci.org/wpup/autoload) 4 | [![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/) 5 | 6 | Simple autoloader that will autoload classes, interfaces or traits with namespace prefix 7 | 8 | # Install 9 | 10 | ``` 11 | composer require frozzare/wp-autoload 12 | ``` 13 | 14 | ## Example 15 | 16 | Example of your main php file. 17 | 18 | ```php 19 | require 'vendor/autoload.php'; 20 | register_wp_autoload( 'Example\\', __DIR__ . '/src' ); 21 | ``` 22 | 23 | Example of `src/class-plugin-loader.php` 24 | 25 | ```php 26 | namespace Example; 27 | class Plugin_Loader {} 28 | ``` 29 | 30 | Example of `src/trait-crawler.php` 31 | 32 | ```php 33 | namespace Example; 34 | trait Crawler {} 35 | ``` 36 | 37 | Example of `src/interface-say.php` 38 | 39 | ```php 40 | namespace Example; 41 | interface Say {} 42 | ``` 43 | 44 | ## License 45 | 46 | MIT © [Fredrik Forsmo](https://github.com/frozzare) 47 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frozzare/wp-autoload", 3 | "description": "Simple autoloader that will autoload classes or traits with namespace prefix", 4 | "keywords": ["wordpress", "autoload", "namespace"], 5 | "license": "MIT", 6 | "authors": [ 7 | { 8 | "name": "Fredrik Forsmo", 9 | "email": "fredrik.forsmo@gmail.com" 10 | } 11 | ], 12 | "require": { 13 | "php": "^5.4 || ^7.0" 14 | }, 15 | "require-dev": { 16 | "phpunit/phpunit": "~4.0" 17 | }, 18 | "autoload": { 19 | "files": [ 20 | "src/autoload.php" 21 | ] 22 | }, 23 | "minimum-stability": "dev" 24 | } 25 | -------------------------------------------------------------------------------- /phpcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | WordPress autoload rules for PHP_CodeSniffer 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | ./tests/cases 20 | 21 | 22 | 23 | 24 | ./src 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/autoload.php: -------------------------------------------------------------------------------- 1 | assertEquals( 'Hello, world!', $plugin->hello() ); 10 | 11 | $hello_name = $plugin->hello_name( 'Foo' ); 12 | $this->assertEquals( 'Hello, Foo!', $hello_name ); 13 | $this->assertEquals( 11, $plugin->strlen( $hello_name ) ); 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /tests/fixtures/class-plugin.php: -------------------------------------------------------------------------------- 1 |