Example #1
0
 public function release()
 {
     $result = 1;
     try {
         if ($this->has_lock()) {
             $redis = mr_bootstrap::redis();
             if (empty($this->timetolive)) {
                 $result = $redis->delete($this->uniquekey);
             } else {
                 $timetolive = $this->parse_timetolive($redis->get($this->uniquekey));
                 // We check to value to make sure the key hasn't expired and been re-acquired by another process
                 if ($timetolive == $this->timetolive and $timetolive > time()) {
                     $result = $redis->delete($this->uniquekey);
                 }
             }
             $redis->close();
         }
     } catch (RedisException $e) {
         debugging("RedisException caught on host {$this->get_hostname()} with message: {$e->getMessage()}");
     } catch (Exception $e) {
         debugging("Exception caught on host {$this->get_hostname()} with message: {$e->getMessage()}");
     }
     $this->set_lockacquired(false);
     return $result == 1;
 }
Example #2
0
 /**
  * Constructor - create a new interface to the cache
  *
  * @param string $prefix Prefix all cache IDs with this string
  */
 public function __construct($prefix = NULL)
 {
     // Setup Zend
     mr_bootstrap::zend();
     require_once 'Zend/Cache.php';
     require_once 'Zend/Cache/Exception.php';
     // For prefixes, switch forward slashes, which are not accepted, to underscores
     if (!is_null($prefix)) {
         $prefix = str_replace('/', '_', $prefix);
     }
     // DISABLED!!! Not yet implemented on our servers
     if (defined('MR_CACHE_TEST') and !empty(mr_var::instance()->get('mrconfig')->cache_lifetime)) {
         $frontendoptions = array('cache_id_prefix' => $prefix, 'lifetime' => mr_var::instance()->get('mrconfig')->cache_lifetime);
         $backendoptions = array();
         try {
             $this->cache = Zend_Cache::factory(self::FRONTEND, self::BACKEND, $frontendoptions, $backendoptions);
         } catch (Zend_Cache_Exception $e) {
             $this->cache = false;
         }
     }
 }
 public function test_zend_include_path()
 {
     global $CFG;
     mr_bootstrap::zend();
     $files = array($CFG->dirroot . '/lib/zend/Zend/Validate/Barcode/Ean13.php');
     if (is_dir($CFG->dirroot . '/local/mr/vendor/zend')) {
         $files[] = $CFG->dirroot . '/local/mr/vendor/zend/Zend/Controller/Request/Http.php';
     }
     if (is_dir($CFG->dirroot . '/search')) {
         $files[] = $CFG->dirroot . '/search/Zend/Exception.php';
     }
     $included = get_included_files();
     foreach ($files as $file) {
         $this->assertFalse(in_array($file, $included));
     }
     include_once 'Zend/Exception.php';
     include_once 'Zend/Controller/Request/Http.php';
     include_once 'Zend/Validate/Barcode/Ean13.php';
     $included = get_included_files();
     foreach ($files as $file) {
         $this->assertTrue(in_array($file, $included));
     }
 }
Example #4
0
 * along with this program.  If not, see http://opensource.org/licenses/gpl-3.0.html.
 *
 * @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
 * @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
 * @package mr
 * @author Mark Nielsen
 */
defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
/**
 * @see mr_boostrap
 */
require_once $CFG->dirroot . '/local/mr/framework/bootstrap.php';
/**
 * Setup Zend
 */
mr_bootstrap::zend();
/**
 * @see Zend_Validate
 */
require_once 'Zend/Validate.php';
/**
 * MR Server Abstract
 *
 * The server is responsible for security validation
 * and the routing of incoming requests to mr_server_service_abstract.
 *
 * @author Mark Nielsen
 * @package mr
 * @example webservices.php Example server usage
 * @example controller/server.php Example client
 */
Example #5
0
<?php

/**
 * Moodlerooms Framework
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see http://opensource.org/licenses/gpl-3.0.html.
 *
 * @copyright Copyright (c) 2009 Moodlerooms Inc. (http://www.moodlerooms.com)
 * @license http://opensource.org/licenses/gpl-3.0.html GNU Public License
 * @package mr
 * @author Mark Nielsen
 */
defined('MOODLE_INTERNAL') or die('Direct access to this script is forbidden.');
global $CFG;
/**
 * @see mr_bootstrap
 */
require_once $CFG->dirroot . '/local/mr/framework/bootstrap.php';
mr_bootstrap::startup();
 /**
  * Document a web service along with its response
  *
  * @param string $classname The service class name
  * @param string $methodname The service method name
  * @param string $response The server response
  * @return string
  * @author Mark Nielsen
  */
 public function document($classname, $methodname, $response)
 {
     $markup = '';
     if (!empty($methodname)) {
         mr_bootstrap::zend();
         require_once 'Zend/Reflection/Class.php';
         $class = new Zend_Reflection_Class($classname);
         $method = $class->getMethod($methodname);
         $phpdoc = $method->getDocblock();
         $params = $method->getParameters();
         $description = $phpdoc->getShortDescription();
         $longdesc = $phpdoc->getLongDescription();
         if (!empty($longdesc)) {
             $description .= "\n{$longdesc}";
         }
         $markup .= "h2. {$methodname}\n";
         $markup .= "*Description:*\n{$description}\n\n";
         $markup .= "*Parameters:*\n";
         $markup .= "* _string_ *method*: (Required) Must be set to '{$methodname}'\n";
         /** @var $params Zend_Reflection_Parameter[] */
         foreach ($params as $param) {
             $name = $param->getName();
             $tags = $phpdoc->getTags('param');
             if (isset($tags[$param->getPosition()])) {
                 $tag = $tags[$param->getPosition()];
                 $typestr = '_' . $tag->getType() . '_ ';
                 $descstr = $tag->getDescription();
             } else {
                 $typestr = $descstr = '';
             }
             if ($param->isOptional() and $param->isDefaultValueAvailable()) {
                 $default = $param->getDefaultValue();
                 if (is_null($default)) {
                     $default = 'NULL';
                 } else {
                     if (!is_numeric($default) and is_string($default)) {
                         $default = "'{$default}'";
                     }
                 }
                 $descstr = "(Optional, default = {$default}) {$descstr}";
             } else {
                 if ($param->isOptional()) {
                     $descstr = "(Optional) {$descstr}";
                 } else {
                     $descstr = "(Required) {$descstr}";
                 }
             }
             $markup .= "* {$typestr}*{$name}*: {$descstr}\n";
         }
         $markup .= "\n*Example Response:*\n";
         if ($simplexml = @simplexml_load_string($response)) {
             $dom = dom_import_simplexml($simplexml)->ownerDocument;
             $dom->formatOutput = true;
             $markup .= "{code:xml}\n";
             $markup .= trim($dom->saveXML());
             $markup .= "\n{code}\n";
         } else {
             if (($json = json_decode($response)) !== NULL) {
                 $markup .= "{noformat}\n";
                 $markup .= $response;
                 $markup .= "\n{noformat}\n\n";
                 $markup .= "*Example Response (decoded JSON):*\n";
                 $markup .= "{noformat}\n";
                 $markup .= trim(print_r($json, true));
                 $markup .= "\n{noformat}\n";
             } else {
                 $markup .= "{noformat}\n";
                 $markup .= trim($response);
                 $markup .= "\n{noformat}\n";
             }
         }
         $markup = $this->generalize_text($markup);
         // Add to overall markup string
         $this->markup .= "{$markup}\n\n";
     }
     return $markup;
 }
Example #7
0
 /**
  * Bootstrap Zend Framework
  *
  * Right now, this just sets a proper include path
  * so you can require_once(...) Zend files.
  *
  * @return void
  */
 public static function zend()
 {
     global $CFG;
     if (!self::$zend) {
         // Include path for Zend
         $includepath = get_include_path();
         $searchpath = $CFG->dirroot . '/search';
         $zendpath = $CFG->libdir . '/zend';
         $zendmrpath = $CFG->dirroot . '/local/mr/vendor/zend';
         $paths = array($zendmrpath, $zendpath, $searchpath);
         if (is_dir($searchpath) or is_dir($zendmrpath)) {
             // Remove paths that we are adding
             $includepaths = explode(PATH_SEPARATOR, $includepath);
             foreach ($includepaths as $key => $path) {
                 if (in_array($path, $paths)) {
                     unset($includepaths[$key]);
                 }
             }
             // Add our paths to the front
             foreach ($paths as $path) {
                 if (is_dir($path)) {
                     array_unshift($includepaths, $path);
                 }
             }
             set_include_path(implode(PATH_SEPARATOR, $includepaths));
         }
         // Init done!
         self::$zend = true;
     }
 }