{"id":23387228,"url":"https://github.com/wp-forge/fluent","last_synced_at":"2025-04-08T12:34:08.586Z","repository":{"id":57082025,"uuid":"465895160","full_name":"wp-forge/fluent","owner":"wp-forge","description":"A PHP utility class which allows for more flexible ways of getting and setting data.","archived":false,"fork":false,"pushed_at":"2022-08-26T17:39:11.000Z","size":2,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-16T16:47:33.378Z","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/wp-forge.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":"2022-03-03T21:48:09.000Z","updated_at":"2022-03-03T21:50:44.000Z","dependencies_parsed_at":"2022-08-24T14:58:18.535Z","dependency_job_id":null,"html_url":"https://github.com/wp-forge/fluent","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Ffluent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Ffluent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Ffluent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wp-forge%2Ffluent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wp-forge","download_url":"https://codeload.github.com/wp-forge/fluent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247843595,"owners_count":21005475,"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-12-22T01:15:20.166Z","updated_at":"2025-04-08T12:34:08.563Z","avatar_url":"https://github.com/wp-forge.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Fluent Class\n\nA PHP utility class which allows for more flexible ways of getting and setting data.\n\n## Installation\n\n```shell\ncomposer require wp-forge/fluent\n```\n\n## Usage\n\n- [Setting Values](#setting-values)\n- [Getting Values](#getting-values)\n- [Checking if a Key Exists](#checking-if-a-key-exists)\n- [Deleting Values](#deleting-values)\n\n### Setting Values\n\nPopulate data from an existing array, object, or iterable\n\n```php\n\u003c?php\n\nuse WP_Forge\\Fluent\\Fluent;\n\n// Populate using an array\n$fluent = new Fluent( [ 'a' =\u003e 1 ] );\n\nvar_dump( $fluent-\u003etoJson() ); // {\"a\":1}\n\n// Populate using an object\n$fluent = new Fluent( (object) [ 'b' =\u003e 2 ] );\n\nvar_dump( $fluent-\u003etoJson() ); // {\"b\":2}\n\n// Populate using an iterable\n$fluent = new Fluent( (function () { yield 1; yield 2; })() );\n\nvar_dump( $fluent-\u003etoJson() ); // [1,2]\n```\n\nSet values using array syntax\n\n```php\n\u003c?php\n\n$fluent = new \\WP_Forge\\Fluent\\Fluent();\n\n$fluent['isActive'] = true;\n\nvar_dump( $fluent-\u003etoJson() ); // {\"isActive\":true}\n```\n\nSet values using property syntax\n\n```php\n\u003c?php\n\n$fluent = new \\WP_Forge\\Fluent\\Fluent();\n\n$fluent-\u003eisActive = true;\n\nvar_dump( $fluent-\u003etoJson() ); // {\"isActive\":true}\n```\n\nSet values using the `set()` method\n\n```php\n\u003c?php\n\n$fluent = new \\WP_Forge\\Fluent\\Fluent();\n\n$fluent-\u003eset('isActive', true);\n\nvar_dump( $fluent-\u003etoJson() ); // {\"isActive\":true}\n```\n\nSet values using by calling non-existent methods\n\n```php\n\u003c?php\n\n$fluent = new \\WP_Forge\\Fluent\\Fluent();\n\n$fluent-\u003eisActive(); // Will set to true by default\n\nvar_dump( $fluent-\u003etoJson() ); // {\"isActive\":true}\n\n$fluent-\u003eisActive( false );\n\nvar_dump( $fluent-\u003etoJson() ); // {\"isActive\":false}\n```\n\n### Getting Values\n\nGet values using array syntax\n\n```php\n\u003c?php\n\n$fluent = new \\WP_Forge\\Fluent\\Fluent( ['isActive' =\u003e true] );\n\nvar_dump( $fluent['isActive'] ); // true\n```\n\nGet values using property syntax\n\n```php\n\u003c?php\n\n$fluent = new \\WP_Forge\\Fluent\\Fluent( ['isActive' =\u003e true] );\n\nvar_dump( $fluent-\u003eisActive ); // true\n```\n\nGet values using the `get()` method\n\n```php\n\u003c?php\n\n$fluent = new \\WP_Forge\\Fluent\\Fluent( ['isActive' =\u003e true] );\n\nvar_dump( $fluent-\u003eget( 'isActive' ) ); // true\n\n// Since \"isRegistered\" doesn't exist, it returns the defined default value instead\nvar_dump( $fluent-\u003eget( 'isRegistered', 'Ask again later' ) ); // Ask again later\n```\n\nFetch all data using special methods\n\n```php\n\u003c?php\n\nuse WP_Forge\\Fluent\\Fluent;\n\n$fluent = new Fluent( ['a' =\u003e 1] );\n\n$fluent-\u003etoArray(); // Returns all data as an array\n$fluent-\u003etoJson(); // Returns all data as JSON\n```\n\n### Checking if a Key Exists\n\nUsing array syntax\n\n```php\n\u003c?php\n\nuse WP_Forge\\Fluent\\Fluent;\n\n$fluent = new Fluent( ['a' =\u003e 1] );\n\nvar_dump( isset( $fluent['a'] ) ); // true\nvar_dump( isset( $fluent['b'] ) ); // false\n```\n\nUsing property syntax\n\n```php\n\u003c?php\n\nuse WP_Forge\\Fluent\\Fluent;\n\n$fluent = new Fluent( ['a' =\u003e 1] );\n\nvar_dump( isset( $fluent-\u003ea ) ); // true\nvar_dump( isset( $fluent-\u003eb ) ); // false\n```\n\nUsing the `has()` method\n\n```php\n\u003c?php\n\nuse WP_Forge\\Fluent\\Fluent;\n\n$fluent = new Fluent( ['a' =\u003e 1] );\n\nvar_dump( $fluent-\u003ehas( 'a' ) ); // true\nvar_dump( $fluent-\u003ehas( 'b' ) ); // false\n```\n\n### Deleting Values\n\nUsing array syntax\n\n```php\n\u003c?php\n\nuse WP_Forge\\Fluent\\Fluent;\n\n$fluent = new Fluent( ['a' =\u003e 1] );\n\nunset( $fluent['a'] );\n\nvar_dump( $fluent-\u003etoJson() ); // []\n```\n\nUsing property syntax\n\n```php\n\u003c?php\n\nuse WP_Forge\\Fluent\\Fluent;\n\n$fluent = new Fluent( ['a' =\u003e 1] );\n\nunset( $fluent-\u003ea );\n\nvar_dump( $fluent-\u003etoJson() ) ); // []\n```\n\nUsing the `delete()` method\n\n```php\n\u003c?php\n\nuse WP_Forge\\Fluent\\Fluent;\n\n$fluent = new Fluent( ['a' =\u003e 1] );\n\n$fluent-\u003edelete( 'a' );\n\nvar_dump( $fluent-\u003etoJson() ); // []\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-forge%2Ffluent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwp-forge%2Ffluent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwp-forge%2Ffluent/lists"}