コード例 #1
0
 /**
  * Instantiates a new InstantArticleStatus object.
  *
  * @param string $status
  * @param ServerMessage[] $messages
  */
 public function __construct($status, $messages = [])
 {
     Type::enforceWithin($status, [self::SUCCESS, self::NOT_FOUND, self::IN_PROGRESS, self::FAILED, self::UNKNOWN]);
     Type::enforceArrayOf($messages, ServerMessage::getClassName());
     $this->status = $status;
     $this->messages = $messages;
 }
コード例 #2
0
 public function withProperties($properties, $configuration)
 {
     Type::enforceArrayOf($properties, Type::STRING);
     foreach ($properties as $property) {
         $this->withProperty($property, self::retrieveProperty($configuration, $property));
     }
 }
コード例 #3
0
 /**
  * Sets the text content of the credits
  *
  * @param string|string[]|Paragraph[] $credits - A list of paragraphs or a single string for the content of the credit.
  *
  * @return $this
  */
 public function withCredits($credits)
 {
     Type::enforce($credits, [Type::ARRAY_TYPE, Paragraph::getClassName(), Type::STRING]);
     // Checks if it is array to apply the enforce of param types as documented.
     if (Type::is($credits, Type::ARRAY_TYPE)) {
         if (!Type::isArrayOf($credits, Type::STRING) && !Type::isArrayOf($credits, Paragraph::getClassName())) {
             Type::enforceArrayOf($credits, Type::STRING);
             Type::enforceArrayOf($credits, Paragraph::getClassName());
         }
     }
     $this->credits = $credits;
     return $this;
 }
コード例 #4
0
 /**
  * Sets all items of the list as the array on the parameter
  *
  * @param string|[]ListItem[] $new_items The new items. Replaces all items from the list
  *
  * @return $this
  */
 public function withItems($new_items)
 {
     Type::enforceArrayOf($new_items, [ListItem::getClassName(), Type::STRING]);
     $this->items = [];
     foreach ($new_items as $new_item) {
         $this->addItem($new_item);
     }
     return $this;
 }
コード例 #5
0
 public function testIsNotArrayInInheritanceException()
 {
     $this->setExpectedException('InvalidArgumentException');
     Type::enforceArrayOf([Image::create(), Video::create()], Image::getClassName());
 }
コード例 #6
0
 /**
  * Replace all ads within this Article
  *
  * @param Ad[] $ads All the ads
  *
  * @return $this
  */
 public function withAds($ads)
 {
     Type::enforceArrayOf($ads, Ad::getClassName());
     $this->ads = $ads;
     return $this;
 }
コード例 #7
0
 /**
  * Overrides all rules already set in this transformer instance.
  *
  * @return Rule[] List of configured rules.
  */
 public function setRules($rules)
 {
     // Do not receive internal map, just a plain list
     // to keep the interface backwards compatible.
     Type::enforceArrayOf($rules, Rule::getClassName());
     $this->resetRules();
     foreach ($rules as $rule) {
         $this->addRule($rule);
     }
 }
コード例 #8
0
 /**
  * Sets the Image list of images for the slideshow. It is REQUIRED.
  *
  * @param Image[] The images. Ie: http://domain.com/img.png
  *
  * @return $this
  */
 public function withImages($article_images)
 {
     Type::enforceArrayOf($article_images, Image::getClassName());
     $this->article_images = $article_images;
     return $this;
 }