Esempio n. 1
0
 /**
  * Creates a message instance from a file.
  *
  * @param string $file - File.
  *
  * @return Message
  */
 public function createMessageFromFile(string $file) : Message
 {
     if (!is_file($file)) {
         throw new \InvalidArgumentException('File "' . $file . '" does not exist!');
     }
     $config = new Config();
     $config->load(['file' => $file]);
     if (!$config->has('body')) {
         throw new \RuntimeException('File has no "body" element.');
     }
     return $this->createMessage($config->get('body'), $config->get('headers', []), $config->get('options', []));
 }
Esempio n. 2
0
 /**
  * Imports a graph from a source. We use the ironedge/config component
  * to read the data from a ReaderInterface, and then we use the obtained array
  * to call this service's "create" method to create the graph.
  *
  * @param string $readerType    - Reader Type.
  * @param array  $readerOptions - Reader options.
  *
  * @throws ValidationException
  * @throws \IronEdge\Component\Config\Exception\ImportException
  * @throws \IronEdge\Component\Config\Exception\InvalidOptionTypeException
  *
  * @return NodeInterface
  */
 public function import(string $readerType, array $readerOptions = []) : NodeInterface
 {
     $options = ['reader' => $readerType, 'loadOptions' => ['processImports' => true, 'readerOptions' => $readerOptions]];
     $config = new Config([], $options);
     $config->load();
     return $this->create($config->getData());
 }