Subversion Repositories Applications.gtt

Rev

Rev 11 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11 Rev 37
Line 1... Line 1...
1
<?php
1
<?php
Line 2... Line 2...
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)
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 {
-
 
22
			if (!is_null($position)) {
-
 
23
				$tab_fin = array_slice($this->suivant, $position);
-
 
24
				$tab_deb = array_slice($this->suivant, 0, $position);
-
 
25
				$this->suivant = array_merge($tab_deb, array($s), $tab_fin);
21
		} else {
26
			} else {
-
 
27
				$this->suivant[] = $s;
22
			$this->suivant[] = $s;
28
			}
23
		}
29
		}
24
	}
30
	}
25
	
31
 
26
	public function demarrer()
32
	public function demarrer()
27
    {
33
    {
28
		if (!is_null($this->getSuivant())) {
34
		if (!is_null($this->getSuivant())) {
29
			// ATTENTION :
35
			// ATTENTION :
30
			// 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
31
			for ($i = 0; $i < count($this->getSuivant()) ; $i++) {
37
			for ($i = 0; $i < count($this->getSuivant()) ; $i++) {
32
				$liste_actions = $this->getSuivant();
38
				//echo '<pre>'.print_r($this->getSuivant(), true).'</pre>';
33
				if ($liste_actions[$i] instanceof aControlleurAction) {
39
				if ($this->getRegistre()->get('action_finale')) {
-
 
40
					// Si l'action met fin au script prématurément nous arrétons
34
					$liste_actions[$i]->demarrer();
41
					break;
35
				} else {
42
				} else {
36
					if ($liste_actions[$i] == '__defaut__') {
-
 
37
						$methode = 'executer';
-
 
38
					} else {
43
					$liste_actions = $this->getSuivant();
39
						$methode = 'executer'.$liste_actions[$i];
-
 
40
					}
44
					//echo '<pre>'.print_r($liste_actions[$i], true).'</pre>';
41
					if (method_exists($this, $methode)) {
45
					if ($liste_actions[$i] instanceof aControlleurAction) {
42
						$this->$methode();
46
						$liste_actions[$i]->demarrer();
-
 
47
					} else {
-
 
48
						if (isset($_POST) || isset($_GET)) {
-
 
49
							// Méthode "vérifier" générale présente dans aControlleurAction
-
 
50
							$this->verifier();
-
 
51
							$methode_verif = 'verifier'.$liste_actions[$i];
-
 
52
							if (method_exists($this, $methode_verif)) {
-
 
53
								// Méthode "vérifier" spécifique à une action
-
 
54
								$this->$methode_verif();
-
 
55
							}
-
 
56
						}
-
 
57
						if ($liste_actions[$i] == '__defaut__') {
-
 
58
							$methode = 'executer';
-
 
59
						} else {
-
 
60
							$methode = 'executer'.$liste_actions[$i];
-
 
61
						}
-
 
62
						if (method_exists($this, $methode)) {
-
 
63
							$this->$methode();
43
					} else {
64
						} else {
44
						$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);
45
    					trigger_error($m, E_USER_ERROR);
67
						}
46
					}
68
					}
47
				}
69
				}
48
			}
70
			}
49
		} else {
71
		} else {
50
			$m = "Le registre ne  contient aucune action!";
72
			$m = "Le registre ne  contient aucune action!";
51
    		trigger_error($m, E_USER_ERROR);
73
    		trigger_error($m, E_USER_ERROR);
52
		}
74
		}
53
    }
75
    }
54
    
76
 
55
	public function verifier()
77
	public function verifier()
56
    {
78
    {
57
    	// 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.
58
    	foreach ($_POST as $cle => $val) {
80
    	foreach ($_POST as $cle => $val) {
59
    		$morceau = array();
81
    		$morceau = array();
60
    		if (preg_match('/^(.+?)(:.+)+$/', $cle, $morceau)) {
82
    		if (preg_match('/^(.+?)(:.+)+$/', $cle, $morceau)) {
61
    			$table = '';
83
    			$table = '';
62
    			foreach (explode(':', trim($morceau[2], ':')) as $c) { 
84
    			foreach (explode(':', trim($morceau[2], ':')) as $c) {
63
    				$table .= '['.$c.']';
85
    				$table .= '['.$c.']';
64
    			}
86
    			}
65
    			eval('$_POST[$morceau[1]]'.$table.' = $val;');
87
    			eval('$_POST[$morceau[1]]'.$table.' = $val;');
66
    			unset($_POST[$cle]);
88
    			unset($_POST[$cle]);