PageRenderTime 19ms CodeModel.GetById 18ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/log/logger/callback.php

https://bitbucket.org/eternaware/joomus
PHP | 68 lines | 22 code | 5 blank | 41 comment | 2 complexity | c3d9c3f2f0d5bdfdd01d4ad5cc497e25 MD5 | raw file
Possible License(s): LGPL-2.1
 1<?php
 2/**
 3 * @package     Joomla.Platform
 4 * @subpackage  Log
 5 *
 6 * @copyright   Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 7 * @license     GNU General Public License version 2 or later; see LICENSE
 8 */
 9
10defined('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 */
22class JLoggerCallback extends JLogLogger
23{
24	/**
25	 * @var    callback  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::_('JLoggerCallback 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}