Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 257 | Rev 524 | 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 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, $ressources, $bdd);
                        $this->partages['Versions'] = $versions;
                }
                return $this->partages['Versions'];
        }

        public function getProjet() {
                if (!isset($this->partages['Projet'])){
                        $ressources = $this->getRessourcesUrl();
                        $projet = new Projet($ressources);
                        $projet->setCheminBase($this->getParametre('cheminBase'));
                        $projet->setCheminConfig($this->getParametre('chemin_configurations'));
                        $projet->setCheminBiblio($this->getParametre('chemin_bibliotheque'));
                        $projet->initialiser();
                        $projet->setParamsVerif($this->getParametresUrlVerificateur());
                        $projet->setRessourcesVerif($this->getRessourcesUrlVerificateur());
                        $projet->setVersionVerif($this->getVersionVerificateur());
                        $projet->setServiceGenerique($this->getServiceGenerique());
                        $this->partages['Projet'] = $projet;
                }
                return $this->partages['Projet'];
        }

        public function getNomDao() {
                $ressources = $this->getRessourcesUrl();
                $parametres = $this->getParametresUrl();
                $bdd = $this->getBdd();
                $versions = $this->getVersions();
                $nomDao = new NomDAO($ressources, $parametres, $bdd, $versions);
                return $nomDao;
        }

        public function getOntologiesDao() {
                $ressources = $this->getRessourcesUrl();
                $parametres = $this->getParametresUrl();
                $bdd = $this->getBdd();
                $versions = $this->getVersions();
                $ontologieDao = new OntologieDAO($ressources, $parametres, $bdd, $versions);
                return $ontologieDao;
        }

        public function getNomFormateur() {
                $formateur = new NomFormateur();
                $formateur->setBdd($this->getBdd());
                $formateur->setChampsProjet($this->getParametreTableau('champsProjet'));
                $formateur->setDetailsHrefTpl($this->getParametre('detailsHrefTpl'));
                $formateur->setOntologieHrefTpl($this->getParametre('ontologieHrefTpl'));
                return $formateur;
        }

        public function getOntologiesFormateur() {
                $formateur = new OntologieFormateur();
                $formateur->setBdd($this->getBdd());
                $formateur->setChampsProjet($this->getParametreTableau('champsProjet'));
                $formateur->setDetailsHrefTpl($this->getParametre('detailsHrefOntologiesTpl'));
                $formateur->setLangueDemandee($this->getParametresUrl()->get('retour.langue'));
                return $formateur;
        }

        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;
        }
}
?>