<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/language.attributes.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'pt_BR',
  ),
  'this' => 
  array (
    0 => 'language.attributes.classes.php',
    1 => 'Declarando Classes de Atributos',
    2 => 'Declarando Classes de Atributos',
  ),
  'up' => 
  array (
    0 => 'language.attributes.php',
    1 => 'Atributos',
  ),
  'prev' => 
  array (
    0 => 'language.attributes.reflection.php',
    1 => 'Lendo Atributos com a API Reflection',
  ),
  'next' => 
  array (
    0 => 'language.references.php',
    1 => 'Refer&ecirc;ncias',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'pt_BR',
    'path' => 'language/attributes.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="language.attributes.classes" class="sect1">
  <h2 class="title">Declarando Classes de Atributos</h2>

  <p class="para">
   É recomendado definir uma classe separada para cada atributo.
   No caso mais simples, uma classe vazia com a declaração <code class="literal">#[Attribute]</code>
   é suficiente. O atributo pode ser importado do namespace global usando uma
   declaração <code class="literal">use</code>.
  </p>

  <div class="example" id="example-1">
   <p><strong>Exemplo #1 Classe de Atributo Simples</strong></p>

   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">namespace </span><span style="color: #0000BB">Example</span><span style="color: #007700">;<br /><br />use </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">;<br /><br />#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">]<br />class </span><span style="color: #0000BB">MyAttribute<br /></span><span style="color: #007700">{<br />}</span></span></code></div>
   </div>

  </div>

  <p class="para">
   Para restringir os tipos de declarações às quais um atributo pode ser aplicado,
   passe uma máscara de bits como o primeiro argumento para a declaração
   <code class="literal">#[Attribute]</code>.
  </p>

  <div class="example" id="example-2">
   <p><strong>Exemplo #2 Usando a especificação de destino para restringir onde os atributos podem ser usados</strong></p>

   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">namespace </span><span style="color: #0000BB">Example</span><span style="color: #007700">;<br /><br />use </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">;<br /><br />#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">(</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">::</span><span style="color: #0000BB">TARGET_METHOD </span><span style="color: #007700">| </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">::</span><span style="color: #0000BB">TARGET_FUNCTION</span><span style="color: #007700">)]<br />class </span><span style="color: #0000BB">MyAttribute<br /></span><span style="color: #007700">{<br />}</span></span></code></div>
   </div>


   <div class="example-contents"><p>
    Declarar <span class="classname"><strong class="classname">MyAttribute</strong></span> em outro tipo agora lançará uma exceção durante a
    chamada para <span class="function"><a href="reflectionattribute.newinstance.php" class="function">ReflectionAttribute::newInstance()</a></span>
   </p></div>
  </div>

  <p class="para">Os seguintes alvos podem ser especificados:</p>

  <ul class="simplelist">
   <li><strong><code><a href="class.attribute.php#attribute.constants.target-class">Attribute::TARGET_CLASS</a></code></strong></li>
   <li><strong><code><a href="class.attribute.php#attribute.constants.target-function">Attribute::TARGET_FUNCTION</a></code></strong></li>
   <li><strong><code><a href="class.attribute.php#attribute.constants.target-method">Attribute::TARGET_METHOD</a></code></strong></li>
   <li><strong><code><a href="class.attribute.php#attribute.constants.target-property">Attribute::TARGET_PROPERTY</a></code></strong></li>
   <li><strong><code><a href="class.attribute.php#attribute.constants.target-class-constant">Attribute::TARGET_CLASS_CONSTANT</a></code></strong></li>
   <li><strong><code><a href="class.attribute.php#attribute.constants.target-parameter">Attribute::TARGET_PARAMETER</a></code></strong></li>
   <li><strong><code><a href="class.attribute.php#attribute.constants.target-all">Attribute::TARGET_ALL</a></code></strong></li>
  </ul>

  <p class="para">
    Por padrão, um atributo só pode ser usado uma vez por declaração. Para permitir
    que um atributo seja repetível, especifique-o na máscara de bits da
    declaração <code class="literal">#[Attribute]</code> usando o sinalizador
    <strong><code><a href="class.attribute.php#attribute.constants.is-repeatable">Attribute::IS_REPEATABLE</a></code></strong>.
  </p>

  <div class="example" id="example-3">
   <p><strong>Exemplo #3 Usando IS_REPEATABLE para permitir o atributo em uma declaração várias vezes</strong></p>

   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">namespace </span><span style="color: #0000BB">Example</span><span style="color: #007700">;<br /><br />use </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">;<br /><br />#[</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">(</span><span style="color: #0000BB">Attribute</span><span style="color: #007700">::</span><span style="color: #0000BB">TARGET_METHOD </span><span style="color: #007700">| </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">::</span><span style="color: #0000BB">TARGET_FUNCTION </span><span style="color: #007700">| </span><span style="color: #0000BB">Attribute</span><span style="color: #007700">::</span><span style="color: #0000BB">IS_REPEATABLE</span><span style="color: #007700">)]<br />class </span><span style="color: #0000BB">MyAttribute<br /></span><span style="color: #007700">{<br />}</span></span></code></div>
   </div>


  </div>
 </div><?php manual_footer($setup); ?>