Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed May 16, 2016
2 parents c4a7769 + 8dbd870 commit 9bec061
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 45 deletions.
40 changes: 28 additions & 12 deletions src/Resource/Domain/Model/Resource/AbstractResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,24 +223,40 @@ function ($pathIdentifier) {
*
* @param array $partMethod Part method components
* @param array $arguments Part method arguments
* @return mixed|AbstractResource Self reference
* @return mixed|AbstractResource Getter result / self reference
*/
protected function callPartMethod(array $partMethod, array $arguments)
{
$partMethod = $partMethod[1];
$isGetterMethod = (!strncmp('get', $partMethod, 3));
$delegateArguments = $isGetterMethod ? array() : array_slice($arguments, 0, 1);
$subpartPathArgIndex = $isGetterMethod ? 0 : 1;
$subparts = $this->partPath(
(count($arguments) > $subpartPathArgIndex) ? $arguments[$subpartPathArgIndex] : '/'
);
$delegateResult = $this->part()->delegate($partMethod, $subparts, $delegateArguments);
return strncmp('get', $partMethod, 3)
? $this->callNonGetterPartMethod($partMethod, $arguments)
: $this->callGetterPartMethod($partMethod, $arguments);
}

if ($isGetterMethod) {
return $delegateResult;
}
/**
* Call a getter method on one of the subparts
*
* @param string $partMethod Part method
* @param array $arguments Part method arguments
* @return mixed Getter result
*/
protected function callGetterPartMethod($partMethod, array $arguments)
{
$subparts = $this->partPath(count($arguments) ? $arguments[0] : '/');
return $this->part()->delegate($partMethod, $subparts, []);
}

$this->part = $delegateResult;
/**
* Call a non-getter method on one of the subparts
*
* @param string $partMethod Part method
* @param array $arguments Part method arguments
* @return AbstractResource Self reference
*/
protected function callNonGetterPartMethod($partMethod, array $arguments)
{
$subparts = $this->partPath((count($arguments) > 1) ? $arguments[1] : '/');
$this->part = $this->part()->delegate($partMethod, $subparts, array_slice($arguments, 0, 1));
return $this;
}
}
3 changes: 2 additions & 1 deletion src/Resource/Ports/Tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public static function delete($src, ...$parameters)
*
* @return InvalidArgumentException If the reader stream wrapper is invalid
*/
protected static function failInvalidReader() {
protected static function failInvalidReader()
{
return new InvalidArgumentException(
'Invalid reader stream wrapper',
InvalidArgumentException::INVALID_READER_STREAM_WRAPPER
Expand Down
2 changes: 1 addition & 1 deletion src/Resource/Tests/AbstractDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @package Jkphl_apparat/resource
* @author Joschi Kuphal <joschi@kuphal.net> / @jkphl
* @copyright Copyright © 2016 Joschi Kuphal <joschi@kuphal.net> / @jkphl
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
* @license http://opensource.org/licenses/MIT The MIT License (MIT)
*/

/***********************************************************************************
Expand Down
38 changes: 19 additions & 19 deletions src/Resource/Tests/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,41 +102,41 @@ class FactoryTest extends AbstractTest
*
* @var string
*/
const TXT_FILE = __DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . 'cc0.txt';
const TXT_FILE = __DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR.'cc0.txt';

/**
* Example JSON file
*
* @var string
*/
const JSON_FILE = __DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . 'invoice.json';
const JSON_FILE = __DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR.'invoice.json';

/**
* Example YAML file
*
* @var string
*/
const YAML_FILE = __DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . 'invoice.yaml';
const YAML_FILE = __DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR.'invoice.yaml';

/**
* Example CommonMark file
*
* @var string
*/
const COMMONMARK_FILE = __DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . 'commonmark.md';
const COMMONMARK_FILE = __DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR.'commonmark.md';

/**
* Example FrontMark file with YAML front matter
*
* @var string
*/
const YAML_FRONTMARK_FILE = __DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . 'yaml-frontmark.md';
const YAML_FRONTMARK_FILE = __DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR.'yaml-frontmark.md';
/**
* Example FrontMark file with JSON front matter
*
* @var string
*/
const JSON_FRONTMARK_FILE = __DIR__ . DIRECTORY_SEPARATOR . 'Fixture' . DIRECTORY_SEPARATOR . 'json-frontmark.md';
const JSON_FRONTMARK_FILE = __DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR.'json-frontmark.md';

/**
* Sets up the fixture
Expand Down Expand Up @@ -169,7 +169,7 @@ public function testTextFactoryStringReader()
*/
public function testTextFactoryFileReader()
{
$textResource = Resource::text('file://' . self::TXT_FILE);
$textResource = Resource::text('file://'.self::TXT_FILE);
$this->assertInstanceOf(TextResource::class, $textResource);
$this->assertEquals($this->text, $textResource->get());
}
Expand All @@ -182,7 +182,7 @@ public function testTextFactoryFileReader()
*/
public function testTextFactoryInvalidReader()
{
Resource::text('foo://' . self::TXT_FILE);
Resource::text('foo://'.self::TXT_FILE);
}

/**
Expand All @@ -204,7 +204,7 @@ public function testTextFactoryFileWriter()
{
$tempFileName = $this->createTemporaryFileName();
$textResource = Resource::text($this->text);
$writer = $textResource->toTarget('file://' . $tempFileName, FileWriter::FILE_CREATE);
$writer = $textResource->toTarget('file://'.$tempFileName, FileWriter::FILE_CREATE);
$this->assertInstanceOf(FileWriter::class, $writer);
$this->assertStringEqualsFile($tempFileName, $this->text);
}
Expand All @@ -217,15 +217,15 @@ public function testTextFactoryFileWriter()
*/
public function testTextFactoryInvalidWriter()
{
Resource::text($this->text)->toTarget('foo://' . $this->createTemporaryFileName());
Resource::text($this->text)->toTarget('foo://'.$this->createTemporaryFileName());
}

/**
* Test the JSON resource factory with a file path input (file reader)
*/
public function testJsonFactoryFileReader()
{
$jsonResource = Resource::json('file://' . self::JSON_FILE);
$jsonResource = Resource::json('file://'.self::JSON_FILE);
$this->assertInstanceOf(JsonResource::class, $jsonResource);
$this->assertEquals($this->json, $jsonResource->get());
}
Expand All @@ -235,7 +235,7 @@ public function testJsonFactoryFileReader()
*/
public function testYamlFactoryFileReader()
{
$yamlResource = Resource::yaml('file://' . self::YAML_FILE);
$yamlResource = Resource::yaml('file://'.self::YAML_FILE);
$this->assertInstanceOf(YamlResource::class, $yamlResource);
$this->assertEquals($this->yaml, $yamlResource->get());
}
Expand All @@ -245,7 +245,7 @@ public function testYamlFactoryFileReader()
*/
public function testCommonMarkFactoryFileReader()
{
$commonMarkResource = Resource::commonMark('file://' . self::COMMONMARK_FILE);
$commonMarkResource = Resource::commonMark('file://'.self::COMMONMARK_FILE);
$this->assertInstanceOf(CommonMarkResource::class, $commonMarkResource);
$this->assertEquals($this->commonMark, $commonMarkResource->get());
}
Expand All @@ -255,18 +255,18 @@ public function testCommonMarkFactoryFileReader()
*/
public function testYamlFrontMarkFactoryFileReader()
{
$yamlFrontMarkResource = Resource::frontMark('file://' . self::YAML_FRONTMARK_FILE);
$this->assertInstanceOf(FrontMarkResource::class, $yamlFrontMarkResource);
$this->assertEquals($this->yamlFrontMark, strval($yamlFrontMarkResource));
$yamlFMResource = Resource::frontMark('file://'.self::YAML_FRONTMARK_FILE);
$this->assertInstanceOf(FrontMarkResource::class, $yamlFMResource);
$this->assertEquals($this->yamlFrontMark, strval($yamlFMResource));
}

/**
* Test the JSON FrontMark resource factory with a file path input (file reader)
*/
public function testJsonFrontMarkFactoryFileReader()
{
$jsonFrontMarkResource = Resource::frontMark('file://' . self::JSON_FRONTMARK_FILE);
$this->assertInstanceOf(FrontMarkResource::class, $jsonFrontMarkResource);
$this->assertEquals($this->jsonFrontMark, strval($jsonFrontMarkResource));
$jsonFMResource = Resource::frontMark('file://'.self::JSON_FRONTMARK_FILE);
$this->assertInstanceOf(FrontMarkResource::class, $jsonFMResource);
$this->assertEquals($this->jsonFrontMark, strval($jsonFMResource));
}
}
5 changes: 3 additions & 2 deletions src/Resource/Tests/FileIoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ public function testFileWriterWithRecursiveDirectoryCreation()
$tempFile = $this->createTemporaryFile();
unlink($tempFile);
$this->tmpFiles[] = $tempFile .= DIRECTORY_SEPARATOR.'recursive.txt';
$textResource->dump(Kernel::create(Writer::class,
[$tempFile, Writer::FILE_CREATE | Writer::FILE_CREATE_DIRS]));
$textResource->dump(
Kernel::create(Writer::class, [$tempFile, Writer::FILE_CREATE | Writer::FILE_CREATE_DIRS])
);
$this->assertFileEquals(self::TXT_FILE, $tempFile);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Resource/Tests/Fixture/commonmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ Readability, however, is emphasized above all else. A Markdown-formatted
document should be publishable as-is, as plain text, without looking
like it's been marked up with tags or formatting instructions. While
Markdown's syntax has been influenced by several existing text-to-HTML
filters -- including [Setext] [1], [atx] [2], [Textile] [3], [reStructuredText] [4],
[Grutatext] [5], and [EtText] [6] -- the single biggest source of
filters -- including [Setext][1], [atx][2], [Textile][3], [reStructuredText][4],
[Grutatext][5], and [EtText][6] -- the single biggest source of
inspiration for Markdown's syntax is the format of plain text email.

[1]: http://docutils.sourceforge.net/mirror/setext.html
Expand Down Expand Up @@ -209,7 +209,7 @@ work best -- and look better -- when you format them with hard breaks.

<h3 id="header">Headers</h3>

Markdown supports two styles of headers, [Setext] [1] and [atx] [2].
Markdown supports two styles of headers, [Setext][1] and [atx][2].

Setext-style headers are "underlined" using equal signs (for first-level
headers) and dashes (for second-level headers). For example:
Expand Down
6 changes: 3 additions & 3 deletions src/Resource/Tests/Fixture/json-frontmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Readability, however, is emphasized above all else. A Markdown-formatted
document should be publishable as-is, as plain text, without looking
like it's been marked up with tags or formatting instructions. While
Markdown's syntax has been influenced by several existing text-to-HTML
filters -- including [Setext] [1], [atx] [2], [Textile] [3], [reStructuredText] [4],
[Grutatext] [5], and [EtText] [6] -- the single biggest source of
filters -- including [Setext][1], [atx][2], [Textile][3], [reStructuredText][4],
[Grutatext][5], and [EtText][6] -- the single biggest source of
inspiration for Markdown's syntax is the format of plain text email.

[1]: http://docutils.sourceforge.net/mirror/setext.html
Expand Down Expand Up @@ -213,7 +213,7 @@ work best -- and look better -- when you format them with hard breaks.

<h3 id="header">Headers</h3>

Markdown supports two styles of headers, [Setext] [1] and [atx] [2].
Markdown supports two styles of headers, [Setext][1] and [atx][2].

Setext-style headers are "underlined" using equal signs (for first-level
headers) and dashes (for second-level headers). For example:
Expand Down
6 changes: 3 additions & 3 deletions src/Resource/Tests/Fixture/yaml-frontmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ Readability, however, is emphasized above all else. A Markdown-formatted
document should be publishable as-is, as plain text, without looking
like it's been marked up with tags or formatting instructions. While
Markdown's syntax has been influenced by several existing text-to-HTML
filters -- including [Setext] [1], [atx] [2], [Textile] [3], [reStructuredText] [4],
[Grutatext] [5], and [EtText] [6] -- the single biggest source of
filters -- including [Setext][1], [atx][2], [Textile][3], [reStructuredText][4],
[Grutatext][5], and [EtText][6] -- the single biggest source of
inspiration for Markdown's syntax is the format of plain text email.

[1]: http://docutils.sourceforge.net/mirror/setext.html
Expand Down Expand Up @@ -213,7 +213,7 @@ work best -- and look better -- when you format them with hard breaks.

<h3 id="header">Headers</h3>

Markdown supports two styles of headers, [Setext] [1] and [atx] [2].
Markdown supports two styles of headers, [Setext][1] and [atx][2].

Setext-style headers are "underlined" using equal signs (for first-level
headers) and dashes (for second-level headers). For example:
Expand Down
3 changes: 2 additions & 1 deletion src/Resource/Tests/FrontMarkResourceMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public function invalidateCommonMarkPart()
*
* @return PartSequence Sequence aggregate
*/
public function getSequence() {
public function getSequence()
{
return $this->part();
}
}

0 comments on commit 9bec061

Please sign in to comment.