<?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_TimeSync
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @version $Id$
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/**
* Zend_Date
*/
require_once 'Zend/Date.php';
/**
* @category Zend
* @package Zend_TimeSync
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Zend_TimeSync implements IteratorAggregate
{
/**
* Set the default timeserver protocol to "Ntp". This will be called
* when no protocol is specified
*/
const DEFAULT_PROTOCOL = 'Ntp';
/**
* Contains array of timeserver objects
*
* @var array
*/
protected $_timeservers = array();
/**
* Holds a reference to the timeserver that is currently being used
*
* @var object
*/
protected $_current;
/**
* Allowed timeserver schemes
*
* @var array
*/
protected $_allowedSchemes = array(
'Ntp',
'Sntp'
);
/**
* Configuration array, set using the constructor or using
* ::setOptions() or ::setOption()
*
* @var array
*/
public static $options = array(
'timeout' => 1
);
/**
* Zend_TimeSync constructor
*
* @param string|array $target - OPTIONAL single timeserver, or an array of timeservers.
* @param string $alias - OPTIONAL an alias for this timeserver
* @return object
*/
public function __construct($target = null, $alias = null)
{
if ($target !== null) {
$this->addServer($target, $alias);
}
}
/**
* getIterator() - return an iteratable object for use in foreach and the like,
* this completes the IteratorAggregate interface
*
* @return ArrayObject
*/
public function getIterator()
{
return new ArrayObject($this->_timeservers);
}
/**
* Add a timeserver or multiple timeservers
*
* Server should be a single string representation of a timeserver,
* or a structured array listing multiple timeservers.
*
* If you provide an array of timeservers in the $target variable,
* $alias will be ignored. you can enter these as the array key
* in the provided array, which should be structured as follows:
*
* <code>
* $example = array(
* 'server_a' => 'ntp://127.0.0.1',
* 'server_b' => 'ntp://127.0.0.1:123',
* 'server_c' => 'ntp://[2000:364:234::2.5]',
* 'server_d' => 'ntp://[2000:364:234::2.5]:123'
* );
* </code>
*
* If no port number has been suplied, the default matching port
* number will be used.
*
* Supported protocols are:
* - ntp
* - sntp
*
* @param string|array $target - Single timeserver, or an array of timeservers.
* @param string $alias - OPTIONAL an alias for this timeserver
* @throws Zend_TimeSync_Exception
*/
public function addServer($target, $alias = null)
{
if (is_array($target)) {
foreach ($target as $key => $server) {
$this->_addServer($server, $key);
}
} else {
$this->_addServer($target, $alias);
}
}
/**
* Sets the value for the given options
*
* This will replace any currently defined options.
*
* @param array $options - An array of options to be set
*/
public static function setOptions(array $options)
{
foreach ($options as $key => $value) {
Zend_TimeSync::$options[$key] = $value;
}
}
/**
* Marks a nameserver as current
*
* @param string|integer $alias - The alias from the timeserver to set as current
* @throws Zend_TimeSync_Exception
*/
public function setServer($alias)
{
if (isset($this->_timeservers[$alias]) === true) {
$this->_current = $this->_timeservers[$alias];
} else {
require_once 'Zend/TimeSync/Exception.php';
throw new Zend_TimeSync_Exception("'$alias' does not point to valid timeserver");
}
}
/**
* Returns the value to the option
*
* @param string $key - The option's identifier
* @return mixed
* @throws Zend_TimeSync_Exception
*/
public static function getOptions($key = null)
{
if ($key == null) {
return Zend_TimeSync::$options;
}
if (isset(Zend_TimeSync::$options[$key]) === true) {
return Zend_TimeSync::$options[$key];
} else {
require_once 'Zend/TimeSync/Exception.php';
throw new Zend_TimeSync_Exception("'$key' does not point to valid option");
}
}
/**
* Return a specified timeserver by alias
* If no alias is given it will return the current timeserver
*
* @param string|integer $alias - The alias from the timeserver to return
* @return object
* @throws Zend_TimeSync_Exception
*/
public function getServer($alias = null)
{
if ($alias === null) {
if (isset($this->_current) && $this->_current !== false) {
return $this->_current;
} else {
require_once 'Zend/TimeSync/Exception.php';
throw new Zend_TimeSync_Exception('there is no timeserver set');
}
}
if (isset($this->_timeservers[$alias]) === true) {
return $this->_timeservers[$alias];
} else {
require_once 'Zend/TimeSync/Exception.php';
throw new Zend_TimeSync_Exception("'$alias' does not point to valid timeserver");
}
}
/**
* Returns information sent/returned from the current timeserver
*
* @return array
*/
public function getInfo()
{
return $this->getServer()->getInfo();
}
/**
* Query the timeserver list using the fallback mechanism
*
* If there are multiple servers listed, this method will act as a
* facade and will try to return the date from the first server that
* returns a valid result.
*
* @param Zend_Locale $locale - OPTIONAL locale
* @return object
* @throws Zend_TimeSync_Exception
*/
public function getDate($locale = null)
{
require_once 'Zend/TimeSync/Exception.php';
foreach ($this->_timeservers as $alias => $server) {
$this->_current = $server;
try {
return $server->getDate($locale);
} catch (Zend_TimeSync_Exception $e) {
if (!isset($masterException)) {
$masterException = new Zend_TimeSync_Exception('all timeservers are bogus');
}
$masterException->addException($e);
}
}
throw $masterException;
}
/**
* Adds a timeserver object to the timeserver list
*
* @param string|array $target - Single timeserver, or an array of timeservers.
* @param string $alias - An alias for this timeserver
*/
protected function _addServer($target, $alias)
{
if ($pos = strpos($target, '://')) {
$protocol = substr($target, 0, $pos);
$adress = substr($target, $pos + 3);
} else {
$adress = $target;
$protocol = self::DEFAULT_PROTOCOL;
}
if ($pos = strrpos($adress, ':')) {
$posbr = strpos($adress, ']');
if ($posbr and ($pos > $posbr)) {
$port = substr($adress, $pos + 1);
$adress = substr($adress, 0, $pos);
} else if (!$posbr and $pos) {
$port = substr($adress, $pos + 1);
$adress = substr($adress, 0, $pos);
} else {
$port = null;
}
} else {
$port = null;
}
$protocol = ucfirst(strtolower($protocol));
if (!in_array($protocol, $this->_allowedSchemes)) {
require_once 'Zend/TimeSync/Exception.php';
throw new Zend_TimeSync_Exception("'$protocol' is not a supported protocol");
}
$className = 'Zend_TimeSync_' . $protocol;
if (!class_exists($className)) {
require_once 'Zend/Loader.php';
Zend_Loader::loadClass($className);
}
$timeServerObj = new $className($adress, $port);
$this->_timeservers[$alias] = $timeServerObj;
}
}
| nama | waktu | ukuran | owner | perm | aksi |
|---|---|---|---|---|---|
| .. | |||||
| Acl/ | 2016-11-07 16:01 | 18.18 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Auth/ | 2016-11-07 16:01 | 110.51 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Cache/ | 2016-11-07 16:01 | 301.58 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Config/ | 2016-11-07 16:01 | 67.48 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Controller/ | 2016-11-07 16:01 | 433.7 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Crypt/ | 2016-11-07 16:01 | 58.94 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Currency/ | 2016-11-07 15:59 | 2.25 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Date/ | 2016-11-07 15:59 | 63.91 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Db/ | 2016-11-07 16:01 | 522.98 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Dom/ | 2016-11-07 16:01 | 18.5 KB | 76129f60960:kunden | dxwrx-rx-r | |
| File/ | 2016-11-07 16:01 | 74.13 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Filter/ | 2016-11-07 16:01 | 248.23 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Form/ | 2016-11-07 16:01 | 256.39 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Http/ | 2016-11-07 16:01 | 292.14 KB | 76129f60960:kunden | dxwrx-rx-r | |
| InfoCard/ | 2016-11-07 16:01 | 110.37 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Json/ | 2016-11-07 15:59 | 40.19 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Layout/ | 2016-11-07 16:03 | 9.91 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Ldap/ | 2016-11-07 16:03 | 210.38 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Loader/ | 2016-11-07 16:01 | 79 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Locale/ | 2016-11-07 16:01 | 9.04 MB | 76129f60960:kunden | dxwrx-rx-r | |
| Log/ | 2016-11-07 16:01 | 68.07 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Mail/ | 2016-11-07 16:01 | 267.86 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Mime/ | 2016-11-07 15:59 | 24.28 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Navigation/ | 2016-11-07 16:01 | 81.02 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Oauth/ | 2016-11-07 16:01 | 92.36 KB | 76129f60960:kunden | dxwrx-rx-r | |
| OpenId/ | 2016-11-07 16:01 | 114.52 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Paginator/ | 2016-11-07 16:01 | 34.29 KB | 76129f60960:kunden | dxwrx-rx-r | |
| ProgressBar/ | 2016-11-07 16:01 | 26.92 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Rest/ | 2016-11-07 16:01 | 53.33 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Server/ | 2016-11-07 16:01 | 86.45 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Service/ | 2016-11-07 15:59 | 2.8 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Session/ | 2016-11-07 16:01 | 50.38 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Soap/ | 2016-11-07 16:01 | 134.06 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Stdlib/ | 2016-11-07 16:01 | 32.44 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Text/ | 2016-11-07 16:01 | 90.27 KB | 76129f60960:kunden | dxwrx-rx-r | |
| TimeSync/ | 2016-11-07 15:59 | 22.15 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Translate/ | 2016-11-07 16:01 | 86.71 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Uri/ | 2016-11-07 15:59 | 24.51 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Validate/ | 2016-11-07 16:01 | 818.28 KB | 76129f60960:kunden | dxwrx-rx-r | |
| View/ | 2016-11-07 16:01 | 428.19 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Wildfire/ | 2016-11-07 16:01 | 57.02 KB | 76129f60960:kunden | dxwrx-rx-r | |
| XmlRpc/ | 2016-11-07 16:02 | 139.14 KB | 76129f60960:kunden | dxwrx-rx-r | |
| Acl.php | 2016-11-07 15:58 | 46.16 KB | 76129f60960:kunden | -xw-x----- | |
| Auth.php | 2016-11-07 15:58 | 3.95 KB | 76129f60960:kunden | -xw-x----- | |
| Cache.php | 2016-11-07 15:58 | 9.44 KB | 76129f60960:kunden | -xw-x----- | |
| Config.php | 2016-11-07 15:58 | 12.61 KB | 76129f60960:kunden | -xw-x----- | |
| Crypt.php | 2016-11-07 15:58 | 4.36 KB | 76129f60960:kunden | -xw-x----- | |
| Currency.php | 2016-11-07 15:58 | 28.97 KB | 76129f60960:kunden | -xw-x----- | |
| Date.php | 2016-11-07 15:58 | 193.33 KB | 76129f60960:kunden | -xw-x----- | |
| Db.php | 2016-11-07 15:58 | 9.85 KB | 76129f60960:kunden | -xw-x----- | |
| Debug.php | 2016-11-07 15:58 | 3.11 KB | 76129f60960:kunden | -xw-x----- | |
| Exception.php | 2016-11-07 15:58 | 2.45 KB | 76129f60960:kunden | -xw-x----- | |
| Filter.php | 2016-11-07 15:58 | 7 KB | 76129f60960:kunden | -xw-x----- | |
| Form.php | 2016-11-07 15:58 | 93.43 KB | 76129f60960:kunden | -xw-x----- | |
| InfoCard.php | 2016-11-07 15:58 | 17.23 KB | 76129f60960:kunden | -xw-x----- | |
| Json.php | 2016-11-07 15:58 | 16.7 KB | 76129f60960:kunden | -xw-x----- | |
| Layout.php | 2016-11-07 15:58 | 18.49 KB | 76129f60960:kunden | -xw-x----- | |
| Ldap.php | 2016-11-07 15:58 | 51.21 KB | 76129f60960:kunden | -xw-x----- | |
| Loader.php | 2016-11-07 15:58 | 11.29 KB | 76129f60960:kunden | -xw-x----- | |
| Locale.php | 2016-11-07 15:58 | 41.5 KB | 76129f60960:kunden | -xw-x----- | |
| Log.php | 2016-11-07 15:58 | 19.53 KB | 76129f60960:kunden | -xw-x----- | |
| Mail.php | 2016-11-07 15:58 | 31.56 KB | 76129f60960:kunden | -xw-x----- | |
| Mime.php | 2016-11-07 15:58 | 12.6 KB | 76129f60960:kunden | -xw-x----- | |
| Navigation.php | 2016-11-07 15:58 | 1.74 KB | 76129f60960:kunden | -xw-x----- | |
| Oauth.php | 2016-11-07 15:58 | 2.67 KB | 76129f60960:kunden | -xw-x----- | |
| OpenId.php | 2016-11-07 15:58 | 26.2 KB | 76129f60960:kunden | -xw-x----- | |
| Paginator.php | 2016-11-07 15:58 | 30.12 KB | 76129f60960:kunden | -xw-x----- | |
| ProgressBar.php | 2016-11-07 15:58 | 5.71 KB | 76129f60960:kunden | -xw-x----- | |
| Registry.php | 2016-11-07 15:58 | 5.91 KB | 76129f60960:kunden | -xw-x----- | |
| Session.php | 2016-11-07 15:58 | 29.51 KB | 76129f60960:kunden | -xw-x----- | |
| TimeSync.php | 2016-11-07 15:58 | 8.93 KB | 76129f60960:kunden | -xw-x----- | |
| Translate.php | 2016-11-07 15:58 | 5.97 KB | 76129f60960:kunden | -xw-x----- | |
| Uri.php | 2016-11-07 15:58 | 6.29 KB | 76129f60960:kunden | -xw-x----- | |
| Validate.php | 2016-11-07 15:58 | 8.16 KB | 76129f60960:kunden | -xw-x----- | |
| Version.php | 2016-11-07 15:58 | 2.45 KB | 76129f60960:kunden | -xw-x----- | |
| View.php | 2016-11-07 15:58 | 2.92 KB | 76129f60960:kunden | -xw-x----- | |