Overview

Packages

  • Support

Classes

  • Horde_Support_Array
  • Horde_Support_Backtrace
  • Horde_Support_CombineStream
  • Horde_Support_ConsistentHash
  • Horde_Support_Guid
  • Horde_Support_Inflector
  • Horde_Support_Memory
  • Horde_Support_Numerizer
  • Horde_Support_Numerizer_Locale_Base
  • Horde_Support_Numerizer_Locale_De
  • Horde_Support_Numerizer_Locale_Pt
  • Horde_Support_Randomid
  • Horde_Support_Stack
  • Horde_Support_StringStream
  • Horde_Support_Stub
  • Horde_Support_Timer
  • Horde_Support_Uuid
  • Overview
  • Package
  • Class
  • Tree
 1: <?php
 2: /**
 3:  * Class for generating GUIDs. Usage:
 4:  *
 5:  * <code>
 6:  * $uid = (string)new Horde_Support_Guid([$opts = array()]);
 7:  * </code>
 8:  *
 9:  * Copyright 2009-2012 Horde LLC (http://www.horde.org/)
10:  *
11:  * @category   Horde
12:  * @package    Support
13:  * @license    http://www.horde.org/licenses/bsd
14:  */
15: class Horde_Support_Guid
16: {
17:     /**
18:      * Generated GUID.
19:      *
20:      * @var string
21:      */
22:     private $_guid;
23: 
24:     /**
25:      * New GUID.
26:      *
27:      * @param array $opts  Additional options:
28:      * <pre>
29:      * 'prefix' - (string) A prefix to add between the date string and the
30:      *            random string.
31:      *            DEFAULT: NONE
32:      * 'server' - (string) The server name.
33:      *            DEFAULT: $_SERVER['SERVER_NAME'] (or 'localhost')
34:      * </pre>
35:      */
36:     public function __construct(array $opts = array())
37:     {
38:         $this->generate($opts);
39:     }
40: 
41:     /**
42:      * Generates a GUID.
43:      *
44:      * @param array $opts  Additional options:
45:      * <pre>
46:      * 'prefix' - (string) A prefix to add between the date string and the
47:      *            random string.
48:      *            DEFAULT: NONE
49:      * 'server' - (string) The server name.
50:      *            DEFAULT: $_SERVER['SERVER_NAME'] (or 'localhost')
51:      * </pre>
52:      */
53:     public function generate(array $opts = array())
54:     {
55:         $this->_guid = date('YmdHis')
56:             . '.'
57:             . (isset($opts['prefix']) ? $opts['prefix'] . '.' : '')
58:             . strval(new Horde_Support_Randomid())
59:             . '@'
60:             . (isset($opts['server']) ? $opts['server'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost'));
61:     }
62: 
63:     /**
64:      * Cooerce to string.
65:      *
66:      * @return string
67:      */
68:     public function __toString()
69:     {
70:         return $this->_guid;
71:     }
72: 
73: }
74: 
API documentation generated by ApiGen