{"id":18929390,"url":"https://github.com/thecodingmachine/utils.common.conditioninterface","last_synced_at":"2025-04-15T15:30:55.429Z","repository":{"id":4392374,"uuid":"5529404","full_name":"thecodingmachine/utils.common.conditioninterface","owner":"thecodingmachine","description":"This package contains one interface for condition, and a few classes that implement it. A condition is a class that possesses an \"isOk\" method. The condition returns true if the condition is met, and false otherwise.","archived":false,"fork":false,"pushed_at":"2019-08-29T15:23:12.000Z","size":14,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"2.0","last_synced_at":"2025-04-11T18:59:51.760Z","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/thecodingmachine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-08-23T16:50:00.000Z","updated_at":"2019-08-29T15:22:49.000Z","dependencies_parsed_at":"2022-08-23T12:20:24.269Z","dependency_job_id":null,"html_url":"https://github.com/thecodingmachine/utils.common.conditioninterface","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.common.conditioninterface","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.common.conditioninterface/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.common.conditioninterface/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thecodingmachine%2Futils.common.conditioninterface/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thecodingmachine","download_url":"https://codeload.github.com/thecodingmachine/utils.common.conditioninterface/tar.gz/refs/heads/2.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249097807,"owners_count":21212356,"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-11-08T11:32:20.204Z","updated_at":"2025-04-15T15:30:55.197Z","avatar_url":"https://github.com/thecodingmachine.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"What is this package?\n=====================\n\nThis package contains an interface used by test conditions.\nBasically, instances of classes implementing this interface can be tested and the instance will return \"true\" or \"false\".\n\nThe concept is very abstract, but also very powerful. Let's take a sample:\n- you might write a \"LoggedCondition\" class that implements a condition that returns true if the current user is logged, false otherwise.\n- you might write a \"HasRightCondition\" class that implements a condition that returns true if the current user has some set of rights, false otherwise.\n- you might write a \"TimeCondition\" class that implements a condition that returns true only at some time of the day.\n- ...\n\nObviously, this package is useless on its own. It is useful only if you implement the interface in your classes.\n\nBut what is it useful for?\n--------------------------\n\nIt gets very useful if some components of your code are just expecting a condition. For instance, let's assume you are\ndeveloping a menu system. A particular menu item should only be displayed when a user is logged.\n\nIf a menu item is represented by an instance of the MenuItem class, there are several way you can tackle this problem.\nUsing OO design, you could extend the MenuItem class to add special behaviour regarding the \"must be logged\" requirement. \nBut using the ConditionInterface, it gets more powerful. If each MenuItem contains a ConditionInterface, you only need\nto add a \"LoggedCondition\" instance to your menu item, and you are done!\nIt gets really interesting when you are using a dependency injection framework like Mouf.\n\nIn practice\n-----------\n\nImplementing the condition interface is simple stupid: just add a \"isOk\" method to your code:\n\n\t/**\n\t * Returns true if the condition is met, false otherwise.\n\t *\n\t * @param mixed $caller The condition caller. Optional.\n\t * @return bool\n\t */\n\tfunction isOk($caller = null);\n\nProvided classes\n----------------\n\nThis package comes with a few utility classes:\n\n- `TrueCondition`: always returns true\n- `FalseCondition`: always returns false\n- `AndCondition`: performs a logical AND between child conditions\n- `OrCondition`: performs a logical OR between child conditions\n- `NotCondition`: performs a logical NOT on a condition\n- `BoolToCondition`: wraps boolean into condition interface (useful to set it dynamically)\n\n\nMouf package\n------------\n\nThis package is part of Mouf (http://mouf-php.com), an effort to ensure good developing practices by providing a graphical dependency injection framework.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Futils.common.conditioninterface","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthecodingmachine%2Futils.common.conditioninterface","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthecodingmachine%2Futils.common.conditioninterface/lists"}