1. Jon Langevin
  2. ActiveDocument

Commits

Jon Langevin  committed ef0beed

Reverted change to MetaData which had disabled the incorrect functionality. Class-level phpdoc parsing to detect magic attributes is now properly disabled.

  • Participants
  • Parent commits 794a257
  • Branches default

Comments (0)

Files changed (1)

File MetaData.php

View file
  • Ignore whitespace
      * @var \ArrayObject
      */
     protected $_classMeta;
+    protected $_docAttributeRegex = '/\@(?<attribute>\w+)(?<!property|property-read|property-write|var)\s+(?:(\$)\w+\:\s)?\s*(?<value>[^\s]+)\s+\2?\s*(?<comment>.*)?/';
 
     /**
      * @var \ArrayObject
         ), \ArrayObject::ARRAY_AS_PROPS);
 
         /**
-         * Parse class phpdoc
+         * Parse class phpdoc (also detects magic properties)
          */
-        $this->parsePhpDoc($reflectionClass->getDocComment());
+        #$this->parsePhpDoc($reflectionClass->getDocComment());
 
         /**
          * Get physical class properties & metadata from phpdoc if available
             /**
              * Parse class meta
              */
+            if ($property === null)
+                array_walk($phpdoc, array($this, 'parsePhpDocAttributes'));
             array_walk($phpdoc, array($this, 'parsePhpDocProperties'), $property);
         }
     }
     }
 
     /**
+     * Parses phpdoc text to find general pattern of "attribute value comment"
+     *
+     * @param string $string Line of phpdoc
+     * @param int    $index
+     */
+    protected function parsePhpDocAttributes($string, $index) {
+        if (preg_match($this->_docAttributeRegex, $string, $matches)) {
+            $matches = array_intersect_key($matches, array('attribute' => null, 'value' => null, 'comment' => null));
+
+            if (!array_key_exists($matches['attribute'], $this->_classMeta))
+                $this->_classMeta->{$matches['attribute']} = new \ArrayObject($matches, \ArrayObject::ARRAY_AS_PROPS);
+        }
+    }
+
+    /**
      * Parses phpdoc text to identify class property definitions
      *
      * @param string                   $string Line of phpdoc