atelierspierrot/library

View on GitHub
phpdoc/Library/Factory.html

Summary

Maintainability
Test Coverage
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="robots" content="index, follow, all" />
    <title>Library\Factory | Library</title>

            <link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="../css/bootstrap-theme.min.css">
        <link rel="stylesheet" type="text/css" href="../css/sami.css">
        <script src="../js/jquery-1.11.1.min.js"></script>
        <script src="../js/bootstrap.min.js"></script>
        <script src="../js/typeahead.min.js"></script>
        <script src="../sami.js"></script>
        <meta name="MobileOptimized" content="width">
        <meta name="HandheldFriendly" content="true">
        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
    
    
    </head>

    <body id="class" data-name="class:Library_Factory" data-root-path="../">
            <div id="content">
        <div id="left-column">
                <div id="control-panel">
                <form id="search-form" action="../search.html" method="GET">
            <span class="glyphicon glyphicon-search"></span>
            <input name="search"
                   class="typeahead form-control"
                   type="search"
                   placeholder="Search">
        </form>
    </div>

                <div id="api-tree"></div>

        </div>
        <div id="right-column">
                <nav id="site-nav" class="navbar navbar-default" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-elements">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="../index.html">Library</a>
            </div>
            <div class="collapse navbar-collapse" id="navbar-elements">
                <ul class="nav navbar-nav">
                    <li><a href="../classes.html">Classes</a></li>
                                            <li><a href="../namespaces.html">Namespaces</a></li>
                                        <li><a href="../interfaces.html">Interfaces</a></li>
                    <li><a href="../traits.html">Traits</a></li>
                    <li><a href="../doc-index.html">Index</a></li>
                    <li><a href="../search.html">Search</a></li>
                </ul>
            </div>
        </div>
    </nav>

                        <div class="namespace-breadcrumbs">
            <ol class="breadcrumb">
                <li><span class="label label-default">class</span></li>
                                                            <li><a href="../Library.html">Library</a></li>
    
                <li>Factory</li>
            </ol>
        </div>
                <div id="page-content">
                
    <div class="page-header">
        <h1>Factory</h1>
    </div>

    <p>    class
    <strong>Factory</strong>        extends <abbr title="Patterns\Abstracts\AbstractStaticCreator">AbstractStaticCreator</abbr>        implements
        <a href="../Library/FactoryInterface.html"><abbr title="Library\FactoryInterface">FactoryInterface</abbr></a>
</p>

            <div class="description">
            <p>Factory will try to create an object following user rules and passing it arguments</p>            <p><h2>Usage</h2>

<pre><code>$factory = \Library\Factory::create()
    // all methods are optional
    -&gt;factoryName('A Name To Identify Error Message')
    -&gt;mustImplement('RequiredInterface')
    -&gt;mustImplementAll(array('RequiredInterface1', 'RequiredInterface2'))
    -&gt;mustExtend('RequiredInheritance')
    -&gt;mustImplementOrExtend(array('RequiredInheritance', 'OR', 'RequiredInterface'))
    -&gt;defaultNamespace('\Possible\Namespace')
    -&gt;mandatoryNamespace('\Required\Namespace')
    -&gt;classNameMask(array('%s', '%s_Suffix'))
    -&gt;callMethod('load')
    ;
</code></pre>

<p>You can also define all options as an array to the creator:</p>

<pre><code>$factory = \Library\Factory::create(array(
    // all options are optional
    'factory_name' =&gt; 'A Name To Identify Error Message',
    'must_implement' =&gt; 'RequiredInterface',
    'must_implement_all' =&gt; array('RequiredInterface1', 'RequiredInterface2'),
    'must_extend' =&gt; 'RequiredInheritance',
    'must_implement_or_extend' =&gt; array('RequiredInheritance', 'OR', 'RequiredInterface'),
    'default_namespace' =&gt; '\Possible\Namespace',
    'mandatory_namespace' =&gt; '\Required\Namespace',
    'class_name_mask' =&gt; array('%s', '%s_Suffix'),
    'call_method' =&gt; 'load',
));
</code></pre>

<p>Then, to try to build the object:</p>

<pre><code>$object = $factory-&gt;build($name, $params);
</code></pre>

<p>Errors are thrown by default. You can avoid this using the <code>GRACEFULLY_FAILURE</code> constant flag.
All error messages are loaded in the <code>$logs</code> last parameter of the <code>build()</code> and
<code>findBuilder()</code> methods.</p>

<h2>Method parameters</h2>

<p>When the object creation method is called, the parameters passed to the <code>Factory::build()</code>
method are re-organized before to pass them to the method. This way, you can define the
parameters as an array using explicit indexes corresponding to the parameters names in
method declaration without working about their order.</p>

<h2>Specific method to build the instance</h2>

<p>In the case of a specific <code>$call_method</code> (not the classic <code>__construct</code>), the builder will
try to first construct the object except if the call method is static. If it is not static,
any existing constructor will be first called without parameters and then the defined
call method passing it the parameters.</p>        </div>
    
    
    
    
            <h2>Methods</h2>

            <div class="container-fluid underlined">
                    <div class="row">
                <div class="col-md-2 type">
                    
    void
                </div>
                <div class="col-md-8 type">
                    <a href="#method_init">init</a>(
    array $options = null)
                                            <p>Initialize the factory with an array of options</p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    
    <a href="../Library/Factory.html"><abbr title="Library\Factory">Factory</abbr></a>
                </div>
                <div class="col-md-8 type">
                    <a href="#method___call">__call</a>(
    string $name, 
    array $arguments)
                                            <p>Magic method to allow usage of <code>$factory-&gt;propertyInCamelCase()</code> for each class property</p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    
    <a href="../Library/Factory.html"><abbr title="Library\Factory">Factory</abbr></a>
                </div>
                <div class="col-md-8 type">
                    <a href="#method_setOptions">setOptions</a>(
    array $options)
                                            <p>Set the object options like <code>property =&gt; value</code></p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    
    object
                </div>
                <div class="col-md-8 type">
                    <a href="#method_build">build</a>(
    string $name, 
    array $parameters = null, 
    int $flag = self::ERROR_ON_FAILURE, 
    array $logs = array())
                                            <p>Build the object instance following current factory settings</p>                </div>
                <div class="col-md-2"></div>
            </div>
                    <div class="row">
                <div class="col-md-2 type">
                    
    null|string
                </div>
                <div class="col-md-8 type">
                    <a href="#method_findBuilder">findBuilder</a>(
    string $name, 
    int $flag = self::ERROR_ON_FAILURE, 
    array $logs = array())
                                            <p>Find the object builder class following current factory settings</p>                </div>
                <div class="col-md-2"></div>
            </div>
            </div>


        <h2>Details</h2>

            <div id="method-details">
                    <div class="method-item">
                    <h3 id="method_init">
        <div class="location">at line 202</div>
        <code>                    
    void
    <strong>init</strong>(
    array $options = null)</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Initialize the factory with an array of options</p>                    <p>The options must be defined like <code>property =&gt; value</code></p>            </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    array</td>
                <td>$options</td>
                <td>
</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    void</td>
            <td>
</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method___call">
        <div class="location">at line 216</div>
        <code>                    
    <a href="../Library/Factory.html"><abbr title="Library\Factory">Factory</abbr></a>
    <strong>__call</strong>(
    string $name, 
    array $arguments)</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Magic method to allow usage of <code>$factory-&gt;propertyInCamelCase()</code> for each class property</p>                                </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    string</td>
                <td>$name</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    array</td>
                <td>$arguments</td>
                <td>
</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    <a href="../Library/Factory.html"><abbr title="Library\Factory">Factory</abbr></a></td>
            <td>
</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method_setOptions">
        <div class="location">at line 236</div>
        <code>                    
    <a href="../Library/Factory.html"><abbr title="Library\Factory">Factory</abbr></a>
    <strong>setOptions</strong>(
    array $options)</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Set the object options like <code>property =&gt; value</code></p>                                </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    array</td>
                <td>$options</td>
                <td>
</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    <a href="../Library/Factory.html"><abbr title="Library\Factory">Factory</abbr></a></td>
            <td>
</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method_build">
        <div class="location">at line 261</div>
        <code>                    
    object
    <strong>build</strong>(
    string $name, 
    array $parameters = null, 
    int $flag = self::ERROR_ON_FAILURE, 
    array $logs = array())</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Build the object instance following current factory settings</p>                    <p>Errors are thrown by default but can be "gracefully" skipped using the flag <code>GRACEFULLY_FAILURE</code>.
In all cases, error messages are loaded in final parameter <code>$logs</code> passed by reference.</p>            </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    string</td>
                <td>$name</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    array</td>
                <td>$parameters</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    int</td>
                <td>$flag</td>
                <td>One of the class constants flags</td>
            </tr>
                    <tr>
                <td>
    array</td>
                <td>$logs</td>
                <td>Passed by reference</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    object</td>
            <td>
</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
                    <div class="method-item">
                    <h3 id="method_findBuilder">
        <div class="location">at line 350</div>
        <code>                    
    null|string
    <strong>findBuilder</strong>(
    string $name, 
    int $flag = self::ERROR_ON_FAILURE, 
    array $logs = array())</code>
    </h3>
    <div class="details">
                    <div class="method-description">
                                    <p>Find the object builder class following current factory settings</p>                    <p>Errors are thrown by default but can be "gracefully" skipped using the flag <code>GRACEFULLY_FAILURE</code>.
In all cases, error messages are loaded in final parameter <code>$logs</code> passed by reference.</p>            </div>
                <div class="tags">
                            <h4>Parameters</h4>

                    <table class="table table-condensed">
                    <tr>
                <td>
    string</td>
                <td>$name</td>
                <td>
</td>
            </tr>
                    <tr>
                <td>
    int</td>
                <td>$flag</td>
                <td>One of the class constants flags</td>
            </tr>
                    <tr>
                <td>
    array</td>
                <td>$logs</td>
                <td>Passed by reference</td>
            </tr>
            </table>

            
                            <h4>Return Value</h4>

                    <table class="table table-condensed">
        <tr>
            <td>
    null|string</td>
            <td>
</td>
        </tr>
    </table>

            
            
                    </div>
    </div>

            </div>
            </div>

    
            </div>
                <div id="footer">
        Generated by <a href="http://sami.sensiolabs.org/">Sami, the API Documentation Generator</a>.
    </div>

        </div>
    </div>
    </body>

</html>