The Entity class can also be used as a base class for your own custom data objects, and is the basis for generating forms with the Form helper.
또한 보기: lithium\template\helper\Form
상속: extends lithium\core\Object
예제 #1
0
 public function testConversion()
 {
     $data = array('foo' => '!!', 'bar' => '??', 'baz' => '--');
     $entity = new Entity(compact('data'));
     $this->assertEqual($data, $entity->to('array'));
     $this->assertEqual($data, $entity->data());
     $this->assertEqual($entity, $entity->to('foo'));
 }
예제 #2
0
 public function testModified()
 {
     $entity = new Entity();
     $this->assertEqual(array(), $entity->modified());
     $data = array('foo' => 'bar', 'baz' => 'dib');
     $entity->set($data);
     $this->assertEqual(array('foo' => true, 'baz' => true), $entity->modified());
 }
예제 #3
0
파일: Record.php 프로젝트: fedeisas/lithium
 protected function _init()
 {
     parent::_init();
     $this->_handlers += array('stdClass' => function ($item) {
         return $item;
     });
 }
예제 #4
0
 /**
  * Converts a `Record` object to another specified format.
  *
  * @param string $format The format used by default is `array`
  * @param array $options
  * @return mixed
  */
 public function to($format, array $options = array())
 {
     $defaults = array('handlers' => array('stdClass' => function ($item) {
         return $item;
     }));
     $options += $defaults;
     return parent::to($format, $options);
 }
예제 #5
0
파일: Document.php 프로젝트: EHER/monopolis
 /**
  * Instantiates a new `Document` object as a descendant of the current object, and sets all
  * default values and internal state.
  *
  * @param string $classType The type of class to create, either `'entity'` or `'set'`.
  * @param string $key The key name to which the related object is assigned.
  * @param array $data The internal data of the related object.
  * @param array $options Any other options to pass when instantiating the related object.
  * @return object Returns a new `Document` object instance.
  */
 protected function _relation($classType, $key, $data, $options = array())
 {
     $options['exists'] = false;
     return parent::_relation($classType, $key, $data, $options);
 }
예제 #6
0
 public function testHandlers()
 {
     $handlers = array('stdClass' => function ($value) {
         return substr($value->scalar, -1);
     });
     $array = new Entity(compact('handlers') + array('data' => array('value' => (object) 'hello')));
     $expected = array('value' => 'o');
     $this->assertIdentical($expected, $array->to('array', array('indexed' => false)));
 }
예제 #7
0
 /**
  * Adds conversions checks to ensure certain class types and embedded values are properly cast.
  *
  * @param string $format Currently only `array` is supported.
  * @param array $options
  * @return mixed
  */
 public function to($format, array $options = array())
 {
     $options['internal'] = false;
     return parent::to($format, $options);
 }
예제 #8
0
 /**
  * Adds conversions checks to ensure certain class types and embedded values are properly cast.
  *
  * @param string $format Currently only `array` is supported.
  * @param array $options
  * @return mixed
  */
 public function to($format, array $options = array())
 {
     $defaults = array('handlers' => array('MongoId' => function ($value) {
         return (string) $value;
     }, 'MongoDate' => function ($value) {
         return $value->sec;
     }));
     $options += $defaults;
     $options['internal'] = false;
     return parent::to($format, $options);
 }
예제 #9
0
 public function testModified()
 {
     $entity = new Entity();
     $this->assertEqual(array(), $entity->modified());
     $data = array('foo' => 'bar', 'baz' => 'dib');
     $entity->set($data);
     $this->assertEqual(array('foo' => true, 'baz' => true), $entity->modified());
     $this->assertTrue($entity->modified('foo'));
     $this->assertTrue($entity->modified('baz'));
     $this->assertNull($entity->modified('ole'));
     $subentity = new Entity();
     $subentity->set($data);
     $entity->set(array('ble' => $subentity));
     $this->assertEqual(array('foo' => true, 'baz' => true, 'ble' => true), $entity->modified());
     $this->assertTrue($entity->ble->modified('foo'));
     $this->assertFalse($entity->ble->modified('iak'));
     $this->assertEqual($entity->ble->modified(), array('foo' => true, 'baz' => true));
 }
예제 #10
0
파일: Model.php 프로젝트: rich97/li3_tree
	/**
	 * deleteFromTree
	 * 
	 * deletes a node (and its children) from the tree
	 * 
	 * @param \lithium\data\Model $self the model using this behavior
	 * @param \lithium\data\Entity $entity updated tree element
	 */
	private static function deleteFromTree($self,$entity){
		extract(static::$_tree_config[$self]);
		$span = 1;
		if($entity->data($right) - $entity->data($left) != 1){
			$span = $entity->data($right) - $entity->data($left);
			$connection = $self::connection();
			$connection->read('delete from '.$self::meta('source').' where '.$parent.'='.$entity->data($self::meta('key')),array('return'=>'resource'));
		}
		static::updateNodesIndices($self,$entity->data($right),'-',$span+1);
	}
 public function testRespondsToParentCall()
 {
     $model = $this->_model;
     $data = array('foo' => true);
     $entity = new Entity(compact('model', 'data'));
     $this->assertTrue($entity->respondsTo('applyFilter'));
     $this->assertFalse($entity->respondsTo('fooBarBaz'));
 }
예제 #12
0
 /**
  * Checks if entity **has any** of the given tags.
  *
  * @param string $model Class name of the model.
  * @param object $behavior Instance of the behavior.
  * @param object $entity
  * @return boolean
  */
 public function hasAnyTags($model, Behavior $behavior, Entity $entity, array $tags)
 {
     return (bool) array_intersect($entity->tags(['serialized' => false]), $tags);
 }
예제 #13
0
파일: Record.php 프로젝트: rapzo/lithium
 /**
  * Converts a `Record` object to another specified format.
  *
  * @param string $format The format used by default is `array`
  * @param array $options
  * @return mixed
  */
 public function to($format, array $options = array())
 {
     return parent::to($format, $options);
 }
예제 #14
0
파일: Form.php 프로젝트: EHER/chegamos
 /**
  * Creates an HTML form, and optionally binds it to a data object which contains information on
  * how to render form fields, any data to pre-populate the form with, and any validation errors.
  * Typically, a data object will be a `Record` object returned from a `Model`, but you can
  * define your own custom objects as well. For more information on custom data objects, see
  * `lithium\template\helper\Form::$_binding`.
  *
  * @see lithium\template\helper\Form::$_binding
  * @see lithium\data\Entity
  * @param object $binding
  * @param array $options
  * @return string Returns a `<form />` open tag with the `action` attribute defined by either
  *         the `'action'` or `'url'` options (defaulting to the current page if none is
  *         specified), the HTTP method is defined by the `'method'` option, and any HTML
  *         attributes passed in `$options`.
  */
 public function create(\lithium\data\Entity $binding = null, array $options = array())
 {
     $defaults = array('url' => $this->_context->request()->params, 'type' => null, 'action' => null, 'method' => $binding ? $binding->exists() ? 'put' : 'post' : 'post');
     list(, $options, $template) = $this->_defaults(__FUNCTION__, null, $options);
     list($scope, $options) = $this->_options($defaults, $options);
     $_binding =& $this->_binding;
     $method = __METHOD__;
     $params = compact('scope', 'options', 'binding');
     $filter = function ($self, $params, $chain) use($method, $template, $defaults, &$_binding) {
         $scope = $params['scope'];
         $options = $params['options'];
         $_binding = $params['binding'];
         $append = null;
         if ($scope['type'] == 'file') {
             if (strtolower($scope['method']) == 'get') {
                 $scope['method'] = 'post';
             }
             $options['enctype'] = 'multipart/form-data';
         }
         if (!in_array(strtolower($scope['method']), array('get', 'post'))) {
             $append = $self->hidden('_method', array('value' => strtoupper($scope['method'])));
             $scope['method'] = 'post';
         }
         $url = $scope['action'] ? array('action' => $scope['action']) : $scope['url'];
         $options['method'] = strtolower($scope['method']);
         return $self->invokeMethod('_render', array($method, $template, compact('url', 'options', 'append')));
     };
     return $this->_filter($method, $params, $filter);
 }