{"id":12528,"date":"2022-11-07T10:00:00","date_gmt":"2022-11-07T01:00:00","guid":{"rendered":"https:\/\/www.gigas-jp.com\/appnews\/?p=12528"},"modified":"2022-11-04T19:02:25","modified_gmt":"2022-11-04T10:02:25","slug":"sanitizing-and-formatting-data-with-the-transformer-php-package","status":"publish","type":"post","link":"https:\/\/www.gigas-jp.com\/appnews\/archives\/12528","title":{"rendered":"Sanitizing and formatting data with the Transformer PHP package"},"content":{"rendered":"\n<p>Transformer is a PHP package for sanitizing and formatting data powered by Laravel&#8217;s validation components. The package uses a familiar Laravel validation-like syntax to transform data using classes, callable functions and etc.<\/p>\n\n\n\n<p>Here is a quick sample.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$input = &#091;\n  'name' =&gt; '  yuuma  ',\n  'phone_number' =&gt; '123-4567-7891',\n  'date_of_birth' =&gt; \"1998-04-12\",\n];\n\n(new DataTransformer($input, &#091;\n    'name' =&gt; 'trim|ucfirst',\n    'phone_number' =&gt; 'only_numbers',\n    'date_of_birth' =&gt; 'to_carbon|-&gt;format:m\/d\/y',\n]))-&gt;transform();\n\n\/\/ Returns:\n\/\/ &#091;\n\/\/     \"name\" =&gt; \"Yuuma\",\n\/\/     \"phone_number\" =&gt; \"12345677891\",\n\/\/     \"date_of_birth\" =&gt; \"04\/12\/98\",\n\/\/ ]<\/code><\/pre>\n\n\n\n<p>Data can also be transformed using closures or classes that implement the provided Transformable interface. Additionally, this package supports nested array data using dot notation, wildcard input (applying functions to keys matching a wildcard pattern), and more.<\/p>\n\n\n\n<p>Learn more about this package, get full installation instructions, and view the <a href=\"https:\/\/github.com\/surgiie\/transformer\" data-type=\"URL\" data-id=\"https:\/\/github.com\/surgiie\/transformer\" target=\"_blank\" rel=\"noreferrer noopener\">source code on GitHub<\/a>.<\/p>\n\n\n\n<p>Yuuma<\/p>\n<div class='wp_social_bookmarking_light'>\n            <div class=\"wsbl_google_plus_one\"><g:plusone size=\"medium\" annotation=\"none\" href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12528\" ><\/g:plusone><\/div>\n            <div class=\"wsbl_hatena_button\"><a href=\"\/\/b.hatena.ne.jp\/entry\/https:\/\/www.gigas-jp.com\/appnews\/archives\/12528\" class=\"hatena-bookmark-button\" data-hatena-bookmark-title=\"Sanitizing and formatting data with the Transformer PHP package\" data-hatena-bookmark-layout=\"standard\" title=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\"> <img src=\"\/\/b.hatena.ne.jp\/images\/entry-button\/button-only@2x.png\" alt=\"\u3053\u306e\u30a8\u30f3\u30c8\u30ea\u30fc\u3092\u306f\u3066\u306a\u30d6\u30c3\u30af\u30de\u30fc\u30af\u306b\u8ffd\u52a0\" width=\"20\" height=\"20\" style=\"border: none;\" \/><\/a><script type=\"text\/javascript\" src=\"\/\/b.hatena.ne.jp\/js\/bookmark_button.js\" charset=\"utf-8\" async=\"async\"><\/script><\/div>\n            <div class=\"wsbl_twitter\"><a href=\"https:\/\/twitter.com\/share\" class=\"twitter-share-button\" data-url=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12528\" data-text=\"Sanitizing and formatting data with the Transformer PHP package\" data-via=\"GIGASJAPAN_APPS\" data-lang=\"ja\">Tweet<\/a><\/div>\n            <div class=\"wsbl_facebook_like\"><div id=\"fb-root\"><\/div><fb:like href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12528\" layout=\"button_count\" action=\"like\" width=\"100\" share=\"false\" show_faces=\"false\" ><\/fb:like><\/div>\n            <div class=\"wsbl_facebook_send\"><div id=\"fb-root\"><\/div><fb:send href=\"https:\/\/www.gigas-jp.com\/appnews\/archives\/12528\" colorscheme=\"light\" ><\/fb:send><\/div>\n    <\/div>\n<br class='wp_social_bookmarking_light_clear' \/>\n","protected":false},"excerpt":{"rendered":"<p>Transformer is a PHP package for sanitizing and formatting data powered by Laravel&#8217;s validation componen [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[100],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12528"}],"collection":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/comments?post=12528"}],"version-history":[{"count":2,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12528\/revisions"}],"predecessor-version":[{"id":12531,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/posts\/12528\/revisions\/12531"}],"wp:attachment":[{"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/media?parent=12528"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/categories?post=12528"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gigas-jp.com\/appnews\/wp-json\/wp\/v2\/tags?post=12528"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}