setBody() 공개 메소드

Set the code body
public setBody ( string $body, boolean $newline = true ) : Generator
$body string
$newline boolean
리턴 Generator
예제 #1
0
 public function testRenderAndSave()
 {
     $c = new Generator(__DIR__ . '/../tmp/Test.php', Generator::CREATE_CLASS);
     $c->setNamespace(new NamespaceGenerator('Test\\Space'));
     $c->setBody('test body')->setClose(true);
     $c->appendToBody('more code');
     $body = $c->render(true);
     ob_start();
     $c->render();
     $output = ob_get_clean();
     $this->assertContains('namespace Test\\Space', $output);
     $c->save();
     $this->assertContains('test body', $body);
     $this->assertContains('more code', $body);
     $this->fileExists(__DIR__ . '/../tmp/Test.php');
     if (file_exists(__DIR__ . '/../tmp/Test.php')) {
         unlink(__DIR__ . '/../tmp/Test.php');
     }
 }
예제 #2
0
파일: code.php 프로젝트: nicksagona/PopPHP
<?php

require_once '../../bootstrap.php';
use Pop\Code;
try {
    // Create the code generator object
    $code = new Code\Generator('code.php');
    $code->setBody("// Let's get some stuff to happen here." . PHP_EOL . "\$blah = 'Sounds like a good idea';")->appendToBody("echo \$blah;", false)->setClose(true);
    // Render and output the code
    $code->output();
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}