Using PHP Slim Framework - php

I want to use Slim for PHP in my project for the first time.
The manual says:
Install composer in your project:
curl -s https://getcomposer.org/installer | php
Create a composer.json file in your project root:
{
"require": {
"slim/slim": "2.*"
}
}
Install via composer:
php composer.phar install
Add this line to your application’s index.php file:
<?php
require 'vendor/autoload.php';
I'm afraid, I don't get it. Where should the commands "curl" and "php" be used? I only access my webspace through Filezilla. How can I then apply such a command?
What do those steps do anyway? Sadly, the manual is not helpful at all.

See http://www.slimframework.com/install:
MANUAL INSTALL
Download and extract the Slim Framwork into your project directory and require it in your application’s index.php file. You’ll also need to register Slim’s autoloader.
<?php
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
And there are links to zip-files.

If you're getting started on slim i'd definitely suggest that you get a good IDE that will guide you through the whole process. When I started the slim framework, I came across an IDE by jetbrains called PHPStorm. It makes everything so easy by doing most of the stuff you listed for you...
download and install PHPStorm https://www.jetbrains.com/phpstorm/download/
download and install Composer https://getcomposer.org/download/ so PHPStorm can use it.
get to the part where you start PHPStorm.
go to File > new Project > Composer Project and follow the motions.
It'll create all the files you listed. Then all you have to do is look and learn what it all means.
Composer is basically a package manager, you basically open a cmd and navigate to the place you want to create you PHP Slim application and type some composer commands to install package files in that folder. Composer then gets the packages and puts them in a directory called 'vendor' in that project folder of yours.
{
"require": {
"slim/slim": "2.*"
}
}
that's basically a config file that either you or composer will create in the same file also.

Related

installing php app via composer

I wanted to install via composer given information like this
{
"name": "bitcoin app",
"require": {
"slim/slim": "2.2.0"
}
}
I am unable to recognize do I have to write this to a php file and upload to the server?
Composer is a PHP based dependency management system.
That's a snippet of a composer.json file used to get & manage initial dependencies, to use it you'll need to have PHP & Composer installed and then create a file called composer.json in the location you'd like to have the project created.
Once you'd done that run composer install to get the dependencies. This won't actually install an app persay, you'll still need to make that yourself.
Scotch.io has a decent beginners guide to Composer if you're uncertain about how to install it & what it's actually used for.
No. You should write this to a json file named composer.json.
Then use composer to install the package: composer install
1) First you need to create or found composer.json
2) Then write your code in this file
3) In last you have to update composer.

PHP framework AMPHP/THREAD used with SYMFONY - Where does it have to be installed?

I am looking to implement the framework amphp/thread, with Symfony3, which I ve read about in this article (https://www.mullie.eu/parallel-processing-multi-tasking-php/).
I'd looked at the setting process on the git page: https://github.com/amphp/thread.
I've followed the checklist:
PHP5.5+ = OK Php 5.5.12
pecl/pthread = OK I did install it as explained on Windows8
Now, 3rd task on the checklist, I have the installation of the framework itself (amphp/thread) left to do.
I am a bit confuse, because it is not an "official" Symfony bundle. So I don't think I can put it under [my_symfony_project]/vendor/ and refer to it in the file [my_symfony_project]/app/AppKernel.php. So how do one do in this case:
Do one put the directory of the library under the root directory [my_symfony_project]?
And afterwards, how can one refer to it in the Symphony class/file, should I write: "use amphp/thread" between the namespace declaration of my Symfony file and the class code itself?
You can simply install the library with composer, as example launching this command from the root of your project:
>php composer.phar require amphp/thread
And use it in your code directly: the composer process generate the correct autoloader for you. No necessary add to the list of the Symfony2 bundle (is not a bundle).
Hope this help
You will need to install the package by adding the following to your composer.json file:
"require": {
"amphp/thread": "0.8.1"
}
Then run "composer install" on your server.

Guzzle installation - Client Use

Forgive my ignorance but i've been struggling to get Guzzle to install in my project's folder.
I have installed Composer via it's .exe installer.
I have a composer.json file which contains the following:
{
"require": {
"guzzlehttp/guzzle": "~5.1"
} }
I can run 'composer update' in which it installs Guzzle.
However, it installs "Vendor" folder which has folders
'Guzzlehttp'-> 'guzzle' then is has 'build','src',tests' etc.
I want to use the Client object but the documentation says add:
'use GuzzleHttp\Client;' to the top of the PHP file but I don't actually have that file structure. Inside my guzzlehttp is just 'guzzle' or 'streams'folders.
Am I write in thinking Guzzle has not installed propperly? Or is there a different way to do it in Guzzle 5?
Many thanks for any help
You should include Composer's autoloader file which takes care of loading any Composer-installed library, the autoloader file is located in the vendor directory.
Use the following in your code :
// include Composer's autoloader
require "vendor/autoload.php";
// this should work just fine now
$resp = GuzzleHttp\get("http://stackoverflow.com");

PHP failed to load vendor folder : How to install composer on my server?

Asked Here but no proper response.
Hi, When I tried to use paypal sdk, and when I tried to submit the details, it is showing this error.
Fatal error: require(): Failed opening required '/home/wwwrapid/public_html/test/samples/vendor/paypal/paypal-merchant-sdk-php-4f570f5/lib/services/PayPalAPIInterfaceService/PayPalAPIInterfaceService.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/wwwrapid/public_html/test/merchant-sdk-php-master/samples/PPAutoloader.php on line 451
When I go through the folders path, I dont find any folder named 'vendor'.
I have been searching the solution for this for two days. Some sites say it's a composer error and installing composer solves the issue. and this is the code for that.
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
My problem is I am not able to understand what they mean? I don't even know where to add this code? I mean in which file? How can that composer be installed on my site?
If you're on Windows the easiest thing to do is download the Windows installer and use it.
In order for Composer to install, though, you're going to need PHP installed. The easiest way to do this is to just configure a local server setup using WAMP or something similar. You'll need do that prior to installing Composer.
Once all of that is done you'll be able to utilize Composer to manage PHP packages within your projects. It's really pretty awesome stuff, but it can be a little confusing if you've never worked with it before.
Basically, once it's installed, you can just create a composer.json file at your project root. This file is basically a config file that tells Composer what PHP packages you want to use (among other things.)
For PayPal's SDK you could setup a composer.json file with nothing but this in it:
"require": {
"php": ">=5.3.0",
"ext-curl": "*",
"ext-json": "*",
"paypal/rest-api-sdk-php" : "0.5.*"
}
Then, from the command line, you can browse to the project root (where the composer.json file is) and run "composer update".
This would look at the composer.json file and download any/all packages that are required based on that line. In this case it would be pulling in the PayPal REST API SDK, and then all of the samples that PayPal provides would work for you.
Composer is what creates that /vendor directory and sets up an autoloader for you. Hope that helps.

where do I put composer.json

I have installed composer.
My project dir tree looks something like this
/home/myproject/public_html/myproject.com
I initially installed it in:
/home/myproject/public_html/myproject.com/bin/composer/
But later moved it to:
/home/myproject/usr/local/bin/composer
Questions:
Where to I create composer.json ?
In the official docs they mention that in order to install new packages I need to write a require key in the json format in that file, does this mean that I dont have to upload the package through ftp?
The docs further say that I can simply install dependencies like ths:
php composer.phar install
I dont understand the workflow of this process (im fairly new).. what exactly do I need to do to get some packages going (like Respect)
Composer has 2 basic elements for you to consider:
The composer.php file itself - this can be located anywhere on your system - usually it is convenient to have it in you search path so you can invoke it by name (no path) from the command line.
Composer.json - this file is the configuration for your project. This is usually best located at the top level of your project. Ideally this is a directory outside the scope of your web server - so that it will never be exposed or served.
Symfony2 has some great documentation and examples of composer in use.
Also be aware that some packages you reference via composer will themselves have composer files - to ensure they match your required dependancies - and they may also have their own dependancies that need to be considered.
I would install composer.json in the following
/home/myproject/composer.json
It would be out of scope of the web server and could be used to manage many assets e.g.
public_html/
libs/
config/
docs/
vendor/
Where to I create composer.json ?
You should create composer.json to your project root like /home/myproject/public_html/myproject.com/composer.json. If all files of your application live inside your myproject.com folder.
In the official docs they mention that in order to install new
packages I need to write a require key in the json format in that
file, does this mean that I dont have to upload the package through
ftp?
Yes as long as you're not in shared hosting because most of them don't allow CLI (SSH).
The docs further say that I can simply install dependencies like this
php composer.phar install
Yes you can simple type the above command and composer.json will install the latest version of your package.
Composer.json (Respect Package)
{
"require": {
"respect/validation": "dev-master"
}
}
Now run composer install will install the require package.
For further packages
{
"require": {
"respect/validation": "dev-master",
"doctrine/orm": "2.*"
}
}
Now run update composer update it will download the doctrine/orm as well.

Categories