Subversion Repositories Applications.gtt

Rev

Rev 62 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 62 Rev 104
1
<?php
1
<?php
2
 
2
 
3
abstract class aControlleurAction {
3
abstract class aControlleurAction {
4
 
4
 
5
    private $suivant;
5
    private $suivant;
6
 
6
 
7
	public function getRegistre()
7
	public function getRegistre()
8
	{
8
	{
9
		return Registre::getRegistre();
9
		return Registre::getRegistre();
10
	}
10
	}
11
 
11
 
12
    // Suivant
12
    // Suivant
13
    public function getSuivant()
13
    public function getSuivant()
14
	{
14
	{
15
		return $this->suivant;
15
		return $this->suivant;
16
	}
16
	}
17
	public function setSuivant($s, $position = null)
17
	public function setSuivant($s, $position = null)
18
	{
18
	{
19
		if (is_array($s)){
19
		if (is_array($s)){
20
			$this->suivant = $s;
20
			$this->suivant = $s;
21
		} else {
21
		} else {
22
			if (!is_null($position)) {
22
			if (!is_null($position)) {
23
				$tab_fin = array_slice($this->suivant, $position);
23
				$tab_fin = array_slice($this->suivant, $position);
24
				$tab_deb = array_slice($this->suivant, 0, $position);
24
				$tab_deb = array_slice($this->suivant, 0, $position);
25
				$this->suivant = array_merge($tab_deb, array($s), $tab_fin);
25
				$this->suivant = array_merge($tab_deb, array($s), $tab_fin);
26
			} else {
26
			} else {
27
				$this->suivant[] = $s;
27
				$this->suivant[] = $s;
28
			}
28
			}
29
		}
29
		}
30
	}
30
	}
31
 
31
 
32
	public function demarrer()
32
	public function demarrer()
33
    {
33
    {
34
		if (!is_null($this->getSuivant())) {
34
		if (!is_null($this->getSuivant())) {
35
			// ATTENTION :
35
			// ATTENTION :
36
			// Il est important de laisser "count($this->getSuivant())" $this->getSuivant() peut varier de taille
36
			// Il est important de laisser "count($this->getSuivant())" $this->getSuivant() peut varier de taille
37
			for ($i = 0; $i < count($this->getSuivant()) ; $i++) {
37
			for ($i = 0; $i < count($this->getSuivant()) ; $i++) {
38
				//echo '<pre>'.print_r($this->getSuivant(), true).'</pre>';
38
				//echo '<pre>'.print_r($this->getSuivant(), true).'</pre>';
39
				if ($this->getRegistre()->get('action_finale')) {
39
				if ($this->getRegistre()->get('action_finale')) {
40
					// Si l'action met fin au script prématurément nous arrétons
40
					// Si l'action met fin au script prématurément nous arrétons
41
					break;
41
					break;
42
				} else {
42
				} else {
43
					$liste_actions = $this->getSuivant();
43
					$liste_actions = $this->getSuivant();
44
					//echo '<pre>'.print_r($liste_actions[$i], true).'</pre>';
44
					//echo '<pre>'.print_r($liste_actions[$i], true).'</pre>';
45
					if ($liste_actions[$i] instanceof aControlleurAction) {
45
					if ($liste_actions[$i] instanceof aControlleurAction) {
46
						$liste_actions[$i]->demarrer();
46
						$liste_actions[$i]->demarrer();
47
					} else {
47
					} else {
48
						if (isset($_POST) || isset($_GET)) {
48
						if (isset($_POST) || isset($_GET)) {
49
							// Méthode "vérifier" générale présente dans aControlleurAction
49
							// Méthode "vérifier" générale présente dans aControlleurAction
50
							$this->verifier();
50
							$this->verifier();
51
							$methode_verif = 'verifier'.$liste_actions[$i];
51
							$methode_verif = 'verifier'.$liste_actions[$i];
52
							if (method_exists($this, $methode_verif)) {
52
							if (method_exists($this, $methode_verif)) {
53
								// Méthode "vérifier" spécifique à une action
53
								// Méthode "vérifier" spécifique à une action
54
								$this->$methode_verif();
54
								$this->$methode_verif();
55
							}
55
							}
56
						}
56
						}
57
						if ($liste_actions[$i] == '__defaut__') {
57
						if ($liste_actions[$i] == '__defaut__') {
58
							$methode = 'executer';
58
							$methode = 'executer';
59
						} else {
59
						} else {
60
							$methode = 'executer'.$liste_actions[$i];
60
							$methode = 'executer'.$liste_actions[$i];
61
						}
61
						}
62
						if (method_exists($this, $methode)) {
62
						if (method_exists($this, $methode)) {
63
							$this->$methode();
63
							$this->$methode();
64
						} else {
64
						} else {
65
							$m = "La méthode $methode de la classe ".get_class($this)." est introuvable!";
65
							$m = "La méthode $methode de la classe ".get_class($this)." est introuvable!";
66
	    					trigger_error($m, E_USER_ERROR);
66
	    					trigger_error($m, E_USER_ERROR);
67
						}
67
						}
68
					}
68
					}
69
				}
69
				}
70
			}
70
			}
71
		} else {
71
		} else {
72
			$m = "Le registre ne  contient aucune action!";
72
			$m = "Le registre ne  contient aucune action!";
73
    		trigger_error($m, E_USER_ERROR);
73
    		trigger_error($m, E_USER_ERROR);
74
		}
74
		}
75
    }
75
    }
76
 
76
 
77
	public function verifier()
77
	public function verifier()
78
    {
78
    {
79
    	// Nous rassemblons les valeurs du tableau _POST contenant des : dans des sous-tableau de _POST.
79
    	// Nous rassemblons les valeurs du tableau _POST contenant des : dans des sous-tableau de _POST.
80
    	foreach ($_POST as $cle => $val) {
80
    	foreach ($_POST as $cle => $val) {
81
    		$morceau = array();
81
    		$morceau = array();
82
    		if (preg_match('/^(.+?)(:.+)+$/', $cle, $morceau)) {
82
    		if (preg_match('/^(.+?)(:.+)+$/', $cle, $morceau)) {
83
    			$table = '';
83
    			$table = '';
84
    			foreach (explode(':', trim($morceau[2], ':')) as $c) {
84
    			foreach (explode(':', trim($morceau[2], ':')) as $c) {
85
    				$table .= '['.$c.']';
85
    				$table .= '['.$c.']';
86
    			}
86
    			}
87
    			eval('$_POST[$morceau[1]]'.$table.' = $val;');
87
    			eval('$_POST[$morceau[1]]'.$table.' = $val;');
88
    			unset($_POST[$cle]);
88
    			unset($_POST[$cle]);
89
    		}
89
    		}
90
    	}
90
    	}
91
    }
91
    }
92
 
92
 
93
    abstract protected function executer();
93
    abstract protected function executer();
94
}
94
}
95
?>
95
?>