Commits

Mark Story  committed c1b9f44

Add support for trait directives and cross referencing.

  • Participants
  • Parent commits 37d4203

Comments (0)

Files changed (1)

File phpdomain/sphinxcontrib/phpdomain.py

 NS = '\\'
 
 separators = {
-  'method':'::', 'function':NS, 'class':NS, 'namespace':NS,
-  'global':'', 'const':'::', 'attr': '::$', 'exception': '',
-  'staticmethod':'::', 'interface':NS
+  'method': '::',
+  'function': NS,
+  'class': NS,
+  'namespace': NS,
+  'global': '',
+  'const': '::',
+  'attr': '::$',
+  'exception': '',
+  'staticmethod': '::',
+  'interface': NS,
+  'trait': NS
 }
 
 php_separator = re.compile(r"(\w+)?(?:[:]{2})?")
                 fullname = name_prefix + name
 
             # Currently in a class, but not creating another class,
-            elif classname and not self.objtype in ['class', 'exception', 'interface']:
+            elif classname and not self.objtype in ['class', 'exception', 'interface', 'trait']:
                 if not self.env.temp_data['php:in_class']:
                     name_prefix = classname + separator
-                
+
                 fullname = classname + separator + name
             else:
                 classname = ''
 
 class PhpClasslike(PhpObject):
     """
-    Description of a class-like object (classes, exceptions).
+    Description of a class-like object
+    (classes, exceptions, interfaces, traits).
     """
 
     def get_signature_prefix(self, sig):
             if not modname:
                 return _('%s (interface)') % name_cls[0]
             return _('%s (interface in %s)') % (name_cls[0], modname)
+        elif self.objtype == 'trait':
+            if not modname:
+                return _('%s (trait)') % name_cls[0]
+            return _('%s (trait in %s)') % (name_cls[0], modname)
         elif self.objtype == 'exception':
             return name_cls[0]
         else:
         'exception': ObjType(l_('exception'), 'exc', 'obj'),
         'namespace': ObjType(l_('namespace'), 'ns', 'obj'),
         'interface': ObjType(l_('interface'), 'interface', 'obj'),
+        'trait': ObjType(l_('trait'), 'trait', 'obj'),
     }
 
     directives = {
         'staticmethod': PhpClassmember,
         'attr': PhpClassmember,
         'exception': PhpClasslike,
+        'interface': PhpClasslike,
+        'trait': PhpClasslike,
         'namespace': PhpNamespace,
-        'interface': PhpClasslike,
     }
 
     roles = {
         'ns': PhpXRefRole(),
         'obj': PhpXRefRole(),
         'interface': PhpXRefRole(),
+        'trait': PhpXRefRole(),
     }
 
     initial_data = {