Пример #1
0
 /**
  * Gets the current content of a slot, if any.
  * If slot content is null, then raises an event
  * to try to fill the slot. If it is filled,
  * returns the content. Otherwise, returns null.
  * @param string|array $slot_name
  *  The name of the slot.
  * @param boolean $default_slot_name
  *  Optional. If the slot named in $slot_name returns null,
  *  the handler corresponding to the default slot will be called,
  *  passing it the requested slot's name in the 'slot_name' parameter,
  *  and its value will be returned instead.
  *  Note: this does not fill the slot named $default_slot_name!
  *  That is to say, the computed value is not saved, so that
  *  the slot's handler is called again if it is ever consulted again.
  * @param string $prefix
  *  Optional. Sets a prefix for the HTML ids of all the elements in the slot.
  * @return string|null
  */
 static function fillSlot($slot_name, $default_slot_name = null, $prefix = null)
 {
     if (isset(self::$slots[$slot_name])) {
         return self::$slots[$slot_name];
     }
     $prev_slot_name = self::$slotName;
     self::$slotName = $slot_name;
     if (isset($prefix)) {
         Pie_Html::pushIdPrefix($prefix);
     }
     try {
         if (isset($default_slot_name)) {
             if (!Pie::canHandle("pie/response/{$slot_name}")) {
                 $result = Pie::event("pie/response/{$default_slot_name}", compact('slot_name'));
                 if (isset(self::$slots[$slot_name])) {
                     // The slot was already filled, while we were rendering it
                     // so discard the $result and return the slot's contents
                     return self::$slots[$slot_name];
                 }
                 return $result;
             }
         }
         $result = Pie::event("pie/response/{$slot_name}");
     } catch (Exception $e) {
         self::$slotName = $prev_slot_name;
         if (isset($prefix)) {
             Pie_Html::pieIdPrefix();
         }
         throw $e;
     }
     self::$slotName = $prev_slot_name;
     if (isset($prefix)) {
         Pie_Html::pieIdPrefix();
     }
     if (isset(self::$slots[$slot_name])) {
         // The slot was already filled, while we were rendering it
         // so discard the $result and return the slot's contents
         return self::$slots[$slot_name];
     }
     if (isset($result)) {
         self::setSlot($slot_name, $result);
         return $result;
     }
     // Otherwise, render default slot
     if (!isset($default_slot_name)) {
         return null;
     }
     return Pie::event("pie/response/{$default_slot_name}", compact('slot_name'));
 }