{"id":19357718,"url":"https://github.com/joomla-framework/data","last_synced_at":"2025-07-27T14:36:20.077Z","repository":{"id":7094461,"uuid":"8385743","full_name":"joomla-framework/data","owner":"joomla-framework","description":"Joomla Framework Data Package","archived":false,"fork":false,"pushed_at":"2024-12-10T07:03:02.000Z","size":5503,"stargazers_count":5,"open_issues_count":1,"forks_count":7,"subscribers_count":13,"default_branch":"3.x-dev","last_synced_at":"2025-03-31T10:08:44.185Z","etag":null,"topics":["data-object","joomla","joomla-framework","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joomla-framework.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"joomla","custom":"https://community.joomla.org/sponsorship-campaigns.html"}},"created_at":"2013-02-24T03:17:22.000Z","updated_at":"2024-12-10T07:03:07.000Z","dependencies_parsed_at":"2024-06-18T21:29:12.771Z","dependency_job_id":"5531b8c9-a2b3-4bed-8661-238124318bad","html_url":"https://github.com/joomla-framework/data","commit_stats":{"total_commits":131,"total_committers":18,"mean_commits":7.277777777777778,"dds":0.5038167938931297,"last_synced_commit":"1fd9dbac7a19c761874784ea4c8215c3c3ff775b"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomla-framework%2Fdata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomla-framework%2Fdata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomla-framework%2Fdata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joomla-framework%2Fdata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joomla-framework","download_url":"https://codeload.github.com/joomla-framework/data/tar.gz/refs/heads/3.x-dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648976,"owners_count":20972945,"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":["data-object","joomla","joomla-framework","php"],"created_at":"2024-11-10T07:08:57.711Z","updated_at":"2025-07-27T14:36:20.070Z","avatar_url":"https://github.com/joomla-framework.png","language":"PHP","funding_links":["https://github.com/sponsors/joomla","https://community.joomla.org/sponsorship-campaigns.html"],"categories":[],"sub_categories":[],"readme":"## The Data Package [![Build Status](https://github.com/joomla-framework/data/actions/workflows/ci.yml/badge.svg?branch=3.x-dev)](https://github.com/joomla-framework/data)\n\n[![Latest Stable Version](https://poser.pugx.org/joomla/data/v/stable)](https://packagist.org/packages/joomla/data)\n[![Total Downloads](https://poser.pugx.org/joomla/data/downloads)](https://packagist.org/packages/joomla/data)\n[![Latest Unstable Version](https://poser.pugx.org/joomla/data/v/unstable)](https://packagist.org/packages/joomla/data)\n[![License](https://poser.pugx.org/joomla/data/license)](https://packagist.org/packages/joomla/data)\n\n### `Data\\DataObject`\n\n`Data\\DataObject` is a class that is used to store data but allowing you to access the data by mimicking the way PHP handles class properties. Rather than explicitly declaring properties in the class, `Data\\DataObject` stores virtual properties of the class in a private internal array. Concrete properties can still be defined but these are separate from the data.\n\n#### Construction\n\nThe constructor for a new `Data\\DataObject` object can optionally take an array or an object. The keys of the array or the properties of the object will be bound to the properties of the `Data\\DataObject` object.\n\n```php\nuse Joomla\\Data\\DataObject;\n\n// Create an empty object.\n$object1 = new DataObject;\n\n// Create an object with data. You can use an array or another object.\n$data = array(\n    'foo' =\u003e 'bar',\n);\n\n$object2 = new DataObject($data);\n\n// The following should echo \"bar\".\necho $object2-\u003efoo;\n```\n\n#### General Usage\n\n`Data\\DataObject` includes magic getters and setters to provide access to the internal property store as if they were explicitly declared properties of the class.\n\nThe `bind` method allows for injecting an existing array or object into the `Data\\DataObject` object.\n\nThe `dump` method gets a plain `stdClass` version of the `Data\\DataObject` object's properties. It will also support recursion to a specified number of levels where the default is 3 and a depth of 0 would return a `stdClass` object with all the properties in native form. Note that the `dump` method will only return virtual properties set binding and magic methods. It will not include any concrete properties defined in the class itself.\n\nThe `JsonSerializable` interface is implemented. This method proxies to the `dump` method (defaulting to a recursion depth of 3). Note that this interface only takes effect implicitly in PHP 5.4 so any code built for PHP 5.3 needs to explicitly use either the `jsonSerialize` or the `dump` method before passing to `json_encode`.\n\nThe `Data\\DataObject` class also implements the `IteratorAggregate` interface so it can easily be used in a `foreach` statement.\n\n```php\nuse Joomla\\Data\\DataObject;\n\n// Create an empty object.\n$object = new DataObject;\n\n// Set a property.\n$object-\u003efoo = 'bar';\n\n// Get a property.\n$foo = $object-\u003efoo;\n\n// Binding some new data to the object.\n$object-\u003ebind(array('goo' =\u003e 'car');\n\n// Get a plain object version of the data object.\n$stdClass = $object-\u003edump();\n\n// Get a property with a default value if it is not already set.\n$foo = $object-\u003efoo ?: 'The default';\n\n// Iterate over the properties as if the object were a real array.\nforeach ($object as $key =\u003e $value)\n{\n    echo \"\\n$key = $value\";\n}\n\nif (version_compare(PHP_VERSION, '5.4') \u003e= 0)\n{\n\t// PHP 5.4 is aware of the JsonSerializable interface.\n\t$json = json_encode($object);\n}\nelse\n{\n\t// Have to do it the hard way to be compatible with PHP 5.3.\n\t$json = json_encode($object-\u003ejsonSerialize());\n}\n```\n\n### `Data\\DataSet`\n\n`Data\\DataSet` is a collection class that allows the developer to operate on a list of `Data\\DataObject` objects as if they were in a typical PHP array (`Data\\DataSet` implements the `ArrayAccess`, `Countable` and `Iterator` interfaces).\n\n#### Construction\n\nA typical `Data\\DataSet` object will be instantiated by passing an array of `Data\\DataObject` objects in the constructor.\n\n```php\nuse Joomla\\Data\\DataObject;\nuse Joomla\\Data\\DataSet;\n\n// Create an empty object.\n$players = new DataSet(\n    array(\n        new DataObject(array('race' =\u003e 'Elf', 'level' =\u003e 1)),\n        new DataObject(array('race' =\u003e 'Chaos Dwarf', 'level' =\u003e 2)),\n    )\n);\n```\n\n#### General Usage\n\nArray elements can be manipulated with the `offsetSet` and `offsetUnset` methods, or by using PHP array nomenclature.\n\nThe magic `__get` method in the `Data\\DataSet` class effectively works like a \"get column\" method. It will return an array of values of the properties for all the objects in the list.\n\nThe magic `__set` method is similar and works like a \"set column\" method. It will set all a value for a property for all the objects in the list.\n\nThe `clear` method will clear all the objects in the data set.\n\nThe `keys` method will return all of the keys of the objects stored in the set. It works like the `array_keys` function does on an PHP array.\n\n```php\nuse Joomla\\Data\\DataObject;\n\n// Add a new element to the end of the list.\n$players[] =\u003e new DataObject(array('race' =\u003e 'Skaven', 'level' =\u003e 2));\n\n// Add a new element with an associative key.\n$players['captain'] =\u003e new DataObject(array('race' =\u003e 'Human', 'level' =\u003e 3));\n\n// Get a keyed element from the list.\n$captain = $players['captain'];\n\n// Set the value of a property for all objects. Upgrade all players to level 4.\n$players-\u003elevel = 4;\n\n// Get the value of a property for all object and also the count (get the average level).\n$average = $players-\u003elevel / count($players);\n\n// Clear all the objects.\n$players-\u003eclear();\n```\n\n`Data\\DataSet` supports magic methods that operate on all the objects in the list. Calling an arbitrary method will iterate of the list of objects, checking if each object has a callable method of the name of the method that was invoked. In such a case, the return values are assembled in an array forming the return value of the method invoked on the `Data\\DataSet` object. The keys of the original objects are maintained in the result array.\n\n```php\nuse Joomla\\Data\\DataObject;\nuse Joomla\\Data\\DataSet;\n\n/**\n * A custom data object.\n *\n * @since  1.0\n */\nclass PlayerObject extends DataObject\n{\n    /**\n     * Get player damage.\n     *\n     * @return  integer  The amount of damage the player has received.\n     *\n     * @since   1.0\n     */\n    public function hurt()\n    {\n        return (int) $this-\u003emaxHealth - $this-\u003eactualHealth;\n    }\n}\n\n$players = new DataSet(\n    array(\n        // Add a normal player.\n        new PlayerObject(array('race' =\u003e 'Chaos Dwarf', 'level' =\u003e 2,\n        \t'maxHealth' =\u003e 40, 'actualHealth' =\u003e '32')),\n        // Add an invincible player.\n        new PlayerObject(array('race' =\u003e 'Elf', 'level' =\u003e 1)),\n    )\n);\n\n// Get an array of the hurt players.\n$hurt = $players-\u003ehurt();\n\nif (!empty($hurt))\n{\n    // In this case, $hurt = array(0 =\u003e 8);\n    // There is no entry for the second player\n    // because that object does not have a \"hurt\" method.\n    foreach ($hurt as $playerKey =\u003e $player)\n    {\n        // Do something with the hurt players.\n    }\n};\n```\n\n### `Data\\DumpableInterface`\n\n`Data\\DumpableInterface` is an interface that defines a `dump` method for dumping the properties of an object as a `stdClass` with or without recursion.\n\n## Installation via Composer\n\nAdd `\"joomla/data\": \"~3.0\"` to the require block in your composer.json and then run `composer install`.\n\n```json\n{\n\t\"require\": {\n\t\t\"joomla/data\": \"~3.0\"\n\t}\n}\n```\n\nAlternatively, you can simply run the following from the command line:\n\n```sh\ncomposer require joomla/data \"~3.0\"\n```\n\nIf you want to include the test sources, use\n\n```sh\ncomposer require --prefer-source joomla/data \"~3.0\"\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoomla-framework%2Fdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoomla-framework%2Fdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoomla-framework%2Fdata/lists"}