{"action":"created","issue":{"url":"https://api.github.com/repos/castle/castle-php/issues/8","labels_url":"https://api.github.com/repos/castle/castle-php/issues/8/labels{/name}","comments_url":"https://api.github.com/repos/castle/castle-php/issues/8/comments","events_url":"https://api.github.com/repos/castle/castle-php/issues/8/events","html_url":"https://github.com/castle/castle-php/issues/8","id":92759699,"number":8,"title":"Use an autoloader instead of manually including each file.","user":{"login":"tankerkiller125","id":3457368,"avatar_url":"https://avatars.githubusercontent.com/u/3457368?v=3","gravatar_id":"","url":"https://api.github.com/users/tankerkiller125","html_url":"https://github.com/tankerkiller125","followers_url":"https://api.github.com/users/tankerkiller125/followers","following_url":"https://api.github.com/users/tankerkiller125/following{/other_user}","gists_url":"https://api.github.com/users/tankerkiller125/gists{/gist_id}","starred_url":"https://api.github.com/users/tankerkiller125/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tankerkiller125/subscriptions","organizations_url":"https://api.github.com/users/tankerkiller125/orgs","repos_url":"https://api.github.com/users/tankerkiller125/repos","events_url":"https://api.github.com/users/tankerkiller125/events{/privacy}","received_events_url":"https://api.github.com/users/tankerkiller125/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-02T23:48:12Z","updated_at":"2015-08-28T07:20:08Z","closed_at":null,"body":"You could use an autoloader on lib/Castle.php this is very easy todo.\r\n\r\nlib/Castle/autoloader.php\r\n```php\r\n<?php\r\n/**\r\n * Get all files from the lib directory and require them.\r\n */\r\nfunction getFiles() \r\n{\r\n    $files = array_diff(scandir(dirname(__FILE__)), array('..', '.'));\r\n    foreach($files as $file)\r\n    {\r\n        require($file);\r\n    }\r\n}\r\nspl_autload_register('getFiles');\r\n```\r\n\r\nlib/Castle/Castle.php\r\n```php\r\n// Everything above requires remain the same\r\nrequire(dirname(__FILE__) . '/autoloader.php');\r\n// All other requires can be removed.\r\n```\r\n\r\nThis should greatly reduce the amount of effort needed to maintain this lib.\r\n\r\nAnother valid way of doing this (even easier) would be to use the following code in place of all the requires\r\n\r\n```php\r\nrequire(dirname(dirname(__FILE__)) . \"/vendor/autoload.php\");\r\n```\r\nThus using composer."},"comment":{"url":"https://api.github.com/repos/castle/castle-php/issues/comments/135659723","html_url":"https://github.com/castle/castle-php/issues/8#issuecomment-135659723","issue_url":"https://api.github.com/repos/castle/castle-php/issues/8","id":135659723,"user":{"login":"JavaPortals","id":1457521,"avatar_url":"https://avatars.githubusercontent.com/u/1457521?v=3","gravatar_id":"","url":"https://api.github.com/users/JavaPortals","html_url":"https://github.com/JavaPortals","followers_url":"https://api.github.com/users/JavaPortals/followers","following_url":"https://api.github.com/users/JavaPortals/following{/other_user}","gists_url":"https://api.github.com/users/JavaPortals/gists{/gist_id}","starred_url":"https://api.github.com/users/JavaPortals/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JavaPortals/subscriptions","organizations_url":"https://api.github.com/users/JavaPortals/orgs","repos_url":"https://api.github.com/users/JavaPortals/repos","events_url":"https://api.github.com/users/JavaPortals/events{/privacy}","received_events_url":"https://api.github.com/users/JavaPortals/received_events","type":"User","site_admin":false},"created_at":"2015-08-28T07:20:08Z","updated_at":"2015-08-28T07:20:08Z","body":"While the idea of an auto loader is great. The first example poses a security risk as it would load all PHP files in the specified directory."}}