Je tente mes premières expérimentations en POO.
Je n'ai pas encore intégré tous le verbage mais il faut bien commencer.
J'ai un problème avec le script suivant:
class Test
{
protected $view = array();
protected $output = array();
public function setOutput($data)
{
$this->output['data'] = $data;
}
public function setCurrentview($view)
{
$this->view['current'] = $view;
}
public function getCurrentView()
{
return $this->view['current'];
}
public function getData($view)
{
$provider = outputFactoryProvider::createOutput($view);
$provider->getOutput($view);
}
public function outputContent()
{
return $this->output;
}
}
interface outputProvider
{
public function getOutput($view);
}
class OutputDefaultProvider implements outputProvider
{
public function getOutput($view)
{
$cc = new CommandChain();
$cc->addCommand( new categoryCommand() );
$cc->runCommand( 'category', $view );
}
}
class outputFactoryProvider
{
public static function createOutput($view)
{
switch($view) {
default:
return new OutputDefaultProvider();
break;
}
}
}
interface ICommand
{
function onCommand($name, $args);
}
class CommandChain
{
private $_commands = array();
public function addCommand($cmd)
{
$this->_commands[] = $cmd;
}
public function runCommand($name, $args)
{
foreach($this->_commands as $cmd)
{
if ($cmd->onCommand($name, $args))
return;
}
}
}
class categoryCommand extends Test Implements ICommand
{
public function onCommand($name, $args)
{
$data = 'categoryCommand handling category<br/>';
parent::setOutput($data);
$this->output['category'] = 'category';
//print_r($this->output);
}
}
Avec le code suivant:$Test = new Test;
$Test->setCurrentView('testok');
$Test->getData( $Test->getCurrentView() );
print_r( $Test->outputContent() );
outputContent me renvoi NULL.le code mis en commentaire lui me renvoi bien les array.
Pourquoi mon objet est vide à la fin du script?