-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from spiral/develop
sync
- Loading branch information
Showing
15 changed files
with
254 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
/** | ||
* (c) Lev Seleznev (tuneyourserver) 2017 | ||
*/ | ||
|
||
namespace Spiral\Views; | ||
|
||
/** | ||
* Class AbstractViewCache | ||
* | ||
* Provides ability to locate cache files by common prefix with many environments. | ||
* | ||
* @package Spiral\Views | ||
*/ | ||
abstract class AbstractViewCache | ||
{ | ||
/** | ||
* Returns file name prefix by namespace:name | ||
* | ||
* @param string $name | ||
* @param string $namespace | ||
* @return string | ||
*/ | ||
protected function getPrefix($name, $namespace = 'default') | ||
{ | ||
$prefix = $namespace . ViewManager::NS_SEPARATOR . $name; | ||
$prefix = preg_replace('/([^A-Za-z0-9]|-)+/', '-', $prefix) . '-' . | ||
hash('md5', $name . ViewManager::NS_SEPARATOR . $namespace); | ||
|
||
return $prefix; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* (c) Lev Seleznev (tuneyourserver) 2017 | ||
*/ | ||
|
||
namespace Spiral\Views; | ||
|
||
|
||
use Spiral\Files\FileManager; | ||
use Spiral\Views\Configs\ViewsConfig; | ||
|
||
/** | ||
* Class ViewCacheLocator | ||
* | ||
* Provides ability to locate cache files by view name and namespace | ||
* | ||
* @package Spiral\Views | ||
*/ | ||
class ViewCacheLocator extends AbstractViewCache | ||
{ | ||
/** @var FileManager */ | ||
protected $fileManager; | ||
|
||
/** @var ViewsConfig */ | ||
protected $config; | ||
|
||
/** | ||
* CacheLocator constructor. | ||
* | ||
* @param ViewsConfig $config | ||
* @param FileManager $fileManager | ||
*/ | ||
public function __construct(ViewsConfig $config, FileManager $fileManager) | ||
{ | ||
$this->config = $config; | ||
$this->fileManager = $fileManager; | ||
} | ||
|
||
/** | ||
* Returns all cache files for view. | ||
* | ||
* @param string $view | ||
* @param string $namespace | ||
* @return array | ||
*/ | ||
public function getFiles($view, $namespace = 'default') | ||
{ | ||
$prefix = $this->getPrefix($view, $namespace); | ||
|
||
return $this->fileManager->getFiles($this->config->cacheDirectory(), $prefix.'-*'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Spiral\Tests\Http\Fixtures; | ||
|
||
use Spiral\Http\Request\RequestFilter; | ||
|
||
class FirstDepthRequest extends RequestFilter | ||
{ | ||
const SCHEMA = [ | ||
'first' => SecondDepthRequest::class | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Spiral\Tests\Http\Fixtures; | ||
|
||
use Spiral\Http\Request\RequestFilter; | ||
|
||
class SecondDepthRequest extends RequestFilter | ||
{ | ||
const SCHEMA = [ | ||
'second' => ThirdDepthRequest::class | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Spiral\Tests\Http\Fixtures; | ||
|
||
use Spiral\Http\Request\RequestFilter; | ||
|
||
class ThirdDepthRequest extends RequestFilter | ||
{ | ||
const SCHEMA = [ | ||
'third' => 'data:third' | ||
]; | ||
|
||
const VALIDATES = [ | ||
'third' => ['notEmpty'] | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace Spiral\Tests\Http\RequestFilters; | ||
|
||
use Psr\Http\Message\ServerRequestInterface; | ||
use Spiral\Tests\Http\Fixtures\DemoRequest; | ||
use Spiral\Tests\Http\Fixtures\FirstDepthRequest; | ||
use Spiral\Tests\Http\Fixtures\ThirdDepthRequest; | ||
use Spiral\Tests\Http\HttpTest; | ||
use Zend\Diactoros\ServerRequest; | ||
|
||
class MultipleDepthRequestTest extends HttpTest | ||
{ | ||
public function testHasErrors() | ||
{ | ||
$serverRequest = new ServerRequest(); | ||
$serverRequest = $serverRequest->withParsedBody([]); | ||
$this->container->bind(ServerRequestInterface::class, $serverRequest); | ||
|
||
/** @var DemoRequest $request */ | ||
$request = $this->container->get(FirstDepthRequest::class); | ||
|
||
$this->assertFalse($request->isValid()); | ||
$this->assertArrayHasKey('first', $request->getErrors()); | ||
$this->assertArrayHasKey('second', $request->getErrors()['first']); | ||
$this->assertArrayHasKey('third', $request->getErrors()['first']['second']); | ||
} | ||
|
||
public function testDataPassed() | ||
{ | ||
$serverRequest = new ServerRequest(); | ||
$serverRequest = $serverRequest->withParsedBody([ | ||
'first' => [ | ||
'second' => [ | ||
'third' => '3rd value', | ||
], | ||
] | ||
]); | ||
$this->container->bind(ServerRequestInterface::class, $serverRequest); | ||
|
||
/** @var DemoRequest $request */ | ||
$request = $this->container->get(FirstDepthRequest::class); | ||
|
||
$this->assertTrue($request->isValid()); | ||
$this->assertArrayNotHasKey('first', $request->getErrors()); | ||
|
||
$this->assertArrayHasKey('first', $request->getValidator()->getData()); | ||
$this->assertArrayHasKey('second', $request->getValidator()->getData()['first']); | ||
$this->assertArrayHasKey('third', $request->getValidator()->getData()['first']['second']); | ||
$this->assertSame('3rd value', $request->getValidator()->getData()['first']['second']['third']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters