{"id":22121113,"url":"https://github.com/samcrosoft/constantaccess","last_synced_at":"2025-03-24T06:44:46.756Z","repository":{"id":6868089,"uuid":"8117047","full_name":"samcrosoft/constantaccess","owner":"samcrosoft","description":"This library makes it possible to create and read (access) constants using an array-like object or a typical class object to make it possible to use constants in strings without the need of concatenation of strings","archived":false,"fork":false,"pushed_at":"2015-11-28T15:55:28.000Z","size":20,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-29T12:30:18.659Z","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/samcrosoft.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":"2013-02-10T00:06:24.000Z","updated_at":"2015-11-28T15:55:28.000Z","dependencies_parsed_at":"2022-09-18T11:02:53.048Z","dependency_job_id":null,"html_url":"https://github.com/samcrosoft/constantaccess","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samcrosoft%2Fconstantaccess","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samcrosoft%2Fconstantaccess/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samcrosoft%2Fconstantaccess/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/samcrosoft%2Fconstantaccess/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/samcrosoft","download_url":"https://codeload.github.com/samcrosoft/constantaccess/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245224199,"owners_count":20580363,"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-01T14:33:54.851Z","updated_at":"2025-03-24T06:44:46.734Z","avatar_url":"https://github.com/samcrosoft.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/samcrosoft/constantaccess.svg?branch=master)](https://travis-ci.org/samcrosoft/constantaccess)\n\nconstantaccess\n==============\n\nThis library makes it possible to create and read (access) constants using an array-like object or a typical class object to make it possible to use constants in strings without the need of concatenation of strings\n\n\u003cbr/\u003e\n\n## Example\nCreate an object of the constant access library and then start creating or reading constants\n\u003cpre\u003e\n$oConst = new Samcrosoft\\ConstantAccess\\ConstantAccess();\n\n\u003c/pre\u003e\n\n\u003cbr/\u003e\n\n## Instantiating The Constant Class With An Array\nyou can supply an array key=\u003epair values for constants to create, **NOTE: this array should be a 1 dimensional array**\n\ne.g\n\u003cpre\u003e\n\t$aData = array(\n\t\t\t\t\t'const1'  =\u003e 2,\n\t\t\t\t\t'const2'  =\u003e 22,\n\t\t\t\t\t'_const3' =\u003e 'another constant'\n\t\t\t\t   );\n\n // then create it now as\n\n $oConst = new Samcrosoft\\ConstantAccess\\ConstantAccess($aData);\n\u003c/pre\u003e\n\n\u003cbr/\u003e\n\n### Creating Constants Using Object Method or Array Access\n\u003cpre\u003e\n$oConst-\u003eCONST1 = 23;               This creates a constant called CONST1\n$oConst['CONST2'] = \"constant 2\";   This creates another constant called CONST2\n\u003c/pre\u003e\n\n\u003cbr/\u003e\n\n### Throwing Exceptions\nTo create a valid php constant, the following conditions must be met\n\n- A constant key can only be a valid php variable name \n- A Constant value can only be a value of scalar type, \n\nBefore creating a constant, the above tests are conducted, hence there are possibilities of exceptions been thrown if any of the above listed conditions are not adhered to or met\n\nThe ConstantAccess **dies** silently i.e it does not throw any exception by default but for good programming practice, you should handle all possibilites of exceptions\n\n\u003cbr/\u003e\n\n### Enabling Exceptions\nYou can enable the exceptions in two(2) ways, \n\n - At the creation of the class object\n - By using the **setThrowException** method\n\n **e.g**\n \u003cpre\u003e\n 1 - $oConst = new Samcrosoft\\ConstantAccess\\ConstantAccess(array(), true);\n 2 - $oConst-\u003esetThrowException(false);\n \u003c/pre\u003e\n\n\u003cbr/\u003e\n\n\n### Default Return Value\nIf a constant is not defined, you can configure a default return value that is returned in that case instead of breaking ur application\n\n\u003cpre\u003e\n e.g To set the default return value to null, you do the following\n\n $oConst-\u003esetValueReturnIfNotDefined(null);\n\n hence, $oConst-\u003eUNDEFINED; would return null\n\u003c/pre\u003e\n\n\n\u003cbr/\u003e\n\n### Reading / Accessing Constants\n\n\u003cpre\u003e\nprint \"this is a trial message with {$oConst-\u003eCONST1} or another {$oConst-\u003eCONST2}\";\n\u003c/pre\u003e\n\n\u003cbr/\u003e\n\n### Tests\n just run Phpunit in the folder where you have placed the library\n\n\n\u003cbr/\u003e\n### Examples\n\nexamples are located in the **/examples** folder\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamcrosoft%2Fconstantaccess","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsamcrosoft%2Fconstantaccess","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsamcrosoft%2Fconstantaccess/lists"}