Skip to content

Instantly share code, notes, and snippets.

@stenehall
Created December 12, 2010 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stenehall/738335 to your computer and use it in GitHub Desktop.
Save stenehall/738335 to your computer and use it in GitHub Desktop.
Suggested stack improvements
<?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