當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataMapper類代碼示例

本文整理匯總了PHP中DataMapper的典型用法代碼示例。如果您正苦於以下問題:PHP DataMapper類的具體用法?PHP DataMapper怎麽用?PHP DataMapper使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DataMapper類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUp

 protected function setUp()
 {
     $this->dataMapper = $this->getMock('FSi\\Component\\DataGrid\\DataMapper\\DataMapperInterface');
     $this->dataMapper->expects($this->any())->method('getData')->will($this->returnCallback(function ($field, $object) {
         switch ($field) {
             case 'name':
                 return $object->getName();
                 break;
         }
     }));
     $this->dataMapper->expects($this->any())->method('setData')->will($this->returnCallback(function ($field, $object, $value) {
         switch ($field) {
             case 'name':
                 return $object->setName($value);
                 break;
         }
     }));
     $this->indexingStrategy = $this->getMock('FSi\\Component\\DataGrid\\Data\\IndexingStrategyInterface');
     $this->indexingStrategy->expects($this->any())->method('getIndex')->will($this->returnCallback(function ($object, $dataMapper) {
         if (is_object($object)) {
             return $object->getName();
         }
         return null;
     }));
     $this->factory = $this->getMock('FSi\\Component\\DataGrid\\DataGridFactoryInterface');
     $this->factory->expects($this->any())->method('getExtensions')->will($this->returnValue(array(new FooExtension())));
     $this->factory->expects($this->any())->method('getColumnType')->with($this->equalTo('foo'))->will($this->returnValue(new FooType()));
     $this->factory->expects($this->any())->method('hasColumnType')->with($this->equalTo('foo'))->will($this->returnValue(true));
     $this->datagrid = new DataGrid('grid', $this->factory, $this->dataMapper, $this->indexingStrategy);
 }
開發者ID:norzechowicz,項目名稱:datagrid,代碼行數:30,代碼來源:DataGridTest.php

示例2: testGlobalMapping

 /**
  * @dataProvider globalMappedData
  */
 public function testGlobalMapping($path, $data, $expected)
 {
     $mapper = new DataMapper();
     foreach ($data as $globalData) {
         $mapper->mapAll($globalData);
     }
     $this->assertEquals($expected, $mapper->data($path));
 }
開發者ID:bloge,項目名稱:bloge,代碼行數:11,代碼來源:DataMapperTest.php

示例3: testShouldListPossibleParents

 function testShouldListPossibleParents()
 {
     $mapper = new DataMapper($this->db);
     $parent1_id = $mapper->save(array('name' => 'Parent 1'));
     $mapper = new DataMapper($this->db);
     $parent2_id = $mapper->save(array('name' => 'Parent 1a', 'paths' => array($parent1_id)));
     $form = new Form($mapper);
     $expected = array($parent1_id => 'Parent 1', $parent1_id . '/' . $parent2_id => 'Parent 1a');
     $this->assertEquals($expected, $form->getElement('paths')->getMultiOptions());
 }
開發者ID:metator,項目名稱:application,代碼行數:10,代碼來源:FormTest.php

示例4: testShouldUpdateAddress

 function testShouldUpdateAddress()
 {
     $address = array('first_name' => 'Joshua', 'last_name' => 'Ribakoff', 'email' => 'josh.ribakoff@gmail.com', 'address' => '123 Test St', 'address2' => 'Suite 5', 'city' => 'Port St Lucie', 'state' => 'FL', 'postal' => '00123', 'country' => 'USA', 'phone' => '0101010101', 'fax' => '0202020202');
     $addressMapper = new DataMapper($this->db);
     $id = $addressMapper->save($address);
     $updatedAddress = array('id' => $id, 'first_name' => 'Joshua-updated', 'last_name' => 'Ribakoff-updated', 'email' => 'josh.ribakoff-updated@gmail.com', 'address' => '123 Test St-updated', 'address2' => 'Suite 5-updated', 'city' => 'Port St Lucie-updated', 'state' => 'FL-updated', 'postal' => '12345', 'country' => 'USA-updated', 'phone' => '111111111', 'fax' => '2222222222');
     $addressMapper = new DataMapper($this->db);
     $id = $addressMapper->save($updatedAddress);
     $loadedAddress = $addressMapper->load($id);
     $this->assertSame($updatedAddress, $loadedAddress, 'should save new address');
 }
開發者ID:metator,項目名稱:application,代碼行數:11,代碼來源:DataMapperTest.php

示例5: testShouldSaveCartAndItems

 function testShouldSaveCartAndItems()
 {
     $cart = new \Metator\Cart\Cart();
     $cart->add(1, 9.99);
     $cart->add(2, 4.99);
     $cart->setQuantity(2, 2);
     $order = array('items' => $cart, 'created' => '0000-00-00 00:00:00');
     $orderMapper = new DataMapper($this->db);
     $id = $orderMapper->save($order, null);
     $reloaded_order = $orderMapper->load($id);
     $this->assertEquals(array(1, 2), $reloaded_order['items']->items(), 'should save items');
 }
開發者ID:metator,項目名稱:application,代碼行數:12,代碼來源:DataMapperTest.php

示例6: __construct

 public function __construct()
 {
     Cowl::timer('cowl init');
     @session_start();
     // I know that the @-notation is frowned upon, but adding it to session_start saves us unnecessary warnings
     Cache::setDir(COWL_CACHE_DIR);
     Current::initialize(COWL_DIR);
     if (COWL_CLI) {
         $this->parseCLIPath();
     } else {
         $this->parseRequestPath();
     }
     Cowl::timer('cowl set defaults');
     // Get and set all directories for various things.
     list($commands_dir, $model_dir, $validators_dir, $library_dir, $view_dir, $helpers_dir, $helpers_app_dir, $drivers_dir, $app_dir, $view_layout_dir, $validator_error_messages, $lang) = Current::$config->gets('paths.commands', 'paths.model', 'paths.validators', 'paths.library', 'paths.view', 'paths.helpers', 'paths.helpers_app', 'paths.drivers', 'paths.app', 'paths.layouts', 'paths.validator_messages', 'lang');
     Controller::setDir($commands_dir);
     DataMapper::setMappersDir($model_dir);
     DataMapper::setObjectsDir($model_dir);
     Validator::setPath($validators_dir);
     Validator::loadStrings($validator_error_messages, $lang);
     Templater::setBaseDir($view_dir);
     Templater::setLayoutDir($view_layout_dir);
     Library::setPath($library_dir);
     Helpers::setPath($helpers_dir);
     Helpers::setAppPath($helpers_app_dir);
     Database::setPath($drivers_dir);
     StaticServer::setDir($app_dir);
     Cowl::timerEnd('cowl set defaults');
     Cowl::timer('cowl plugins load');
     Current::$plugins = new Plugins();
     Cowl::timerEnd('cowl plugins load');
     // Load default helper
     Helpers::load('standard', 'form');
     Cowl::timerEnd('cowl init');
 }
開發者ID:erkie,項目名稱:cowl,代碼行數:35,代碼來源:frontcontroller.php

示例7: __construct

 public function __construct()
 {
     foreach ($this->objects as $map) {
         $this->{strtolower($map . 'mapper')} = DataMapper::get($map);
     }
     $this->template = new Templater();
 }
開發者ID:erkie,項目名稱:cowl,代碼行數:7,代碼來源:command.php

示例8: __construct

 public function __construct($id = null)
 {
     if (!is_null($id)) {
         $this->setID($id);
     }
     $this->validator = new Validator();
     $this->validator->setStoreErrors(true);
     $this->mapper = DataMapper::get(get_class($this));
 }
開發者ID:erkie,項目名稱:cowl,代碼行數:9,代碼來源:domainobject.php

示例9: delete

 /**
  * Delete this student or related object.
  * If no parameters are set, this method deletes current student and all participant record related with this student.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     if (empty($object) && !is_array($object) && !empty($this->id)) {
         $participant = new Participant();
         $participant->where_related($this);
         $participant->get();
         $participant->delete_all();
     }
     parent::delete($object, $related_field);
 }
開發者ID:andrejjursa,項目名稱:list-lms,代碼行數:16,代碼來源:student.php

示例10: delete

 /**
  * Delete this test or related object.
  * If no parameters are set, this method deletes current test and all files associated with this test.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     if (empty($object) && !is_array($object) && !empty($this->id)) {
         $path_to_test_files = 'private/uploads/unit_tests/test_' . $this->id;
         if (file_exists($path_to_test_files)) {
             unlink_recursive($path_to_test_files, TRUE);
         }
     }
     parent::delete($object, $related_field);
 }
開發者ID:andrejjursa,項目名稱:list-lms,代碼行數:16,代碼來源:test.php

示例11: delete

 /**
  * Deletes relations (if parameters are set) or this object from database.
  * All comments which replies to this one will be deleted as well.
  * @param DataMapper|string $object related object to delete from relation.
  * @param string $related_field relation internal name.
  */
 public function delete($object = '', $related_field = '')
 {
     $this_id = $this->id;
     if (empty($object) && !is_array($object) && !empty($this_id)) {
         $comments = $this->comment->get_iterated();
         foreach ($comments as $comment) {
             $comment->delete();
         }
     }
     parent::delete($object, $related_field);
 }
開發者ID:andrejjursa,項目名稱:list-lms,代碼行數:17,代碼來源:comment.php

示例12: __construct

 /**
  * {@inheritdoc}
  */
 public function __construct($id = null)
 {
     $trace = debug_backtrace();
     if ((empty($trace[2]['object']) || !$trace[2]['object'] instanceof DataMapper) && self::$isInstantiated) {
         throw new RuntimeException('System_setting can be instantiated only once!');
     }
     if ($this->hasTable($this->prefix . $this->table)) {
         parent::__construct($id);
     }
     self::$isInstantiated = true;
 }
開發者ID:andrewkrug,項目名稱:repucaution,代碼行數:14,代碼來源:system_setting.php

示例13: delete

 function delete($object = '')
 {
     if (empty($object)) {
         $this->deattach();
     }
     return parent::delete($object);
 }
開發者ID:blumine,項目名稱:vunsy,代碼行數:7,代碼來源:content.php

示例14: __get

 public function __get($name)
 {
     // // the conditions below should be replace by using the _get_relationship_type method
     // belongs to relationship
     if (in_array($name, $this->belongs_to)) {
         return $this->_belongs_to($name);
     } elseif (array_key_exists($name, $this->belongs_to) && is_array($this->belongs_to[$name])) {
         return $this->_belongs_to($name, $this->belongs_to[$name]);
     } elseif (in_array($name, $this->has_many)) {
         return $this->_has_many($name);
     } elseif (array_key_exists($name, $this->has_many) && is_array($this->has_many[$name])) {
         return $this->_has_many($name, $this->has_many[$name]);
         // for has_many :through
     } elseif (array_key_exists($name, $this->has_many_through)) {
         return $this->_has_many_through($name);
     } elseif (in_array($name, $this->has_one)) {
         return $this->_has_one($name);
     } elseif (array_key_exists($name, $this->has_one) && is_array($this->has_one[$name])) {
         return $this->_has_one($name, $this->has_one[$name]);
     } elseif (method_exists($this, $name)) {
         #echo $this;
         return $this->{$name}();
     } else {
         return parent::__get($name);
     }
 }
開發者ID:pmorris,項目名稱:CodeIgniter-Libraries,代碼行數:26,代碼來源:RailsMapper.php

示例15: __construct

 public function __construct(Database $db, $user)
 {
     parent::__construct($db);
     $this->table('logins');
     $this->columns(array('id', 'users_id', 'unixtime'));
     $this->has_one = array($user);
 }
開發者ID:bamcod,項目名稱:PubCodeHub,代碼行數:7,代碼來源:User.php


注:本文中的DataMapper類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。