phpSPO icon indicating copy to clipboard operation
phpSPO copied to clipboard

Using phpSPO without Composer?

Open dotjsprogrammer opened this issue 6 years ago • 7 comments

Hi, is it possible to use this API without Composer? I'm trying to write PHP applications for our intranet and we're thinking of using our SharePoint credentials so that everyone can just use the same login they use for our Office365 accounts. I tried uploading the files and doing the includes but it's giving me a 500 error looking for some Composer-related files. Thanks for any assistance, this is all new to me.

dotjsprogrammer avatar Jul 20 '17 13:07 dotjsprogrammer

Composer is not necessary for phpSPO itself. You could install Composer on your PC 😉 Load the whole project and upload the autoload.php / vendor folder.

Error 500? Did you viewed the Server log?

ghost avatar Jul 20 '17 13:07 ghost

Yes, I did this: require_once('vendor/autoload.php');

And this is what the error log is saying: [Wed Jul 19 15:15:50 2017] [error] [client 192.168.80.76] PHP Warning: require_once(/var/www/spotest/vendor/composer/autoload_real.php): failed to open stream: No such file or directory in /var/www/spotest/vendor/autoload.php on line 5, referer: http://office.mwmgmt.local/spotest/vendor/ [Wed Jul 19 15:15:50 2017] [error] [client 192.168.80.76] PHP Fatal error: require_once(): Failed opening required '/var/www/spotest/vendor/composer/autoload_real.php' (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/spotest/vendor/autoload.php on line 5, referer: http://localhost/spotest/vendor/

dotjsprogrammer avatar Jul 20 '17 13:07 dotjsprogrammer

Fastest way: Install composer on your local PC. Use it to download the phpSPO files.

  • Composer will download the whole project. (you will get a working autoload.php in vendor folder with phpSPO),
  • Upload the vendor folder (with autoload.php and phpSPO project).
  • Include the autoload.php again :-)

ghost avatar Jul 20 '17 14:07 ghost

Install all the dependencies on local and push the /Vendor folder to your production server then include the autoload.php and Baym!

ayimdomnic avatar Jul 20 '17 14:07 ayimdomnic

Now I'm getting this error:

Installation failed, reverting ./composer.json to its original content.

[Composer\Downloader\TransportException] Your configuration does not allow connections to http://packagist.org/packages.json. See https://getcomposer.org/do c/06-config.md#secure-http for details.

What do you mean by dependencies? Is there a way where I can download them off somewhere and simply package that with the phpSPO files? My apologies, I'm coming from a WordPress development background so find these dependencies/Composer stuff confusing as it's all new to me.

dotjsprogrammer avatar Jul 20 '17 15:07 dotjsprogrammer

Sorry to necropost, but I noticed the original question was never answered and I'm in the same situation.

I have no interest in using composer. I downloaded the entire package directly. All of the instructions reference composer and autoload fails because it's expecting composer.

Is there a list of required files by function somewhere? Even in the example files it references the broken autoload.php stuff.

Everynameistakenalready avatar Dec 19 '18 16:12 Everynameistakenalready

@Everynameistakenalready make a simple autoloader and include it in your project.

e.g. create a file called autoloader.php and place it in the src folder. Use the content below.

<?php
if (defined("PHP_SPO_BASE_PATH") === false) {
	define("PHP_SPO_BASE_PATH", __DIR__ . DIRECTORY_SEPARATOR);
	spl_autoload_register(function($className) {
		if (class_exists($className) === false) {
			$cPath	= array_values(array_filter(explode("\\", $className)));
			if (
				$cPath[0] == "Office365" 
				&& $cPath[1] == "PHP"
				&& $cPath[2] == "Client"
			) {
				$cPath		= array_slice($cPath, 3);
				$fileName	= array_pop($cPath);
				$filePath	= PHP_SPO_BASE_PATH;
				foreach($cPath as $c) {
					$filePath	.= $c . DIRECTORY_SEPARATOR;
				}
				$filePath	.= $fileName . ".php";
				if (is_readable($filePath) === true) {
					require_once $filePath;
				}
			}
		}
	});
}

when you need phpSPO:

require_once "/some/path/to/phpSPO/autoloader.php";

merlinthemagic avatar Jul 29 '19 10:07 merlinthemagic