// This is a index stub for a IPF Projects
-$ipf_path = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'ipf';
-$project_path = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'project';
+$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) && IPF_Project::getInstance()->run();
+return IPF::boot($ipf_path, $project_path, $here) && IPF_Project::getInstance()->run();
return is_file($path);
}
- public static function boot($ipf_path, $project_path)
+ public static function boot($ipf_path, $project_path, $document_root)
{
if (php_sapi_name() === 'cli-server' && IPF::requestedFileExists())
return false;
IPF::$settings['ipf_path'] = $ipf_path;
IPF::$settings['project_path'] = $project_path;
+ IPF::$settings['document_root'] = $document_root;
try {
IPF::loadSettings();
public function __construct()
{
$this->commands = array(
+ new IPF_Command_DebugServer,
+ new IPF_Command_Routes,
new IPF_Command_BuildModels,
new IPF_Command_BuildContribModels,
new IPF_Command_Sql,
print "Usage: php index.php <subcommand> [options] [args]\n\n";
print "Available subcommands:\n";
- $firstColumnSize = 7;
- foreach ($this->commands as $command) {
- $l = strlen($command->command);
- if ($l > $firstColumnSize)
- $firstColumnSize = $l;
- }
- foreach ($this->commands as $command) {
- print ' '.str_pad($command->command, $firstColumnSize) . "\t" . $command->description . "\n";
- }
+ $rows = array();
+ foreach ($this->commands as $command)
+ $rows[] = array(
+ ' ' . $command->command,
+ $command->description,
+ );
+
+ IPF_Shell::displayTwoColumns($rows);
+
print "\n";
}
--- /dev/null
+<?php
+
+class IPF_Command_DebugServer
+{
+ public $command = 'run';
+ public $description = 'Run debug server on 0.0.0.0:8000';
+
+ public function run($args=null)
+ {
+ $root = IPF::get('document_root');
+ IPF_Shell::call('php', '-S', '0.0.0.0:8000', '-t', $root, $root . '/index.php');
+ }
+}
+
--- /dev/null
+<?php
+
+class IPF_Command_Routes
+{
+ public $command = 'routes';
+ public $description = 'Displays all routes';
+
+ public function run($args=null)
+ {
+ $rows = IPF_Router::describe();
+ IPF_Shell::displayTwoColumns($rows);
+ }
+}
+
}
return new IPF_HTTP_Response_NotFound();
}
+
+ public static function describe()
+ {
+ $routes = array();
+ foreach (IPF::get('urls') as $url) {
+ $prefix = $url['prefix'];
+ foreach ($url['urls'] as $suburl) {
+ $routes[] = array(
+ $prefix . $suburl['regex'],
+ $suburl['func'],
+ );
+ }
+ }
+ return $routes;
+ }
}
$process = proc_open($str, $descriptorspec, $pipes);
proc_close($process);
}
+
+ public static function displayTwoColumns($rows, $firstColumnMin=7, $firstColumnMax=47)
+ {
+ $firstColumnSize = $firstColumnMin;
+ foreach ($rows as $row) {
+ $l = strlen($row[0]);
+ if ($l > $firstColumnSize)
+ $firstColumnSize = $l;
+ }
+ if ($firstColumnSize > $firstColumnMax)
+ $firstColumnSize = $firstColumnMax;
+ foreach ($rows as $row) {
+ echo str_pad($row[0], $firstColumnSize) . "\t" . $row[1] . "\n";
+ }
+ }
}