{"id":18553292,"url":"https://github.com/namshi/namshiutilitybundle","last_synced_at":"2025-07-07T21:32:56.164Z","repository":{"id":8192422,"uuid":"9621555","full_name":"namshi/NamshiUtilityBundle","owner":"namshi","description":"A collection of utilities for Sf2 apps.","archived":false,"fork":false,"pushed_at":"2014-05-01T06:45:47.000Z","size":216,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-03-24T13:21:21.321Z","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/namshi.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-04-23T11:29:18.000Z","updated_at":"2019-01-17T14:38:49.000Z","dependencies_parsed_at":"2022-08-06T21:15:37.387Z","dependency_job_id":null,"html_url":"https://github.com/namshi/NamshiUtilityBundle","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/namshi%2FNamshiUtilityBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/namshi%2FNamshiUtilityBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/namshi%2FNamshiUtilityBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/namshi%2FNamshiUtilityBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/namshi","download_url":"https://codeload.github.com/namshi/NamshiUtilityBundle/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248129508,"owners_count":21052584,"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-06T21:16:40.058Z","updated_at":"2025-04-09T23:30:39.249Z","avatar_url":"https://github.com/namshi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NAMSHI | UtilityBundle\n\nThis bundle provides some basic, silly utilities\nthat we use across our Symfony2 applications.\n\n## Installation\n\nThe bundle can be easily installed via\ncomposer (`\"namshi/utility-bundle\": \"dev-master\"`).\n\nMore informations available on\n[Packagist](https://packagist.org/packages/namshi/utility-bundle).\n\nThen enable it in the `AppKernel.php`:\n\n``` php\nnew Namshi\\UtilityBundle\\NamshiUtilityBundle(),\n```\n\n## Doctrine CommaSeparatedList type\n\nIf you want to persist an array into the\nDB as a list of comma-separated strings (ie.\nto be able to execute [FIND_IN_SET](http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set))\nyou can simply use the `Namshi\\UtilityBundle\\ORM\\Type\\CommaSeparatedList`\ntype.\n\nRemember to register it inside Symfony2's `config.yml`:\n\n```\ndoctrine:\n    dbal:\n        types:\n            comma_separated_list: Namshi\\UtilityBundle\\ORM\\Type\\CommaSeparatedList\n```\n\nand then use it on your entities:\n\n``` php\n/**\n * @var array\n *\n * @ORM\\Column(name=\"tags\", type=\"comma_separated_list\", nullable=true)\n */\nprotected $tags = array();\n```\n\n## File serving with authentication\n\nOne of the utilities that you can take\nadvantage of is file serving, mixing it\nwith authentication.\n\nSuppose you have a file, `protected.txt`,\nin `/path/to/symfony2/data/protected.txt`\nand you want only some users to be able\nto access it.\n\nYou just have to enable a route that tells\nthe bundle which file to serve:\n\n``` yml\nprotected_file:\n    pattern:  /protected.txt\n    defaults: { _controller: NamshiUtilityBundle:Default:serveFile, file: protected.txt }\n```\n\nand define the file path in the `parameters.yml`:\n\n``` yml\nnamshi_utility.files.protected.txt: /path/to/symfony2/data/protected.txt\n```\n\nAt that point you will be able to access the\ncontent of the file (it uses `file_get_contents()`, so\ndon't try using this utility as a download manager).\n\nHow to restrict access to the file then? Simply use\nthe built-in ACL system that you have in Symfony2:\nconfigure your `security.yml` for the path `^/protected.txt`\nand you're done.\n\n## Currency conversion\n\nTotally unrelated to Symfony2, but included here for (our) conveniency,\nthere is a currency converter that accepts conversion rates\nand can be used to easily convert an amount from a currency to\nanother one.\n\n``` php\n\u003c?php\n\nuse Namshi\\UtilityBundle\\Currency\\Converter;\nuse Namshi\\UtilityBundle\\Currency\\Currency;\nuse Namshi\\UtilityBundle\\Exception\\CurrencyNotFound;\n\n$conversionRates = array(\n  'EUR' =\u003e array(\n    'USD' =\u003e 1.3,\n  ),\n  'USD' =\u003e array(\n    'AED' =\u003e 4,\n    'EUR' =\u003e 0.7,\n  ),\n);\n\n$converter = new Converter($conversionRates);\n\ntry {\n    echo $converter-\u003econvert(12, Currency::UNITED_STATES_DOLLAR, Currency::EURO)\n} catch (CurrencyNotFound $e) {\n    echo \"Yo boss, can ya provide conversion rates here?\";\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnamshi%2Fnamshiutilitybundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnamshi%2Fnamshiutilitybundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnamshi%2Fnamshiutilitybundle/lists"}