nozavroni / csvelte

🕺🏻 CSV and Tabular Data library for PHP
http://phpcsv.com/
Other
6 stars 0 forks source link

Remove autoload functionality from ``CSVelte\Autoloader`` class file #106

Closed nozavroni closed 7 years ago

nozavroni commented 7 years ago

It's apparently bad practice to define a class and then perform logic with it in the same file. This makes complete sense. Not sure why I did that in the first place. Rather than ask users to

<?php
require_once 'path/to/CSVelte/Autoloader.php';

You should instead, keep the Autoloader class definition inside the Autoloader.php file, but then create a new file named "autoload.php" and place it in either the "src" directory or in the "src/CSVelte" directory (I think I prefer the former). Maybe even create a src/bootstrap/autoload.php... I don't know. Think about it... then make it happen.

Contents of src/autoload.php

<?php
/**
 * Add the "src" directory to list of search paths and register autoloader
 * @var Autoloader
 */
$autoloader = new Autoloader();
$autoloader->addPath(__DIR__);
$autoloader->register();

From RTD todo item(s)

  • Look into PSR-4 for autoloading. According to a book I was just reading, PSR-4 eliminates the need for me to register an autoload function. See what this is all about...
  • Look into the other PSRs and see if any of them might benefit you as well (after looking through them, PSR-7 and PSR-17 were both very interesting - see GitHub issue #107)
nozavroni commented 7 years ago

Fixed and tested