├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── autoload.php ├── composer.json ├── examples ├── PublisherAPI │ ├── DeleteArticle.php │ ├── GetArticle.php │ ├── GetChannel.php │ ├── GetSection.php │ ├── GetSections.php │ ├── PostArticle.php │ └── UpdateArticle.php └── README.md ├── src ├── Document.php ├── Document │ ├── AdvertisingSettings.php │ ├── Anchor.php │ ├── Animations │ │ ├── ComponentAnimations │ │ │ ├── AppearAnimation.php │ │ │ ├── ComponentAnimation.php │ │ │ ├── FadeInAnimation.php │ │ │ ├── MoveInAnimation.php │ │ │ └── ScaleFadeAnimation.php │ │ └── Scenes │ │ │ ├── FadingStickyHeader.php │ │ │ ├── ParallaxScaleHeader.php │ │ │ └── Scene.php │ ├── Base.php │ ├── Behaviors │ │ ├── BackgroundMotion.php │ │ ├── BackgroundParallax.php │ │ ├── Behavior.php │ │ ├── Motion.php │ │ ├── Parallax.php │ │ └── Springy.php │ ├── CaptionDescriptor.php │ ├── Components │ │ ├── Advertisements │ │ │ ├── BannerAdvertisement.php │ │ │ └── MediumRectangleAdvertisement.php │ │ ├── Audio.php │ │ ├── Author.php │ │ ├── Body.php │ │ ├── Byline.php │ │ ├── Caption.php │ │ ├── Chapter.php │ │ ├── Component.php │ │ ├── ComponentNested.php │ │ ├── Container.php │ │ ├── Divider.php │ │ ├── EmbedWebVideo.php │ │ ├── FacebookPost.php │ │ ├── Figure.php │ │ ├── Gallery.php │ │ ├── Header.php │ │ ├── Heading.php │ │ ├── Illustrator.php │ │ ├── Image.php │ │ ├── Instagram.php │ │ ├── Intro.php │ │ ├── Logo.php │ │ ├── Mosaic.php │ │ ├── Music.php │ │ ├── Photo.php │ │ ├── Photographer.php │ │ ├── Portrait.php │ │ ├── Pullquote.php │ │ ├── Quote.php │ │ ├── ScalableImage.php │ │ ├── Section.php │ │ ├── Text.php │ │ ├── Title.php │ │ ├── Tweet.php │ │ ├── Video.php │ │ └── VinePost.php │ ├── ContentInset.php │ ├── GalleryItem.php │ ├── Layouts │ │ ├── AdvertisingLayout.php │ │ ├── ComponentLayout.php │ │ └── Layout.php │ ├── Margin.php │ ├── Markdown.php │ ├── Metadata.php │ └── Styles │ │ ├── Border.php │ │ ├── ComponentStyle.php │ │ ├── ComponentTextStyle.php │ │ ├── DocumentStyle.php │ │ ├── DropCapStyle.php │ │ ├── Fills │ │ ├── Fill.php │ │ ├── Gradients │ │ │ ├── ColorStop.php │ │ │ ├── GradientFill.php │ │ │ └── LinearGradientFill.php │ │ ├── ImageFill.php │ │ └── VideoFill.php │ │ ├── InlineTextStyle.php │ │ ├── Offset.php │ │ ├── ShadowStyle.php │ │ ├── StrokeStyle.php │ │ ├── TextStrokeStyle.php │ │ └── TextStyle.php ├── PublisherAPI.php └── PublisherAPI │ ├── Base.php │ └── Curl.php └── tests ├── Document ├── AdvertisingSettingsTest.php ├── AnchorTest.php ├── Animations │ └── ComponentAnimations │ │ ├── AppearAnimationTest.php │ │ ├── FadeInAnimationTest.php │ │ ├── MoveInAnimationTest.php │ │ └── ScaleFadeAnimationTest.php ├── BaseTest.php ├── Behaviors │ ├── BackgroundMotionTest.php │ ├── BackgroundParallaxTest.php │ ├── MotionTest.php │ ├── ParallaxTest.php │ └── SpringyTest.php ├── Components │ ├── AuthorTest.php │ ├── BodyTest.php │ ├── BylineTest.php │ ├── CaptionTest.php │ ├── ComponentTest.php │ ├── ContainerBaseTest.php │ ├── ContainerTest.php │ ├── FacebookPostTest.php │ ├── HeaderTest.php │ ├── HeadingTest.php │ ├── IllustratorTest.php │ ├── ImageTest.php │ ├── IntroTest.php │ ├── PhotographerTest.php │ ├── PullquoteTest.php │ ├── QuoteTest.php │ ├── TextTest.php │ ├── TitleTest.php │ ├── TweetTest.php │ └── VinePostTest.php ├── ContentInsetTest.php ├── Layouts │ ├── AdvertisingLayoutTest.php │ ├── ComponentLayoutTest.php │ └── LayoutTest.php ├── MarginTest.php ├── MarkdownTest.php ├── MetadataTest.php └── Styles │ ├── BorderTest.php │ ├── ComponentStyleTest.php │ ├── ComponentTextStyleTest.php │ ├── DropCapStyleTest.php │ ├── Fills │ ├── FillTest.php │ ├── Gradients │ │ ├── ColorStopTest.php │ │ ├── GradientFillTest.php │ │ └── LinearGradientFillTest.php │ ├── ImageFillTest.php │ └── VideoFillTest.php │ ├── InlineTextStyleTest.php │ ├── OffsetTest.php │ ├── ShadowStyleTest.php │ ├── StrokeStyleTest.php │ ├── TextStrokeStyleTest.php │ └── TextStyleTest.php ├── DocumentTest.php ├── PublisherAPI └── article.json └── PublisherAPITest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /composer.phar 2 | /vendor 3 | composer.lock 4 | src/local/* -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - 5.4 4 | - 5.5 5 | - 5.6 6 | dist: trusty 7 | before_script: 8 | - composer self-update 9 | - composer install --prefer-source --no-interaction --dev 10 | script: "./vendor/bin/phpunit --bootstrap vendor/autoload.php tests" 11 | notifications: 12 | slack: 13 | secure: KhXa8DPSNEc5B+frlL1jgwnJKjW724bcCP2AqrhWlCpcGxfM3Uvx4Mphu5PBSmEUDbgs7r4QbPFyNFPpqy28UJJxxR2UAhIH1MKDvqm+M1egOq8lS9vgv5uHXp6TV2q4qXhGVJP8Rls0FRooXeZZKNKwjpUK3bDGHgZQYJeId0tab/UqYl7jbQovUlNAsbxgyu+ZNvSts4sMc7tkYbtgW3Dq04GHkVqwuYRtci8BnsY/RQxamebCNiHLmC6KBdJIuNI/gcq+NTFy2y5TKtWxeQ+GjVxT3lJ1LrBURQHSkAsWNa+Yp0fEaXJOfZZQtuDGI6s4AYewjSQCrQ54tX66OzOujAzpkfU3mGp7RJxIhutudrTXDuBZkV8ukHmrsINaXVOw70thdlpr62vbYvV7kmcjSlwx3i+JuHqRxleY3JC0VIvVTJiySIrDyQrXl/gsCfS7EIZ3gDyvVbLcM/8j+IMpShiCnAAmg4JQPfM2i03IzHzfH08SGTYJhmOl26ZB8ltsstzlF0T1O2eRNSsnexRfR0OKaixiwuRSR1G4Aj86wH9WYpoArKx6XwT7c0PqWgvla+XM3CGvXaAeQzrsIASFo/FAQDMDobrAzrj9I9l9J0EVYDJjn5vgZswqvEmK2P9G2RLL8QPJCB3D8SiiZytlV+d+9KvUXnuYSsi09NU= 14 | 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Chapter Three, Inc 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AppleNewsAPI 2 | 3 | [![Travis CI build status](https://travis-ci.org/chapter-three/AppleNewsAPI.svg?branch=master)](https://travis-ci.org/chapter-three/AppleNewsAPI) 4 | 5 | `AppleNewsAPI\PublisherAPI` is a PHP library that allows you to publish content to Apple News. You can also retrieve and delete articles you’ve already published, and get basic information about your channel and sections. 6 | 7 | `AppleNewsAPI\Document` is a PHP library that helps construct documents in the [Apple News JSON format](https://developer.apple.com/library/ios/documentation/General/Conceptual/Apple_News_Format_Ref/). 8 | 9 | [API Documentation](http://chapter-three.github.io/AppleNewsAPI/) 10 | 11 | ## Installation 12 | 13 | ```shell 14 | composer require chapter-three/apple-news-api 15 | ``` 16 | 17 | or 18 | 19 | ```shell 20 | git clone git@github.com:chapter-three/AppleNewsAPI.git 21 | cd AppleNewsAPI 22 | curl -sS https://getcomposer.org/installer | php 23 | ./composer.phar install 24 | ``` 25 | 26 | ## Document class Quick Start and Examples 27 | 28 | ```php 29 | use ChapterThree\AppleNewsAPI\Document; 30 | use ChapterThree\AppleNewsAPI\Document\Components\Body; 31 | use ChapterThree\AppleNewsAPI\Document\Layouts\Layout; 32 | use ChapterThree\AppleNewsAPI\Document\Styles\ComponentTextStyle; 33 | 34 | $obj = new Document(uniqid(), 'title', 'en', new Layout(7, 1024)); 35 | $obj->addComponent(new Body('body text')) 36 | ->addComponentTextStyle('default', new ComponentTextStyle()); 37 | 38 | $json = $obj->json(); 39 | ``` 40 | 41 | ## PublisherAPI class Quick Start and Examples 42 | 43 | ```php 44 | $api_key_id = ""; 45 | $api_key_secret = ""; 46 | $endpoint = "https://endpoint_url"; 47 | 48 | $PublisherAPI = new ChapterThree\AppleNewsAPI\PublisherAPI( 49 | $api_key_id, 50 | $api_key_secret, 51 | $endpoint 52 | ); 53 | ``` 54 | 55 | ##### GET Channel 56 | 57 | ```php 58 | // Fetches information about a channel. 59 | $response = $PublisherAPI->get('/channels/{channel_id}', 60 | [ 61 | 'channel_id' => CHANNEL_ID 62 | ] 63 | ); 64 | ``` 65 | 66 | ##### GET Sections 67 | 68 | ```php 69 | // Fetches a list of all sections for a channel. 70 | $response = $PublisherAPI->get('/channels/{channel_id}/sections', 71 | [ 72 | 'channel_id' => CHANNEL_ID 73 | ] 74 | ); 75 | ``` 76 | 77 | ##### GET Section 78 | 79 | ```php 80 | // Fetches information about a single section. 81 | $response = $PublisherAPI->get('/sections/{section_id}', 82 | [ 83 | 'section_id' => SECTION_ID 84 | ] 85 | ); 86 | ``` 87 | 88 | ##### GET Article 89 | 90 | ```php 91 | // Fetches an article. 92 | $response = $PublisherAPI->get('/articles/{article_id}', 93 | [ 94 | 'article_id' => ARTICLE_ID 95 | ] 96 | ); 97 | ``` 98 | 99 | ##### POST Article 100 | 101 | ```php 102 | // Publishes a new article to a channel. 103 | // $response contains an article ID and revision ID. 104 | $response = $PublisherAPI->post('/channels/{channel_id}/articles', 105 | [ 106 | 'channel_id' => CHANNEL_ID 107 | ], 108 | [ 109 | // List of files to POST 110 | 'files' => [], // optional. A list of article assets [uri => path] 111 | // JSON metadata string 112 | 'metadata' => $metadata, // required 113 | 'json' => '', // required. Apple News Native formatted JSON string. 114 | ] 115 | ); 116 | ``` 117 | 118 | ##### UPDATE Article 119 | 120 | ```php 121 | // Metadata information `revision` is required. 122 | $metadata = json_encode([ 123 | 'data' => [ 124 | 'revision' => REVISION_ID 125 | ] 126 | ]); 127 | // Updates an existing article. 128 | // See $response variable to get a new revision ID. 129 | $response = $PublisherAPI->post('/articles/{article_id}', 130 | [ 131 | 'article_id' => ARTICLE_ID 132 | ], 133 | [ 134 | // List of files to POST 135 | 'files' => [], // optional. A list of article assets [uri => path] 136 | // JSON metadata string 137 | 'metadata' => $metadata, // required 138 | // Apple News Native formatted JSON string. See examples. 139 | 'json' => '', // required. 140 | ] 141 | ); 142 | ``` 143 | 144 | ##### DELETE Article 145 | 146 | ```php 147 | // Deletes an article. 148 | $response = $PublisherAPI->delete('/articles/{article_id}', 149 | [ 150 | 'article_id' => ARTICLE_ID 151 | ] 152 | ); 153 | ``` 154 | 155 | ## Contribute 156 | 157 | ### Run Unit Tests 158 | 159 | ```shell 160 | ./vendor/bin/phpunit -v --colors=auto --bootstrap vendor/autoload.php tests 161 | ``` 162 | 163 | To test PublisherAPI GET/POST/DELETE methods use the following pattern: 164 | 165 | ```shell 166 | ./vendor/bin/phpunit -v --colors=auto --bootstrap vendor/autoload.php 167 | tests/PublisherAPITest.php [API_KEY] [API_SECRET] [ENDPOINT_URL] [METHOD] [ENDPOINT_PATH] 168 | ``` 169 | 170 | ### Generate PHPDoc 171 | 172 | ```shell 173 | git clone --branch gh-pages git@github.com:chapter-three/AppleNewsAPI.git ../AppleNewsAPI_phpdoc 174 | ./vendor/bin/phpdoc run --title='chapter-three/apple-news-api v'$(cat composer.json | jq -r '.version') -d ./ -i vendor/,tests/ -t ../AppleNewsAPI_phpdoc 175 | ``` 176 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name" : "chapter-three/apple-news-api", 3 | "type": "library", 4 | "description": "Push content to Apple News.", 5 | "keywords": ["apple", "push", "news", "api"], 6 | "version": "0.3.11", 7 | "homepage": "https://github.com/chapter-three/AppleNewsAPI", 8 | "license": "MIT", 9 | "require": { 10 | "php": ">=5.4.0", 11 | "php-curl-class/php-curl-class": "^4.6" 12 | }, 13 | "require-dev": { 14 | "mikey179/vfsstream": "1.5.*", 15 | "phpunit/phpunit": "4.7.*", 16 | "phpdocumentor/phpdocumentor": "~2.8" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "ChapterThree\\AppleNewsAPI\\": "src/" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /examples/PublisherAPI/DeleteArticle.php: -------------------------------------------------------------------------------- 1 | Delete('/articles/{article_id}', 24 | [ 25 | 'article_id' => '[ARTICLE_ID]' 26 | ] 27 | ); 28 | -------------------------------------------------------------------------------- /examples/PublisherAPI/GetArticle.php: -------------------------------------------------------------------------------- 1 | Get('/articles/{article_id}', 24 | [ 25 | 'article_id' => '[ARTICLE_ID]' 26 | ] 27 | ); 28 | -------------------------------------------------------------------------------- /examples/PublisherAPI/GetChannel.php: -------------------------------------------------------------------------------- 1 | Get('/channels/{channel_id}', 24 | [ 25 | 'channel_id' => '[CHANNEL_ID]' 26 | ] 27 | ); 28 | -------------------------------------------------------------------------------- /examples/PublisherAPI/GetSection.php: -------------------------------------------------------------------------------- 1 | Get('/sections/{section_id}', 24 | [ 25 | 'section_id' => '[SECTION_ID]' 26 | ] 27 | ); 28 | -------------------------------------------------------------------------------- /examples/PublisherAPI/GetSections.php: -------------------------------------------------------------------------------- 1 | Get('/channels/{channel_id}/sections', 24 | [ 25 | 'channel_id' =>'[CHANNEL_ID]' 26 | ] 27 | ); 28 | -------------------------------------------------------------------------------- /examples/PublisherAPI/PostArticle.php: -------------------------------------------------------------------------------- 1 | [ 28 | 'isSponsored' => true, 29 | 'links' => [ 30 | 'sections' => [ 31 | 'https://endpoint_url/sections/{your_section_id}', 32 | ], 33 | ], 34 | ], 35 | ]; 36 | 37 | // Publishes a new article to a channel. 38 | $response = $PublisherAPI->Post('/channels/{channel_id}/articles', 39 | [ 40 | 'channel_id' => '[CHANNEL_ID]' 41 | ], 42 | [ 43 | // required. Apple News Native formatted JSON string. 44 | 'json' => '{"version":"0.10.13","identifier":"10","title":"Test article","language":"en","layout":{"columns":7,"width":1024},"components":[{"text":"Test article content\n\n","format":"markdown","role":"body"},{"URL":"bundle:\/\/article.jpg","role":"photo"}],"componentTextStyles":{"default":{}}}', 45 | // List of files to POST 46 | 'files' => [ 47 | 'bundle://article.jpg' => __DIR__ . '/files/article.jpg', 48 | ], // optional 49 | // JSON metadata string 50 | 'metadata' => json_encode($metadata, JSON_UNESCAPED_SLASHES), // optional 51 | ] 52 | ); 53 | -------------------------------------------------------------------------------- /examples/PublisherAPI/UpdateArticle.php: -------------------------------------------------------------------------------- 1 | [ 28 | 'isSponsored' => true, 29 | 'links' => [ 30 | 'sections' => [ 31 | 'https://endpoint_url/sections/{your_section_id}', 32 | ], 33 | ], 34 | 'revision' => REVISION_ID // required. 35 | ], 36 | ]; 37 | 38 | // Updates an existing article. 39 | // See $response variable to get a new revision ID. 40 | $response = $PublisherAPI->post('/articles/{article_id}', 41 | [ 42 | 'article_id' => ARTICLE_ID 43 | ], 44 | [ 45 | // required. Apple News Native formatted JSON string. 46 | 'json' => '{"version":"0.10.13","identifier":"10","title":"Test article","language":"en","layout":{"columns":7,"width":1024},"components":[{"text":"Test article content\n\n","format":"markdown","role":"body"},{"URL":"bundle:\/\/article.jpg","role":"photo"}],"componentTextStyles":{"default":{}}}', 47 | // List of files to POST 48 | 'files' => [ 49 | 'bundle://article.jpg' => __DIR__ . '/files/article.jpg', 50 | ], // optional 51 | // JSON metadata string 52 | 'metadata' => json_encode($metadata, JSON_UNESCAPED_SLASHES), // optional 53 | ] 54 | ); 55 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | 3 | This directory contains usage examples of `AppleNewsAPI\PublisherAPI` and `AppleNewsAPI\Document` PHP libraries. 4 | -------------------------------------------------------------------------------- /src/Document/AdvertisingSettings.php: -------------------------------------------------------------------------------- 1 | bannerType; 41 | } 42 | 43 | /** 44 | * Setting for bannerType. 45 | * 46 | * @param string $bannerType 47 | * The banner type that should be shown. One of 'any', 'standard', 48 | * 'double_height', and 'large'. 49 | * 50 | * @return $this 51 | */ 52 | public function setBannerType($bannerType) { 53 | if (!in_array($bannerType, [ 54 | self::BANNER_TYPE_ANY, 55 | self::BANNER_TYPE_DOUBLE, 56 | self::BANNER_TYPE_LARGE, 57 | self::BANNER_TYPE_STANDARD, 58 | ])) { 59 | $this->triggerError('Invalid value for bannerType advertisingSettings.'); 60 | } 61 | else { 62 | $this->bannerType = $bannerType; 63 | } 64 | return $this; 65 | } 66 | 67 | /** 68 | * Getter for frequency. 69 | */ 70 | public function getFrequency() { 71 | return $this->frequency; 72 | } 73 | 74 | /** 75 | * Setter for frequency. 76 | * 77 | * @param int $frequency 78 | * A number between 0 and 10 defining the frequency for automatically 79 | * inserting advertising components into articles. 80 | * 81 | * @return $this 82 | */ 83 | public function setFrequency($frequency) { 84 | if ($frequency >= 0 && $frequency <= 10) { 85 | $this->frequency = $frequency; 86 | } 87 | else { 88 | $this->triggerError('Invalid value for frequency advertisingSettings.'); 89 | } 90 | return $this; 91 | } 92 | 93 | /** 94 | * Getter for layout. 95 | */ 96 | public function getLayout() { 97 | return $this->layout; 98 | } 99 | 100 | /** 101 | * Setter for layout. 102 | * 103 | * @param AdvertisingLayout $layout 104 | * Layout object that currently supports only margin. 105 | * 106 | * @return $this 107 | */ 108 | public function setLayout(AdvertisingLayout $layout) { 109 | $this->layout = $layout; 110 | return $this; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /src/Document/Anchor.php: -------------------------------------------------------------------------------- 1 | setTargetAnchorPosition($target_anchor_position); 29 | } 30 | 31 | /** 32 | * Define optional properties. 33 | */ 34 | protected function optional() { 35 | return array_merge(parent::optional(), array( 36 | 'originAnchorPosition', 37 | 'targetComponentIdentifier', 38 | 'rangeStart', 39 | 'rangeLength', 40 | )); 41 | } 42 | 43 | /** 44 | * Getter for targetAnchorPosition. 45 | */ 46 | public function getTargetAnchorPosition() { 47 | return $this->targetAnchorPosition; 48 | } 49 | 50 | /** 51 | * Setter for targetAnchorPosition. 52 | * 53 | * @param mixed $value 54 | * TargetAnchorPosition. 55 | * 56 | * @return $this 57 | */ 58 | public function setTargetAnchorPosition($value) { 59 | if ($this->validateTargetAnchorPosition($value)) { 60 | $this->targetAnchorPosition = (string) $value; 61 | } 62 | return $this; 63 | } 64 | 65 | /** 66 | * Getter for originAnchorPosition. 67 | */ 68 | public function getOriginAnchorPosition() { 69 | return $this->originAnchorPosition; 70 | } 71 | 72 | /** 73 | * Setter for originAnchorPosition. 74 | * 75 | * @param mixed $value 76 | * OriginAnchorPosition. 77 | * 78 | * @return $this 79 | */ 80 | public function setOriginAnchorPosition($value) { 81 | $this->originAnchorPosition = (string) $value; 82 | return $this; 83 | } 84 | 85 | /** 86 | * Getter for targetComponentIdentifier. 87 | */ 88 | public function getTargetComponentIdentifier() { 89 | return $this->targetComponentIdentifier; 90 | } 91 | 92 | /** 93 | * Setter for targetComponentIdentifier. 94 | * 95 | * @param mixed $value 96 | * TargetComponentIdentifier. 97 | * 98 | * @return $this 99 | */ 100 | public function setTargetComponentIdentifier($value) { 101 | $this->targetComponentIdentifier = (string) $value; 102 | return $this; 103 | } 104 | 105 | /** 106 | * Getter for rangeStart. 107 | */ 108 | public function getRangeStart() { 109 | return $this->rangeStart; 110 | } 111 | 112 | /** 113 | * Setter for rangeStart. 114 | * 115 | * @param int $value 116 | * RangeStart. 117 | * 118 | * @return $this 119 | */ 120 | public function setRangeStart($value) { 121 | $this->rangeStart = $value; 122 | return $this; 123 | } 124 | 125 | /** 126 | * Getter for rangeLength. 127 | */ 128 | public function getRangeLength() { 129 | return $this->rangeLength; 130 | } 131 | 132 | /** 133 | * Setter for rangeLength. 134 | * 135 | * @param int $value 136 | * RangeLength. 137 | * 138 | * @return $this 139 | */ 140 | public function setRangeLength($value) { 141 | $this->rangeLength = $value; 142 | return $this; 143 | } 144 | 145 | /** 146 | * Implements JsonSerializable::jsonSerialize(). 147 | */ 148 | public function jsonSerialize() { 149 | if (isset($this->rangeStart) && !isset($this->rangeLength)) { 150 | $msg = "If rangeStart is specified, rangeLength is required."; 151 | $this->triggerError($msg); 152 | return NULL; 153 | } 154 | $valid = (!isset($this->targetAnchorPosition) || 155 | $this->validateTargetAnchorPosition($this->targetAnchorPosition)); 156 | if (!$valid) { 157 | return NULL; 158 | } 159 | return parent::jsonSerialize(); 160 | } 161 | 162 | /** 163 | * Validates the targetAnchorPosition attribute. 164 | */ 165 | protected function validateTargetAnchorPosition($value) { 166 | if (!in_array($value, array( 167 | 'top', 168 | 'center', 169 | 'bottom', 170 | )) 171 | ) { 172 | $this->triggerError('targetAnchorPosition is not valid'); 173 | return FALSE; 174 | } 175 | return TRUE; 176 | } 177 | 178 | } 179 | -------------------------------------------------------------------------------- /src/Document/Animations/ComponentAnimations/AppearAnimation.php: -------------------------------------------------------------------------------- 1 | setType($type); 32 | } 33 | 34 | /** 35 | * Define optional properties. 36 | */ 37 | protected function optional() { 38 | return array_merge(parent::optional(), array( 39 | 'userControllable', 40 | )); 41 | } 42 | 43 | /** 44 | * Getter for type. 45 | */ 46 | public function getType() { 47 | return $this->type; 48 | } 49 | 50 | /** 51 | * Setter for type. 52 | * 53 | * Concrete classes are expected to set this explicitly. 54 | * 55 | * @param bool $value 56 | * Type. 57 | * 58 | * @return $this 59 | */ 60 | protected function setType($value) { 61 | $this->type = $value; 62 | return $this; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/Document/Animations/ComponentAnimations/FadeInAnimation.php: -------------------------------------------------------------------------------- 1 | initialAlpha; 41 | } 42 | 43 | /** 44 | * Setter for initialAlpha. 45 | * 46 | * @param float|int $value 47 | * initialAlpha. 48 | * 49 | * @return $this 50 | */ 51 | public function setInitialAlpha($value) { 52 | if ($this->validateInitialAlpha($value)) { 53 | $this->initialAlpha = $value; 54 | } 55 | return $this; 56 | } 57 | 58 | /** 59 | * Getter for userControllable. 60 | */ 61 | public function getUserControllable() { 62 | return $this->userControllable; 63 | } 64 | 65 | /** 66 | * Setter for userControllable. 67 | * 68 | * @param boolean $value 69 | * userControllable. 70 | * 71 | * @return $this 72 | */ 73 | public function setUserControllable($value) { 74 | $this->userControllable = $value; 75 | return $this; 76 | } 77 | 78 | /** 79 | * Implements JsonSerializable::jsonSerialize(). 80 | */ 81 | public function jsonSerialize() { 82 | $valid = !isset($this->initialAlpha) || 83 | $this->validateInitialAlpha($this->initialAlpha); 84 | if (!$valid) { 85 | return NULL; 86 | } 87 | return parent::jsonSerialize(); 88 | } 89 | 90 | /** 91 | * Validates the initialAlpha attribute. 92 | */ 93 | protected function validateInitialAlpha($value) { 94 | if (!$this->isUnitInterval($value)) { 95 | $this->triggerError('initialAlpha is not a Unit Interval'); 96 | return FALSE; 97 | } 98 | return TRUE; 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/Document/Animations/ComponentAnimations/MoveInAnimation.php: -------------------------------------------------------------------------------- 1 | preferredStartingPosition; 38 | } 39 | 40 | /** 41 | * Setter for preferredStartingPosition. 42 | * 43 | * @param mixed $value 44 | * preferredStartingPosition. 45 | * 46 | * @return $this 47 | */ 48 | public function setPreferredStartingPosition($value) { 49 | if ($this->validatePreferredStartingPosition($value)) { 50 | $this->preferredStartingPosition = $value; 51 | } 52 | return $this; 53 | } 54 | 55 | /** 56 | * Implements JsonSerializable::jsonSerialize(). 57 | */ 58 | public function jsonSerialize() { 59 | $valid = !isset($this->preferredStartingPosition) || 60 | $this->validatePreferredStartingPosition($this->preferredStartingPosition); 61 | if (!$valid) { 62 | return NULL; 63 | } 64 | return parent::jsonSerialize(); 65 | } 66 | 67 | /** 68 | * Validates the preferredStartingPosition attribute. 69 | */ 70 | protected function validatePreferredStartingPosition($value) { 71 | if (!in_array($value, array('left', 'right'))) { 72 | $this->triggerError('preferredStartingPosition not one of "left" or "right"'); 73 | return FALSE; 74 | } 75 | return TRUE; 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/Document/Animations/ComponentAnimations/ScaleFadeAnimation.php: -------------------------------------------------------------------------------- 1 | initialAlpha; 40 | } 41 | 42 | /** 43 | * Setter for initialAlpha. 44 | * 45 | * @param float|int $value 46 | * initialAlpha. 47 | * 48 | * @return $this 49 | */ 50 | public function setInitialAlpha($value) { 51 | if ($this->validateInitialAlpha($value)) { 52 | $this->initialAlpha = $value; 53 | } 54 | return $this; 55 | } 56 | 57 | /** 58 | * Getter for initialScale. 59 | */ 60 | public function getInitialScale() { 61 | return $this->initialScale; 62 | } 63 | 64 | /** 65 | * Setter for initialScale. 66 | * 67 | * @param float $value 68 | * initialScale. 69 | * 70 | * @return $this 71 | */ 72 | public function setInitialScale($value) { 73 | if ($this->validateInitialScale($value)) { 74 | $this->initialScale = $value; 75 | } 76 | return $this; 77 | } 78 | 79 | /** 80 | * Implements JsonSerializable::jsonSerialize(). 81 | */ 82 | public function jsonSerialize() { 83 | $valid = 84 | (!isset($this->initialAlpha) || 85 | $this->validateInitialAlpha($this->initialAlpha)) && 86 | (!isset($this->initialScale) || 87 | $this->validateInitialScale($this->initialScale)); 88 | if (!$valid) { 89 | return NULL; 90 | } 91 | return parent::jsonSerialize(); 92 | } 93 | 94 | /** 95 | * Validates the initialAlpha attribute. 96 | */ 97 | protected function validateInitialAlpha($value) { 98 | if (!$this->isUnitInterval($value)) { 99 | $this->triggerError('initialAlpha is not a Unit Interval'); 100 | return FALSE; 101 | } 102 | return TRUE; 103 | } 104 | 105 | /** 106 | * Validates the initialScale attribute. 107 | */ 108 | protected function validateInitialScale($value) { 109 | if (!$this->isUnitInterval($value)) { 110 | $this->triggerError('initialScale is not a Unit Interval'); 111 | return FALSE; 112 | } 113 | return TRUE; 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /src/Document/Animations/Scenes/FadingStickyHeader.php: -------------------------------------------------------------------------------- 1 | setType($type); 29 | } 30 | 31 | /** 32 | * Getter for type. 33 | */ 34 | public function getType() { 35 | return $this->type; 36 | } 37 | 38 | /** 39 | * Setter for type. 40 | * 41 | * Concrete classes are expected to set this explicitly. 42 | * 43 | * @param bool $value 44 | * Type. 45 | * 46 | * @return $this 47 | */ 48 | protected function setType($value) { 49 | $this->type = $value; 50 | return $this; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/Document/Base.php: -------------------------------------------------------------------------------- 1 | optional()); 40 | foreach ($names as $name) { 41 | if (!isset($out[$name]) || !$present($out[$name])) { 42 | $this->triggerError("Missing required attribute ${name}."); 43 | return NULL; 44 | } 45 | } 46 | 47 | // Unset optional attributes. 48 | $names = array_intersect($this->optional(), array_keys($out)); 49 | foreach ($names as $name) { 50 | if (!$present($out[$name])) { 51 | unset($out[$name]); 52 | } 53 | } 54 | 55 | // Return empty object, not array. 56 | if (empty($out)) { 57 | return new \stdClass(); 58 | } 59 | 60 | return $out; 61 | } 62 | 63 | /** 64 | * Implements __toString(). 65 | */ 66 | public function __toString() { 67 | return json_encode($this, JSON_UNESCAPED_SLASHES); 68 | } 69 | 70 | /** 71 | * Generates json representation. 72 | * 73 | * @return bool|string 74 | * JSON string, or FALSE on error. 75 | */ 76 | public function json() { 77 | $out = (string) $this; 78 | return $out == 'null' ? FALSE : $out; 79 | } 80 | 81 | /** 82 | * Define optional properties. 83 | */ 84 | protected function optional() { 85 | return array(); 86 | } 87 | 88 | /** 89 | * Helper function to determine if a value is suffixed by a supported unit. 90 | * 91 | * @param mixed $value 92 | * Value. 93 | * 94 | * @return bool 95 | * Result. 96 | */ 97 | protected static function isSupportedUnit($value) { 98 | $units = array( 99 | 'vh', 100 | 'vw', 101 | 'vmin', 102 | 'vmax', 103 | 'gut', 104 | 'cw', 105 | 'pt', 106 | ); 107 | $re = '/^(0|[1-9][0-9]*)(' . implode('|', $units) . ')?$/'; 108 | return preg_match($re, $value); 109 | } 110 | 111 | /** 112 | * Helper function to determine if a value is a unit interval. 113 | * 114 | * A unit interval is the closed interval [0,1], that is, the set of all real 115 | * numbers that are greater than or equal to 0 and less than or equal to 1. 116 | * 117 | * @param float|int $value 118 | * Value. 119 | * 120 | * @return bool 121 | * Result. 122 | */ 123 | protected static function isUnitInterval($value) { 124 | if (!is_int($value) && !is_float($value)) { 125 | return FALSE; 126 | } 127 | return 0 <= $value && $value <= 1; 128 | } 129 | 130 | /** 131 | * Helper to validate color hex code. 132 | * 133 | * Valid codes are hexadecimal numbers of length 3, 6 or 8 (with opacity), 134 | * prefixed with "#". 135 | * 136 | * @param string $value 137 | * Value. 138 | * 139 | * @return bool 140 | * Result. 141 | */ 142 | protected static function isHexColor($value) { 143 | return preg_match('/^#[0-9A-F]+$/', $value) && 144 | in_array(strlen($value), array(4, 7, 9)); 145 | } 146 | 147 | /** 148 | * Error handler. 149 | * 150 | * @param string $message 151 | * Message. 152 | * @param int $message_type 153 | * Matching E_USER_ERROR|E_USER_WARNING|E_USER_NOTICE|E_USER_DEPRECATED. 154 | */ 155 | public function triggerError($message, $message_type = E_USER_NOTICE) { 156 | $trace = debug_backtrace(); 157 | trigger_error($message . ' in ' . $trace[0]['file'] . ' on line ' . 158 | $trace[0]['line'], $message_type); 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /src/Document/Behaviors/BackgroundMotion.php: -------------------------------------------------------------------------------- 1 | setType($type); 29 | } 30 | 31 | /** 32 | * Getter for type. 33 | */ 34 | public function getType() { 35 | return $this->type; 36 | } 37 | 38 | /** 39 | * Setter for type. 40 | * 41 | * Concrete classes are expected to set this explicitly. 42 | * 43 | * @param bool $value 44 | * Type. 45 | * 46 | * @return $this 47 | */ 48 | protected function setType($value) { 49 | $this->type = $value; 50 | return $this; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/Document/Behaviors/Motion.php: -------------------------------------------------------------------------------- 1 | factor; 40 | } 41 | 42 | /** 43 | * Setter for factor. 44 | * 45 | * @param float $value 46 | * Factor. 47 | * 48 | * @return $this 49 | */ 50 | public function setFactor($value) { 51 | $this->factor = $value; 52 | return $this; 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/Document/Behaviors/Springy.php: -------------------------------------------------------------------------------- 1 | setText($text); 27 | } 28 | 29 | /** 30 | * {@inheritdoc} 31 | */ 32 | protected function optional() { 33 | return array_merge(parent::optional(), array( 34 | // Note that CaptionDescriptor from Text components in that it is a 35 | // referenced property, not a component. Thus we mark role as optional. 36 | 'role', 37 | 'additions', 38 | )); 39 | } 40 | 41 | /** 42 | * @return mixed 43 | */ 44 | public function getAdditions() { 45 | return $this->additions; 46 | } 47 | 48 | /** 49 | * @param mixed $additions 50 | */ 51 | public function setAdditions($additions) { 52 | $this->additions = $additions; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Document/Components/Advertisements/BannerAdvertisement.php: -------------------------------------------------------------------------------- 1 | bannerType; 43 | } 44 | 45 | /** 46 | * Setter for bannerType. 47 | * 48 | * @param mixed $value 49 | * bannerType. 50 | * 51 | * @return $this 52 | */ 53 | public function setBannerType($value = 'any') { 54 | if ($this->validateBannerType($value)) { 55 | $this->bannerType = $value; 56 | } 57 | return $this; 58 | } 59 | 60 | /** 61 | * Validates the bannerType attribute. 62 | */ 63 | protected function validateBannerType($value) { 64 | if (!in_array($value, ['any', 'standard', 'double_height', 'large'])) { 65 | $this->triggerError('bannerType not one of "any", "standard", "double_height" or "large".'); 66 | return FALSE; 67 | } 68 | return TRUE; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/Document/Components/Advertisements/MediumRectangleAdvertisement.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 35 | } 36 | 37 | /** 38 | * {@inheritdoc} 39 | */ 40 | protected function optional() { 41 | return array_merge(parent::optional(), array( 42 | 'caption', 43 | 'imageURL', 44 | 'accessibilityCaption', 45 | 'explicitContent', 46 | )); 47 | } 48 | 49 | /** 50 | * Getter for url. 51 | */ 52 | public function getUrl() { 53 | return $this->URL; 54 | } 55 | 56 | /** 57 | * Setter for url. 58 | * 59 | * @param mixed $url 60 | * Url. 61 | * 62 | * @return $this 63 | */ 64 | public function setUrl($url) { 65 | $this->URL = $url; 66 | return $this; 67 | } 68 | 69 | /** 70 | * Getter for caption. 71 | */ 72 | public function getCaption() { 73 | return $this->caption; 74 | } 75 | 76 | /** 77 | * Setter for caption. 78 | * 79 | * @param string $value 80 | * Caption. 81 | * 82 | * @return $this 83 | */ 84 | public function setCaption($value) { 85 | $this->caption = (string) $value; 86 | return $this; 87 | } 88 | 89 | /** 90 | * Getter for imageURL. 91 | */ 92 | public function getImageURL() { 93 | return $this->imageURL; 94 | } 95 | 96 | /** 97 | * Setter for imageURL. 98 | * 99 | * @param string $value 100 | * ImageURL. 101 | * 102 | * @return $this 103 | */ 104 | public function setImageURL($value) { 105 | $this->imageURL = (string) $value; 106 | return $this; 107 | } 108 | 109 | /** 110 | * Getter for accessibilityCaption. 111 | */ 112 | public function getAccessibilityCaption() { 113 | return $this->accessibilityCaption; 114 | } 115 | 116 | /** 117 | * Setter for accessibilityCaption. 118 | * 119 | * @param string $value 120 | * AccessibilityCaption. 121 | * 122 | * @return $this 123 | */ 124 | public function setAccessibilityCaption($value) { 125 | $this->accessibilityCaption = (string) $value; 126 | return $this; 127 | } 128 | 129 | /** 130 | * Getter for explicitContent. 131 | */ 132 | public function getExplicitContent() { 133 | return $this->explicitContent; 134 | } 135 | 136 | /** 137 | * Setter for explicitContent. 138 | * 139 | * @param bool $value 140 | * ExplicitContent. 141 | * 142 | * @return $this 143 | */ 144 | public function setExplicitContent($value = false) { 145 | $this->explicitContent = $value; 146 | return $this; 147 | } 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/Document/Components/Author.php: -------------------------------------------------------------------------------- 1 | scene; 44 | } 45 | 46 | /** 47 | * Setter for scene. 48 | * 49 | * @param \ChapterThree\AppleNewsAPI\Document\Animations\Scenes\Scene $scene 50 | * Scene. 51 | * 52 | * @return $this 53 | */ 54 | public function setScene(Scene $scene) { 55 | $this->scene = $scene; 56 | return $this; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/Document/Components/ComponentNested.php: -------------------------------------------------------------------------------- 1 | components; 43 | } 44 | 45 | /** 46 | * Gets nested components as a flattened list. 47 | * 48 | * @return array 49 | * List of \ChapterThree\AppleNewsAPI\Document\Components\Component. 50 | */ 51 | public function getComponentsFlattened() { 52 | $components = []; 53 | foreach ($this->getComponents() as $component) { 54 | $components[] = $component; 55 | /** @var \ChapterThree\AppleNewsAPI\Document\Components\ComponentNested $component */ 56 | if ($component instanceof ComponentNested) { 57 | $descendants = $component->getComponentsFlattened(); 58 | array_merge($components, $descendants); 59 | } 60 | } 61 | return $components; 62 | } 63 | 64 | /** 65 | * Component has a child of a certain type. 66 | */ 67 | public function hasComponentType($class_name) { 68 | /** @var \ChapterThree\AppleNewsAPI\Document\Components\Component $comp */ 69 | foreach ($this->components as $comp) { 70 | if ($comp instanceof $class_name) { 71 | return TRUE; 72 | } 73 | if ($comp instanceof ComponentNested) { 74 | /** @var \ChapterThree\AppleNewsAPI\Document\Components\ComponentNested $comp */ 75 | if ($comp->hasComponentType($class_name)) { 76 | return TRUE; 77 | } 78 | } 79 | } 80 | return FALSE; 81 | } 82 | 83 | /** 84 | * Setter for components. 85 | * 86 | * @param Component $component 87 | * Component. 88 | * 89 | * @return $this 90 | */ 91 | public function addComponent(Component $component) { 92 | $this->components[] = $component; 93 | return $this; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/Document/Components/Container.php: -------------------------------------------------------------------------------- 1 | stroke; 44 | } 45 | 46 | /** 47 | * Setter for Stroke. 48 | * 49 | * @param \ChapterThree\AppleNewsAPI\Document\Styles\StrokeStyle $stroke 50 | * StrokeStyle. 51 | * 52 | * @return $this 53 | */ 54 | public function setStroke(StrokeStyle $stroke) { 55 | $this->stroke = $stroke; 56 | return $this; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/Document/Components/EmbedWebVideo.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 33 | } 34 | 35 | /** 36 | * {@inheritdoc} 37 | */ 38 | protected function optional() { 39 | return array_merge(parent::optional(), array( 40 | 'caption', 41 | 'aspectRatio', 42 | 'accessibilityCaption', 43 | 'explicitContent', 44 | )); 45 | } 46 | 47 | /** 48 | * Getter for url. 49 | */ 50 | public function getUrl() { 51 | return $this->URL; 52 | } 53 | 54 | /** 55 | * Setter for url. 56 | * 57 | * @param mixed $url 58 | * Url. 59 | * 60 | * @return $this 61 | */ 62 | public function setUrl($url) { 63 | $this->URL = $url; 64 | return $this; 65 | } 66 | 67 | /** 68 | * Getter for aspectRatio. 69 | */ 70 | public function getAspectRatio() { 71 | return $this->aspectRatio; 72 | } 73 | 74 | /** 75 | * Setter for aspectRatio. 76 | * 77 | * @param bool $value 78 | * ExplicitContent. 79 | * 80 | * @return $this 81 | */ 82 | public function setAspectRatio($value) { 83 | $this->aspectRatio = $value; 84 | return $this; 85 | } 86 | 87 | /** 88 | * Getter for caption. 89 | */ 90 | public function getCaption() { 91 | return $this->caption; 92 | } 93 | 94 | /** 95 | * Setter for caption. 96 | * 97 | * @param string $value 98 | * Caption. 99 | * 100 | * @return $this 101 | */ 102 | public function setCaption($value) { 103 | $this->caption = (string) $value; 104 | return $this; 105 | } 106 | 107 | /** 108 | * Getter for accessibilityCaption. 109 | */ 110 | public function getAccessibilityCaption() { 111 | return $this->accessibilityCaption; 112 | } 113 | 114 | /** 115 | * Setter for accessibilityCaption. 116 | * 117 | * @param string $value 118 | * AccessibilityCaption. 119 | * 120 | * @return $this 121 | */ 122 | public function setAccessibilityCaption($value) { 123 | $this->accessibilityCaption = (string) $value; 124 | return $this; 125 | } 126 | 127 | /** 128 | * Getter for explicitContent. 129 | */ 130 | public function getExplicitContent() { 131 | return $this->explicitContent; 132 | } 133 | 134 | /** 135 | * Setter for explicitContent. 136 | * 137 | * @param bool $value 138 | * ExplicitContent. 139 | * 140 | * @return $this 141 | */ 142 | public function setExplicitContent($value = false) { 143 | $this->explicitContent = $value; 144 | return $this; 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/Document/Components/FacebookPost.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 28 | } 29 | 30 | /** 31 | * Getter for url. 32 | */ 33 | public function getUrl() { 34 | return $this->URL; 35 | } 36 | 37 | /** 38 | * Setter for url. 39 | * 40 | * @param mixed $value 41 | * Url. 42 | * 43 | * @return $this 44 | */ 45 | public function setUrl($value) { 46 | $this->URL = $value; 47 | return $this; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/Document/Components/Figure.php: -------------------------------------------------------------------------------- 1 | setItems($items); 31 | } 32 | 33 | /** 34 | * Getter for items. 35 | */ 36 | public function getItems() { 37 | return $this->items; 38 | } 39 | 40 | /** 41 | * Setter for items. 42 | * 43 | * @param array $value 44 | * Items. 45 | * 46 | * @return $this 47 | */ 48 | public function setItems(array $value) { 49 | if (isset($value[0]) && 50 | is_object($value[0]) && 51 | !$value[0] instanceof GalleryItem 52 | ) { 53 | $this->triggerError('Object not of type GalleryItem'); 54 | } 55 | else { 56 | $this->items = $value; 57 | } 58 | return $this; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Document/Components/Header.php: -------------------------------------------------------------------------------- 1 | validateRole($value); 37 | return parent::setRole($value); 38 | } 39 | 40 | /** 41 | * Implements JsonSerializable::jsonSerialize(). 42 | */ 43 | public function jsonSerialize() { 44 | if (!$this->validateRole($this->role)) { 45 | return NULL; 46 | } 47 | return parent::jsonSerialize(); 48 | } 49 | 50 | /** 51 | * Validates the role attribute. 52 | */ 53 | protected function validateRole($value) { 54 | if (!preg_match('/^heading[1-6]?$/', $value)) { 55 | $this->triggerError('Heading not one of "heading" or "heading1" through "heading6"'); 56 | return FALSE; 57 | } 58 | return TRUE; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Document/Components/Illustrator.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 34 | } 35 | 36 | /** 37 | * {@inheritdoc} 38 | */ 39 | protected function optional() { 40 | return array_merge(parent::optional(), array( 41 | 'caption', 42 | 'accessibilityCaption', 43 | 'explicitContent', 44 | )); 45 | } 46 | 47 | /** 48 | * Getter for url. 49 | */ 50 | public function getUrl() { 51 | return $this->URL; 52 | } 53 | 54 | /** 55 | * Setter for url. 56 | * 57 | * @param mixed $value 58 | * Url. 59 | * 60 | * @return $this 61 | */ 62 | public function setUrl($value) { 63 | $this->URL = $value; 64 | return $this; 65 | } 66 | 67 | /** 68 | * Getter for caption. 69 | */ 70 | public function getCaption() { 71 | return $this->caption; 72 | } 73 | 74 | /** 75 | * Setter for caption. 76 | * 77 | * @param string $value 78 | * Caption. 79 | * 80 | * @return $this 81 | */ 82 | public function setCaption($value) { 83 | $this->caption = (string) $value; 84 | return $this; 85 | } 86 | 87 | /** 88 | * Getter for accessibilityCaption. 89 | */ 90 | public function getAccessibilityCaption() { 91 | return $this->accessibilityCaption; 92 | } 93 | 94 | /** 95 | * Setter for accessibilityCaption. 96 | * 97 | * @param string $value 98 | * AccessibilityCaption. 99 | * 100 | * @return $this 101 | */ 102 | public function setAccessibilityCaption($value) { 103 | $this->accessibilityCaption = (string) $value; 104 | return $this; 105 | } 106 | 107 | /** 108 | * Getter for explicitContent. 109 | */ 110 | public function getExplicitContent() { 111 | return $this->explicitContent; 112 | } 113 | 114 | /** 115 | * Setter for explicitContent. 116 | * 117 | * @param bool $value 118 | * ExplicitContent. 119 | * 120 | * @return $this 121 | */ 122 | public function setExplicitContent($value = false) { 123 | $this->explicitContent = $value; 124 | return $this; 125 | } 126 | 127 | } 128 | -------------------------------------------------------------------------------- /src/Document/Components/Instagram.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 28 | } 29 | 30 | /** 31 | * Getter for url. 32 | */ 33 | public function getUrl() { 34 | return $this->URL; 35 | } 36 | 37 | /** 38 | * Setter for url. 39 | * 40 | * @param mixed $value 41 | * Url. 42 | * 43 | * @return $this 44 | */ 45 | public function setUrl($value) { 46 | $this->URL = $value; 47 | return $this; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/Document/Components/Intro.php: -------------------------------------------------------------------------------- 1 | setItems($items); 31 | } 32 | 33 | /** 34 | * Getter for items. 35 | */ 36 | public function getItems() { 37 | return $this->items; 38 | } 39 | 40 | /** 41 | * Setter for items. 42 | * 43 | * @param array $value 44 | * Items. 45 | * 46 | * @return $this 47 | */ 48 | public function setItems(array $value) { 49 | if (isset($value[0]) && 50 | is_object($value[0]) && 51 | !$value[0] instanceof GalleryItem 52 | ) { 53 | $this->triggerError('Object not of type GalleryItem'); 54 | } 55 | else { 56 | $this->items = $value; 57 | } 58 | return $this; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Document/Components/Music.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 36 | } 37 | 38 | /** 39 | * {@inheritdoc} 40 | */ 41 | protected function optional() { 42 | return array_merge(parent::optional(), array( 43 | 'caption', 44 | 'accessibilityCaption', 45 | 'explicitContent', 46 | )); 47 | } 48 | 49 | /** 50 | * Getter for url. 51 | */ 52 | public function getUrl() { 53 | return $this->URL; 54 | } 55 | 56 | /** 57 | * Setter for url. 58 | * 59 | * @param mixed $value 60 | * Url. 61 | * 62 | * @return $this 63 | */ 64 | public function setUrl($value) { 65 | $this->URL = $value; 66 | return $this; 67 | } 68 | 69 | /** 70 | * Getter for caption. 71 | */ 72 | public function getCaption() { 73 | return $this->caption; 74 | } 75 | 76 | /** 77 | * Setter for caption. 78 | * 79 | * @param string|CaptionDescriptor $value 80 | * Caption. 81 | * 82 | * @return $this 83 | */ 84 | public function setCaption($value) { 85 | $class = CaptionDescriptor::class; 86 | if (is_object($value)) { 87 | if ($value instanceof $class) { 88 | $this->caption = $value; 89 | } 90 | else { 91 | $this->triggerError("Caption not of class ${class}."); 92 | } 93 | } 94 | else { 95 | $this->caption = (string) $value; 96 | } 97 | return $this; 98 | } 99 | 100 | /** 101 | * Getter for accessibilityCaption. 102 | */ 103 | public function getAccessibilityCaption() { 104 | return $this->accessibilityCaption; 105 | } 106 | 107 | /** 108 | * Setter for accessibilityCaption. 109 | * 110 | * @param string $value 111 | * AccessibilityCaption. 112 | * 113 | * @return $this 114 | */ 115 | public function setAccessibilityCaption($value) { 116 | $this->accessibilityCaption = (string) $value; 117 | return $this; 118 | } 119 | 120 | /** 121 | * Getter for explicitContent. 122 | */ 123 | public function getExplicitContent() { 124 | return $this->explicitContent; 125 | } 126 | 127 | /** 128 | * Setter for explicitContent. 129 | * 130 | * @param bool $value 131 | * ExplicitContent. 132 | * 133 | * @return $this 134 | */ 135 | public function setExplicitContent($value = false) { 136 | $this->explicitContent = $value; 137 | return $this; 138 | } 139 | 140 | } 141 | -------------------------------------------------------------------------------- /src/Document/Components/Section.php: -------------------------------------------------------------------------------- 1 | scene; 44 | } 45 | 46 | /** 47 | * Setter for scene. 48 | * 49 | * @param \ChapterThree\AppleNewsAPI\Document\Animations\Scenes\Scene $scene 50 | * Scene. 51 | * 52 | * @return $this 53 | */ 54 | public function setScene(Scene $scene) { 55 | $this->scene = $scene; 56 | return $this; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/Document/Components/Text.php: -------------------------------------------------------------------------------- 1 | setText($text); 37 | } 38 | 39 | /** 40 | * {@inheritdoc} 41 | */ 42 | protected function optional() { 43 | return array_merge(parent::optional(), array( 44 | 'format', 45 | 'textStyle', 46 | 'inlineTextStyles', 47 | )); 48 | } 49 | 50 | /** 51 | * Getter for text. 52 | */ 53 | public function getText() { 54 | return $this->text; 55 | } 56 | 57 | /** 58 | * Setter for text. 59 | * 60 | * @param mixed $value 61 | * Text. 62 | * 63 | * @return $this 64 | */ 65 | public function setText($value) { 66 | $this->text = (string) $value; 67 | return $this; 68 | } 69 | 70 | /** 71 | * Getter for format. 72 | */ 73 | public function getFormat() { 74 | return $this->format; 75 | } 76 | 77 | /** 78 | * Setter for format. 79 | * 80 | * @param mixed $value 81 | * Format. 82 | * 83 | * @return $this 84 | */ 85 | public function setFormat($value = 'none') { 86 | // Inline text styles are ignored when format is set to markdown. 87 | $this->format = (string) $value; 88 | return $this; 89 | } 90 | 91 | /** 92 | * Getter for textStyle. 93 | * 94 | * @return \ChapterThree\AppleNewsAPI\Document\Styles\ComponentTextStyle|string 95 | */ 96 | public function getTextStyle() { 97 | return $this->textStyle; 98 | } 99 | 100 | /** 101 | * Setter for textStyle. 102 | * 103 | * @param \ChapterThree\AppleNewsAPI\Document\Styles\ComponentTextStyle|string $text_style 104 | * Either a ComponentTextStyle object, or a string reference to one defined 105 | * in $document. 106 | * @param \ChapterThree\AppleNewsAPI\Document|NULL $document 107 | * If required by first parameter. 108 | * 109 | * @return $this 110 | */ 111 | public function setTextStyle($text_style, Document $document = NULL) { 112 | $class = 'ChapterThree\AppleNewsAPI\Document\Styles\ComponentTextStyle'; 113 | if (is_string($text_style)) { 114 | // Check that text_style exists. 115 | if ($document && 116 | empty($document->getComponentTextStyles()[$text_style]) 117 | ) { 118 | $this->triggerError("No ComponentTextStyle \"${text_style}\" found."); 119 | return $this; 120 | } 121 | } 122 | elseif (!$text_style instanceof $class) { 123 | $this->triggerError("Style not of class ${class}."); 124 | return $this; 125 | } 126 | $this->textStyle = $text_style; 127 | return $this; 128 | } 129 | 130 | /** 131 | * Getter for inlineTextStyles. 132 | */ 133 | public function getInlineTextStyles() { 134 | return $this->inlineTextStyles; 135 | } 136 | 137 | /** 138 | * Setter for inlineTextStyles. 139 | * 140 | * @param \ChapterThree\AppleNewsAPI\Document\Styles\InlineTextStyle $inline_text_style 141 | * InlineTextStyle. 142 | * 143 | * @return $this 144 | */ 145 | public function addInlineTextStyles(InlineTextStyle $inline_text_style) { 146 | $this->inlineTextStyles[] = $inline_text_style; 147 | return $this; 148 | } 149 | 150 | /** 151 | * Validates the format attribute. 152 | */ 153 | protected function validateFormat($value) { 154 | if (!in_array($value, ['none', 'markdown'])) { 155 | $this->triggerError('format not one of "none" or "markdown"'); 156 | return FALSE; 157 | } 158 | return TRUE; 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /src/Document/Components/Title.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 28 | } 29 | 30 | /** 31 | * Getter for url. 32 | */ 33 | public function getUrl() { 34 | return $this->URL; 35 | } 36 | 37 | /** 38 | * Setter for url. 39 | * 40 | * @param mixed $value 41 | * Url. 42 | * 43 | * @return $this 44 | */ 45 | public function setUrl($value) { 46 | $this->URL = $value; 47 | return $this; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/Document/Components/Video.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 34 | } 35 | 36 | /** 37 | * {@inheritdoc} 38 | */ 39 | protected function optional() { 40 | return array_merge(parent::optional(), array( 41 | 'caption', 42 | 'stillURL', 43 | 'aspectRatio', 44 | 'accessibilityCaption', 45 | 'explicitContent', 46 | )); 47 | } 48 | 49 | /** 50 | * Getter for url. 51 | */ 52 | public function getUrl() { 53 | return $this->URL; 54 | } 55 | 56 | /** 57 | * Setter for url. 58 | * 59 | * @param mixed $value 60 | * Url. 61 | * 62 | * @return $this 63 | */ 64 | public function setUrl($value) { 65 | $this->URL = $value; 66 | return $this; 67 | } 68 | 69 | /** 70 | * Getter for stillURL. 71 | */ 72 | public function getStillURL() { 73 | return $this->stillURL; 74 | } 75 | 76 | /** 77 | * Setter for stillURL. 78 | * 79 | * @param bool $value 80 | * ExplicitContent. 81 | * 82 | * @return $this 83 | */ 84 | public function setStillURL($value) { 85 | $this->stillURL = $value; 86 | return $this; 87 | } 88 | 89 | /** 90 | * Getter for aspectRatio. 91 | */ 92 | public function getAspectRatio() { 93 | return $this->aspectRatio; 94 | } 95 | 96 | /** 97 | * Setter for aspectRatio. 98 | * 99 | * @param bool $value 100 | * ExplicitContent. 101 | * 102 | * @return $this 103 | */ 104 | public function setAspectRatio($value) { 105 | $this->aspectRatio = $value; 106 | return $this; 107 | } 108 | 109 | /** 110 | * Getter for caption. 111 | */ 112 | public function getCaption() { 113 | return $this->caption; 114 | } 115 | 116 | /** 117 | * Setter for caption. 118 | * 119 | * @param string $value 120 | * Caption. 121 | * 122 | * @return $this 123 | */ 124 | public function setCaption($value) { 125 | $this->caption = (string) $value; 126 | return $this; 127 | } 128 | 129 | /** 130 | * Getter for accessibilityCaption. 131 | */ 132 | public function getAccessibilityCaption() { 133 | return $this->accessibilityCaption; 134 | } 135 | 136 | /** 137 | * Setter for accessibilityCaption. 138 | * 139 | * @param string $value 140 | * AccessibilityCaption. 141 | * 142 | * @return $this 143 | */ 144 | public function setAccessibilityCaption($value) { 145 | $this->accessibilityCaption = (string) $value; 146 | return $this; 147 | } 148 | 149 | /** 150 | * Getter for explicitContent. 151 | */ 152 | public function getExplicitContent() { 153 | return $this->explicitContent; 154 | } 155 | 156 | /** 157 | * Setter for explicitContent. 158 | * 159 | * @param bool $value 160 | * ExplicitContent. 161 | * 162 | * @return $this 163 | */ 164 | public function setExplicitContent($value) { 165 | $this->explicitContent = $value; 166 | return $this; 167 | } 168 | 169 | } 170 | -------------------------------------------------------------------------------- /src/Document/Components/VinePost.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 28 | } 29 | 30 | /** 31 | * Getter for url. 32 | */ 33 | public function getUrl() { 34 | return $this->URL; 35 | } 36 | 37 | /** 38 | * Setter for url. 39 | * 40 | * @param mixed $value 41 | * Url. 42 | * 43 | * @return $this 44 | */ 45 | public function setUrl($value) { 46 | $this->URL = $value; 47 | return $this; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/Document/ContentInset.php: -------------------------------------------------------------------------------- 1 | top; 37 | } 38 | 39 | /** 40 | * Setter for top. 41 | * 42 | * @param bool $top 43 | * Top. 44 | * 45 | * @return $this 46 | */ 47 | public function setTop($top) { 48 | $this->top = $top; 49 | return $this; 50 | } 51 | 52 | /** 53 | * Getter for right. 54 | */ 55 | public function getRight() { 56 | return $this->right; 57 | } 58 | 59 | /** 60 | * Setter for right. 61 | * 62 | * @param bool $right 63 | * Right. 64 | * 65 | * @return $this 66 | */ 67 | public function setRight($right) { 68 | $this->right = $right; 69 | return $this; 70 | } 71 | 72 | /** 73 | * Getter for bottom. 74 | */ 75 | public function getBottom() { 76 | return $this->bottom; 77 | } 78 | 79 | /** 80 | * Setter for bottom. 81 | * 82 | * @param bool $bottom 83 | * Bottom. 84 | * 85 | * @return $this 86 | */ 87 | public function setBottom($bottom) { 88 | $this->bottom = $bottom; 89 | return $this; 90 | } 91 | 92 | /** 93 | * Getter for left. 94 | */ 95 | public function getLeft() { 96 | return $this->left; 97 | } 98 | 99 | /** 100 | * Setter for left. 101 | * 102 | * @param bool $left 103 | * Left. 104 | * 105 | * @return $this 106 | */ 107 | public function setLeft($left) { 108 | $this->left = $left; 109 | return $this; 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /src/Document/GalleryItem.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 29 | } 30 | 31 | /** 32 | * Define optional properties. 33 | */ 34 | protected function optional() { 35 | return array_merge(parent::optional(), array( 36 | 'caption', 37 | 'accessibilityCaption', 38 | 'explicitContent', 39 | )); 40 | } 41 | 42 | /** 43 | * Getter for URL. 44 | */ 45 | public function getUrl() { 46 | return $this->URL; 47 | } 48 | 49 | /** 50 | * Setter for URL. 51 | * 52 | * @param string $URL 53 | * URL. 54 | * 55 | * @return $this 56 | */ 57 | public function setUrl($url) { 58 | $this->URL = $url; 59 | return $this; 60 | } 61 | 62 | /** 63 | * Getter for caption. 64 | */ 65 | public function getCaption() { 66 | return $this->caption; 67 | } 68 | 69 | /** 70 | * Setter for caption. 71 | * 72 | * @param string|CaptionDescriptor $value 73 | * Caption. 74 | * 75 | * @return $this 76 | */ 77 | public function setCaption($value) { 78 | $class = CaptionDescriptor::class; 79 | if (is_object($value)) { 80 | if ($value instanceof $class) { 81 | $this->caption = $value; 82 | } 83 | else { 84 | $this->triggerError("Caption not of class ${class}."); 85 | } 86 | } 87 | else { 88 | $this->caption = (string) $value; 89 | } 90 | return $this; 91 | } 92 | 93 | /** 94 | * Getter for accessibilityCaption. 95 | */ 96 | public function getAccessibilityCaption() { 97 | return $this->accessibilityCaption; 98 | } 99 | 100 | /** 101 | * Setter for accessibilityCaption. 102 | * 103 | * @param string $value 104 | * AccessibilityCaption. 105 | * 106 | * @return $this 107 | */ 108 | public function setAccessibilityCaption($value) { 109 | $this->accessibilityCaption = (string) $value; 110 | return $this; 111 | } 112 | 113 | /** 114 | * Getter for explicitContent. 115 | */ 116 | public function getExplicitContent() { 117 | return $this->explicitContent; 118 | } 119 | 120 | /** 121 | * Setter for explicitContent. 122 | * 123 | * @param bool $value 124 | * ExplicitContent. 125 | * 126 | * @return $this 127 | */ 128 | public function setExplicitContent($value) { 129 | $this->explicitContent = $value; 130 | return $this; 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/Document/Layouts/AdvertisingLayout.php: -------------------------------------------------------------------------------- 1 | margin; 25 | } 26 | 27 | /** 28 | * Setter for margin. 29 | * 30 | * @param Margin $value 31 | * Margin. 32 | * 33 | * @return $this 34 | */ 35 | public function setMargin($value) { 36 | if (is_object($value) && !$value instanceof Margin) { 37 | $this->triggerError('Object not of type Margin'); 38 | } 39 | else { 40 | $this->margin = $value; 41 | } 42 | return $this; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Document/Layouts/Layout.php: -------------------------------------------------------------------------------- 1 | setColumns($columns); 33 | $this->setWidth($width); 34 | } 35 | 36 | /** 37 | * Define optional properties. 38 | */ 39 | protected function optional() { 40 | return array_merge(parent::optional(), array( 41 | 'margin', 42 | 'gutter', 43 | )); 44 | } 45 | 46 | /** 47 | * Getter for columns. 48 | */ 49 | public function getColumns() { 50 | return $this->columns; 51 | } 52 | 53 | /** 54 | * Setter for columns. 55 | * 56 | * @param int $value 57 | * Columns. 58 | * 59 | * @return $this 60 | */ 61 | public function setColumns($value) { 62 | $this->columns = $value; 63 | return $this; 64 | } 65 | 66 | /** 67 | * Getter for width. 68 | */ 69 | public function getWidth() { 70 | return $this->width; 71 | } 72 | 73 | /** 74 | * Setter for columns. 75 | * 76 | * @param int $value 77 | * Width. 78 | * 79 | * @return $this 80 | */ 81 | public function setWidth($value) { 82 | $this->width = $value; 83 | return $this; 84 | } 85 | 86 | /** 87 | * Getter for margin. 88 | */ 89 | public function getMargin() { 90 | return $this->margin; 91 | } 92 | 93 | /** 94 | * Setter for margin. 95 | * 96 | * @param int $value 97 | * Margin. 98 | * 99 | * @return $this 100 | */ 101 | public function setMargin($value) { 102 | $this->margin = $value; 103 | return $this; 104 | } 105 | 106 | /** 107 | * Getter for gutter. 108 | */ 109 | public function getGutter() { 110 | return $this->gutter; 111 | } 112 | 113 | /** 114 | * Setter for gutter. 115 | * 116 | * @param int $value 117 | * Gutter. 118 | * 119 | * @return $this 120 | */ 121 | public function setGutter($value) { 122 | $this->gutter = $value; 123 | return $this; 124 | } 125 | 126 | } 127 | -------------------------------------------------------------------------------- /src/Document/Margin.php: -------------------------------------------------------------------------------- 1 | setTop($top); 27 | } 28 | if ($bottom !== NULL) { 29 | $this->setBottom($bottom); 30 | } 31 | } 32 | 33 | /** 34 | * Define optional properties. 35 | */ 36 | protected function optional() { 37 | return array_merge(parent::optional(), array( 38 | 'top', 39 | 'bottom', 40 | )); 41 | } 42 | 43 | /** 44 | * Getter for top. 45 | */ 46 | public function getTop() { 47 | return $this->top; 48 | } 49 | 50 | /** 51 | * Setter for top. 52 | * 53 | * @param string $top 54 | * Top. 55 | * 56 | * @return $this 57 | */ 58 | public function setTop($top) { 59 | if (!$this->isSupportedUnit($top)) { 60 | $this->triggerError("Value \"${top}\" does not use a supported unit."); 61 | } 62 | else { 63 | $this->top = $top; 64 | } 65 | return $this; 66 | } 67 | 68 | /** 69 | * Getter for bottom. 70 | */ 71 | public function getBottom() { 72 | return $this->bottom; 73 | } 74 | 75 | /** 76 | * Setter for bottom. 77 | * 78 | * @param mixed $bottom 79 | * Bottom. 80 | * 81 | * @return $this 82 | */ 83 | public function setBottom($bottom) { 84 | if (!$this->isSupportedUnit($bottom)) { 85 | $this->triggerError("Value \"${bottom}\" does not use a supported unit."); 86 | } 87 | else { 88 | $this->bottom = $bottom; 89 | } 90 | return $this; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/Document/Styles/Border.php: -------------------------------------------------------------------------------- 1 | top; 47 | } 48 | 49 | /** 50 | * Setter for top. 51 | * 52 | * @param bool $value 53 | * Top. 54 | * 55 | * @return $this 56 | */ 57 | public function setTop($value = true) { 58 | $this->top = $value; 59 | return $this; 60 | } 61 | 62 | /** 63 | * Getter for bottom. 64 | */ 65 | public function getBottom() { 66 | return $this->bottom; 67 | } 68 | 69 | /** 70 | * Setter for bottom. 71 | * 72 | * @param bool $value 73 | * Bottom. 74 | * 75 | * @return $this 76 | */ 77 | public function setBottom($value = true) { 78 | $this->bottom = $value; 79 | return $this; 80 | } 81 | 82 | /** 83 | * Getter for left. 84 | */ 85 | public function getLeft() { 86 | return $this->left; 87 | } 88 | 89 | /** 90 | * Setter for left. 91 | * 92 | * @param bool $value 93 | * Left. 94 | * 95 | * @return $this 96 | */ 97 | public function setLeft($value = true) { 98 | $this->left = $value; 99 | return $this; 100 | } 101 | 102 | /** 103 | * Getter for right. 104 | */ 105 | public function getRight() { 106 | return $this->right; 107 | } 108 | 109 | /** 110 | * Setter for right. 111 | * 112 | * @param bool $value 113 | * Right. 114 | * 115 | * @return $this 116 | */ 117 | public function setRight($value = true) { 118 | $this->right = $value; 119 | return $this; 120 | } 121 | 122 | /** 123 | * Getter for all. 124 | */ 125 | public function getAll() { 126 | return $this->all; 127 | } 128 | 129 | /** 130 | * Setter for all. 131 | * 132 | * @param \ChapterThree\AppleNewsAPI\Document\Styles\StrokeStyle $value 133 | * All. 134 | * 135 | * @return $this 136 | */ 137 | public function setAll(StrokeStyle $value) { 138 | $this->all = $value; 139 | return $this; 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /src/Document/Styles/ComponentStyle.php: -------------------------------------------------------------------------------- 1 | backgroundColor; 40 | } 41 | 42 | /** 43 | * Setter for backgroundColor. 44 | * 45 | * @param string $value 46 | * BackgroundColor. 47 | * 48 | * @return $this 49 | */ 50 | public function setBackgroundColor($value = 'transparent') { 51 | if ($this->validateBackgroundColor($value)) { 52 | $this->backgroundColor = $value; 53 | } 54 | return $this; 55 | } 56 | 57 | /** 58 | * Getter for opacity. 59 | */ 60 | public function getOpacity() { 61 | return $this->opacity; 62 | } 63 | 64 | /** 65 | * Setter for opacity. 66 | * 67 | * @param float $value 68 | * Opacity. 69 | * 70 | * @return $this 71 | */ 72 | public function setOpacity($value = 1) { 73 | if ($this->validateOpacity($value)) { 74 | $this->opacity = $value; 75 | } 76 | return $this; 77 | } 78 | 79 | /** 80 | * Getter for fill. 81 | */ 82 | public function getFill() { 83 | return $this->fill; 84 | } 85 | 86 | /** 87 | * Setter for fill. 88 | * 89 | * @param \ChapterThree\AppleNewsAPI\Document\Styles\Fills\Fill $value 90 | * Fill. 91 | * 92 | * @return $this 93 | */ 94 | public function setFill(Fill $value) { 95 | $this->fill = $value; 96 | return $this; 97 | } 98 | 99 | /** 100 | * Getter for border. 101 | */ 102 | public function getBorder() { 103 | return $this->border; 104 | } 105 | 106 | /** 107 | * Setter for border. 108 | * 109 | * @param \ChapterThree\AppleNewsAPI\Document\Styles\Border $value 110 | * Border. 111 | * 112 | * @return $this 113 | */ 114 | public function setBorder(Border $value) { 115 | $this->border = $value; 116 | return $this; 117 | } 118 | 119 | /** 120 | * Implements JsonSerializable::jsonSerialize(). 121 | */ 122 | public function jsonSerialize() { 123 | $valid = (!isset($this->backgroundColor) || 124 | $this->validateBackgroundColor($this->backgroundColor)) && 125 | (!isset($this->opacity) || 126 | $this->validateOpacity($this->opacity)); 127 | if (!$valid) { 128 | return NULL; 129 | } 130 | return parent::jsonSerialize(); 131 | } 132 | 133 | /** 134 | * Validates the backgroundColor attribute. 135 | */ 136 | protected function validateBackgroundColor($value) { 137 | if (!$this->isHexColor($value)) { 138 | $this->triggerError('backgroundColor is not valid'); 139 | return FALSE; 140 | } 141 | return TRUE; 142 | } 143 | 144 | /** 145 | * Validates the opacity attribute. 146 | */ 147 | protected function validateOpacity($value) { 148 | if (!$this->isUnitInterval($value)) { 149 | $this->triggerError('opacity is not valid'); 150 | return FALSE; 151 | } 152 | return TRUE; 153 | } 154 | 155 | } 156 | -------------------------------------------------------------------------------- /src/Document/Styles/ComponentTextStyle.php: -------------------------------------------------------------------------------- 1 | textAlignment; 39 | } 40 | 41 | /** 42 | * Setter for textAlignment. 43 | * 44 | * @param string $value 45 | * TextAlignment. 46 | * 47 | * @return $this 48 | */ 49 | public function setTextAlignment($value) { 50 | if ($this->validateTextAlignment($value)) { 51 | $this->textAlignment = $value; 52 | } 53 | return $this; 54 | } 55 | 56 | /** 57 | * Getter for lineHeight. 58 | */ 59 | public function getLineHeight() { 60 | return $this->lineHeight; 61 | } 62 | 63 | /** 64 | * Setter for lineHeight. 65 | * 66 | * @param int $value 67 | * LineHeight. 68 | * 69 | * @return $this 70 | */ 71 | public function setLineHeight($value) { 72 | $this->lineHeight = $value; 73 | return $this; 74 | } 75 | 76 | /** 77 | * Getter for dropCapStyle. 78 | */ 79 | public function getDropCapStyle() { 80 | return $this->dropCapStyle; 81 | } 82 | 83 | /** 84 | * Setter for dropCapStyle. 85 | * 86 | * @param \ChapterThree\AppleNewsAPI\Document\Styles\DropCapStyle $value 87 | * DropCapStyle. 88 | * 89 | * @return $this 90 | */ 91 | public function setDropCapStyle(DropCapStyle $value) { 92 | $this->dropCapStyle = $value; 93 | return $this; 94 | } 95 | 96 | /** 97 | * Getter for linkStyle. 98 | */ 99 | public function getLinkStyle() { 100 | return $this->linkStyle; 101 | } 102 | 103 | /** 104 | * Setter for linkStyle. 105 | * 106 | * @param \ChapterThree\AppleNewsAPI\Document\Styles\TextStyle $value 107 | * LinkStyle. 108 | * 109 | * @return $this 110 | */ 111 | public function setLinkStyle(TextStyle $value) { 112 | $this->linkStyle = $value; 113 | return $this; 114 | } 115 | 116 | /** 117 | * Getter for hyphenation. 118 | */ 119 | public function getHyphenation() { 120 | return $this->hyphenation; 121 | } 122 | 123 | /** 124 | * Setter for hyphenation. 125 | * 126 | * @param bool $value 127 | * Hyphenation. 128 | * 129 | * @return $this 130 | */ 131 | public function setHyphenation($value) { 132 | $this->hyphenation = $value; 133 | return $this; 134 | } 135 | 136 | /** 137 | * Implements JsonSerializable::jsonSerialize(). 138 | */ 139 | public function jsonSerialize() { 140 | $valid = (!isset($this->textAlignment) || 141 | $this->validateTextAlignment($this->textAlignment)); 142 | if (!$valid) { 143 | return NULL; 144 | } 145 | return parent::jsonSerialize(); 146 | } 147 | 148 | /** 149 | * Validates the textAlignment attribute. 150 | */ 151 | protected function validateTextAlignment($value) { 152 | if (!in_array($value, array( 153 | 'left', 154 | 'center', 155 | 'right', 156 | 'justified', 157 | 'none', 158 | )) 159 | ) { 160 | $this->triggerError('textAlignment is not valid'); 161 | return FALSE; 162 | } 163 | return TRUE; 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /src/Document/Styles/DocumentStyle.php: -------------------------------------------------------------------------------- 1 | setBackgroundColor($background_color); 27 | } 28 | 29 | /** 30 | * Getter for backgroundColor. 31 | */ 32 | public function getBackgroundColor() { 33 | return $this->backgroundColor; 34 | } 35 | 36 | /** 37 | * Setter for backgroundColor. 38 | * 39 | * @param string $value 40 | * BackgroundColor. 41 | * 42 | * @return $this 43 | */ 44 | public function setBackgroundColor($value) { 45 | if ($this->validateBackgroundColor($value)) { 46 | $this->backgroundColor = $value; 47 | } 48 | return $this; 49 | } 50 | 51 | /** 52 | * Implements JsonSerializable::jsonSerialize(). 53 | */ 54 | public function jsonSerialize() { 55 | $valid = (!isset($this->backgroundColor) || 56 | $this->validateBackgroundColor($this->backgroundColor)); 57 | if (!$valid) { 58 | return NULL; 59 | } 60 | return parent::jsonSerialize(); 61 | } 62 | 63 | /** 64 | * Validates the backgroundColor attribute. 65 | */ 66 | protected function validateBackgroundColor($value) { 67 | if (!$this->isUnitInterval($value)) { 68 | $this->triggerError('backgroundColor is not valid'); 69 | return FALSE; 70 | } 71 | return TRUE; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/Document/Styles/DropCapStyle.php: -------------------------------------------------------------------------------- 1 | setNumberOfLines($number_of_lines); 32 | } 33 | 34 | /** 35 | * Define optional properties. 36 | */ 37 | protected function optional() { 38 | return array_merge(parent::optional(), array( 39 | 'numberOfCharacters', 40 | 'fontName', 41 | 'textColor', 42 | 'backgroundColor', 43 | 'padding', 44 | )); 45 | } 46 | 47 | /** 48 | * Getter for numberOfLines. 49 | */ 50 | public function getNumberOfLines() { 51 | return $this->numberOfLines; 52 | } 53 | 54 | /** 55 | * Setter for numberOfLines. 56 | * 57 | * @param int $value 58 | * NumberOfLines. 59 | * 60 | * @return $this 61 | */ 62 | public function setNumberOfLines($value) { 63 | $this->numberOfLines = $value; 64 | return $this; 65 | } 66 | 67 | /** 68 | * Getter for numberOfCharacters. 69 | */ 70 | public function getNumberOfCharacters() { 71 | return $this->numberOfCharacters; 72 | } 73 | 74 | /** 75 | * Setter for numberOfCharacters. 76 | * 77 | * @param int $value 78 | * NumberOfCharacters. 79 | * 80 | * @return $this 81 | */ 82 | public function setNumberOfCharacters($value) { 83 | $this->numberOfCharacters = $value; 84 | return $this; 85 | } 86 | 87 | /** 88 | * Getter for fontName. 89 | */ 90 | public function getFontName() { 91 | return $this->fontName; 92 | } 93 | 94 | /** 95 | * Setter for fontName. 96 | * 97 | * @param string $value 98 | * FontName. 99 | * 100 | * @return $this 101 | */ 102 | public function setFontName($value) { 103 | $this->fontName = $value; 104 | return $this; 105 | } 106 | 107 | /** 108 | * Getter for textColor. 109 | */ 110 | public function getTextColor() { 111 | return $this->textColor; 112 | } 113 | 114 | /** 115 | * Setter for textColor. 116 | * 117 | * @param string $value 118 | * TextColor. 119 | * 120 | * @return $this 121 | */ 122 | public function setTextColor($value) { 123 | if ($this->validateTextColor($value)) { 124 | $this->textColor = $value; 125 | } 126 | return $this; 127 | } 128 | 129 | /** 130 | * Getter for backgroundColor. 131 | */ 132 | public function getBackgroundColor() { 133 | return $this->backgroundColor; 134 | } 135 | 136 | /** 137 | * Setter for backgroundColor. 138 | * 139 | * @param string $value 140 | * BackgroundColor. 141 | * 142 | * @return $this 143 | */ 144 | public function setBackgroundColor($value) { 145 | if ($this->validateBackgroundColor($value)) { 146 | $this->backgroundColor = $value; 147 | } 148 | return $this; 149 | } 150 | 151 | /** 152 | * Getter for padding. 153 | */ 154 | public function getPadding() { 155 | return $this->padding; 156 | } 157 | 158 | /** 159 | * Setter for padding. 160 | * 161 | * @param int $value 162 | * Padding. 163 | * 164 | * @return $this 165 | */ 166 | public function setPadding($value) { 167 | $this->padding = $value; 168 | return $this; 169 | } 170 | 171 | /** 172 | * Implements JsonSerializable::jsonSerialize(). 173 | */ 174 | public function jsonSerialize() { 175 | $valid = (!isset($this->textColor) || 176 | $this->validateTextColor($this->textColor)) && 177 | (!isset($this->backgroundColor) || 178 | $this->validateBackgroundColor($this->backgroundColor)); 179 | if (!$valid) { 180 | return NULL; 181 | } 182 | return parent::jsonSerialize(); 183 | } 184 | 185 | /** 186 | * Validates the textColor attribute. 187 | */ 188 | protected function validateTextColor($value) { 189 | if (!$this->isHexColor($value)) { 190 | $this->triggerError('textColor is not valid'); 191 | return FALSE; 192 | } 193 | return TRUE; 194 | } 195 | 196 | /** 197 | * Validates the backgroundColor attribute. 198 | */ 199 | protected function validateBackgroundColor($value) { 200 | if (!$this->isHexColor($value)) { 201 | $this->triggerError('backgroundColor is not valid'); 202 | return FALSE; 203 | } 204 | return TRUE; 205 | } 206 | 207 | } 208 | -------------------------------------------------------------------------------- /src/Document/Styles/Fills/Fill.php: -------------------------------------------------------------------------------- 1 | setType($type); 28 | } 29 | 30 | /** 31 | * Define optional properties. 32 | */ 33 | protected function optional() { 34 | return array_merge(parent::optional(), array( 35 | 'attachment', 36 | )); 37 | } 38 | 39 | /** 40 | * Getter for type. 41 | */ 42 | public function getType() { 43 | return (string) $this->type; 44 | } 45 | 46 | /** 47 | * Setter for type. 48 | * 49 | * @param bool $value 50 | * Type. 51 | * 52 | * @return $this 53 | */ 54 | public function setType($value) { 55 | $this->type = $value; 56 | return $this; 57 | } 58 | 59 | /** 60 | * Getter for attachment. 61 | */ 62 | public function getAttachment() { 63 | return $this->attachment; 64 | } 65 | 66 | /** 67 | * Setter for attachment. 68 | * 69 | * @param bool $value 70 | * Attachment. 71 | * 72 | * @return $this 73 | */ 74 | public function setAttachment($value) { 75 | $this->attachment = $value; 76 | return $this; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/Document/Styles/Fills/Gradients/ColorStop.php: -------------------------------------------------------------------------------- 1 | setColor($color); 27 | } 28 | 29 | /** 30 | * Define optional properties. 31 | */ 32 | protected function optional() { 33 | return array_merge(parent::optional(), array( 34 | 'location', 35 | )); 36 | } 37 | 38 | /** 39 | * Getter for color. 40 | */ 41 | public function getColor() { 42 | return $this->color; 43 | } 44 | 45 | /** 46 | * Setter for color. 47 | * 48 | * @param string $value 49 | * The color of this color stop, defined as a 3- to 8-character RGBA 50 | * hexadecimal string; e.g., #000 for black or #FF00007F for red with 51 | * an alpha (opacity) of 50%. 52 | * 53 | * @return $this 54 | */ 55 | public function setColor($value) { 56 | $this->color = $value; 57 | return $this; 58 | } 59 | 60 | /** 61 | * Getter for location. 62 | */ 63 | public function getLocation() { 64 | return $this->location; 65 | } 66 | 67 | /** 68 | * Setter for location. 69 | * 70 | * @param float $value 71 | * An optional location of the color stop within the gradient, as a 72 | * percentage of the gradient size. If location is omitted, the 73 | * length of the stop is calculated by first subtracting color stops 74 | * with specified locations from the full length, then equally distributing 75 | * the remaining length. 76 | * 77 | * @return $this 78 | */ 79 | public function setLocation($value) { 80 | $this->location = $value; 81 | return $this; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/Document/Styles/Fills/Gradients/GradientFill.php: -------------------------------------------------------------------------------- 1 | setColorStops($color_stops); 31 | } 32 | 33 | /** 34 | * Getter for url. 35 | */ 36 | public function getColorStops() { 37 | return $this->colorStops; 38 | } 39 | 40 | /** 41 | * Setter for url. 42 | * 43 | * @param array|\ChapterThree\AppleNewsAPI\Document\Styles\Fills\Gradients\ColorStop $items 44 | * An array of color stops. Each stop sets a color and percentage. 45 | * 46 | * @return $this 47 | */ 48 | public function setColorStops(array $items) { 49 | if (isset($items[0]) && 50 | is_object($items[0]) && 51 | !$items[0] instanceof Fills\Gradients\ColorStop 52 | ) { 53 | $this->triggerError('Object not of type Gradients\ColorStop'); 54 | } 55 | else { 56 | $this->colorStops = $items; 57 | } 58 | return $this; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Document/Styles/Fills/Gradients/LinearGradientFill.php: -------------------------------------------------------------------------------- 1 | angle; 44 | } 45 | 46 | /** 47 | * Setter for angle. 48 | * 49 | * @param float $value 50 | * The angle of the gradient fill, in degrees Use the angle to set 51 | * the direction of the gradient. For example, a value of 180 defines 52 | * a gradient that changes color from top to bottom. An angle of 90 53 | * defines a gradient that changes color from left to right. 54 | * 55 | * If angle is omitted, an angle of 180 (top to bottom) is used. 56 | * 57 | * @return $this 58 | */ 59 | public function setAngle($value) { 60 | $this->angle = $value; 61 | return $this; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/Document/Styles/Fills/ImageFill.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 29 | } 30 | 31 | /** 32 | * Define optional properties. 33 | */ 34 | protected function optional() { 35 | return array_merge(parent::optional(), array( 36 | 'fillMode', 37 | 'verticalAlignment', 38 | 'horizontalAlignment', 39 | )); 40 | } 41 | 42 | /** 43 | * Getter for url. 44 | */ 45 | public function getUrl() { 46 | return $this->URL; 47 | } 48 | 49 | /** 50 | * Setter for url. 51 | * 52 | * @param string $value 53 | * Url. 54 | * 55 | * @return $this 56 | */ 57 | public function setUrl($value) { 58 | $this->URL = $value; 59 | return $this; 60 | } 61 | 62 | /** 63 | * Getter for fillMode. 64 | */ 65 | public function getFillMode() { 66 | return $this->fillMode; 67 | } 68 | 69 | /** 70 | * Setter for fillMode. 71 | * 72 | * @param string $value 73 | * FillMode. 74 | * 75 | * @return $this 76 | */ 77 | public function setFillMode($value) { 78 | if ($this->validateFillMode($value)) { 79 | $this->fillMode = $value; 80 | } 81 | return $this; 82 | } 83 | 84 | /** 85 | * Getter for verticalAlignment. 86 | */ 87 | public function getVerticalAlignment() { 88 | return $this->verticalAlignment; 89 | } 90 | 91 | /** 92 | * Setter for verticalAlignment. 93 | * 94 | * @param string $value 95 | * VerticalAlignment. 96 | * 97 | * @return $this 98 | */ 99 | public function setVerticalAlignment($value) { 100 | if ($this->validateVerticalAlignment($value)) { 101 | $this->verticalAlignment = $value; 102 | } 103 | return $this; 104 | } 105 | 106 | /** 107 | * Getter for horizontalAlignment. 108 | */ 109 | public function getHorizontalAlignment() { 110 | return $this->horizontalAlignment; 111 | } 112 | 113 | /** 114 | * Setter for horizontalAlignment. 115 | * 116 | * @param string $value 117 | * HorizontalAlignment. 118 | * 119 | * @return $this 120 | */ 121 | public function setHorizontalAlignment($value) { 122 | if ($this->validateHorizontalAlignment($value)) { 123 | $this->horizontalAlignment = $value; 124 | } 125 | return $this; 126 | } 127 | 128 | /** 129 | * Implements JsonSerializable::jsonSerialize(). 130 | */ 131 | public function jsonSerialize() { 132 | $valid = (!isset($this->fillMode) || 133 | $this->validateFillMode($this->fillMode)) && 134 | (!isset($this->verticalAlignment) || 135 | $this->validateVerticalAlignment($this->verticalAlignment)) && 136 | (!isset($this->horizontalAlignment) || 137 | $this->validateHorizontalAlignment($this->horizontalAlignment)); 138 | if (!$valid) { 139 | return NULL; 140 | } 141 | return parent::jsonSerialize(); 142 | } 143 | 144 | /** 145 | * Validates the fillMode attribute. 146 | */ 147 | protected function validateFillMode($value) { 148 | if (!in_array($value, array( 149 | 'fit', 150 | 'cover', 151 | )) 152 | ) { 153 | $this->triggerError('fillMode is not valid'); 154 | return FALSE; 155 | } 156 | return TRUE; 157 | } 158 | 159 | /** 160 | * Validates the verticalAlignment attribute. 161 | */ 162 | protected function validateVerticalAlignment($value) { 163 | if (!in_array($value, array( 164 | 'top', 165 | 'center', 166 | 'bottom', 167 | )) 168 | ) { 169 | $this->triggerError('verticalAlignment is not valid'); 170 | return FALSE; 171 | } 172 | return TRUE; 173 | } 174 | 175 | /** 176 | * Validates the horizontalAlignment attribute. 177 | */ 178 | protected function validateHorizontalAlignment($value) { 179 | if (!in_array($value, array( 180 | 'left', 181 | 'center', 182 | 'right', 183 | )) 184 | ) { 185 | $this->triggerError('horizontalAlignment is not valid'); 186 | return FALSE; 187 | } 188 | return TRUE; 189 | } 190 | 191 | } 192 | -------------------------------------------------------------------------------- /src/Document/Styles/Fills/VideoFill.php: -------------------------------------------------------------------------------- 1 | setUrl($url); 32 | $this->setStillURL($stillURL); 33 | } 34 | 35 | /** 36 | * Define optional properties. 37 | */ 38 | protected function optional() { 39 | return array_merge(parent::optional(), array( 40 | 'fillMode', 41 | 'verticalAlignment', 42 | 'horizontalAlignment', 43 | )); 44 | } 45 | 46 | /** 47 | * Getter for url. 48 | */ 49 | public function getUrl() { 50 | return $this->URL; 51 | } 52 | 53 | /** 54 | * Setter for url. 55 | * 56 | * @param string $value 57 | * Url. 58 | * 59 | * @return $this 60 | */ 61 | public function setUrl($value) { 62 | $this->URL = $value; 63 | return $this; 64 | } 65 | 66 | /** 67 | * Getter for stillURL. 68 | */ 69 | public function getStillURL() { 70 | return $this->stillURL; 71 | } 72 | 73 | /** 74 | * Setter for stillURL. 75 | * 76 | * @param string $value 77 | * Url. 78 | * 79 | * @return $this 80 | */ 81 | public function setStillURL($value) { 82 | $this->stillURL = $value; 83 | return $this; 84 | } 85 | 86 | /** 87 | * Getter for fillMode. 88 | */ 89 | public function getFillMode() { 90 | return $this->fillMode; 91 | } 92 | 93 | /** 94 | * Setter for fillMode. 95 | * 96 | * @param string $value 97 | * FillMode. 98 | * 99 | * @return $this 100 | */ 101 | public function setFillMode($value = 'cover') { 102 | if ($this->validateFillMode($value)) { 103 | $this->fillMode = $value; 104 | } 105 | return $this; 106 | } 107 | 108 | /** 109 | * Getter for verticalAlignment. 110 | */ 111 | public function getVerticalAlignment() { 112 | return $this->verticalAlignment; 113 | } 114 | 115 | /** 116 | * Setter for verticalAlignment. 117 | * 118 | * @param string $value 119 | * VerticalAlignment. 120 | * 121 | * @return $this 122 | */ 123 | public function setVerticalAlignment($value = 'center') { 124 | if ($this->validateVerticalAlignment($value)) { 125 | $this->verticalAlignment = $value; 126 | } 127 | return $this; 128 | } 129 | 130 | /** 131 | * Getter for horizontalAlignment. 132 | */ 133 | public function getHorizontalAlignment() { 134 | return $this->horizontalAlignment; 135 | } 136 | 137 | /** 138 | * Setter for horizontalAlignment. 139 | * 140 | * @param string $value 141 | * HorizontalAlignment. 142 | * 143 | * @return $this 144 | */ 145 | public function setHorizontalAlignment($value = 'center') { 146 | if ($this->validateHorizontalAlignment($value)) { 147 | $this->horizontalAlignment = $value; 148 | } 149 | return $this; 150 | } 151 | 152 | /** 153 | * Implements JsonSerializable::jsonSerialize(). 154 | */ 155 | public function jsonSerialize() { 156 | $valid = (!isset($this->fillMode) || 157 | $this->validateFillMode($this->fillMode)) && 158 | (!isset($this->verticalAlignment) || 159 | $this->validateVerticalAlignment($this->verticalAlignment)) && 160 | (!isset($this->horizontalAlignment) || 161 | $this->validateHorizontalAlignment($this->horizontalAlignment)); 162 | if (!$valid) { 163 | return NULL; 164 | } 165 | return parent::jsonSerialize(); 166 | } 167 | 168 | /** 169 | * Validates the fillMode attribute. 170 | */ 171 | protected function validateFillMode($value) { 172 | if (!in_array($value, array( 173 | 'fit', 174 | 'cover', 175 | )) 176 | ) { 177 | $this->triggerError('fillMode is not valid'); 178 | return FALSE; 179 | } 180 | return TRUE; 181 | } 182 | 183 | /** 184 | * Validates the verticalAlignment attribute. 185 | */ 186 | protected function validateVerticalAlignment($value) { 187 | if (!in_array($value, array( 188 | 'top', 189 | 'center', 190 | 'bottom', 191 | )) 192 | ) { 193 | $this->triggerError('verticalAlignment is not valid'); 194 | return FALSE; 195 | } 196 | return TRUE; 197 | } 198 | 199 | /** 200 | * Validates the horizontalAlignment attribute. 201 | */ 202 | protected function validateHorizontalAlignment($value) { 203 | if (!in_array($value, array( 204 | 'left', 205 | 'center', 206 | 'right', 207 | )) 208 | ) { 209 | $this->triggerError('horizontalAlignment is not valid'); 210 | return FALSE; 211 | } 212 | return TRUE; 213 | } 214 | 215 | } 216 | -------------------------------------------------------------------------------- /src/Document/Styles/InlineTextStyle.php: -------------------------------------------------------------------------------- 1 | setRangeStart($range_start); 35 | $this->setRangeLength($range_length); 36 | $this->setTextStyle($text_style); 37 | } 38 | 39 | /** 40 | * Getter for rangeStart. 41 | */ 42 | public function getRangeStart() { 43 | return $this->rangeStart; 44 | } 45 | 46 | /** 47 | * Setter for rangeStart. 48 | * 49 | * @param int $value 50 | * RangeStart. 51 | * 52 | * @return $this 53 | */ 54 | public function setRangeStart($value) { 55 | $this->rangeStart = $value; 56 | return $this; 57 | } 58 | 59 | /** 60 | * Getter for rangeLength. 61 | */ 62 | public function getRangeLength() { 63 | return $this->rangeLength; 64 | } 65 | 66 | /** 67 | * Setter for rangeLength. 68 | * 69 | * @param int $value 70 | * RangeLength. 71 | * 72 | * @return $this 73 | */ 74 | public function setRangeLength($value) { 75 | $this->rangeLength = $value; 76 | return $this; 77 | } 78 | 79 | /** 80 | * Getter for textStyle. 81 | */ 82 | public function getTextStyle() { 83 | return $this->textStyle; 84 | } 85 | 86 | /** 87 | * Setter for textStyle. 88 | * 89 | * @param string|\ChapterThree\AppleNewsAPI\Document\Styles\TextStyle $value 90 | * Either a TextStyle object, or a string reference to one defined 91 | * in $document. 92 | * @param \ChapterThree\AppleNewsAPI\Document|NULL $document 93 | * If required by first parameter. 94 | * 95 | * @return $this 96 | */ 97 | public function setTextStyle($value, Document $document = NULL) { 98 | $class = 'ChapterThree\AppleNewsAPI\Document\Styles\TextStyle'; 99 | if (is_string($value)) { 100 | // Check that value exists. 101 | if ($document && 102 | empty($document->getTextStyles()[$value]) 103 | ) { 104 | $this->triggerError("No TextStyle \"${value}\" found."); 105 | return $this; 106 | } 107 | } 108 | elseif (!$value instanceof $class) { 109 | $this->triggerError("Style not of class ${class}."); 110 | return $this; 111 | } 112 | $this->textStyle = $value; 113 | return $this; 114 | } 115 | 116 | /** 117 | * Implements JsonSerializable::jsonSerialize(). 118 | */ 119 | public function jsonSerialize() { 120 | 121 | if (isset($this->rangeStart) && !isset($this->rangeLength)) { 122 | $msg = "If rangeStart is specified, rangeLength is required."; 123 | $this->triggerError($msg); 124 | return NULL; 125 | } 126 | 127 | return parent::jsonSerialize(); 128 | } 129 | 130 | } 131 | -------------------------------------------------------------------------------- /src/Document/Styles/Offset.php: -------------------------------------------------------------------------------- 1 | setX($x); 42 | $this->setY($y); 43 | } 44 | 45 | /** 46 | * Gets x 47 | * 48 | * @return float 49 | */ 50 | public function getX() { 51 | return $this->x; 52 | } 53 | 54 | /** 55 | * Sets x 56 | * 57 | * @param float $x 58 | */ 59 | public function setX($x) { 60 | if ($this->validateOffset($x)) { 61 | $this->x = round($x, 1); 62 | } 63 | } 64 | 65 | /** 66 | * Gets y 67 | * 68 | * @return float 69 | */ 70 | public function getY() { 71 | return $this->y; 72 | } 73 | 74 | /** 75 | * Sets y 76 | * 77 | * @param float $y 78 | */ 79 | public function setY($y) { 80 | if ($this->validateOffset($y)) { 81 | $this->y = round($y, 1); 82 | } 83 | } 84 | 85 | /** 86 | * Validates the offset. 87 | * 88 | * @param mixed $value 89 | * 90 | * @return bool 91 | */ 92 | protected function validateOffset($value) { 93 | return is_numeric($value) && $value >= -50 && $value <= 50; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/Document/Styles/ShadowStyle.php: -------------------------------------------------------------------------------- 1 | setColor($color); 43 | $this->setRadius($radius); 44 | } 45 | 46 | /** 47 | * Getter for color. 48 | */ 49 | public function getColor() { 50 | return $this->color; 51 | } 52 | 53 | /** 54 | * Setter for color. 55 | * 56 | * @param string $value 57 | * Color. 58 | * 59 | * @return $this 60 | */ 61 | public function setColor($value) { 62 | if ($this->validateColor($value)) { 63 | $this->color = $value; 64 | } 65 | return $this; 66 | } 67 | 68 | /** 69 | * Getter for radius. 70 | */ 71 | public function getRadius() { 72 | return $this->radius; 73 | } 74 | 75 | /** 76 | * Setter for radius. 77 | * 78 | * @param int $value 79 | * Width. 80 | * 81 | * @return $this 82 | */ 83 | public function setRadius($value) { 84 | if ($this->validateRadius($value)) { 85 | $this->radius = $value; 86 | } 87 | return $this; 88 | } 89 | 90 | /** 91 | * Getter for opacity. 92 | */ 93 | public function getOpacity() { 94 | return $this->opacity; 95 | } 96 | 97 | /** 98 | * Setter for opacity. 99 | * 100 | * @param string $value 101 | * Opacity. 102 | * 103 | * @return $this 104 | */ 105 | public function setOpacity($value) { 106 | if ($this->validateOpacity($value)) { 107 | $this->opacity = $value; 108 | } 109 | return $this; 110 | } 111 | 112 | /** 113 | * Getter for Offset. 114 | * 115 | * @return Offset 116 | */ 117 | public function getOffset() { 118 | return $this->offset; 119 | } 120 | 121 | /** 122 | * Setter for Offset 123 | * 124 | * @param Offset $offset 125 | */ 126 | public function setOffset(Offset $offset) { 127 | $this->offset = $offset; 128 | } 129 | 130 | /** 131 | * Implements JsonSerializable::jsonSerialize(). 132 | */ 133 | public function jsonSerialize() { 134 | $valid = (!isset($this->color) || 135 | $this->validateColor($this->color)); 136 | if (!$valid) { 137 | return NULL; 138 | } 139 | return parent::jsonSerialize(); 140 | } 141 | 142 | /** 143 | * Validates the color attribute. 144 | */ 145 | protected function validateColor($value) { 146 | if (!$this->isHexColor($value)) { 147 | $this->triggerError('color is not valid'); 148 | return FALSE; 149 | } 150 | return TRUE; 151 | } 152 | 153 | /** 154 | * Validates the opacity attribute. 155 | */ 156 | protected function validateOpacity($value) { 157 | if (!is_numeric($value) || $value < 0 || $value > 100) { 158 | $this->triggerError('opacity is not valid'); 159 | return FALSE; 160 | } 161 | return TRUE; 162 | } 163 | 164 | /** 165 | * Validates the radius attribute. 166 | */ 167 | protected function validateRadius($value) { 168 | if (!is_numeric($value) || $value < 0 || $value > 100) { 169 | $this->triggerError('radius is not valid'); 170 | return FALSE; 171 | } 172 | return TRUE; 173 | } 174 | 175 | } 176 | -------------------------------------------------------------------------------- /src/Document/Styles/StrokeStyle.php: -------------------------------------------------------------------------------- 1 | color; 37 | } 38 | 39 | /** 40 | * Setter for color. 41 | * 42 | * @param string $value 43 | * Color. 44 | * 45 | * @return $this 46 | */ 47 | public function setColor($value) { 48 | if ($this->validateColor($value)) { 49 | $this->color = $value; 50 | } 51 | return $this; 52 | } 53 | 54 | /** 55 | * Getter for width. 56 | */ 57 | public function getWidth() { 58 | return $this->width; 59 | } 60 | 61 | /** 62 | * Setter for width. 63 | * 64 | * @param string|int $value 65 | * Width. 66 | * 67 | * @return $this 68 | */ 69 | public function setWidth($value) { 70 | if ($this->validateWidth($value)) { 71 | $this->width = $value; 72 | } 73 | return $this; 74 | } 75 | 76 | /** 77 | * Getter for style. 78 | */ 79 | public function getStyle() { 80 | return $this->style; 81 | } 82 | 83 | /** 84 | * Setter for style. 85 | * 86 | * @param string $value 87 | * Style. 88 | * 89 | * @return $this 90 | */ 91 | public function setStyle($value) { 92 | if ($this->validateStyle($value)) { 93 | $this->style = $value; 94 | } 95 | return $this; 96 | } 97 | 98 | /** 99 | * Implements JsonSerializable::jsonSerialize(). 100 | */ 101 | public function jsonSerialize() { 102 | $valid = (!isset($this->color) || 103 | $this->validateColor($this->color)); 104 | if (!$valid) { 105 | return NULL; 106 | } 107 | return parent::jsonSerialize(); 108 | } 109 | 110 | /** 111 | * Validates the color attribute. 112 | */ 113 | protected function validateColor($value) { 114 | if (!$this->isHexColor($value)) { 115 | $this->triggerError('color is not valid'); 116 | return FALSE; 117 | } 118 | return TRUE; 119 | } 120 | 121 | /** 122 | * Validates the width attribute. 123 | */ 124 | protected function validateWidth($value) { 125 | if (!$this->isSupportedUnit($value)) { 126 | $this->triggerError('width is not valid'); 127 | return FALSE; 128 | } 129 | return TRUE; 130 | } 131 | 132 | /** 133 | * Validates the style attribute. 134 | */ 135 | protected function validateStyle($value) { 136 | if (!in_array($value, array( 137 | 'solid', 138 | 'dashed', 139 | 'dotted', 140 | )) 141 | ) { 142 | $this->triggerError('style is not valid'); 143 | return FALSE; 144 | } 145 | return TRUE; 146 | } 147 | 148 | } 149 | -------------------------------------------------------------------------------- /src/Document/Styles/TextStrokeStyle.php: -------------------------------------------------------------------------------- 1 | color; 33 | } 34 | 35 | /** 36 | * Setter for color. 37 | * 38 | * @param string $value 39 | * Color. 40 | * 41 | * @return $this 42 | */ 43 | public function setColor($value) { 44 | if ($this->validateColor($value)) { 45 | $this->color = $value; 46 | } 47 | return $this; 48 | } 49 | 50 | /** 51 | * Implements JsonSerializable::jsonSerialize(). 52 | */ 53 | public function jsonSerialize() { 54 | $valid = (!isset($this->color) || 55 | $this->validateColor($this->color)); 56 | if (!$valid) { 57 | return NULL; 58 | } 59 | return parent::jsonSerialize(); 60 | } 61 | 62 | /** 63 | * Validates the color attribute. 64 | */ 65 | protected function validateColor($value) { 66 | if (!$this->isHexColor($value)) { 67 | $this->triggerError('color is not valid'); 68 | return FALSE; 69 | } 70 | return TRUE; 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /src/PublisherAPI.php: -------------------------------------------------------------------------------- 1 | assertEquals($expected, $obj->json()); 22 | 23 | $expected = '{"bannerType":"large","frequency":5,"layout":{"margin":{"top":10,"bottom":10}}}'; 24 | $obj->setBannerType('any'); 25 | $obj->setBannerType('double_height'); 26 | $obj->setBannerType('standard'); 27 | $obj->setBannerType('large'); 28 | 29 | $obj->setFrequency(0); 30 | $obj->setFrequency(10); 31 | $obj->setFrequency(5); 32 | 33 | $ad_layout = new AdvertisingLayout(); 34 | $ad_layout->setMargin(new Margin(10, 10)); 35 | $obj->setLayout($ad_layout); 36 | $this->assertEquals($expected, $obj->json()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tests/Document/AnchorTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 25 | 26 | // Test validation. 27 | @$obj->setTargetAnchorPosition('asdf'); 28 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 29 | @$obj->setRangeStart(5); 30 | $this->assertEquals(FALSE, $obj->json()); 31 | 32 | // Optional properties. 33 | $expected = '{"targetAnchorPosition":"bottom","originAnchorPosition":"top","targetComponentIdentifier":"02767FCB-3901-4340-B403-96CDEAF76EE8","rangeStart":5,"rangeLength":20}'; 34 | 35 | $obj->setOriginAnchorPosition('top') 36 | ->setTargetComponentIdentifier('02767FCB-3901-4340-B403-96CDEAF76EE8') 37 | ->setRangeLength(20); 38 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /tests/Document/Animations/ComponentAnimations/AppearAnimationTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/Document/Animations/ComponentAnimations/FadeInAnimationTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 24 | 25 | // Test validation. 26 | @$obj->setInitialAlpha('random'); 27 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 28 | @$obj->setInitialAlpha(1.2); 29 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /tests/Document/Animations/ComponentAnimations/MoveInAnimationTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 24 | 25 | // Test validation. 26 | @$obj->setPreferredStartingPosition('random'); 27 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /tests/Document/Animations/ComponentAnimations/ScaleFadeAnimationTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 24 | 25 | // Test validation. 26 | @$obj->setInitialAlpha('random'); 27 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 28 | @$obj->setInitialAlpha(1.2); 29 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 30 | @$obj->setInitialScale('random'); 31 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 32 | @$obj->setInitialScale(1.2); 33 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /tests/Document/BaseTest.php: -------------------------------------------------------------------------------- 1 | required = $value; 30 | return $this; 31 | } 32 | 33 | } 34 | 35 | /** 36 | * A test class for Base. 37 | */ 38 | class BaseTestValidationClass extends Base { 39 | 40 | /** 41 | * Expose for testing. 42 | */ 43 | public static function isSupportedUnit($value) { 44 | return parent::isSupportedUnit($value); 45 | } 46 | 47 | /** 48 | * Expose for testing. 49 | */ 50 | public static function isUnitInterval($value) { 51 | return parent::isUnitInterval($value); 52 | } 53 | 54 | /** 55 | * Expose for testing. 56 | */ 57 | public static function isHexColor($value) { 58 | return parent::isHexColor($value); 59 | } 60 | 61 | } 62 | 63 | /** 64 | * Tests for the Base class. 65 | */ 66 | class BaseTest extends PHPUnit_Framework_TestCase { 67 | 68 | /** 69 | * Setting properties and outputting json. 70 | */ 71 | public function testSetters() { 72 | 73 | $obj = new BaseTestAttributesClass(); 74 | 75 | // Missing required. 76 | $this->assertEquals(FALSE, @$obj->json()); 77 | 78 | $json = '{"required":"asdf"}'; 79 | $obj->setRequired('asdf'); 80 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 81 | 82 | $obj = new BaseTestValidationClass(); 83 | 84 | // PHP "arrays" by default get converted to JSON arrays. 85 | $json = '{}'; 86 | $this->assertEquals($json, $obj->json()); 87 | 88 | foreach (array( 89 | // Out of range. 90 | 2, 1.1, -1, -0.1, 91 | ) as $value 92 | ) { 93 | $this->assertEquals(FALSE, 94 | @BaseTestValidationClass::isUnitInterval($value)); 95 | } 96 | foreach (array( 97 | 0, 1, 0.1, 98 | ) as $value 99 | ) { 100 | $this->assertEquals(TRUE, 101 | BaseTestValidationClass::isUnitInterval($value)); 102 | } 103 | 104 | foreach (array( 105 | 1.1, 'asdf', 106 | ) as $value 107 | ) { 108 | $this->assertEquals(FALSE, 109 | @BaseTestValidationClass::isSupportedUnit($value)); 110 | } 111 | foreach (array( 112 | // Integers. 113 | 0, 1, 10, 515, 114 | // With unit. 115 | '1vh', '10vw', '515vmin', '1vmax', '1gut', '1cw', '1pt', 116 | ) as $value 117 | ) { 118 | // 0 is supported 119 | if ($value == 0) { 120 | $this->assertEquals(TRUE, TRUE); 121 | } 122 | else { 123 | $this->assertEquals(TRUE, 124 | BaseTestValidationClass::isSupportedUnit($value)); 125 | } 126 | } 127 | 128 | foreach (array( 129 | // Wrong number or digits. 130 | '#00', '#0000000000', '#', 131 | // Missing "#". 132 | '000', '000000', '00000000', 133 | // Not uppercase. 134 | '#fff', '#ffffff', '#ffffffff', 135 | // Digit out of range. 136 | '#00G', '#G00000', '#00G00000', 137 | // Not hex color. 138 | 'blue', 'black', 139 | ) as $value 140 | ) { 141 | $this->assertEquals(FALSE, 142 | @BaseTestValidationClass::isHexColor($value)); 143 | } 144 | foreach (array( 145 | '#000', '#FFF', '#3C6', 146 | '#000000', '#FFFFFF', '#3C69F0', 147 | '#00000000', '#FFFFFFFF', '#3C69F0E1', 148 | ) as $value 149 | ) { 150 | $this->assertEquals(TRUE, 151 | BaseTestValidationClass::isHexColor($value)); 152 | } 153 | 154 | } 155 | 156 | } 157 | -------------------------------------------------------------------------------- /tests/Document/Behaviors/BackgroundMotionTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/Document/Behaviors/BackgroundParallaxTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/Document/Behaviors/MotionTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/Document/Behaviors/ParallaxTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/Document/Behaviors/SpringyTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/Document/Components/AuthorTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/Document/Components/BodyTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/Document/Components/BylineTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/Document/Components/CaptionTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/Document/Components/ComponentTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 41 | 42 | // Test assigning document level objects. 43 | $expected = '{"role":"role","layout":"key"}'; 44 | $layout = new ComponentLayout(); 45 | $document = new Document('1', 'title', 'en-us', new Layout(2, 512)); 46 | $document->addComponentLayout('key', $layout); 47 | $obj->setLayout('key', $document); 48 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 49 | @$obj->setLayout('invalid key', $document); 50 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 51 | 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /tests/Document/Components/ContainerBaseTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 26 | 27 | $expected = '{"role":"container","components":[{"role":"body","text":"some body text."}]}'; 28 | $obj->addComponent(new Body('some body text.')); 29 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 30 | 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /tests/Document/Components/FacebookPostTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/Document/Components/HeaderTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/Document/Components/HeadingTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 24 | 25 | // Validate. 26 | @$obj->setRole('asdf'); 27 | $this->assertEquals(FALSE, $obj->json()); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /tests/Document/Components/IllustratorTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/Document/Components/ImageTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /tests/Document/Components/IntroTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/Document/Components/PhotographerTest.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chapter-three/AppleNewsAPI/3d8e8f19b4c63f772c01dbb0927b52d51b9496ee/tests/Document/Components/PhotographerTest.php -------------------------------------------------------------------------------- /tests/Document/Components/PullquoteTest.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chapter-three/AppleNewsAPI/3d8e8f19b4c63f772c01dbb0927b52d51b9496ee/tests/Document/Components/PullquoteTest.php -------------------------------------------------------------------------------- /tests/Document/Components/QuoteTest.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chapter-three/AppleNewsAPI/3d8e8f19b4c63f772c01dbb0927b52d51b9496ee/tests/Document/Components/QuoteTest.php -------------------------------------------------------------------------------- /tests/Document/Components/TextTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 43 | 44 | $expected = '{"role":"role","text":"some other text"}'; 45 | $obj->setText('some other text'); 46 | $this->assertEquals('some other text', $obj->getText()); 47 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 48 | 49 | $expected = '{"role":"role","text":"some other text","format":"markdown"}'; 50 | $obj->setFormat('markdown'); 51 | $this->assertEquals('markdown', $obj->getFormat()); 52 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 53 | 54 | // Test assigning document level objects. 55 | $document = new Document('1', 'title', 'en-us', new Layout(2, 512)); 56 | 57 | $expected = '{"role":"role","text":"some other text","format":"markdown","textStyle":"key"}'; 58 | $style = new ComponentTextStyle(); 59 | $document->addComponentTextStyle('key', $style); 60 | $obj->setTextStyle('key', $document); 61 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 62 | @$obj->setTextStyle('invalid key', $document); 63 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 64 | 65 | $expected = '{"role":"role","text":"some other text","format":"markdown","textStyle":"key","inlineTextStyles":[{"rangeStart":0,"rangeLength":1,"textStyle":{}}]}'; 66 | $style = new InlineTextStyle(0, 1, new TextStyle()); 67 | $obj->addInlineTextStyles($style); 68 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 69 | 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /tests/Document/Components/TitleTest.php: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chapter-three/AppleNewsAPI/3d8e8f19b4c63f772c01dbb0927b52d51b9496ee/tests/Document/Components/TitleTest.php -------------------------------------------------------------------------------- /tests/Document/Components/TweetTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/Document/Components/VinePostTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /tests/Document/ContentInsetTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($json, $obj->json()); 24 | 25 | // Optional properties. 26 | $expected = '{"top":true,"right":true,"bottom":true,"left":true}'; 27 | 28 | $obj->setTop(TRUE); 29 | $obj->setRight(TRUE); 30 | $obj->setBottom(TRUE); 31 | $obj->setLeft(TRUE); 32 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /tests/Document/Layouts/AdvertisingLayoutTest.php: -------------------------------------------------------------------------------- 1 | setMargin(new Margin(10, 10)); 20 | $this->assertEquals($expected, $obj->json()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Document/Layouts/ComponentLayoutTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($expected, $obj->json()); 26 | 27 | // Test validation. 28 | @$obj->setMargin(new \stdClass()); 29 | $this->assertEquals($expected, $obj->json()); 30 | @$obj->setContentInset(new \stdClass()); 31 | $this->assertEquals($expected, $obj->json()); 32 | @$obj->setIgnoreDocumentMargin('asdf'); 33 | $this->assertEquals($expected, $obj->json()); 34 | @$obj->setIgnoreDocumentGutter('asdf'); 35 | $this->assertEquals($expected, $obj->json()); 36 | @$obj->setMinimumHeight('1asdf'); 37 | $this->assertEquals($expected, $obj->json()); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /tests/Document/Layouts/LayoutTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($json, $obj->json()); 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /tests/Document/MarginTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($json, $obj->json()); 24 | 25 | // Test validation. 26 | @$obj->setTop('67rndm'); 27 | @$obj->setBottom('57rndm'); 28 | $this->assertEquals($json, $obj->json()); 29 | 30 | // Optional properties. 31 | $expected = '{"top":"10vh","bottom":15}'; 32 | 33 | $obj->setTop('10vh'); 34 | $obj->setBottom(15); 35 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 36 | 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /tests/Document/MetadataTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($json, $obj->json()); 24 | 25 | // Test validation. 26 | for ($i = 0; $i < 50; $i++) { 27 | $obj->addKeyword('a'); 28 | } 29 | @$obj->addKeyword('a'); 30 | $this->assertEquals(50, count($obj->getKeywords()), 31 | 'Max 50 keywords.'); 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /tests/Document/Styles/BorderTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($json, $obj->json()); 25 | 26 | // Optional properties. 27 | $json = '{"all":{}}'; 28 | 29 | $obj->setAll(new StrokeStyle()); 30 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 31 | 32 | $json = '{"all":{},"top":true,"bottom":false,"left":true,"right":false}'; 33 | 34 | $obj->setTop(TRUE) 35 | ->setBottom(FALSE) 36 | ->setLeft(TRUE) 37 | ->setRight(FALSE); 38 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /tests/Document/Styles/ComponentStyleTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($json, $obj->json()); 26 | 27 | // Optional properties. 28 | $json = '{"fill":{"type":"image","URL":"bundle://header-image.png"},"border":{}}'; 29 | $obj->setFill(new ImageFill('bundle://header-image.png')) 30 | ->setBorder(new Border()); 31 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 32 | 33 | $json = '{"backgroundColor":"#FFFFFF","fill":{"type":"image","URL":"bundle://header-image.png"},"opacity":1,"border":{}}'; 34 | $obj->setBackgroundColor('#FFFFFF') 35 | ->setOpacity(1); 36 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 37 | 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /tests/Document/Styles/ComponentTextStyleTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($json, $obj->json()); 26 | 27 | // Optional properties. 28 | $json = '{"dropCapStyle":{"numberOfLines":3},"linkStyle":{}}'; 29 | 30 | $obj->setDropCapStyle(new DropCapStyle(3)) 31 | ->setLinkStyle(new TextStyle()); 32 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 33 | 34 | $json = '{"dropCapStyle":{"numberOfLines":3},"linkStyle":{},"textAlignment":"right","lineHeight":14,"hyphenation":true}'; 35 | 36 | $obj->setTextAlignment('right') 37 | ->setLineHeight(14) 38 | ->setHyphenation(TRUE); 39 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /tests/Document/Styles/DropCapStyleTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($json, $obj->json()); 23 | 24 | // Test Validation. 25 | @$obj->setTextColor('000000'); 26 | $this->assertEquals($json, $obj->json()); 27 | @$obj->setTextColor('#00000'); 28 | $this->assertEquals($json, $obj->json()); 29 | @$obj->setTextColor('blue'); 30 | $this->assertEquals($json, $obj->json()); 31 | @$obj->setBackgroundColor('000000'); 32 | $this->assertEquals($json, $obj->json()); 33 | @$obj->setBackgroundColor('#00000'); 34 | $this->assertEquals($json, $obj->json()); 35 | @$obj->setBackgroundColor('blue'); 36 | $this->assertEquals($json, $obj->json()); 37 | 38 | // Optional properties. 39 | $json = '{"numberOfLines":3,"numberOfCharacters":2,"fontName":"HelveticaNeue","textColor":"#FFF","backgroundColor":"#000000","padding":5}'; 40 | 41 | $obj->setNumberOfCharacters(2) 42 | ->setFontName('HelveticaNeue') 43 | ->setTextColor('#FFF') 44 | ->setBackgroundColor('#000000') 45 | ->setPadding(5); 46 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /tests/Document/Styles/Fills/FillTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($json, $obj->json()); 40 | 41 | // Optional properties. 42 | $json = '{"type":"video","attachment":"fixed"}'; 43 | $obj->setAttachment('fixed'); 44 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 45 | 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /tests/Document/Styles/Fills/Gradients/ColorStopTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($json, $obj->json()); 25 | 26 | $json = '{"color":"#FF0000","location":25}'; 27 | 28 | $obj->setLocation(25); 29 | 30 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /tests/Document/Styles/Fills/Gradients/GradientFillTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($json, $obj->json()); 42 | 43 | $json = '{"type":"linear_gradient","colorStops":[{"color":"#FF0000"},{"color":"#000000"}],"attachment":"fixed"}'; 44 | $obj->setAttachment('fixed'); 45 | 46 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /tests/Document/Styles/Fills/Gradients/LinearGradientFillTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($json, $obj->json()); 29 | 30 | $json = '{"type":"linear_gradient","colorStops":[{"color":"#FF0000"},{"color":"#000000"}],"attachment":"fixed"}'; 31 | $obj->setAttachment('fixed'); 32 | 33 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /tests/Document/Styles/Fills/ImageFillTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($json, $obj->json()); 26 | 27 | // Optional properties. 28 | $json = '{"URL":"bundle:\/\/header-image.png","fillMode":"cover","verticalAlignment":"top","horizontalAlignment":"center","type":"image","attachment":"fixed"}'; 29 | $obj->setAttachment('fixed') 30 | ->setFillMode('cover') 31 | ->setVerticalAlignment('top') 32 | ->setHorizontalAlignment('center'); 33 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /tests/Document/Styles/Fills/VideoFillTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($json, $obj->json()); 26 | 27 | // Optional properties. 28 | $json = '{"URL":"https://live-streaming.apple.com/hls/2014/fded0-1077dae/main.m3u8","type":"video","stillURL":"bundle://video-still.jpg","fillMode":"fit","verticalAlignment":"top","horizontalAlignment":"center","attachment":"fixed"}'; 29 | $obj->setAttachment('fixed') 30 | ->setFillMode('fit') 31 | ->setVerticalAlignment('top') 32 | ->setHorizontalAlignment('center'); 33 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 34 | 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /tests/Document/Styles/InlineTextStyleTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($expected, $obj->json()); 27 | 28 | $expected = '{"rangeStart":1,"rangeLength":10,"textStyle":{}}'; 29 | $obj->setRangeLength(10); 30 | $obj->setRangeStart(1); 31 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 32 | 33 | // Test assigning document level objects. 34 | $document = new Document('1', 'title', 'en-us', new Layout(2, 512)); 35 | 36 | $expected = '{"rangeStart":1,"rangeLength":10,"textStyle":"key"}'; 37 | $style = new TextStyle(); 38 | $document->addTextStyle('key', $style); 39 | $obj->setTextStyle('key', $document); 40 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 41 | @$obj->setTextStyle('invalid key', $document); 42 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 43 | 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /tests/Document/Styles/OffsetTest.php: -------------------------------------------------------------------------------- 1 | assertJsonStringEqualsJsonString($json, $obj->json()); 24 | 25 | $obj->setX('asdf'); 26 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 27 | $obj->setY('asdf'); 28 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /tests/Document/Styles/ShadowStyleTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($json, $obj->json()); 25 | 26 | // Test Validation. 27 | @$obj->setColor('000000'); 28 | $this->assertEquals($json, $obj->json()); 29 | @$obj->setColor('blue'); 30 | $this->assertEquals($json, $obj->json()); 31 | 32 | @$obj->setRadius(1000); 33 | $this->assertEquals($json, $obj->json()); 34 | @$obj->setRadius('asdf'); 35 | $this->assertEquals($json, $obj->json()); 36 | 37 | @$obj->setOpacity(1000); 38 | $this->assertEquals($json, $obj->json()); 39 | @$obj->setOpacity('asdf'); 40 | $this->assertEquals($json, $obj->json()); 41 | 42 | // Optional properties. 43 | $json = '{"color":"#FFC800","radius":50,"opacity":50,"offset":{"x":50,"y":50}}'; 44 | 45 | @$obj->setColor('#FFC800'); 46 | @$obj->setRadius(50); 47 | @$obj->setOpacity(50); 48 | @$obj->setOffset(new Offset(50, 50)); 49 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 50 | 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /tests/Document/Styles/StrokeStyleTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($json, $obj->json()); 24 | 25 | // Test Validation. 26 | @$obj->setColor('000000'); 27 | $this->assertEquals($json, $obj->json()); 28 | @$obj->setColor('#00000'); 29 | $this->assertEquals($json, $obj->json()); 30 | @$obj->setColor('blue'); 31 | $this->assertEquals($json, $obj->json()); 32 | 33 | @$obj->setStyle('asdf'); 34 | $this->assertEquals($json, $obj->json()); 35 | 36 | @$obj->setWidth('72rndm'); 37 | $this->assertEquals($json, $obj->json()); 38 | 39 | // Optional properties. 40 | $json = '{"color":"#FFC800","width":1,"style":"dashed"}'; 41 | 42 | $obj->setColor('#FFC800'); 43 | $obj->setWidth(1); 44 | $obj->setStyle('dashed'); 45 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /tests/Document/Styles/TextStrokeStyleTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($json, $obj->json()); 24 | 25 | // Test Validation. 26 | @$obj->setColor('000000'); 27 | $this->assertEquals($json, $obj->json()); 28 | @$obj->setColor('#00000'); 29 | $this->assertEquals($json, $obj->json()); 30 | @$obj->setColor('blue'); 31 | $this->assertEquals($json, $obj->json()); 32 | 33 | // Optional properties. 34 | $json = '{"color":"#FFC800"}'; 35 | 36 | $obj->setColor('#FFC800'); 37 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /tests/Document/Styles/TextStyleTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($json, $obj->json()); 25 | 26 | // Test Validation. 27 | @$obj->setTextColor('000000'); 28 | $this->assertEquals($json, $obj->json()); 29 | @$obj->setTextColor('#00000'); 30 | $this->assertEquals($json, $obj->json()); 31 | @$obj->setTextColor('blue'); 32 | $this->assertEquals($json, $obj->json()); 33 | 34 | @$obj->setTextTransform('asdf'); 35 | $this->assertEquals($json, $obj->json()); 36 | 37 | @$obj->setBackgroundColor('000000'); 38 | $this->assertEquals($json, $obj->json()); 39 | @$obj->setBackgroundColor('#00000'); 40 | $this->assertEquals($json, $obj->json()); 41 | @$obj->setBackgroundColor('blue'); 42 | $this->assertEquals($json, $obj->json()); 43 | 44 | @$obj->setVerticalAlignment('asdf'); 45 | $this->assertEquals($json, $obj->json()); 46 | 47 | // Optional properties. 48 | $json = '{"underline":{},"strikethrough":{}}'; 49 | 50 | $obj->setUnderline(new TextStrokeStyle()); 51 | $obj->setStrikethrough(new TextStrokeStyle()); 52 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 53 | 54 | // Reset object. 55 | $obj = new TextStyle(); 56 | 57 | $json = '{"fontName":"GillSans-Bold","fontSize":12,"textColor":"#333333","textTransform":"capitalize","backgroundColor":"#FF00007F","verticalAlignment":"baseline","tracking":0.5}'; 58 | 59 | $obj->setFontName('GillSans-Bold'); 60 | $obj->setTextColor('#333333'); 61 | $obj->setTextTransform('capitalize'); 62 | $obj->setBackgroundColor('#FF00007F'); 63 | $obj->setVerticalAlignment('baseline'); 64 | $obj->setFontSize(12); 65 | $obj->setTracking(0.5); 66 | $this->assertJsonStringEqualsJsonString($json, $obj->json()); 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /tests/DocumentTest.php: -------------------------------------------------------------------------------- 1 | addComponent(new Body('body text')) 37 | ->addComponentTextStyle('default', new ComponentTextStyle()); 38 | 39 | $expected = '{"version":"' . $obj->getVersion() . '","identifier":"1","title":"title","language":"en","layout":{"columns":7,"width":1024},"components":[{"text":"body text","role": "body"}],"componentTextStyles":{"default":{}}}'; 40 | 41 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 42 | 43 | // Optional properties. 44 | $expected = '{"version":"' . $obj->getVersion() . '","identifier":"1","title":"title","subtitle":"subtitle","language":"en","layout":{"columns":7,"width":1024},"components":[{"text":"body text","role": "body"}],"componentTextStyles":{"default":{}}}'; 45 | 46 | $obj->setSubtitle('subtitle'); 47 | $this->assertJsonStringEqualsJsonString($expected, $obj->json()); 48 | 49 | // Test validation. 50 | $obj = new Document(1, 'title', 'en', new Layout(7, 1024)); 51 | $this->assertEquals(FALSE, $obj->json()); 52 | 53 | } 54 | 55 | } 56 | --------------------------------------------------------------------------------