Skip to content

Commit

Permalink
remove feature: directory-based auto include
Browse files Browse the repository at this point in the history
  • Loading branch information
tomaskraus committed Sep 22, 2016
1 parent 6bae3a1 commit e4c6784
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 30 deletions.
32 changes: 7 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ via composer. include this snippet to composer.json

Assume we have our php application in `/var/www/myApp`. A `/var/www/myApp` is our application root directory (`./`).

example: `./index.php`
example: file `./index.php`
```php
<?php
//require piLoader
Expand All @@ -54,7 +54,7 @@ PI::joinPath("/var/www", "dist/app.zip"); //returns "/var/www/dist/app.zip", pre
PI::joinPath("C:\\www\\", "/dist/app.zip"); //returns "C:\\www/dist/app.zip", mixed result for Windows path (still works in PHP)
PI::joinPath("C:\\www", "dist/app.zip"); //returns the same...
```
**example**: `./login/index.php`
**example**: file `./login/index.php`
```php
<?php
//require piLoader
Expand All @@ -79,34 +79,16 @@ If there is a `pi.global.php` file in the application root directory, it is auto
```php
<?php

//class auto loader
//here you can already use a php-includer object, it is already included
include $pi->path("conf/config.php"); //includes /var/www/myapp/conf/config.php


//This file is a right place to write the class auto loader
$autoLoaderFile = __DIR__ . "/vendor/autoload.php";
if (file_exists($autoLoaderFile)) {
require_once $autoLoaderFile;
}

//here you can already use a php-includer object, it is already included
include $pi->path("conf/config.php"); //includes /var/www/myapp/conf/config.php
```

From the previous examples, `./pi.global.php` will be included in both `./index.php and` `./login/index.php` files.

### Auto include, based on a directory

If there is a `pi.dir.php` file in a `directory`, it is automatically included, wherever you include/require `piLoader` in php files in that `directory`.

**example**: `./user/pi.dir.php`
```php
<?php
//here you can already use a php-includer object, it is already included
include $pi->path("conf/config.php");

//restrict the access
if (userIsNotLoggedIn) {
require $pi->path("login/index.php"); //requires "/var/www/myApp/login/index.php"
}
```

`./user/pi.dir.php` will be applied to all files in (and only) the `./user` directory that includes the `piLoader`.

**note**: `pi.dir.php` inclusion behavior does not act recursively - that is, no eventual `pi.dir.php` from parent directory is included
5 changes: 0 additions & 5 deletions piLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,3 @@
include_once $fileToIncludeAlways;
}

//within the directory of a top-level includer
$fileToIncludeOnDirectoryLevel = "pi.dir.php";
if (file_exists($fileToIncludeOnDirectoryLevel)) {
include_once $fileToIncludeOnDirectoryLevel;
}

0 comments on commit e4c6784

Please sign in to comment.