-
-
Save scoates/738340 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* README | |
* mkdir one && mkdir two && mkdir three && touch one/blueprint-1.3.css && touch one/foobar.css && touch two/jquery.js && touch three/jquery-1.4.js | |
* | |
*/ | |
include('stack.php'); | |
Stack::header('jquery', '1.4', array(array('name' => 'blueprint', 'version' => '1.3'))); | |
echo "----------------<br/>"; | |
Stack::footer('jquery', '1.4'); | |
class Stack { | |
static $header = array(); | |
static $footer = array(); | |
static $added = array(); | |
// Add some searchable paths, one would be the most important folder | |
static $stack = array('one', 'two', 'three'); | |
static $list = array( | |
'jquery' => array('ext' => 'js', 'reqiures' => array(array('name' => 'foobar'))), | |
'blueprint' => array('ext' => 'css'), | |
'foobar' => array('ext' => 'css') | |
); | |
public static function header($name, $version = null, $reqiures = array()) | |
{ | |
if (self::added($name)) | |
{ | |
echo 'Already added! '.$name.'<br/>'; | |
return true; | |
} | |
if ( ! empty(self::$list[$name]['reqiures'])) | |
{ | |
$reqiures = array_merge($reqiures, self::$list[$name]['reqiures']); | |
} | |
if( ! empty($reqiures)) | |
{ | |
foreach($reqiures as $script) | |
{ | |
$req_name = $script['name']; | |
$req_version = ! empty($script['version']) ? $script['version'] : null; | |
$req_reqiures = ! empty($script['reqiures']) ? $script['reqiures'] : null; | |
Stack::header($req_name, $req_version, $req_reqiures); | |
} | |
} | |
foreach (self::$stack as $dir) | |
{ | |
$tmp = $dir.'/'.$name; | |
$tmp .= $version ? '-'.$version : ""; | |
$tmp .= '.'.self::$list[$name]['ext']; | |
if (is_file($tmp)) | |
{ | |
echo 'Found it! '.$tmp.'<br/>'; | |
// This path has a file, add it to the list | |
self::$header[] = $tmp; | |
self::$added[] = $name; | |
break; | |
} | |
} | |
} | |
public static function footer($name, $version = null, $reqiures = array()) | |
{ | |
if (self::added($name)) | |
{ | |
echo 'Already added! '.$name.'<br/>'; | |
return true; | |
} | |
if ( ! empty(self::$list[$name]['reqiures'])) | |
{ | |
$reqiures = array_merge($reqiures, self::$list[$name]['reqiures']); | |
} | |
if( ! empty($reqiures)) | |
{ | |
foreach($reqiures as $script) | |
{ | |
$req_name = $script['name']; | |
$req_version = ! empty($script['version']) ? $script['version'] : null; | |
$req_reqiures = ! empty($script['reqiures']) ? $script['reqiures'] : null; | |
Stack::footer($req_name, $req_version, $req_reqiures); | |
} | |
} | |
foreach (self::$stack as $dir) | |
{ | |
$tmp = $dir.'/'.$name; | |
$tmp .= $version ? '-'.$version : ""; | |
$tmp .= '.'.self::$list[$name]['ext']; | |
if (is_file($tmp)) | |
{ | |
echo 'Found it! '.$tmp.'<br/>'; | |
// This path has a file, add it to the list | |
self::$footer[] = $tmp; | |
self::$added[] = $name; | |
break; | |
} | |
} | |
} | |
public static function added($name) | |
{ | |
return in_array($name, self::$added); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment