Initial Commit
This commit is contained in:
115
database/php/pear/examples/bubbling.php
Normal file
115
database/php/pear/examples/bubbling.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?PHP
|
||||
/**
|
||||
* example that shows how to create event bubbling
|
||||
*
|
||||
* This allows you to create several levels of event handling and you
|
||||
* may post a notification to any of these levels.
|
||||
*
|
||||
* After a notification has been posted on a lower level, it will bubble
|
||||
* up through all other levels.
|
||||
*
|
||||
* @package Event_Dispatcher
|
||||
* @subpackage Examples
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
*/
|
||||
|
||||
/**
|
||||
* load Event_Dispatcher package
|
||||
*/
|
||||
require_once 'Event/Dispatcher.php';
|
||||
|
||||
/**
|
||||
* example sender class
|
||||
*/
|
||||
class sender
|
||||
{
|
||||
var $_dispatcher = null;
|
||||
|
||||
function sender(&$dispatcher)
|
||||
{
|
||||
$this->_dispatcher = &$dispatcher;
|
||||
}
|
||||
|
||||
function foo($bubble = true)
|
||||
{
|
||||
$this->_dispatcher->post($this, 'onFoo', 'Some Info...', true, $bubble);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* example observer
|
||||
*/
|
||||
function receiver1(&$notification)
|
||||
{
|
||||
echo "receiver 1 received notification<br />\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* example observer
|
||||
*/
|
||||
function receiver2(&$notification)
|
||||
{
|
||||
echo "receiver 2 received notification<br />\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* example observer
|
||||
*/
|
||||
function receiver3(&$notification)
|
||||
{
|
||||
echo "receiver 3 received notification<br />\n";
|
||||
}
|
||||
|
||||
// get the different dispatchers
|
||||
$dispatcher1 = &Event_Dispatcher::getInstance();
|
||||
$dispatcher2 = &Event_Dispatcher::getInstance('child');
|
||||
$dispatcher3 = &Event_Dispatcher::getInstance('grandchild');
|
||||
|
||||
// create senders in two different levels
|
||||
$sender1 = &new sender($dispatcher1);
|
||||
$sender2 = &new sender($dispatcher2);
|
||||
|
||||
// build three levels
|
||||
$dispatcher1->addNestedDispatcher($dispatcher2);
|
||||
$dispatcher2->addNestedDispatcher($dispatcher3);
|
||||
|
||||
// add observers in level one and two
|
||||
$dispatcher1->addObserver('receiver1', 'onFoo');
|
||||
$dispatcher2->addObserver('receiver2', 'onFoo');
|
||||
|
||||
// this will bubble up from 1 to 3
|
||||
echo 'sender1->foo()<br />';
|
||||
$sender1->foo();
|
||||
|
||||
// this will not bubble up
|
||||
echo '<br />';
|
||||
echo 'sender1->foo(), but disable bubbling<br />';
|
||||
$sender1->foo(false);
|
||||
|
||||
|
||||
// this will bubble up from 2 to 3
|
||||
echo '<br />';
|
||||
echo 'sender2->foo()<br />';
|
||||
$sender2->foo();
|
||||
|
||||
// This observer will receive the two pending notifications on level 3
|
||||
echo '<br />';
|
||||
echo 'dispatcher3->addObserver()<br />';
|
||||
$dispatcher3->addObserver('receiver3', 'onFoo');
|
||||
|
||||
// remove one level
|
||||
$success = $dispatcher1->removeNestedDispatcher($dispatcher2);
|
||||
if ($success === true) {
|
||||
echo '<br />';
|
||||
echo 'removed nested dispatcher2 from dispatcher1<br />';
|
||||
}
|
||||
|
||||
// this will stay in level 1
|
||||
echo 'sender1->foo()<br />';
|
||||
$sender1->foo();
|
||||
|
||||
// this will bubble up from 2-3
|
||||
echo '<br />';
|
||||
echo 'sender2->foo()<br />';
|
||||
$sender2->foo();
|
||||
?>
|
||||
60
database/php/pear/examples/cancel.php
Normal file
60
database/php/pear/examples/cancel.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?PHP
|
||||
/**
|
||||
* example that shows how to cancel an event
|
||||
*
|
||||
* @package Event_Dispatcher
|
||||
* @subpackage Examples
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
*/
|
||||
|
||||
/**
|
||||
* load Event_Dispatcher package
|
||||
*/
|
||||
require_once 'Event/Dispatcher.php';
|
||||
|
||||
/**
|
||||
* example sender
|
||||
*/
|
||||
class sender
|
||||
{
|
||||
var $_dispatcher = null;
|
||||
|
||||
function sender(&$dispatcher)
|
||||
{
|
||||
$this->_dispatcher = &$dispatcher;
|
||||
}
|
||||
|
||||
function foo()
|
||||
{
|
||||
$this->_dispatcher->post($this, 'onFoo', 'Some Info...');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* example observer
|
||||
*/
|
||||
function receiver1(&$notification)
|
||||
{
|
||||
echo "receiver 1 received notification<br />\n";
|
||||
// the notification will be cancelled and no other observers
|
||||
// will be notified
|
||||
$notification->cancelNotification();
|
||||
}
|
||||
|
||||
/**
|
||||
* example observer
|
||||
*/
|
||||
function receiver2(&$notification)
|
||||
{
|
||||
echo "receiver 2 received notification<br />\n";
|
||||
}
|
||||
|
||||
|
||||
$dispatcher = &Event_Dispatcher::getInstance();
|
||||
$sender = &new sender($dispatcher);
|
||||
|
||||
$dispatcher->addObserver('receiver1', 'onFoo');
|
||||
$dispatcher->addObserver('receiver2', 'onFoo');
|
||||
|
||||
$sender->foo();
|
||||
?>
|
||||
50
database/php/pear/examples/debugging.php
Normal file
50
database/php/pear/examples/debugging.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?PHP
|
||||
/**
|
||||
* example that shows how to cancel an event
|
||||
*
|
||||
* @package Event_Dispatcher
|
||||
* @subpackage Examples
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
*/
|
||||
|
||||
/**
|
||||
* load Event_Dispatcher package
|
||||
*/
|
||||
require_once 'Event/Dispatcher.php';
|
||||
|
||||
/**
|
||||
* example observers
|
||||
*/
|
||||
function receiver1(&$notification)
|
||||
{
|
||||
echo "receiver 1 received notification<br />\n";
|
||||
}
|
||||
|
||||
function receiver2(&$notification)
|
||||
{
|
||||
echo "receiver 2 received notification<br />\n";
|
||||
}
|
||||
|
||||
$dispatcher = &Event_Dispatcher::getInstance();
|
||||
$dispatcher->addObserver('receiver1', 'onFoo', 'TestClass');
|
||||
$dispatcher->addObserver('receiver2', 'onFoo', 'AnotherTestClass');
|
||||
$dispatcher->addObserver('receiver2', 'onBar');
|
||||
|
||||
// Test, whether an observer has been registered
|
||||
$registered = $dispatcher->observerRegistered('receiver1', 'onFoo');
|
||||
if ($registered === true) {
|
||||
echo "Observer successfully registered";
|
||||
}
|
||||
|
||||
$observers = $dispatcher->getObservers('onFoo');
|
||||
echo '<pre>';
|
||||
print_r($observers);
|
||||
echo '</pre>';
|
||||
|
||||
// Filter using a class name
|
||||
$observers = $dispatcher->getObservers('onFoo', 'TestClass');
|
||||
echo '<pre>';
|
||||
print_r($observers);
|
||||
echo '</pre>';
|
||||
|
||||
?>
|
||||
299
database/php/pear/examples/example.php
Normal file
299
database/php/pear/examples/example.php
Normal file
@@ -0,0 +1,299 @@
|
||||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Examples (file #1)
|
||||
*
|
||||
* several examples for the methods of XML_Util
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @category XML
|
||||
* @package XML_Util
|
||||
* @subpackage Examples
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license New BSD License
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/XML_Util
|
||||
*/
|
||||
|
||||
/**
|
||||
* set error level
|
||||
*/
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once 'XML/Util.php';
|
||||
|
||||
/**
|
||||
* replacing XML entities
|
||||
*/
|
||||
print 'replace XML entities:<br>';
|
||||
print XML_Util::replaceEntities('This string contains < & >.');
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* reversing XML entities
|
||||
*/
|
||||
print 'replace XML entities:<br>';
|
||||
print XML_Util::reverseEntities('This string contains < & >.');
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* building XML declaration
|
||||
*/
|
||||
print 'building XML declaration:<br>';
|
||||
print htmlspecialchars(XML_Util::getXMLDeclaration());
|
||||
print "\n<br><br>\n";
|
||||
|
||||
print 'building XML declaration with additional attributes:<br>';
|
||||
print htmlspecialchars(XML_Util::getXMLDeclaration('1.0', 'UTF-8', true));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* building document type declaration
|
||||
*/
|
||||
print 'building DocType declaration:<br>';
|
||||
print htmlspecialchars(XML_Util::getDocTypeDeclaration('package',
|
||||
'http://pear.php.net/dtd/package-1.0'));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
print 'building DocType declaration with public ID (does not exist):<br>';
|
||||
print htmlspecialchars(XML_Util::getDocTypeDeclaration('package',
|
||||
array('uri' => 'http://pear.php.net/dtd/package-1.0',
|
||||
'id' => '-//PHP//PEAR/DTD PACKAGE 0.1')));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
print 'building DocType declaration with internal DTD:<br>';
|
||||
print '<pre>';
|
||||
print htmlspecialchars(XML_Util::getDocTypeDeclaration('package',
|
||||
'http://pear.php.net/dtd/package-1.0',
|
||||
'<!ELEMENT additionalInfo (#PCDATA)>'));
|
||||
print '</pre>';
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating an attribute string
|
||||
*/
|
||||
$att = array(
|
||||
'foo' => 'bar',
|
||||
'argh' => 'tomato'
|
||||
);
|
||||
|
||||
print 'converting array to string:<br>';
|
||||
print XML_Util::attributesToString($att);
|
||||
print "\n<br><br>\n";
|
||||
|
||||
|
||||
/**
|
||||
* creating an attribute string with linebreaks
|
||||
*/
|
||||
$att = array(
|
||||
'foo' => 'bar',
|
||||
'argh' => 'tomato'
|
||||
);
|
||||
|
||||
print 'converting array to string (including line breaks):<br>';
|
||||
print '<pre>';
|
||||
print XML_Util::attributesToString($att, true, true);
|
||||
print '</pre>';
|
||||
print "\n<br><br>\n";
|
||||
|
||||
|
||||
/**
|
||||
* splitting a qualified tag name
|
||||
*/
|
||||
print 'splitting qualified tag name:<br>';
|
||||
print '<pre>';
|
||||
print_r(XML_Util::splitQualifiedName('xslt:stylesheet'));
|
||||
print '</pre>';
|
||||
print "\n<br>\n";
|
||||
|
||||
|
||||
/**
|
||||
* splitting a qualified tag name (no namespace)
|
||||
*/
|
||||
print 'splitting qualified tag name (no namespace):<br>';
|
||||
print '<pre>';
|
||||
print_r(XML_Util::splitQualifiedName('foo'));
|
||||
print '</pre>';
|
||||
print "\n<br>\n";
|
||||
|
||||
/**
|
||||
* splitting a qualified tag name (no namespace, but default namespace specified)
|
||||
*/
|
||||
print 'splitting qualified tag name '
|
||||
. '(no namespace, but default namespace specified):<br>';
|
||||
print '<pre>';
|
||||
print_r(XML_Util::splitQualifiedName('foo', 'bar'));
|
||||
print '</pre>';
|
||||
print "\n<br>\n";
|
||||
|
||||
/**
|
||||
* verifying XML names
|
||||
*/
|
||||
print 'verifying \'My private tag\':<br>';
|
||||
print '<pre>';
|
||||
print_r(XML_Util::isValidname('My Private Tag'));
|
||||
print '</pre>';
|
||||
print "\n<br><br>\n";
|
||||
|
||||
print 'verifying \'-MyTag\':<br>';
|
||||
print '<pre>';
|
||||
print_r(XML_Util::isValidname('-MyTag'));
|
||||
print '</pre>';
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating an XML tag
|
||||
*/
|
||||
$tag = array(
|
||||
'namespace' => 'foo',
|
||||
'localPart' => 'bar',
|
||||
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
|
||||
'content' => 'I\'m inside the tag'
|
||||
);
|
||||
|
||||
print 'creating a tag with namespace and local part:<br>';
|
||||
print htmlentities(XML_Util::createTagFromArray($tag));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating an XML tag
|
||||
*/
|
||||
$tag = array(
|
||||
'qname' => 'foo:bar',
|
||||
'namespaceUri' => 'http://foo.com',
|
||||
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
|
||||
'content' => 'I\'m inside the tag'
|
||||
);
|
||||
|
||||
print 'creating a tag with qualified name and namespaceUri:<br>';
|
||||
print htmlentities(XML_Util::createTagFromArray($tag));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating an XML tag
|
||||
*/
|
||||
$tag = array(
|
||||
'qname' => 'bar',
|
||||
'namespaceUri' => 'http://foo.com',
|
||||
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable')
|
||||
);
|
||||
|
||||
print 'creating an empty tag without namespace but namespace Uri:<br>';
|
||||
print htmlentities(XML_Util::createTagFromArray($tag));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating an XML tag with more namespaces
|
||||
*/
|
||||
$tag = array(
|
||||
'namespace' => 'foo',
|
||||
'localPart' => 'bar',
|
||||
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
|
||||
'content' => 'I\'m inside the tag',
|
||||
'namespaces' => array(
|
||||
'bar' => 'http://bar.com',
|
||||
'pear' => 'http://pear.php.net',
|
||||
)
|
||||
);
|
||||
|
||||
print 'creating an XML tag with more namespaces:<br />';
|
||||
print htmlentities(XML_Util::createTagFromArray($tag));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating an XML tag with a CData Section
|
||||
*/
|
||||
$tag = array(
|
||||
'qname' => 'foo',
|
||||
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
|
||||
'content' => 'I\'m inside the tag'
|
||||
);
|
||||
|
||||
print 'creating a tag with CData section:<br>';
|
||||
print htmlentities(XML_Util::createTagFromArray($tag, XML_UTIL_CDATA_SECTION));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating an XML tag with a CData Section
|
||||
*/
|
||||
$tag = array(
|
||||
'qname' => 'foo',
|
||||
'attributes' => array('key' => 'value', 'argh' => 't<>t<EFBFBD>'),
|
||||
'content' =>
|
||||
'Also XHTML-tags can be created '
|
||||
. 'and HTML entities can be replaced <20> <20> <20> <20> <>.'
|
||||
);
|
||||
|
||||
print 'creating a tag with HTML entities:<br>';
|
||||
print htmlentities(XML_Util::createTagFromArray($tag, XML_UTIL_ENTITIES_HTML));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating an XML tag with createTag
|
||||
*/
|
||||
print 'creating a tag with createTag:<br>';
|
||||
print htmlentities(XML_Util::createTag('myNs:myTag',
|
||||
array('foo' => 'bar'),
|
||||
'This is inside the tag',
|
||||
'http://www.w3c.org/myNs#'));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
|
||||
/**
|
||||
* trying to create an XML tag with an array as content
|
||||
*/
|
||||
$tag = array(
|
||||
'qname' => 'bar',
|
||||
'content' => array('foo' => 'bar')
|
||||
);
|
||||
print 'trying to create an XML tag with an array as content:<br>';
|
||||
print '<pre>';
|
||||
print_r(XML_Util::createTagFromArray($tag));
|
||||
print '</pre>';
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* trying to create an XML tag without a name
|
||||
*/
|
||||
$tag = array(
|
||||
'attributes' => array('foo' => 'bar'),
|
||||
);
|
||||
print 'trying to create an XML tag without a name:<br>';
|
||||
print '<pre>';
|
||||
print_r(XML_Util::createTagFromArray($tag));
|
||||
print '</pre>';
|
||||
print "\n<br><br>\n";
|
||||
?>
|
||||
145
database/php/pear/examples/example2.php
Normal file
145
database/php/pear/examples/example2.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
||||
|
||||
/**
|
||||
* Examples (file #2)
|
||||
*
|
||||
* several examples for the methods of XML_Util
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* LICENSE:
|
||||
*
|
||||
* Copyright (c) 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * 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.
|
||||
* * The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @category XML
|
||||
* @package XML_Util
|
||||
* @subpackage Examples
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
* @copyright 2003-2008 Stephan Schmidt <schst@php.net>
|
||||
* @license http://opensource.org/licenses/bsd-license New BSD License
|
||||
* @version CVS: $Id$
|
||||
* @link http://pear.php.net/package/XML_Util
|
||||
*/
|
||||
|
||||
/**
|
||||
* set error level
|
||||
*/
|
||||
error_reporting(E_ALL);
|
||||
|
||||
require_once 'XML/Util.php';
|
||||
|
||||
/**
|
||||
* creating a start element
|
||||
*/
|
||||
print 'creating a start element:<br>';
|
||||
print htmlentities(XML_Util::createStartElement('myNs:myTag',
|
||||
array('foo' => 'bar'), 'http://www.w3c.org/myNs#'));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
|
||||
/**
|
||||
* creating a start element
|
||||
*/
|
||||
print 'creating a start element:<br>';
|
||||
print htmlentities(XML_Util::createStartElement('myTag',
|
||||
array(), 'http://www.w3c.org/myNs#'));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating a start element
|
||||
*/
|
||||
print 'creating a start element:<br>';
|
||||
print '<pre>';
|
||||
print htmlentities(XML_Util::createStartElement('myTag',
|
||||
array('foo' => 'bar', 'argh' => 'tomato'),
|
||||
'http://www.w3c.org/myNs#', true));
|
||||
print '</pre>';
|
||||
print "\n<br><br>\n";
|
||||
|
||||
|
||||
/**
|
||||
* creating an end element
|
||||
*/
|
||||
print 'creating an end element:<br>';
|
||||
print htmlentities(XML_Util::createEndElement('myNs:myTag'));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating a CData section
|
||||
*/
|
||||
print 'creating a CData section:<br>';
|
||||
print htmlentities(XML_Util::createCDataSection('I am content.'));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating a comment
|
||||
*/
|
||||
print 'creating a comment:<br>';
|
||||
print htmlentities(XML_Util::createComment('I am a comment.'));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* creating an XML tag with multiline mode
|
||||
*/
|
||||
$tag = array(
|
||||
'qname' => 'foo:bar',
|
||||
'namespaceUri' => 'http://foo.com',
|
||||
'attributes' => array('key' => 'value', 'argh' => 'fruit&vegetable'),
|
||||
'content' => 'I\'m inside the tag & contain dangerous chars'
|
||||
);
|
||||
|
||||
print 'creating a tag with qualified name and namespaceUri:<br>';
|
||||
print '<pre>';
|
||||
print htmlentities(XML_Util::createTagFromArray($tag,
|
||||
XML_UTIL_REPLACE_ENTITIES, true));
|
||||
print '</pre>';
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* create an attribute string without replacing the entities
|
||||
*/
|
||||
$atts = array('series' => 'Starsky & Hutch', 'channel' => 'ABC');
|
||||
print 'creating a attribute string, '
|
||||
. 'entities in values already had been replaced:<br>';
|
||||
print htmlentities(XML_Util::attributesToString($atts,
|
||||
true, false, false, false, XML_UTIL_ENTITIES_NONE));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
/**
|
||||
* using the array-syntax for attributesToString()
|
||||
*/
|
||||
$atts = array('series' => 'Starsky & Hutch', 'channel' => 'ABC');
|
||||
print 'using the array-syntax for attributesToString()<br>';
|
||||
print htmlentities(XML_Util::attributesToString($atts,
|
||||
array('entities' => XML_UTIL_ENTITIES_NONE)));
|
||||
print "\n<br><br>\n";
|
||||
|
||||
|
||||
?>
|
||||
76
database/php/pear/examples/notification-class.php
Normal file
76
database/php/pear/examples/notification-class.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?PHP
|
||||
/**
|
||||
* example that shows how to change the class used for notifications
|
||||
*
|
||||
* You may change the notification class per dispatcher or globally for all
|
||||
* newly created dispatchers.
|
||||
*
|
||||
* @package Event_Dispatcher
|
||||
* @subpackage Examples
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
*/
|
||||
|
||||
/**
|
||||
* load Event_Dispatcher package
|
||||
*/
|
||||
require_once 'Event/Dispatcher.php';
|
||||
|
||||
/**
|
||||
* example sender
|
||||
*
|
||||
* @package Event_Dispatcher
|
||||
* @subpackage Examples
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
*/
|
||||
class sender
|
||||
{
|
||||
var $_dispatcher = null;
|
||||
|
||||
function sender(&$dispatcher)
|
||||
{
|
||||
$this->_dispatcher = &$dispatcher;
|
||||
}
|
||||
|
||||
function foo()
|
||||
{
|
||||
$this->_dispatcher->post($this, 'onFoo', 'Some Info...');
|
||||
}
|
||||
}
|
||||
|
||||
function receiver(&$notification)
|
||||
{
|
||||
echo 'received notification: ';
|
||||
echo get_class($notification);
|
||||
echo '<br />';
|
||||
}
|
||||
|
||||
/**
|
||||
* custom notification class
|
||||
*
|
||||
* @package Event_Dispatcher
|
||||
* @subpackage Examples
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
*/
|
||||
class MyNotification extends Event_Notification
|
||||
{
|
||||
}
|
||||
|
||||
$dispatcher = &Event_Dispatcher::getInstance();
|
||||
$dispatcher->setNotificationClass('MyNotification');
|
||||
$sender = &new sender($dispatcher);
|
||||
|
||||
$dispatcher->addObserver('receiver');
|
||||
|
||||
echo 'sender->foo()<br />';
|
||||
$sender->foo();
|
||||
|
||||
Event_Dispatcher::setNotificationClass('MyNotification');
|
||||
|
||||
$dispatcher2 = &Event_Dispatcher::getInstance();
|
||||
$sender2 = &new sender($dispatcher2);
|
||||
|
||||
$dispatcher2->addObserver('receiver');
|
||||
|
||||
echo '<br />sender2->foo()<br />';
|
||||
$sender2->foo();
|
||||
?>
|
||||
63
database/php/pear/examples/object.php
Normal file
63
database/php/pear/examples/object.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?PHP
|
||||
/**
|
||||
* example that show how to use objects as observers without
|
||||
* loosing references
|
||||
*
|
||||
* @package Event_Dispatcher
|
||||
* @subpackage Examples
|
||||
* @author Stephan Schmidt <schst@php.net>
|
||||
*/
|
||||
|
||||
/**
|
||||
* load Event_Dispatcher package
|
||||
*/
|
||||
require_once 'Event/Dispatcher.php';
|
||||
|
||||
/**
|
||||
* example sender
|
||||
*/
|
||||
class sender
|
||||
{
|
||||
var $_dispatcher = null;
|
||||
|
||||
function sender(&$dispatcher)
|
||||
{
|
||||
$this->_dispatcher = &$dispatcher;
|
||||
}
|
||||
|
||||
function foo()
|
||||
{
|
||||
$notification = &$this->_dispatcher->post($this, 'onFoo', 'Some Info...');
|
||||
echo "notification::foo is {$notification->foo}<br />";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* example observer
|
||||
*/
|
||||
class receiver
|
||||
{
|
||||
var $foo;
|
||||
|
||||
function notify(&$notification)
|
||||
{
|
||||
echo "received notification<br />";
|
||||
echo "receiver::foo is {$this->foo}<br />";
|
||||
$notification->foo = 'bar';
|
||||
}
|
||||
}
|
||||
|
||||
$dispatcher = &Event_Dispatcher::getInstance();
|
||||
|
||||
$sender = &new sender($dispatcher);
|
||||
$receiver = new receiver();
|
||||
$receiver->foo = 42;
|
||||
|
||||
// make sure you are using an ampersand here!
|
||||
$dispatcher->addObserver(array(&$receiver, 'notify'));
|
||||
|
||||
$receiver->foo = 'bar';
|
||||
|
||||
echo 'sender->foo()<br />';
|
||||
$sender->foo();
|
||||
?>
|
||||
Reference in New Issue
Block a user