{"id":27158894,"url":"https://github.com/activecollab/resistance","last_synced_at":"2025-10-28T07:13:20.003Z","repository":{"id":27633585,"uuid":"31118121","full_name":"activecollab/resistance","owner":"activecollab","description":"Redis powered data persistence for PHP (experiment)","archived":false,"fork":false,"pushed_at":"2015-07-01T04:28:17.000Z","size":302,"stargazers_count":1,"open_issues_count":0,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-30T13:03:29.017Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/activecollab.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":"2015-02-21T07:06:53.000Z","updated_at":"2017-02-10T22:35:35.000Z","dependencies_parsed_at":"2022-08-29T16:30:48.399Z","dependency_job_id":null,"html_url":"https://github.com/activecollab/resistance","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Fresistance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Fresistance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Fresistance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/activecollab%2Fresistance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/activecollab","download_url":"https://codeload.github.com/activecollab/resistance/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247941718,"owners_count":21022035,"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":"2025-04-08T22:39:20.161Z","updated_at":"2025-10-28T07:13:14.952Z","avatar_url":"https://github.com/activecollab.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Resistance\n\n[![Build Status](https://travis-ci.org/activecollab/resistance.svg?branch=master)](https://travis-ci.org/activecollab/resistance)\n\nResistance is a simple Redis key manager for PHP. It does not try to be a fully featured ORM, just to make keyspace \nmanagement easier.\n\n## How to use?\n\nInclude it in your project using Composer:\n\n```json\n{\n    \"require\": {\n        \"activecollab/resistance\": \"~0.1\"\n    }\n}\n```\n\nImplement a storage:\n\n```php\n\u003c?php\n  namespace My\\App\\Storage;\n\n  use Predis\\Client;\n  use ActiveCollab\\Resistance\\Storage\\Storage;\n  use ActiveCollab\\Resistance\\Storage\\Field\\StringField;\n  use ActiveCollab\\Resistance\\Storage\\Field\\IntegerField;\n  use ActiveCollab\\Resistance\\Storage\\Field\\BooleanField;\n\n  /**\n   * @package ActiveCollab\\GrandCentral\\Storage\n   */\n  final class MyObjects extends Storage\n  {\n    /**\n     * Construct a new storage instance\n     *\n     * @param Client $connection\n     * @param string $application_namespace\n     */\n    public function __construct(Client \u0026$connection, $application_namespace)\n    {\n      parent::__construct($connection, $application_namespace);\n\n      $this-\u003esetFields([\n        'url'           =\u003e (new StringField)-\u003erequired()-\u003eunique()-\u003eisUrl()-\u003emodifier('trim'),\n        'is_paid'       =\u003e  new BooleanField,\n        'members_count' =\u003e  new IntegerField,\n        'clients_count' =\u003e  new IntegerField,\n      ]);\n    }\n  }\n```\n\n## Field Settings\n\nCommon field settings:\n\n1. ``map`` - Map ID-s and values and make them accessible via ``getIdsBy()`` method,\n1. ``protect`` - Protect field from being set on ``insert()``, \n2. ``required`` - Value is required not to be empty,\n3. ``unique`` - Make sure that field value is unique in the storage (required is implied). This setting is not applicable to boolean fields,\n\nString field settings:\n\n1. ``format`` - Value is required and needs to match the given format,\n2. ``isEmail`` - Value is required and needs to be a valid email address,\n3. ``isUrl`` - Value is required and needs to be a valid URL,\n4. ``modifier`` - Make sure that values go through this callback or function before they are stored.\n\n\n## Read, Update, Delete\n\nInstantiate it using a ``\\ActiveCollab\\Resistance::factory()``:\n\n```php\n\\ActiveCollab\\Resistance::factory(\"\\My\\App\\Storage\\MyObjects\")-\u003einsert([], [], …);\n\\ActiveCollab\\Resistance::factory(\"\\My\\App\\Storage\\MyObjects\")-\u003eupdate($id, []);\n\\ActiveCollab\\Resistance::factory(\"\\My\\App\\Storage\\MyObjects\")-\u003eget($id);\n\\ActiveCollab\\Resistance::factory(\"\\My\\App\\Storage\\MyObjects\")-\u003egetFieldValue($id, 'url');\n\\ActiveCollab\\Resistance::factory(\"\\My\\App\\Storage\\MyObjects\")-\u003edelete($id);\n```\n\n## Migrations\n\nResistance implements a simple data migration system. to use migrations, create directory in your project where you will store migrations and name them like ``Migration0001.ThisIsMigrationDescription.php`` or ``Migration0001.php``. Class names of migrations should be in ``Migration0001`` format and they need to extend ``ActiveCollab\\Resistance\\Storage\\Migration`` class. Description bit is optional and ignored - it's just for your reference. Example:\n \n \n    /my/awesome/project/migrations/Migration0001.AddedNewField.php\n    /my/awesome/project/migrations/Migration0002.MappedFieldValue.php\n    /my/awesome/project/migrations/Migration0003.MadeFieldUnqiue.php\n    /my/awesome/project/migrations/Migration0004.NoLongerNeedsToBeUnique.php\n    \nYou can instruct Resistance to execute all migrations using:\n\n```php\n\\ActiveCollab\\Resistance::migrate('/my/awesome/project/migrations/', 'MyOrg\\MyProject\\Migrations');\n```\n\nFirst parameter is path to the folder where you have your migration classes stored, and second parameter is your migrations namespace. If you are not namespacing your migrations (not recommended), ommit the second parameter blank.\n\nUseful methods that you can use in migrations:\n\n* ``\\ActiveCollab\\Resistance\\Storage\\Collection::bulkSetFieldValue($field_name, $value)`` - Bulk set field value. ``$value`` can be callback that is called for each record, or a value that will be cast and stored, \n* ``\\ActiveCollab\\Resistance\\Storage\\Collection::bulkRemoveFieldValue($field_name)`` - Clean up values from the database, usually after field has been dropped from the collection, \n* ``\\ActiveCollab\\Resistance\\Storage\\Collection::buildValueMap($field_name)`` - Create value map for the field, usually after field has been added to the collection, \n* ``\\ActiveCollab\\Resistance\\Storage\\Collection::removeValueMap($field_name)`` - Remove value map from the field, after field was removed or mapping is no longer needed, \n* ``\\ActiveCollab\\Resistance\\Storage\\Collection::buildUniquenessMap($field_name)`` - Create uniqueness map for the field, usually after field has been added to the collection, \n* ``\\ActiveCollab\\Resistance\\Storage\\Collection::removeUniquenessMap($field_name)`` - Remove uniqueness map from the field, after field was removed or it no longer needs to be marked as unique. \n    \n## How to contribute?\n\nFive simple steps to contribute.\n\n1. Fork the repo, \n2. Clone to your computer,\n3. ``cd`` to checkout folder and run ``composer install`` to update dependencies, \n4. Make and push the changes. Make sure that you have tests in place,\n5. Send a Pull Request.\n\nThank you!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factivecollab%2Fresistance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Factivecollab%2Fresistance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Factivecollab%2Fresistance/lists"}