2017 © Pedro Peláez
 

library php-includer

A minimalistic PHP library/framework for include/require

image

tomaskraus/php-includer

A minimalistic PHP library/framework for include/require

  • Friday, August 18, 2017
  • by tomaskraus
  • Repository
  • 1 Watchers
  • 0 Stars
  • 18 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 18 Versions
  • 0 % Grown

The README.md

php-includer

NOTE: This project is Obsolete. Use the path-utils library - it does one thing and does it good., (*1)

A minimalistic PHP library/framework for include/require, (*2)

features

  • application root path
  • smart path join
  • "bootstrap" file auto include

Installation

Via composer:, (*3)

composer require tomaskraus/php-includer

, or add this snippet to composer.json, (*4)

    "require": {
        "tomaskraus/php-includer": "^0.4"
    },

php-includer usage options

  1. Use as a library: Create a new PI (php includer) instance with your application root path as a parameter.
  2. Use as a framework: Include piLoader.php in your requested page. It guesses your application root path and creates a new PI instance (a $pi variable) with that path guessed. It also automatically includes an user-defined "bootstrap" file (pi.bootstrap.php), an ideal place for your specific initialization piece of code.

application root path guess logic

  1. piLoader.php assumes that it is in a vendor/tomaskraus/php-include directory.
  2. piLoader.php assumes that a vendor directory is in the application root directory.

php-includer framework examples

Assume we have our php application in /var/www/myApp. A /var/www/myApp is our application root path (./)., (*5)

example 1: php-includer in the ./index.php file, (*6)

<?php
//A loader. Guesses an application root path and initializes a PhpIncluder instance.
require_once "./vendor/tomaskraus/php-includer/piLoader.php";

//once piLoader is included, a php-includer object ($pi) is available

//provides a web application root path
echo $pi->path(); //echoes "/var/www/myApp/"

//we can create new, non-existing path strings, based on a web application root
$pi->path("conf/file-to-be-created.php"); //returns "/var/www/myapp/conf/file-to-be-created.php".

//path-safe include, wherever you are
include $pi->path("myLib/utils.php"); //includes /var/www/myapp/myLib/utils.php

//smart path join, fixes missing or too many separators
PI::joinPath("myapp/", "/dist/app.zip"); //returns "myapp/dist/app.zip"
PI::joinPath("/var/www", "dist/app.zip"); //returns "/var/www/dist/app.zip", preserves a root slash
//join Windows path
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 2: php-includer in the ./login/index.php file, (*7)

<?php
//require piLoader
//we are not in application root directory, so we changed the path accordingly
require_once "./../vendor/tomaskraus/php-includer/piLoader.php";

//once piLoader is included, a php-includer object ($pi) is available

//provides a web application root path, even if you are not in application root directory
echo $pi->path(); //echoes "/var/www/myapp/"

//path-safe include, wherever you are (now we are in the "login" subdirectory)
include $pi->path("myLib/utils.php"); //includes /var/www/myapp/myLib/utils.php

bootstrap file

You can create a pi.bootstrap.php file in the application root directory and put whatever you want in it. That bootstrap file will be automatically included, wherever you include/require piLoader, regardless of (sub)directory. A bootstrap file is an ideal place for your specific initialization piece of code., (*8)

note: this bootstrap file has nothing to do with the Bootstrap CSS framework, (*9)

pi.bootstrap.php file example: assume we have a pi.bootstrap.php file in /var/www/myapp directory:, (*10)

<?php

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


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

//other, globally needed stuff...

This bootstrap file will be automatically included in both ./index.php and ./login/index.php files from previous examples., (*11)

The Versions

18/08 2017

dev-master

9999999-dev https://github.com/tomaskraus/php-includer

A minimalistic PHP library/framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

25/01 2017

v0.4.1

0.4.1.0 https://github.com/tomaskraus/php-includer

A minimalistic PHP library/framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

22/09 2016

0.4.0

0.4.0.0 https://github.com/tomaskraus/php-includer

A minimalistic PHP library/framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

22/09 2016

v0.3.2

0.3.2.0 https://github.com/tomaskraus/php-includer

A minimalistic PHP library/framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

22/09 2016

v0.3.3

0.3.3.0 https://github.com/tomaskraus/php-includer

A minimalistic PHP library/framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

22/09 2016

v0.3.1

0.3.1.0 https://github.com/tomaskraus/php-includer

A minimalistic PHP library/framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

22/09 2016

0.3.3

0.3.3.0 https://github.com/tomaskraus/php-includer

A minimalistic PHP framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

22/09 2016

0.3.2

0.3.2.0 https://github.com/tomaskraus/php-includer

A minimalistic PHP framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

22/09 2016

0.3.1

0.3.1.0 https://github.com/tomaskraus/php-includer

A minimalistic PHP framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

22/09 2016

v0.3.0

0.3.0.0 https://github.com/tomaskraus/php-includer

A minimalistic PHP framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

31/08 2016

v0.2.3-alpha

0.2.3.0-alpha https://github.com/tomaskraus/php-includer

A minimalistic PHP framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

31/08 2016

v0.2.2-alpha

0.2.2.0-alpha https://github.com/tomaskraus/php-includer

A minimalistic PHP framework for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

31/08 2016

v0.2.1-alpha

0.2.1.0-alpha https://github.com/tomaskraus/php-includer

A minimalistic PHP library for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

31/08 2016

v0.2.0-alpha

0.2.0.0-alpha https://github.com/tomaskraus/php-includer

A minimalistic PHP library for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

31/08 2016

v0.1.2-alpha

0.1.2.0-alpha https://github.com/tomaskraus/php-includer

A minimalistic PHP library for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

31/08 2016

v0.1.1-alpha

0.1.1.0-alpha https://github.com/tomaskraus/php-includer

A minimalistic PHP library for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

31/08 2016

v0.1.0-alpha

0.1.0.0-alpha https://github.com/tomaskraus/php-includer

A minimalistic PHP library for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path

30/08 2016

v0.1-alpha

0.1.0.0-alpha https://github.com/tomaskraus/php-includer

A minimalistic PHP library for include/require

  Sources   Download

MIT

The Requires

  • php ^5.3|^7.0

 

The Development Requires

by Avatar tomaskraus

php include require path