phpdoc/Patterns/Traits/SingletonTrait.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="robots" content="index, follow, all" />
<title>Patterns\Traits\SingletonTrait | Patterns</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:Patterns_Traits_SingletonTrait" 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">Patterns</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">trait</span></li>
<li><a href="../../Patterns.html">Patterns</a></li>
<li><a href="../../Patterns/Traits.html">Traits</a></li>
<li>SingletonTrait</li>
</ol>
</div>
<div id="page-content">
<div class="page-header">
<h1>SingletonTrait</h1>
</div>
<p> trait
<strong>SingletonTrait</strong>
</p>
<div class="description">
<p>Basic singleton object definition</p> <p>Usage</p>
<pre><code> $instance = class::getInstance( $args )
</code></pre>
<p>This trait defines an abstract <code>__construct</code> method forcing
your implementations to define the hard constructor yourself
choosing its visibility. The best practice is to make your
constructor protected or private.</p>
<p>If your constructor is not public and the <code>getInstance</code> received
arguments, it will call a <code>init( $args )</code> method (if it is public)
fetching it received arguments. This allows to build an instance
with parameters.</p> </div>
<h2>Methods</h2>
<div class="container-fluid underlined">
<div class="row">
<div class="col-md-2 type">
</div>
<div class="col-md-8 type">
<a href="#method___construct">__construct</a>()
<p>Constructor : classic object constructor</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
static
<a href="../../Patterns/Traits/SingletonTrait.html"><abbr title="Patterns\Traits\SingletonTrait">SingletonTrait</abbr></a>
</div>
<div class="col-md-8 type">
<a href="#method_getInstance">getInstance</a>()
<p>This is the static constructor/getter of the singleton instance</p> </div>
<div class="col-md-2"></div>
</div>
<div class="row">
<div class="col-md-2 type">
void
</div>
<div class="col-md-8 type">
<a href="#method___clone">__clone</a>()
<p>This must throw an error as cloning a singleton is forbidden</p> </div>
<div class="col-md-2"></div>
</div>
</div>
<h2>Details</h2>
<div id="method-details">
<div class="method-item">
<h3 id="method___construct">
<div class="location">at line 62</div>
<code> abstract
<strong>__construct</strong>()</code>
</h3>
<div class="details">
<div class="method-description">
<p>Constructor : classic object constructor</p> <p>The best practice is to define a <code>private</code> constructor to avoid object direct
creation ; if the constructor is public, it will receive the arguments passed
to the <code>getInstance</code> method.</p> </div>
<div class="tags">
</div>
</div>
</div>
<div class="method-item">
<h3 id="method_getInstance">
<div class="location">at line 86</div>
<code> static
<a href="../../Patterns/Traits/SingletonTrait.html"><abbr title="Patterns\Traits\SingletonTrait">SingletonTrait</abbr></a>
<strong>getInstance</strong>()</code>
</h3>
<div class="details">
<div class="method-description">
<p>This is the static constructor/getter of the singleton instance</p> <p>If the instance does not exist yet, it will create it fetching
received arguments to the constructor if it is public, or to
an <code>init()</code> method if it exists and is callable.</p>
<p>If this method receives arguments but can not fetch them to
the constructor or an <code>init</code> method, a E<em>USER</em>WARNING is triggered
to inform user about the arguments loss.</p> </div>
<div class="tags">
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
<a href="../../Patterns/Traits/SingletonTrait.html"><abbr title="Patterns\Traits\SingletonTrait">SingletonTrait</abbr></a></td>
<td>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="method-item">
<h3 id="method___clone">
<div class="location">at line 116</div>
<code>
void
<strong>__clone</strong>()</code>
</h3>
<div class="details">
<div class="method-description">
<p>This must throw an error as cloning a singleton is forbidden</p> </div>
<div class="tags">
<h4>Return Value</h4>
<table class="table table-condensed">
<tr>
<td>
void</td>
<td>
</td>
</tr>
</table>
<h4>Exceptions</h4>
<table class="table table-condensed">
<tr>
<td><a target="_blank" href="http://php.net/Exception"><abbr title="Exception">Exception</abbr></a></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>