"source": {
"type": "git",
"url": "git://git.andy128k.net/missing-tools.git",
- "reference": "b415e5cacd202b096112c9f4690dcc4f1cb16643"
+ "reference": "7d22f1cd70189d7b13d1cc30b846f9086abfc545"
},
"require": {
"andy128k/pegp": "0.1.*@dev",
}
],
"description": "Miscellaneous utilities",
- "time": "2014-09-14 13:43:45"
+ "time": "2014-11-09 08:28:31"
},
{
"name": "andy128k/pegp",
"source": {
"type": "git",
"url": "https://github.com/lichtner/fluentpdo.git",
- "reference": "80ab91b942439b50cf8d436d9826336a8fbe7d49"
+ "reference": "82801a7bd227c0224635433acdceff96d201b062"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/lichtner/fluentpdo/zipball/80ab91b942439b50cf8d436d9826336a8fbe7d49",
- "reference": "80ab91b942439b50cf8d436d9826336a8fbe7d49",
+ "url": "https://api.github.com/repos/lichtner/fluentpdo/zipball/82801a7bd227c0224635433acdceff96d201b062",
+ "reference": "82801a7bd227c0224635433acdceff96d201b062",
"shasum": ""
},
"type": "library",
"dbal",
"pdo"
],
- "time": "2014-09-06 19:01:53"
+ "time": "2014-11-07 19:35:13"
},
{
"name": "pear/archive_tar",
},
{
"name": "phpunit/phpunit",
- "version": "3.7.37",
+ "version": "3.7.38",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git",
- "reference": "ae6cefd7cc84586a5ef27e04bae11ee940ec63dc"
+ "reference": "38709dc22d519a3d1be46849868aa2ddf822bcf6"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ae6cefd7cc84586a5ef27e04bae11ee940ec63dc",
- "reference": "ae6cefd7cc84586a5ef27e04bae11ee940ec63dc",
+ "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/38709dc22d519a3d1be46849868aa2ddf822bcf6",
+ "reference": "38709dc22d519a3d1be46849868aa2ddf822bcf6",
"shasum": ""
},
"require": {
"testing",
"xunit"
],
- "time": "2014-04-30 12:24:19"
+ "time": "2014-10-17 09:04:17"
},
{
"name": "phpunit/phpunit-mock-objects",
},
{
"name": "symfony/yaml",
- "version": "v2.5.4",
+ "version": "v2.5.6",
"target-dir": "Symfony/Component/Yaml",
"source": {
"type": "git",
"url": "https://github.com/symfony/Yaml.git",
- "reference": "01a7695bcfb013d0a15c6757e15aae120342986f"
+ "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/Yaml/zipball/01a7695bcfb013d0a15c6757e15aae120342986f",
- "reference": "01a7695bcfb013d0a15c6757e15aae120342986f",
+ "url": "https://api.github.com/repos/symfony/Yaml/zipball/2d9f527449cabfa8543dd7fa3a466d6ae83d6726",
+ "reference": "2d9f527449cabfa8543dd7fa3a466d6ae83d6726",
"shasum": ""
},
"require": {
],
"description": "Symfony Yaml Component",
"homepage": "http://symfony.com",
- "time": "2014-08-31 03:22:04"
+ "time": "2014-10-01 05:50:18"
}
],
"aliases": [],
{
return array();
}
+
+ /**
+ * Returns Dictionary of assets
+ *
+ * @return array Dictionary of asset entry points mapped to output file
+ */
+ public function assets()
+ {
+ return array();
+ }
}
--- /dev/null
+<?php
+
+class IPF_Assets
+{
+ private $files = array();
+
+ public static function compile($dir, $path)
+ {
+ $compiler = new IPF_Assets;
+
+ $root = self::joinPath($dir, $path);
+ list($success, $data) = \PFF\TopSort::sort(array($root), array($compiler, 'following'));
+ if (!$success)
+ throw new Exception('Loop detected: '.implode(' -> ', $data));
+
+ $dump = array();
+ foreach ($data as $path) {
+ $dump[] = $compiler->files[$path];
+ }
+ return implode("\n", $dump);
+ }
+
+ function following($path)
+ {
+ if (!array_key_exists($path, $this->files))
+ $this->files[$path] = file_get_contents($path);
+ $content = $this->files[$path];
+
+ if (!preg_match_all('#^(//=\\s*require\\s*(\\S+)|/\\*=\\s*require\\s*(\\S+)\\s*\\*/)\\s*$#m', $content, $matches, PREG_SET_ORDER))
+ return array();
+
+ $dir = dirname($path);
+ $result = array();
+ foreach ($matches as $m) {
+ $result[] = self::joinPath($dir, @$m[2].@$m[3]);
+ }
+
+ return $result;
+ }
+
+ private static function joinPath($base, $file)
+ {
+ if (mb_substr($file, 0, 1) === '/')
+ $path = realpath($file);
+ else
+ $path = realpath($base . '/' . $file);
+
+ if (!$path)
+ throw new Exception("File '$file' not found in '$base'.");
+
+ return $path;
+ }
+}
+
$this->commands['Project'] = $project;
}
+ private function getCommand($commandName)
+ {
+ foreach ($this->commands as $group => $commands)
+ foreach ($commands as $command)
+ if ($command->command === $commandName)
+ return $command;
+ return null;
+ }
+
protected function usage()
{
print "Usage: php index.php <subcommand> [options] [args]\n";
return;
}
- foreach ($this->commands as $group => $commands) {
- foreach ($commands as $command) {
- if ($command->command === $args[1]) {
- $command->run(array_slice($args, 2));
- return;
- }
- }
+ $command = $this->getCommand($args[1]);
+ if (!$command) {
+ print "Unknown command: '".$args[1]."'\n\n";
+ $this->usage();
+ return;
}
- print "Unknown command: '".$args[1]."'\n\n";
- $this->usage();
+ try {
+ $command->run(array_slice($args, 2));
+ } catch (Exception $e) {
+ $m = $e->getMessage();
+ print "\n\033[1;31m$m\033[0m\n";
+ }
}
}
$source = $app->getPath() . 'static';
if (is_dir($source))
IPF_Utils::copyDirectory($source, $destination);
+
+ foreach ($app->assets() as $asset => $output) {
+ $content = IPF_Assets::compile($app->getPath(), $asset);
+
+ $dest = $destination . $output;
+ IPF_Utils::makeDirectories(dirname($dest));
+ file_put_contents($dest, $content);
+ }
}
}
}
{
private $filename;
- function __construct($filename, $downloadName, $mimetype='application/octet-stream')
+ function __construct($filename, $downloadName=null, $mimetype='application/octet-stream')
{
parent::__construct('', $mimetype);
$this->filename = $filename;
- $this->headers['Content-Description'] = 'File Transfer';
- $this->headers['Content-Disposition'] = 'attachment; filename='.basename($downloadName);
+ if ($downloadName) {
+ $this->headers['Content-Description'] = 'File Transfer';
+ $this->headers['Content-Disposition'] = 'attachment; filename='.basename($downloadName);
+ }
$this->headers['Content-Transfer-Encoding'] = 'binary';
$this->headers['Content-Length'] = filesize($filename);
}
class IPF_Middleware_Common
{
- function processRequest(&$request)
+ function processRequest($request)
{
if (IPF::get('append_slash', true)) {
$url = $request->absoluteUrl();
--- /dev/null
+<?php
+
+class IPF_Serve_Static_Middleware
+{
+ function processRequest($request)
+ {
+ $staticUrl = IPF::get('static_url');
+
+ if (!preg_match('#^'.preg_quote($staticUrl).'(.*)$#', $request->query, $matches))
+ return false;
+
+ $query = $matches[1];
+
+ foreach (IPF_Project::getInstance()->appList() as $app) {
+ $static = $app->getPath() . $staticUrl . $query;
+ if (is_file($static))
+ return new IPF_HTTP_Response_File($static, null, $this->mimetype($query));
+
+ $asset = array_search($query, $app->assets());
+ if ($asset !== false) {
+ $content = IPF_Assets::compile($app->getPath(), $asset);
+ return new IPF_HTTP_Response($content, $this->mimetype($query));
+ }
+ }
+
+ return false;
+ }
+
+ private function mimetype($filename)
+ {
+ switch (strtolower(pathinfo($filename, PATHINFO_EXTENSION))) {
+ case 'jpg':
+ case 'jpeg': return 'image/jpeg';
+ case 'png': return 'image/png';
+ case 'gif': return 'image/gif';
+ case 'svg': return 'image/svg+xml';
+ case 'js': return 'application/javascript';
+ case 'css': return 'text/css';
+ case 'htm':
+ case 'html': return 'text/html';
+ default: return 'application/octet-stream';
+ }
+ }
+}
+