[GH-ISSUE #92] Using this API without Composer #48

Closed
opened 2026-02-27 19:25:46 +03:00 by kerem · 2 comments
Owner

Originally created by @celsowhite on GitHub (Jul 10, 2017).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/92

Hi, I'd love to use this API just by installing the src files within my Wordpress theme. Getting composer setup with WP is a bit of a headache and I'd rather just include the files manually. Do you have recommendations for doing so?

Right now I'm doing:

require_once('Request.php');
require_once('Session.php');
require_once('SpotifyWebAPI.php');
require_once('SpotifyWebAPIException.php');
Originally created by @celsowhite on GitHub (Jul 10, 2017). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/92 Hi, I'd love to use this API just by installing the src files within my Wordpress theme. Getting composer setup with WP is a bit of a headache and I'd rather just include the files manually. Do you have recommendations for doing so? Right now I'm doing: ``` require_once('Request.php'); require_once('Session.php'); require_once('SpotifyWebAPI.php'); require_once('SpotifyWebAPIException.php'); ```
kerem 2026-02-27 19:25:46 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jwilsson commented on GitHub (Jul 10, 2017):

Hi!
I'd recommend using a autoloader but making sure you only include the classes for SpotifyWebAPI with that (in case some plugin are using autoloaders too).

Quick, untested, example:

spl_autoload_register(function ($class) {
    if (strpos($class, 'SpotifyWebAPI') !== false) {
        $path = path_join(get_stylesheet_directory(), '/classes/' . $class);

        require_once $path;
    }
});

You might run in to some trouble with other plugins registrering autoloaders too, though.

Your approach will work (I highly doubt we'll add any new files in the near future, causing something to break) but I highly recommend you to use an autoloader.

Hope this works!

<!-- gh-comment-id:314191594 --> @jwilsson commented on GitHub (Jul 10, 2017): Hi! I'd recommend using a [autoloader](http://php.net/manual/en/function.spl-autoload-register.php) but making sure you only include the classes for `SpotifyWebAPI` with that (in case some plugin are using autoloaders too). Quick, untested, example: ```php spl_autoload_register(function ($class) { if (strpos($class, 'SpotifyWebAPI') !== false) { $path = path_join(get_stylesheet_directory(), '/classes/' . $class); require_once $path; } }); ``` You might run in to some trouble with other plugins registrering autoloaders too, though. Your approach will work (I highly doubt we'll add any new files in the near future, causing something to break) but I highly recommend you to use an autoloader. Hope this works!
Author
Owner

@celsowhite commented on GitHub (Jul 11, 2017):

Thanks @jwilsson! I'll give autoloader a try. My approach did end up working but I see the advantage of the autoloader.

Great wrapper. Thanks for the work.

<!-- gh-comment-id:314414688 --> @celsowhite commented on GitHub (Jul 11, 2017): Thanks @jwilsson! I'll give autoloader a try. My approach did end up working but I see the advantage of the autoloader. Great wrapper. Thanks for the work.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#48
No description provided.