PHPackages                             dalia-it/rough - 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. dalia-it/rough

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

dalia-it/rough
==============

Adds macro support to composer

v0.0.1-alpha1(13y ago)019MITPHP

Since Feb 14Pushed 13y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (0)

rough
=====

[](#rough)

Add a comment to your code, run the macro command and rough generates code.

The macros are not removed from the source code and can easly be updated.

Currently there are macros to:

- generate get methods
- generate set methods
- emulate traits in PHP 5.3

Macro Syntax
------------

[](#macro-syntax)

```
#@   .... #
#@ä

```

- Macros are line comments.
- There must not be anything but whitespace before the first '#'.

I will use the get macro as an example.

\###basic syntax

```
protected $name;
#@get public name#
#@#

```

The first line starts the macro- The second marks the end of the macro. All code generated by the macro will go between those two lines.

\###shorthand notation

```
protected $name;
#@get public name@#

```

\###arguments arguments are seperated by whitespace:

```
#@get public name string@#

```

The simplest form of argument is a *single word*.

In the example above the 'get' macro will be called with the two arguments 'name' and 'string'.

If an argument contains whitespace surround it with double quotes to mark it as a *litteral*:

```
@get "public final" name string@#

```

In the example above the 'get' macro will be called with the two arguments 'public final' and 'string'.

Some macros support passing a *array* as an arument:

```
protected
    $name,
    $email;

#@get public [name email] string@#

```

In the example above the 'get' macro will be called with the two arguments array('name','email') and 'string'. The members of the array are seperated the same way normal arguments are so you can place an literal in an array:

```
protected
    $name,
    $email;

#@get public [name email "invalid property name"] string@#

```

Nested arrays are *not* supported.

Running Macros
--------------

[](#running-macros)

Running the macros requires two steps:

- add build settings to your composer.json
- run the rough commandline tool

\###The Build File

Before running the rough tool you have to add some information to your composer.json.

```
"extra":{
        "dalia-it":{
            "rough":{
                "build":{
                    "source": "src/",
                    "output": "src/"
                }
            }
        }
    }
}

```

The *source* option tells rough where to look for files.

The *output* option tells rough where to write the results.

Once you have everything set up, run the rough commandline tool:

```
php vendor/bin/rough macros

```

Rough will look for a composer.json in the current work directory. If you want to use a differnt file you can pass it as an parameter.

```
php vendor/bin/rough macros vendor/foo/foo/build.json

```

Default Macrosos
----------------

[](#default-macrosos)

- [Acess](src/daliaIT/rough/macro/AccessMacro.php)
- [Get](src/daliaIT/rough/macro/AccessMacro.php)
- [import](src/daliaIT/rough/macro/AccessMacro.php)
- [set](src/daliaIT/rough/macro/AccessMacro.php)
- [trait](src/daliaIT/rough/macro/AccessMacro.php)

imports and trait
-----------------

[](#imports-and-trait)

Traits are a great PHP 5.4 feature. In PHP 5.3 you can use rough to emulate some (but not all) features of traits.

The import macro simply copies the body of one class into another.

The advantages over a manual copy and paste:

- The import macro will update the code if you change it.
- If you build your project in PHP &gt;=5.4.0 the macros will create normal traits

Since this sollution does *not* support inheritance or namespaces you should only import classes which are designed to be used this way (pseudo traits).

- Pseudo traits are final.
- Psudo must always use fully qualified class names.

Rough will use the composer autoloader to find thze class definition. If you have duplicate code in your project you can use the `which` command to find out which file will be used:

```
php vemdor/bin rough ehich my\\duplicate\\ClassName

```

Define a pseudo trait:

```
namespace vendor\product;
#@trait Unique@#
{
    protected $uniqueId;

    public function getUniqueId(){...}
    public function setUniqueId(\vendor\product\UniqueId $value){...}
}

```

Use the pseudo trait:

```
namespace vendor\product;
class User:
{
    #@import vendor\product\Unique@#
}

```

\###Results:

\####PHP &lt; 5.4.0

The trait:

```
namespace vendor\product;
#@trait#
final class Unique
#@#
{
    protected $uniqueId;

    public function getUniqueId(){...}
    public function setUniqueId(\vendor\product\UniqueId $value){...}
}

```

The using class:

```
namespace vendor\product;
class User:
{
    #@import vendor\product\Unique@#
    protected $uniqueId;
    public function getUniqueId(){...}
    public function setUniqueId(\vendor\product\UniqueId $value){...}
    #@#
}

```

\####PHP &gt;= 5.4.0

The trait:

```
namespace vendor\product;
#@trait#
trait Unique
#@#
{
    protected $uniqueId;

    public function getUniqueId(){...}
    public function setUniqueId(\vendor\product\UniqueId $value){...}
}

```

The using class:

```
namespace vendor\product;
class User:
{
    #@import vendor\product\Unique@#
    use \vendor\product\Unique;
    #@#
}

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

4832d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/723d4c456103036cd65e82cb4fd91ad3ca259dc0d69d77ca064cd2db95981100?d=identicon)[noptic](/maintainers/noptic)

---

Top Contributors

[![noptic](https://avatars.githubusercontent.com/u/465885?v=4)](https://github.com/noptic "noptic (48 commits)")

### Embed Badge

![Health badge](/badges/dalia-it-rough/health.svg)

```
[![Health](https://phpackages.com/badges/dalia-it-rough/health.svg)](https://phpackages.com/packages/dalia-it-rough)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
