composer.json in the wrong place. Gone now.
[yaffs-website] / vendor / gabordemooij / redbean / RedBeanPHP / Util / MultiLoader.php
1 <?php
2
3 namespace RedBeanPHP\Util;
4
5 use RedBeanPHP\OODB as OODB;
6
7 /**
8  * Multi Bean Loader Helper
9  *
10  * This code was originally part of the facade, however it has
11  * been decided to remove unique features to service classes like
12  * this to make them available to developers not using the facade class.
13  *
14  * This helper class offers limited support for one-to-one
15  * relations by providing a service to load a set of beans
16  * with differnt types and a common ID.
17  *
18  * @file    RedBeanPHP/Util/MultiLoader.php
19  * @author  Gabor de Mooij and the RedBeanPHP Community
20  * @license BSD/GPLv2
21  *
22  * @copyright
23  * copyright (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community
24  * This source file is subject to the BSD/GPLv2 License that is bundled
25  * with this source code in the file license.txt.
26  */
27 class MultiLoader
28 {
29         /**
30          * Loads multiple types of beans with the same ID.
31          * This might look like a strange method, however it can be useful
32          * for loading a one-to-one relation.
33          *
34          * @param OODB         $oodb  OODB object
35          * @param string|array $types the set of types to load at once
36          * @param mixed        $id    the common ID
37          *
38          * @return OODBBean
39          */
40         public static function load( OODB $oodb, $types, $id )
41         {
42                 if ( is_string( $types ) ) {
43                         $types = explode( ',', $types );
44                 }
45
46                 if ( !is_array( $types ) ) {
47                         return array();
48                 }
49
50                 foreach ( $types as $k => $typeItem ) {
51                         $types[$k] = $oodb->load( $typeItem, $id );
52                 }
53
54                 return $types;
55         }
56 }