You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "artem antonenko (JIRA)" <ji...@apache.org> on 2016/04/19 00:04:25 UTC
[jira] [Commented] (THRIFT-3046) Allow PSR4 class loading for
generated classes (PHP)
[ https://issues.apache.org/jira/browse/THRIFT-3046?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15246649#comment-15246649 ]
artem antonenko commented on THRIFT-3046:
-----------------------------------------
As was discussed in THRIFT-3776 there're 3 languages that don't support multiple IDL files with the same namespace - Go, PHP and Perl. It's because they write all types in the same file. Multiple calls to thrift compiler will overwrite that file. All other generators work because they put everything into it's own file. Go was fixed in THRIFT-3776. Looks like patch to this issue will also fix PHP.
[~fduch], may be it would be better to submit a PR on Github for this instead of a patch so that it would go throught the tests? That would definitely bring more attention to this change. Also, because every other generator puts everything into it's own file, may be it should be default setting for PHP also? And if it's really needed make current behaviour as a separate option?
My goal here is to make every language generator work the same way. They should all work with multiple IDLs with the same namespace and produce every type in it's own file by default. Or, at least, generate one file (header/source pair) for every IDL file. As it is now, only PHP and Perl don't work that way.
> Allow PSR4 class loading for generated classes (PHP)
> ----------------------------------------------------
>
> Key: THRIFT-3046
> URL: https://issues.apache.org/jira/browse/THRIFT-3046
> Project: Thrift
> Issue Type: New Feature
> Components: PHP - Compiler, PHP - Library
> Affects Versions: 0.9.2
> Reporter: Alex Medvedev
> Attachments: php-compiler-psr4-option.patch
>
>
> Nowadays thrift PHP library contains it's own class loader lib/php/lib/Thrift/ClassLoader/ThriftClassLoader.php for loading of generated classes. This loader is based on psr0 approach and combines it with some thrift specialties like locating all the structs and exceptions in Types.php file and all the service classes (processor, interface, rest handler, *_args and *_result) in single service file.
> These points make thrift class loading not so flexible:
> 1. It is not possible to use advantages of psr4 autoloading. For example we cannot omit first part of class namespace inside procedure of translating namespace to file system paths. It can be useful when we are locating generated client classes in some vendor package inside the application.
> 2. This approach makes impossible to use all the power of Composer class loader (except the case when we providing preliminarily prepared classmap for the thrift classes) to load classes and forces to register ThriftClassLoader each time when we use generated classes.
> The patch attached allows generation of all the PHP classes in separate files in case of 'psr4' option is provided. Such generated classes can be loaded with standard composer (or any other psr4-compatible) class loader.
> Because of big amount of *_args and *_result classes thrift compiler with psr4-option generates significant amount of files. Nevertheless we can consider refactoring (omiting) of these classes in separate PR (may be we can implement java-style approach there).
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)