1: <?php
2:
3: namespace RedBeanPHP\Util;
4:
5: use RedBeanPHP\OODB as OODB;
6: use RedBeanPHP\OODBBean as OODBBean;
7:
8: /**
9: * Dump helper
10: *
11: * This code was originally part of the facade, however it has
12: * been decided to remove unique features to service classes like
13: * this to make them available to developers not using the facade class.
14: *
15: * Dumps the contents of a bean in an array for
16: * debugging purposes.
17: *
18: * @file RedBeanPHP/Util/Dump.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 Dump
28: {
29: /**
30: * Simple but effective debug function.
31: * Given a one or more beans this method will
32: * return an array containing first part of the string
33: * representation of each item in the array.
34: *
35: * @param OODBBean|array $data either a bean or an array of beans
36: *
37: * @return array
38: */
39: public static function dump( $data )
40: {
41: $array = array();
42:
43: if ( $data instanceof OODBBean ) {
44: $str = strval( $data );
45: if (strlen($str) > 35) {
46: $beanStr = substr( $str, 0, 35 ).'... ';
47: } else {
48: $beanStr = $str;
49: }
50: return $beanStr;
51: }
52:
53: if ( is_array( $data ) ) {
54: foreach( $data as $key => $item ) {
55: $array[$key] = self::dump( $item );
56: }
57: }
58:
59: return $array;
60: }
61: }
62: