package.xml 0000664 0001750 0001750 00000040075 12654065536 011321 0 ustar jan jan
Horde_Rdopear.horde.orgRdoRampage Data ObjectsLightweight ORM layerChuck Hagenbuchchuckchuck@horde.orgyes2016-02-022.0.51.2.0stablestableLGPL-2.1
* [jan] Mark PHP 7 as supported.
5.3.08.0.0alpha18.0.0alpha11.7.0Horde_Dbpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Exceptionpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Utilpear.horde.org2.0.03.0.0alpha13.0.0alpha1Horde_Testpear.horde.org2.1.03.0.0alpha13.0.0alpha10.3.00.3.0betabeta2008-03-15LGPL-2.1
Major improvements including inflection, eager or lazy loading of relationships and fields, and more.
1.0.0RC11.0.0betabeta2011-03-22LGPL-2.1
* First release candidate for Horde 4.
1.0.0RC21.0.0betabeta2011-03-29LGPL-2.1
* Second release candidate for Horde 4.
1.0.01.0.0stablestable2011-04-06LGPL-2.1
* First stable release for Horde 4.
1.0.11.0.0stablestable2011-06-01LGPL-2.1
* [jan] Add missing dependency on Horde_Db.
1.1.01.1.0stablestable2011-10-11LGPL-2.1
* [jan] Add Horde_Rdo_Query#distinct() (Request #10535).
1.1.11.1.0stablestable2012-02-22LGPL-2.1
* [rla] Fix issue with retrieving lazy fields (Bug #11012).
1.2.01.2.0stablestable2012-03-20LGPL-2.1
* [jan] Implement ArrayAccess in Horde_Rdo_Base.
* [jan] Fix Horde_Rdo_Exception not extending Horde_Exception.
2.0.0alpha11.2.0alphastable2012-07-05LGPL-2.1
* First alpha release for Horde 5.
2.0.0beta11.2.0betastable2012-07-19LGPL-2.1
* First beta release for Horde 5.
2.0.01.2.0stablestable2012-10-30LGPL-2.1
* First stable release for Horde 5.
2.0.11.2.0stablestable2012-11-19LGPL-2.1
* [mms] Use new Horde_Test layout.
2.0.21.2.0stablestable2013-03-05LGPL-2.1
* [jan] Improve unit tests.
2.0.31.2.0stablestable2015-01-09LGPL-2.1
* [jan] Add Composer definition.
2.0.41.2.0stablestable2015-04-28LGPL-2.1
* [jan] Fix issues with certain locales like Turkish.
2.0.51.2.0stablestable2016-02-02LGPL-2.1
* [jan] Mark PHP 7 as supported.
Horde_Rdo-2.0.5/doc/Horde/Rdo/examples/clotho.data.php 0000664 0001750 0001750 00000002377 12654065536 020575 0 ustar jan jan create(array('item_name' => 'Test Item', 'item_parent' => 0));
echo get_class($item) . "\n";
$item = $im->create(array('item_name' => 'Test Item 2', 'item_parent' => 0));
echo get_class($item) . "\n";
$item = $im->create(array('item_name' => 'Child Item', 'item_parent' => 1));
echo get_class($item) . "\n";
$dep = $dm->create(array('dependency_type' => 'S', 'dependency_lhs_item' => 1, 'dependency_rhs_item' => 2));
echo get_class($dep) . "\n";
$cal = $cm->create(array('calendar_name' => 'Test Calendar', 'calendar_hoursinday' => 8,
'calendar_hoursinweek' => 40, 'calendar_type' => 'weekly', 'calendar_data' => ''));
echo get_class($cal) . "\n";
$res = $rm->create(array('resource_type' => 'M', 'resource_name' => 'Test Resource', 'resource_base_calendar' => 1));
echo get_class($res) . "\n";
$resavail = $ram->create(array('resource_id' => 1, 'availability_date' => 1121404095, 'availability_hours' => 2));
echo get_class($resavail) . "\n";
Horde_Rdo-2.0.5/doc/Horde/Rdo/examples/clotho.mysql.sql 0000664 0001750 0001750 00000003275 12654065536 021037 0 ustar jan jan CREATE TABLE `clotho_calendars` (
`calendar_id` int(11) NOT NULL AUTO_INCREMENT,
`calendar_name` varchar(128) NOT NULL,
`calendar_hoursinday` int(11) NOT NULL,
`calendar_hoursinweek` int(11) NOT NULL,
`calendar_type` varchar(32) NOT NULL,
`calendar_data` text NOT NULL,
PRIMARY KEY (`calendar_id`)
);
CREATE TABLE `clotho_resource_availability` (
`availability_id` int(11) NOT NULL AUTO_INCREMENT,
`resource_id` int(11) NOT NULL,
`availability_date` int(11) NOT NULL,
`availability_hours` decimal(10,0) NOT NULL,
PRIMARY KEY (`availability_id`)
);
CREATE TABLE `clotho_resources` (
`resource_id` int(11) NOT NULL AUTO_INCREMENT,
`resource_type` char(1) NOT NULL,
`resource_name` varchar(128) NOT NULL,
`resource_uid` varchar(64) DEFAULT NULL,
`resource_base_calendar` int(11) NOT NULL,
`resource_start` int(11) DEFAULT NULL,
`resource_finish` int(11) DEFAULT NULL,
PRIMARY KEY (`resource_id`)
);
CREATE TABLE `clotho_wbs_dependencies` (
`dependency_id` int(11) NOT NULL AUTO_INCREMENT,
`dependency_type` char(1) NOT NULL,
`dependency_lhs_item` int(11) NOT NULL,
`dependency_rhs_item` int(11) NOT NULL,
`dependency_duration` varchar(20) DEFAULT NULL,
PRIMARY KEY (`dependency_id`)
);
CREATE TABLE `clotho_wbs_items` (
`item_id` int(11) NOT NULL AUTO_INCREMENT,
`item_name` varchar(128) DEFAULT NULL,
`item_parent` int(11) NOT NULL,
`item_duration` varchar(20) DEFAULT NULL,
`item_start` int(11) DEFAULT NULL,
`item_start_fixed` int(11) NOT NULL,
`item_finish` int(11) DEFAULT NULL,
`item_finish_fixed` int(11) NOT NULL,
PRIMARY KEY (`item_id`)
);
CREATE TABLE `clotho_wbs_resources` (
`item_id` int(11) NOT NULL,
`resource_id` int(11) NOT NULL
);
Horde_Rdo-2.0.5/doc/Horde/Rdo/examples/Clotho.php 0000664 0001750 0001750 00000005353 12654065536 017622 0 ustar jan jan array('type' => Horde_Rdo::ONE_TO_ONE,
'foreignKey' => 'item_parent',
'mapper' => 'ItemMapper'),
);
protected $_lazyRelationships = array(
'resources' => array('type' => Horde_Rdo::MANY_TO_MANY,
'mapper' => 'ResourceMapper',
'through' => 'clotho_wbs_resources'),
);
protected $_table = 'clotho_wbs_items';
}
/**
* Dependencies
*/
class Dependency extends Horde_Rdo_Base
{
}
/**
* Dependency Mapper.
*/
class DependencyMapper extends Horde_Rdo_Mapper
{
protected $_table = 'clotho_wbs_dependencies';
}
/**
* Calendars
*/
class Calendar extends Horde_Rdo_Base
{
}
/**
* Calendar Mapper.
*/
class CalendarMapper extends Horde_Rdo_Mapper
{
protected $_table = 'clotho_calendars';
}
/**
* Resources
*/
class Resource extends Horde_Rdo_Base
{
}
/**
* Resource Mapper.
*/
class ResourceMapper extends Horde_Rdo_Mapper
{
protected $_lazyRelationships = array(
'availabilities' => array('type' => Horde_Rdo::ONE_TO_MANY,
'foreignKey' => 'resource_id',
'mapper' => 'ResourceAvailabilityMapper'),
'items' => array('type' => Horde_Rdo::MANY_TO_MANY,
'mapper' => 'ItemMapper',
'through' => 'clotho_wbs_resources'),
);
protected $_table = 'clotho_resources';
}
/**
* ResourceAvailability
*/
class ResourceAvailability extends Horde_Rdo_Base
{
}
/**
* ResourceAvailability Mapper.
*/
class ResourceAvailabilityMapper extends Horde_Rdo_Mapper
{
protected $_relationships = array(
'resource' => array('type' => Horde_Rdo::MANY_TO_ONE,
'foreignKey' => 'resource_id',
'mapper' => 'ResourceMapper'),
);
protected $_table = 'clotho_resource_availability';
}
Horde_Rdo-2.0.5/doc/Horde/Rdo/examples/conf.php.dist 0000664 0001750 0001750 00000000177 12654065536 020260 0 ustar jan jan ':memory'));
Horde_Rdo-2.0.5/doc/Horde/Rdo/examples/CountTest.php 0000664 0001750 0001750 00000000631 12654065536 020314 0 ustar jan jan appendChild($doc->createElement(get_class($this)));
foreach ($this as $field => $value) {
$f = $root->appendChild($doc->createElement($field));
$f->appendChild($doc->createTextNode($value));
}
return $doc->saveXML();
}
}
$im = new XmlItemMapper($conf['adapter']);
$i = $im->findOne(1);
echo $i->toXml();
Horde_Rdo-2.0.5/doc/Horde/Rdo/examples/RelationshipTest.php 0000664 0001750 0001750 00000003324 12654065536 021667 0 ustar jan jan findOne(3);
echo "({$i->item_id}) {$i->item_name} has parent:\n";
echo " ({$i->parent->item_id}) {$i->parent->item_name}\n";
// one-to-many
$rm = new ResourceMapper($conf['adapter']);
$r = $rm->findOne(1);
echo "Resource ({$r->resource_id}) {$r->resource_name} has " . count($r->availabilities) . " availabilities:\n";
foreach ($r->availabilities as $ra) {
echo ' (' . $ra->availability_id . ') ' . $ra->resource->resource_name . " on " . strftime('%x %X', $ra->availability_date) . " (" . $ra->availability_hours . " hours)\n";
}
// many-to-one
$ram = new ResourceAvailabilityMapper($conf['adapter']);
$ra = $ram->findOne(1);
echo "Resource Availability ({$ra->availability_id}) " . strftime('%x %X', $ra->availability_date) . " has resource:\n";
echo " ({$ra->resource->resource_id}) {$ra->resource->resource_name}\n";
// many-to-many
echo "Listing all Items and their Resources:\n\n";
$im = new ItemMapper($conf['adapter']);
foreach ($im->find() as $i) {
if (count($i->resources)) {
echo " (" . $i->item_id . ") " . $i->item_name . " has resources:\n";
foreach ($i->resources as $r) {
echo ' (' . $r->resource_id . ') ' . $r->resource_name . "\n";
}
}
}
echo "\n\nListing all Resources and their Items:\n\n";
$rm = new ResourceMapper($conf['adapter']);
foreach ($rm->find() as $r) {
if (count($r->items)) {
echo " (" . $r->resource_id . ") " . $r->resource_name . " has items:\n";
foreach ($r->items as $i) {
echo ' (' . $i->item_id . ') ' . $i->item_name . "\n";
}
}
}
Horde_Rdo-2.0.5/doc/Horde/Rdo/examples/Task.php 0000664 0001750 0001750 00000001356 12654065536 017273 0 ustar jan jan count();
echo "# tasks: $count\n";
// List all tasks.
echo "Looking for all tasks:\n";
foreach ($tm->find(Horde_Rdo::FIND_ALL) as $task) {
echo " " . $task->task_name . "\n";
}
// List all of Chuck's tasks.
$chuck = $tm->find(Horde_Rdo::FIND_ALL, array('task_owner' => 'chuck'));
echo "\nChuck's tasks:\n";
foreach ($chuck as $task) {
echo " " . $task->task_name . "\n";
}
Horde_Rdo-2.0.5/doc/Horde/Rdo/examples/User.php 0000664 0001750 0001750 00000003402 12654065536 017301 0 ustar jan jan count();
echo "# users: $userCount\n";
// Get the number of new users in May 2005
//$userCount = $um->count('created > \'2005-05-01\' AND created <= \'2005-05-31\'');
//echo "# new: $userCount\n";
// Check if id 1 exists.
$exists = $um->exists(1);
echo "exists: " . ($exists ? 'yes' : 'no') . "\n";
// Look for Alice
$userTwo = $um->findOne(array('name' => 'Alice'));
if ($userTwo) {
echo "Found Alice: id $userTwo->id\n";
} else {
echo "No Alice found, creating:\n";
// $userOne = $um->create(array('name' => 'Alice', 'phone' => '212-555-6565'));
$userOne = new User(array('name' => 'Alice', 'phone' => '212-555-6565'));
$userOne->setMapper($um);
$userOne->save();
$userOneId = $userOne->id;
echo "Created new user with id: $userOneId\n";
}
// Change the name of the user and save.
if ($userTwo) {
$userTwo->name = 'Bob';
$result = $userTwo->save();
var_dump($result);
}
// List all users.
echo "Looking for all:\n";
foreach ($um->find() as $userOb) {
echo " (" . $userOb->id . ") " . $userOb->name . "\n";
}
// Fetch id 2.
//$user = $um->findOne(2);
// Try to delete it.
//$result = $user->delete();
//var_dump($result);
/*
// $user->billingAddresses is an Iterator.
foreach ($user->billingAddresses as $billingAddress) {
echo $billingAddress->zipCode . "\n";
}
if ($user->favorite) {
echo $user->favorite->name . "\n";
} else {
$user->favorite = new User(array('name' => 'Charles'));
}
*/
Horde_Rdo-2.0.5/doc/Horde/Rdo/examples/users.mysql.sql 0000664 0001750 0001750 00000000321 12654065536 020675 0 ustar jan jan CREATE TABLE users (
id INT(11) auto_increment NOT NULL,
name varchar(255),
favorite_id int(11),
phone varchar(20),
created varchar(10),
updated varchar(10),
PRIMARY KEY (id)
);
Horde_Rdo-2.0.5/doc/Horde/Rdo/examples/users.pgsql.sql 0000664 0001750 0001750 00000000303 12654065536 020656 0 ustar jan jan CREATE TABLE users (
id bigserial NOT NULL,
name varchar(255),
favorite_id integer,
phone varchar(20),
created varchar(10),
updated varchar(10),
PRIMARY KEY (id)
);
Horde_Rdo-2.0.5/doc/Horde/Rdo/examples/users.sqlite.sql 0000664 0001750 0001750 00000000272 12654065536 021036 0 ustar jan jan CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name VARCHAR(255),
favorite_id INTEGER,
phone VARCHAR(20),
created VARCHAR(10),
updated VARCHAR(10)
);
Horde_Rdo-2.0.5/doc/Horde/Rdo/COPYING 0000664 0001750 0001750 00000057646 12654065536 015112 0 ustar jan jan GNU LESSER GENERAL PUBLIC LICENSE
Version 2.1, February 1999
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
[This is the first released version of the Lesser GPL. It also counts
as the successor of the GNU Library Public License, version 2, hence
the version number 2.1.]
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
Licenses are intended to guarantee your freedom to share and change
free software--to make sure the software is free for all its users.
This license, the Lesser General Public License, applies to some
specially designated software packages--typically libraries--of the
Free Software Foundation and other authors who decide to use it. You
can use it too, but we suggest you first think carefully about whether
this license or the ordinary General Public License is the better
strategy to use in any particular case, based on the explanations below.
When we speak of free software, we are referring to freedom of use,
not price. Our General Public Licenses are designed to make sure that
you have the freedom to distribute copies of free software (and charge
for this service if you wish); that you receive source code or can get
it if you want it; that you can change the software and use pieces of
it in new free programs; and that you are informed that you can do
these things.
To protect your rights, we need to make restrictions that forbid
distributors to deny you these rights or to ask you to surrender these
rights. These restrictions translate to certain responsibilities for
you if you distribute copies of the library or if you modify it.
For example, if you distribute copies of the library, whether gratis
or for a fee, you must give the recipients all the rights that we gave
you. You must make sure that they, too, receive or can get the source
code. If you link other code with the library, you must provide
complete object files to the recipients, so that they can relink them
with the library after making changes to the library and recompiling
it. And you must show them these terms so they know their rights.
We protect your rights with a two-step method: (1) we copyright the
library, and (2) we offer you this license, which gives you legal
permission to copy, distribute and/or modify the library.
To protect each distributor, we want to make it very clear that
there is no warranty for the free library. Also, if the library is
modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
restrictive license from a patent holder. Therefore, we insist that
any patent license obtained for a version of the library must be
consistent with the full freedom of use specified in this license.
Most GNU software, including some libraries, is covered by the
ordinary GNU General Public License. This license, the GNU Lesser
General Public License, applies to certain designated libraries, and
is quite different from the ordinary General Public License. We use
this license for certain libraries in order to permit linking those
libraries into non-free programs.
When a program is linked with a library, whether statically or using
a shared library, the combination of the two is legally speaking a
combined work, a derivative of the original library. The ordinary
General Public License therefore permits such linking only if the
entire combination fits its criteria of freedom. The Lesser General
Public License permits more lax criteria for linking other code with
the library.
We call this license the "Lesser" General Public License because it
does Less to protect the user's freedom than the ordinary General
Public License. It also provides other free software developers Less
of an advantage over competing non-free programs. These disadvantages
are the reason we use the ordinary General Public License for many
libraries. However, the Lesser license provides advantages in certain
special circumstances.
For example, on rare occasions, there may be a special need to
encourage the widest possible use of a certain library, so that it becomes
a de-facto standard. To achieve this, non-free programs must be
allowed to use the library. A more frequent case is that a free
library does the same job as widely used non-free libraries. In this
case, there is little to gain by limiting the free library to free
software only, so we use the Lesser General Public License.
In other cases, permission to use a particular library in non-free
programs enables a greater number of people to use a large body of
free software. For example, permission to use the GNU C Library in
non-free programs enables many more people to use the whole GNU
operating system, as well as its variant, the GNU/Linux operating
system.
Although the Lesser General Public License is Less protective of the
users' freedom, it does ensure that the user of a program that is
linked with the Library has the freedom and the wherewithal to run
that program using a modified version of the Library.
The precise terms and conditions for copying, distribution and
modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License Agreement applies to any software library or other
program which contains a notice placed by the copyright holder or
other authorized party saying it may be distributed under the terms of
this Lesser General Public License (also called "this License").
Each licensee is addressed as "you".
A "library" means a collection of software functions and/or data
prepared so as to be conveniently linked with application programs
(which use some of those functions and data) to form executables.
The "Library", below, refers to any such software library or work
which has been distributed under these terms. A "work based on the
Library" means either the Library or any derivative work under
copyright law: that is to say, a work containing the Library or a
portion of it, either verbatim or with modifications and/or translated
straightforwardly into another language. (Hereinafter, translation is
included without limitation in the term "modification".)
"Source code" for a work means the preferred form of the work for
making modifications to it. For a library, complete source code means
all the source code for all modules it contains, plus any associated
interface definition files, plus the scripts used to control compilation
and installation of the library.
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running a program using the Library is not restricted, and output from
such a program is covered only if its contents constitute a work based
on the Library (independent of the use of the Library in a tool for
writing it). Whether that is true depends on what the Library does
and what the program that uses the Library does.
1. You may copy and distribute verbatim copies of the Library's
complete source code as you receive it, in any medium, provided that
you conspicuously and appropriately publish on each copy an
appropriate copyright notice and disclaimer of warranty; keep intact
all the notices that refer to this License and to the absence of any
warranty; and distribute a copy of this License along with the
Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) The modified work must itself be a software library.
b) You must cause the files modified to carry prominent notices
stating that you changed the files and the date of any change.
c) You must cause the whole of the work to be licensed at no
charge to all third parties under the terms of this License.
d) If a facility in the modified Library refers to a function or a
table of data to be supplied by an application program that uses
the facility, other than as an argument passed when the facility
is invoked, then you must make a good faith effort to ensure that,
in the event an application does not supply such function or
table, the facility still operates, and performs whatever part of
its purpose remains meaningful.
(For example, a function in a library to compute square roots has
a purpose that is entirely well-defined independent of the
application. Therefore, Subsection 2d requires that any
application-supplied function or table used by this function must
be optional: if the application does not supply it, the square
root function must still compute square roots.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Library,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Library, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote
it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Library.
In addition, mere aggregation of another work not based on the Library
with the Library (or with a work based on the Library) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may opt to apply the terms of the ordinary GNU General Public
License instead of this License to a given copy of the Library. To do
this, you must alter all the notices that refer to this License, so
that they refer to the ordinary GNU General Public License, version 2,
instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
This option is useful when you wish to copy part of the code of
the Library into a program that is not a library.
4. You may copy and distribute the Library (or a portion or
derivative of it, under Section 2) in object code or executable form
under the terms of Sections 1 and 2 above provided that you accompany
it with the complete corresponding machine-readable source code, which
must be distributed under the terms of Sections 1 and 2 above on a
medium customarily used for software interchange.
If distribution of object code is made by offering access to copy
from a designated place, then offering equivalent access to copy the
source code from the same place satisfies the requirement to
distribute the source code, even though third parties are not
compelled to copy the source along with the object code.
5. A program that contains no derivative of any portion of the
Library, but is designed to work with the Library by being compiled or
linked with it, is called a "work that uses the Library". Such a
work, in isolation, is not a derivative work of the Library, and
therefore falls outside the scope of this License.
However, linking a "work that uses the Library" with the Library
creates an executable that is a derivative of the Library (because it
contains portions of the Library), rather than a "work that uses the
library". The executable is therefore covered by this License.
Section 6 states terms for distribution of such executables.
When a "work that uses the Library" uses material from a header file
that is part of the Library, the object code for the work may be a
derivative work of the Library even though the source code is not.
Whether this is true is especially significant if the work can be
linked without the Library, or if the work is itself a library. The
threshold for this to be true is not precisely defined by law.
If such an object file uses only numerical parameters, data
structure layouts and accessors, and small macros and small inline
functions (ten lines or less in length), then the use of the object
file is unrestricted, regardless of whether it is legally a derivative
work. (Executables containing this object code plus portions of the
Library will still fall under Section 6.)
Otherwise, if the work is a derivative of the Library, you may
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
under terms of your choice, provided that the terms permit
modification of the work for the customer's own use and reverse
engineering for debugging such modifications.
You must give prominent notice with each copy of the work that the
Library is used in it and that the Library and its use are covered by
this License. You must supply a copy of this License. If the work
during execution displays copyright notices, you must include the
copyright notice for the Library among them, as well as a reference
directing the user to the copy of this License. Also, you must do one
of these things:
a) Accompany the work with the complete corresponding
machine-readable source code for the Library including whatever
changes were used in the work (which must be distributed under
Sections 1 and 2 above); and, if the work is an executable linked
with the Library, with the complete machine-readable "work that
uses the Library", as object code and/or source code, so that the
user can modify the Library and then relink to produce a modified
executable containing the modified Library. (It is understood
that the user who changes the contents of definitions files in the
Library will not necessarily be able to recompile the application
to use the modified definitions.)
b) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (1) uses at run time a
copy of the library already present on the user's computer system,
rather than copying library functions into the executable, and (2)
will operate properly with a modified version of the library, if
the user installs one, as long as the modified version is
interface-compatible with the version that the work was made with.
c) Accompany the work with a written offer, valid for at
least three years, to give the same user the materials
specified in Subsection 6a, above, for a charge no more
than the cost of performing this distribution.
d) If distribution of the work is made by offering access to copy
from a designated place, offer equivalent access to copy the above
specified materials from the same place.
e) Verify that the user has already received a copy of these
materials or that you have already sent this user a copy.
For an executable, the required form of the "work that uses the
Library" must include any data and utility programs needed for
reproducing the executable from it. However, as a special exception,
the materials to be distributed need not include anything that is
normally distributed (in either source or binary form) with the major
components (compiler, kernel, and so on) of the operating system on
which the executable runs, unless that component itself accompanies
the executable.
It may happen that this requirement contradicts the license
restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
library, provided that the separate distribution of the work based on
the Library and of the other library facilities is otherwise
permitted, and provided that you do these two things:
a) Accompany the combined library with a copy of the same work
based on the Library, uncombined with any other library
facilities. This must be distributed under the terms of the
Sections above.
b) Give prominent notice with the combined library of the fact
that part of it is a work based on the Library, and explaining
where to find the accompanying uncombined form of the same work.
8. You may not copy, modify, sublicense, link with, or distribute
the Library except as expressly provided under this License. Any
attempt otherwise to copy, modify, sublicense, link with, or
distribute the Library is void, and will automatically terminate your
rights under this License. However, parties who have received copies,
or rights, from you under this License will not have their licenses
terminated so long as such parties remain in full compliance.
9. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Library or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Library (or any work based on the
Library), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Library or works based on it.
10. Each time you redistribute the Library (or any work based on the
Library), the recipient automatically receives a license from the
original licensor to copy, distribute, link with or modify the Library
subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Library at all. For example, if a patent
license would not permit royalty-free redistribution of the Library by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Library.
If any portion of this section is held invalid or unenforceable under any
particular circumstance, the balance of the section is intended to apply,
and the section as a whole is intended to apply in other circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
12. If the distribution and/or use of the Library is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Library under this License may add
an explicit geographical distribution limitation excluding those countries,
so that distribution is permitted only in or among countries not thus
excluded. In such case, this License incorporates the limitation as if
written in the body of this License.
13. The Free Software Foundation may publish revised and/or new
versions of the Lesser General Public License from time to time.
Such new versions will be similar in spirit to the present version,
but may differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the Library
specifies a version number of this License which applies to it and
"any later version", you have the option of following the terms and
conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
copyrighted by the Free Software Foundation, write to the Free
Software Foundation; we sometimes make exceptions for this. Our
decision will be guided by the two goals of preserving the free status
of all derivatives of our free software and of promoting the sharing
and reuse of software generally.
NO WARRANTY
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
Horde_Rdo-2.0.5/doc/Horde/Rdo/TODO 0000664 0001750 0001750 00000013162 12654065536 014530 0 ustar jan jan - Add query logging/profiling (also something like
http://blog.talbott.ws/articles/2006/05/17/querytrace-my-first-official-rails-plugin
?)
- Remove Horde_Rdo::CUSTOM, allow custom 'query' arrays on all
relationships as possible, and have a new type (not relationships,
but mixins? extra_fields? that can be defined by a Query and that
allows the flexibility of CUSTOM without being smooshed into
relationships.
- Allow Horde_Rdo_Query objects to be turned into just WHERE (or JOIN)
clauses
- Allow relationships to be defined by Query objects?
- allow for using php.ini-set database configs for security, or perhaps
$ENV variables - see Ilia's security presentation. Example php.ini dsn:
[PDO]
pdo.dsn.MYDB="odbc:SAMPLE"
- Ensure that Rdo_Base objects are serializable
- Charset support: support a database charset config parameter, and
convert field values to the requested client charset.
- Implement named queries
(http://www.tonybibbs.com/article.php/PropelDAO)
- Support composite primary keys. Discussion of surragate vs. natural
primary keys: http://www.bcarter.com/intsurr1.htm
- Saving arrays, hashes, and other non-mappable objects in text
columns ?
- Allow setting $key field explicitly (not just by overriding the
model)
- Some check for whether or not an object is new (has been saved to
the backend yet)?
- Freezing: implement $frozen variable for Rdo objects for when the
object has been deleted, or similar?
- Caching hooks - not required, but allow caching of models, query
generation, etc. with a passed-in Cache object.
- Work on the basic Horde_Support_Inflector enough that it supports
standard Horde table naming.
- Use fetchObject (at least in PDO drivers) for performance?
- Eager loading of MANY relationships - see
http://darwinweb.net/article/Optimizing_And_Simplifying_Limited_Eager_Loading_In_Activerecord
- Two-query eager loading of a specific relationship (load the main
object in one query, then all foreign-key objects in a 2nd, and join
the two.
- Implement eager loading with several relationships to the same table.
- Observer hooks: beforeDelete, afterDelete, beforeUpdate, afterUpdate, beforeCreate, afterCreate
- Support fixtures (YAML?) for testing
- Test suite for Rdo:
http://www.ds-o.com/archives/64-Adding-Database-Tests-to-Existing-PHPUnit-Test-Cases.html
http://mikenaberezny.com/archives/79
http://www.phpunit.de/browser/phpunit/branches/3.2/PHPUnit/Extensions/Database/Operation
Links:
http://www.analysisandsolutions.com/code/dates.htm
http://www.qcodo.com/
http://dev.mysql.com/doc/refman/5.0/en/example-maximum-column-group-row.html
http://www.phpdoctrine.com/
http://www.artfulsoftware.com/mysqlbook/sampler/mysqled1ch20.html
http://www.analysisandsolutions.com/presentations/portability/slides/toc.htm
http://fuzzyblog.com/archives/2006/08/12/sql_calc_found_rows-and-faster-count-alternatives/
http://phplens.com/phpeverywhere/?q=node/view/231
http://pooteeweet.org/blog/688
http://pooteeweet.org/blog/711
http://pooteeweet.org/blog/809
http://schlitt.info/applications/blog/?/archives/528-Object-relation-mapping-in-eZ-Components.html
http://nubyonrails.com/articles/2005/12/27/dump-or-slurp-yaml-reference-data
http://db.apache.org/ddlutils/
http://www.thespanner.co.uk/2007/07/23/php-mysql-tips/
http://www.sqlalchemy.org/
things that can be specified on relationships:
className - only if it can't be inferred from the field name
foreignKey - also if can't be inferred
criteria - restrict associations by more than foreign keys
dependent - if true, associated object is destroyed when main object is
order - of associated objects?
- cascading deletes/updates: ?
- Single table inheritance ?
::
class Company extends Rdo
class Firm extends Company
class Client extends Company
class PriorityClient extends Client
CREATE TABLE companies (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
client_of int(11),
name varchar(255),
type varchar(100),
PRIMARY KEY (id)
);
CREATE TABLE people (
id int(11) unsigned NOT NULL AUTO_INCREMENT,
name text,
company_id text,
PRIMARY KEY (id)
);
potential field parameters:
size
maxsize
fixedsize
numeric
null
canbenull
default
canhavedefault
unsigned
canbeunsigned
realname
description
type
base
>> Here I disagree. To me the key point of a DBAL compared to just a DBL (database layer) is that it provides almost everything necessary to manually build portable SQL. This means that instead of passing of an array that magically builds my SQL, the user remains in the driver seat and is provided with a rich enough API to build almost everything in the SQL spec (and a bit beyond that) in a portable manner.
> What you want to say is that a DBAL must additionally provide:
> a Query Builder, maybe extendable by the driver to provide RDBMS specific options/methods
no .. not a query builder .. that would imply that you just pass of some data and it magically constructs the entire SQL for you .. that is the job for some OO<->SQL tool. what I think a DBAL should provide is methods to generate pieces of SQL that are then assembled by the user.
so for example setLimit() would either return or automatically append to an supplied SQL string. same applies to field abstraction, you still call quote() to get the necessary SQL fragment to embedd in your SQL statement.
Pierre Minnieur wrote:
> Must a DBAL then provide OO access to executed statements, prepared statements and results sets, too (like PDO does)?
absolutely .. a DBAL also needs to cover the reading part. so you need to have a portable way to read data from the database (including data type abstraction, handling of trimming off empty spaces etc).
Horde_Rdo-2.0.5/lib/Horde/Rdo/Query/Literal.php 0000664 0001750 0001750 00000002112 12654065536 017244 0 ustar jan jan _string = (string)$string;
}
/**
* @return string The SQL literal stored in this object.
*/
public function __toString()
{
return $this->_string;
}
}
Horde_Rdo-2.0.5/lib/Horde/Rdo/Base.php 0000664 0001750 0001750 00000033606 12654065536 015431 0 ustar jan jan setFields($fields);
}
/**
* When Rdo objects are cloned, unset the unique id that
* identifies them so that they can be modified and saved to the
* backend as new objects. If you don't really want a new object,
* don't clone.
*/
public function __clone()
{
// @TODO Support composite primary keys
unset($this->{$this->getMapper()->primaryKey});
// @TODO What about associated objects?
}
/**
* Fetch fields that haven't yet been loaded. Lazy-loaded fields
* and lazy-loaded relationships are handled this way. Once a
* field is retrieved, it is cached in the $_fields array so it
* doesn't need to be fetched again.
*
* @param string $field The name of the field to access.
*
* @return mixed The value of $field or null.
*/
public function __get($field)
{
// Honor any explicit getters.
$fieldMethod = 'get' . Horde_String::ucfirst($field);
// If an Rdo_Base subclass has a __call() method, is_callable
// returns true on every method name, so use method_exists
// instead.
if (method_exists($this, $fieldMethod)) {
return call_user_func(array($this, $fieldMethod));
}
if (isset($this->_fields[$field])) {
return $this->_fields[$field];
}
$mapper = $this->getMapper();
// Look for lazy fields first, then relationships.
if (in_array($field, $mapper->lazyFields)) {
// @TODO Support composite primary keys
$query = new Horde_Rdo_Query($mapper);
$query->setFields($field)
->addTest($mapper->primaryKey, '=', $this->{$mapper->primaryKey});
list($sql, $params) = $query->getQuery();
$this->_fields[$field] = $mapper->adapter->selectValue($sql, $params);;
return $this->_fields[$field];
} elseif (isset($mapper->lazyRelationships[$field])) {
$rel = $mapper->lazyRelationships[$field];
} else {
return null;
}
// Try to find the Mapper class for the object the
// relationship is with, and fail if we can't.
if (isset($rel['mapper'])) {
if ($mapper->factory) {
$m = $mapper->factory->create($rel['mapper']);
} else {
// @TODO - should be getting this instance from somewhere
// else external, and not passing the adapter along
// automatically.
$m = new $rel['mapper']($mapper->adapter);
}
} else {
$m = $mapper->tableToMapper($field);
if (is_null($m)) {
return null;
}
}
// Based on the kind of relationship, fetch the appropriate
// objects and fill the cache.
switch ($rel['type']) {
case Horde_Rdo::ONE_TO_ONE:
case Horde_Rdo::MANY_TO_ONE:
if (isset($rel['query'])) {
$query = $this->_fillPlaceholders($rel['query']);
$this->_fields[$field] = $m->findOne($query);
} elseif (!empty($this->{$rel['foreignKey']})) {
$this->_fields[$field] = $m->findOne($this->{$rel['foreignKey']});
if (empty($this->_fields[$field])) {
throw new Horde_Rdo_Exception('The referenced object with key ' . $this->{$rel['foreignKey']} . ' does not exist. Your data is inconsistent');
}
} else {
$this->_fields[$field] = null;
}
break;
case Horde_Rdo::ONE_TO_MANY:
$this->_fields[$field] = $m->find(array($rel['foreignKey'] => $this->{$rel['foreignKey']}));
break;
case Horde_Rdo::MANY_TO_MANY:
$key = $mapper->primaryKey;
$query = new Horde_Rdo_Query();
$on = isset($rel['on']) ? $rel['on'] : $m->primaryKey;
$query->addRelationship($field, array('mapper' => $mapper,
'table' => $rel['through'],
'type' => Horde_Rdo::MANY_TO_MANY,
'query' => array("$m->table.$on" => new Horde_Rdo_Query_Literal($rel['through'] . '.' . $on), $key => $this->$key)));
$this->_fields[$field] = $m->find($query);
break;
}
return $this->_fields[$field];
}
/**
* Implements getter for ArrayAccess interface.
*
* @see __get()
*/
public function offsetGet($field)
{
return $this->__get($field);
}
/**
* Set a field's value.
*
* @param string $field The field to set
* @param mixed $value The field's new value
*/
public function __set($field, $value)
{
// Honor any explicit setters.
$fieldMethod = 'set' . Horde_String::ucfirst($field);
// If an Rdo_Base subclass has a __call() method, is_callable
// returns true on every method name, so use method_exists
// instead.
if (method_exists($this, $fieldMethod)) {
return call_user_func(array($this, $fieldMethod), $value);
}
$this->_fields[$field] = $value;
}
/**
* Implements setter for ArrayAccess interface.
*
* @see __set()
*/
public function offsetSet($field, $value)
{
$this->__set($field, $value);
}
/**
* Allow using isset($rdo->foo) to check for field or
* relationship presence.
*
* @param string $field The field name to check existence of.
*/
public function __isset($field)
{
$m = $this->getMapper();
return isset($this->_fields[$field])
|| isset($m->fields[$field])
|| isset($m->lazyFields[$field])
|| isset($m->relationships[$field])
|| isset($m->lazyRelationships[$field]);
}
/**
* Implements isset() for ArrayAccess interface.
*
* @see __isset()
*/
public function offsetExists($field)
{
return $this->__isset($field);
}
/**
* Allow using unset($rdo->foo) to unset a basic
* field. Relationships cannot be unset in this way.
*
* @param string $field The field name to unset.
*/
public function __unset($field)
{
// @TODO Should unsetting a MANY_TO_MANY relationship remove
// the relationship?
unset($this->_fields[$field]);
}
/**
* Implements unset() for ArrayAccess interface.
*
* @see __unset()
*/
public function offsetUnset($field)
{
$this->__unset($field);
}
/**
* Set field values for the object
*
* @param array $fields Initial values for the new object.
*
* @see Horde_Rdo_Mapper::map()
*/
public function setFields($fields = array())
{
$this->_fields = $fields;
}
/**
* Implement the IteratorAggregate interface. Looping over an Rdo
* object goes through each property of the object in turn.
*
* @return Horde_Rdo_Iterator The Iterator instance.
*/
public function getIterator()
{
return new Horde_Rdo_Iterator($this);
}
/**
* Get a Mapper instance that can be used to manage this
* object. The Mapper instance can come from a few places:
*
* - If the class Mapper exists, it will be used
* automatically.
*
* - Any Rdo instance created with Horde_Rdo_Mapper::map() will have a
* $mapper object set automatically.
*
* - Subclasses can override getMapper() to return the correct
* mapper object.
*
* - The programmer can call $rdoObject->setMapper($mapper) to provide a
* mapper object.
*
* A Horde_Rdo_Exception will be thrown if none of these
* conditions are met.
*
* @return Horde_Rdo_Mapper The Mapper instance managing this object.
*/
public function getMapper()
{
if (!$this->_mapper) {
$class = get_class($this) . 'Mapper';
if (class_exists($class)) {
$this->_mapper = new $class();
} else {
throw new Horde_Rdo_Exception('No Horde_Rdo_Mapper object found. Override getMapper() or define the ' . get_class($this) . 'Mapper class.');
}
}
return $this->_mapper;
}
/**
* Associate this Rdo object with the Mapper instance that will
* manage it. Called automatically by Horde_Rdo_Mapper:map().
*
* @param Horde_Rdo_Mapper $mapper The Mapper to manage this Rdo object.
*
* @see Horde_Rdo_Mapper::map()
*/
public function setMapper($mapper)
{
$this->_mapper = $mapper;
}
/**
* Adds a relation to one of the relationships defined in the mapper.
*
* - For one-to-one relations, simply updates the relation field.
* - For one-to-many relations, updates the related object's relation field.
* - For many-to-many relations, adds an entry in the "through" table.
* - Performs a no-op if the peer is already related.
*
* This is a proxy to the mapper's addRelation() method.
*
* @param string $relationship The relationship key in the mapper.
* @param Horde_Rdo_Base $peer The object to add the relation.
*
* @throws Horde_Rdo_Exception
*/
public function addRelation($relationship, Horde_Rdo_Base $peer)
{
$this->mapper->addRelation($relationship, $this, $peer);
}
/**
* Checks whether a relation to a peer is defined through one of the
* relationships in the mapper.
*
* @param string $relationship The relationship key in the mapper.
* @param Horde_Rdo_Base $peer The object to check for the relation.
* If this is null, check if there is any peer
* for this relation.
*
* @return boolean True if related.
* @throws Horde_Rdo_Exception
*/
public function hasRelation($relationship, Horde_Rdo_Base $peer = null)
{
$mapper = $this->getMapper();
if (isset($mapper->relationships[$relationship])) {
$rel = $mapper->relationships[$relationship];
} elseif (isset($mapper->lazyRelationships[$relationship])) {
$rel = $mapper->lazyRelationships[$relationship];
} else {
throw new Horde_Rdo_Exception('The requested relation is not defined in the mapper');
}
$result = $this->$relationship;
switch ($rel['type']) {
case Horde_Rdo::ONE_TO_ONE:
case Horde_Rdo::MANY_TO_ONE:
if (empty($peer) || empty($result)) {
return (bool) $result;
}
$key = $result->mapper->primaryKey;
return $result->$key == $peer->$key;
case Horde_Rdo::ONE_TO_MANY:
case Horde_Rdo::MANY_TO_MANY:
if (empty($peer)) {
return (bool) count($result);
}
$key = $peer->mapper->primaryKey;
foreach ($result as $item) {
if ($item->$key == $peer->$key) {
return true;
}
}
break;
}
return false;
}
/**
* Removes a relation to one of the relationships defined in the mapper.
*
* - For one-to-one and one-to-many relations, simply sets the relation
* field to 0.
* - For many-to-many, either deletes all relations to this object or just
* the relation to a given peer object.
* - Performs a no-op if the peer is already unrelated.
*
* This is a proxy to the mapper's removeRelation method.
*
* @param string $relationship The relationship key in the mapper
* @param Horde_Rdo_Base $peer The object to remove from the relation
* @return integer The number of relations affected
* @throws Horde_Rdo_Exception
*/
public function removeRelation($relationship, Horde_Rdo_Base $peer = null)
{
return $this->mapper->removeRelation($relationship, $this, $peer);
}
/**
* Save any changes to the backend.
*
* @return boolean Success.
*/
public function save()
{
return $this->getMapper()->update($this) == 1;
}
/**
* Delete this object from the backend.
*
* @return boolean Success or failure.
*/
public function delete()
{
return $this->getMapper()->delete($this) == 1;
}
/**
* Take a query array and replace @field@ placeholders with values
* from this object.
*
* @param array $query The query to process placeholders on.
*
* @return array The query with placeholders filled in.
*/
protected function _fillPlaceholders($query)
{
foreach (array_keys($query) as $field) {
$value = $query[$field];
if (preg_match('/^@(.*)@$/', $value, $matches)) {
$query[$field] = $this->{$matches[1]};
}
}
return $query;
}
}
Horde_Rdo-2.0.5/lib/Horde/Rdo/Exception.php 0000664 0001750 0001750 00000000235 12654065536 016505 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL
*/
/**
* The Horde_Rdo_Factory is a caching root object for Horde_Rdo_Mapper instances
* This should itself be injected into applications by an injector
*
* @category Horde
* @package Rdo
*/
class Horde_Rdo_Factory
{
/**
* The list of already loaded Horde_Rdo_Mapper classes
* @var array
*/
protected $_mappers = array();
/**
* The database connection to pass to the Horde_Rdo_Mapper classes
* @var Horde_Db_Adapter
*/
protected $_adapter;
/**
* Constructor.
*
* @param Horde_Db_Adapter $adapter A database adapter.
* @return Horde_Rdo_Factory The Horde_Rdo_Factory
*/
public function __construct(Horde_Db_Adapter $adapter)
{
$this->_adapter = $adapter;
}
/**
* Counts the number of cached mappers.
*
* @return integer The number of cached mappers.
*/
public function count()
{
return count($this->_mappers);
}
/**
* Return the mapper instance.
*
* @param string $class The mapper class.
* @param Horde_Db_Adapter $adapter A database adapter.
*
* @return Horde_Rdo_Mapper The Horde_Rdo_Mapper descendant instance.
* @throws Horde_Rdo_Exception
*/
public function create($class, Horde_Db_Adapter $adapter = null)
{
if (!empty($this->_mappers[$class])) {
return $this->_mappers[$class];
}
if (!class_exists($class)) {
throw new Horde_Rdo_Exception(sprintf('Class %s not found', $class));
}
if (!$adapter) {
$adapter = $this->_adapter;
}
$this->_mappers[$class] = new $class($adapter);
return $this->_mappers[$class]->setFactory($this);
}
}
Horde_Rdo-2.0.5/lib/Horde/Rdo/Iterator.php 0000664 0001750 0001750 00000004065 12654065536 016345 0 ustar jan jan _rdo = $rdo;
$m = $rdo->getMapper();
$this->_keys = array_merge($m->fields,
$m->lazyFields,
array_keys($m->relationships),
array_keys($m->lazyRelationships));
}
/**
* Reset to the first key.
*/
public function rewind()
{
$this->_valid = (false !== reset($this->_keys));
}
/**
* Return the current value.
*
* @return mixed The current value
*/
public function current()
{
$key = $this->key();
return $this->_rdo->$key;
}
/**
* Return the current key.
*
* @return mixed The current key
*/
public function key()
{
return current($this->_keys);
}
/**
* Move to the next key in the iterator.
*/
public function next()
{
$this->_valid = (false !== next($this->_keys));
}
/**
* Check array bounds.
*
* @return boolean Inside array bounds?
*/
public function valid()
{
return $this->_valid;
}
}
Horde_Rdo-2.0.5/lib/Horde/Rdo/List.php 0000664 0001750 0001750 00000016135 12654065536 015470 0 ustar jan jan mapper) {
throw new Horde_Rdo_Exception('Mapper must be set on the Query object or explicitly passed.');
}
$mapper = $query->mapper;
}
// Convert the query into a SQL statement and an array of
// bind parameters.
list($this->_sql, $this->_bindParams) = $query->getQuery();
} elseif (is_string($query)) {
// Straight SQL query, empty bind parameters array.
$this->_sql = $query;
$this->_bindParams = array();
} else {
// $query is already an array with SQL and bind parameters.
list($this->_sql, $this->_bindParams) = $query;
}
if (!$mapper) {
throw new Horde_Rdo_Exception('Mapper must be provided either explicitly or in a Query object');
}
$this->_query = $query;
$this->_mapper = $mapper;
}
/**
* Destructor - release any resources.
*/
public function __destruct()
{
if ($this->_result) {
unset($this->_result);
}
}
/**
* Implementation of the rewind() method for iterator.
*/
public function rewind()
{
if ($this->_result) {
unset($this->_result);
}
$this->_current = null;
$this->_index = null;
$this->_eof = true;
$this->_result = $this->_mapper->adapter->select($this->_sql, $this->_bindParams);
$this->next();
}
/**
* Implementation of the current() method for iterator.
*
* @return mixed The current row, or null if no rows.
*/
public function current()
{
if (is_null($this->_result)) {
$this->rewind();
}
return $this->_current;
}
/**
* Implementation of the key() method for iterator.
*
* @return mixed The current row number (starts at 0), or NULL if no rows
*/
public function key()
{
if (is_null($this->_result)) {
$this->rewind();
}
return $this->_index;
}
/**
* Implementation of the next() method.
*
* @return Horde_Rdo_Base|null The next Rdo object in the set or
* null if no more results.
*/
public function next()
{
if (is_null($this->_result)) {
$this->rewind();
}
if ($this->_result) {
$row = $this->_result->fetch();
if (!$row) {
$this->_eof = true;
} else {
$this->_eof = false;
if (is_null($this->_index)) {
$this->_index = 0;
} else {
++$this->_index;
}
$this->_current = $this->_mapper->map($row);
}
}
return $this->_current;
}
/**
* Implementation of the offsetExists() method for ArrayAccess
* This method is executed when using isset() or empty() on Horde_Rdo_List objects
* @param integer $offset The offset to check.
*
* @return boolean Whether or not an offset exists.
*/
public function offsetExists($offset)
{
$query = Horde_Rdo_Query::create($this->_query);
$query->limit(1, $offset);
return $this->_mapper->exists($query);
}
/**
* Implementation of the offsetGet() method for ArrayAccess
* This method is executed when using isset() or empty() on Horde_Rdo_List objects
* @param integer $offset The offset to retrieve.
*
* @return Horde_Rdo_Base An entity object at the offset position or null
*/
public function offsetGet($offset)
{
$query = Horde_Rdo_Query::create($this->_query);
$query->limit(1, $offset);
return $this->_mapper->find($query)->current();
}
/**
* Not implemented.
*
* Stub of the offsetSet() method for ArrayAccess
* This method is executed when adding an item to the Horde_Rdo_List
* @param Horde_Rdo_Base $item The item to add to the list.
* @param integer $offset The offset to add or change.
* @param Horde_Rdo_Base $offset The item to add to the list.
*
* @return Horde_Rdo_Base An entity object at the offset position or null
*/
public function offsetSet($offset, $item)
{
throw new Horde_Rdo_Exception('You cannot add objects to a result set');
}
/**
* Not implemented.
*
* Stub of the offsetUnset() method for ArrayAccess
* This method is executed when calling unset on a Horde_Rdo_List index
* @param Horde_Rdo_Base $item The item to add to the list.
* @param integer $offset The offset to unset.
*
* @return Horde_Rdo_Base An entity object at the offset position or null
*/
public function offsetUnset($offset)
{
throw new Horde_Rdo_Exception('You cannot remove objects from a result set');
}
/**
* Implementation of the valid() method for iterator
*
* @return boolean Whether the iteration is valid
*/
public function valid()
{
if (is_null($this->_result)) {
$this->rewind();
}
return !$this->_eof;
}
/**
* Implementation of count() for Countable
*
* @return integer Number of elements in the list
*/
public function count()
{
if (is_null($this->_count)) {
$this->_count = $this->_mapper->count($this->_query);
}
return $this->_count;
}
}
Horde_Rdo-2.0.5/lib/Horde/Rdo/Mapper.php 0000664 0001750 0001750 00000053670 12654065536 016006 0 ustar jan jan adapter = $adapter;
}
/**
* Attach a Horde_Rdo_Factory to the mapper.
* If called without arguments, detaches the mapper from factory
*
* @param Horde_Rdo_Factory $factory A Factory instance or null
* @return Horde_Rdo_Mapper this mapper
*/
public function setFactory(Horde_Rdo_Factory $factory = null)
{
$this->_factory = $factory;
return $this;
}
/**
* Provide read-only, on-demand access to several properties. This
* method will only be called for properties that aren't already
* present; once a property is fetched once it is cached and
* returned directly on any subsequent access.
*
* These properties are available:
*
* adapter: The Horde_Db_Adapter this mapper is using to talk to
* the database.
*
* factory: The Horde_Rdo_Factory instance, if present
*
* inflector: The Horde_Support_Inflector this Mapper uses to singularize
* and pluralize PHP class, database table, and database field/key names.
*
* table: The database table or view that this Mapper manages.
*
* tableDefinition: The Horde_Db_Adapter_Base_TableDefinition object describing
* the table or view this Mapper manages.
*
* fields: Array of all field names that are loaded up front
* (eager loading) from the table.
*
* lazyFields: Array of fields that are only loaded when accessed.
*
* relationships: Array of relationships to other Mappers.
*
* lazyRelationships: Array of relationships to other Mappers which
* are only loaded when accessed.
*
* @param string $key Property name to fetch
*
* @return mixed Value of $key
*/
public function __get($key)
{
switch ($key) {
case 'inflector':
$this->inflector = new Horde_Support_Inflector();
return $this->inflector;
case 'primaryKey':
$this->primaryKey = (string)$this->tableDefinition->getPrimaryKey();
return $this->primaryKey;
case 'table':
$this->table = !empty($this->_table) ? $this->_table : $this->mapperToTable();
return $this->table;
case 'tableDefinition':
$this->tableDefinition = $this->adapter->table($this->table);
return $this->tableDefinition;
case 'fields':
$this->fields = array_diff($this->tableDefinition->getColumnNames(), $this->_lazyFields);
return $this->fields;
case 'lazyFields':
case 'relationships':
case 'lazyRelationships':
case 'factory':
case 'defaultSort':
return $this->{'_' . $key};
}
return null;
}
/**
* Create an instance of $this->_classname from a set of data.
*
* @param array $fields Field names/default values for the new object.
*
* @see $_classname
*
* @return Horde_Rdo_Base An instance of $this->_classname with $fields
* as initial data.
*/
public function map($fields = array())
{
// Guess a classname if one isn't explicitly set.
if (!$this->_classname) {
$this->_classname = $this->mapperToEntity();
if (!$this->_classname) {
throw new Horde_Rdo_Exception('Unable to find an entity class (extending Horde_Rdo_Base) for ' . get_class($this));
}
}
$o = new $this->_classname();
$o->setMapper($this);
$this->mapFields($o, $fields);
if (is_callable(array($o, 'afterMap'))) {
$o->afterMap();
}
return $o;
}
/**
* Update an instance of $this->_classname from a set of data.
*
* @param Horde_Rdo_Base $object The object to update
* @param array $fields Field names/default values for the object
*/
public function mapFields($object, $fields = array())
{
$relationships = array();
foreach ($fields as $fieldName => &$fieldValue) {
if (strpos($fieldName, '@') !== false) {
list($rel, $field) = explode('@', $fieldName, 2);
$relationships[$rel][$field] = $fieldValue;
unset($fields[$fieldName]);
}
if (isset($this->fields[$fieldName])) {
$fieldName = $this->fields[$fieldName];
}
$column = $this->tableDefinition->getColumn($fieldName);
if ($column) {
$fieldValue = $column->typeCast($fieldValue);
}
}
$object->setFields($fields);
if (count($relationships)) {
foreach ($this->relationships as $relationship => $rel) {
if (isset($rel['mapper'])) {
if ($this->_factory) {
$m = $this->_factory->create($rel['mapper']);
}
// @TODO - should be getting this instance from somewhere
// else external, and not passing the adapter along
// automatically.
else {
$m = new $rel['mapper']($this->adapter);
}
} else {
$m = $this->tableToMapper($relationship);
if (is_null($m)) {
// @TODO Throw an exception?
continue;
}
}
if (isset($relationships[$m->table])) {
$object->$relationship = $m->map($relationships[$m->table]);
}
}
}
}
/**
* Transform a table name to a mapper class name.
*
* @param string $table The database table name to look up.
*
* @return Horde_Rdo_Mapper A new Mapper instance if it exists, else null.
*/
public function tableToMapper($table)
{
if (class_exists(($class = Horde_String::ucwords($table) . 'Mapper'))) {
return new $class;
}
return null;
}
/**
* Transform this mapper's class name to a database table name.
*
* @return string The database table name.
*/
public function mapperToTable()
{
return $this->inflector->pluralize(Horde_String::lower(str_replace('Mapper', '', get_class($this))));
}
/**
* Transform this mapper's class name to an entity class name.
*
* @return string A Horde_Rdo_Base concrete class name if the class exists, else null.
*/
public function mapperToEntity()
{
$class = str_replace('Mapper', '', get_class($this));
if (class_exists($class)) {
return $class;
}
return null;
}
/**
* Count objects that match $query.
*
* @param mixed $query The query to count matches of.
*
* @return integer All objects matching $query.
*/
public function count($query = null)
{
$query = Horde_Rdo_Query::create($query, $this);
$query->setFields('COUNT(*)')
->clearSort();
list($sql, $bindParams) = $query->getQuery();
return $this->adapter->selectValue($sql, $bindParams);
}
/**
* Check if at least one object matches $query.
*
* @param mixed $query Either a primary key, an array of keys
* => values, or a Horde_Rdo_Query object.
*
* @return boolean True or false.
*/
public function exists($query)
{
$query = Horde_Rdo_Query::create($query, $this);
$query->setFields(1)
->clearSort();
list($sql, $bindParams) = $query->getQuery();
return (bool)$this->adapter->selectValue($sql, $bindParams);
}
/**
* Create a new object in the backend with $fields as initial values.
*
* @param array $fields Array of field names => initial values.
*
* @return Horde_Rdo_Base The newly created object.
*/
public function create($fields)
{
// If configured to record creation and update times, set them
// here. We set updated_at to the initial creation time so it's
// always set.
if ($this->_setTimestamps) {
$time = time();
$fields['created_at'] = $time;
$fields['updated_at'] = $time;
}
// Filter out any extra fields.
$fields = array_intersect_key($fields, array_flip($this->tableDefinition->getColumnNames()));
if (!$fields) {
throw new Horde_Rdo_Exception('create() requires at least one field value.');
}
$sql = 'INSERT INTO ' . $this->adapter->quoteTableName($this->table);
$keys = array();
$placeholders = array();
$bindParams = array();
foreach ($fields as $field => $value) {
$keys[] = $this->adapter->quoteColumnName($field);
$placeholders[] = '?';
$bindParams[] = $value;
}
$sql .= ' (' . implode(', ', $keys) . ') VALUES (' . implode(', ', $placeholders) . ')';
$id = $this->adapter->insert($sql, $bindParams);
return $this->map(array_merge($fields, array($this->primaryKey => $id)));
}
/**
* Updates a record in the backend. $object can be either a
* primary key or an Rdo object. If $object is an Rdo instance
* then $fields will be ignored as values will be pulled from the
* object.
*
* @param string|Rdo $object The Rdo instance or unique id to update.
* @param array $fields If passing a unique id, the array of field properties
* to set for $object.
*
* @return integer Number of objects updated.
*/
public function update($object, $fields = null)
{
if ($object instanceof Horde_Rdo_Base) {
$key = $this->primaryKey;
$id = $object->$key;
$fields = iterator_to_array($object);
if (!$id) {
// Object doesn't exist yet; create it instead.
$o = $this->create($fields);
$this->mapFields($object, iterator_to_array($o));
return 1;
}
} else {
$id = $object;
}
// If configured to record update time, set it here.
if ($this->_setTimestamps) {
$fields['updated_at'] = time();
}
// Filter out any extra fields.
$fields = array_intersect_key($fields, array_flip($this->tableDefinition->getColumnNames()));
if (!$fields) {
// Nothing to change.
return 0;
}
$sql = 'UPDATE ' . $this->adapter->quoteTableName($this->table) . ' SET';
$bindParams = array();
foreach ($fields as $field => $value) {
$sql .= ' ' . $this->adapter->quoteColumnName($field) . ' = ?,';
$bindParams[] = $value;
}
$sql = substr($sql, 0, -1) . ' WHERE ' . $this->primaryKey . ' = ?';
$bindParams[] = $id;
return $this->adapter->update($sql, $bindParams);
}
/**
* Deletes a record from the backend. $object can be either a
* primary key, an Rdo_Query object, or an Rdo object.
*
* @param string|Horde_Rdo_Base|Horde_Rdo_Query $object The Rdo object,
* Horde_Rdo_Query, or unique id to delete.
*
* @return integer Number of objects deleted.
*/
public function delete($object)
{
if ($object instanceof Horde_Rdo_Base) {
$key = $this->primaryKey;
$id = $object->$key;
$query = array($key => $id);
} elseif ($object instanceof Horde_Rdo_Query) {
$query = $object;
} else {
$key = $this->primaryKey;
$query = array($key => $object);
}
$query = Horde_Rdo_Query::create($query, $this);
$clauses = array();
$bindParams = array();
foreach ($query->tests as $test) {
$clauses[] = $this->adapter->quoteColumnName($test['field']) . ' ' . $test['test'] . ' ?';
$bindParams[] = $test['value'];
}
if (!$clauses) {
throw new Horde_Rdo_Exception('Refusing to delete the entire table.');
}
$sql = 'DELETE FROM ' . $this->adapter->quoteTableName($this->table) .
' WHERE ' . implode(' ' . $query->conjunction . ' ', $clauses);
return $this->adapter->delete($sql, $bindParams);
}
/**
* find() can be called in several ways.
*
* Primary key mode: pass find() a numerically indexed array of primary
* keys, and it will return a list of the objects that correspond to those
* keys.
*
* If you pass find() no arguments, all objects of this type will be
* returned.
*
* If you pass find() an associative array, it will be turned into a
* Horde_Rdo_Query object.
*
* If you pass find() a Horde_Rdo_Query, it will return a list of all
* objects matching that query.
*/
public function find($arg = null)
{
if (is_null($arg)) {
$query = null;
} elseif (is_array($arg)) {
if (!count($arg)) {
throw new Horde_Rdo_Exception('No criteria found');
}
if (is_numeric(key($arg))) {
// Numerically indexed arrays are assumed to be an array of
// primary keys.
$query = new Horde_Rdo_Query();
$query->combineWith('OR');
foreach ($argv[0] as $id) {
$query->addTest($this->primaryKey, '=', $id);
}
} else {
$query = $arg;
}
} else {
$query = $arg;
}
// Build a full Query object.
$query = Horde_Rdo_Query::create($query, $this);
return new Horde_Rdo_List($query);
}
/**
* Adds a relation.
*
* - For one-to-one relations, simply updates the relation field.
* - For one-to-many relations, updates the related object's relation field.
* - For many-to-many relations, adds an entry in the "through" table.
* - Performs a no-op if the peer is already related.
*
* @param string $relationship The relationship key in the mapper.
* @param Horde_Rdo_Base $ours The object from this mapper to add the
* relation.
* @param Horde_Rdo_Base $theirs The other object from any mapper to add
* the relation.
*
* @throws Horde_Rdo_Exception
*/
public function addRelation($relationship, Horde_Rdo_Base $ours,
Horde_Rdo_Base $theirs)
{
if ($ours->hasRelation($relationship, $theirs)) {
return;
}
$ourKey = $this->primaryKey;
$theirKey = $theirs->mapper->primaryKey;
if (isset($this->relationships[$relationship])) {
$rel = $this->relationships[$relationship];
} elseif (isset($this->lazyRelationships[$relationship])) {
$rel = $this->lazyRelationships[$relationship];
} else {
throw new Horde_Rdo_Exception('The requested relation is not defined in the mapper');
}
switch ($rel['type']) {
case Horde_Rdo::ONE_TO_ONE:
case Horde_Rdo::MANY_TO_ONE:
$ours->{$rel['foreignKey']} = $theirs->$theirKey;
$ours->save();
break;
case Horde_Rdo::ONE_TO_MANY:
$theirs->{$rel['foreignKey']} = $ours->$ourKey;
$theirs->save();
break;
case Horde_Rdo::MANY_TO_MANY:
$sql = sprintf('INSERT INTO %s (%s, %s) VALUES (?, ?)',
$this->adapter->quoteTableName($rel['through']),
$this->adapter->quoteColumnName($ourKey),
$this->adapter->quoteColumnName($theirKey));
try {
$this->adapter->insert($sql, array($ours->$ourKey, $theirs->$theirKey));
} catch (Horde_Db_Exception $e) {
throw new Horde_Rdo_Exception($e);
}
break;
}
}
/**
* Removes a relation to one of the relationships defined in the mapper.
*
* - For one-to-one and one-to-many relations, simply sets the relation
* field to 0.
* - For many-to-many, either deletes all relations to this object or just
* the relation to a given peer object.
* - Performs a no-op if the peer is already unrelated.
*
* This is a proxy to the mapper's removeRelation method.
*
* @param string $relationship The relationship key in the mapper.
* @param Horde_Rdo_Base $ours The object from this mapper.
* @param Horde_Rdo_Base $theirs The object to remove from the relation.
* @return integer the number of affected relations
*
* @throws Horde_Rdo_Exception
*/
public function removeRelation($relationship, Horde_Rdo_Base $ours,
Horde_Rdo_Base $theirs = null)
{
if (!$ours->hasRelation($relationship, $theirs)) {
return;
}
$ourKey = $this->primaryKey;
if (isset($this->relationships[$relationship])) {
$rel = $this->relationships[$relationship];
} elseif (isset($this->lazyRelationships[$relationship])) {
$rel = $this->lazyRelationships[$relationship];
} else {
throw new Horde_Rdo_Exception('The requested relation is not defined in the mapper');
}
switch ($rel['type']) {
case Horde_Rdo::ONE_TO_ONE:
case Horde_Rdo::MANY_TO_ONE:
$ours->{$rel['foreignKey']} = null;
$ours->save();
return 1;
break;
case Horde_Rdo::ONE_TO_MANY:
$theirs->{$rel['foreignKey']} = null;
$theirs->save();
return 1;
break;
case Horde_Rdo::MANY_TO_MANY:
$sql = sprintf('DELETE FROM %s WHERE %s = ? ',
$this->adapter->quoteTableName($rel['through']),
$this->adapter->quoteColumnName($ourKey));
$values = array($ours->$ourKey);
if (!empty($theirs)) {
$theirKey = $theirs->mapper->primaryKey;
$sql .= sprintf(' AND %s = ?',
$this->adapter->quoteColumnName($theirKey));
$values[] = $theirs->$theirKey;
}
try {
return $this->adapter->delete($sql, $values);
} catch (Horde_Db_Exception $e) {
throw new Horde_Rdo_Exception($e);
}
break;
}
}
/**
* findOne can be called in several ways.
*
* Primary key mode: pass find() a single primary key, and it will return a
* single object matching that primary key.
*
* If you pass findOne() no arguments, the first object of this type will be
* returned.
*
* If you pass findOne() an associative array, it will be turned into a
* Horde_Rdo_Query object.
*
* If you pass findOne() a Horde_Rdo_Query, it will return the first object
* matching that query.
*/
public function findOne($arg = null)
{
if (is_null($arg)) {
$query = null;
} elseif (is_scalar($arg)) {
$query = array($this->primaryKey => $arg);
} else {
$query = $arg;
}
// Build a full Query object, and limit it to one result.
$query = Horde_Rdo_Query::create($query, $this);
$query->limit(1);
$list = new Horde_Rdo_List($query);
return $list->current();
}
/**
* Set a default sort rule for all queries done with this Mapper.
*
* @param string $sort SQL sort fragment, such as 'updated DESC'
*/
public function sortBy($sort)
{
$this->_defaultSort = $sort;
return $this;
}
}
Horde_Rdo-2.0.5/lib/Horde/Rdo/Query.php 0000664 0001750 0001750 00000036473 12654065536 015671 0 ustar jan jan setMapper($mapper);
}
return $query;
}
$q = new Horde_Rdo_Query($mapper);
if (is_scalar($query)) {
$q->addTest($mapper->tableDefinition->getPrimaryKey(), '=', $query);
} elseif ($query) {
$q->combineWith('AND');
foreach ($query as $key => $value) {
$q->addTest($key, '=', $value);
}
}
return $q;
}
/**
* @param Horde_Rdo_Mapper $mapper Rdo mapper base class
*/
public function __construct($mapper = null)
{
$this->setMapper($mapper);
}
/**
* @param Horde_Rdo_Mapper $mapper Rdo mapper base class
*
* @return Horde_Rdo_Query Return the query object for fluent chaining.
*/
public function setMapper($mapper)
{
if ($mapper === $this->mapper) {
return $this;
}
$this->mapper = $mapper;
// Fetch all non-lazy-loaded fields for the mapper.
$this->setFields($mapper->fields, $mapper->table . '.');
// Add all non-lazy relationships.
foreach ($mapper->relationships as $relationship => $rel) {
if (isset($rel['mapper'])) {
// @TODO - should be getting this instance from somewhere
// else external, and not passing the adapter along
// automatically.
$m = new $rel['mapper']($this->mapper->adapter);
} else {
$m = $this->mapper->tableToMapper($relationship);
if (is_null($m)) {
throw new Horde_Rdo_Exception('Unable to find a Mapper class for eager-loading relationship ' . $relationship);
}
}
// Add the fields for this relationship to the query.
$m->tableAlias = $this->_alias($m->table);
$this->addFields($m->fields, $m->tableAlias . '.@');
switch ($rel['type']) {
case Horde_Rdo::ONE_TO_ONE:
case Horde_Rdo::MANY_TO_ONE:
if (isset($rel['query'])) {
$query = $this->_fillJoinPlaceholders($m, $mapper, $rel['query']);
} else {
$query = array($mapper->table . '.' . $rel['foreignKey'] => new Horde_Rdo_Query_Literal($m->table . '.' . $m->tableDefinition->getPrimaryKey()));
}
$this->addRelationship($relationship, array('mapper' => $m,
'type' => $rel['type'],
'query' => $query));
break;
case Horde_Rdo::ONE_TO_MANY:
case Horde_Rdo::MANY_TO_MANY:
//@TODO
}
}
return $this;
}
/**
* Makes the query return only distinct (different) values.
*
* @param boolean $distinct Whether to enable a distinct query.
*
* @return Horde_Rdo_Query Returns self for fluent method chaining.
*/
public function distinct($distinct)
{
$this->distinct = $distinct;
return $this;
}
/**
* @param array $fields The fields to load with this query.
*
* @return Horde_Rdo_Query Returns self for fluent method chaining.
*/
public function setFields($fields, $fieldPrefix = null)
{
if (!is_array($fields)) {
$fields = array($fields);
}
if (!is_null($fieldPrefix)) {
array_walk($fields, array($this, '_prefix'), $fieldPrefix);
}
$this->fields = $fields;
return $this;
}
/**
* @param array $fields Additional Fields to load with this query.
*
* @return Horde_Rdo_Query Returns self for fluent method chaining.
*/
public function addFields($fields, $fieldPrefix = null)
{
if (!is_null($fieldPrefix)) {
array_walk($fields, array($this, '_prefix'), $fieldPrefix);
}
$this->fields = array_merge($this->fields, $fields);
}
/**
* @param string $conjunction SQL conjunction such as "AND", "OR".
*/
public function combineWith($conjunction)
{
$this->conjunction = $conjunction;
return $this;
}
/**
*/
public function addTest($field, $test, $value)
{
$this->tests[] = array('field' => $field,
'test' => $test,
'value' => $value);
return $this;
}
/**
* Adds a relationship type to a query.
* @param string $relationship The name of the relationship as defined in
* the mapper.
* @param array $args The parameter array as defined in the
* mapper:
* - mapper: The mapper object of the
* result class.
* - table: Optional name of the table to
* use.
* - tableAlias: Optional alias name for the
* base table.
* - join_type: Optional explicitly control
* the type of join.
* - type: The type of relation, any of
* the constants in Horde_Rdo.
*
* @return Horde_Rdo_Query This object.
*/
public function addRelationship($relationship, $args)
{
if (!isset($args['mapper'])) {
throw new InvalidArgumentException('Relationships must contain a Horde_Rdo_Mapper object.');
}
if (!isset($args['table'])) {
$args['table'] = $args['mapper']->table;
}
if (!isset($args['tableAlias'])) {
if (isset($args['mapper']->tableAlias)) {
$args['tableAlias'] = $args['mapper']->tableAlias;
} else {
$args['tableAlias'] = $this->_alias($args['table']);
}
}
if (!isset($args['type'])) {
$args['type'] = Horde_Rdo::MANY_TO_MANY;
}
if (!isset($args['join_type'])) {
switch ($args['type']) {
case Horde_Rdo::ONE_TO_ONE:
case Horde_Rdo::MANY_TO_ONE:
case Horde_Rdo::MANY_TO_MANY:
$args['join_type'] = 'INNER JOIN';
break;
default:
$args['join_type'] = 'LEFT JOIN';
}
}
$this->relationships[$relationship] = $args;
return $this;
}
/**
* Add a sorting rule.
*
* @param string $sort SQL sort fragment, such as 'updated DESC'
*/
public function sortBy($sort)
{
$this->_sortby[] = $sort;
return $this;
}
/**
*/
public function clearSort()
{
$this->_sortby = array();
return $this;
}
/**
* Restrict the query to a subset of the results.
*
* @param integer $limit Number of items to fetch.
* @param integer $offset Offset to start fetching at.
*/
public function limit($limit, $offset = null)
{
$this->limit = $limit;
$this->limitOffset = $offset;
return $this;
}
/**
* Accessor for any fields that we want some logic around.
*
* @param string $key
*/
public function __get($key)
{
switch ($key) {
case 'sortby':
if (!$this->_sortby && $this->mapper->defaultSort) {
// Add in any default sort values, if none are already
// set.
$this->sortBy($this->mapper->defaultSort);
}
return $this->_sortby;
}
throw new InvalidArgumentException('Undefined property ' . $key);
}
/**
* Query generator.
*
* @return array A two-element array of the SQL query and an array
* of bind parameters.
*/
public function getQuery()
{
$bindParams = array();
$sql = '';
$this->_select($sql, $bindParams);
$this->_from($sql, $bindParams);
$this->_join($sql, $bindParams);
$this->_where($sql, $bindParams);
$this->_orderBy($sql, $bindParams);
$this->_limit($sql, $bindParams);
return array($sql, $bindParams);
}
/**
*/
protected function _select(&$sql, &$bindParams)
{
$fields = array();
foreach ($this->fields as $field) {
$parts = explode('.@', $field, 2);
if (count($parts) == 1) {
$fields[] = $field;
} else {
list($tableName, $columnName) = $parts;
if (isset($this->_aliases[$tableName])) {
$tableName = $this->_aliases[$tableName];
}
$fields[] = str_replace('.@', '.', $field) . ' AS ' . $this->mapper->adapter->quoteColumnName($tableName . '@' . $columnName);
}
}
if ($this->distinct) {
$sql = 'SELECT ' . $this->mapper->adapter->distinct(implode(', ', $fields), implode(', ', $this->sortby));
} else {
$sql = 'SELECT ' . implode(', ', $fields);
}
}
/**
*/
protected function _from(&$sql, &$bindParams)
{
$sql .= ' FROM ' . $this->mapper->table;
}
/**
*/
protected function _join(&$sql, &$bindParams)
{
foreach ($this->relationships as $relationship) {
$relsql = array();
$table = $relationship['table'];
$tableAlias = $relationship['tableAlias'];
foreach ($relationship['query'] as $key => $value) {
if ($value instanceof Horde_Rdo_Query_Literal) {
$relsql[] = $key . ' = ' . str_replace("{$table}.", "{$tableAlias}.", (string)$value);
} else {
$relsql[] = $key . ' = ?';
$bindParams[] = $value;
}
}
$sql .= ' ' . $relationship['join_type'] . ' ' . $relationship['table'] . ' ' . $tableAlias . ' ON ' . implode(' AND ', $relsql);
}
}
/**
*/
protected function _where(&$sql, &$bindParams)
{
$clauses = array();
foreach ($this->tests as $test) {
if (strpos($test['field'], '@') !== false) {
list($rel, $field) = explode('@', $test['field']);
if (!isset($this->relationships[$rel])) {
continue;
}
$clause = $this->relationships[$rel]['tableAlias'] . '.' . $field . ' ' . $test['test'];
} else {
$clause = $this->mapper->table . '.' . $this->mapper->adapter->quoteColumnName($test['field']) . ' ' . $test['test'];
}
if ($test['value'] instanceof Horde_Rdo_Query_Literal) {
$clauses[] = $clause . ' ' . (string)$test['value'];
} else {
if (($test['test'] == 'IN' || $test['test'] == 'NOT IN') && is_array($test['value'])) {
$clauses[] = $clause . '(?' . str_repeat(',?', count($test['value']) - 1) . ')';
$bindParams = array_merge($bindParams, array_values($test['value']));
} else {
$clauses[] = $clause . ' ?';
$bindParams[] = $test['value'];
}
}
}
if ($clauses) {
$sql .= ' WHERE ' . implode(' ' . $this->conjunction . ' ', $clauses);
}
}
/**
*/
protected function _orderBy(&$sql, &$bindParams)
{
if ($this->sortby) {
$sql .= ' ORDER BY';
foreach ($this->sortby as $sort) {
if (strpos($sort, '@') !== false) {
list($rel, $field) = explode('@', $sort);
if (!isset($this->relationships[$rel])) {
continue;
}
$sql .= ' ' . $this->relationships[$rel]['tableAlias'] . '.' . $field . ',';
} else {
$sql .= " $sort,";
}
}
$sql = substr($sql, 0, -1);
}
}
/**
*/
protected function _limit(&$sql, &$bindParams)
{
if ($this->limit) {
$opts = array('limit' => $this->limit, 'offset' => $this->limitOffset);
$sql = $this->mapper->adapter->addLimitOffset($sql, $opts);
}
}
/**
* Callback for array_walk to prefix all elements of an array with
* a given prefix.
*/
protected function _prefix(&$fieldName, $key, $prefix)
{
$fieldName = $prefix . $fieldName;
}
/**
* Get a unique table alias
*/
protected function _alias($tableName)
{
$alias = 't' . ++$this->_aliasCount;
$this->_aliases[$alias] = $tableName;
return $alias;
}
/**
* Take a query array and replace @field@ placeholders with values
* that will match in the load query.
*
* @param Horde_Rdo_Mapper $m1 Left-hand mapper
* @param Horde_Rdo_Mapper $m2 Right-hand mapper
* @param array $query The query to process placeholders on.
*
* @return array The query with placeholders filled in.
*/
protected function _fillJoinPlaceholders($m1, $m2, $query)
{
$q = array();
foreach (array_keys($query) as $field) {
$value = $query[$field];
if (preg_match('/^@(.*)@$/', $value, $matches)) {
$q[$m1->tableAlias . '.' . $field] = new Horde_Rdo_Query_Literal($m2->table . '.' . $matches[1]);
} else {
$q[$m1->tableAlias . '.' . $field] = $value;
}
}
return $q;
}
}
Horde_Rdo-2.0.5/lib/Horde/Rdo.php 0000664 0001750 0001750 00000001553 12654065536 014553 0 ustar jan jan
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Rdo
*/
/**
* @author Chuck Hagenbuch
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Rdo
*/
class Horde_Rdo
{
/**
* One-to-one relationships.
*/
const ONE_TO_ONE = 1;
/**
* One-to-many relationships (this object has many children).
*/
const ONE_TO_MANY = 2;
/**
* Many-to-one relationships (this object is one of many children
* of a single parent).
*/
const MANY_TO_ONE = 3;
/**
* Many-to-many relationships (this object relates to many
* objects, each of which relate to many objects of this type).
*/
const MANY_TO_MANY = 4;
}
Horde_Rdo-2.0.5/test/Horde/Rdo/fixtures/unit_tests.sql 0000664 0001750 0001750 00000004563 12654065536 021052 0 ustar jan jan --
-- Copyright 2012-2016 Horde LLC (http://www.horde.org/)
--
-- @author Ralf Lang
-- @category Horde
-- @package Rdo
-- @subpackage UnitTests
--
INSERT INTO test_somelazybaseobjects (baseobject_id, relatedthing_id, atextproperty) VALUES ('1', '1', 'First Base Thing');
INSERT INTO test_somelazybaseobjects (baseobject_id, relatedthing_id, atextproperty) VALUES ('2', '2', 'Second Base Thing');
INSERT INTO test_somelazybaseobjects (baseobject_id, relatedthing_id, atextproperty) VALUES ('3', '99999', 'Third Base Thing with invalid relation');
INSERT INTO test_somelazybaseobjects (baseobject_id, relatedthing_id, atextproperty) VALUES ('4', '', 'Fourth Base Thing with empty string relation');
INSERT INTO test_someeagerbaseobjects (baseobject_id, relatedthing_id, atextproperty) VALUES ('1', '1', 'First Base Thing');
INSERT INTO test_someeagerbaseobjects (baseobject_id, relatedthing_id, atextproperty) VALUES ('2', '2', 'Second Base Thing');
INSERT INTO test_someeagerbaseobjects (baseobject_id, relatedthing_id, atextproperty) VALUES ('3', '99999', 'Third Base Thing with invalid relation');
INSERT INTO test_someeagerbaseobjects (baseobject_id, relatedthing_id, atextproperty) VALUES ('4', '', 'Fourth Base Thing with empty string relation');
INSERT INTO test_relatedthings (relatedthing_id, relatedthing_textproperty, relatedthing_intproperty) VALUES ('1', 'First Related Thing', '100');
INSERT INTO test_relatedthings (relatedthing_id, relatedthing_textproperty, relatedthing_intproperty) VALUES ('2', 'Second Related Thing', '200');
INSERT INTO test_manytomanya (a_id, a_intproperty) VALUES ('1', '200');
INSERT INTO test_manytomanya (a_id, a_intproperty) VALUES ('2', '220');
INSERT INTO test_manytomanya (a_id, a_intproperty) VALUES ('3', '230');
INSERT INTO test_manytomanya (a_id, a_intproperty) VALUES ('4', '240');
INSERT INTO test_manytomanya (a_id, a_intproperty) VALUES ('5', '250');
INSERT INTO test_manytomanyb (b_id, b_intproperty) VALUES ('11', '400');
INSERT INTO test_manytomanyb (b_id, b_intproperty) VALUES ('12', '420');
INSERT INTO test_manytomanyb (b_id, b_intproperty) VALUES ('13', '430');
INSERT INTO test_manytomanyb (b_id, b_intproperty) VALUES ('14', '440');
INSERT INTO test_manytomanyb (b_id, b_intproperty) VALUES ('15', '450');
INSERT INTO test_manythrough (a_id, b_id) VALUES (2, 12);
INSERT INTO test_manythrough (a_id, b_id) VALUES (2, 14); Horde_Rdo-2.0.5/test/Horde/Rdo/Objects/ManyToManyA.php 0000664 0001750 0001750 00000000113 12654065536 020501 0 ustar jan jan array(
'type' => Horde_Rdo::MANY_TO_MANY,
'through' => 'test_manythrough',
'mapper' => 'Horde_Rdo_Test_Objects_ManyToManyBMapper'));
}
Horde_Rdo-2.0.5/test/Horde/Rdo/Objects/ManyToManyB.php 0000664 0001750 0001750 00000000113 12654065536 020502 0 ustar jan jan array('type' => Horde_Rdo::ONE_TO_ONE,
'foreignKey' => 'relatedthing_id',
'mapper' => 'Horde_Rdo_Test_Objects_RelatedThingMapper'),
);
}
Horde_Rdo-2.0.5/test/Horde/Rdo/Objects/SomeLazyBaseObject.php 0000664 0001750 0001750 00000000122 12654065536 022031 0 ustar jan jan array('type' => Horde_Rdo::ONE_TO_ONE,
'foreignKey' => 'relatedthing_id',
'mapper' => 'Horde_Rdo_Test_Objects_RelatedThingMapper'),
);
}
Horde_Rdo-2.0.5/test/Horde/Rdo/Sql/Pdo/SqliteTest.php 0000664 0001750 0001750 00000001210 12654065536 020334 0 ustar jan jan
* @category Horde
* @package Rdo
* @subpackage UnitTests
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
*/
class Horde_Rdo_Sql_Pdo_SqliteTest extends Horde_Rdo_Test_Sql_Base
{
public static function setUpBeforeClass()
{
$factory_db = new Horde_Test_Factory_Db();
try {
self::$db = $factory_db->create();
parent::setUpBeforeClass();
} catch (Horde_Test_Exception $e) {}
}
}
Horde_Rdo-2.0.5/test/Horde/Rdo/Sql/Base.php 0000664 0001750 0001750 00000026602 12654065536 016377 0 ustar jan jan
* @category Horde
* @package Rdo
* @subpackage UnitTests
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
*/
class Horde_Rdo_Test_Sql_Base extends Horde_Test_Case
{
protected static $db;
protected static $EagerBaseObjectMapper;
protected static $LazyBaseObjectMapper;
protected static $RelatedThingMapper;
protected static $MtmaMapper;
protected static $MtmbMapper;
protected static function _migrate_sql_rdo($db)
{
$migration = new Horde_Db_Migration_Base($db);
/* Cleanup potential left-overs. */
try {
$migration->dropTable('test_someeagerbaseobjects');
$migration->dropTable('test_somelazybaseobjects');
$migration->dropTable('test_relatedthings');
$migration->dropTable('test_manytomanya');
$migration->dropTable('test_manytomanyb');
$migration->dropTable('test_manythrough');
} catch (Horde_Db_Exception $e) {
}
$t = $migration->createTable('test_someeagerbaseobjects', array('autoincrementKey' => 'baseobject_id'));
$t->column('relatedthing_id', 'integer');
$t->column('atextproperty', 'string');
$t->end();
$t = $migration->createTable('test_somelazybaseobjects', array('autoincrementKey' => 'baseobject_id'));
$t->column('relatedthing_id', 'integer');
$t->column('atextproperty', 'string');
$t->end();
$t = $migration->createTable('test_relatedthings', array('autoincrementKey' => 'relatedthing_id'));
$t->column('relatedthing_textproperty', 'string', array('limit' => 255, 'null' => false));
$t->column('relatedthing_intproperty', 'integer', array('null' => false));
$t->end();
$t = $migration->createTable('test_manytomanya', array('autoincrementKey' => 'a_id'));
$t->column('a_intproperty', 'integer', array('null' => false));
$t->end();
$t = $migration->createTable('test_manytomanyb', array('autoincrementKey' => 'b_id'));
$t->column('b_intproperty', 'integer', array('null' => false));
$t->end();
$t = $migration->createTable('test_manythrough');
$t->column('a_id', 'integer');
$t->column('b_id', 'integer');
$t->end();
$migration->migrate('up');
}
public static function setUpBeforeClass()
{
self::_migrate_sql_rdo(self::$db);
// read sql file for statements
$statements = array();
$current_stmt = '';
$fp = fopen(__DIR__ . '/../fixtures/unit_tests.sql', 'r');
while ($line = fgets($fp, 8192)) {
$line = rtrim(preg_replace('/^(.*)--.*$/s', '\1', $line));
if (!$line) {
continue;
}
$current_stmt .= $line;
if (substr($line, -1) == ';') {
// leave off the ending ;
$statements[] = substr($current_stmt, 0, -1);
$current_stmt = '';
}
}
// run statements
foreach ($statements as $stmt) {
self::$db->execute($stmt);
}
}
public function testListOffsetExistsReturnFalseForTooBigOffset()
{
$list = self::$LazyBaseObjectMapper->find();
$this->assertFalse(isset($list[$list->count()]), "return false for index not in list");
}
public function testListOffsetExistsReturnFalseFor0inemptylist()
{
$list = self::$LazyBaseObjectMapper->find(5000);
$this->assertFalse(isset($list[0]), "return false for first index in empty list");
}
public function testHasRelationManyToManyAny()
{
$objectA = self::$MtmaMapper->findOne(2);
$this->assertTrue($objectA->hasRelation('manybs'));
}
public function testHasRelationManyToManyAnyButEmpty()
{
$objectA = self::$MtmaMapper->findOne(1);
$this->assertFalse($objectA->hasRelation('manybs'));
}
public function testHasRelationManyToManyWrongPeer()
{
$objectA = self::$MtmaMapper->findOne(2);
$objectB = self::$MtmbMapper->findOne(11);
$this->assertFalse($objectA->hasRelation('manybs', $objectB));
}
public function testHasRelationManyToManyRightPeer()
{
$objectA = self::$MtmaMapper->findOne(2);
$objectB = self::$MtmbMapper->findOne(12);
$this->assertTrue($objectA->hasRelation('manybs', $objectB));
}
public function testHasRelationOneToOne()
{
$objectA1 = self::$LazyBaseObjectMapper->findOne(1);
$objectA2 = self::$LazyBaseObjectMapper->findOne(4);
$objectB1 = self::$LazyBaseObjectMapper->findOne(1);
$this->assertTrue($objectA1->hasRelation('lazyRelatedThing', $objectB1));
$this->assertFalse($objectA2->hasRelation('lazyRelatedThing', $objectB1));
$this->assertTrue($objectA1->hasRelation('lazyRelatedThing'));
$this->assertFalse($objectA2->hasRelation('lazyRelatedThing'));
}
public function testAddRelationManyToMany()
{
$objectA = self::$MtmaMapper->findOne(1);
$objectB = self::$MtmbMapper->findOne(11);
$objectA->addRelation('manybs', $objectB);
$this->assertTrue($objectA->hasRelation('manybs', $objectB));
}
public function testRemoveRelationManyToManyOne()
{
$objectA = self::$MtmaMapper->findOne(2);
$objectB1 = self::$MtmbMapper->findOne(12);
$objectB2 = self::$MtmbMapper->findOne(14);
$objectA->removeRelation('manybs', $objectB1);
$this->assertFalse($objectA->hasRelation('manybs', $objectB1));
$this->assertTrue($objectA->hasRelation('manybs', $objectB2));
}
public function testRemoveRelationManyToManyAll()
{
$objectA = self::$MtmaMapper->findOne(2);
$objectB1 = self::$MtmbMapper->findOne(12);
$objectB2 = self::$MtmbMapper->findOne(14);
$objectA->removeRelation('manybs');
$this->assertFalse($objectA->hasRelation('manybs', $objectB1));
$this->assertFalse($objectA->hasRelation('manybs', $objectB2));
}
public function testListOffsetExistsReturnTrueForFirst()
{
$list = self::$LazyBaseObjectMapper->find();
$this->assertTrue(isset($list[0]), "return true for first index in list");
}
public function testListOffsetExistsReturnTrueForLast()
{
$list = self::$LazyBaseObjectMapper->find();
$this->assertTrue(isset($list[$list->count() - 1]), "return true for last index in list");
}
public function testListOffsetGetReturnNullForTooBig()
{
$list = self::$LazyBaseObjectMapper->find();
$this->assertNull($list[$list->count()], "return Null for one after last index in list");
}
public function testListOffsetGetReturnObjectForLast()
{
$list = self::$LazyBaseObjectMapper->find();
$this->assertTrue($list[$list->count()-1] instanceof Horde_Rdo_Test_Objects_SomeLazyBaseObject, "return Object for last index in list");
}
public function testListOffsetGetReturnObjectForFirst()
{
$list = self::$LazyBaseObjectMapper->find();
$this->assertTrue($list[0] instanceof Horde_Rdo_Test_Objects_SomeLazyBaseObject, "return Object for first index in list");
}
/**
* @expectedException Horde_Rdo_Exception
*/
public function testListOffsetSetThrowException()
{
$list = self::$LazyBaseObjectMapper->find();
$list[0] = $list[0];
$this->assertTrue($list[0] instanceof Horde_Rdo_Test_Objects_SomeLazyBaseObject, "Throw exception when trying to set a new element to the list");
}
/**
* @expectedException Horde_Rdo_Exception
*/
public function testListOffsetUnsetThrowException()
{
$list = self::$LazyBaseObjectMapper->find();
unset($list[0]);
$this->assertTrue($list[0] instanceof Horde_Rdo_Test_Objects_SomeLazyBaseObject, "Throw exception when trying to unset an element");
}
public function testFindReturnsHordeRdoList()
{
$result = self::$LazyBaseObjectMapper->find();
$this->assertTrue($result instanceof Horde_Rdo_List, "find() returns a Horde_Rdo_List");
}
public function testFindOneReturnsEntity()
{
$result = self::$LazyBaseObjectMapper->findOne();
$this->assertTrue($result instanceof Horde_Rdo_Base, "findOne() returns a Horde_Rdo_Base");
}
public function testFindOneWithScalarReturnsEntityWithKeyValue()
{
$result = self::$LazyBaseObjectMapper->findOne(2);
$this->assertEquals(2, $result->baseobject_id, "findOne() returns the right Horde_Rdo_Base if key is given as argument");
}
public function testToOneRelationRetrievesEntityWhenKeyIsFound()
{
$entity = self::$LazyBaseObjectMapper->findOne(1);
$this->assertTrue($entity->lazyRelatedThing instanceof Horde_Rdo_Test_Objects_RelatedThing, "to-one-relations return an instance object");
}
public function testToOneRelationRetrievesCorrectEntityWhenKeyIsFound()
{
$result = self::$LazyBaseObjectMapper->findOne(1);
$this->assertEquals(100, $result->lazyRelatedThing->relatedthing_intproperty, "to-one-relations return correct related object when key is found");
}
/**
* @expectedException Horde_Rdo_Exception
*/
public function testLazyToOneRelationThrowsExceptionWhenKeyIsNotFound()
{
$entity = self::$LazyBaseObjectMapper->findOne(3);
$this->assertNull($entity->lazyRelatedThing, "lazy to-one-relations throw exception when relation key is not found");
}
public function testLazyToOneRelationReturnsNullWhenKeyIsEmpty()
{
$entity = self::$LazyBaseObjectMapper->findOne(4);
$this->assertNull($entity->lazyRelatedThing, "lazy to-one-relations returns 0 when relation key is empty() value");
}
public function testObjectWithEagerToOneRelationIsNotLoadedWhenRelatedObjectDoesntExist()
{
$entity = self::$EagerBaseObjectMapper->findOne(3);
$this->assertNull($entity, "Base Object not loaded when eager relation key references nonexisting line");
}
public function testObjectWithEagerToOneRelationIsNotLoadedWhenlWhenKeyIsNull()
{
$entity = self::$EagerBaseObjectMapper->findOne(4);
$this->assertNull($entity, "Base Object not loaded when eager relation key is null");
}
public static function tearDownAfterClass()
{
if (self::$db) {
$migration = new Horde_Db_Migration_Base(self::$db);
$migration->dropTable('test_someeagerbaseobjects');
$migration->dropTable('test_somelazybaseobjects');
$migration->dropTable('test_relatedthings');
$migration->dropTable('test_manytomanya');
$migration->dropTable('test_manytomanyb');
$migration->dropTable('test_manythrough');
self::$db->disconnect();
self::$db = null;
}
}
public function setUp()
{
if (!self::$db) {
$this->markTestSkipped('No sqlite extension or no sqlite PDO driver.');
}
self::$LazyBaseObjectMapper = new Horde_Rdo_Test_Objects_SomeLazyBaseObjectMapper(self::$db);
self::$EagerBaseObjectMapper = new Horde_Rdo_Test_Objects_SomeEagerBaseObjectMapper(self::$db);
self::$MtmaMapper = new Horde_Rdo_Test_Objects_ManyToManyAMapper(self::$db);
self::$MtmbMapper = new Horde_Rdo_Test_Objects_ManyToManyBMapper(self::$db);
}
}
Horde_Rdo-2.0.5/test/Horde/Rdo/AllTests.php 0000664 0001750 0001750 00000000132 12654065536 016507 0 ustar jan jan run();
Horde_Rdo-2.0.5/test/Horde/Rdo/Autoload.php 0000664 0001750 0001750 00000002040 12654065536 016524 0 ustar jan jan
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
*/
/** Load Mapper definitions */
require_once __DIR__ . '/Objects/SomeLazyBaseObjectMapper.php';
require_once __DIR__ . '/Objects/SomeLazyBaseObject.php';
require_once __DIR__ . '/Objects/SomeEagerBaseObjectMapper.php';
require_once __DIR__ . '/Objects/SomeEagerBaseObject.php';
require_once __DIR__ . '/Objects/RelatedThingMapper.php';
require_once __DIR__ . '/Objects/RelatedThing.php';
require_once __DIR__ . '/Objects/ManyToManyA.php';
require_once __DIR__ . '/Objects/ManyToManyB.php';
require_once __DIR__ . '/Objects/ManyToManyAMapper.php';
require_once __DIR__ . '/Objects/ManyToManyBMapper.php';
Horde_Rdo-2.0.5/test/Horde/Rdo/bootstrap.php 0000664 0001750 0001750 00000000143 12654065536 016773 0 ustar jan jan
../../../lib