{"id":13623915,"url":"https://github.com/ircmaxell/filterus","last_synced_at":"2025-12-17T02:57:56.826Z","repository":{"id":6397196,"uuid":"7635206","full_name":"ircmaxell/filterus","owner":"ircmaxell","description":"A simple filtering library for PHP","archived":false,"fork":false,"pushed_at":"2018-11-21T21:48:10.000Z","size":27,"stargazers_count":452,"open_issues_count":8,"forks_count":54,"subscribers_count":26,"default_branch":"master","last_synced_at":"2025-03-12T07:59:32.033Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ircmaxell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-15T23:14:06.000Z","updated_at":"2025-01-29T19:32:36.000Z","dependencies_parsed_at":"2022-08-21T12:50:57.065Z","dependency_job_id":null,"html_url":"https://github.com/ircmaxell/filterus","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2Ffilterus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2Ffilterus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2Ffilterus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ircmaxell%2Ffilterus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ircmaxell","download_url":"https://codeload.github.com/ircmaxell/filterus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681595,"owners_count":21144714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T21:01:36.933Z","updated_at":"2025-12-17T02:57:56.783Z","avatar_url":"https://github.com/ircmaxell.png","language":"PHP","readme":"Filterus - A flexible PHP 5.3 filter package\n============================================\n\n## Filter Methods:\n\nEach filter class has two primary methods:\n\n* `$filter-\u003efilter($var)` - returns a modified version of `$var` filtered to the options. If it cannot be safely modified, a default value will be returned.\n* `$filter-\u003evalidate($var)` - Returns a boolean identifying if the value is valid.\n\n## Simple Filters (with options):\n\n* `alnum` - Alpha numeric\n    * `min` - 0 - Minimum length\n    * `max` - PHP_INT_MAX - Maximum length\n    * `default` - `''` - Default return value\n* `array` - Array matching\n    * `min` - 0 - Minimum size\n    * `maximum` - PHP_INT_MAX - Maximum size\n    * `keys` - `null` - Filter to run on the keys\n    * `values` - `null` - Filter to run on the values\n    * `default` - `array()` - Default return value\n* `bool` - Boolean matching\n    * `default` - `null` - Default return value\n* `email` - Matches emails\n* `float` - Floating point numbers\n    * `min` - `null` - Minimum length\n    * `max` - `null` - Maximum length\n    * `default` - 0.0 - Default return value\n* `int` - Integers numbers\n    * `min` - `null` - Minimum length\n    * `max` - `null` - Maximum length\n    * `default` - 0 - Default return value\n* `ip` - Matches IP addresses\n    * `ipv4` - `true` - Boolean to match IPv4 addresses\n    * `ipv6` - `true` - Boolean to match IPv6 addresses\n    * `private` - `true` - Include private addresses?\n    * `reserved` - `true` - Include reserved addresses?\n* `object` - Objects\n    * `class` - `''` - Required class or interface name\n    * `default` - `null` - The default value\n    * `defaultFactory` - `null` - A callback to instantiate a return value\n* `raw` - Returns whatever is passed in\n* `regex` - Matches strings via a regex\n    * `min` - 0 - Minimum length\n    * `max` - PHP_INT_MAX - Maximum length\n    * `default` - `''` - Default return value\n    * `regex` - `/.?/` - The regex to run\n* `string` - Matches strings\n    * `min` - 0 - Minimum length\n    * `max` - PHP_INT_MAX - Maximum length\n    * `default` - `''` - Default return value\n* `url` - Matches URLs\n    * `path` - `false` - Force a path to be present\n    * `query` - `false` - Force a query string to be present\n\n## Complex Filters\n\n* `Filter::map(array())` - \"maps\" several filters over key-value pairs. Useful for filtering associative arrays or stdclass objects.\n* `Filter::chain($filter1, $filter2...)` - Chains multiple filters together to run on the same value (similar to `AND` joining filters).\n* `Filter::pool($filter1, $filter2...)` - Runs the same value through multiple filters using the first valid return (similar to `OR` joining filters)\n\n## Usage:\n\nSimple filters can be specified using a comma-separated-value list. So a filter specifying a string with minimum length of 5 could be represented as:\n\n``` php\n$filter = Filter::factory('string,min:5');\n```\n\nOr\n\n``` php\n$filter = new Filters\\String(array('min' =\u003e 5));\n```\n\nIf you pass a filter to `Filter::factory()`, it will be returned unmodified. So you can write functions like:\n\n``` php\nfunction foo($bar, $filter) {\n    // do something with $bar and set in $baz\n    return Filter::factory($filter)-\u003efilter($baz);\n}\n```\n\nComplex chaining can also be supported. So if you wanted to check if an array with a minimum size of 4, with numeric keys and containing strings of minimum length 5, that could be built like so:\n\n``` php\n$filter = Filter::array('min:4', 'int', 'string,min:5');\n```\n\nIf we wanted to validate an associative array, we would use a \"map\" filter:\n\n``` php\n$array = array(\n    'foo' =\u003e 2,\n    'bar' =\u003e 'test',\n);\n\n$filter = Filter::map(array(\n    'foo' =\u003e 'int',\n    'bar' =\u003e 'string,min:4',\n));\n\nvar_dump($filter-\u003evalidate($array)); // true\n```\n\n## Procedural Interface\n\nFilterus also ships with a procedural interface for calling filters.\n\n``` php\n\\Filterus\\filter($var, $filter);\n```\n\nAnd\n\n``` php\n\\Filterus\\validate($var, $filter);\n```\n\nAny filter is supported (both are basically simple wrappers):\n\n``` php\nfunction \\Filterus\\filter($var, $filter) {\n    return \\Filterus\\Filter::factory($filter)-\u003efilter($var);\n}\n```\n\nBoth are just convenience functions.\n\n\nSecurity Vulnerabilities\n========================\n\nIf you have found a security issue, please contact the author directly at [me@ircmaxell.com](mailto:me@ircmaxell.com).\n","funding_links":[],"categories":["过滤和验证","目录","Table of Contents","PHP","Filtering and Validation","过滤和验证 Filtering and Validation","过滤和验证( Filtering ang Validation )"],"sub_categories":["过滤和验证 Filtering and Validation","Filtering and Validation","Filtering, Sanitizing and Validation"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fircmaxell%2Ffilterus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fircmaxell%2Ffilterus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fircmaxell%2Ffilterus/lists"}