This repository has been archived by the owner on Nov 15, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
beff13e
commit 46e67d7
Showing
7 changed files
with
122 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\HttpFoundation\File { | ||
|
||
/** | ||
* *************************************************************************** | ||
* ******* WARNING **** WARNING **** WARNING **** WARNING **** WARNING *******. | ||
* *************************************************************************** | ||
* ******* ******* | ||
* ******* THIS FUNCTION OVERLOADING IS NECESSARY MEASURE ******* | ||
* ******* https://github.com/spiral/roadrunner-laravel/issues/43 ******* | ||
* ******* ******* | ||
* ***************************************************************************. | ||
* | ||
* Moves an uploaded file to a new location. | ||
* | ||
* @link https://php.net/manual/en/function.move-uploaded-file.php | ||
* | ||
* @param string $from The filename of the uploaded file | ||
* @param string $to The destination of the moved file | ||
* | ||
* @return bool If filename is a valid file, but cannot be moved for some | ||
* reason, no action will occur, and will return false. | ||
* | ||
* @see \Symfony\Component\HttpFoundation\File\UploadedFile::move | ||
* | ||
* @since 4.0.3 | ||
* @since 5.0 | ||
* @since 7.0 | ||
* @since 8.0 | ||
*/ | ||
function move_uploaded_file(string $from, string $to): bool | ||
{ | ||
return \is_file($from) && \rename($from, $to); | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\RoadRunnerLaravel\Listeners; | ||
|
||
/** | ||
* @link https://github.com/spiral/roadrunner-laravel/issues/43 | ||
*/ | ||
class FixSymfonyFileMovingListener implements ListenerInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handle($event): void | ||
{ | ||
if (!\function_exists('\\Symfony\\Component\\HttpFoundation\\File\\move_uploaded_file')) { | ||
require __DIR__ . '/../../fixes/fix-symfony-file-moving.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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\RoadRunnerLaravel\Tests\Unit\Listeners; | ||
|
||
use Illuminate\Support\Str; | ||
use Spiral\RoadRunnerLaravel\Listeners\FixSymfonyFileMovingListener; | ||
|
||
/** | ||
* @covers \Spiral\RoadRunnerLaravel\Listeners\FixSymfonyFileMovingListener | ||
*/ | ||
class FixSymfonyFileMovingListenerTest extends AbstractListenerTestCase | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function testHandle(): void | ||
{ | ||
$function_location = '\\Symfony\\Component\\HttpFoundation\\File\\move_uploaded_file'; | ||
|
||
$this->assertFalse(\function_exists($function_location)); | ||
$this->assertFalse(\is_uploaded_file('foo')); | ||
|
||
$this->listenerFactory()->handle(new \stdClass()); | ||
|
||
$this->assertTrue(\function_exists($function_location)); | ||
|
||
$tmp_dir = $this->createTemporaryDirectory(); | ||
$old_file_path = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); | ||
$new_file_path = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); | ||
\file_put_contents($old_file_path, ''); | ||
$this->assertFileExists($old_file_path); | ||
$this->assertTrue($function_location($old_file_path, $new_file_path)); | ||
$this->assertFileExists($new_file_path); | ||
$this->assertFileNotExists($old_file_path); | ||
$rnd_file_path1 = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); | ||
$rnd_file_path2 = $tmp_dir . DIRECTORY_SEPARATOR . Str::random(); | ||
$this->assertFalse($function_location($rnd_file_path1, $rnd_file_path2)); | ||
} | ||
|
||
/** | ||
* @return FixSymfonyFileMovingListener | ||
*/ | ||
protected function listenerFactory(): FixSymfonyFileMovingListener | ||
{ | ||
return new FixSymfonyFileMovingListener(); | ||
} | ||
} |