-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ad35c9
commit 6236f89
Showing
4 changed files
with
488 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- EN-Revision: 4a211b7c8fb2b4410851d06c6f90f751d1f670d0 Maintainer: leonardolara Status: ready --> | ||
|
||
<refentry xml:id="yaf-application.bootstrap" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
<refnamediv> | ||
<refname>Yaf_Application::bootstrap</refname> | ||
<refpurpose>Chama o bootstrap</refpurpose> | ||
</refnamediv> | ||
|
||
<refsect1 role="description"> | ||
&reftitle.description; | ||
<methodsynopsis> | ||
<modifier>public</modifier> <type>void</type><methodname>Yaf_Application::bootstrap</methodname> | ||
<methodparam choice="opt"><type>Yaf_Bootstrap_Abstract</type><parameter>bootstrap</parameter></methodparam> | ||
</methodsynopsis> | ||
<para> | ||
Executa um Bootstrap, todos os métodos definidos no Bootstrap e nomeados com | ||
o prefixo "_init" serão chamados na ordem de suas declarações. Se o parâmetro bootstrap não for informado, Yaf procurará | ||
um Bootstrap no diretório especificado por application.directory. | ||
</para> | ||
|
||
</refsect1> | ||
|
||
<refsect1 role="parameters"> | ||
&reftitle.parameters; | ||
<variablelist> | ||
<varlistentry> | ||
<term><parameter>bootstrap</parameter></term> | ||
<listitem> | ||
<para> | ||
Uma instância de <classname>Yaf_Bootstrap_Abstract</classname>. | ||
</para> | ||
</listitem> | ||
</varlistentry> | ||
</variablelist> | ||
</refsect1> | ||
|
||
<refsect1 role="returnvalues"> | ||
&reftitle.returnvalues; | ||
<para> | ||
Uma instância de <classname>Yaf_Application</classname>. | ||
</para> | ||
</refsect1> | ||
|
||
<refsect1 role="examples"> | ||
&reftitle.examples; | ||
<example> | ||
<title>Um exemplo de Bootstrap</title> | ||
<programlisting role="php"> | ||
<![CDATA[ | ||
<?php | ||
/** | ||
* Este arquivo deve estar no caminho APPLICATION_PATH . "/application/" (que foi definido na configuração passada para Yaf_Application) | ||
* e nomeado como Bootstrap.php, para que o Yaf_Application possa encontrá-lo. | ||
*/ | ||
class Bootstrap extends Yaf_Bootstrap_Abstract { | ||
function _initConfig(Yaf_Dispatcher $dispatcher) { | ||
echo "primeira chamada\n"; | ||
} | ||
function _initPlugin($dispatcher) { | ||
echo "segunda chamada\n"; | ||
} | ||
} | ||
?> | ||
]]> | ||
</programlisting> | ||
</example> | ||
<example> | ||
<title>Exemplo de <function>Yaf_Application::bootstrap</function></title> | ||
<programlisting role="php"> | ||
<![CDATA[ | ||
<?php | ||
defined('APPLICATION_PATH') // APPLICATION_PATH será usado no arquivo de configuração INI | ||
|| define('APPLICATION_PATH', __DIR__); | ||
$application = new Yaf_Application(APPLICATION_PATH . '/conf/application.ini'); | ||
$application->bootstrap(); | ||
?> | ||
]]> | ||
</programlisting> | ||
&example.outputs.similar; | ||
<screen> | ||
<![CDATA[ | ||
primeira chamada | ||
segunda chamada | ||
]]> | ||
</screen> | ||
</example> | ||
</refsect1> | ||
|
||
<refsect1 role="seealso"> | ||
&reftitle.seealso; | ||
<simplelist> | ||
<member><classname>Yaf_Bootstrap_Abstract</classname></member> | ||
</simplelist> | ||
</refsect1> | ||
|
||
</refentry> | ||
|
||
<!-- Keep this comment at the end of the file | ||
Local variables: | ||
mode: sgml | ||
sgml-omittag:t | ||
sgml-shorttag:t | ||
sgml-minimize-attributes:nil | ||
sgml-always-quote-attributes:t | ||
sgml-indent-step:1 | ||
sgml-indent-data:t | ||
indent-tabs-mode:nil | ||
sgml-parent-document:nil | ||
sgml-default-dtd-file:"~/.phpdoc/manual.ced" | ||
sgml-exposed-tags:nil | ||
sgml-local-catalogs:nil | ||
sgml-local-ecat-files:nil | ||
End: | ||
vim600: syn=xml fen fdm=syntax fdl=2 si | ||
vim: et tw=78 syn=sgml | ||
vi: ts=1 sw=1 | ||
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,251 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- EN-Revision: 4a211b7c8fb2b4410851d06c6f90f751d1f670d0 Maintainer: leonardolara Status: ready --> | ||
|
||
<refentry xml:id="yaf-dispatcher.setview" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"> | ||
<refnamediv> | ||
<refname>Yaf_Dispatcher::setView</refname> | ||
<refpurpose>Define um mecanismo de visualização customizado</refpurpose> | ||
</refnamediv> | ||
|
||
<refsect1 role="description"> | ||
&reftitle.description; | ||
<methodsynopsis> | ||
<modifier>public</modifier> <type>Yaf_Dispatcher</type><methodname>Yaf_Dispatcher::setView</methodname> | ||
<methodparam><type>Yaf_View_Interface</type><parameter>view</parameter></methodparam> | ||
</methodsynopsis> | ||
<para> | ||
Este método fornece uma solução se a intenção for usar um mecanismo de visualização | ||
customizado ao invés de um <classname>Yaf_View_Simple</classname>. | ||
</para> | ||
|
||
</refsect1> | ||
|
||
<refsect1 role="parameters"> | ||
&reftitle.parameters; | ||
<variablelist> | ||
<varlistentry> | ||
<term><parameter>view</parameter></term> | ||
<listitem> | ||
<para> | ||
Uma instância de <classname>Yaf_View_Interface</classname>. | ||
</para> | ||
</listitem> | ||
</varlistentry> | ||
</variablelist> | ||
</refsect1> | ||
|
||
<refsect1 role="returnvalues"> | ||
&reftitle.returnvalues; | ||
<para> | ||
|
||
</para> | ||
</refsect1> | ||
|
||
<refsect1 role="examples"> | ||
&reftitle.examples; | ||
<example> | ||
<title>Exemplo de um mecanismo de visualização customizado</title> | ||
<programlisting role="php"> | ||
<![CDATA[ | ||
<?php | ||
require "/path/to/smarty/Smarty.class.php"; | ||
class Smarty_Adapter implements Yaf_View_Interface | ||
{ | ||
/** | ||
* Smarty object | ||
* @var Smarty | ||
*/ | ||
public $_smarty; | ||
/** | ||
* Construtor | ||
* | ||
* @param string $tmplPath | ||
* @param array $extraParams | ||
* @return void | ||
*/ | ||
public function __construct($tmplPath = null, $extraParams = array()) { | ||
$this->_smarty = new Smarty; | ||
if (null !== $tmplPath) { | ||
$this->setScriptPath($tmplPath); | ||
} | ||
foreach ($extraParams as $key => $value) { | ||
$this->_smarty->$key = $value; | ||
} | ||
} | ||
/** | ||
* Define o caminho para os modelos | ||
* | ||
* @param string $path O diretório a ser definido como o caminho. | ||
* @return void | ||
*/ | ||
public function setScriptPath($path) | ||
{ | ||
if (is_readable($path)) { | ||
$this->_smarty->template_dir = $path; | ||
return; | ||
} | ||
throw new Exception('Invalid path provided'); | ||
} | ||
/** | ||
* Atribui uma variável ao modelo | ||
* | ||
* @param string $key O nome da variável. | ||
* @param mixed $val O valor da variável. | ||
* @return void | ||
*/ | ||
public function __set($key, $val) | ||
{ | ||
$this->_smarty->assign($key, $val); | ||
} | ||
/** | ||
* Permite que testes com empty() e isset() funcionem | ||
* | ||
* @param string $key | ||
* @return boolean | ||
*/ | ||
public function __isset($key) | ||
{ | ||
return (null !== $this->_smarty->get_template_vars($key)); | ||
} | ||
/** | ||
* Permite que unset() funcione em propriedade de objeto | ||
* | ||
* @param string $key | ||
* @return void | ||
*/ | ||
public function __unset($key) | ||
{ | ||
$this->_smarty->clear_assign($key); | ||
} | ||
/** | ||
* Atribui variáveis ao modelo | ||
* | ||
* Permite definir uma chave específica ao valor especificado ou passar | ||
* um array de pares de chave => valor para definir em massa. | ||
* | ||
* @see __set() | ||
* @param string|array $spec A estratégia de atribuição a ser usada (chave ou | ||
* array de pares chave => valor) | ||
* @param mixed $value (Opcional) Se uma variável nomeada estiver serndo atribuída, | ||
* será usada como o valor. | ||
* @return void | ||
*/ | ||
public function assign($spec, $value = null) { | ||
if (is_array($spec)) { | ||
$this->_smarty->assign($spec); | ||
return; | ||
} | ||
$this->_smarty->assign($spec, $value); | ||
} | ||
/** | ||
* Limpa todas as variáveis atribuídas | ||
* | ||
* Limpa todas as variáveis atribuídas a Yaf_View via | ||
* {@link assign()} ou via sobrecarga de propriedades | ||
* ({@link __get()}/{@link __set()}). | ||
* | ||
* @return void | ||
*/ | ||
public function clearVars() { | ||
$this->_smarty->clear_all_assign(); | ||
} | ||
/** | ||
* Processa um modelo e retorna a saída. | ||
* | ||
* @param string $name O modelo a ser processado. | ||
* @return string A saída. | ||
*/ | ||
public function render($name, $value = NULL) { | ||
return $this->_smarty->fetch($name); | ||
} | ||
public function display($name, $value = NULL) { | ||
echo $this->_smarty->fetch($name); | ||
} | ||
} | ||
?> | ||
]]> | ||
</programlisting> | ||
</example> | ||
<example> | ||
<title>Exemplo de <function>Yaf_Dispatcher::setView</function></title> | ||
<programlisting role="php"> | ||
<![CDATA[ | ||
<?php | ||
class Bootstrap extends Yaf_Bootstrap_Abstract { | ||
/** | ||
* Algumas configurações para "smarty": | ||
* | ||
* smarty.left_delimiter = "{{" | ||
* smarty.right_delimiter = "}}" | ||
* smarty.template_dir = APPLICATION_PATH "/views/scripts/" | ||
* smarty.compile_dir = APPLICATION_PATH "/views/templates_c/" | ||
* smarty.cache_dir = APPLICATION_PATH "/views/templates_d/" | ||
* | ||
*/ | ||
public function _initConfig() { | ||
$config = Yaf_Application::app()->getConfig(); | ||
Yaf_Registry::set("config", $config); | ||
} | ||
public function _initLocalName() { | ||
/** A classe Smarty_Adapter fica no diretório das bibliotecas locais */ | ||
Yaf_Loader::getInstance()->registerLocalNamespace('Smarty'); | ||
} | ||
public function _initSmarty(Yaf_Dispatcher $dispatcher) { | ||
$smarty = new Smarty_Adapter(null, Yaf_Registry::get("config")->get("smarty")); | ||
$dispatcher->setView($smarty); | ||
/* agora o mecanismo de visualização do Smarty se torna o padrão do Yaf */ | ||
} | ||
} | ||
?> | ||
]]> | ||
</programlisting> | ||
</example> | ||
</refsect1> | ||
|
||
<refsect1 role="seealso"> | ||
&reftitle.seealso; | ||
<simplelist> | ||
<member><classname>Yaf_View_Interface</classname></member> | ||
<member><classname>Yaf_View_Simple</classname></member> | ||
</simplelist> | ||
</refsect1> | ||
</refentry> | ||
|
||
<!-- Keep this comment at the end of the file | ||
Local variables: | ||
mode: sgml | ||
sgml-omittag:t | ||
sgml-shorttag:t | ||
sgml-minimize-attributes:nil | ||
sgml-always-quote-attributes:t | ||
sgml-indent-step:1 | ||
sgml-indent-data:t | ||
indent-tabs-mode:nil | ||
sgml-parent-document:nil | ||
sgml-default-dtd-file:"~/.phpdoc/manual.ced" | ||
sgml-exposed-tags:nil | ||
sgml-local-catalogs:nil | ||
sgml-local-ecat-files:nil | ||
End: | ||
vim600: syn=xml fen fdm=syntax fdl=2 si | ||
vim: et tw=78 syn=sgml | ||
vi: ts=1 sw=1 | ||
--> |
Oops, something went wrong.