Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
callback.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Platform
4  * @subpackage Log
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE
8  */
9 
10 defined('JPATH_PLATFORM') or die;
11 
12 /**
13  * Joomla! Callback Log class
14  *
15  * This class allows logging to be handled by a callback function.
16  * This allows unprecedented flexibility in the way logging can be handled.
17  *
18  * @package Joomla.Platform
19  * @subpackage Log
20  * @since 12.2
21  */
23 {
24  /**
25  * @var callable The function to call when an entry is added - should return True on success
26  * @since 12.2
27  */
28  protected $callback;
29 
30  /**
31  * Constructor.
32  *
33  * @param array &$options Log object options.
34  *
35  * @since 12.2
36  */
37  public function __construct(array &$options)
38  {
39  // Call the parent constructor.
40  parent::__construct($options);
41 
42  // Throw an exception if there is not a valid callback
43  if (isset($this->options['callback']) && is_callable($this->options['callback']))
44  {
45  $this->callback = $this->options['callback'];
46  }
47  else
48  {
49  throw new JLogException(JText::_('JLogLoggerCallback created without valid callback function.'));
50  }
51  }
52 
53  /**
54  * Method to add an entry to the log.
55  *
56  * @param JLogEntry $entry The log entry object to add to the log.
57  *
58  * @return boolean True on success.
59  *
60  * @since 12.2
61  * @throws LogException
62  */
63  public function addEntry(JLogEntry $entry)
64  {
65  // Pass the log entry to the callback function
66  call_user_func($this->callback, $entry);
67  }
68 }