Create project laravel with composer [ERROR] - laravel

I am trying to create a new project with composer laravel, but I get this error, as could fix it ??
Note: I installed the .exe installer composer

Looks like you need to add a parameter your global composer.json file. On UNIX it's located in ~/.composer/composer.json .
Open up that file and add this:
"secure-http": false
My whole composer.json file looks like this:
{
"require": {
"laravel/installer": "^1.3"
},
"secure-http": false
}
Since you're using Windows, you'll need to find where this file is.

Related

Can't require_once fdpf/fpdf.php

I am using the FPDI library from JanSlabon for securing PDF file uploads from my laravel app. But I can't execute the code require_once even though I navigated to the file itself. I am getting the error:
Failed opening required '../../vendor/setasign/fpdf/fpdf.php' (include_path='.:/usr/local/Cellar/php/7.3.4/share/php/pear')
My require code is:
require_once('../../vendor/setasign/fpdf/fpdf.php');
require_once('../../vendor/setasign/fpdi/src/autoload.php');
When the libraries are already located in your vendor folder, you should simply make use of the autoload.php file of composer (doesn't laravel uses this by default?).
So just add the dependencies to your composer.json (if not already done):
"require": {
"setasign/fpdf": "^1.8",
"setasign/fpdi": "^2.2",
"setasign/fpdi-protection": "^2.0"
}
Update via composer update and:
<?php
use setasign\FpdiProtection\FpdiProtection;
require_once('vendor/autoload.php');
$pdf = new FpdiProtection();
...
Your relative path ../../ to vendor is probably wrong. To avoid this issue, use the Laravel base_path() helper which will provide an absolute path.
require_once(base_path('vendor/setasign/fpdf/fpdf.php'));
require_once(base_path('vendor/setasign/fpdi/src/autoload.php'));
You can autoload using composer.json. First of all, create a directory called Custom in app directory and copy fpdi directory to app/Custom.
Now in autoload section of your composer.json file, require the file. After requiring the file, your composer.json file's autoload block should look like this if it is a fresh Laravel app:
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
],
"files": [
"app/Custom/fpdi/FPDI_Protection.php"
]
},
After updating your composer.json file, run composer dumpautoload. Now you can utilize the classes in your Laravel controllers or models without requiring the files manually.
While doing tests, I see that this library uses some deprecated methods and so on. You will have to deal with it, i.e. update the code to suite your needs. But I hope that this answer will help you in a way that you will be able to use any other library as well. Do a Google search and find a more modern library if this one's fixes are too broad.

composer.json: change the vendor-dir dynamically through a script

In a project using Composer, shared by many developers and environments, I need to have the vendor-dir config parameter of composer.json to be set dynamically. That is, a script that runs when composer install/update is launched, must be able to change the value of this entry:
//composer.json
"config": {
"vendor-dir": "/var/www/html/......",
I tried the following:
//composer.json
"scripts": {
"pre-install-cmd": "MyBundle\\Composer\\Hook::setVendorDir",
The class Hook has this method:
//MyBundle/Composer/Hook.php
public static function setVendorDir(Event $event)
{
// ... some code set the $vendorDir variable here depending on many thing
$event->getComposer()->getConfig()->merge([
'config' => [
'vendor-dir' => $vendorDir
]
]);
// ...
}
The result is that the file autoloader.php and a composer folder are created in the right vendor directory, but all other packages are still installed in the default vendor directory!
The composer folder I mentioned only contains some PHP files (ClassLoader.php, _autoload\_*.php_, and LICENSE)
Notice: When I change the vendor-dir parameter in composer.json, it works flawlessly.
How may I set vendor-dir dynamically and have it taken into account for every package installations?
You can e.g. write a batch script (Windows) or bash script (Linux) or even a PHP script which you run instead of composer install. The script sets the correct vendor-dir in the composer.json and then runs composer install or whatever.
To set vendor dir just run in your script:
composer config vendor-dir /your/path/to/your/vendor/dir
For more info about composer config see the Composer documentation.

Laravel : best place to create a composer package

I'm going to create my first laravel based composer package . also github for windows is installed . laravel is located in :
E:\xampp\htdocs\pnu
as i need to test my package with laravel during the development(check relational paths , error debugging) where is the best place to create package root folder ?
There is no default location for this. Lets say your packages is called HelloWorld, than you can put your package here:
E:\xampp\htdocs\pnu\packages\Alex\Helloworld
And then add this to your composer file (composer.json in root directory):
"autoload": {
"psr-4": {
"Alex\\Helloworld\\": "packages/Alex/Helloworld/src"
}
},
You can read more about this here https://laracasts.com/discuss/channels/tips/developing-your-packages-in-laravel-5.

Composer: nothing to install or update

I want install this.
I installed composer, set the environment variable path in w10.
Edit the composer.json located in this folder:
C:\Bitnami\wampstack-5.5.29-1\php\PEAR
with this content:
{
"name":"amazonwebservices/aws-sdk-for-php",
"description":"AWS SDK for PHP",
"keywords":["aws","amazon","sdk","s3","ec2","dynamodb"],
"type":"library",
"license":"Apache-2.0",
"authors":[
{
"name":"Amazon Web Services",
"homepage":"http://aws.amazon.com"
}
],
"homepage": "http://aws.amazon.com/sdkforphp/",
"require":{
"php":">=5.2.0"
},
"autoload":{
"classmap": [
"authentication/",
"extensions/",
"lib/",
"services/",
"utilities/",
"sdk.class.php"
]
}
}
{
"require": {
"katzgrau/klogger": "dev-master"
}
}
but when I execute this command in my console:
composer require katzgrau/klogger:dev-master
I get:
nothing to install or update
what I did wrong?
You are reusing the composer.json file of "aws-sdk-for-php".
That is probably not your project. And you are in the wrong folder (PEAR).
Don't copy and paste composer.json files... anyway:
Create a new project folder
then simply run composer require katzgrau/klogger:1.2.0
You'll get all dependencies fetched into the vendor folder and a fresh composer.json file for your project.

Composer autoload path not working

I have this script that use composer to setup the project but for some reasons does not work
<?php
include_once 'vendor/autoload.php';
use \LeagueWrap\Api;
$api = new Api($key = "somekey"); // Load up the API
$summoner = $api->summoner(); // Load up the summoner request object.
$bakasan = $summoner->info('bakasan'); // Get the information about this user.
$bakasan = $summoner->info(74602); // same thing as above, just to show that an id will wo$
echo $bakasan->summonerLevel; // 30
echo $bakasan->id; // 74602
echo $bakasan->name; // "bakasan"
echo $bakasan->profileIconId; // 24
echo $bakasan->revisionDate; // 1387391523000
echo $bakasan->revisionDateStr; // "12/18/2013 06:32 PM UTC"
?>
you can check here http://70.37.98.151/leaguewrap/tests/test2.php the error I get
Warning: include_once(vendor/autoload.php): failed to open stream: No such file or directory in /var/www/html/leaguewrap/tests/test2.php on line 3
my composer.json is
{
"name": "paquettg/leaguewrap",
"type": "library",
"description": "A wrapper for the League of Legends API.",
"version": "0.6.2",
"keywords": ["League", "legends", "wrap", "api", "facade", "proxy"],
"homepage": "https://github.com/paquettg/leaguewrap",
"license": "MIT",
"authors": [
{
"name": "Gilles Paquette",
"email": "paquettg#gmail.com",
"homepage": "http://gillespaquette.ca"
}
],
"require": {
"php": ">=5.4",
"guzzlehttp/guzzle": "4.0.*"
},
"require-dev": {
"phpunit/phpunit": "3.7.*",
"mockery/mockery": "0.8.*",
"satooshi/php-coveralls": "0.6.*"
},
"autoload": {
"psr-0": {
"LeagueWrap": "src/"
}
},
"minimum-stability": "dev"
}
and here folders tree
Your script cannot find the autoload file.
Including that file is like any other file: The path must be right, and which path is right depends on whether you are using an absolute path (unusual) or a relative path. Currently you are using a relative path.
Assuming your script is somewhere inside that src folder you showed, the path to the vendor/autoload.php must at least contain one ../ to go one directory level up - maybe more.
Seems like its the problem with your Composer Installation.
Follow these steps -
First make sure you have the Composer.json file created with all the dependencies.
Let's say you are creating a project, and you need a library that does logging. You decide to use monolog. In order to add it to your project, all you need to do is create a composer.json file which describes the project's dependencies.
{
"require": {
"monolog/monolog": "1.2.*"
}
}
Installation - Linux / Unix / OSX
Downloading the Composer Executable
There are in short, two ways to install Composer. Locally as part of your project, or globally as a system wide executable.
Locally
Installing Composer locally is a matter of just running the installer in your project directory:
curl -sS https://getcomposer.org/installer | php
Note: If the above fails for some reason, you can download the installer with php instead:
php -r "readfile('https://getcomposer.org/installer');" | php
The installer will just check a few PHP settings and then download composer.phar to your working directory. This file is the Composer binary. It is a PHAR (PHP archive), which is an archive format for PHP which can be run on the command line, amongst other things.
You can install Composer to a specific directory by using the --install-dir option and providing a target directory (it can be an absolute or relative path):
curl -sS https://getcomposer.org/installer | php -- --install-dir=bin
Globally
You can place this file anywhere you wish. If you put it in your PATH, you can access it globally. On unixy systems you can even make it executable and invoke it without php.
You can run these commands to easily access composer from anywhere on your system:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
Note: If the above fails due to permissions, run the mv line again with sudo.
Note: In OSX Yosemite the /usr directory does not exist by default. If you receive the error "/usr/local/bin/composer: No such file or directory" then you must create /usr/local/bin/ manually before proceeding.
Then, just run composer in order to run Composer instead of php composer.phar.
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.
Note: Close your current terminal. Test usage with a new terminal: That is
important since the PATH only gets loaded when the terminal starts.
Manual Installation#
Change to a directory on your PATH and run the install snippet to download composer.phar:
C:\Users\username>cd C:\bin
C:\bin>php -r "readfile('https://getcomposer.org/installer');" | php
Note: If the above fails due to readfile, use the http url or enable php_openssl.dll in php.ini
Create a new composer.bat file alongside composer.phar:
C:\bin>echo #php "%~dp0composer.phar" %*>composer.bat
Close your current terminal. Test usage with a new terminal:
C:\Users\username>composer -V
Composer version 27d8904
Using Composer
We will now use Composer to install the dependencies of the project.
To resolve and download dependencies, run the install command:
php composer.phar install
If you did a global install and do not have the phar in that directory run this instead:
composer install
Following the example above, this will download monolog into
the vendor/monolog/monolog directory.
Autoloading
Besides downloading the library, Composer also prepares an autoload file that's capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process:
require 'vendor/autoload.php';
You can also try with below require form -
defined('__ROOT__') or define('__ROOT__', dirname(dirname(__FILE__)));
require_once implode(
    DIRECTORY_SEPARATOR, array(__ROOT__, 'vendor', 'autoload.php')
);

Resources