Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields | Static Public Attributes | Protected Member Functions | Protected Attributes
Zend_TimeSync Class Reference
Inheritance diagram for Zend_TimeSync:

Public Member Functions

 __construct ($target=null, $alias=null)
 
 getIterator ()
 
 addServer ($target, $alias=null)
 
 setServer ($alias)
 
 getServer ($alias=null)
 
 getInfo ()
 
 getDate ($locale=null)
 

Static Public Member Functions

static setOptions (array $options)
 
static getOptions ($key=null)
 

Data Fields

const DEFAULT_PROTOCOL = 'Ntp'
 

Static Public Attributes

static $options
 

Protected Member Functions

 _addServer ($target, $alias)
 

Protected Attributes

 $_timeservers = array()
 
 $_current
 
 $_allowedSchemes
 

Detailed Description

Definition at line 34 of file TimeSync.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $target = null,
  $alias = null 
)

Zend_TimeSync constructor

Parameters
string | array$target- OPTIONAL single timeserver, or an array of timeservers.
string$alias- OPTIONAL an alias for this timeserver
Returns
object

Definition at line 83 of file TimeSync.php.

84  {
85  if ($target !== null) {
86  $this->addServer($target, $alias);
87  }
88  }
$target
Definition: skip.phtml:8
addServer($target, $alias=null)
Definition: TimeSync.php:131
if(!trim($html)) $alias
Definition: details.phtml:20

Member Function Documentation

◆ _addServer()

_addServer (   $target,
  $alias 
)
protected

Adds a timeserver object to the timeserver list

Parameters
string | array$target- Single timeserver, or an array of timeservers.
string$alias- An alias for this timeserver

Definition at line 264 of file TimeSync.php.

265  {
266  if ($pos = strpos($target, '://')) {
267  $protocol = substr($target, 0, $pos);
268  $adress = substr($target, $pos + 3);
269  } else {
270  $adress = $target;
271  $protocol = self::DEFAULT_PROTOCOL;
272  }
273 
274  if ($pos = strrpos($adress, ':')) {
275  $posbr = strpos($adress, ']');
276  if ($posbr and ($pos > $posbr)) {
277  $port = substr($adress, $pos + 1);
278  $adress = substr($adress, 0, $pos);
279  } else if (!$posbr and $pos) {
280  $port = substr($adress, $pos + 1);
281  $adress = substr($adress, 0, $pos);
282  } else {
283  $port = null;
284  }
285  } else {
286  $port = null;
287  }
288 
289  $protocol = ucfirst(strtolower($protocol));
290  if (!in_array($protocol, $this->_allowedSchemes)) {
291  #require_once 'Zend/TimeSync/Exception.php';
292  throw new Zend_TimeSync_Exception("'$protocol' is not a supported protocol");
293  }
294 
295  $className = 'Zend_TimeSync_' . $protocol;
296  if (!class_exists($className)) {
297  #require_once 'Zend/Loader.php';
299  }
300  $timeServerObj = new $className($adress, $port);
301 
302  $this->_timeservers[$alias] = $timeServerObj;
303  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52
const DEFAULT_PROTOCOL
Definition: TimeSync.php:40
$target
Definition: skip.phtml:8
$pos
Definition: list.phtml:42
if(!trim($html)) $alias
Definition: details.phtml:20
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ addServer()

addServer (   $target,
  $alias = null 
)

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:

$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' );

If no port number has been suplied, the default matching port number will be used.

Supported protocols are:

  • ntp
  • sntp
Parameters
string | array$target- Single timeserver, or an array of timeservers.
string$alias- OPTIONAL an alias for this timeserver
Exceptions
Zend_TimeSync_Exception

Definition at line 131 of file TimeSync.php.

132  {
133  if (is_array($target)) {
134  foreach ($target as $key => $server) {
135  $this->_addServer($server, $key);
136  }
137  } else {
138  $this->_addServer($target, $alias);
139  }
140  }
$target
Definition: skip.phtml:8
_addServer($target, $alias)
Definition: TimeSync.php:264
if(!trim($html)) $alias
Definition: details.phtml:20

◆ getDate()

getDate (   $locale = null)

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.

Parameters
Zend_Locale$locale- OPTIONAL locale
Returns
object
Exceptions
Zend_TimeSync_Exception

Definition at line 240 of file TimeSync.php.

241  {
242  #require_once 'Zend/TimeSync/Exception.php';
243  foreach ($this->_timeservers as $alias => $server) {
244  $this->_current = $server;
245  try {
246  return $server->getDate($locale);
247  } catch (Zend_TimeSync_Exception $e) {
248  if (!isset($masterException)) {
249  $masterException = new Zend_TimeSync_Exception('all timeservers are bogus');
250  }
251  $masterException->addException($e);
252  }
253  }
254 
255  throw $masterException;
256  }
if(!trim($html)) $alias
Definition: details.phtml:20

◆ getInfo()

getInfo ( )

Returns information sent/returned from the current timeserver

Returns
array

Definition at line 224 of file TimeSync.php.

225  {
226  return $this->getServer()->getInfo();
227  }
getServer($alias=null)
Definition: TimeSync.php:201

◆ getIterator()

getIterator ( )

getIterator() - return an iteratable object for use in foreach and the like, this completes the IteratorAggregate interface

Returns
ArrayObject

Definition at line 96 of file TimeSync.php.

97  {
98  return new ArrayObject($this->_timeservers);
99  }

◆ getOptions()

static getOptions (   $key = null)
static

Returns the value to the option

Parameters
string$key- The option's identifier
Returns
mixed
Exceptions
Zend_TimeSync_Exception

Definition at line 179 of file TimeSync.php.

180  {
181  if ($key == null) {
183  }
184 
185  if (isset(Zend_TimeSync::$options[$key]) === true) {
186  return Zend_TimeSync::$options[$key];
187  } else {
188  #require_once 'Zend/TimeSync/Exception.php';
189  throw new Zend_TimeSync_Exception("'$key' does not point to valid option");
190  }
191  }
static $options
Definition: TimeSync.php:72

◆ getServer()

getServer (   $alias = null)

Return a specified timeserver by alias If no alias is given it will return the current timeserver

Parameters
string | integer$alias- The alias from the timeserver to return
Returns
object
Exceptions
Zend_TimeSync_Exception

Definition at line 201 of file TimeSync.php.

202  {
203  if ($alias === null) {
204  if (isset($this->_current) && $this->_current !== false) {
205  return $this->_current;
206  } else {
207  #require_once 'Zend/TimeSync/Exception.php';
208  throw new Zend_TimeSync_Exception('there is no timeserver set');
209  }
210  }
211  if (isset($this->_timeservers[$alias]) === true) {
212  return $this->_timeservers[$alias];
213  } else {
214  #require_once 'Zend/TimeSync/Exception.php';
215  throw new Zend_TimeSync_Exception("'$alias' does not point to valid timeserver");
216  }
217  }
if(!trim($html)) $alias
Definition: details.phtml:20

◆ setOptions()

static setOptions ( array  $options)
static

Sets the value for the given options

This will replace any currently defined options.

Parameters
array$options- An array of options to be set

Definition at line 149 of file TimeSync.php.

150  {
151  foreach ($options as $key => $value) {
153  }
154  }
$value
Definition: gender.phtml:16
static $options
Definition: TimeSync.php:72

◆ setServer()

setServer (   $alias)

Marks a nameserver as current

Parameters
string | integer$alias- The alias from the timeserver to set as current
Exceptions
Zend_TimeSync_Exception

Definition at line 162 of file TimeSync.php.

163  {
164  if (isset($this->_timeservers[$alias]) === true) {
165  $this->_current = $this->_timeservers[$alias];
166  } else {
167  #require_once 'Zend/TimeSync/Exception.php';
168  throw new Zend_TimeSync_Exception("'$alias' does not point to valid timeserver");
169  }
170  }
if(!trim($html)) $alias
Definition: details.phtml:20

Field Documentation

◆ $_allowedSchemes

$_allowedSchemes
protected
Initial value:
= array(
'Ntp',
'Sntp'
)

Definition at line 61 of file TimeSync.php.

◆ $_current

$_current
protected

Definition at line 54 of file TimeSync.php.

◆ $_timeservers

$_timeservers = array()
protected

Definition at line 47 of file TimeSync.php.

◆ $options

$options
static
Initial value:
= array(
'timeout' => 1
)

Definition at line 72 of file TimeSync.php.

◆ DEFAULT_PROTOCOL

const DEFAULT_PROTOCOL = 'Ntp'

Set the default timeserver protocol to "Ntp". This will be called when no protocol is specified

Definition at line 40 of file TimeSync.php.


The documentation for this class was generated from the following file: