PageRenderTime 41ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/kernel/private/eztemplate/ezpattributeoperatorformatter.php

http://github.com/ezsystems/ezpublish
PHP | 59 lines | 31 code | 5 blank | 23 comment | 10 complexity | 452db3784f1836fdcd99d02beb49d8b6 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * File containing ezpAttributeOperatorFormatter base class definition
  4. *
  5. * @copyright Copyright (C) eZ Systems AS. All rights reserved.
  6. * @license For full copyright and license information view LICENSE file distributed with this source code.
  7. * @version //autogentag//
  8. * @package kernel
  9. */
  10. class ezpAttributeOperatorFormatter
  11. {
  12. /**
  13. * Returns type for given item
  14. *
  15. * @param mixed $item
  16. * @return string
  17. */
  18. protected function getType( $item )
  19. {
  20. $type = gettype( $item );
  21. if ( is_object( $item ) )
  22. $type .= "[" . get_class( $item ) . "]";
  23. return $type;
  24. }
  25. /**
  26. * Returns value for given item
  27. *
  28. * @param mixed $item
  29. * @return string
  30. */
  31. protected function getValue( $item )
  32. {
  33. if ( is_bool( $item ) )
  34. $value = $item ? "true" : "false";
  35. else if ( is_array( $item ) )
  36. $value = 'Array(' . count( $item ) . ')';
  37. else if ( is_numeric( $item ) )
  38. $value = $item;
  39. else if ( is_string( $item ) )
  40. $value = "'" . $item . "'";
  41. else if ( is_object( $item ) )
  42. $value = method_exists( $item, '__toString' ) ? (string)$item : 'Object';
  43. else
  44. $value = $item;
  45. return $value;
  46. }
  47. /**
  48. * @see ezpAttributeOperatorFormatterInterface::exportScalar()
  49. */
  50. public function exportScalar( $value )
  51. {
  52. return var_export( $value, true );
  53. }
  54. }