{"id":2668,"date":"2017-08-18T12:39:26","date_gmt":"2017-08-18T10:39:26","guid":{"rendered":"http:\/\/nyamsprod.com\/blog\/?p=2668"},"modified":"2017-08-18T12:39:26","modified_gmt":"2017-08-18T10:39:26","slug":"league-csv-9","status":"publish","type":"post","link":"https:\/\/nyamsprod.com\/blog\/league-csv-9\/","title":{"rendered":"League\\Csv 9 is out"},"content":{"rendered":"<div class=\"message warning\">\n<p><strong>Attention:<\/strong> Les informations de ce billet sont susceptibles d'&ecirc;tre obsol&egrave;tes car vieux de plus 2 ans.<\/p>\n<p><strong>Warning: <\/strong> The information you are reading may be obsolete, this post was published more than 2 years ago.<\/p>\n<\/div><p>I&#8217;m happy to announce that <code>League\\Csv<\/code> version 9.0 has been released. This is a new major version which requires PHP7 (HHVM support is dropped). This new version focuses on making the code more SOLID while enabling better CSV document manipulation.<\/p>\n<h3>What&#8217;s new<\/h3>\n<p>The library comes bundle with two new stream filters.<\/p>\n<p><code>League\\Csv\\CharsetConverter<\/code> which converts on the fly your CSV document from one charset to another.<\/p>\n<script src=\"https:\/\/gist.github.com\/30fb4b0fe8fafd533773cca37846827d.js?file=charsetconverter.php\"><\/script>\n<p><code>League\\Csv\\RFC4180Field<\/code> which format on reading or on writing CSV field to be <a href=\"https:\/\/tools.ietf.org\/html\/rfc4180\">RFC4180<\/a> compliant by working around PHP&#8217;s bugs.<\/p>\n<script src=\"https:\/\/gist.github.com\/30fb4b0fe8fafd533773cca37846827d.js?file=rfc4180field.php\"><\/script>\n<h3>What&#8217;s changed<\/h3>\n<p>At the beginning, this library was just a set of 2 classes <code>Reader<\/code> and <code>Writer<\/code> that made it painless to interact with CSV documents. But as features were added those classes inherited too many responsabilities making them more difficult to use. By taking advantage of modern PHP features both classes API have been changed and\/or improve and their responsabilities restricted:<\/p>\n<p>&#8211; The <code>Writer<\/code> connection primary responsability is to add records to the CSV records;<br \/>\n&#8211; The <code>Reader<\/code> connection primary responsability is to access all CSV records;<\/p>\n<p>Everything else (converting, querying) has been delegated to new classes.<\/p>\n<h4>Fetching CSV records<\/h4>\n<p>Previously, accessing the document records was done using the <code>Reader<\/code> object and different methods (ie: <code>Reader::fetchAll<\/code>, <code>Reader::fetchAssoc<\/code>, <code>Reader::each<\/code>, <code>Reader::fetch<\/code>). In version 9,\u00a0 you will only need the newly introduced <code>Reader::getRecords<\/code> method. As such accessing CSV records is easier than before.<\/p>\n<script src=\"https:\/\/gist.github.com\/30fb4b0fe8fafd533773cca37846827d.js?file=getrecords.php\"><\/script>\n<p>Of note, unlike previous version, the <code>Reader<\/code> now automatically strip the BOM sequence if present.<\/p>\n<h4>Querying the CSV document<\/h4>\n<p>Searching the CSV document has been decoupled from the <code>Reader<\/code> class. This means that if you are processing multiple CSV documents you don&#8217;t need to repeat your selection on each CSV object or on the same CSV if you need to make multiple queries on it.<\/p>\n<script src=\"https:\/\/gist.github.com\/30fb4b0fe8fafd533773cca37846827d.js?file=statement.php\"><\/script>\n<h4>Converting the CSV document<\/h4>\n<p>Starting with version 9, only the <code>Reader<\/code> class can be converted or serialized. XML and HTML conversion is done using dedicated classes. For instance, to convert your CSV records to XML you are now required to use the <code>League\\Csv\\XMLConverter<\/code>. Not only, This new class improves how the conversion is done by adding more configuration settings but it can be used for any tabular data like the result of a <code>PDO::Statement<\/code>.<\/p>\n<script src=\"https:\/\/gist.github.com\/30fb4b0fe8fafd533773cca37846827d.js?file=xmlconverter.php\"><\/script>\n<h3>Upgrading to League\\Csv 9<\/h3>\n<p>As you would expect, this is only a quick view of the new features and changes this new version offers. You should head to<a href=\"http:\/\/csv.thephpleague.com\/9.0\/\" target=\"_blank\" rel=\"noopener\"> the documentation website<\/a> for a full explanation about the new version capabilities.<\/p>\n<p>Even though this package introduces many backward compatibility breaks. I&#8217;m confident that upgrading to <code>League\\Csv<\/code> 9 won&#8217;t require changes for most users. If you do encounter an issue <a href=\"http:\/\/csv.thephpleague.com\/upgrading\/9.0\/\" target=\"_blank\" rel=\"noopener\">the upgrading guide<\/a> should help you ease the transition path.<\/p>\n<h3>Last but not least<\/h3>\n<p>The <code>League\\Csv<\/code> is <a href=\"https:\/\/github.com\/thephpleague\/csv\" target=\"_blank\" rel=\"noopener\">an open source project<\/a> with a MIT License so contributions are more than welcome and will be fully credited. These contributions can be anything from reporting an issue, requesting or adding missing features or simply improving or correcting some typo on the documentation website.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>League CSV 9 is out with a simplified and modern API<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5],"tags":[761,814,766,412,785],"class_list":["post-2668","post","type-post","status-publish","format-standard","hentry","category-web","tag-csv","tag-new-release","tag-open-source","tag-php","tag-thephpleague"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/nyamsprod.com\/blog\/wp-json\/wp\/v2\/posts\/2668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nyamsprod.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nyamsprod.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nyamsprod.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nyamsprod.com\/blog\/wp-json\/wp\/v2\/comments?post=2668"}],"version-history":[{"count":5,"href":"https:\/\/nyamsprod.com\/blog\/wp-json\/wp\/v2\/posts\/2668\/revisions"}],"predecessor-version":[{"id":2674,"href":"https:\/\/nyamsprod.com\/blog\/wp-json\/wp\/v2\/posts\/2668\/revisions\/2674"}],"wp:attachment":[{"href":"https:\/\/nyamsprod.com\/blog\/wp-json\/wp\/v2\/media?parent=2668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nyamsprod.com\/blog\/wp-json\/wp\/v2\/categories?post=2668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nyamsprod.com\/blog\/wp-json\/wp\/v2\/tags?post=2668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}