1: <?php
2:
3: namespace Himedia\Padocc\Task\Base;
4:
5: use Himedia\Padocc\AttributeProperties;
6: use Himedia\Padocc\Task\WithProperties;
7:
8: /**
9: * Permet d'appeler une tâche target du même fichier XML.
10: * À inclure dans une tâche env ou target.
11: *
12: * Exemple : <call target="web_content" />
13: *
14: * Dérive Task_WithProperties et supporte donc les attributs XML 'loadtwengaservers', 'propertyshellfile'
15: * et 'propertyinifile'.
16: *
17: * @author Geoffroy AUBRY <gaubry@hi-media.com>
18: */
19: class Call extends WithProperties
20: {
21: /**
22: * Tâche appelée.
23: * @var Target
24: */
25: private $oBoundTask;
26:
27: /**
28: * {@inheritdoc}
29: *
30: * @throws \UnexpectedValueException if target not found or not unique in this project.
31: */
32: protected function init()
33: {
34: parent::init();
35:
36: $this->aAttrProperties = array_merge(
37: $this->aAttrProperties,
38: array('target' => AttributeProperties::REQUIRED)
39: );
40:
41: // Crée une instance de la tâche target appelée :
42: if (! empty($this->aAttValues['target'])) {
43: $aTargets = $this->oProject->getSXE()->xpath("target[@name='" . $this->aAttValues['target'] . "']");
44: if (count($aTargets) !== 1) {
45: $sMsg = "Target '" . $this->aAttValues['target'] . "' not found or not unique in this project!";
46: throw new \UnexpectedValueException($sMsg);
47: }
48: $this->oBoundTask = new Target($aTargets[0], $this->oProject, $this->oDIContainer);
49: }
50: }
51:
52: /**
53: * {@inheritdoc}
54: * @codeCoverageIgnore
55: */
56: public static function getTagName ()
57: {
58: return 'call';
59: }
60:
61: /**
62: * Prépare la tâche avant exécution : vérifications basiques, analyse des serveurs concernés...
63: * @codeCoverageIgnore
64: */
65: public function setUp ()
66: {
67: parent::setUp();
68: $this->oBoundTask->setUp();
69: }
70:
71: /**
72: * Phase de traitements centraux de l'exécution de la tâche.
73: * Elle devrait systématiquement commencer par "parent::centralExecute();".
74: * Appelé par execute().
75: * @see execute()
76: * @codeCoverageIgnore
77: */
78: protected function centralExecute ()
79: {
80: parent::centralExecute();
81: $this->oBoundTask->execute();
82: }
83: }
84: