PageRenderTime 44ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/kernel/private/api/content/field.php

http://github.com/ezsystems/ezpublish
PHP | 79 lines | 43 code | 8 blank | 28 comment | 3 complexity | e6b6612bd357c0729961239f851b62a5 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * File containing the ezpContentField class.
  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 API
  9. */
  10. /**
  11. * This class handles content fields.
  12. * A content field currently wraps around an eZContentObjectAttribute
  13. * @package API
  14. */
  15. class ezpContentField
  16. {
  17. public function __construct()
  18. {
  19. }
  20. /**
  21. * Initializes an ezpContentField using an eZContentObjectAttribute
  22. * @param eZContentObjectAttribute $attribute
  23. * @return ezpContentField
  24. */
  25. public static function fromContentObjectAttribute( eZContentObjectAttribute $attribute )
  26. {
  27. $field = new self;
  28. $field->attribute = $attribute;
  29. return $field;
  30. }
  31. /**
  32. * String representation of the attribute.
  33. * Uses {eZContentObjectAttribute::toString()}
  34. */
  35. public function __toString()
  36. {
  37. if ( $this->attribute instanceof eZContentObjectAttribute )
  38. return $this->attribute->toString();
  39. else
  40. return '';
  41. }
  42. public function __call( $method, $arguments )
  43. {
  44. if ( method_exists( $this->attribute, $method ) )
  45. return call_user_func_array( array( $this->attribute, $method ), $arguments );
  46. else
  47. throw new ezcBasePropertyNotFoundException( $method );
  48. }
  49. public function __get( $property )
  50. {
  51. switch( $property )
  52. {
  53. // returns the serialized version of the attribute through the eZPackage mechanism
  54. // Using package here is very problematic. Some serializations put
  55. // content into the package, which is after this point, dangling.
  56. case 'serializedXML':
  57. return $this->attribute->serialize( new eZPackage );
  58. break;
  59. default:
  60. if ( $this->attribute->hasAttribute( $property ) )
  61. return $this->attribute->attribute( $property );
  62. else
  63. throw new ezcBasePropertyNotFoundException( $property );
  64. }
  65. }
  66. /**
  67. * @var eZContentObjectAttribute
  68. */
  69. protected $attribute;
  70. }
  71. ?>