Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 559 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
class Conteneur {
        protected $parametres = array();
        protected $partages = array();

        public function __construct(array $parametres = null) {
                $this->parametres = is_null($parametres) ? array() : $parametres;
        }

        public function getParametre($cle) {
                $valeur = isset($this->parametres[$cle]) ? $this->parametres[$cle] : Config::get($cle);
                return $valeur;
        }

        public function getParametreTableau($cle) {
                $tableau = array();
                $parametre = $this->getParametre($cle);
                if (empty($parametre) === false) {
                        $tableauPartiel = explode(',', $parametre);
                        $tableauPartiel = array_map('trim', $tableauPartiel);
                        foreach ($tableauPartiel as $champ) {
                                if (strpos($champ, '=') === false) {
                                        $tableau[] = trim($champ);
                                } else {
                                        list($cle, $val) = explode('=', $champ);
                                        $tableau[trim($cle)] = trim($val);
                                }
                        }
                }
                return $tableau;
        }

        public function setParametre($cle, $valeur) {
                $this->parametres[$cle] = $valeur;
        }

        public function getParametresUrl() {
                if (!isset($this->partages['Parametres'])){
                        $this->partages['Parametres'] = new Parametres($this->parametres['parametres'], $this->getBdd());
                }
                return $this->partages['Parametres'];
        }

        public function getParametresUrlVerificateur() {
                if (!isset($this->partages['ParametresVerificateur'])){
                        $parametres = $this->getParametresUrl();
                        $parametresAPI = $this->getParametreTableau('parametresAPI');
                        $this->partages['ParametresVerificateur'] = new ParametresVerificateur($parametres, $parametresAPI);
                }
                return $this->partages['ParametresVerificateur'];
        }

        public function getRessourcesUrl() {
                if (!isset($this->partages['Ressources'])){
                        $this->partages['Ressources'] = new Ressources($this->parametres['ressources']);
                }
                return $this->partages['Ressources'];
        }

        public function getRessourcesUrlVerificateur() {
                if (!isset($this->partages['RessourcesVerificateur'])){
                        $ressources = $this->getRessourcesUrl();
                        $projetsDispo = $this->getParametreTableau('projetsDispo');
                        $servicesDispo = $this->getParametreTableau('servicesDispo');
                        $this->partages['RessourcesVerificateur'] = new RessourcesVerificateur($ressources, $projetsDispo, $servicesDispo);
                }
                return $this->partages['RessourcesVerificateur'];
        }

        public function getUrlFormatage() {
                if (!isset($this->partages['UrlFormatage'])){
                        $Bdd = $this->getBdd();
                        $this->partages['UrlFormatage'] = new UrlFormatage($Bdd);
                }
                return $this->partages['UrlFormatage'];
        }

        public function getRequetesAssemblage() {
                if (!isset($this->partages['RequetesAssemblage'])){
                        $this->partages['RequetesAssemblage'] =  new RequetesAssemblage($this->getBdd());
                }
                return $this->partages['RequetesAssemblage'];
        }


        public function getVersionVerificateur() {
                if (!isset($this->partages['VersionVerificateur'])){
                        $ressources = $this->getRessourcesUrl();
                        $parametres = $this->getParametresUrl();
                        $versions = $this->getVersions();
                        $this->partages['VersionVerificateur'] = new VersionVerificateur($ressources, $parametres, $versions);
                }
                return $this->partages['VersionVerificateur'];
        }

        public function getBdd() {
                if (!isset($this->partages['Bdd'])){
                        $this->partages['Bdd'] = new Bdd();
                }
                return $this->partages['Bdd'];
        }

        public function getCacheSimple($options = array()) {
                $cache = new CacheSimple($options);
                return $cache;
        }

        public function getVersions() {
                if (!isset($this->partages['Versions'])){
                        $parametres = $this->getParametresUrl();
                        $ressources = $this->getRessourcesUrl();
                        $bdd = $this->getBdd();
                        $versions = new Versions($parametres,  $bdd);
                        $this->partages['Versions'] = $versions;
                }
                return $this->partages['Versions'];
        }

        public function getWikipediaBot($options = array()) {
                $wpBot = new WikipediaBot($options);
                return $wpBot;
        }

        public function getUrl($url) {
                $url = new Url($url);
                return $url;
        }

        public function getServiceGenerique() {
                $ressources = $this->getRessourcesUrl();
                $classe = $ressources->getServiceClasse();
                $classeGenerique = $classe.'Generique';
                if ($ressources->getServiceNom() == 'noms' || $ressources->getServiceNom() == 'taxons') {
                        $service = new $classeGenerique($this->getRessourcesUrl(), $this->getParametresUrl(), $this->getNomDao(), $this->getNomFormateur());
                        if ($classe == 'NomsListe') {
                                $service->setListeUrl($this->getParametre('listeUrl'));
                        }
                } else if ($ressources->getServiceNom() == 'ontologies') {
                        $service = new $classeGenerique($this->getRessourcesUrl(), $this->getParametresUrl(), $this->getOntologiesDao(), $this->getOntologiesFormateur());
                        if ($classe == 'OntologiesListe') {
                                $service->setListeUrl($this->getParametre('listeUrlOntologies'));
                        }
                }

                return $service;
        }
}
?>