Composer update not reflecting repository changes - php

I have the follow composer.json
{
"name": "mjohnson/transit",
"type": "library",
"description": "A file uploader, validator, importer and transformer library.",
"keywords": [
"transit", "file", "uploader", "validator", "importer", "transformer", "transporter",
"image", "audio", "video", "text", "application", "archive", "s3", "glacier"
],
"homepage": "http://milesj.me/code/php/transit",
"license": "MIT",
"authors": [
{
"name": "Miles Johnson",
"homepage": "http://milesj.me"
}
],
"require": {
"php": ">=5.3.0",
"ext-curl": "*",
"ext-mbstring": "*",
"aws/aws-sdk-php": "2.0.*"
},
"support": {
"source": "https://github.com/milesj/php-transit"
},
"autoload": {
"psr-0": { "Transit": "src/" }
}
}
when I run a composer update the source code is not updated to reflect current repository: https://github.com/milesj/transit
I tried to delete lock file whitout success. Tried composer [update|install}
For instance, my current (local) code:
src/Transit/File.php:
[...]
public function __construct($path) {
if (!file_exists($path)) {
throw new IoException(sprintf('%s does not exist', $path));
}
$this->_path = $path;
}
[...]
current repository code:
[...]
public function __construct($path) {
if (is_array($path)) {
if (empty($path['tmp_name'])) {
throw new IoException('Passing via array must use $_FILES data');
}
$this->_data = $path;
$path = $path['tmp_name'];
}
if (!file_exists($path)) {
throw new IoException(sprintf('%s does not exist', $path));
}
$this->_path = $path;
// #version 1.3.2 Rename file to add ext if ext is missing
if (!$this->ext()) {
$this->rename();
}
// #version 1.4.0 Reset the cache
$this->_cache = array();
}
[...]

You have the wrong composer.json. The one you mention is for the library named "mjohnson/transit" - if you are not developing this exact software, then this is wrong.
You should create a new composer.json file containing at least this line:
{ "require": { "mjohnson/transit" : "*" } }
Then run composer install.
I do not know what you did to get that composer.json file, but if you originally cloned that other repository, and now edit that file, things will break! Backup your code if any. Try to undo what you did wrong without undoing your own code.

Related

Fatal error when instanciating Pusher - Can't find class

I have a project to test and play around, with the following structure:
app/
controllers/
HomeController.php
handlers/
models/
vendor/
composer/
psr/
pusher/
pusher-php-server/
src/
Pusher.php
PusherException.php
PusherInstance.php
tests/
composer.json
autoload.php
index.php
I tried to require the Pusher autoloader in my index file:
require 'vendor/autoload.php';
Which is the following:
// autoload.php #generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInite16b90ab01042d2a69b1d54243c9e23a::getLoader();
Now, in my HomeController.php, I have the following code:
namespace App\controllers;
use \App\handlers\Views as View;
use \App\models\Home_model as Home;
use \App\controllers\SessionController;
use \Pusher\Pusher as Pusher;
class HomeController {
private $pusher;
public function __construct() {
$options = array(
'cluster' => 'hmm',
'encrypted' => true
);
$this->pusher = new Pusher(
'secret',
'secret',
'secret',
$options
);
}
public function index() {
$data['message'] = 'hello world';
$this->pusher->trigger('my-channel', 'my-event', $data);
return $this->view->render('views/home/index.php');
}
}
But this returns me an error:
Fatal error: Class 'Pusher\Pusher' not found in
And I'm not sure what I'm doing wrong. Could someone explain me what I'm doing wrong?
In composer.json I get the following:
{
"name": "pusher/pusher-php-server",
"description" : "Library for interacting with the Pusher REST API",
"keywords": ["php-pusher-server", "pusher", "rest", "realtime", "real-time", "real time", "messaging", "push", "trigger", "publish", "events"],
"license": "MIT",
"require": {
"php": "^5.4 || ^7.0",
"ext-curl": "*",
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8 || ^5.7"
},
"autoload": {
"psr-4": {
"Pusher\\": "src/"
}
},
"autoload-dev": {
"psr-4": { "": "tests/" }
},
"config": {
"preferred-install": "dist"
},
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
On Github, they mention that the library depends on cURL and JSON modules.
Not realy sure if this has something to do with my issue?
I'm still stuck, so any help is greatly appreciated.
Also, I'm using a .htaccess file, to rewrite my urls.
I have managed your code to work with right composer.json next to index.php:
{
"name": "awesome/project",
"type": "project",
"license": "MIT",
"authors": [
{
"name": "Author",
"email": "author#gmail.com"
}
],
"autoload": {
"psr-4": {
"": ""
}
},
"require": {
"pusher/pusher-php-server": "dev-master"
}
}
Then just run composer install.
My index.php contents:
<?php
require 'vendor/autoload.php';
use app\controllers\HomeController;
$ctrl = new HomeController();

PSR4 not working

I have setup a folder structure like this for a package of legacy classes
vendorname/legacy/src/ClassA.php
namespace Vendorname\Legacy;
class ClassA{}
vendorname/legacy/src/Folder/Class2.php
namespace Vendorname\Legacy\Folder;
class FolderClass2{}
With composer I'm loading this from a github repo like this:
"repositories": [
{
"type": "vcs",
"url": "git#bitbucket.org:username/vendorname-legacy-classes.git"
}
],
"require": {
"vendorname/legacy": "master#dev"
}
When I load ClassA like this it works:
use Vendorname\Legacy\ClassA;
$a = new ClassA();
However none of my subfolder'd classes work:
use Vendorname\Legacy\Folder\FolderClassB;
$b = new FolderClassB();
Class 'Vendorname\\Legacy\\Folder\\FolderClassB' not found
I have already defined the source folder with a file vendor\vendorname\composer.json
{
"name": "vendorname/legacy",
"description": "Vendorname Legacy classes",
"require": {
"php": ">=5.3.0"
},
"autoload": {
"psr-4": {
"Vendorname\\Legacy\\": "src"
}
},
"extra": {
"branch-alias": {
"master": "master"
}
}
}
you need to define one thing more to your composer.json
{
"autoload": {
"psr-4": {"Vendorname\\Legacy\\": "vendorname/legacy/src/"}
}
}

Composer & Parsedown - Class 'UserFrosting\\Parsedown' not found

I managed to install Parsedown using composer with
"require": {
...
"erusev/parsedown": "^1.6"
},
and added the class path to the autoload section
"autoload": {
"classmap" : [
"controllers", "middleware", "models", "plugins", "vendor/erusev/parsedown"
]
}
But when I try to execute this line...
$Parsedown = new Parsedown();
... I end up with this error:
Class 'UserFrosting\Parsedown' not found
Running php composer.phar dump-autoload did not help.
What am I missing here? Why Parsedown is expected under UserFrosting - UserFrosting\Parsedown?
Here is the full composer.json:
{
"name": "userfrosting/UserFrosting",
"type": "project",
"description": "A secure, modern user management system for PHP.",
"keywords": ["php user management", "usercake", "bootstrap"],
"homepage": "https://github.com/userfrosting/UserFrosting",
"license" : "MIT",
"authors" : [
{
"name": "Alexander Weissman",
"homepage": "https://alexanderweissman.com"
}
],
"require": {
"birke/rememberme" : "1.0.4",
"illuminate/database" : "5.0.33",
"league/csv": "8.1.*",
"nikic/php-parser" : "~1",
"php" : ">=5.4.0",
"phpmailer/phpmailer" : "5.2.10",
"twig/twig" : "~1.0",
"slim/slim" : "2.*",
"slim/views" : "0.1.3",
"userfrosting/fortress" : "1.*",
"wikimedia/composer-merge-plugin": "~1",
"components/highlightjs": "9.8.0",
"aws/aws-sdk-php": "3.*",
"erusev/parsedown": "^1.6"
},
"extra": {
"merge-plugin": {
"include": [
"plugins/*/composer.json"
],
"recurse": true,
"replace": false,
"merge-dev": true,
"merge-extra": false
}
},
"autoload": {
"classmap" : [
"controllers", "middleware", "models", "plugins", "vendor/erusev/parsedown"
]
}
}
Looks like you are trying to execute this line of code $Parsedown = new Parsedown(); in a class with namespace UserFrosting.
Either add a use block at the top of your php file, like this: use Parsedown; (this should come after namespace declaration), or type a backslash before the class name when you are using it, like so: $Parsedown = new \Parsedown();. The latter will start looking for this class in a root namespace.
You don't need to add this class to your autoload classmap section of composer.json file. If a package is pulled by composer, the composer will automatically add everything to autoloader after running dump-autoload.

500 server error while using Symfony class

Im trying to run Symfony Crawler in my script, but when I try to do that, I get 500 server error. Where is the problem? The code:
use Symfony\Component\DomCrawler\Crawler;
class Yt_downloader
{
private $__parser;
private $__uri;
public function __construct($cfg)
{
$this->__parser = new Crawler();
if ( is_array($cfg) ) {
foreach ( $cfg as $key => $value ) {
$this->{$key} = $value;
}
}
}
public function test()
{
print_r($this->__uri);
}
}
and the action:
require_once APPPATH . 'libraries/Yt_downloader.php';
$downloader = new Yt_downloader(array(
'__uri' => 'https://www.youtube.com/watch?v=...'
));
btw, my composer.json:
{
"name": "project",
"description": "",
"license": "MIT",
"require-dev": {
"symfony/css-selector": "~2.8|~3.0"
},
"suggest": {
"symfony/css-selector": ""
},
"autoload": {
"psr-4": { "Symfony\\Component\\DomCrawler\\": "" }
},
"minimum-stability": "dev",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
}
}
this is being used in Codeigniter project. I thought it can be composer problem, but when I try to use different library it works. I think there is a problem with namespaces or something. Maybe I can see log anywhere? I use ubuntu..
You need to require
"symfony/dom-crawler": "~2.8|~3.0"
In your composer.json file so that the crawler component is installed

Composer doesnt update autoload namespace

Composer not updating autoload_namespaces.php file, despite downloading package normaly. Can't understand where i did a mistake.
If i load something from packagist, namespaces file updating successfully.
Project structure
Main Composer.json
{
"repositories":[
{
"type": "package",
"package": {
"name": "test/framework",
"version": "1.0.0.1",
"dist": {
"url": "http://localhost/repo/1.zip",
"type": "zip"
}
}
}
],
"require": {
"test/framework": "*"
}
}
Package composer.json
{
"name": "test/framework",
"type": "library",
"require": {
"php": ">=5.2.4"
},
"autoload": {
"psr-0" : {
"Test" : "lib/"
}
}
}
autoload_namespaces.php
<?php
// autoload_namespaces.php #generated by Composer
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
);
You are downloading the package defined in the repositories via zip.
https://getcomposer.org/doc/05-repositories.md#package-2
In this case I feel you should define the package definition at the same place. See the above link for the example which contains autoload definition defined.
{
"repositories":[
{
"type": "package",
"package": {
"name": "test/framework",
"version": "1.0.0.1",
"dist": {
"url": "http://localhost/repo/1.zip",
"type": "zip"
},
"autoload": {
"psr-4" : {
"Test\\": "lib"
}
}
}
}
],
"require": {
"test/framework": "*"
}
}
You can also try some variation see my post over http://harikt.com/blog/2014/05/29/hidden-gems-of-composer/
PS : psr-4 is the recommended way for it can autoload psr-0 structured classes. See https://getcomposer.org/doc/04-schema.md#autoload
Just to add to what Hari K T said, be sure to remove the vendor directory after making an update to the composer.json file as composer uses the installed.json file in the ./vendor/composer directory to generate the autoload php files.
I had setup the composer.json correctly, but did not remove the existing vendor directory, so I assumed the answer provided by Hari K T didn't work.

Categories