PHPackages                             jrdnull/phpwriter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. jrdnull/phpwriter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

jrdnull/phpwriter
=================

PHPWriter generates PHP source code

36PHP

Since Oct 17Pushed 11y ago1 watchersCompare

[ Source](https://github.com/jrdnull/phpwriter)[ Packagist](https://packagist.org/packages/jrdnull/phpwriter)[ RSS](/packages/jrdnull-phpwriter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHPWriter
=========

[](#phpwriter)

[![Build Status](https://camo.githubusercontent.com/e5eaf02083ee77f22dd15df7845f384b13d93dc2bd1597a6fc9e464e3af28c0d/68747470733a2f2f7472617669732d63692e6f72672f6a72646e756c6c2f7068707772697465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jrdnull/phpwriter)[![Code Climate](https://camo.githubusercontent.com/4fc1d0a86bd224bd0ceea3902804a7be773a06ece2dd523f946ad13df9f2248a/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6a72646e756c6c2f7068707772697465722f6261646765732f6770612e737667)](https://codeclimate.com/github/jrdnull/phpwriter)[![Test Coverage](https://camo.githubusercontent.com/b14fc8eb631dc72c35ad68db8fbcc5688d95f3bd140ac2a5d05f55dbf82accae/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6a72646e756c6c2f7068707772697465722f6261646765732f636f7665726167652e737667)](https://codeclimate.com/github/jrdnull/phpwriter)

Inspired by [JavaWriter](https://github.com/square/javawriter), PHPWriter generates PHP source code.

Example
-------

[](#example)

```
$phpWriter->openTag()
          ->beginType('Person', PhpWriter::TYPE_CLASS)
              ->emitDocblock([
                  '@Id',
                  '@Column(type="integer")',
                  '@GeneratedValue',
                  '@var int'
              ])
              ->emitProperty('id', PhpWriter::VISIBILITY_PROTECTED)
              ->emitNewline()
              ->emitDocblock(['@Column(type="string")', '@var string'])
              ->emitProperty('name', PhpWriter::VISIBILITY_PROTECTED)
              ->emitNewline()
              ->beginMethod('getId', PhpWriter::VISIBILITY_PUBLIC)
                  ->emitStatement('return $this->id')
              ->endMethod()
              ->emitNewline()
              ->beginMethod('getName', PhpWriter::VISIBILITY_PUBLIC)
                  ->emitStatement('return $this->name')
              ->endMethod()
              ->emitNewline()
              ->beginMethod('setName', PhpWriter::VISIBILITY_PUBLIC, ['name'])
                  ->emitStatement('$this->name = $name')
              ->endMethod()
          ->endType();
```

Produces:

```
