diff --git a/README.md b/README.md index e1af806..be05b22 100644 --- a/README.md +++ b/README.md @@ -196,15 +196,12 @@ Parsers are what decides how to parse a certain file, and how to structure its r If you have a string containing XML, you may also parse that using the following setup. ```php - use pandaac\Exporter\Parsers; - use pandaac\Exporter\Exporter; + use pandaac\Exporter\Parsers\XMLSource; use pandaac\Exporter\Sources\StringContent; - $exporter = new Exporter( - new StringContent('') - ); - - $response = $exporter->parse(new Parsers\XMLSource); + $exporter->parse(new XMLSource( + new StringContent('') + )); ``` ### OTBM Parsers diff --git a/src/Exporter.php b/src/Exporter.php index 6925c10..1e9ea67 100644 --- a/src/Exporter.php +++ b/src/Exporter.php @@ -26,11 +26,11 @@ class Exporter const ISSUES = 'https://github.com/pandaac/exporter/issues'; /** - * Holds the source. + * Holds the directory path. * - * @var \pandaac\Exporter\Contracts\Source|string + * @var string */ - protected $source; + protected $directory; /** * Holds the output implementation. @@ -42,14 +42,14 @@ class Exporter /** * Instantiate a new exporter object. * - * @param \pandaac\Exporter\Contracts\Source|string $source + * @param string $directory * @return void */ - public function __construct($source) + public function __construct($directory) { - $this->source = $source; + $this->directory = $directory; - if (! $source instanceof Source and ! file_exists($source)) { + if (! file_exists($directory)) { throw new InvalidArgumentException('The first argument must be a valid directory.'); } } @@ -57,23 +57,23 @@ public function __construct($source) /** * Get the absolute file path. * - * @param string $path - * @param string $custom null + * @param \pandaac\Exporter\Contracts\Source|string $source + * @param string $file null * @return \pandaac\Exporter\Contracts\Source|string */ - public function getAbsolutePath($path, $custom = null) + public function getAbsolutePath($source, $file = null) { - if ($this->source instanceof Source) { - return $this->source; + if ($source instanceof Source) { + return $source; } - $path = ltrim($path, DIRECTORY_SEPARATOR); + $source = ltrim($source, DIRECTORY_SEPARATOR); - if (substr($path, -1, 1) === DIRECTORY_SEPARATOR) { - $custom = $path.$custom; + if (substr($source, -1, 1) === DIRECTORY_SEPARATOR) { + $file = $source.$file; } - return $this->source.DIRECTORY_SEPARATOR.($custom ?: $path); + return $this->directory.DIRECTORY_SEPARATOR.($file ?: $source); } /** diff --git a/src/Parsers/XMLSource.php b/src/Parsers/XMLSource.php index 2e5063f..dcb090d 100644 --- a/src/Parsers/XMLSource.php +++ b/src/Parsers/XMLSource.php @@ -6,18 +6,29 @@ use pandaac\Exporter\Exporter; use pandaac\Exporter\Engines\XML; use Illuminate\Support\Collection; +use pandaac\Exporter\Contracts\Source; use pandaac\Exporter\Contracts\Parser as Contract; class XMLSource implements Contract { + /** + * Instantiate a new XML Source parser. + * + * @param \pandaac\Exporter\Contracts\Source $source + */ + public function __construct(Source $source) + { + $this->source = $source; + } + /** * Get the relative file path. * - * @return string + * @return \pandaac\Exporter\Contracts\Source */ public function filePath() { - return null; + return $this->source; } /** @@ -41,6 +52,6 @@ public function engine(array $attributes) */ public function parse(Exporter $exporter, Output $output, array $attributes) { - return $output->all(); + return $output; } }