当前位置: 首页>>代码示例>>PHP>>正文


PHP Book::toArray方法代码示例

本文整理汇总了PHP中Book::toArray方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::toArray方法的具体用法?PHP Book::toArray怎么用?PHP Book::toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Book的用法示例。


在下文中一共展示了Book::toArray方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testToArray

 /**
  * Tests the Base[Object]::toArray() method
  */
 public function testToArray()
 {
     $types = array(BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM);
     $book = new Book();
     $book->fromArray(array('Title' => 'Harry Potter and the Order of the Phoenix', 'ISBN' => '043935806X'));
     $expecteds = array(BasePeer::TYPE_PHPNAME => array('Title' => 'Harry Potter and the Order of the Phoenix', 'ISBN' => '043935806X'), BasePeer::TYPE_STUDLYPHPNAME => array('title' => 'Harry Potter and the Order of the Phoenix', 'iSBN' => '043935806X'), BasePeer::TYPE_COLNAME => array('book.TITLE' => 'Harry Potter and the Order of the Phoenix', 'book.ISBN' => '043935806X'), BasePeer::TYPE_FIELDNAME => array('title' => 'Harry Potter and the Order of the Phoenix', 'isbn' => '043935806X'), BasePeer::TYPE_NUM => array('1' => 'Harry Potter and the Order of the Phoenix', '2' => '043935806X'));
     foreach ($types as $type) {
         $expected = $expecteds[$type];
         $result = $book->toArray($type);
         // remove ID since its autoincremented at each test iteration
         $result = array_slice($result, 1, 2, true);
         $this->assertEquals($expected, $result, 'expected was: ' . print_r($expected, 1) . 'but toArray() returned ' . print_r($result, 1));
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:17,代码来源:FieldnameRelatedTest.php

示例2: it_fills_model_with_given_fields_having_a_validation_rule

 /**
  * @test
  */
 public function it_fills_model_with_given_fields_having_a_validation_rule()
 {
     $bookFields = ['title' => 'Gone with the wind', 'author' => 'Margaret Mitchell'];
     $book = new Book($bookFields);
     $this->assertSame($bookFields, $book->toArray());
 }
开发者ID:stephanecoinon,项目名称:validation,代码行数:9,代码来源:BaseModelTest.php

示例3: testToArrayKeyType

 public function testToArrayKeyType()
 {
     $b = new Book();
     $b->setTitle('Don Juan');
     $arr1 = $b->toArray(BasePeer::TYPE_COLNAME);
     $expectedKeys = array(BookPeer::ID, BookPeer::TITLE, BookPeer::ISBN, BookPeer::PRICE, BookPeer::PUBLISHER_ID, BookPeer::AUTHOR_ID);
     $this->assertEquals($expectedKeys, array_keys($arr1), 'toArray() accepts a $keyType parameter to change the result keys');
     $this->assertEquals('Don Juan', $arr1[BookPeer::TITLE], 'toArray() returns an associative array representation of the object');
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:9,代码来源:GeneratedObjectTest.php

示例4: testToArrayDeep

 public function testToArrayDeep()
 {
     $author = new Author();
     $author->setId(5678);
     $author->setFirstName('George');
     $author->setLastName('Byron');
     $book = new Book();
     $book->setId(9012);
     $book->setTitle('Don Juan');
     $book->setISBN('0140422161');
     $book->setPrice(12.99);
     $book->setAuthor($author);
     $coll = new PropelArrayCollection();
     $coll->setModel('Book');
     $coll[] = $book->toArray(BasePeer::TYPE_PHPNAME, true, array(), true);
     $expected = array(array('Id' => 9012, 'Title' => 'Don Juan', 'ISBN' => '0140422161', 'Price' => 12.99, 'PublisherId' => null, 'AuthorId' => 5678, 'Author' => array('Id' => 5678, 'FirstName' => 'George', 'LastName' => 'Byron', 'Email' => null, 'Age' => null, 'Books' => array('Book_0' => '*RECURSION*'))));
     $this->assertEquals($expected, $coll->toArray());
 }
开发者ID:ketheriel,项目名称:ETVA,代码行数:18,代码来源:PropelArrayCollectionTest.php

示例5: toArray

 /**
  * Exports the object as an array.
  *
  * You can specify the key type of the array by passing one of the class
  * type constants.
  *
  * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  *                    Defaults to BasePeer::TYPE_PHPNAME.
  * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
  * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
  * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
  *
  * @return    array an associative array containing the field names (as keys) and field values
  */
 public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
 {
     if (isset($alreadyDumpedObjects['Item'][$this->getPrimaryKey()])) {
         return '*RECURSION*';
     }
     $alreadyDumpedObjects['Item'][$this->getPrimaryKey()] = true;
     $keys = ItemPeer::getFieldNames($keyType);
     $result = array($keys[0] => $this->getId(), $keys[1] => $this->getIsbn(), $keys[2] => $this->getPackageId(), $keys[3] => $this->getIsPackage(), $keys[4] => $this->getTitle(), $keys[5] => $this->getAuthor(), $keys[6] => $this->getEdition(), $keys[7] => $this->getPublisher(), $keys[8] => $this->getBNew(), $keys[9] => $this->getBUsed(), $keys[10] => $this->getBEbook(), $keys[11] => $this->getImageUrl(), $keys[12] => $this->getProductId(), $keys[13] => $this->getPartNumber(), $keys[14] => $this->getSpideredAt(), $keys[15] => $this->getShallowSpideredAt(), $keys[16] => $this->getTouched(), $keys[17] => $this->getBId(), $keys[18] => $this->getBookstoreType(), $keys[19] => $this->getCreatedAt(), $keys[20] => $this->getUpdatedAt());
     if ($includeForeignObjects) {
         if (null !== $this->aBook) {
             $result['Book'] = $this->aBook->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
         if (null !== $this->aItemRelatedByPackageId) {
             $result['ItemRelatedByPackageId'] = $this->aItemRelatedByPackageId->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
         if (null !== $this->collItemsRelatedById) {
             $result['ItemsRelatedById'] = $this->collItemsRelatedById->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
         }
         if (null !== $this->collSectionHasItems) {
             $result['SectionHasItems'] = $this->collSectionHasItems->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
         }
     }
     return $result;
 }
开发者ID:therealchiko,项目名称:getchabooks,代码行数:39,代码来源:BaseItem.php

示例6: updateBook

 public function updateBook(Book &$dbBook)
 {
     $html = PtHttpCk101::getBookContentPage($dbBook->id, 1);
     $book = PtParserCk101::parseBookFromThread($html);
     if ($book == null) {
         $dbBook->update_time = time();
         $this->db->editBook(Book::toArray($dbBook));
         $this->d("Error! The Book not exists. {$dbBook->id} {$dbBook->name}");
         return;
     }
     $book->current_pages = max($dbBook->current_pages, 1);
     if ($book->posts == 0) {
         $this->d("Error! Can not parse pages! {$book->id}, {$book->current_pages}/{$book->pages}, {$book->name}");
         return;
     }
     do {
         $this->d("Start to update book {$book->id}, {$book->current_pages}/{$book->pages}, {$book->name}");
         if ($book->current_pages != 1) {
             // page 1 is already downloaded
             $html = PtHttpCk101::getBookContentPage($dbBook->id, $book->current_pages);
         }
         if ($html == null) {
             $this->d("Get content text error! Ignore this book");
             break;
         }
         $text = PtParserCk101::parseContentFromThread($html);
         PtFile::saveBook($book->id, $book->current_pages, $text);
         $this->db->editBook(Book::toArray($book));
         sleep(self::QUERY_SLEEP);
     } while (++$book->current_pages <= $book->pages);
 }
开发者ID:poi5305,项目名称:ptnovel,代码行数:31,代码来源:c_server.php


注:本文中的Book::toArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。