Overview

Namespaces

  • NGS
    • Client
      • Exception
    • Converter
    • Patterns
  • PHP

Classes

  • BigDecimal
  • BigInt
  • ByteStream
  • LocalDate
  • Location
  • Money
  • Name
  • Point
  • S3
  • Timestamp
  • Utils
  • UUID
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: namespace NGS;
 3: 
 4: /**
 5:  * Helper functions for converting PHP class names to DSL names
 6:  */
 7: abstract class Name
 8: {
 9:     /**
10:      * Gets DSL name from class or object instance
11:      *
12:      * @param string|object $name Fully qualified class name or object instance
13:      * @return string DSL name
14:      * @throws \InvalidArgumentException If $name is not a string/object
15:      */
16:     public static function full($name)
17:     {
18:         if (is_object($name)) {
19:             $name = get_class($name);
20:         }
21:         elseif(!is_string($name)) {
22:             throw new \InvalidArgumentException('Invalid type for name, name was not string');
23:         }
24:         return str_replace('\\', '.', $name);
25:     }
26: 
27:     /**
28:      * Gets DSL module name from class or object instance
29:      *
30:      * @param string|object $name Fully qualified class name or object instance
31:      * @return string DSL name
32:      * @throws \InvalidArgumentException If $name is not a string/object
33:      */
34:     public static function base($name)
35:     {
36:         $names = explode('.', self::full($name));
37:         return array_pop($names);
38:     }
39: 
40:     /**
41:      * Converts DSL name to class name
42:      *
43:      * @param string|object $name Fully qualified class name or object instance
44:      * @return string DSL name
45:      * @throws \InvalidArgumentException If $name is not a string/object
46:      */
47:     public static function toClass($name)
48:     {
49:         if (is_object($name)) {
50:             return get_class($name);
51:         }
52:         elseif (is_string($name)) {
53:             return str_replace('.', '\\', $name);
54:         }
55:         else {
56:             throw new \InvalidArgumentException('Invalid type for object name');
57:         }
58:     }
59: 
60:     /**
61:      * Gets all but last name
62:      *
63:      * @param string|object $name Fully qualified class name or object instance
64:      * @return string DSL name
65:      * @throws \InvalidArgumentException If $name is not a string/object
66:      */
67:     public static function parent($name)
68:     {
69:         $names = explode('.', self::full($name));
70:         array_pop($names);
71:         return implode('.', $names);
72:     }
73: }
74: 
API documentation generated by ApiGen 2.8.0