Permalink
Browse files

Merge pull request #15 from phoenixrises/master

Various commits from @phoenixrises
  • Loading branch information...
2 parents b0f6669 + 206ffdc commit 8325a77f319d303012527729065ff8ede5d6deab @jimmyff jimmyff committed Feb 1, 2012
@@ -35,6 +35,7 @@
protected $cache = array();
/* CONSTRUCTOR & DESTRUCTOR */
+ public function __construct() { }
/* GET METHODS */
/**
@@ -134,4 +135,4 @@ protected function &initCache($name) {
return $this->cache[$name];
}
}
-?>
+?>
@@ -45,6 +45,13 @@ class atsumi_AppHandler {
private $uri;
/**
+ * The command to be parsed and processed
+ * @access private
+ * @var string
+ */
+ private $command;
+
+ /**
* Holds the base path of atsumi relative to the domain
* @access private
* @var string
@@ -59,6 +66,13 @@ class atsumi_AppHandler {
private $uriParser = 'uriparser_Gyokuro';
/**
+ * The command parser classname or instance to use
+ * @access private
+ * @var string|object
+ */
+ private $claParser = 'claparser_Standard';
+
+ /**
* The controller instance generated based on the parser data
* @access private
* @var object
@@ -127,6 +141,16 @@ public function getBaseUri() {
// SET FUNCTIONS
/**
+ * Sets the command to be parsed and processed
+ * @access public
+ * @param string $path
+ */
+ public function setCommand($command) {
+ $this->command = $command;
+ }
+
+
+ /**
* Sets the uri to be parsed and processed
* @access public
* @param string $path
@@ -184,13 +208,18 @@ public function createUri($controller, $method) {
* @param string $uri The uri to processed
*/
public function go($uri) {
-
- $scriptArr = explode('/',$_SERVER['SCRIPT_NAME']);
- $baseUri = str_replace(array($_SERVER['DOCUMENT_ROOT'], end($scriptArr)), '', $_SERVER['SCRIPT_FILENAME']);
- $this->setBaseUri($baseUri);
-
- $this->setUri($uri);
- $this->parseUri();
+ if(isset($this->settings->get_cli) && $this->settings->get_cli === true) {
+ $this->setBaseUri('.');
+ $this->setCommand($uri);
+ $this->parseCommand();
+ } else {
+ $scriptArr = explode('/',$_SERVER['SCRIPT_NAME']);
+ $baseUri = str_replace(array($_SERVER['DOCUMENT_ROOT'], end($scriptArr)), '', $_SERVER['SCRIPT_FILENAME']);
+ $this->setBaseUri($baseUri);
+
+ $this->setUri($uri);
+ $this->parseUri();
+ }
$this->process();
}
@@ -223,6 +252,29 @@ public function parseUri() {
array_merge(array('path' => $this->uri), $this->parserData), true);
}
+ public function parseCommand() {
+ atsumi_Debug::startTimer();
+ if(!in_array('claparser_Interface', class_implements($this->claParser))) {
+ throw new Exception('Command Line Argument parser must implement claparser_Interface');
+ }
+ if(is_string($this->claParser)) {
+ $this->claParser = new $this->claParser();
+ }
+ $parseData = $this->claParser->parseCommand($this->command, $this->settings->init_specification);
+
+ $this->parserData = array(
+ 'controller' => $parseData['controller'],
+ 'method' => $parseData['method'],
+ 'args' => $parseData['args']
+ );
+
+ atsumi_Debug::setParserData($parseData);
+ atsumi_Debug::record('Command Parsing',
+ 'Command was parsed to determine the controller, method and args.',
+ array_merge(array('path' => $this->command), $this->parserData), true);
+
+ }
+
/**
* Processes the controller and method choosen by the parser
* Note: parseUri method must be execute before this method
@@ -232,7 +284,6 @@ public function process() {
// Could possibly be a fragment of the spec
if(!is_string($this->parserData['controller']))
throw new Exception('Path parsing error, please report to developement team');
-
if(!class_exists($this->parserData['controller']))
throw new Exception('Could not find required controller: '.$this->parserData['controller']);
@@ -316,4 +367,4 @@ public function render() {
atsumi_Debug::record('Rendering Complete', 'All rendering was completed successfully', null, true);
}
}
-?>
+?>
@@ -0,0 +1,37 @@
+<?php
+class app_InvalidUsageException extends atsumi_AbstractException {
+ /**
+ * The controller that was being called
+ * @access protected
+ * @var string
+ */
+ protected $controller;
+
+ /**
+ * The method that was being called
+ * @access protected
+ * @var string
+ */
+ protected $method;
+ protected $args = array();
+
+ /* CONSTRUCTOR & DESTRUCTOR */
+
+ /**
+ * Creates a new app_PageNotFoundException instance
+ * @access public
+ * @param string $controller The name of the controller being called
+ * @param string $method The name of the method being called
+ */
+ public function __construct($_ = null) {
+ parent::__construct('Usage Error: Command malformed');
+ }
+
+ /* GET METHODS */
+ public function getInstructions($contentType) {
+ }
+ /* SET METHODS */
+ /* MAGIC METHODS */
+ /* METHODS */
+}
+?>
@@ -0,0 +1,23 @@
+<?php
+/**
+ * A base interface class for cla parsers
+ * @package Atsumi.Framework
+ * @subpackage Core
+ * @since 0.90
+ */
+interface claparser_Interface {
+ /* CONSTRUCTOR & DESTRUCTOR */
+ /* GET METHODS */
+ /* SET METHODS */
+ /* MAGIC METHODS */
+ /* METHODS */
+
+ /**
+ * Parses a command using the given specification to determine the required controller, method and args
+ * @access public
+ * @param string $uri The uri to parse
+ * @param array $specfication The specification to parse against
+ */
+ public function parseCommand($path, $specfication);
+}
+?>
@@ -0,0 +1,19 @@
+<?php
+class claparser_Standard implements claparser_Interface {
+ public function parseCommand($command, $spec) {
+ $return = array();
+ $baseCommand = array_shift($command);
+ $controller = array_shift($command);
+ // Does the controller exist in the spec?
+ if(in_array($controller, array_keys($spec))) {
+ $controller = $spec[$controller];
+ }
+ $return['controller'] = $controller;
+ // Method will always have to be determinded by methodlessRequest
+ // Required info for working method our further up the stack
+ $return['method'] = 'methodlessRequest';
+ $return['args'] = $command;
+ return $return; # fancy that
+ }
+}
+?>
@@ -132,14 +132,6 @@ static function date($in) {
return atsumi_Date::fromYmd($in);
}
- static function date($in) {
- return atsumi_Date::fromYmd($in);
- }
-
- static function date($in) {
- return atsumi_Date::fromYmd($in);
- }
-
static function time($in) {
if (is_null($in)) return null;
//TODO: time stuff
@@ -152,4 +144,4 @@ static function timeOrNull($in) {
return $in;
}
}
-?>
+?>
@@ -496,13 +496,32 @@ public function count ($table, $where = null) {
* DELETE
* */
public function delete ($args) {
- throw new db_Exception ('TODO');
+ /* parse the query */
+ $args = func_get_args();
+ $query = call_user_func_array (array ($this, 'parseDeleteQuery'), $args);
+
+ /* perform query */
+ $this->query('%l', $query);
+
+ return true;
}
public function deleteOne ($args) {
throw new db_Exception ('TODO');
}
public function parseDeleteQuery ($args) {
- throw new db_Exception ('TODO');
+ if (is_null($this->caster))
+ throw new db_Exception('Caster not loaded.');
+
+ $args = func_get_args ();
+ $sets = $this->caster->castArraySets($args);
+ $deleteFrom = array_shift ($sets);
+ $where = array_shift ($sets);
+
+ /* return update query string */
+ return $this->caster->castString(
+ 'DELETE FROM %@ WHERE %l', $deleteFrom, $where
+ );
+
}
/*
Oops, something went wrong.

0 comments on commit 8325a77

Please sign in to comment.