initial commit; version 22.5.12042
This commit is contained in:
165
libs/Fabiang/Xmpp/Event/Event.php
Normal file
165
libs/Fabiang/Xmpp/Event/Event.php
Normal file
@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those
|
||||
* of the authors and should not be interpreted as representing official policies,
|
||||
* either expressed or implied, of the copyright holders.
|
||||
*
|
||||
* @author Fabian Grutschus <f.grutschus@lubyte.de>
|
||||
* @copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
* @license BSD
|
||||
* @link http://github.com/fabiang/xmpp
|
||||
*/
|
||||
|
||||
namespace Fabiang\Xmpp\Event;
|
||||
|
||||
use Fabiang\Xmpp\Exception\OutOfRangeException;
|
||||
use Fabiang\Xmpp\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Generic event.
|
||||
*
|
||||
* @package Xmpp\Event
|
||||
*/
|
||||
class Event implements EventInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Event name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
* Target object.
|
||||
*
|
||||
* @var object
|
||||
*/
|
||||
protected $target;
|
||||
|
||||
/**
|
||||
* Event parameters.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $parameters = array();
|
||||
|
||||
/**
|
||||
* Event stack.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $eventStack = array();
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getTarget()
|
||||
{
|
||||
return $this->target;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getParameters()
|
||||
{
|
||||
return $this->parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = (string) $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setTarget($target)
|
||||
{
|
||||
$this->target = $target;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setParameters(array $parameters)
|
||||
{
|
||||
$this->parameters = array_values($parameters);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getEventStack()
|
||||
{
|
||||
return $this->eventStack;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setEventStack(array $eventStack)
|
||||
{
|
||||
$this->eventStack = $eventStack;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getParameter($index)
|
||||
{
|
||||
$parameters = $this->getParameters();
|
||||
|
||||
if (!is_int($index)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Argument #1 of "' . __CLASS__ . '::' . __METHOD__ . '" must be an integer'
|
||||
);
|
||||
}
|
||||
|
||||
if (!array_key_exists($index, $parameters)) {
|
||||
throw new OutOfRangeException("The offset $index is out of range.");
|
||||
}
|
||||
|
||||
return $parameters[$index];
|
||||
}
|
||||
}
|
114
libs/Fabiang/Xmpp/Event/EventInterface.php
Normal file
114
libs/Fabiang/Xmpp/Event/EventInterface.php
Normal file
@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those
|
||||
* of the authors and should not be interpreted as representing official policies,
|
||||
* either expressed or implied, of the copyright holders.
|
||||
*
|
||||
* @author Fabian Grutschus <f.grutschus@lubyte.de>
|
||||
* @copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
* @license BSD
|
||||
* @link http://github.com/fabiang/xmpp
|
||||
*/
|
||||
|
||||
namespace Fabiang\Xmpp\Event;
|
||||
|
||||
/**
|
||||
* Interface for events.
|
||||
*
|
||||
* @package Xmpp\Event
|
||||
*/
|
||||
interface EventInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Get event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Set event name.
|
||||
*
|
||||
* @param string $name Event name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name);
|
||||
|
||||
/**
|
||||
* Return calling object.
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getTarget();
|
||||
|
||||
/**
|
||||
* Set calling object.
|
||||
*
|
||||
* @param object $target Calling object
|
||||
* @return $this
|
||||
*/
|
||||
public function setTarget($target);
|
||||
|
||||
/**
|
||||
* Return parameters.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParameters();
|
||||
|
||||
/**
|
||||
* Set parameters.
|
||||
*
|
||||
* @param array $parameters Parameters
|
||||
* @return $this
|
||||
*/
|
||||
public function setParameters(array $parameters);
|
||||
|
||||
/**
|
||||
* Get a parameter by index.
|
||||
*
|
||||
* @param integer $index
|
||||
* @retrun mixed
|
||||
*/
|
||||
public function getParameter($index);
|
||||
|
||||
/**
|
||||
* Get list of previous called callbacks.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEventStack();
|
||||
|
||||
/**
|
||||
* Set event stack.
|
||||
*
|
||||
* @param array $stack Event stack
|
||||
* @return $this
|
||||
*/
|
||||
public function setEventStack(array $stack);
|
||||
}
|
160
libs/Fabiang/Xmpp/Event/EventManager.php
Normal file
160
libs/Fabiang/Xmpp/Event/EventManager.php
Normal file
@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those
|
||||
* of the authors and should not be interpreted as representing official policies,
|
||||
* either expressed or implied, of the copyright holders.
|
||||
*
|
||||
* @author Fabian Grutschus <f.grutschus@lubyte.de>
|
||||
* @copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
* @license BSD
|
||||
* @link http://github.com/fabiang/xmpp
|
||||
*/
|
||||
|
||||
namespace Fabiang\Xmpp\Event;
|
||||
|
||||
use Fabiang\Xmpp\Exception\InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Event manager.
|
||||
*
|
||||
* The EventManager holds and triggers events.
|
||||
*
|
||||
* @package Xmpp\Event
|
||||
*/
|
||||
class EventManager implements EventManagerInterface
|
||||
{
|
||||
|
||||
const WILDCARD = '*';
|
||||
|
||||
/**
|
||||
* Attached events.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $events = array(self::WILDCARD => array());
|
||||
|
||||
/**
|
||||
* Event object.
|
||||
*
|
||||
* @var EventInterface
|
||||
*/
|
||||
protected $eventObject;
|
||||
|
||||
/**
|
||||
* Constructor sets default event object.
|
||||
*
|
||||
* @param EventInterface $eventObject Event object
|
||||
*/
|
||||
public function __construct(EventInterface $eventObject = null)
|
||||
{
|
||||
if (null === $eventObject) {
|
||||
$eventObject = new Event;
|
||||
}
|
||||
|
||||
$this->eventObject = $eventObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function attach($event, $callback)
|
||||
{
|
||||
if (!is_callable($callback, true)) {
|
||||
throw new InvalidArgumentException(
|
||||
'Second argument of "' . __CLASS__ . '"::attach must be a valid callback'
|
||||
);
|
||||
}
|
||||
|
||||
if (!isset($this->events[$event])) {
|
||||
$this->events[$event] = array();
|
||||
}
|
||||
|
||||
if (!in_array($callback, $this->events[$event], true)) {
|
||||
$this->events[$event][] = $callback;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function trigger($event, $caller, array $parameters)
|
||||
{
|
||||
if (empty($this->events[$event]) && empty($this->events[self::WILDCARD])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$events = array();
|
||||
if (!empty($this->events[$event])) {
|
||||
$events = $this->events[$event];
|
||||
}
|
||||
|
||||
$callbacks = array_merge($events, $this->events[self::WILDCARD]);
|
||||
$previous = array();
|
||||
|
||||
$eventObject = clone $this->getEventObject();
|
||||
$eventObject->setName($event);
|
||||
$eventObject->setTarget($caller);
|
||||
$eventObject->setParameters($parameters);
|
||||
|
||||
do {
|
||||
$current = array_shift($callbacks);
|
||||
|
||||
call_user_func($current, $eventObject);
|
||||
|
||||
$previous[] = $current;
|
||||
$eventObject = clone $eventObject;
|
||||
$eventObject->setEventStack($previous);
|
||||
} while (count($callbacks) > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getEventObject()
|
||||
{
|
||||
return $this->eventObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setEventObject(EventInterface $eventObject)
|
||||
{
|
||||
$this->eventObject = $eventObject;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return list of events.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getEventList()
|
||||
{
|
||||
return $this->events;
|
||||
}
|
||||
}
|
61
libs/Fabiang/Xmpp/Event/EventManagerAwareInterface.php
Normal file
61
libs/Fabiang/Xmpp/Event/EventManagerAwareInterface.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those
|
||||
* of the authors and should not be interpreted as representing official policies,
|
||||
* either expressed or implied, of the copyright holders.
|
||||
*
|
||||
* @author Fabian Grutschus <f.grutschus@lubyte.de>
|
||||
* @copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
* @license BSD
|
||||
* @link http://github.com/fabiang/xmpp
|
||||
*/
|
||||
|
||||
namespace Fabiang\Xmpp\Event;
|
||||
|
||||
/**
|
||||
* Objects that use an event manager must implement this interface.
|
||||
*
|
||||
* @package Xmpp\Event
|
||||
*/
|
||||
interface EventManagerAwareInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Set event manager.
|
||||
*
|
||||
* @param EventManagerInterface $events Instance of event manager
|
||||
* @return $this
|
||||
*/
|
||||
public function setEventManager(EventManagerInterface $events);
|
||||
|
||||
/**
|
||||
* Get event manager instance.
|
||||
*
|
||||
* @return EventManagerInterface
|
||||
*/
|
||||
public function getEventManager();
|
||||
}
|
81
libs/Fabiang/Xmpp/Event/EventManagerInterface.php
Normal file
81
libs/Fabiang/Xmpp/Event/EventManagerInterface.php
Normal file
@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those
|
||||
* of the authors and should not be interpreted as representing official policies,
|
||||
* either expressed or implied, of the copyright holders.
|
||||
*
|
||||
* @author Fabian Grutschus <f.grutschus@lubyte.de>
|
||||
* @copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
* @license BSD
|
||||
* @link http://github.com/fabiang/xmpp
|
||||
*/
|
||||
|
||||
namespace Fabiang\Xmpp\Event;
|
||||
|
||||
use Fabiang\Xmpp\Event\EventInterface;
|
||||
|
||||
/**
|
||||
* Event manager interface.
|
||||
*
|
||||
* @package Xmpp\Event
|
||||
*/
|
||||
interface EventManagerInterface
|
||||
{
|
||||
/**
|
||||
* Trigger an event.
|
||||
*
|
||||
* @param string $event Name of the event
|
||||
* @param object $caller Triggering object (caller)
|
||||
* @param array $parameters Event parameters
|
||||
* @return void
|
||||
*/
|
||||
public function trigger($event, $caller, array $parameters);
|
||||
|
||||
/**
|
||||
* Attach event.
|
||||
*
|
||||
* @param string $event Name of the event
|
||||
* @param callback $callback Callback that handles the event
|
||||
* @return void
|
||||
*/
|
||||
public function attach($event, /*callback*/ $callback);
|
||||
|
||||
/**
|
||||
* Return event object.
|
||||
*
|
||||
* @return EventInterface
|
||||
*/
|
||||
public function getEventObject();
|
||||
|
||||
/**
|
||||
* Set event object.
|
||||
*
|
||||
* @param EventInterface $eventObject
|
||||
* @return $this
|
||||
*/
|
||||
public function setEventObject(EventInterface $eventObject);
|
||||
}
|
78
libs/Fabiang/Xmpp/Event/XMLEvent.php
Normal file
78
libs/Fabiang/Xmpp/Event/XMLEvent.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those
|
||||
* of the authors and should not be interpreted as representing official policies,
|
||||
* either expressed or implied, of the copyright holders.
|
||||
*
|
||||
* @author Fabian Grutschus <f.grutschus@lubyte.de>
|
||||
* @copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
* @license BSD
|
||||
* @link http://github.com/fabiang/xmpp
|
||||
*/
|
||||
|
||||
namespace Fabiang\Xmpp\Event;
|
||||
|
||||
/**
|
||||
* XML parsing events.
|
||||
*
|
||||
* @package Xmpp\Event
|
||||
*/
|
||||
class XMLEvent extends Event implements XMLEventInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Is start tag event.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $startTag = false;
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function isStartTag()
|
||||
{
|
||||
return $this->startTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function setStartTag($startTag)
|
||||
{
|
||||
$this->startTag = (bool) $startTag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function isEndTag()
|
||||
{
|
||||
return !$this->isStartTag();
|
||||
}
|
||||
}
|
68
libs/Fabiang/Xmpp/Event/XMLEventInterface.php
Normal file
68
libs/Fabiang/Xmpp/Event/XMLEventInterface.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those
|
||||
* of the authors and should not be interpreted as representing official policies,
|
||||
* either expressed or implied, of the copyright holders.
|
||||
*
|
||||
* @author Fabian Grutschus <f.grutschus@lubyte.de>
|
||||
* @copyright 2014 Fabian Grutschus. All rights reserved.
|
||||
* @license BSD
|
||||
* @link http://github.com/fabiang/xmpp
|
||||
*/
|
||||
|
||||
namespace Fabiang\Xmpp\Event;
|
||||
|
||||
/**
|
||||
* INterface for xml events.
|
||||
*
|
||||
* @package Xmpp\Event
|
||||
*/
|
||||
interface XMLEventInterface extends EventInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Is event triggered by a start tag.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isStartTag();
|
||||
|
||||
/**
|
||||
* Set if event triggered by a start tag.
|
||||
*
|
||||
* @param boolean $startTag Flag
|
||||
* @return $this
|
||||
*/
|
||||
public function setStartTag($startTag);
|
||||
|
||||
/**
|
||||
* Was event triggered by end tag of an element?
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEndTag();
|
||||
}
|
Reference in New Issue
Block a user