{"id":15296256,"url":"https://github.com/sabloger/php-strict","last_synced_at":"2026-01-19T22:01:22.587Z","repository":{"id":62538909,"uuid":"98887000","full_name":"sabloger/php-strict","owner":"sabloger","description":"Strict-type Object base and Array-List for PHP 5!","archived":false,"fork":false,"pushed_at":"2017-10-17T06:52:38.000Z","size":31,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-27T16:29:59.557Z","etag":null,"topics":["array","arraylist","case-insensitive","composer-package","helper","iteration","json","object-oriented-programming","php","php5","strict-types","validation"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sabloger.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-31T12:34:32.000Z","updated_at":"2022-11-08T22:07:24.000Z","dependencies_parsed_at":"2022-11-02T16:15:32.428Z","dependency_job_id":null,"html_url":"https://github.com/sabloger/php-strict","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/sabloger/php-strict","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabloger%2Fphp-strict","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabloger%2Fphp-strict/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabloger%2Fphp-strict/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabloger%2Fphp-strict/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sabloger","download_url":"https://codeload.github.com/sabloger/php-strict/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sabloger%2Fphp-strict/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28587043,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T20:45:59.482Z","status":"ssl_error","status_checked_at":"2026-01-19T20:45:41.500Z","response_time":67,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["array","arraylist","case-insensitive","composer-package","helper","iteration","json","object-oriented-programming","php","php5","strict-types","validation"],"created_at":"2024-09-30T18:09:52.470Z","updated_at":"2026-01-19T22:01:22.567Z","avatar_url":"https://github.com/sabloger.png","language":"PHP","readme":"# php-strict\nStrict-type Object base and Array-List for PHP 5! (5.4 and upper!)\n\n[![License](https://poser.pugx.org/sabloger/php-strict/license.svg)](https://github.com/sabloger/php-strict/blob/master/LICENSE)\n[![Packagist](https://img.shields.io/badge/packagist-dev--master-orange.svg)](https://packagist.org/packages/sabloger/php-strict)\n\n## Introduction\n- If you want PHP much clearer you'll be happy with Php-Strict!\n- If you need a way to pass packed arguments to functions you'll be happy with Php-Strict!\n- If you need a way to validate arguments and get rid of exceptions and data-misses on invalid arguments you'll be happy with Php-Strict!\n- If you want a strict-type ArrayList like Java and other strict-typed languages you'll be happy with Php-Strict!\n- Binding to HTTP request is comming soon!!\n\n## Installation\nAdd following code to your `composer.json` and run `composer update`:\n```json\n{\n  \"require\": {\n    \"sabloger/php-strict\": \"dev-master\"\n  }\n}\n```\n\n## Usage: Object\nFirst extend one sub class from `BaseObject`, implement parent abstract methods, set predefines, instantiate then use! Finally run `$obj-\u003evalidate()` for validate data!. For example:\nSub-class:\n```php\nuse Php_Strict\\BaseObject;\n\n/**\n * Class Book\n * @package Php_Strict\n * @method Book setTitle(string $value)\n * @method Book setAuthor(string $value)\n * @method Book setYear(int $value)\n * @method Book setSome_Object(Object $value)\n * @method string getTitle()\n * @method string getAuthor()\n * @method int getYear()\n * @method Object getSome_Object()\n */\nclass Book extends BaseObject\n{\n    /**\n     * @return array\n     */\n    public function getFieldsStub()\n    {\n        return [\n            'title' =\u003e 'string', // All of types as you want!!\n            'author' =\u003e 'string',\n            'year' =\u003e 'int',\n            'some_object' =\u003e Object::class\n        ];\n    }\n\n    /**\n     * @return array\n     */\n    public function getRequiredFields()\n    {\n        return [\n            'title',\n            'year'\n        ];\n    }\n\n    /**\n     * If you want to allow setting undefined properties, set it True!\n     * @return bool\n     */\n    protected function isUndefinedSettingAllowed()\n    {\n        return false;\n    }\n}\n```\n* For ease of use and get suggestions on IDE for fields setters and getters, I strongly suggesting write class level docs, as like as above sample.\n\nUse:\n```php\n$book = new Book([\"Title\" =\u003e \"Advanced PHP Programming\"]); // Its case-insensitive and auto case-correcter!! :)\n$book-\u003esetAuthor(\"George Schlossnagle\");\n$book[\"Year\"] = 2004;\n\n$obj = new Object();\n$obj-\u003eFoo = \"bar\";\n$obj[\"foO\"] = \"BAR\"; // Yessss its case-insensitive and auto case-correcter!!  [\"Foo\": \"BAR\"]\n\n$book-\u003eset(\"some_object\",$obj); // Several access methods!! Use these as you want!!\n\nprint $book; // It's echoable!!\n//$book-\u003etoJson(); // Jsonable :)\n//$book-\u003etoArray(); // Arrayable :)\n\nforeach ($book as $key =\u003e $value) { // Iterateable :)\n  echo \"key: $key , value: $value \\n\";\n}\n/*\nOut:\n{\"title\":\"Advanced PHP Programming\",\"author\":\"George Schlossnagle\",\"year\":2004,\"some_object\":{\"Foo\":\"BAR\"}}\nkey: title , value: Advanced PHP Programming \nkey: author , value: George Schlossnagle \nkey: year , value: 2004 \nkey: some_object , value: {\"Foo\":\"BAR\"} \n*/\n```\n## Usage: ArrayList\nCan instantiate it directly and extend it for customization. For use only instantiate, setType and use!!\n\nBasic use:\n```php\n//Scalar:\n\n$strArr = new ArrayList('string');\n$strArr[] = \"correct!\";\n$strArr[] = 123; //PHP Fatal error:  Uncaught exception 'Php_Strict\\Exceptions\\InvalidItemTypeException' with message 'Invalid item type exception: Expected type was \"string\" given \"integer\"!'\n\nprint $strArr-\u003etoJson();\n\n\n//Object:\n$obj = new Object();\n$obj-\u003eFoo = \"bar\";\n$obj[\"foO\"] = \"BAR\";\n\n$arr = new ArrayList(Object::class);\n\n//$arr[0] = 11; //PHP Fatal error:  Uncaught exception 'Php_Strict\\Exceptions\\InvalidItemTypeException' with message 'Invalid item type exception: Expected type was \"Php_Strict\\Object\" given \"integer\"!'\n\n$arr[0] = $obj;\n$obj-\u003efoo = \"bar\";\n$arr[1] = $obj;\n$arr[0]-\u003ebaz = \"bag\";\n$arr[2] = $obj;\nprint $arr . \"\\n\";\nprint $obj; // Its by-reference!\n```\nAdvanced use:\n```php\nuse Php_Strict\\ArrayList;\n\nclass BookArrayList extends ArrayList\n{\n    /**\n     * @param array $items\n     * @return BookArrayList\n     */\n    public static function newLib(array $items = [])\n    {\n        return (new self($items));\n    }\n\n    /**\n     * BookArrayList constructor.\n     * @param array $items\n     */\n    public function __construct(array $items = [])\n    {\n        parent::__construct(Book::class, $items);\n    }\n\n    /**\n     * Validate all of items using Object-\u003evalidate() and ArrayList each()\n     * @throws \\Exception\n     * @return null|true\n     */\n    public function validate()\n    {\n        parent::each(function (Book $item, $key) { // ArrayList has each(closure) method! :)\n            try {\n                $item-\u003evalidate();\n            } catch (\\Exception $exception) {\n                throw new \\Exception(sprintf('ArrayList validation failed at offset (%s) with message: %s' , $key, $exception-\u003egetMessage()));\n            }\n        });\n        return true;\n    }\n}\n```\nUse:\n```php\n$book = new Book([\"Title\" =\u003e \"Advanced PHP Programming\"]);\n$book-\u003esetAuthor(\"George Schlossnagle\");\n\n$bookArr = BookArrayList::newLib();\n$bookArr[] = $book;\n$bookArr-\u003evalidate(); // PHP Fatal error:  Uncaught exception 'Exception' with message 'ArrayList validation failed at offset (0) with message: Required fields are not filled. unfilled required fields: ([\"year\"])'\n\nforeach ($bookArr as $book) { // Iterateable :)\n  echo \"item: $book  \\n\";\n}\n```\n## LICENSE\nThis library is released under the [MIT license](https://github.com/sabloger/php-strict/blob/master/LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsabloger%2Fphp-strict","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsabloger%2Fphp-strict","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsabloger%2Fphp-strict/lists"}