diff --git a/README.md b/README.md index 84f576a..ac07e62 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ClassFinder =========== -A lightweight utility to identify classes in a given namespace. This package is an improved implementation of an +A dead simple utility to identify classes in a given namespace. This package is an improved implementation of an [answer on Stack Overflow](https://stackoverflow.com/a/40229665/3000068) that provides additional features with less configuration required. @@ -9,15 +9,8 @@ Requirements ------------ * Application is using Composer. - * Classes are compliant with PSR-4. + * Classes can be autoloaded with PSR-4 or classmaps. * PHP >= 5.3.0 - -Known Limitations ------------------ - -* ClassFinder can only identify classes autoloaded with PSR-4. PSR-0, classmaps, and files are not supported. - -These limitations may eventually be fixed. Installing ---------- @@ -64,4 +57,36 @@ Documentation **Internals** * [How Testing Works](docs/testing.md) -* [Continuous Integration Notes](docs/ci.md) \ No newline at end of file +* [Continuous Integration Notes](docs/ci.md) + +Roadmap +------- + +> **WARNING**: Before 1.0.0, expect that bug fixes _will not_ be backported to older versions. Backwards incompatible changes +may be introduced in minor 0.X.Y versions, where X changes. + +0.0.1 - First party `psr4` classes + +0.1.0 - Third party `psr4` classes + +0.2.0 - `classmap` support. + +0.3.0 - `files` support + +0.4.0 - `psr0` support + +0.5.0 - Additional features: + +Various ideas: + +* `ClassFinder::getClassesInNamespace('TestApp1\Foo', ClassFinder::RECURSIVE_MODE)`. +Providing classes multiple namespaces deep. + +* `ClassFinder::getClassesImplementingInterface('TestApp1\Foo', 'TestApp1\FooInterface', ClassFinder::RECURSIVE_MODE)`. +Filtering classes to only classes that implement a namespace. + +* `ClassFinder::debugRenderReport('TestApp1\Foo\Baz')` +Guidance for solving "class not found" errors resulting from typos in namespaces, missing directories, etc. Would print +an HTML report. Not intended for production use, but debugging. + +1.0.0 - Better compliance with semantic versioning. \ No newline at end of file diff --git a/docs/changelog.md b/docs/changelog.md index 2e07673..20d0f7a 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,3 +1,21 @@ +Version 0.2.0 +------------- + +* Added support for finding classes declared via `classmap`. +* Exceptions will no longer be thrown when PSR4 can't find a registered namespace (because it could be a valid class +declared in a `classmap`) + +Example composer.json that is now supported: +``` + ... + "autoload": { + ... + "classmap": [ "src/foo/", "src/bar/" ] + } + ... +``` + + Version 0.1.2 ------------- diff --git a/docs/exceptions/unknownNamespace.md b/docs/exceptions/unknownNamespace.md new file mode 100644 index 0000000..be55bcd --- /dev/null +++ b/docs/exceptions/unknownNamespace.md @@ -0,0 +1,37 @@ +Unknown Namespace +----------------- + +Example PHP: +``` + Unknown namespace 'Acme\Foo\Bar' + +This exception occurs when the provided namespace isn't declared or isn't accessible based on items are _are_ declared +in `composer.json`. In the given example, `Acme` is declared to map to `src/` in `composer.json`, so PSR4 would mandate +that `src/Foo/Bar` is a valid path for a directory. However, that directory could not be located, and therefore the +provided namespace is unknown. + +If you discover that this exception is raised and Composer _can_ autoload classes found in the namespace, please submit +an issue. diff --git a/docs/exceptions/unknownSubNamespace.md b/docs/exceptions/unknownSubNamespace.md deleted file mode 100644 index bf8af67..0000000 --- a/docs/exceptions/unknownSubNamespace.md +++ /dev/null @@ -1,51 +0,0 @@ -Unknown Child Namespace ------------------------ - -Example composer.json: -``` -{ - "name": "haydenpierce/sample-app", - "type": "application", - "license": "MIT", - "authors": [ - { - "name": "Hayden Pierce", - "email": "hayden@haydenpierce.com" - } - ], - "autoload": { - "psr-4": { - "Acme\\": "src/" - } - } -} -``` - -Example PHP: -``` - Unknown namespace 'TestApp1\Foo\Bar'. Checked for files in *C:\Users\HPierce\PhpstormProjects\ClassFinder\test\app1\src\Foo\Bar*, but that directory did not exist - -ClassFinder attempts to figure out which directory it should look for classes in by piecing together a path from -elements in your `autoload.psr-4` configuration. In this instance, we've asked for classes in the `Acme\Foo\Bar` namespace, -so ClassFinder will attempt to build a directory path there. ClassFinder successfully mapped *Acme* to `src/`, but upon adding -the rest of the namespace to the path, failed to find a directory. - -Things to check for: - -* Does the directory actually exist? -* Does PHP have permissions to the directory? -* Is your app PSR-4 compliant? -* Is the namespace correct? - -If this information doesn't resolve the issue, please feel free to submit an issue. \ No newline at end of file diff --git a/docs/exceptions/unregisteredRoot.md b/docs/exceptions/unregisteredRoot.md deleted file mode 100644 index 0a192fc..0000000 --- a/docs/exceptions/unregisteredRoot.md +++ /dev/null @@ -1,62 +0,0 @@ -Unknown Namespace Root ----------------------- - -Example composer.json: -``` -{ - "name": "haydenpierce/sample-app", - "type": "application", - "license": "MIT", - "authors": [ - { - "name": "Hayden Pierce", - "email": "hayden@haydenpierce.com" - } - ], - "autoload": { - "psr-4": { - "HaydenPierce\\": "src/" - } - } -} -``` - -Example PHP: -``` - Unknown namespace 'DoesNotExist\Foo\Bar'. You should add the namespace prefix to composer.json. - -ClassFinder attempts to figure out which directory it should look for classes in by piecing together a path from -elements in your `autoload.psr-4` configuration. In this instance, we've asked for classes in the `Acme\Foo\Bar` namespace, -so ClassFinder will attempt to build a directory path there. Since none of `Acme`, `Acme\Foo`, or `Acme\Foo\Bar` exist -in the `autoload.psr-4`, ClassFinder cannot determine a valid path. - -This can be solved by adding `Acme` to the `autoload.psr-4` key like so: - -``` -{ - ... - "autoload": { - "psr-4": { - "HaydenPierce\\": "src/", - "Acme\\" : "src/acme" - } - } - ... -} -``` - -This will allow ClassFinder to search `src/acme/Foo/Bar/*` for classes in the `Acme\Foo\Bar` namespace. You could also add -`Acme\Foo` to the `autoload.psr-4` config if that makes more sense. - -If this information doesn't resolve the issue, please feel free to submit an issue. \ No newline at end of file diff --git a/src/ClassFinder.php b/src/ClassFinder.php index 0f5978f..bac6c72 100644 --- a/src/ClassFinder.php +++ b/src/ClassFinder.php @@ -48,7 +48,7 @@ class ClassFinder if (!$isNamespaceKnown) { throw new ClassFinderException(sprintf("Unknown namespace '%s'. See '%s' for details.", $namespace, - 'https://gitlab.com/hpierce1102/ClassFinder/blob/master/docs/exceptions/unregisteredRoot.md' + 'https://gitlab.com/hpierce1102/ClassFinder/blob/master/docs/exceptions/unknownNamespace.md' )); }