Switched to composer generated autoloader.
This commit is contained in:
parent
d89e155947
commit
1febb1a414
|
@ -3,3 +3,4 @@
|
||||||
#*
|
#*
|
||||||
favicon.*
|
favicon.*
|
||||||
tests/coverage.html
|
tests/coverage.html
|
||||||
|
/vendor
|
16
README.md
16
README.md
|
@ -1,6 +1,18 @@
|
||||||
# Friendica Global Directory
|
# Decentralized Friendica Directory
|
||||||
|
|
||||||
Example cronjob.
|
## Installing
|
||||||
|
|
||||||
|
### 1. Create an autoloader with composer
|
||||||
|
|
||||||
|
Make sure you have composer installed globally, or rewrite the command to use a `.phar`.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
composer dump-autoload
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Set up the cronjobs.
|
||||||
|
|
||||||
|
Example cronjob using `www-data` user.
|
||||||
|
|
||||||
```
|
```
|
||||||
*/30 * * * * www-data cd /var/www/friendica-directory; php include/cron_maintain.php
|
*/30 * * * * www-data cd /var/www/friendica-directory; php include/cron_maintain.php
|
||||||
|
|
41
autoload.php
41
autoload.php
|
@ -1,41 +0,0 @@
|
||||||
<?php
|
|
||||||
spl_autoload_register(function ($class) {
|
|
||||||
|
|
||||||
// the package namespace
|
|
||||||
$ns = 'Friendica\Directory';
|
|
||||||
|
|
||||||
// what prefixes should be recognized?
|
|
||||||
$prefixes = array(
|
|
||||||
"{$ns}\\" => array(
|
|
||||||
__DIR__ . '/src',
|
|
||||||
__DIR__ . '/tests/unit/src',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// go through the prefixes
|
|
||||||
foreach ($prefixes as $prefix => $dirs) {
|
|
||||||
|
|
||||||
// does the requested class match the namespace prefix?
|
|
||||||
$prefix_len = strlen($prefix);
|
|
||||||
if (substr($class, 0, $prefix_len) !== $prefix) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// strip the prefix off the class
|
|
||||||
$class = substr($class, $prefix_len);
|
|
||||||
|
|
||||||
// a partial filename
|
|
||||||
$part = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
|
|
||||||
|
|
||||||
// go through the directories to find classes
|
|
||||||
foreach ($dirs as $dir) {
|
|
||||||
$dir = str_replace('/', DIRECTORY_SEPARATOR, $dir);
|
|
||||||
$file = $dir . DIRECTORY_SEPARATOR . $part;
|
|
||||||
if (is_readable($file)) {
|
|
||||||
require $file;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"name": "friendica/dir",
|
||||||
|
"description": "The internet is our social network",
|
||||||
|
"license": "AGPL3",
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {"Friendica\\Directory\\": "src"}
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
//Add the auto loader. This makes sure that we can find the files we need for a class.
|
//Add the auto loader. This makes sure that we can find the files we need for a class.
|
||||||
require_once('autoload.php');
|
require_once('vendor/autoload.php');
|
||||||
|
|
||||||
//This says, we want Hello to mean Friendica\Directory\Example\Hello.
|
//This says, we want Hello to mean Friendica\Directory\Example\Hello.
|
||||||
//It's a shortcut.
|
//It's a shortcut.
|
||||||
|
|
Loading…
Reference in New Issue