[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/lib/alfresco/Service/ -> Repository.php (source)

   1  <?php
   2  /*

   3   * Copyright (C) 2005-2010 Alfresco Software Limited.

   4   *

   5   * This file is part of Alfresco

   6   *

   7   * Alfresco is free software: you can redistribute it and/or modify

   8   * it under the terms of the GNU Lesser General Public License as published by

   9   * the Free Software Foundation, either version 3 of the License, or

  10   * (at your option) any later version.

  11   *

  12   * Alfresco is distributed in the hope that it will be useful,

  13   * but WITHOUT ANY WARRANTY; without even the implied warranty of

  14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

  15   * GNU Lesser General Public License for more details.

  16   *

  17   * You should have received a copy of the GNU Lesser General Public License

  18   * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.

  19   */
  20  
  21  require_once $CFG->libdir.'/alfresco/Service/WebService/WebServiceFactory.php';
  22  require_once $CFG->libdir.'/alfresco/Service/BaseObject.php';
  23  
  24  if (isset($_SESSION) == false)
  25  {
  26     // Start the session

  27     session_start();
  28  }   
  29   
  30  class Alfresco_Repository extends BaseObject
  31  {
  32      private $_connectionUrl;    
  33      private $_host;
  34      private $_port;
  35  
  36  	public function __construct($connectionUrl="http://localhost:8080/alfresco/api")
  37      {
  38          $this->_connectionUrl = $connectionUrl;            
  39          $parts = parse_url($connectionUrl);
  40          $this->_host = $parts["host"];
  41          if (empty($parts["port"])) {
  42              $this->_port = 80;
  43          } else {
  44              $this->_port = $parts["port"];
  45          }
  46      }
  47      
  48  	public function getConnectionUrl()
  49      {
  50          return $this->_connectionUrl;
  51      }
  52      
  53  	public function getHost()
  54      {
  55          return $this->_host;    
  56      }
  57      
  58  	public function getPort()
  59      {
  60          return $this->_port;
  61      }
  62      
  63  	public function authenticate($userName, $password)
  64      {
  65          // TODO need to handle exceptions!

  66          
  67          $authenticationService = WebServiceFactory::getAuthenticationService($this->_connectionUrl);
  68          $result = $authenticationService->startSession(array (
  69              "username" => $userName,
  70              "password" => $password
  71          ));
  72          
  73          // Get the ticket and sessionId

  74          $ticket = $result->startSessionReturn->ticket;
  75          $sessionId = $result->startSessionReturn->sessionid;
  76          
  77          // Store the session id for later use

  78          if ($sessionId != null)
  79          {
  80           $sessionIds = null;
  81           if (isset($_SESSION["sessionIds"]) == false)
  82              {
  83              $sessionIds = array();
  84           }
  85           else
  86           {
  87              $sessionIds = $_SESSION["sessionIds"];
  88           }
  89           $sessionIds[$ticket] = $sessionId;
  90           $_SESSION["sessionIds"] = $sessionIds;
  91          }
  92          
  93          return $ticket;
  94      }
  95      
  96  	public function createSession($ticket=null)
  97      {
  98          $session = null;
  99          
 100          if ($ticket == null)
 101          {
 102              // TODO get ticket from some well known location ie: the $_SESSION

 103          }    
 104          else
 105          {
 106              // TODO would be nice to be able to check that the ticket is still valid!

 107              
 108              // Create new session

 109              $session = new Session($this, $ticket);    
 110          }
 111          
 112          return $session;
 113      }
 114      
 115      /**

 116       * For a given ticket, returns the realated session id, null if one can not be found.

 117       */
 118  	public static function getSessionId($ticket)
 119      {
 120        $result = null;
 121        if (isset($_SESSION["sessionIds"]) == true)
 122        {
 123           $result = $_SESSION["sessionIds"][$ticket];
 124        }
 125        return $result;
 126  
 127      }
 128  
 129  }
 130   
 131   ?>


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1