Is it possible to migrate this to PSR-4
I know that you guys are using some tool like swagger for code generator, but is it possible to create a new tag/version with psr-4 autoloader. It is much more easier and beautiful for reading when you have code like:
<?php
use Google\Service\CloudTalentSolution;
class Service
{
private function someMethod()
{
$talentClient = new CloudTalentSolution($client);
}
}
Any status for this @mattwhisenhunt or @JustinBeckwith? I'd love to have this since it will make our code cleaner.
It remains on our agenda, but unfortunately I don't have an ETA for it yet.
Migrating to PSR-4 will fix another problem -- huge autoload files:
$ cat >composer.json <<EOF
> {
> "name": "test/test",
> "type": "project",
> "require": { "google/apiclient": "^2.2" },
> "config": {
> "optimize-autoloader": true,
> "preferred-install": "dist"
> }
> }
> EOF
$ composer install --no-ansi --no-interaction --no-progress --no-suggest --no-dev
Loading composer repositories with package information
Updating dependencies
Package operations: 13 installs, 0 updates, 0 removals
- Installing ralouphie/getallheaders (3.0.3): Downloading (100%)
- Installing psr/http-message (1.0.1): Loading from cache
- Installing guzzlehttp/psr7 (1.6.1): Downloading (100%)
- Installing guzzlehttp/promises (v1.3.1): Loading from cache
- Installing guzzlehttp/guzzle (6.3.3): Loading from cache
- Installing phpseclib/phpseclib (2.0.21): Downloading (100%)
- Installing psr/log (1.1.0): Loading from cache
- Installing monolog/monolog (1.24.0): Loading from cache
- Installing firebase/php-jwt (v5.0.0): Loading from cache
- Installing google/apiclient-services (v0.111): Downloading (100%)
- Installing psr/cache (1.0.1): Loading from cache
- Installing google/auth (v1.5.2): Downloading (100%)
- Installing google/apiclient (v2.2.4): Downloading (100%)
Writing lock file
Generating optimized autoload files
$ du -sch vendor/google/apiclient-services/src/Google/Service/* | grep -v '.*\.php' | sort -h -k1,1 | tail
744K vendor/google/apiclient-services/src/Google/Service/Dataflow
756K vendor/google/apiclient-services/src/Google/Service/CloudSearch
904K vendor/google/apiclient-services/src/Google/Service/DLP
956K vendor/google/apiclient-services/src/Google/Service/Sheets
1.1M vendor/google/apiclient-services/src/Google/Service/YouTube
1.3M vendor/google/apiclient-services/src/Google/Service/ShoppingContent
1.6M vendor/google/apiclient-services/src/Google/Service/Dfareporting
1.7M vendor/google/apiclient-services/src/Google/Service/Vision
3.7M vendor/google/apiclient-services/src/Google/Service/Compute
49M total
$ du -sch vendor/composer/* | sort -h -k1,1
1.0K vendor/composer/autoload_namespaces.php
4.0K vendor/composer/autoload_files.php
4.0K vendor/composer/autoload_psr4.php
4.0K vendor/composer/autoload_real.php
4.0K vendor/composer/LICENSE
16K vendor/composer/ClassLoader.php
28K vendor/composer/installed.json
1.5M vendor/composer/autoload_classmap.php
1.6M vendor/composer/autoload_static.php
3.2M total
These 3.2Mb of autoload files are loaded into memory on every processed request despite we need only one service.
I would also really like to see this. More and more frameworks are moving to automated PSR-4 loading and the fact that this library has no namespace of it's own is silly.
Please add PSR-4 support, not only for making our code prettier but making it faster
The Client is now PSR-4 compliant. Migrating this lib to PSR-4 would be great for homogeneity of the code...
$googleClient = new Google\Client();
$youtubeService = new \Google_Service_YouTube($googleClient); // Curent
$youtubeService = new Google\YouTube\Service($googleClient); // PSR-4
https://github.com/googleapis/google-api-php-client/pull/1937
2.5 years later and this is still open? Is this still on your agenda?
I do hope someone is working on it, since Composer 2 will not autoload PSR-0 style classes anymore, hence possibly breaking library usage on a modern web application...
This has been merged in #363 and tagged in v0.200.0! You can receive this update immediately by running composer update!