Skip to content

Commit b267778

Browse files
committed
Update for packagist
1 parent a912d47 commit b267778

File tree

11 files changed

+150
-51
lines changed

11 files changed

+150
-51
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: php
2+
3+
cache:
4+
directories:
5+
- $HOME/.composer/cache/files
6+
7+
php:
8+
- 7.2
9+
- 7.3
10+
11+
install:
12+
- composer install
13+
14+
script: phpunit --exclude-group FITS --bootstrap vendor/autoload.php tests/LoaderTest

README.md

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# PHP Auto Autoloader
22

3-
![alt text](https://img.shields.io/github/languages/top/prod3v3loper/php-auto-autoloader.svg?style=flat "Language")
3+
![Language](https://img.shields.io/github/languages/top/prod3v3loper/php-auto-autoloader.svg?style=flat "Language")
44
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/90539baa57ba4ea1beb8451090f42547)](https://www.codacy.com/app/prod3v3loper/php-auto-autoloader?utm_source=github.com&utm_medium=referral&utm_content=prod3v3loper/php-auto-autoloader&utm_campaign=Badge_Grade)
5-
![alt text](https://img.shields.io/github/repo-size/prod3v3loper/php-auto-autoloader.svg?style=flat "Repo size")
6-
![alt text](https://img.shields.io/github/languages/code-size/prod3v3loper/php-auto-autoloader.svg?style=flat "Code size")
7-
![alt text](https://img.shields.io/github/license/prod3v3loper/php-auto-autoloader.svg?style=flat "License")
8-
[![alt text](https://img.shields.io/website-up-down-green-red/https/www.tnado.com/open-source-projects-by-prod3v3loper.svg?style=flat "Website")](https://www.tnado.com/open-source-projects-by-prod3v3loper/ "Website")
5+
![Repo Size](https://img.shields.io/github/repo-size/prod3v3loper/php-auto-autoloader.svg?style=flat "Repo size")
6+
![Code SIze](https://img.shields.io/github/languages/code-size/prod3v3loper/php-auto-autoloader.svg?style=flat "Code size")
7+
![MIT License](https://img.shields.io/github/license/prod3v3loper/php-auto-autoloader.svg?style=flat "MIT License")
8+
[![Website](https://img.shields.io/website-up-down-green-red/https/www.tnado.com/open-source-projects-by-prod3v3loper.svg?style=flat "Website")](https://www.tnado.com/open-source-projects-by-prod3v3loper/ "Website")
99

1010
With this autoloader, you do not need any more, no matter where you have a master in your root, the autoloader of MB tnado Ai will find it.
1111
[Theme Page of this Site](https://prod3v3loper.github.io/php-auto-autoloader/)
@@ -15,11 +15,65 @@ With this autoloader, you do not need any more, no matter where you have a maste
1515
The only thing you have to do is to integrate the file `init.php` and the autoload folder to the root of your project, that's it :)
1616
And now instantiate your classes, interfaces, traits or even abstract classes, no matter where.
1717

18-
## Example
18+
## Git clone
19+
20+
```
21+
git clone https://github.com/prod3v3loper/syntaxo.git /Users/username/projects/
22+
```
23+
24+
Get per [Git](https://git-scm.com/) or download and use it.
25+
26+
```php
27+
<?php
28+
define('MBT_DOCUMENT_ROOT', __DIR__);
29+
require_once './autoload/src/class.Loader.php';
30+
?>
31+
<!DOCTYPE html>
32+
<html>
33+
<head>
34+
<meta charset="UTF-8">
35+
<title>MB tnado Ai - Autoload</title>
36+
</head>
37+
<body>
38+
<?php
39+
40+
// METHOD 1: Fastest way, the namespace is foldername structure and filename is equal to filename
41+
$class_one = new testclasses\classOne();
42+
$class_one->method_from_class_one();
43+
44+
// METHOD 2: The slower way, namespace is equal to folder structure but the classname is differnt to the filename
45+
$class_two = new testclasses\classes\class_two();
46+
$class_two->method_from_class_two();
47+
48+
// METHOD 3: The slowest way, here ist nothing euqal
49+
$three_class = new name_space\namespace2\three_class();
50+
$three_class->method_from_three_class();
51+
52+
?>
53+
</body>
54+
</html>
55+
```
56+
57+
## Packagist with Composer
58+
59+
This solution extends the vendor autoloader because it calls the files with certain criteria. The extension allows you to call classes wherever the Autloder is involved.
60+
61+
Autoload and package in **composer.json**
62+
```json
63+
{
64+
"autoload": {
65+
"psr-4": { "Aautoloder\\": "autoload/src" }
66+
},
67+
"require": {
68+
"prod3v3loper/php-auto-autoloader": ">=1.0"
69+
},
70+
```
1971

2072
```php
2173
<?php
22-
require_once 'init.php';
74+
define('MBT_DOCUMENT_ROOT', __DIR__);
75+
require_once __DIR__ . '/vendor/autoload.php';
76+
new \Aautoloder\Loader(array(MBT_DOCUMENT_ROOT));
2377
?>
2478
<!DOCTYPE html>
2579
<html>
@@ -46,6 +100,7 @@ require_once 'init.php';
46100
</body>
47101
</html>
48102
```
103+
49104
# Debug
50105

51106
`autoload/core.config.php`
@@ -69,7 +124,7 @@ DEFAULT: `MBT_DOCUMENT_ROOT`
69124
The autoloader define get the web root by self on require the `init.php`
70125
```php
71126
define('MBT_DOCUMENT_ROOT', __DIR__);
72-
define('MBT_SERVER_ROOT', str_replace(MBT_DOCUMENT_ROOT, '', str_replace(filter_input(INPUT_SERVER, 'DOCUMENT_ROOT'), '', str_replace("\\", "/", __DIR__))));
127+
define('MBT_SERVER_ROOT', str_replace(MBT_DOCUMENT_ROOT, '', str_replace(filter_input(INPUT_SERVER, 'DOCUMENT_ROOT'), '', str_replace("\\", "/", MBT_DOCUMENT_ROOT))));
73128
define('MBT_HTTP_ROOT', get_protocol() . get_host() . MBT_SERVER_ROOT);
74129
```
75130

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?php
22

3-
namespace autoload;
3+
declare(strict_types = 1);
4+
5+
namespace Aautoloder;
6+
7+
require_once "class.LoaderHelper.php";
8+
require_once "core.config.php";
9+
require_once "func.core.php";
410

511
/**
612
* Description of Autoload
@@ -10,8 +16,8 @@
1016
* @author Samet Tarim (prod3v3loper)
1117
* @copyright (c) 2017, Samet Tarim
1218
* @link https://www.tnado.com/
13-
* @package MelAbu
14-
* @subpackage MB tnado Ai
19+
* @package Melabuai
20+
* @subpackage autoloader
1521
* @since 1.0
1622
* @see https://github.com/prod3v3loper/php-auto-autoloader
1723
*/
@@ -282,9 +288,6 @@ private function loopSort($path, array &$results = array()) {
282288

283289
}
284290

285-
if (class_exists('autoload\Loader')) {
286-
// Path to force - Default: MBT_DOCUMENT_ROOT
287-
$GLOBALS['MBT_AUTOLOAD'] = new Loader(array(MBT_DOCUMENT_ROOT));
288-
} else {
289-
trigger_error("The Class Loader() from Autoload can't initiate.", E_USER_ERROR);
290-
}
291+
// Define web roots
292+
define('MBT_SERVER_ROOT', str_replace(MBT_DOCUMENT_ROOT, '', str_replace(filter_input(INPUT_SERVER, 'DOCUMENT_ROOT'), '', str_replace("\\", "/", MBT_DOCUMENT_ROOT))));
293+
define('MBT_HTTP_ROOT', get_protocol() . get_host() . MBT_SERVER_ROOT);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22

3-
namespace autoload;
3+
namespace Aautoloder;
44

55
/**
66
* Description of Autoload
77
*
88
* @author Samet Tarim (prod3v3loper)
99
* @copyright (c) 2017, Samet Tarim
1010
* @link https://www.tnado.com/
11-
* @package MelAbu
12-
* @subpackage MB tnado Ai
11+
* @package Melabuai
12+
* @subpackage autoloader
1313
* @since 1.0
1414
* @see https://github.com/prod3v3loper/php-auto-autoloader
1515
*/
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
* @author Samet Tarim (prod3v3loper)
77
* @copyright (c) 2017, Samet Tarim
88
* @link https://www.tnado.com/
9-
* @package MelAbu
10-
* @subpackage MB tnado Ai
9+
* @package Melabuai
10+
* @subpackage autoloader
1111
* @since 1.0
1212
* @see https://github.com/prod3v3loper/php-auto-autoloader
1313
*/

composer.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
2-
"name": "prod3v3loper/php-auto-aotoloader",
2+
"name": "prod3v3loper/php-auto-autoloader",
33
"type": "library",
4-
"description": "Testing composer for php",
4+
"description": "Need any more, no matter where you have a master in your root, the autoloader will find it.",
5+
"keywords": ["autoloader"],
56
"homepage": "https://www.tnado.com/open-source-projects-by-prod3v3loper/",
67
"license": "MIT",
78
"repositories": [
89
{
910
"type": "git",
10-
"url": "https://github.com/prod3v3loper/php-auto-aotoloader.git"
11+
"url": "https://github.com/prod3v3loper/php-auto-autoloader.git"
1112
}
1213
],
1314
"authors": [
@@ -18,13 +19,16 @@
1819
}
1920
],
2021
"autoload": {
21-
"psr-4": { "Syn\\": "src/" }
22+
"psr-4": { "Aautoloder\\": "autoload/src" }
2223
},
2324
"autoload-dev": {
24-
"psr-4": { "Syn\\": "tests/" }
25+
"psr-4": {
26+
"Aautoloder\\": "autoload/src",
27+
"Aautoloder\\": "tests/"
28+
}
2529
},
2630
"require": {
27-
"php": ">=7.0"
31+
"php": ">=5.1.2"
2832
},
2933
"require-dev": {
3034
"phpunit/phpunit": "^7"

index.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,14 @@
1-
<?php require_once("./init.php"); ?>
1+
<?php
2+
// Decomment for debug
3+
// error_reporting(-1); // Report all PHP errors
4+
// ini_set('error_reporting', -1); // -1 is E_ALL
5+
// ini_set('display_errors', 1); // Show all PHP errors
6+
7+
define('MBT_DOCUMENT_ROOT', __DIR__);
8+
//require_once './autoload/src/Loader.php';
9+
require_once __DIR__ . '/vendor/autoload.php';
10+
new \Aautoloder\Loader(array(MBT_DOCUMENT_ROOT));
11+
?>
212
<!DOCTYPE html>
313
<html>
414
<head>
@@ -7,19 +17,21 @@
717
</head>
818
<body>
919
<?php
10-
1120
// METHOD 1: Fastest way, the namespace is foldername structure and filename is equal to filename
1221
$class_one = new testclasses\classOne();
1322
$class_one->method_from_class_one();
14-
23+
?>
24+
<br>
25+
<?php
1526
// METHOD 2: The slower way, namespace is equal to folder structure but the classname is differnt to the filename
1627
$class_two = new testclasses\classes\class_two();
1728
$class_two->method_from_class_two();
18-
29+
?>
30+
<br>
31+
<?php
1932
// METHOD 3: The slowest way, here ist nothing euqal
2033
$three_class = new name_space\namespace2\three_class();
2134
$three_class->method_from_three_class();
22-
2335
?>
2436
</body>
2537
</html>

init.php

Lines changed: 0 additions & 17 deletions
This file was deleted.

testclasses/classOne.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class classOne {
66

77
public function method_from_class_one() {
88

9-
echo "I am Class classOne have a namespace testclasses and a method method_from_class_one\n";
9+
echo "I am Class classOne have a namespace testclasses and a method method_from_class_one";
1010
}
1111

1212
}

0 commit comments

Comments
 (0)