[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-8240":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":19,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":22,"hasPages":24,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":16,"starSnapshotCount":16,"syncStatus":29,"lastSyncTime":30,"discoverSource":31},8240,"assert","webmozarts\u002Fassert","webmozarts","Assertions to validate method input\u002Foutput with nice error messages.","",null,"PHP",7646,161,31,24,0,9,17,5,37.63,"MIT License",false,"master",true,[],"2026-06-12 02:01:51","Webmozart Assert\n================\n\n[![Latest Stable Version](https:\u002F\u002Fposer.pugx.org\u002Fwebmozart\u002Fassert\u002Fv\u002Fstable.svg)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fwebmozart\u002Fassert)\n[![Total Downloads](https:\u002F\u002Fposer.pugx.org\u002Fwebmozart\u002Fassert\u002Fdownloads.svg)](https:\u002F\u002Fpackagist.org\u002Fpackages\u002Fwebmozart\u002Fassert)\n\nThis library contains efficient assertions to test the input and output of\nyour methods. With these assertions, you can greatly reduce the amount of coding\nneeded to write a safe implementation.\n\nAll assertions in the [`Assert`] class throw an `Webmozart\\Assert\\InvalidArgumentException` if\nthey fail.\n\nFAQ\n---\n\n**What's the difference to [beberlei\u002Fassert]?**\n\nThis library is heavily inspired by Benjamin Eberlei's wonderful [assert package],\nbut fixes a usability issue with error messages that can't be fixed there without\nbreaking backwards compatibility.\n\nThis package features usable error messages by default. However, you can also\neasily write custom error messages:\n\n```\nAssert::string($path, 'The path is expected to be a string. Got: %s');\n```\n\nIn [beberlei\u002Fassert], the ordering of the `%s` placeholders is different for\nevery assertion. This package, on the contrary, provides consistent placeholder\nordering for all assertions:\n\n* `%s`: The tested value as string, e.g. `\"\u002Ffoo\u002Fbar\"`.\n* `%2$s`, `%3$s`, ...: Additional assertion-specific values, e.g. the\n  minimum\u002Fmaximum length, allowed values, etc.\n\nCheck the source code of the assertions to find out details about the additional\navailable placeholders.\n\nInstallation\n------------\n\nUse [Composer] to install the package:\n\n```bash\ncomposer require webmozart\u002Fassert\n```\n\nExample\n-------\n\n```php\nuse Webmozart\\Assert\\Assert;\n\nclass Employee\n{\n    public function __construct($id)\n    {\n        Assert::integer($id, 'The employee ID must be an integer. Got: %s');\n        Assert::greaterThan($id, 0, 'The employee ID must be a positive integer. Got: %s');\n    }\n}\n```\n\nIf you create an employee with an invalid ID, an exception is thrown:\n\n```php\nnew Employee('foobar');\n\u002F\u002F => Webmozart\\Assert\\InvalidArgumentException:\n\u002F\u002F    The employee ID must be an integer. Got: string\n\nnew Employee(-10);\n\u002F\u002F => Webmozart\\Assert\\InvalidArgumentException:\n\u002F\u002F    The employee ID must be a positive integer. Got: -10\n```\n\nAssertions\n----------\n\nThe [`Assert`] class provides the following assertions:\n\n### Type Assertions\n\nMethod                                                      | Description\n----------------------------------------------------------- | --------------------------------------------------\n`string($value, $message = '')`                             | Check that a value is a string\n`stringNotEmpty($value, $message = '')`                     | Check that a value is a non-empty string\n`integer($value, $message = '')`                            | Check that a value is an integer\n`integerish($value, $message = '')`                         | Check that a value casts to an integer\n`positiveInteger($value, $message = '')`                    | Check that a value is a positive (non-zero) integer\n`negativeInteger($value, $message = '')`                    | Check that a value is a negative integer\n`notNegativeInteger($value, $message = '')`                 | Check that a value is a non-negative integer\n`float($value, $message = '')`                              | Check that a value is a float\n`numeric($value, $message = '')`                            | Check that a value is numeric\n`natural($value, $message = '')`                            | Check that a value is a non-negative integer\n`boolean($value, $message = '')`                            | Check that a value is a boolean\n`scalar($value, $message = '')`                             | Check that a value is a scalar\n`object($value, $message = '')`                             | Check that a value is an object\n`objectish($value, $message = '')`                          | Check that a value is an object or a string of a class that exists\n`resource($value, $type = null, $message = '')`             | Check that a value is a resource\n`isInitialized($value, $property, $message = '')`           | Check that a value has an initialized property\n`isCallable($value, $message = '')`                         | Check that a value is a callable\n`isArray($value, $message = '')`                            | Check that a value is an array\n`isIterable($value, $message = '')`                         | Check that a value is an array or a `\\Traversable`\n`isCountable($value, $message = '')`                        | Check that a value is an array or a `\\Countable`\n`isInstanceOf($value, $class, $message = '')`               | Check that a value is an `instanceof` a class\n`isInstanceOfAny($value, array $classes, $message = '')`    | Check that a value is an `instanceof` at least one class on the array of classes\n`notInstanceOf($value, $class, $message = '')`              | Check that a value is not an `instanceof` a class\n`isNotInstanceOfAny($value, array $classes, $message = '')` | Check that a value is not an `instanceof` at least one class on the array of classes\n`isAOf($value, $class, $message = '')`                      | Check that a value is of the class or has one of its parents\n`isAnyOf($value, array $classes, $message = '')`            | Check that a value is of at least one of the classes or has one of its parents\n`isNotA($value, $class, $message = '')`                     | Check that a value is not of the class or has not one of its parents\n`isArrayAccessible($value, $message = '')`                  | Check that a value can be accessed as an array\n`uniqueValues($values, $message = '')`                      | Check that the given array contains unique values\n\n### Comparison Assertions\n\nMethod                                                | Description\n----------------------------------------------------- | ------------------------------------------------------------------\n`true($value, $message = '')`                         | Check that a value is `true`\n`false($value, $message = '')`                        | Check that a value is `false`\n`notFalse($value, $message = '')`                     | Check that a value is not `false`\n`null($value, $message = '')`                         | Check that a value is `null`\n`notNull($value, $message = '')`                      | Check that a value is not `null`\n`isEmpty($value, $message = '')`                      | Check that a value is `empty()`\n`notEmpty($value, $message = '')`                     | Check that a value is not `empty()`\n`eq($value, $value2, $message = '')`                  | Check that a value equals another (`==`)\n`notEq($value, $value2, $message = '')`               | Check that a value does not equal another (`!=`)\n`same($value, $value2, $message = '')`                | Check that a value is identical to another (`===`)\n`notSame($value, $value2, $message = '')`             | Check that a value is not identical to another (`!==`)\n`greaterThan($value, $value2, $message = '')`         | Check that a value is greater than another\n`greaterThanEq($value, $value2, $message = '')`       | Check that a value is greater than or equal to another\n`lessThan($value, $value2, $message = '')`            | Check that a value is less than another\n`lessThanEq($value, $value2, $message = '')`          | Check that a value is less than or equal to another\n`range($value, $min, $max, $message = '')`            | Check that a value is within a range\n`inArray($value, array $values, $message = '')`       | Check that a value is one of a list of values\n`notInArray($value, array $values, $message = '')`    | Check that a value is not one of a list of values\n`oneOf($value, array $values, $message = '')`         | Check that a value is one of a list of values (alias of `inArray`)\n`notOneOf($value, array $values, $message = '')`      | Check that a value is not one of a list of values (alias of `notInArray`)\n\n### String Assertions\n\nYou should check that a value is a string with `Assert::string()` before making\nany of the following assertions.\n\nMethod                                              | Description\n--------------------------------------------------- | -----------------------------------------------------------------\n`contains($value, $subString, $message = '')`       | Check that a string contains a substring\n`notContains($value, $subString, $message = '')`    | Check that a string does not contain a substring\n`startsWith($value, $prefix, $message = '')`        | Check that a string has a prefix\n`notStartsWith($value, $prefix, $message = '')`     | Check that a string does not have a prefix\n`startsWithLetter($value, $message = '')`           | Check that a string starts with a letter\n`endsWith($value, $suffix, $message = '')`          | Check that a string has a suffix\n`notEndsWith($value, $suffix, $message = '')`       | Check that a string does not have a suffix\n`regex($value, $pattern, $message = '')`            | Check that a string matches a regular expression\n`notRegex($value, $pattern, $message = '')`         | Check that a string does not match a regular expression\n`unicodeLetters($value, $message = '')`             | Check that a string contains Unicode letters only\n`alpha($value, $message = '')`                      | Check that a string contains letters only\n`digits($value, $message = '')`                     | Check that a string contains digits only\n`alnum($value, $message = '')`                      | Check that a string contains letters and digits only\n`lower($value, $message = '')`                      | Check that a string contains lowercase characters only\n`upper($value, $message = '')`                      | Check that a string contains uppercase characters only\n`length($value, $length, $message = '')`            | Check that a string has a certain number of characters\n`minLength($value, $min, $message = '')`            | Check that a string has at least a certain number of characters\n`maxLength($value, $max, $message = '')`            | Check that a string has at most a certain number of characters\n`lengthBetween($value, $min, $max, $message = '')`  | Check that a string has a length in the given range\n`uuid($value, $message = '')`                       | Check that a string is a valid UUID\n`ip($value, $message = '')`                         | Check that a string is a valid IP (either IPv4 or IPv6)\n`ipv4($value, $message = '')`                       | Check that a string is a valid IPv4\n`ipv6($value, $message = '')`                       | Check that a string is a valid IPv6\n`email($value, $message = '')`                      | Check that a string is a valid e-mail address\n`notWhitespaceOnly($value, $message = '')`          | Check that a string contains at least one non-whitespace character\n\n### File Assertions\n\nMethod                              | Description\n----------------------------------- | --------------------------------------------------\n`fileExists($value, $message = '')` | Check that a value is an existing path\n`file($value, $message = '')`       | Check that a value is an existing file\n`directory($value, $message = '')`  | Check that a value is an existing directory\n`readable($value, $message = '')`   | Check that a value is a readable path\n`writable($value, $message = '')`   | Check that a value is a writable path\n\n### Object Assertions\n\nMethod                                                | Description\n----------------------------------------------------- | --------------------------------------------------\n`classExists($value, $message = '')`                  | Check that a value is an existing class name\n`subclassOf($value, $class, $message = '')`           | Check that a class is a subclass of another\n`interfaceExists($value, $message = '')`              | Check that a value is an existing interface name\n`implementsInterface($value, $class, $message = '')`  | Check that a class implements an interface\n`propertyExists($value, $property, $message = '')`    | Check that a property exists in a class\u002Fobject\n`propertyNotExists($value, $property, $message = '')` | Check that a property does not exist in a class\u002Fobject\n`methodExists($value, $method, $message = '')`        | Check that a method exists in a class\u002Fobject\n`methodNotExists($value, $method, $message = '')`     | Check that a method does not exist in a class\u002Fobject\n\n### Array Assertions\n\nMethod                                             | Description\n-------------------------------------------------- | ------------------------------------------------------------------\n`keyExists($array, $key, $message = '')`           | Check that a key exists in an array\n`keyNotExists($array, $key, $message = '')`        | Check that a key does not exist in an array\n`validArrayKey($key, $message = '')`               | Check that a value is a valid array key (int or string)\n`count($array, $number, $message = '')`            | Check that an array contains a specific number of elements\n`minCount($array, $min, $message = '')`            | Check that an array contains at least a certain number of elements\n`maxCount($array, $max, $message = '')`            | Check that an array contains at most a certain number of elements\n`countBetween($array, $min, $max, $message = '')`  | Check that an array has a count in the given range\n`isList($array, $message = '')`                    | Check that an array is a non-associative list\n`isNonEmptyList($array, $message = '')`            | Check that an array is a non-associative list, and not empty\n`isMap($array, $message = '')`                     | Check that an array is associative and has strings as keys\n`isNonEmptyMap($array, $message = '')`             | Check that an array is associative and has strings as keys, and is not empty\n\n### Function Assertions\n\nMethod                                    | Description\n------------------------------------------| -----------------------------------------------------------------------------------------------------\n`throws($closure, $class, $message = '')` | Check that a function throws a certain exception. Subclasses of the exception class will be accepted.\n`isStatic($closure, $message = '')`       | Check that a function is static.\n`notStatic($closure, $message = '')`    | Check that a function is not static.\n\n### Collection Assertions\n\nAll of the above assertions can be prefixed with `all*()` to test the contents\nof an array or a `\\Traversable`:\n\n```php\nAssert::allIsInstanceOf($employees, 'Acme\\Employee');\n```\n\n### Nullable Assertions\n\nAll of the above assertions can be prefixed with `nullOr*()` to run the\nassertion only if the value is not `null`:\n\n```php\nAssert::nullOrString($middleName, 'The middle name must be a string or null. Got: %s');\n```\n\n### Lazy assertion messages\n\nAssertion messages can be provided as callables to avoid unnecessary computation when the assertion passes:\n\n```php\nAssert::string($value, fn() => expensiveMessage());\n```\n\nThe callable will only be executed if the assertion fails.\n\n### Extending Assert\n\nThe `Assert` class comes with a few methods, which can be overridden to change the class behaviour. You can also extend it to\nadd your own assertions.\n\n\n#### Overriding methods\n\nOverriding the following methods in your assertion class allows you to change the behaviour of the assertions:\n\n* `public static function __callStatic($name, $arguments)`\n  * This method is used to 'create' the `nullOr` and `all` versions of the assertions.\n* `protected static function valueToString($value)`\n  * This method is used for error messages, to convert the value to a string value for displaying. You could use this for representing a value object with a `__toString` method for example.\n* `protected static function typeToString($value)`\n  * This method is used for error messages, to convert a value to a string representing its type.\n* `protected static function strlen($value)`\n  * This method is used to calculate string length for relevant methods, using the `mb_strlen` if available and useful.\n* `protected static function reportInvalidArgument($message)`\n  * This method is called when an assertion fails, with the specified error message. Here you can throw your own exception, or log something.\n\n## Static analysis support\n\nWhere applicable, assertion functions are annotated to support Psalm's\n[Assertion syntax](https:\u002F\u002Fpsalm.dev\u002Fdocs\u002Fannotating_code\u002Fassertion_syntax\u002F).\nA dedicated [PHPStan Plugin](https:\u002F\u002Fgithub.com\u002Fphpstan\u002Fphpstan-webmozart-assert) is\nrequired for proper type support.\n\nAuthors\n-------\n\n* [Bernhard Schussek] a.k.a. [@webmozart]\n* [The Community Contributors]\n\nContribute\n----------\n\nContributions to the package are always welcome!\n\n* Report any bugs or issues you find on the [issue tracker].\n* You can grab the source code at the package's [Git repository].\n\nLicense\n-------\n\nAll contents of this package are licensed under the [MIT license].\n\n[beberlei\u002Fassert]: https:\u002F\u002Fgithub.com\u002Fbeberlei\u002Fassert\n[assert package]: https:\u002F\u002Fgithub.com\u002Fbeberlei\u002Fassert\n[Composer]: https:\u002F\u002Fgetcomposer.org\n[Bernhard Schussek]: https:\u002F\u002Fwebmozarts.com\n[The Community Contributors]: https:\u002F\u002Fgithub.com\u002Fwebmozart\u002Fassert\u002Fgraphs\u002Fcontributors\n[issue tracker]: https:\u002F\u002Fgithub.com\u002Fwebmozart\u002Fassert\u002Fissues\n[Git repository]: https:\u002F\u002Fgithub.com\u002Fwebmozart\u002Fassert\n[@webmozart]: https:\u002F\u002Ftwitter.com\u002Fwebmozart\n[MIT license]: LICENSE\n[`Assert`]: src\u002FAssert.php\n","webmozart\u002Fassert 是一个用于验证方法输入输出并提供友好错误信息的 PHP 库。其核心功能是通过高效的断言减少编写安全代码所需的工作量，所有断言失败时都会抛出 `Webmozart\\Assert\\InvalidArgumentException` 异常，并支持自定义错误消息以提高可读性和用户体验。该库特别适合需要对函数参数或返回值进行严格类型检查和范围验证的场景，如数据处理、API 开发等。使用 Composer 可轻松集成到项目中。",2,"2026-06-11 03:16:57","top_language"]