PHP Classes

PHP Script Loader: Load PHP scripts from predefined directories

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 161 This week: 1All time: 8,946 This week: 560Up
Version License PHP version Categories
script-loader 1.0.0GNU Free Document...5.0PHP 5, Language
Description 

Author

This package can be used to load PHP scripts from predefined directories.

It takes the file name of a given script to load and determines its full path based on a list of directories to lookup regardless of what is defined in the include_path PHP configuration directive.

If the script exists, it can be loaded using either include_once or require_once.

The package comes also with auto-loader class to load classes from the same list of directories.

Picture of Everton da Rosa
  Performance   Level  
Name: Everton da Rosa <contact>
Classes: 17 packages by
Country: Brazil Brazil
Age: 42
All time rank: 78856 in Brazil Brazil
Week rank: 106 Up7 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 3x

Example

<?php

/*
 * Copyright (C) 2014 Everton
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */


/**
 * This file is a simple example use for Ptk\utils\ScriptLoader Class
 */

try{
    require
'examples.inc.php';
   
$loader = new \Ptk\utils\ScriptLoader(\Ptk\utils\ScriptLoader::getDirTree('..'));//get a instance of loader
   
    //show the include path
   
echo '<pre>';
   
print_r($loader->getPath());
    echo
'</pre>';
   
    try{
       
$loader->load('ptk.utils.validator.class.php');//require_once equivalent
   
} catch (Exception $ex) {
        throw
$ex;
    }
    if(
class_exists('Ptk\utils\Validator', false)){
        echo
'<p>ptk.utils.validator.class.php loaded!</p>';
    }else{
        echo
'<p>Fail on load ptk.utils.validator.class.php!</p>';
    }
   
    try{
       
$loader->load('ptk.utils.debug.class.php', false);//include_once equivalent
   
} catch (Exception $ex) {
        throw
$ex;
    }
    if(
class_exists('Ptk\utils\Debug', false)){
        echo
'<p>ptk.utils.debug.class.php loaded!</p>';
    }else{
        echo
'<p>Fail on load ptk.utils.debug.class.php!</p>';
    }
   
} catch (
Exception $ex) {
    echo
$ex->getMessage();
   
//echo $ex->getTraceAsString();
   
exit($ex->getCode());
}



  Files folder image Files  
File Role Description
Accessible without login Plain text file examples.inc.php Aux. Auxiliari file to examples
Plain text file ptk.class.php Class Auxiliari class
Plain text file ptk.fs.filefolder.directory.class.php Class Auxiliari class
Accessible without login Plain text file ptk.inc.php Aux. Auxiliary file
Plain text file ptk.utils.scriptloader.class.php Class The main class
Plain text file ptk.utils.validator.class.php Class Auxiliari class
Accessible without login Plain text file scriptloader.php Example Sample for use

 Version Control Unique User Downloads Download Rankings  
 0%
Total:161
This week:1
All time:8,946
This week:560Up