From e33cc3f0ef05b70e33f2cea882fb75a6d83bdcbd Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Sat, 22 Jun 2013 13:37:15 +0300 Subject: [PATCH] use composer and class maps --- composer.json | 14 ++++++++++++- composer.lock | 48 ++++++++++++++++++++++++++++++++++++++----- index.php | 8 +++----- ipf.php | 57 ++++++++++++++++++++++++++++++++++++++------------- 4 files changed, 102 insertions(+), 25 deletions(-) diff --git a/composer.json b/composer.json index c09cfaf..6983e78 100644 --- a/composer.json +++ b/composer.json @@ -12,8 +12,20 @@ "email": "andy128k@gmail.com" } ], + "autoload": { + "classmap" : ["."] + }, + "require": { + "andy128k/routeexpression": "dev-master" + }, "require-dev": { "phpunit/phpunit": "3.7.*" - } + }, + "repositories": [ + { + "type": "composer", + "url": "http://packages.andy128k.net/php/" + } + ] } diff --git a/composer.lock b/composer.lock index 576434e..adb9fdc 100644 --- a/composer.lock +++ b/composer.lock @@ -3,9 +3,47 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "1177f075c09daf9849c259a2f3c79236", + "hash": "20bffa57e6d8564e8b9bf75a6d2f70af", "packages": [ - + { + "name": "andy128k/routeexpression", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/andy128k/routeexpression.git", + "reference": "60f822ca0f7ea50a3bccdd29970d7ee1900c10a8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/andy128k/routeexpression/zipball/60f822ca0f7ea50a3bccdd29970d7ee1900c10a8", + "reference": "60f822ca0f7ea50a3bccdd29970d7ee1900c10a8", + "shasum": "" + }, + "require-dev": { + "phpunit/phpunit": "3.7.*" + }, + "type": "library", + "autoload": { + "classmap": [ + "src" + ] + }, + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Andrey Kutejko", + "email": "andy128k@gmail.com" + } + ], + "description": "Route expression", + "support": { + "source": "https://github.com/andy128k/routeexpression/tree/master", + "issues": "https://github.com/andy128k/routeexpression/issues" + }, + "time": "2013-06-22 08:01:38" + } ], "packages-dev": [ { @@ -417,9 +455,9 @@ ], "minimum-stability": "stable", - "stability-flags": [ - - ], + "stability-flags": { + "andy128k/routeexpression": 20 + }, "platform": [ ], diff --git a/index.php b/index.php index 93fb5ce..adeedf7 100644 --- a/index.php +++ b/index.php @@ -3,9 +3,7 @@ // This is a index stub for a IPF Projects $here = dirname(__FILE__); -$ipf_path = $here.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'ipf'; -$project_path = $here.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'project'; -set_include_path(get_include_path() . PATH_SEPARATOR . $ipf_path . PATH_SEPARATOR . $project_path); -require 'ipf.php'; -return IPF::boot($ipf_path, $project_path, $here) && IPF_Project::getInstance()->run(); +$project_path = $here . '/../project'; +require $project_path . '/vendor/andy128k/ipf/ipf.php'; +return IPF::setUp($project_path, $here) && IPF_Project::getInstance()->run(); diff --git a/ipf.php b/ipf.php index 2edf6c8..e4c99e0 100644 --- a/ipf.php +++ b/ipf.php @@ -1,12 +1,5 @@ getMessage()."\n"); } return true; @@ -144,10 +139,10 @@ final class IPF { if (function_exists($function)) return; - if (preg_match('/^(\w+)::\w+$/', $function, $m)) { - IPF_Autoload($m[1]); - return; - } + + if (preg_match('/^(\w+)::\w+$/', $function, $m)) + return; // nothing to do. autoloader will load a class. + $elts = explode('_', $function); array_pop($elts); $file = strtolower(implode(DIRECTORY_SEPARATOR, $elts)).'.php'; @@ -174,6 +169,40 @@ final class IPF } } +class IPF_ClassLoader +{ + private $classMap; + + private static $loader = null; + + public static function getInstance($project_path) + { + if (self::$loader == null) + self::$loader = new IPF_ClassLoader($project_path); + return self::$loader; + } + + private function __construct($project_path) + { + $dir = $project_path . '/vendor/composer/'; + + $includePaths = require $project_path . '/vendor/composer/include_paths.php'; + array_push($includePaths, get_include_path()); + set_include_path(join(PATH_SEPARATOR, $includePaths)); + + $this->classMap = require $project_path . '/vendor/composer/autoload_classmap.php'; + + spl_autoload_register(array($this, 'load'), true, true); + } + + public function load($class) + { + if (isset($this->classMap[$class])) { + include $this->classMap[$class]; + } + } +} + function __($str) { $t = trim($str); -- 2.49.0