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


PHP Book::validate方法代码示例

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


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

示例1: process

 /**
  * @return bool
  * @throws Exception
  */
 public function process()
 {
     $bookModel = new Book();
     if (!$bookModel->load($this->data) || !$bookModel->validate()) {
         throw new Exception('Invalid data!');
     }
     return $bookModel->delete();
 }
开发者ID:alfytu,项目名称:booklibrary,代码行数:12,代码来源:Delete.php

示例2: process

 /**
  * @return bool
  * @throws Exception
  */
 public function process()
 {
     $bookModel = new Book();
     if ($bookModel->load($this->data) && $bookModel->validate()) {
         $bookModel->save();
         return (array) $bookModel;
     }
     throw new Exception('Invalid data!');
 }
开发者ID:alfytu,项目名称:booklibrary,代码行数:13,代码来源:Set.php

示例3: process

 /**
  * @return array
  * @throws Exception
  */
 public function process()
 {
     $bookModel = new Book();
     if (!$bookModel->load($this->data)) {
         return $bookModel->getAllRecords();
     }
     if ($bookModel->validate()) {
         return $bookModel->getRecords();
     }
     throw new Exception('Invalid data!');
 }
开发者ID:alfytu,项目名称:booklibrary,代码行数:15,代码来源:View.php

示例4: it_returns_errors_on_failed_validation

 /**
  * @test
  */
 public function it_returns_errors_on_failed_validation()
 {
     $errors = ['attribute' => 'Attribute is missing'];
     $validator = m::mock('Coinon\\Validation\\ValidatorInterface');
     $validator->shouldReceive('fails')->once()->andReturn(true);
     $validator->shouldReceive('errors')->once()->andReturn($errors);
     $this->validatorFactory->shouldReceive('make')->once()->andReturn($validator);
     $book = new Book();
     $validates = $book->validate();
     $this->assertFalse($validates);
     $this->assertSame($errors, $book->errors());
 }
开发者ID:stephanecoinon,项目名称:validation,代码行数:15,代码来源:BaseModelTest.php

示例5: saveBook

 /** @param Book $book */
 protected function saveBook($book)
 {
     if ($book->isNewRecord) {
         $r = $book->validate();
         $_SESSION["book_for_edit"] = serialize($book);
         if (!$r) {
             return false;
         }
         return true;
     } else {
         return $book->save();
     }
 }
开发者ID:norayr,项目名称:notabenoid,代码行数:14,代码来源:BookEditController.php

示例6: doValidate

 /**
  * This function performs the validation work for complex object models.
  *
  * In addition to checking the current object, all related objects will
  * also be validated.  If all pass then <code>true</code> is returned; otherwise
  * an aggreagated array of ValidationFailed objects will be returned.
  *
  * @param      array $columns Array of column names to validate.
  * @return     mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
  */
 protected function doValidate($columns = null)
 {
     if (!$this->alreadyInValidation) {
         $this->alreadyInValidation = true;
         $retval = null;
         $failureMap = array();
         // We call the validate method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aCategory !== null) {
             if (!$this->aCategory->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aCategory->getValidationFailures());
             }
         }
         if ($this->aBook !== null) {
             if (!$this->aBook->validate($columns)) {
                 $failureMap = array_merge($failureMap, $this->aBook->getValidationFailures());
             }
         }
         if (($retval = ArticlePeer::doValidate($this, $columns)) !== true) {
             $failureMap = array_merge($failureMap, $retval);
         }
         if ($this->collAuthorArticles !== null) {
             foreach ($this->collAuthorArticles as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         if ($this->collAttachments !== null) {
             foreach ($this->collAttachments as $referrerFK) {
                 if (!$referrerFK->validate($columns)) {
                     $failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
                 }
             }
         }
         $this->alreadyInValidation = false;
     }
     return !empty($failureMap) ? $failureMap : true;
 }
开发者ID:omarcl,项目名称:training-spot,代码行数:51,代码来源:BaseArticle.php

示例7: testScenarioUsingQuery


//.........这里部分代码省略.........
     $r->setReviewDate($control);
     $r->save();
     $r2 = ReviewQuery::create()->findPk($r_id);
     $this->assertEquals(new Datetime('2004-02-29 00:00:00'), $r2->getReviewDate(null), 'ability to fetch DateTime');
     $this->assertEquals($control, $r2->getReviewDate('U'), 'ability to fetch native unix timestamp');
     $this->assertEquals('2-29-2004', $r2->getReviewDate('n-j-Y'), 'ability to use date() formatter');
     // Handle BLOB/CLOB Columns
     // ------------------------
     $blob_path = dirname(__FILE__) . '/../../etc/lob/tin_drum.gif';
     $blob2_path = dirname(__FILE__) . '/../../etc/lob/propel.gif';
     $clob_path = dirname(__FILE__) . '/../../etc/lob/tin_drum.txt';
     $m1 = new Media();
     $m1->setBook($phoenix);
     $m1->setCoverImage(file_get_contents($blob_path));
     $m1->setExcerpt(file_get_contents($clob_path));
     $m1->save();
     $m1_id = $m1->getId();
     $m1_lookup = MediaQuery::create()->findPk($m1_id);
     $this->assertNotNull($m1_lookup, 'Can find just-created media item');
     $this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m1_lookup->getCoverImage())), 'BLOB was correctly updated');
     $this->assertEquals(file_get_contents($clob_path), (string) $m1_lookup->getExcerpt(), 'CLOB was correctly updated');
     // now update the BLOB column and save it & check the results
     $m1_lookup->setCoverImage(file_get_contents($blob2_path));
     $m1_lookup->save();
     $m2_lookup = MediaQuery::create()->findPk($m1_id);
     $this->assertNotNull($m2_lookup, 'Can find just-created media item');
     $this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2_lookup->getCoverImage())), 'BLOB was correctly overwritten');
     // Test Validators
     // ---------------
     require_once 'tools/helpers/bookstore/validator/ISBNValidator.php';
     $bk1 = new Book();
     $bk1->setTitle("12345");
     // min length is 10
     $ret = $bk1->validate();
     $this->assertFalse($ret, 'validation failed');
     $failures = $bk1->getValidationFailures();
     $this->assertEquals(1, count($failures), '1 validation message was returned');
     $el = array_shift($failures);
     $this->assertContains("must be more than", $el->getMessage(), 'Expected validation message was returned');
     $bk2 = new Book();
     $bk2->setTitle("Don Juan");
     $ret = $bk2->validate();
     $this->assertFalse($ret, 'validation failed');
     $failures = $bk2->getValidationFailures();
     $this->assertEquals(1, count($failures), '1 validation message was returned');
     $el = array_shift($failures);
     $this->assertContains("Book title already in database.", $el->getMessage(), 'Expected validation message was returned');
     //Now trying some more complex validation.
     $auth1 = new Author();
     $auth1->setFirstName("Hans");
     // last name required; will fail
     $bk1->setAuthor($auth1);
     $rev1 = new Review();
     $rev1->setReviewDate("08/09/2001");
     // will fail: reviewed_by column required
     $bk1->addReview($rev1);
     $ret2 = $bk1->validate();
     $this->assertFalse($ret2, 'validation failed');
     $failures2 = $bk1->getValidationFailures();
     $this->assertEquals(3, count($failures2), '3 validation messages were returned');
     $expectedKeys = array(AuthorPeer::LAST_NAME, BookPeer::TITLE, ReviewPeer::REVIEWED_BY);
     $this->assertEquals($expectedKeys, array_keys($failures2), 'correct columns failed');
     $bk2 = new Book();
     $bk2->setTitle("12345678901");
     // passes
     $auth2 = new Author();
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:67,代码来源:BookstoreTest.php

示例8: Author

    // passes
    $auth2 = new Author();
    $auth2->setLastName("Blah");
    //passes
    $auth2->setEmail("some@body.com");
    //passes
    $auth2->setAge(50);
    //passes
    $bk2->setAuthor($auth2);
    $rev2 = new Review();
    $rev2->setReviewedBy("Me!");
    // passes
    $rev2->setStatus("new");
    // passes
    $bk2->addReview($rev2);
    $ret3 = $bk2->validate();
    print "Making sure complex validation can pass: ";
    print boolTest($ret3 === true);
} catch (Exception $e) {
    die("Error doing validation tests: " . $e->__toString());
}
// Test doCount()
//
try {
    print "\nTesting doCount() functionality\n";
    print "-------------------------------\n\n";
    $c = new Criteria();
    $records = BookPeer::doSelect($c);
    $count = BookPeer::doCount($c);
    print "Making sure correct number of results: ";
    print boolTest(count($records) === $count);
开发者ID:yasirgit,项目名称:afids,代码行数:31,代码来源:bookstore-test.php

示例9: testDoValidate_CustomValidator

 public function testDoValidate_CustomValidator()
 {
     $book = new Book();
     $book->setTitle("testDoValidate_CustomValidator");
     // (valid)
     $book->setISBN("Foo.Bar.Baz");
     // (invalid)
     $res = $book->validate();
     $this->assertFalse($res, "Expected validation to fail.");
     $failures = $book->getValidationFailures();
     $this->assertEquals(1, count($failures), "Expected 1 column to fail validation.");
     $this->assertEquals(array(BookPeer::ISBN), array_keys($failures), "Expected EMAIL to fail validation.");
     $validator = $failures[BookPeer::ISBN]->getValidator();
     $this->assertType('ISBNValidator', $validator, "Expected validator that failed to be ISBNValidator");
 }
开发者ID:nhemsley,项目名称:propel,代码行数:15,代码来源:ValidatorTest.php

示例10: testSpeed


//.........这里部分代码省略.........
     $results = BookPeer::doSelect($crit);
     // Perform a lookup & update!
     // --------------------------
     $qs_lookup = BookPeer::retrieveByPk($qs_id);
     $new_title = "Quicksilver (" . crc32(uniqid(rand())) . ")";
     $qs_lookup->setTitle($new_title);
     $qs_lookup->save();
     $qs_lookup2 = BookPeer::retrieveByPk($qs_id);
     // Test some basic DATE / TIME stuff
     // ---------------------------------
     // that's the control timestamp.
     $control = strtotime('2004-02-29 00:00:00');
     // should be two in the db
     $r = ReviewPeer::doSelectOne(new Criteria());
     $r_id = $r->getId();
     $r->setReviewDate($control);
     $r->save();
     $r2 = ReviewPeer::retrieveByPk($r_id);
     // Testing the DATE/TIME columns
     // -----------------------------
     // that's the control timestamp.
     $control = strtotime('2004-02-29 00:00:00');
     // should be two in the db
     $r = ReviewPeer::doSelectOne(new Criteria());
     $r_id = $r->getId();
     $r->setReviewDate($control);
     $r->save();
     $r2 = ReviewPeer::retrieveByPk($r_id);
     // Testing the column validators
     // -----------------------------
     $bk1 = new Book();
     $bk1->setTitle("12345");
     // min length is 10
     $ret = $bk1->validate();
     // Unique validator
     $bk2 = new Book();
     $bk2->setTitle("Don Juan");
     $ret = $bk2->validate();
     // Now trying some more complex validation.
     $auth1 = new Author();
     $auth1->setFirstName("Hans");
     // last name required; will fail
     $bk1->setAuthor($auth1);
     $rev1 = new Review();
     $rev1->setReviewDate("08/09/2001");
     // will fail: reviewed_by column required
     $bk1->addReview($rev1);
     $ret2 = $bk1->validate();
     $bk2 = new Book();
     $bk2->setTitle("12345678901");
     // passes
     $auth2 = new Author();
     $auth2->setLastName("Blah");
     //passes
     $auth2->setEmail("some@body.com");
     //passes
     $auth2->setAge(50);
     //passes
     $bk2->setAuthor($auth2);
     $rev2 = new Review();
     $rev2->setReviewedBy("Me!");
     // passes
     $rev2->setStatus("new");
     // passes
     $bk2->addReview($rev2);
     $ret3 = $bk2->validate();
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:67,代码来源:speed.php

示例11: actionManual

 public function actionManual()
 {
     $book = new Book();
     $thesis = new Thesis();
     $journal = new Journal();
     $proceeding = new Proceeding();
     if (isset($_POST['Book'])) {
         $book->attributes = $_POST['Book'];
         if ($book->validate()) {
             $data['citation'] = $book->formatCitation();
             $data['inline'] = $book->formatInlineCitation();
             $data['oid'] = $this->saveSubmission('book-manual', $book);
         }
     }
     if (isset($_POST['Thesis'])) {
         $thesis->attributes = $_POST['Thesis'];
         if ($thesis->validate()) {
             $data['citation'] = $thesis->formatCitation();
             $data['inline'] = $thesis->formatInlineCitation();
             $data['oid'] = $this->saveSubmission('thesis-manual', $thesis);
         }
     }
     if (isset($_POST['Journal'])) {
         $journal->attributes = $_POST['Journal'];
         if ($journal->validate()) {
             $data['citation'] = $journal->formatCitation();
             $data['inline'] = $journal->formatInlineCitation();
             $data['oid'] = $this->saveSubmission('journal-article-manual', $journal);
         }
     }
     if (isset($_POST['Proceeding'])) {
         $proceeding->attributes = $_POST['Proceeding'];
         if ($proceeding->validate()) {
             $data['citation'] = $proceeding->formatCitation();
             $data['inline'] = $proceeding->formatInlineCitation();
             $data['oid'] = $this->saveSubmission('proceedings-article-manual', $proceeding);
         }
     }
     $data['book'] = $book;
     $data['thesis'] = $thesis;
     $data['journal'] = $journal;
     $data['proceeding'] = $proceeding;
     $this->render('form', $data);
 }
开发者ID:ardhimaarik,项目名称:dapus-generator,代码行数:44,代码来源:SiteController.php


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