Created
June 30, 2010 20:30
-
-
Save manuelkiessling/459175 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class cCommandLineTool implements cCommandLineToolInterface extends cTool { | |
const TYPE_DECLARED = 0; | |
const TYPE_BOOLEAN = 1; | |
private $sCronjobTitle = NULL; | |
private $sCronjobDescription = NULL; | |
private $aArguments = array(); | |
protected $bIsRunning = FALSE; | |
public $iErrorLevel = 0; | |
public $sErrorString = 0; | |
public function __construct($sCronjobTitle = NULL, cCronjobTemplate $oTemplate) { | |
$this->errorLevel = E_USER_NOTICE + E_NOTICE + E_WARNING; | |
$a = self::getTime(); | |
echo $a; | |
} | |
protected static function getTime() { | |
return time(); | |
} | |
protected function execute() { | |
if (!$oSystemRole->isCommandLine()) { | |
$this->printline('<pre>'); | |
} elseif ($oSystemRole->isSoap() && $this->hasXml() || $this->hasApi()) { | |
$this->printline('<xml>'): | |
} else { | |
$this->printline(); | |
} | |
try { | |
cShellPrinter::print($this->sOutput); | |
} catch (cShellPrinterException $e) { | |
$this->bUseOtherPrinter = TRUE; | |
} | |
foreach ($this->aArguments as $sArgumentName => $sArgumentDescription) { | |
$this->setArgumentValue($sArgumentName); | |
} | |
for ($i = 0; $i < 10; $i++) { | |
echo($i); | |
} | |
} | |
public function setArgumentValue($sArgumentTitle, $mArgumentValue) { | |
switch($this->aArgumentTypes[$sArgumentTitle]) { | |
case self::TYPE_BOOLEAN: | |
switch(strtolower($mArgumentValue)) { | |
case 'y': | |
case 'yes': | |
case TRUE: | |
$this->aArgumentValues[$sArgumentTitle] = TRUE; | |
break; | |
case 'n': | |
case 'no': | |
case FALSE: | |
$this->aArgumentValues[$sArgumentTitle] = FALSE; | |
break; | |
default: | |
$this->throwError('Trying to set argument --' . $sArgumentTitle . | |
' with invalid boolean ' . $mArgumentValue); | |
break; | |
} | |
break; | |
case self::TYPE_INTEGER: | |
if (is_numeric($mArgumentValue)) { | |
$this->aArgumentValues[$sArgumentTitle] = (int) $mArgumentValue; | |
} else { | |
$this->throwError('Trying to set argument --' . $sArgumentTitle . | |
' with invalid integer value ' . $mArgumentValue); | |
} | |
break; | |
default: | |
$this->throwError('Trying to set argument --' . $sArgumentTitle . | |
' with invalid type "' . gettype($mArgumentValue) . | |
'", expecting "' . | |
$this->getTypeAsString($this->aArgumentTypes[$sArgument])); | |
break; | |
} | |
} | |
public function __destruct() { | |
if ($this->bStarted) { | |
$this->printline('<<< OUTPUT END >>>'); | |
$this->printPerformance(); | |
$oSystemRole = cSystemRole::getInstance(); | |
if (!$oSystemRole->isCommandLine()) { | |
$this->printline('</pre>'); | |
} | |
} | |
} | |
} | |
class cCommandLineToolNoShellFoundException extends cException {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment