I’m not thrilled about this proposal.
It seems to me, the reason you ran into problems/limitations with the original syntax, is because it was too simple and based on various assumptions about needs. Now you’ve extended the assumptions to include support for URLs, but it doesn’t feel like a great solution to me, because it’s still based on assumptions about a limited number of uses.
I like the approach taken by the stream handlers in PHP. Of course, we’re not dealing with streams here, but we are dealing with resources, and the Uniform Resource Identifier is the de-facto standard for identifying resources.
You’re trying to expand your custom resource-identification scheme to include URLs, which are just one type of URI - this to me is an indication that you’re working backwards; from a limited, non-standard scheme, to a single kind of URI, just one of a broad spectrum of resource-types supported by the URI scheme.
It doesn’t look to me like you can even fully support URL with this syntax? For instance, ‘@yiiframework/doc/api/1.1/CAttributeCollection#properties’ works for a URL, but won’t work for a file path - so you’re mixing two different types of “resources” (using one “alias”) that are incompatible.
The benefit of URI, is that type of resource is explicit rather than implied - “http://” clearly means it’s a web-address, while “mailto:” clearly identifies an email address, and “yii:” clearly defines an entirely different kind of resource.
The interpretation of each kind of URI is well-defined, yet fully flexible.
echo Yii::getPathOfAlias('yii:base/Component'); // => '/webroot/yii/base/Component.php'
echo Yii::getUrlOfAlias('doc:api/1.1/CAttributeCollection'); // => 'http://www.yiiframework.com/doc/api/...'
echo Yii::getPathOfAlias('components/MyClass'); // => '/webroot/app/protected/components/MyClass.php'
The last example (with no resource-type at the start) would imply a default resource-type, which might be called ‘alias’, so it would be the equivalent of, say ‘alias:components/MyClass’ - which would be interpreted at run-time the way aliases are interpreted now, searching for a root-alias, then a module, etc.
Each type of resource would need a handler of some sort - some handlers may implement an interface that Yii::getPathOfAlias() can use to obtain a path, some may implement an interface that enables Yii::getUrlOfAlias() to obtain a URL, and others might implement who-knows-what.
Providing a lower-level interface like Yii::getResource($uri) would enable you to identify a type of resource at run-time, and enable you to interact with that resource in different ways.
Other example of candidates for resources:
Images - for example, given a URI like ‘image:cat.jpg?320x200’, Yii::getUrlOfAlias() might give you ‘http://site.com/images/resized/cat_320x200.jpg’, while Yii::getPathOfAlias() might give you ‘/webroot/protected/files/images/resized/cat_320x200.jpg’.
Controllers and actions - for example, given a URI like ‘app:posts/show/4’, Yii::getUrlOfAlias() might give you ‘http://site.com/post/4-article-title’, while Yii::getPathOfAlias() might give you ‘/webroot/protected/controllers/PostController.php’.
Just throwing that out there for debate