Version 1
[yaffs-website] / web / modules / contrib / migrate_plus / src / Plugin / migrate_plus / data_fetcher / File.php
1 <?php
2
3 namespace Drupal\migrate_plus\Plugin\migrate_plus\data_fetcher;
4
5 use Drupal\migrate\MigrateException;
6 use Drupal\migrate_plus\DataFetcherPluginBase;
7
8 /**
9  * Retrieve data from a local path or general URL for migration.
10  *
11  * @DataFetcher(
12  *   id = "file",
13  *   title = @Translation("File")
14  * )
15  */
16 class File extends DataFetcherPluginBase {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function setRequestHeaders(array $headers) {
22     // Does nothing.
23   }
24
25   /**
26    * {@inheritdoc}
27    */
28   public function getRequestHeaders() {
29     // Does nothing.
30     return [];
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function getResponse($url) {
37       $response = file_get_contents($url);
38       if ($response === FALSE) {
39         throw new MigrateException('file parser plugin: could not retrieve data from ' . $url);
40       }
41     return $response;
42   }
43
44   /**
45    * {@inheritdoc}
46    */
47   public function getResponseContent($url) {
48     $response = $this->getResponse($url);
49     return $response;
50   }
51
52 }