generate() 공개 메소드

public generate ( ) : string
리턴 string
예제 #1
0
    public function testPropertyDefaultValueCanHandleComplexArrayOfTypes()
    {
        $targetValue = array(5, 'one' => 1, 'two' => '2', 'constant1' => '__DIR__ . \'/anydir1/anydir2\'', array('baz' => true, 'foo', 'bar', array('baz1', 'baz2', 'constant2' => 'ArrayObject::STD_PROP_LIST')), new ValueGenerator('PHP_EOL', 'constant'));
        $expectedSource = <<<EOS
array(
        5,
        'one' => 1,
        'two' => '2',
        'constant1' => __DIR__ . '/anydir1/anydir2',
        array(
            'baz' => true,
            'foo',
            'bar',
            array(
                'baz1',
                'baz2',
                'constant2' => ArrayObject::STD_PROP_LIST
                )
            ),
        PHP_EOL
        )
EOS;
        $valueGenerator = new ValueGenerator();
        $valueGenerator->initEnvironmentConstants();
        $valueGenerator->setValue($targetValue);
        $generatedTargetSource = $valueGenerator->generate();
        $this->assertEquals($expectedSource, $generatedTargetSource);
    }
예제 #2
0
 private function generateConfig()
 {
     $allClasses = get_declared_classes();
     $classList = [];
     foreach ($allClasses as $class) {
         $class = new ClassReflection($class);
         if ($this->shouldSkip($class)) {
             continue;
         }
         $classList[] = $class->getName();
     }
     $generator = new ValueGenerator($classList);
     return $generator->generate();
 }
예제 #3
0
    public function testPropertyDefaultValueCanHandleComplexArrayOfTypes()
    {
        $targetValue = array(5, 'one' => 1, 'two' => '2', array('foo', 'bar', array('baz1', 'baz2')), new ValueGenerator('PHP_EOL', 'constant'));
        $expectedSource = <<<EOS
array(
        5,
        'one' => 1,
        'two' => '2',
        array(
            'foo',
            'bar',
            array(
                'baz1',
                'baz2'
                )
            ),
        PHP_EOL
        )
EOS;
        $valueGenerator = new ValueGenerator();
        $valueGenerator->setValue($targetValue);
        $generatedTargetSource = $valueGenerator->generate();
        $this->assertEquals($expectedSource, $generatedTargetSource);
    }
예제 #4
0
 /**
  * Generate the getConfig() method
  *
  * @return MethodGenerator
  */
 protected function generateGetConfigMethod()
 {
     // create method body
     $body = new ValueGenerator();
     $body->initEnvironmentConstants();
     $body->setValue('include __DIR__ . \'/config/module.config.php\'');
     // create method
     $method = new MethodGenerator();
     $method->setName('getConfig');
     $method->setBody('return ' . $body->generate() . ';' . AbstractGenerator::LINE_FEED);
     // add optional doc block
     if ($this->flagCreateApiDocs) {
         $method->setDocBlock(new DocBlockGenerator('Get module configuration', null, array($this->generateReturnTag('array'))));
     }
     return $method;
 }
    $extendedClass = $resourceFile->getClass()->getExtendedClass();
    if (in_array($resourceFile->getClass()->getName(), $requestTypes) || in_array($extendedClass, $requestTypes)) {
        $type = $requestNamespacePart;
        $resourceFile->getClass()->setNamespaceName($requestNamespace);
        if (!$extendedClass) {
            $resourceFile->getClass()->setExtendedClass(SoapGenerator::ABSTRACT_REQUEST_ALIAS)->addUse("{$namespace}\\{$soapNamespace}\\AbstractRequest", SoapGenerator::ABSTRACT_REQUEST_ALIAS);
        }
    } elseif (in_array($resourceFile->getClass()->getName(), $responseTypes) || in_array($extendedClass, $responseTypes)) {
        $type = $responseNamespacePart;
        $resourceFile->getClass()->setNamespaceName($responseNamespace);
        if (!$extendedClass) {
            $resourceFile->getClass()->setExtendedClass(SoapGenerator::ABSTRACT_RESPONSE_ALIAS)->addUse("{$namespace}\\{$soapNamespace}\\AbstractResult", SoapGenerator::ABSTRACT_RESPONSE_ALIAS);
        }
    } else {
        $type = $structureNamespacePart;
        $resourceFile->getClass()->setNamespaceName($structureNamespace);
    }
    $resourceFile->setFilename("{$sourceDirectory}/{$soapNamespace}/{$type}/{$resourceFile->getClass()->getName()}.php");
    $resourceFile->write();
    $classmap[$resourceFile->getClass()->getName()] = $resourceFile->getClass()->getNamespaceName() . '\\' . $resourceFile->getClass()->getName();
}
foreach (glob("{$commonResourceDirectory}/*.php") as $fileName) {
    $className = basename($fileName, ".php");
    $classmap[$className] = "{$commonResourceNamespace}\\{$className}";
}
$classmapValueGenerator = new ValueGenerator($classmap);
$classmapFileGenerator = new FileGenerator();
$classmapFileGenerator->setBody('return ' . $classmapValueGenerator->generate() . ';');
$classmapFileGenerator->setFilename("{$sourceDirectory}/{$soapNamespace}/classmap.php");
$classmapFileGenerator->write();
passthru('php ' . __DIR__ . '/../vendor/fabpot/php-cs-fixer/php-cs-fixer fix ' . __DIR__ . '/../src/CallFire/Api/Soap/ --level=all');
 protected function coolFormat($array)
 {
     $generator = new ValueGenerator($array);
     return $generator->generate();
 }
예제 #7
0
    public function testPropertyDefaultValueCanHandleArrayWithUnsortedKeys()
    {
        $value = array(1 => 'a', 0 => 'b', 'c', 7 => 'd', 3 => 'e');
        $valueGenerator = new ValueGenerator();
        $valueGenerator->setValue($value);
        $expectedSource = <<<EOS
array(
    1 => 'a',
    0 => 'b',
    'c',
    7 => 'd',
    3 => 'e'
)
EOS;
        $this->assertEquals($expectedSource, $valueGenerator->generate());
    }
예제 #8
0
 /**
  * Generate the getAutoloaderConfig() method
  *
  * @return void
  */
 protected function addGetAutoloaderConfigMethod()
 {
     // set array data
     $array = ['Zend\\Loader\\ClassMapAutoloader' => ['__NAMESPACE__ => __DIR__ . \'/autoload_classmap.php\''], 'Zend\\Loader\\StandardAutoloader' => ['namespaces' => ['__NAMESPACE__ => __DIR__ . \'/src/\' . __NAMESPACE__']]];
     // create method body
     $body = new ValueGenerator();
     $body->initEnvironmentConstants();
     $body->setValue($array);
     // create method
     $method = new MethodGenerator();
     $method->setName('getAutoloaderConfig');
     $method->setBody('return ' . $body->generate() . ';' . AbstractGenerator::LINE_FEED);
     // check for api docs
     if ($this->config['flagAddDocBlocks']) {
         $method->setDocBlock(new DocBlockGenerator('Get module autoloader configuration', 'Sets up the module autoloader configuration', [new ReturnTag(['array'], 'module autoloader configuration')]));
     }
     // add method
     $this->addMethodFromGenerator($method);
     $this->addUse('Zend\\ModuleManager\\Feature\\AutoloaderProviderInterface');
     $this->setImplementedInterfaces(array_merge($this->getImplementedInterfaces(), ['AutoloaderProviderInterface']));
 }