{"id":27117116,"url":"https://github.com/a904guy/phingleton","last_synced_at":"2025-09-13T22:33:37.547Z","repository":{"id":13562429,"uuid":"16254695","full_name":"a904guy/phingleton","owner":"a904guy","description":"PHP Singleton Function Factory Generator.","archived":false,"fork":false,"pushed_at":"2014-01-26T15:22:08.000Z","size":132,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-24T12:20:33.108Z","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/a904guy.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":"2014-01-26T14:44:56.000Z","updated_at":"2014-01-26T15:22:08.000Z","dependencies_parsed_at":"2022-07-12T15:11:26.131Z","dependency_job_id":null,"html_url":"https://github.com/a904guy/phingleton","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a904guy%2Fphingleton","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a904guy%2Fphingleton/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a904guy%2Fphingleton/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/a904guy%2Fphingleton/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/a904guy","download_url":"https://codeload.github.com/a904guy/phingleton/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247601457,"owners_count":20964864,"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-07T05:54:12.303Z","updated_at":"2025-04-07T05:54:12.942Z","avatar_url":"https://github.com/a904guy.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"**Author**: Andy Hawkins  \n**Email**: YW5keUBhOTA0Z3V5LmNvbQ==  \n**About**: http://a904guy.com/  \n**Facebook**: http://fb.me/andyhawkins  \n**HackerNews**: http://hackerne.ws/user?id=a904guy  \n\n**Disclaimer Linux Only**\n \nThis file will allow you to create a project that will create global functions that allow you to instantly access an singleton classes from their class name\n \nIn the examples below I've defined a project folder called '/myproject/', and inside that folder there is an 'obj/' folder which contains your classes:\n \n\t/myproject/obj/\n        \t       db.class.php\n\t               cache.class.php\n \n \nOnce this code is executed, you can then call either easily from your code like so:\n \n\tdb()-\u003eset_creds('l33t','h@#0r');\n \n\tif(is_null($data = cache()-\u003eget(\"mysqlquery\")))\n\t{\n\t    $data = db()-\u003equery(\"Select...\");\n\t    cache()-\u003eset(\"mysqlquery\",$data);\n\t}\n \n\tvar_dump($data);\n \netc.\n \nYou can even pass constructor variables to these functions to create the singletons, they are keep separately, so no two returned methods with parameters defined collide.\n \n\tdb('mysql')\n\tdb('sqlite')\n\tcache('memcache')\n\tcache('file')\n\tcache('redis')\n \nWill return their respective classes initialized using the supplied variables. \n\n\n// Configuration\n \n\t$_CODE = array(); // Used to store object instances created.\n \n\t$_CODE['code_pwd'] = '/myproject/';\n\t$_CODE['objs_pwd'] = 'obj/';\n \n\n// Descriptions\n\n\tfunction getPath()\n\ngetPath ensures that the path given cannot break from the chroot path inside $_CODE['code_pwd'] or it will return false;\n   \nI would recommend using this in any project so that if you have to use variables within an include (dear jebus, DON'T!)\nit will atleast make sure they are chrooted to your project path\n\n\n\tclass singleton {}\n\nThe singleton class will scan the folder in question looking for files ending in .class.php, it will then create a function using the file/class name that can be called anywhere. I'll be burned alive for implementing \"eval\", but I assure you there is no way to exploit it. If you a wizard and do so, please email me, and I'll buy you a beer.\n \nIt will not actually read the contents of the files for the sake of speed, so Naming convention has to match the filename db = db.class.php (This can be changed below easily).\n \nAlthough you can make class revisions easily without breaking your code by specifying in db.class.php that class_alias('db_v2','db') and call the new class by using db() still.\n \nNOTE: I haven't used this to work with namespaces yet, but it could easily be done so with a folder, and file naming convention logic.\n \n\tfunction o()\n\nFactory Function o called from dynamically created Functions initialized in the Singleton Class to return the object.\nThis function also handles keep track of the previously initialized objects and return them as needed.\n \n\n\tfunction func_clean_args()\n\nSimple function to rearrange the func_get_args, to work with ReflectionClass::newInstanceArgs()\nThis could be turned into a map but what the hell it works great and is fast;\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa904guy%2Fphingleton","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fa904guy%2Fphingleton","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fa904guy%2Fphingleton/lists"}