This repository has been archived by the owner on Sep 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DAL: Introduce iterators over result sets!
Now we can iterate over result sets with a `foreach` loop in a very straightforward way. Simply do this: foreach ($statement as $result) { // … } The iterator behavior is defined by the fetching style, i.e. the way data are fetched by the database statement. By default, fetching style is set to: `FROM_START`, `FORWARD` and `AS_MAP`, i.e. the expected default behavior. Actually, the fetching style is defined by: * An offset: `FROM_START` or `FROM_END`, * A direction: `FORWARD` or `BACKWARD`, * And a result “type”/style: `AS_MAP`, `AS_SET`, `AS_OBJECT`, `AS_CLASS`, `AS_LAZY_OBJECT`, `AS_REUSABLE_OBJECT` or `AS_DEBUG_MAP`. Please, read the detailed API documentation to understand these constants, but most of them are self-describing. Why is this feature **very** important and cool? Because it can be combined with the `Hoa\Iterator` library. Thus, it is possible to use the `Hoa\Iterator\Lookahead` iterator with a database iterator to look ahead of one result, or `Hoa\Iterator\Lookbehind` to have a “cache”/to look behind of one result. This is also possible to use `Hoa\Iterator\Buffer`, `Hoa\Iterator\Append` or `Hoa\Iterator\Demultiplexer` to respectively bufferizing the results, to have an union of results or to demuxe results. Anyway… Possibilities are numerous and exciting!
- Loading branch information
Showing
7 changed files
with
529 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* Hoa | ||
* | ||
* | ||
* @license | ||
* | ||
* New BSD License | ||
* | ||
* Copyright © 2007-2016, Hoa community. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* * Neither the name of the Hoa nor the names of its contributors may be | ||
* used to endorse or promote products derived from this software without | ||
* specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
namespace Hoa\Database\IDal; | ||
|
||
use Hoa\Iterator; | ||
|
||
/** | ||
* Interface \Hoa\Database\IDal\WrapperIterator. | ||
* | ||
* Interface of a DAL iterator statement wrapper. | ||
* | ||
* @copyright Copyright © 2007-2016 Hoa community | ||
* @license New BSD License | ||
*/ | ||
interface WrapperIterator extends Iterator\Iterator | ||
{ | ||
/** | ||
* Create an iterator instance. | ||
* | ||
* @param object $statement The underlying statement instance. | ||
* @param array $style An array of fetching style options. | ||
* @return void | ||
*/ | ||
public function __construct($statement, $style); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.