Bonjour,

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:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
 
<?php
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:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
<?php
$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?