-
Notifications
You must be signed in to change notification settings - Fork 428
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 #405 from qiniu/features/compatible-php-8.x
make compatible with php 8.x and fix compatible with php 5.3
- Loading branch information
Showing
24 changed files
with
219 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,53 @@ | ||
<?php | ||
// @codingStandardsIgnoreStart | ||
// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses | ||
|
||
namespace Qiniu\Enum; | ||
|
||
use MyCLabs\Enum\Enum; | ||
|
||
/** | ||
* 扩展 MyCLabs\Enum\Enum 以使用其新版本的 from 方法 | ||
* | ||
* @link https://github.com/myclabs/php-enum | ||
*/ | ||
abstract class QiniuEnum extends Enum | ||
{ | ||
/** | ||
* @param mixed $value | ||
* @return static | ||
*/ | ||
public static function from($value) | ||
if (method_exists("MyCLabs\\Enum\\Enum", "from")) { | ||
abstract class QiniuEnum extends Enum | ||
{ | ||
$key = self::assertValidValueReturningKey($value); | ||
|
||
return self::__callStatic($key, array()); | ||
// @codingStandardsIgnoreEnd | ||
// @codingStandardsIgnoreStart | ||
} | ||
|
||
} else { | ||
/** | ||
* Asserts valid enum value | ||
* poly fill MyCLabs\Enum\Enum::from in low version | ||
* | ||
* @psalm-pure | ||
* @psalm-assert T $value | ||
* @param mixed $value | ||
* @return string | ||
* @link https://github.com/myclabs/php-enum | ||
*/ | ||
private static function assertValidValueReturningKey($value) | ||
abstract class QiniuEnum extends Enum | ||
{ | ||
if (false === ($key = self::search($value))) { | ||
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . __CLASS__); | ||
// @codingStandardsIgnoreEnd | ||
/** | ||
* @param mixed $value | ||
* @return static | ||
*/ | ||
public static function from($value) | ||
{ | ||
$key = self::assertValidValueReturningKey($value); | ||
|
||
return self::__callStatic($key, array()); | ||
} | ||
|
||
return $key; | ||
/** | ||
* Asserts valid enum value | ||
* | ||
* @psalm-pure | ||
* @psalm-assert T $value | ||
* @param mixed $value | ||
* @return string | ||
*/ | ||
private static function assertValidValueReturningKey($value) | ||
{ | ||
if (false === ($key = self::search($value))) { | ||
throw new \UnexpectedValueException("Value '$value' is not part of the enum " . __CLASS__); | ||
} | ||
|
||
return $key; | ||
} | ||
// @codingStandardsIgnoreStart | ||
} | ||
} |
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
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
Oops, something went wrong.