Beispiel #1
0
 /**
  * Outputs a set of reflections.
  * 
  * @param array $reflections array in the form (filename=>reflection)
  * @return void
  */
 protected function _outputReflectionFiles($reflections)
 {
     $name = $this->_name;
     $serial = Vonnegut::mergeReflections($reflections, $name);
     $serial = Vonnegut::convertNamespaces($serial);
     $namespace = new StdClass();
     $namespace->namespace = $serial;
     //print_r($serial);
     $this->_outputReflectionFile("vonnegut", $serial);
 }
    public function testReflectString()
    {
        $phpString = <<<PHPSTRING
<?php
/**
 * phpString.php file description.
 * 
 * @package VonnegutTests
 * @author Joe Bloggs
 * @see SomethingElse
 */
/**
 * Lorem ipsum dolor sit amet.
 * 
 * Long description would go here and be a bit longer.
 * 
 * @package VonnegutTests
 * @author Joe Bloggs
 * @see SomethingElse
 */
class OneThing
{
    /**
     * Reference to the hoozit.
     * 
     * This is the long description of the hoozit which spans multiple
     * lines.
     * 
     * @var HoozitObject \$hoozit
     */
    protected \$hoozit;
    
    /**
     * Gets a whatsit.
     *
     * @param string \$thingy 
     * @param object \$mabob 
     * @return HoozitObject \$hoozit
     */
    public function whatsit(\$thingy, \$mabob) {
        return \$this->hoozit;
    }
    protected function eck() {
        
    }
}
/**
 * Short description of AndAnother
 * 
 * @package VonnegutTests
 * @author Joe Bloggs
 * @see SomethingElse
 */
class AndAnother
{
    
}
class UndocumentedClass
{
    private function undocumentedMethod(\$param1, \$param2) {
        
    }
}
PHPSTRING;
        $vonnegut = new Vonnegut();
        $serial = $vonnegut->reflectString($phpString);
        $vType = "Vonnegut String Serialization";
        $this->assertObjectHasAttribute('classes', $serial, "{$vType} has 'classes'");
        $this->assertObjectHasAttribute('OneThing', $serial->classes, "{$vType} classes contains 'OneThing'");
        $oneThing = $serial->classes->OneThing;
        $this->assertObjectHasAttribute('constants', $serial, "{$vType} has 'constants'");
        $this->assertObjectHasAttribute('variables', $serial, "{$vType} has 'variables'");
        $this->assertObjectHasAttribute('namespaces', $serial, "{$vType} has 'namespaces'");
        $this->assertObjectHasAttribute('meta', $serial, "{$vType} has 'meta'");
        $this->assertEquals(3, count((array) $serial->classes), "{$vType} contains 3 classes");
        $this->assertObjectHasAttribute('methods', $oneThing, "{$vType} Class contains a 'methods' attribute");
        $this->assertArrayHasKey('whatsit', $oneThing->methods, "{$vType} Class contains whatsit method");
        $this->assertArrayHasKey('eck', $oneThing->methods, "{$vType} Class contains eck method");
        $this->assertEquals("Gets a whatsit.", $oneThing->methods['whatsit']->description, "OneThing::whatsit method has the right description");
    }
Beispiel #3
0
 /**
  * Converts classes to "namespaced" structure.
  *
  * @param object $serial a vonnegut serial
  * @return $serial the converted object
  */
 public static function convertNamespaces($serial)
 {
     foreach ($serial->classes as $className => $classSerial) {
         if (Vonnegut::hasNamespaces($className)) {
             $names = explode('_', $classSerial->name);
             $littleName = $classSerial->name = array_pop($names);
             $curContext = $serial;
             foreach ($names as $namespace) {
                 if (!isset($curContext->namespaces->{$namespace})) {
                     $curContext->namespaces->{$namespace} = new Vonnegut_Namespace();
                     $curContext->namespaces->{$namespace}->name = $namespace;
                 }
                 $curContext = $curContext->namespaces->{$namespace};
             }
             $curContext->classes->{$littleName} = clone $classSerial;
             unset($serial->classes->{$className});
         }
     }
     return $serial;
 }