public function getParameters() { $params = array(); sgAutoloader::loadFile('Console_Getopt', dirname(__FILE__) . '/vendor/Console/Getopt.php'); $cg = new Console_Getopt(); $params = $cg->readPHPArgv(); array_shift($params); return $params; }
public static function checkCache() { if (sgConfiguration::get('settings.cache_autoload')) { $cacheFile = sgConfiguration::get('settings.cache_dir') . '/sgAutoloadCache.cache'; if (file_exists($cacheFile)) { self::$isCached = true; self::$_cache = unserialize(file_get_contents($cacheFile)); return true; } } self::$isCached = false; //self::loadPaths(array(dirname(__FILE__) . '/../')); return false; }
protected function parseParams($namespace, $task, $cliParams = array()) { sgAutoloader::loadFile('Console_Getopt', dirname(__FILE__) . '/vendor/Console/Getopt.php'); $arguments = array(); $options = array(); $taskDefinition = self::getTask($namespace, $task); if (isset($taskDefinition['options']) || isset($taskDefinition['arguments'])) { if (!isset($taskDefinition['arguments'])) { $taskDefinition['arguments'] = array(); } if (!isset($taskDefinition['options']['short'])) { $taskDefinition['options']['short'] = null; } if (!isset($taskDefinition['options']['long'])) { $taskDefinition['options']['long'] = array(); } try { $params = Console_Getopt::getopt($cliParams, $taskDefinition['options']['short'], $taskDefinition['options']['long']); if (!empty($taskDefinition['arguments']) && (!isset($params[1]) || count($taskDefinition['arguments']) !== count($params[1]))) { throw new Exception('Missing required argument.'); } $arguments = array(); if (!empty($taskDefinition['arguments'])) { $arguments = array_combine($taskDefinition['arguments'], $params[1]); } $options = array(); foreach ($params[0] as $param) { $options[$param[0]] = $param[1]; } } catch (Exception $e) { $error = array(); $error[] = $e->getMessage(); if (isset($taskDefinition['usage'])) { $error[] = 'Usage: ' . $taskDefinition['usage']; } sgCLI::error($error); return false; } } return array('arguments' => $arguments, 'options' => $options); }
public static function init() { self::registerDoctrine(); sgAutoloader::loadPaths(array(self::getPath('models')), '.class.php'); }
private static function _initPlugins($dir, array $plugins) { foreach ($plugins as $pluginName) { $plugin = new StdClass(); $plugin->name = $pluginName; $plugin->path = "{$dir}/plugins/{$pluginName}"; sgAutoloader::loadPaths(array($plugin->path)); $class = $plugin->name . "Configuration"; if (class_exists($class)) { $configuration = new $class(); sgToolkit::executeMethod($configuration, 'preConfig'); $plugin->configuration = $configuration; } self::loadConfig('settings', "{$plugin->path}/config/config.php", true); self::loadConfig('routing', "{$plugin->path}/config/routing.php", true); if (isset($configuration)) { sgToolkit::executeMethod($configuration, 'postConfig'); } self::$enabledPlugins[$plugin->name] = $plugin; } }
public static function stick($routes) { if (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { $method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']); } else { if (isset($_REQUEST['_method'])) { $method = strtoupper($_REQUEST['_method']); } else { $method = strtoupper($_SERVER['REQUEST_METHOD']); } } if (!in_array($method, self::$allowedMethods)) { throw new BadMethodCallException("Method, {$method}, not supported"); exit; } $path = sgContext::getCurrentPath(); $matchedRoute = null; if (sgConfiguration::get('settings.cache_routes')) { $matchedRoute = self::checkRouteCache($path, $method); } if (!$matchedRoute) { foreach ($routes as $name => $route) { $matches = array(); $regex = str_replace('/', '\\/', $route['path']); $regex = '^' . $regex . '\\/?$'; if (preg_match("/{$regex}/i", $path, $matches)) { $route['name'] = $name; $route['matches'] = $matches; $route['path'] = $path; $matchedRoute = $route; self::$cachedRoutes["{$method} {$path}"] = $matchedRoute; break; } } } if (!$matchedRoute) { if (sgConfiguration::get('settings.magic_routing')) { $matchedRoute = array('path' => $path, 'class' => 'sgMagicController', 'method' => $method, 'matches' => array()); self::$cachedRoutes["{$method} {$path}"] = $matchedRoute; } else { $obj = new sgBaseController($matches); print $obj->throwErrorCode('404'); } } if ($matchedRoute) { if (!sgConfiguration::get('settings.magic_routing') && $matchedRoute['class'] == 'sgMagicController') { $obj = new sgBaseController($matchedRoute['matches']); print $obj->throwErrorCode('404'); } else { self::dispatch($matchedRoute, $method, $matchedRoute['matches']); } } self::shutdown(); sgAutoloader::shutdown(); }
public static function preConfig() { sgAutoloader::loadFile('Spyc', realpath(dirname(__FILE__) . '/../lib/vendor/spyc/spyc.php')); }