-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MediaBundle] Add web_root configuration to support both web and publ…
…ic as the root dir for uploads
- Loading branch information
Showing
5 changed files
with
67 additions
and
1 deletion.
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
25 changes: 25 additions & 0 deletions
25
src/Kunstmaan/MediaBundle/Tests/Utils/SymfonyVersionTest.php
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,25 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\MediaBundle\Tests\Utils; | ||
|
||
use Kunstmaan\MediaBundle\Utils\SymfonyVersion; | ||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
/** | ||
* @covers \Kunstmaan\MediaBundle\Utils\SymfonyVersion | ||
*/ | ||
class SymfonyVersionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testGetRootWebPath() | ||
{ | ||
$path = SymfonyVersion::getRootWebPath(); | ||
$this->assertStringStartsWith('%kernel.project_dir%/', $path); | ||
$this->assertStringEndsWith(Kernel::VERSION_ID < 40000 ? 'web' : 'public', $path); | ||
} | ||
|
||
public function testIsKernelLessThan() | ||
{ | ||
$this->assertTrue(SymfonyVersion::isKernelLessThan(100, 100, 100)); | ||
$this->assertFalse(SymfonyVersion::isKernelLessThan(1, 1, 1)); | ||
} | ||
} |
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,35 @@ | ||
<?php | ||
|
||
namespace Kunstmaan\MediaBundle\Utils; | ||
|
||
use Symfony\Component\HttpKernel\Kernel; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
class SymfonyVersion | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public static function getRootWebPath() | ||
{ | ||
return sprintf('%%kernel.project_dir%%/%s', self::isKernelLessThan(4) ? 'web' : 'public'); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public static function isKernelLessThan($major, $minor = null, $patch = null) | ||
{ | ||
return static::kernelVersionCompare('<', $major, $minor, $patch); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
private static function kernelVersionCompare($operator, $major, $minor = null, $patch = null) | ||
{ | ||
return version_compare(Kernel::VERSION_ID, sprintf("%d%'.02d%'.02d", $major, $minor ?: 0, $patch ?: 0), $operator); | ||
} | ||
} |