Skip to content
Permalink
Browse files

Added ToStringBuilder docs.

  • Loading branch information...
piotrooo committed Mar 11, 2019
1 parent 7cdab56 commit 7c5141758ac64ba516008982b5be8105d0a57807
Showing with 130 additions and 5 deletions.
  1. +1 −0 docs/index.rst
  2. +119 −0 docs/utils/to_string_builder.rst
  3. +10 −5 src/Ouzo/Goodies/README.md
@@ -43,6 +43,7 @@ Start with `5 minutes tutorial`_, read about project structure and then dive dee
utils/clock
utils/joiner
utils/time_ago
utils/to_string_builder

.. toctree::
:maxdepth: 2
@@ -0,0 +1,119 @@
ToStringBuilder
===============

Assists in implementing ``__toString()`` methods.

To use this class write code as follows:

::

namespace Application\Model;

class Person
{
/** @var string */
private $name;
/** @var int */
private $age;
/** @var boolean */
private $smoking;
/** @var array */
private $tags;

public function __construct($name, $age, $smoking, $tags)
{
$this->name = $name;
$this->age = $age;
$this->smoking = $smoking;
$this->tags = $tags;
}

public function __toString()
{
return (new ToStringBuilder($this))
->append('name', $this->name)
->append('age', $this->age)
->append('smoking', $this->smoking)
->append('tags', $this->tags)
->toString();
}
}

This will produce a ``__toString`` of the format: ``Application\Model\Person[name=jon,age=91,smoking=true,tags={tag1,tag2,another tag}]``

There are several possible styles:

----

ToStringStyle::defaultStyle()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The default ``__toString`` style.

**Example:**

``Application\Model\Person[name=jon,age=91,smoking=true,tags={tag1,tag2,another tag}]``

----

ToStringStyle::noFieldNamesStyle()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The no field names style.

**Example:**

``Application\Model\Person[jon,91,true,{tag1,tag2,another tag}]``

----

ToStringStyle::shortPrefixStyle()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The short class name style.

**Example:**

``Person[name=jon,age=91,smoking=true,tags={tag1,tag2,another tag}]``

----

ToStringStyle::simpleStyle()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The simple style.

**Example:**

``jon,91,true,{tag1,tag2,another tag}``

----

ToStringStyle::noClassNameStyle()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The no class names style.

**Example:**

``[name=jon,age=91,smoking=true,tags={tag1,tag2,another tag}]``

----

ToStringStyle::multiLineStyle()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The multi line style.

**Example:**

::

Application\Model\Person[
name=jon
age=91
smoking=true
tags={tag1,tag2,another tag}
]


@@ -1,7 +1,8 @@
Ouzo Goodies
==============

###What is it
What is it
----------

Utility classes, test assertions and mocking framework extracted from [Ouzo framework](http://ouzoframework.org). We are compatible with PHP 5.3 and later.

@@ -11,7 +12,8 @@ Utility classes, test assertions and mocking framework extracted from [Ouzo fram
[![Total Downloads](https://poser.pugx.org/letsdrink/ouzo-goodies/downloads.svg)](https://packagist.org/packages/letsdrink/ouzo-goodies)
[![License](https://poser.pugx.org/letsdrink/ouzo-goodies/license.svg)](https://packagist.org/packages/letsdrink/ouzo-goodies)

###How to use it
How to use it
-------------

Couple of examples.

@@ -111,7 +113,8 @@ CatchException::assertThat()->isInstanceOf("FooException");

This is just a taste of Ouzo. Look at the documentation for more goodies.

###Where to get it
Where to get it
---------------

Download from github or simply add composer dependency:
```
@@ -120,7 +123,8 @@ Download from github or simply add composer dependency:

[Ouzo Goodies at packagist](https://packagist.org/packages/letsdrink/ouzo-goodies).

###Documentation
Documentation
-------------

Tutorials:
* [Functional programming with Ouzo](http://ouzo.readthedocs.org/en/latest/documentation/functional_programming.html)
@@ -148,7 +152,8 @@ Tests:

Check out full docs at http://ouzo.readthedocs.org

###PhpStorm plugins:
PhpStorm plugins:
-----------------
* [Ouzo framework plugin](http://plugins.jetbrains.com/plugin/7565?pr=)
* [DynamicReturnTypePlugin](http://plugins.jetbrains.com/plugin/7251) - for Mock and CatchException. You have to copy [dynamicReturnTypeMeta.json ](https://github.com/letsdrink/ouzo/blob/master/dynamicReturnTypeMeta.json) to your project root.

0 comments on commit 7c51417

Please sign in to comment.
You can’t perform that action at this time.