Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I factorize a parameters repeats several times in my class?
    primarykey
    data
    text
    <p>I show you firsly my class : as you can see I repeated several times $versionId param because all the method needs it. I am asking myself if there is a way to factorize it so there is lesser repetition.</p> <pre><code>&lt;?php class Admin_Model_Version { private $_db; private $_versionId; private $_path; public function __construct() { } /** * Récupère l'objet de la table version. * * @return Zend_Db_Table */ public function getDb() { if(!isset($this-&gt;_db)) { $this-&gt;_db = new Admin_Model_DbTable_Version(); } return $this-&gt;_db; } /** * Retourne toutes les versions d'un projet. * * @param integer $versionId */ public function getVersions($projectId) { $db = $this-&gt;getDb(); $select = $db-&gt;select(); return $select -&gt;where("project_idproject = ?", $projectId) -&gt;query()-&gt;fetchAll(); } public function getVersionPath($versionId) { $root = realpath(dirname($_SERVER['SCRIPT_FILENAME']) . "/../"); $patrimonyName = $this-&gt;getPatrimonyRecordByVersionId($versionId)-&gt;name_patrimony; $projectName = $this-&gt;getProjectRecordByVersionId($versionId)-&gt;name_project; $versionName = $this-&gt;getVersionRecordByVersionId($versionId)-&gt;lab_version; return $root . "/data/projects/" . $patrimonyName . "/" . $projectName . "/" . $versionName . "/"; } /** * Vérifie si la version possède un repertoire de travail. * * Tous les répertoires de travail sont dans le répertoire /data/projects/ */ public function hasVersionDirectory($versionId) { $versionPath = $this-&gt;getVersionPath($versionId); // Si le chemin n'existe pas retourner une exception. if(!realpath($versionPath)) { throw new Exception("&lt;b&gt;Admin_Model_Version&lt;/b&gt; " . __LINE__ . " : Le répertoire n'existe pas!"); return false; } else { return true; } } public function getPatrimonyRecordByVersionId($versionId) { $db = $this-&gt;getDb(); // setIntegrityCheck(false) is required for join $row = $db-&gt;select()-&gt;setIntegrityCheck(false); return $row-&gt;from(array('ve' =&gt; 'version'), array()) -&gt;join(array('pr' =&gt; 'project'), 've.project_idproject = pr.idproject', array()) -&gt;join(array('pa' =&gt; 'patrimony'), 'pa.idpatrimony = pr.patrimony_idpatrimony') -&gt;where('ve.idversion = ?', $versionId) -&gt;query()-&gt;fetchObject(); } public function getProjectRecordByVersionId($versionId) { $db = $this-&gt;getDb(); // setIntegrityCheck(false) is required for join $row = $db-&gt;select()-&gt;setIntegrityCheck(false); return $row-&gt;from(array('ve' =&gt; 'version'), array()) -&gt;join(array('pr' =&gt; 'project'), 've.project_idproject = pr.idproject') -&gt;where('ve.idversion = ?', $versionId) -&gt;query()-&gt;fetchObject(); } public function getVersionRecordByVersionId($versionId) { $db = $this-&gt;getDb(); // setIntegrityCheck(false) is required for join $row = $db-&gt;select(); $row-&gt;where('idversion = ?', $versionId); return $row-&gt;query()-&gt;fetchObject(); } /** * Crée le répertoire de travail avec comme chemin le nom du patrimoine * suivi du nom de projet et du nom de version. */ public function createHome($versionId) { $path = $this-&gt;getVersionPath($versionId); Zend_Registry::get('firephp')-&gt;info($path); if(!mkdir($path, 0755, true)) { throw new Exception(__METHOD__ . "can't create directory"); } } public function hasDirectorySRC($versionId) { $path = } public function hasDirectoryHTML($versionId) { } public function hasDirectoryXML($versionId) { } public function hasDirectorySVG($versionId) { } } </code></pre> <p>Thx</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload