Subversion Repositories Applications.bazar

Rev

Rev 468 | Blame | Compare with Previous | Last modification | View Log | RSS feed

<?php
/**
* PHP Version 5
*
* @category  PHP
* @package   jrest
* @author       aurelien <aurelien@tela-botanica.org>
* @copyright 2009 Tela-Botanica
* @license   http://www.cecill.info/licences/Licence_CeCILL_V2-fr.txt Licence CECILL
* @version   $$id$$
* @link   /doc/jrest/
*/

class JrestService {

        protected $config;
        protected $script_time;
        protected $max_exec_time;

        public function JrestService($config) {
                $this->config = config;
                $this->script_time = microtime(true);
                $this->max_exec_time = ini_get('max_execution_time');
        }

        public function isAdmin($id) {
                $admins = $this->config['jrest_admin']['admin'];
                $admin_tab = split(',',$admins);

                if (in_array($id,$admin_tab)) {
                        return true;
                } else {
                        return false;
                }
        }

        public function controleUtilisateur($id) {
                if ($_SESSION['user']['name'] == '') {
                        //cas de la session temporaire, on ne fait rien de particulier
                } else {
                        if (!$this->isAdmin($_SESSION['user']['name']) && $_SESSION['user']['name'] != $id) {
                                // cas d'usurpation d'identité
                                print 'Accès interdit';
                                exit();
                        }
                }
        }

        public function logger($index,$chaine) {
                if(!class_exists('Log')) {
                        include_once('Log.php');
                        Log::getInstance();
                }

                Log::setCheminLog($this->config['log']['cheminlog']);
                Log::setTimeZone($this->config['log']['timezone']);
                Log::setTailleMax($this->config['log']['taillemax']);

                Log::ajouterEntree($index,$chaine);
        }

        public function verifierOuRelancerExecution() {

                if((microtime(true) - $this->script_time) > ($this->max_exec_time - 5)*100) {
                        set_time_limit(2);
                        $this->logger('JRestService','Durée du script augmentée :'.microtime(true).' - '.$this->script_time.'.) > ('.$this->max_exec_time.' - 5)*1000000');
                        return true;
                }
                return false;
        }
}
?>