Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc98bc83

Browse files
author
Dominik Liebler
committed
Merge commit 'refs/pull/origin/86'
2 parents06b2af4 +bebb526 commitc98bc83

File tree

217 files changed

+1142
-679
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

217 files changed

+1142
-679
lines changed

‎ChainOfResponsibilities/Handler.phprenamed to‎Behavioral/ChainOfResponsibilities/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespaceDesignPatterns\ChainOfResponsibilities;
3+
namespaceDesignPatterns\Behavioral\ChainOfResponsibilities;
44

55
/**
66
* Handler is a generic handler in the chain of responsibilities

‎ChainOfResponsibilities/Request.phprenamed to‎Behavioral/ChainOfResponsibilities/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespaceDesignPatterns\ChainOfResponsibilities;
3+
namespaceDesignPatterns\Behavioral\ChainOfResponsibilities;
44

55
/**
66
* Request is a request which goes through the chain of responsibilities.

‎ChainOfResponsibilities/Responsible/FastStorage.phprenamed to‎Behavioral/ChainOfResponsibilities/Responsible/FastStorage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespaceDesignPatterns\ChainOfResponsibilities\Responsible;
3+
namespaceDesignPatterns\Behavioral\ChainOfResponsibilities\Responsible;
44

5-
useDesignPatterns\ChainOfResponsibilities\Handler;
6-
useDesignPatterns\ChainOfResponsibilities\Request;
5+
useDesignPatterns\Behavioral\ChainOfResponsibilities\Handler;
6+
useDesignPatterns\Behavioral\ChainOfResponsibilities\Request;
77

88
/**
99
* Class FastStorage

‎ChainOfResponsibilities/Responsible/SlowStorage.phprenamed to‎Behavioral/ChainOfResponsibilities/Responsible/SlowStorage.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespaceDesignPatterns\ChainOfResponsibilities\Responsible;
3+
namespaceDesignPatterns\Behavioral\ChainOfResponsibilities\Responsible;
44

5-
useDesignPatterns\ChainOfResponsibilities\Handler;
6-
useDesignPatterns\ChainOfResponsibilities\Request;
5+
useDesignPatterns\Behavioral\ChainOfResponsibilities\Handler;
6+
useDesignPatterns\Behavioral\ChainOfResponsibilities\Request;
77

88
/**
99
* This is mostly the same code as FastStorage but in fact, it may greatly differs

‎Tests/ChainOfResponsibilities/ChainTest.phprenamed to‎Behavioral/ChainOfResponsibilities/Tests/ChainTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
<?php
22

3-
namespaceDesignPatterns\Tests\ChainOfResponsibilities;
3+
namespaceDesignPatterns\Behavioral\ChainOfResponsibilities\Tests;
44

5-
useDesignPatterns\ChainOfResponsibilities\Request;
6-
useDesignPatterns\ChainOfResponsibilities\Responsible;
5+
useDesignPatterns\Behavioral\ChainOfResponsibilities\Request;
6+
useDesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage;
7+
useDesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage;
8+
useDesignPatterns\Behavioral\ChainOfResponsibilities\Responsible;
79

810
/**
911
* ChainTest tests the CoR
1012
*/
1113
class ChainTestextends \PHPUnit_Framework_TestCase
1214
{
1315

16+
/**
17+
* @var FastStorage
18+
*/
1419
protected$chain;
1520

1621
protectedfunctionsetUp()
1722
{
18-
$this->chain =newResponsible\FastStorage(array('bar' =>'baz'));
19-
$this->chain->append(newResponsible\SlowStorage(array('bar' =>'baz','foo' =>'bar')));
23+
$this->chain =newFastStorage(array('bar' =>'baz'));
24+
$this->chain->append(newSlowStorage(array('bar' =>'baz','foo' =>'bar')));
2025
}
2126

2227
publicfunctionmakeRequest()
@@ -40,7 +45,8 @@ public function testFastStorage($request)
4045
$this->assertObjectHasAttribute('response',$request);
4146
$this->assertEquals('baz',$request->response);
4247
// despite both handle owns the 'bar' key, the FastStorage is responding first
43-
$this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\FastStorage',$request->forDebugOnly);
48+
$className ='DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\FastStorage';
49+
$this->assertEquals($className,$request->forDebugOnly);
4450
}
4551

4652
/**
@@ -55,7 +61,8 @@ public function testSlowStorage($request)
5561
$this->assertObjectHasAttribute('response',$request);
5662
$this->assertEquals('bar',$request->response);
5763
// FastStorage has no 'foo' key, the SlowStorage is responding
58-
$this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\SlowStorage',$request->forDebugOnly);
64+
$className ='DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage';
65+
$this->assertEquals($className,$request->forDebugOnly);
5966
}
6067

6168
/**
@@ -68,6 +75,7 @@ public function testFailure($request)
6875

6976
$this->assertFalse($ret);
7077
// the last responsible :
71-
$this->assertEquals('DesignPatterns\ChainOfResponsibilities\Responsible\SlowStorage',$request->forDebugOnly);
78+
$className ='DesignPatterns\Behavioral\ChainOfResponsibilities\Responsible\SlowStorage';
79+
$this->assertEquals($className,$request->forDebugOnly);
7280
}
7381
}

‎Command/CommandInterface.phprenamed to‎Behavioral/Command/CommandInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespaceDesignPatterns\Command;
3+
namespaceDesignPatterns\Behavioral\Command;
44

55
/**
66
* class CommandInterface

‎Command/HelloCommand.phprenamed to‎Behavioral/Command/HelloCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespaceDesignPatterns\Command;
3+
namespaceDesignPatterns\Behavioral\Command;
44

55
/**
66
* This concrete command calls "print" on the Receiver, but an external

‎Command/Invoker.phprenamed to‎Behavioral/Command/Invoker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespaceDesignPatterns\Command;
3+
namespaceDesignPatterns\Behavioral\Command;
44

55
/**
66
* Invoker is using the command given to it.
File renamed without changes.

‎Command/Receiver.phprenamed to‎Behavioral/Command/Receiver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespaceDesignPatterns\Command;
3+
namespaceDesignPatterns\Behavioral\Command;
44

55
/**
66
* Receiver is specific service with its own contract and can be only concrete

‎Tests/Command/CommandTest.phprenamed to‎Behavioral/Command/Tests/CommandTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
<?php
22

3-
namespaceDesignPatterns\Tests\Command;
3+
namespaceDesignPatterns\Behavioral\Command\Tests;
44

5-
useDesignPatterns\Command\Invoker;
6-
useDesignPatterns\Command\Receiver;
7-
useDesignPatterns\Command\HelloCommand;
5+
useDesignPatterns\Behavioral\Command\Invoker;
6+
useDesignPatterns\Behavioral\Command\Receiver;
7+
useDesignPatterns\Behavioral\Command\HelloCommand;
88

99
/**
1010
* CommandTest has the role of the Client in the Command Pattern
1111
*/
1212
class CommandTestextends \PHPUnit_Framework_TestCase
1313
{
1414

15+
/**
16+
* @var Invoker
17+
*/
1518
protected$invoker;
19+
20+
/**
21+
* @var Receiver
22+
*/
1623
protected$receiver;
1724

1825
protectedfunctionsetUp()
1926
{
20-
// this is the context of the application
2127
$this->invoker =newInvoker();
2228
$this->receiver =newReceiver();
2329
}

‎Behavioral/Iterator/Book.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespaceDesignPatterns\Behavioral\Iterator;
4+
5+
class Book
6+
{
7+
8+
private$author;
9+
10+
private$title;
11+
12+
publicfunction__construct($title,$author)
13+
{
14+
$this->author =$author;
15+
$this->title =$title;
16+
}
17+
18+
publicfunctiongetAuthor()
19+
{
20+
return$this->author;
21+
}
22+
23+
publicfunctiongetTitle()
24+
{
25+
return$this->title;
26+
}
27+
28+
publicfunctiongetAuthorAndTitle()
29+
{
30+
return$this->getTitle() .' by' .$this->getAuthor();
31+
}
32+
}

‎Behavioral/Iterator/BookList.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespaceDesignPatterns\Behavioral\Iterator;
4+
5+
class BookListimplements \Countable
6+
{
7+
8+
private$books;
9+
10+
publicfunctiongetBook($bookNumberToGet)
11+
{
12+
if ((int)$bookNumberToGet <=$this->count()) {
13+
return$this->books[$bookNumberToGet];
14+
}
15+
16+
returnnull;
17+
}
18+
19+
publicfunctionaddBook(Book$book)
20+
{
21+
$this->books[] =$book;
22+
23+
return$this->count();
24+
}
25+
26+
publicfunctionremoveBook(Book$bookToRemove)
27+
{
28+
foreach ($thisas$key =>$book) {
29+
/** @var Book $book */
30+
if ($book->getAuthorAndTitle() ===$bookToRemove->getAuthorAndTitle()) {
31+
unset($this->books[$key]);
32+
}
33+
}
34+
35+
return$this->count();
36+
}
37+
38+
publicfunctioncount()
39+
{
40+
returncount($this->books);
41+
}
42+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
namespaceDesignPatterns\Behavioral\Iterator;
4+
5+
class BookListIteratorimplements \Iterator
6+
{
7+
8+
/**
9+
* @var BookList
10+
*/
11+
protected$bookList;
12+
13+
/**
14+
* @var int
15+
*/
16+
protected$currentBook =0;
17+
18+
publicfunction__construct(BookList$bookList)
19+
{
20+
$this->bookList =$bookList;
21+
}
22+
23+
/**
24+
* Return the current book
25+
* @link http://php.net/manual/en/iterator.current.php
26+
* @return Book Can return any type.
27+
*/
28+
publicfunctioncurrent()
29+
{
30+
return$this->bookList->getBook($this->currentBook);
31+
}
32+
33+
/**
34+
* (PHP 5 &gt;= 5.0.0)<br/>
35+
* Move forward to next element
36+
* @link http://php.net/manual/en/iterator.next.php
37+
* @return void Any returned value is ignored.
38+
*/
39+
publicfunctionnext()
40+
{
41+
$this->currentBook++;
42+
}
43+
44+
/**
45+
* (PHP 5 &gt;= 5.0.0)<br/>
46+
* Return the key of the current element
47+
* @link http://php.net/manual/en/iterator.key.php
48+
* @return mixed scalar on success, or null on failure.
49+
*/
50+
publicfunctionkey()
51+
{
52+
return$this->currentBook;
53+
}
54+
55+
/**
56+
* (PHP 5 &gt;= 5.0.0)<br/>
57+
* Checks if current position is valid
58+
* @link http://php.net/manual/en/iterator.valid.php
59+
* @return boolean The return value will be casted to boolean and then evaluated.
60+
* Returns true on success or false on failure.
61+
*/
62+
publicfunctionvalid()
63+
{
64+
return$this->currentBook <$this->bookList->count();
65+
}
66+
67+
/**
68+
* (PHP 5 &gt;= 5.0.0)<br/>
69+
* Rewind the Iterator to the first element
70+
* @link http://php.net/manual/en/iterator.rewind.php
71+
* @return void Any returned value is ignored.
72+
*/
73+
publicfunctionrewind()
74+
{
75+
$this->currentBook =0;
76+
}
77+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespaceDesignPatterns\Behavioral\Iterator;
4+
5+
class BookListReverseIteratorextends BookListIterator
6+
{
7+
8+
publicfunction__construct(BookList$bookList)
9+
{
10+
$this->bookList =$bookList;
11+
$this->currentBook =$this->bookList->count() -1;
12+
}
13+
14+
publicfunctionnext()
15+
{
16+
$this->currentBook--;
17+
}
18+
19+
publicfunctionvalid()
20+
{
21+
return0 <=$this->currentBook;
22+
}
23+
}
File renamed without changes.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp