"Installing" API with composer - php

I'm trying to use a PHP classes I downloaded, and I have no idea how to import them to my project. I've been usually using include() or require() to import classes, but it seem a little bit more complicated. This is the folder:
I've been trying to understand the composer point and I didn't understand how to include or install it in my project..
I have already downloaded this .
I'm using Xampp and developing on my windows machine. I might want to upload the final project to my web hosting (Linux) after that, and it seem that the composer just making the life harder. Anyone can help me install this API/Classes so I can use them now and later?

Related

Using "PHP Cache" without Composer

I found a PHP caching library that I'd like to use in CodeIgniter, but the docs only have instructions for installing / using with composer: http://www.php-cache.com/en/latest/
I inherited a project on a server that doesn't have Composer. Ideally I would like to use it without Composer. Does anyone have any knowledge of how to load this without it?
well, you could download the package itself and add it to your Codeignitter libraries autoload (if that's possible, sorry, dont know too much of CodeIgnitter). Though if i'd be you i'd go into Composer, it is revolutionary for php apps and you're loosing out so much by not using it... just composer init in main app folder & make sure that your CI is reading the autoloaded classes (i bet you'll find some tutorial for that)
by download I mean download and require in your php files where you're using it!

Beginner trouble understanding composer and frameworks

im having a really big problem understanding the usage of composer and frameworks.
The tutorials i have seen use some kind of online-editor so they dont really help me.
I learned about OOP etc and now i want to do the next step and learn about frameworks and composer.
I have a server and already managed to install composer. Plus i managed to install packages.
But what now? Can you tell me at a very basic level how to make use of this stuff?
I have an editor on my notebook and installed composer on my server. How do I interact with the classes?
Do i just write them and upload the file to check if it works? Do i somehow install them on my local environment? And if yes, how would i deploy my project afterwards?
I know its much but im not getting the basics of usage here :(
Thank you very much!
I watched tutorial for hours now but they always just seem to use the stuff. And i dont know how.
What you have to understand is that Composer is only a package manager, it will allow you to download some libraries (and their dependencies), and provide you an autoloader file to include on your files, so that you can use library classes.
Actually, you better install Composer on your local machine, develop your website locally, then, when it's ready, deploy it to your server.
A simple example, supposing you want to use Silex microframework.
Install Silex with composer
composer require 'silex/silex:1.3.0'
Include Silex in your script
Including Composer autoloader file
<?php
require_once './vendor/autoload.php';
$app = new Silex\Application();
?>
Develop
It's up to you, test it locally with a webserver installed on your computer.
Deploy
Deploy your website by pushing it on your webserver (with a FTP client for example).

Using composer installed library, class not found error

I used composer to download a php bitcoin library to play around with. https://github.com/phramz/php-bitcoin-api
This one specifically.
Anyways, everytime I try to use the library with
use Phramz\Bitcoin\Api\Connection\BuzzConnection;
use Phramz\Bitcoin\Api\BitcoindClient;
I get
Interface 'Phramz\Bitcoin\Api\Client' not found in
/root/vendor/phramz/php-bitcoin-api/src/Phramz/Bitcoin/Api/BitcoindClient.php
whenever I try to run any test code. I really want to play around with this library but Im sort of a newbie php programmer and this is frustrating me. Any help would be appreciated!
Make sure you require vendor/autoload.php as described in Composer documentation.
If Composer's vendor directory is not located in the current directory you'll need to use an absolute path or something like:
<?php
require_once(__DIR__."/../../vendor/autoload.php");
I had the kind of issue when I installed a new lib, and i just deployed the new lib to server only as I was new to PHP, it took me hours to figure out that the vendor/composer folder is updated when we install a new lib.
So if your server doesn't support composer install , upload the whole vendor folder to your server is the way.

Trouble installing Omnipay via Netbeans composer extension

I am currently trying to install Omnipay into my Codeigniter project. I am stuck on windows because I do not have ssh access to the box where this needs to run on. So far I have gotten a new directory in the project root that is named "vendor" and it contains a lot of empty directories referring to Symfony (for what reason is beyond me).
Then I get a runtime exception that I need to enable the openssl extension in my php to download the necessary files and this is where I am stuck at. I don't run WAMP on my computer and I just use the php.exe I downloaded to work with netbeans.
Isn't there an easier way to get omnipay to run? Like just download the files from somewhere and plug them into my project like normal? It seems to be an aweful lot of headache to get a simple library to run in my CI project.
Please forgive my ignorance towards composer but I currently see no benefit of using it for this particular project.
You can "just download" the files here: https://github.com/omnipay/common/archive/master.zip
The problem is, Omnipay depends on Guzzle (an HTTP library), and Guzzle depends on some Symfony components. So you will spend the rest of the day downloading dependencies and making sure you have all the necessary files. That is the problem Composer solves for you.
I don't have any experience running Composer on Windows, but I would start here:
http://getcomposer.org/doc/00-intro.md#installation-windows
Using the Installer
This is the easiest way to get Composer set up on your machine.
Download and run Composer-Setup.exe, it will install the latest
Composer version and set up your PATH so that you can just call
composer from any directory in your command line.
Once you have Composer installed, you should simply be able to make a file named composer.json in your project root, with the following contents:
{
"require": {
"omnipay/omnipay": "~2.0"
}
}
Then use the Command Prompt and cd to your project's directory, and run composer update to download the Omnipay files and all their dependencies.

How to install the Zend Framework offline

I have downloaded the file from Git
https://github.com/zendframework/ZendSkeletonApplication/archive/master.zip
and then unzip the file to the working directory.
i have got the error like 'Unable to load ZF2 ...'
i have downloaded the library files and pasted in vendor folder and also created the Envorinmental variable. but still the same issue.
I have come across many such issues in this forum, but no once has said about running/installing Zend OFFLINE.
Can you guys, please give an idea how to install in both windows and ubuntu
Downloading a full copy of Zend Framework 2 separately and extracting it into vendor/ZF2/library should do it. (To see if it worked see if you ended up with a file at vendor/ZF2/library/Zend/Loader/AutoloaderFactory.php.)
If not you'll need to debug a little in init_autoloader.php to see what's going on.
Doing it 'live' with Composer will make your life easier in the long run though.

Categories