{"id":19764379,"url":"https://github.com/brick/std","last_synced_at":"2025-04-30T14:33:00.544Z","repository":{"id":62497016,"uuid":"109395500","full_name":"brick/std","owner":"brick","description":"An attempt at a standard library for PHP","archived":false,"fork":false,"pushed_at":"2024-05-02T23:30:46.000Z","size":226,"stargazers_count":42,"open_issues_count":2,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-06T13:48:24.146Z","etag":null,"topics":["php","standard-library"],"latest_commit_sha":null,"homepage":null,"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/brick.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-11-03T12:55:52.000Z","updated_at":"2024-10-01T13:38:04.000Z","dependencies_parsed_at":"2023-01-20T21:18:56.296Z","dependency_job_id":null,"html_url":"https://github.com/brick/std","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick%2Fstd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick%2Fstd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick%2Fstd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brick%2Fstd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brick","download_url":"https://codeload.github.com/brick/std/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224214016,"owners_count":17274524,"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":["php","standard-library"],"created_at":"2024-11-12T04:13:43.708Z","updated_at":"2024-11-12T04:13:44.316Z","avatar_url":"https://github.com/brick.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Brick\\Std\n=========\n\n\u003cimg src=\"https://raw.githubusercontent.com/brick/brick/master/logo.png\" alt=\"\" align=\"left\" height=\"64\"\u003e\n\nAn attempt at a standard library for PHP.\n\n[![Build Status](https://github.com/brick/std/workflows/CI/badge.svg)](https://github.com/brick/std/actions)\n[![Coverage Status](https://coveralls.io/repos/github/brick/std/badge.svg?branch=master)](https://coveralls.io/github/brick/std?branch=master)\n[![Latest Stable Version](https://poser.pugx.org/brick/std/v/stable)](https://packagist.org/packages/brick/std)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)\n\nIntroduction\n------------\n\nThe PHP internal functions are notorious for their inconsistency: inconsistent naming, inconsistent parameter order, inconsistent error handling: sometimes returning `false`, sometimes triggering an error, sometimes throwing an exception, and sometimes a mix of these.\nThe aim of this library is mainly to provide a consistent, object-oriented wrapper around PHP native functions, that deals with inconsistencies internally to expose a cleaner API externally.\nHopefully PHP will do this job one day; in the meantime, this project is a humble attempt to fill the gap.\n\nThe library will start small. Functionality will be added as needs arise. Contributions are welcome.\n\nProject status \u0026 release process\n--------------------------------\n\nThe current releases are numbered `0.x.y`. When a non-breaking change is introduced (adding new methods, optimizing existing code, etc.), `y` is incremented.\n\n**When a breaking change is introduced, a new `0.x` version cycle is always started.**\n\nIt is therefore safe to lock your project to a given release cycle, such as `0.3.*`.\n\nIf you need to upgrade to a newer release cycle, check the [release history](https://github.com/brick/std/releases)\nfor a list of changes introduced by each further `0.x.0` version.\n\nInstallation\n------------\n\nThis library is installable via [Composer](https://getcomposer.org/):\n\n```bash\ncomposer require brick/std\n```\n\nRequirements\n------------\n\nThis library requires PHP 7.2 or later.\n\nOverview\n--------\n\n### IO\n\nFile I/O functionality is provided via static methods in the [FileSystem](https://github.com/brick/std/blob/master/src/Io/FileSystem.php) class. All methods throw an [IoException](https://github.com/brick/std/blob/master/src/Io/IoException.php) on failure.\n\n*The ultimate aim of this class would be to throw fine-grained exceptions for specific cases (file already exists, destination is a directory, etc.) but this would require to analyze PHP error messages, making the library fragile to changes, and/or call several internal filesystem functions in a row, making most of the operations non-atomic. Both approaches have potentially serious drawbacks. Ideas and comments welcome.*\n\nMethod list:\n\n- `copy()` Copies a file.\n- `move()` Moves a file or a directory.\n- `delete()` Deletes a file.\n- `createDirectory()` Creates a directory.\n- `createDirectories()` Creates a directory by creating all nonexistent parent directories first.\n- `exists()` Checks whether a file or directory exists.\n- `isFile()` Checks whether the path points to a regular file.\n- `isDirectory()` Checks whether the path points to a directory.\n- `isSymbolicLink()` Checks whether the path points to a symbolic link.\n- `createSymbolicLink()` Creates a symbolic link to a target.\n- `createLink()` Creates a hard link to an existing file.\n- `readSymbolicLink()` Returns the target of a symbolic link.\n- `getRealPath()` Returns the canonicalized absolute pathname.\n- `write()` Writes data to a file.\n- `read()` Reads data from a file.\n\n### Iterator\n\nThe library ships with two handy iterator for CSV files:\n\n#### CsvFileIterator\n\nThis iterator iterates over a CSV file, and returns an indexed array by default:\n\n```php\nuse Brick\\Std\\Iterator\\CsvFileIterator;\n\n// 1,Bob,New York\n// 2,John,Los Angeles\n$users = new CsvFileIterator('users.csv');\n\nforeach ($users as [$id, $name, $city]) {\n    // ...\n}\n```\n\nIt can also read the first line of the file that contains column names, and use them to return an associative array:\n\n```php\nuse Brick\\Std\\Iterator\\CsvFileIterator;\n\n// id,name,city\n// 1,Bob,New York\n// 2,John,Los Angeles\n$users = new CsvFileIterator('users.csv', true);\n\nforeach ($users as $user) {\n    // $user['id'], $user['name'], $user['city']\n}\n```\n\nDelimiter, enclosure and escape characters can be provided to the constructor.\n\n#### CsvJsonFileIterator\n\nThis iterator iterates over a CSV file whose fields are JSON-encoded:\n\n```php\nuse Brick\\Std\\Iterator\\CsvJsonFileIterator;\n\n// 1,\"Bob\",[\"John\",\"Mike\"]\n// 2,\"John\",[\"Bob\",\"Brad\"]\n$users = new CsvJsonFileIterator('users.csv');\n\nforeach ($users as [$id, $name, $friends]) {\n    // $id is an int\n    // $name is a string\n    // $friends is an array\n}\n```\n\nThe JSON-encoded fields must not contain newline characters.\n\n### JSON\n\nJSON functionality is provided by [JsonEncoder](https://github.com/brick/std/blob/master/src/Json/JsonEncoder.php) and [JsonDecoder](https://github.com/brick/std/blob/master/src/Json/JsonDecoder.php). Options are set on the encoder/decoder instance, via explicit methods. If an error occurs, a [JsonException](https://github.com/brick/std/blob/master/src/Json/JsonException.php) is thrown.\n\nEncoding:\n\n```php\nuse Brick\\Std\\Json\\JsonEncoder;\n\n$encoder = new JsonEncoder();\n$encoder-\u003eforceObject(true);\n\n$encoder-\u003eencode(['Hello World']); // '{\"0\":\"Hello World\"}'\n$encoder-\u003eencode(tmpfile()); // Brick\\Std\\Json\\JsonException: Type is not supported\n```\n\nDecoding:\n\n```php\nuse Brick\\Std\\Json\\JsonDecoder;\n\n$decoder = new JsonDecoder();\n$decoder-\u003edecodeObjectAsArray(true);\n\n$decoder-\u003edecode('{\"hello\":\"world\"}'); // ['hello' =\u003e 'world']\n$decoder-\u003edecode('{hello}'); // Brick\\Std\\Json\\JsonException: Syntax error\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrick%2Fstd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrick%2Fstd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrick%2Fstd/lists"}