Ver Mensaje Individual
  #11 (permalink)  
Antiguo 03/11/2012, 10:09
Avatar de portalmana
portalmana
 
Fecha de Ingreso: septiembre-2007
Ubicación: Montevideo-Uruguay
Mensajes: 633
Antigüedad: 16 años, 7 meses
Puntos: 80
Respuesta: Tener solamente código php 5

Esta es una clase de Zend FramwWork
Código PHP:
Ver original
  1. <?php
  2. /**
  3.  * Zend Framework (http://framework.zend.com/)
  4.  *
  5.  * @link      http://github.com/zendframework/zf2 for the canonical source repository
  6.  * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  7.  * @license   http://framework.zend.com/license/new-bsd New BSD License
  8.  * @package   Zend_View
  9.  */
  10.  
  11. namespace Zend\View;
  12.  
  13. use Zend\EventManager\EventManager;
  14. use Zend\EventManager\EventManagerAwareInterface;
  15. use Zend\EventManager\EventManagerInterface;
  16. use Zend\Stdlib\RequestInterface as Request;
  17. use Zend\Stdlib\ResponseInterface as Response;
  18. use Zend\View\Model\ModelInterface as Model;
  19. use Zend\View\Renderer\RendererInterface as Renderer;
  20. use Zend\View\Renderer\TreeRendererInterface;
  21.  
  22. /**
  23.  * @category   Zend
  24.  * @package    Zend_View
  25.  */
  26. class View implements EventManagerAwareInterface
  27. {
  28.     /**
  29.      * @var EventManagerInterface
  30.      */
  31.     protected $events;
  32.  
  33.     /**
  34.      * @var Request
  35.      */
  36.     protected $request;
  37.  
  38.     /**
  39.      * @var Response
  40.      */
  41.     protected $response;
  42.  
  43.     /**
  44.      * Set MVC request object
  45.      *
  46.      * @param  Request $request
  47.      * @return View
  48.      */
  49.     public function setRequest(Request $request)
  50.     {
  51.         $this->request = $request;
  52.         return $this;
  53.     }
  54.  
  55.     /**
  56.      * Set MVC response object
  57.      *
  58.      * @param  Response $response
  59.      * @return View
  60.      */
  61.     public function setResponse(Response $response)
  62.     {
  63.         $this->response = $response;
  64.         return $this;
  65.     }
  66.  
  67.     /**
  68.      * Get MVC request object
  69.      *
  70.      * @return null|Request
  71.      */
  72.     public function getRequest()
  73.     {
  74.         return $this->request;
  75.     }
  76.  
  77.     /**
  78.      * Get MVC response object
  79.      *
  80.      * @return null|Response
  81.      */
  82.     public function getResponse()
  83.     {
  84.         return $this->response;
  85.     }
  86.  
  87.     /**
  88.      * Set the event manager instance
  89.      *
  90.      * @param  EventManagerInterface $events
  91.      * @return View
  92.      */
  93.     public function setEventManager(EventManagerInterface $events)
  94.     {
  95.         $events->setIdentifiers(array(
  96.             __CLASS__,
  97.             get_called_class(),
  98.         ));
  99.         $this->events = $events;
  100.         return $this;
  101.     }
  102.  
  103.     /**
  104.      * Retrieve the event manager instance
  105.      *
  106.      * Lazy-loads a default instance if none available
  107.      *
  108.      * @return EventManagerInterface
  109.      */
  110.     public function getEventManager()
  111.     {
  112.         if (!$this->events instanceof EventManagerInterface) {
  113.             $this->setEventManager(new EventManager());
  114.         }
  115.         return $this->events;
  116.     }
  117.  
  118.     /**
  119.      * Add a rendering strategy
  120.      *
  121.      * Expects a callable. Strategies should accept a ViewEvent object, and should
  122.      * return a Renderer instance if the strategy is selected.
  123.      *
  124.      * Internally, the callable provided will be subscribed to the "renderer"
  125.      * event, at the priority specified.
  126.      *
  127.      * @param  callable $callable
  128.      * @param  int $priority
  129.      * @return View
  130.      */
  131.     public function addRenderingStrategy($callable, $priority = 1)
  132.     {
  133.         $this->getEventManager()->attach(ViewEvent::EVENT_RENDERER, $callable, $priority);
  134.         return $this;
  135.     }
  136.  
  137.     /**
  138.      * Add a response strategy
  139.      *
  140.      * Expects a callable. Strategies should accept a ViewEvent object. The return
  141.      * value will be ignored.
  142.      *
  143.      * Typical usages for a response strategy are to populate the Response object.
  144.      *
  145.      * Internally, the callable provided will be subscribed to the "response"
  146.      * event, at the priority specified.
  147.      *
  148.      * @param  callable $callable
  149.      * @param  int $priority
  150.      * @return View
  151.      */
  152.     public function addResponseStrategy($callable, $priority = 1)
  153.     {
  154.         $this->getEventManager()->attach(ViewEvent::EVENT_RESPONSE, $callable, $priority);
  155.         return $this;
  156.     }
  157.  
  158.     /**
  159.      * Render the provided model.
  160.      *
  161.      * Internally, the following workflow is used:
  162.      *
  163.      * - Trigger the "renderer" event to select a renderer.
  164.      * - Call the selected renderer with the provided Model
  165.      * - Trigger the "response" event
  166.      *
  167.      * @triggers renderer(ViewEvent)
  168.      * @triggers response(ViewEvent)
  169.      * @param  Model $model
  170.      * @throws Exception\RuntimeException
  171.      * @return void
  172.      */
  173.     public function render(Model $model)
  174.     {
  175.         $event   = $this->getEvent();
  176.         $event->setModel($model);
  177.         $events  = $this->getEventManager();
  178.         $results = $events->trigger(ViewEvent::EVENT_RENDERER, $event, function($result) {
  179.             return ($result instanceof Renderer);
  180.         });
  181.         $renderer = $results->last();
  182.         if (!$renderer instanceof Renderer) {
  183.             throw new Exception\RuntimeException(sprintf(
  184.                 '%s: no renderer selected!',
  185.                 __METHOD__
  186.             ));
  187.         }
  188.  
  189.         // If we have children, render them first, but only if:
  190.         // a) the renderer does not implement TreeRendererInterface, or
  191.         // b) it does, but canRenderTrees() returns false
  192.         if ($model->hasChildren()
  193.             && (!$renderer instanceof TreeRendererInterface
  194.                 || !$renderer->canRenderTrees())
  195.         ) {
  196.             $this->renderChildren($model);
  197.         }
  198.  
  199.         // Reset the model, in case it has changed, and set the renderer
  200.         $event->setModel($model);
  201.         $event->setRenderer($renderer);
  202.  
  203.         $rendered = $renderer->render($model);
  204.  
  205.         // If this is a child model, return the rendered content; do not
  206.         // invoke the response strategy.
  207.         $options = $model->getOptions();
  208.         if (array_key_exists('has_parent', $options) && $options['has_parent']) {
  209.             return $rendered;
  210.         }
  211.  
  212.         $event->setResult($rendered);
  213.  
  214.         $events->trigger(ViewEvent::EVENT_RESPONSE, $event);
  215.     }
  216.  
  217.     /**
  218.      * Loop through children, rendering each
  219.      *
  220.      * @param  Model $model
  221.      * @throws Exception\DomainException
  222.      * @return void
  223.      */
  224.     protected function renderChildren(Model $model)
  225.     {
  226.         foreach ($model as $child) {
  227.             if ($child->terminate()) {
  228.                 throw new Exception\DomainException('Inconsistent state; child view model is marked as terminal');
  229.             }
  230.             $child->setOption('has_parent', true);
  231.             $result  = $this->render($child);
  232.             $child->setOption('has_parent', null);
  233.             $capture = $child->captureTo();
  234.             if (!empty($capture)) {
  235.                 if ($child->isAppend()) {
  236.                     $oldResult=$model->{$capture};
  237.                     $model->setVariable($capture, $oldResult . $result);
  238.                 } else {
  239.                     $model->setVariable($capture, $result);
  240.                 }
  241.             }
  242.         }
  243.     }
  244.  
  245.     /**
  246.      * Create and return ViewEvent used by render()
  247.      *
  248.      * @return ViewEvent
  249.      */
  250.     protected function getEvent()
  251.     {
  252.         $event = new ViewEvent();
  253.         $event->setTarget($this);
  254.         if (null !== ($request = $this->getRequest())) {
  255.             $event->setRequest($request);
  256.         }
  257.         if (null !== ($response = $this->getResponse())) {
  258.             $event->setResponse($response);
  259.         }
  260.         return $event;
  261.     }
  262. }

Estandard de Codificacion

Como puedes ver se usan mayusculas. Tanto en nombre de archivos, clases y variables.

Saludos
__________________
"La imaginación es más importante que el conocimiento. El conocimiento es limitado, mientras que la imaginación no" -- A.Einstein
objetivophp.com,twitter.com/objetivophp