Fatal error: Class 'eftec\bladeone\BladeOne' not found - php

I am using PHP 5.5.9 and have installed the library BladeOne in my composer file:
{
"name": "test",
"authors": [
{
"name": "test",
"email": "test#test.com"
}
],
"require": {
"eftec/bladeone": "^3.0",
"davechild/textstatistics": "1.*",
"hassankhan/config": "^1.0"
}
}
I am running my script the following way:
<?php
require "vendor/autoload.php";
Use eftec\bladeone;
use DaveChild\TextStatistics as TS;
$views = __DIR__ . '/views';
$cache = __DIR__ . '/cache';
define("BLADEONE_MODE",1); // (optional) 1=forced (test),2=run fast (production), 0=automatic, default value.
$blade=new bladeone\BladeOne($views,$cache); <----- Here I get the error!
However, I get the following error here:
Fatal error: Class 'eftec\bladeone\BladeOne' not found in /home/ubuntu/workspace/testExample.php on line 10
Any suggestions why the library cannot be used in my script?

As per the docs you are supposed to add the namespace to the autoloading of composer by adding it to your composer.json.
"autoload": {
"psr-4": {
"eftec\\": "vendor/eftec/"
}
}
then, (again, the docs say) run composer update. I suppose though that composer dump-autoload would suffice.

Related

Composer class not Found Error

I've been working on a project and for which I needed to make a package. But it always returns
PHP Fatal error: Uncaught Error: Class 'youtubetomp3\downloader' not found
Here the structure of directory.
youtubetomp3/
src/
downloader.php
test/
downloaderTest.php
composer.json
composer.lock
and other files
The composer.json contains following details.
{
"name": "princeyadav05/youtubetomp3",
"description": "Downloads mp3 of a video given video-id",
"keywords": ["youtube", "songs", "downloader", "package"],
"license": "",
"authors": [
{
"name": "Prince Yadav",
"email": "princeyadav96#gmail.com"
}
],
"type": "package",
"require": {
"php": ">=5.4",
"php-ffmpeg/php-ffmpeg": "^0.11.0"
},
"require-dev": {
"phpunit/phpunit": "5.2.*"
},
"autoload": {
"psr-4": {
"princeyadav05\\youtubetomp3\\": "src/"
}
}
}
And this is how I'm creating object of class.
<?php
require 'vendor/autoload.php';
require 'scrapper.php';
include 'database.php';
echo "** WELCOME TO THE MP3 DOWNLOADER ** \n \n";
$name = readline("Hey There. Lets start with your name : ");
echo "\nHello " . $name . ".\n";
$search = readline("Please enter the search query : ");
$data_array = searchVideo($search); //returns data array
displayVideos($data_array); // returns video id
$download = new downloader();
$video_details = $download->downloadSong($video_id);
// returns array with video title, Duration, url, path
savingToDb($video_title, $video_duration, $video_url, $songs_path);
?>
Please help. I've tried many things but nothing worked.I'm really frustrated.
It's not clear whether you're including autoload.php file generated by composer. Would you mind posting the full code?
Then I'm not sure about your autoload directive, I would try something like this:
"autoload": {
"classmap": [
"src/"
]
},
see composer docs for more info

Composer autoload can't find class

I'm trying to create a MVC structure and use composer to autoload everything.
But I keep getting this error:
Fatal error: Uncaught Error: Class 'App\Init' not found in C:\wamp64\www\activity\Public\index.php on line 5
|MainFolder
|App
|Public
|Vendor
|ACT
|composer
|autoload.php
|composer.json
composer.json:
{
"name": "vendor/activity",
"description": "descrip",
"require": {
"php": ">=5.6.25"
},
"authors":[
{
"name": "John Doe",
"email": "johndoe#gmail.com"
}
],
"autoload":{
"psr-4": {
"ACT\\": "vendor/",
"App\\": "/"
}
},
"config":{
"bin-dir": "bin"
}
}
App\init.php
<?php
namespace App;
class Init
{
public function __construct()
{
echo "Loaded!!";
}
}
Public\index.php
<?php
require_once '../vendor/autoload.php';
$init = new \App\Init;
\Vendor\composer\autoload_namespaces.php
<?php
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
"ACT" => array($vendorDir . false),
"App" => array($baseDir . '/'),
);
Obs: Already did composer dump-autoload
Don't manually put things in /vendor.
While adhering to #1, don't reference /vendor in autoload, the packages should all have their own fully-functionaly autoloaders that composer will find and use.
You need to specify more of the path in your autoload.
"autoload":{
"psr-4": {
"App\\": "App/"
}
},
Think of it like telling composer "look for things starting with the namespace foo\bar\ in the following folder".
Note: The folder name doesn't have to match the namespace.
Eg: Following the suggested Vendor\Package\ scheme for PSR/Composer
{
"autoload": {
"psr-4": {
"sammitch\\meatstacker\\": "src/"
}
}
}
And then:
\sammitch\meatstacker\Client maps to src/Client.php
\sammitch\meatstacker\Bread\Rye maps to src/Bread/Rye.php
and so on

php composer autoload class not found error

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//Include Composer's autoloader
include 'vendor/autoload.php';
public function test_auth() {
try{
$hybridauth = new Hybridauth\Hybridauth($config);
//Attempt to authenticate users with a provider by name
$adapter = $hybridauth->authenticate('Twitter');
//Returns a boolean of whether the user is connected with Twitter
$isConnected = $adapter->isConnected();
//Retrieve the user's profile
$userProfile = $adapter->getUserProfile();
//Inspect profile's public attributes
var_dump($userProfile);
//Disconnect the adapter
$adapter->disconnect();
}
catch(\Exception $e){
echo 'Oops, we ran into an issue! ' . $e->getMessage();
}
}
An uncaught Exception was encountered
Type: Error
Message: Class 'Hybridauth\Hybridauth\Hybridauth' not found
Filename: C:\xampp\htdocs\paymatrix_v2\application\controllers\Hauth.php
Line Number: 35
Backtrace:
File: C:\xampp\htdocs\paymatrix_v2\index.php
Line: 294
Function: require_once
composer.json file
{
"description": "The CodeIgniter framework",
"name": "codeigniter/framework",
"type": "project",
"homepage": "https://codeigniter.com",
"license": "MIT",
"support": {
"forum": "http://forum.codeigniter.com/",
"wiki": "https://github.com/bcit-ci/CodeIgniter/wiki",
"irc": "irc://irc.freenode.net/codeigniter",
"source": "https://github.com/bcit-ci/CodeIgniter"
},
"require": {
"php": ">=5.2.4",
"mailgun/mailgun-php": "^2.1",
"php-http/curl-client": "^1.6",
"guzzlehttp/psr7": "^1.3",
"aws/aws-sdk-php": "3.*",
"pipl/piplapis-php" : "^5.0",
"hybridauth/hybridauth": "^2.9"
},
"require-dev": {
"mikey179/vfsStream": "1.1.*",
"aws/aws-sdk-php": "dev-master"
},
"autoload": {
"classmap": ["vendor/pipl/piplapis-php/src","vendor/pipl/"]
}
}
autoload.php
// autoload.php #generated by Composer
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit9da23362304113093d59b5cbcc0e2b35::getLoader();
hybrid auth location
vendor/hybridauth/hybridauth/
This file already included in codeigniter core file. dont need to incluse again in your class file
include 'vendor/autoload.php';
Within your function
public function test_auth() {
// Before code
$config = [
'callback' => 'https://example.com/path/to/script.php',
'keys' => [ 'key' => 'your-twitter-consumer-key', 'secret' => 'your-twitter-consumer-secret' ]
];
try {
$twitter = new Hybridauth\Provider\Twitter($config);
$twitter->authenticate();
$accessToken = $twitter->getAccessToken();
$userProfile = $twitter->getUserProfile();
$apiResponse = $twitter->apiRequest( 'statuses/home_timeline.json' );
}
catch(\Exception $e){
echo 'Oops, we ran into an issue! ' . $e->getMessage();
}
}
Check the usage from the package README
https://github.com/hybridauth/hybridauth
I have also faced the same issue. When I install a package using the composer on the root location then it was still saying that the third party class not found.
So here is my solution.
First of all, I change the "composer_autoload" config to TRUE.
$config['composer_autoload'] = TRUE;
By default after change the above configuration Codeigniter looking vendor/autoload file under APPPATH(application folder) which is incorrect. So I change the constant to FCPATH(root path) because the root is the correct path to install the third-party packages using the composer.
change from
System/core/Codeigniter.php:165
if ($composer_autoload === TRUE)
{
file_exists(APPPATH.'vendor/autoload.php')
? require_once(APPPATH.'vendor/autoload.php')
: log_message('error', '$config[\'composer_autoload\'] is set to TRUE but '.APPPATH.'vendor/autoload.php was not found.');
}
to
if ($composer_autoload === TRUE)
{
file_exists(FCPATH.'vendor/autoload.php')
? require_once(FCPATH.'vendor/autoload.php')
: log_message('error', '$config[\'composer_autoload\'] is set to TRUE but '.FCPATH.'vendor/autoload.php was not found.');
}
and finally, run
composer dumpautoload
in case if still not working.
Happy coding!!!

PSR-4 autoloading with Composer - Class not found

I'm create composer package with type library. And trying to require it to Symfony2 project.
The package has following composer.json
{
"name": "vendor/package-sdk",
"description": "My private package",
"type": "library",
"license": "MIT",
"autoload": {
"psr-4": {"Vendor\\PackageSDK\\": "src/"}
},
"require": {
"php": ">=5.3.3"
}
}
Then I require it to my SF2 project.
"repositories": [
{
"type": "git",
"url": "git#github.com:me/vendor-package-sdk.git"
},
],
"require": {
...
"vendor/package-sdk": "~0.0.1-alpha1"
...
}
When I calling
use Vendor\PackageSDK\Client;
...
$client = new Client();
```
And I got fatal error:
PHP Fatal error: Class 'Vendor\PackageSDK\Client' not found in /path
If I do
composer dump-autoload -o
It works, but
composer dump-autoload
not.
The file vendor/composer/autoload_psr4.php contain:
'Vendor\\PackageSDK\\' => array($vendorDir . '/vendor/package-sdk/src'),
Could anybody tell me what am I doing wrong?
In composer autoload_classmap.php file I saw the following line
'Vendor\PackageSDK\Client' => $vendorDir . '/vendor/package-sdk/src/Cilent.php',
So it's just a typo in filename of package
Cilent.php should be Client.php

Fatal error: Class 'Slim\Views' not found in ...vendor\slim\views\Twig.php

I'm building a simple website in PHP with Slim Framework and Twig template engine.
I've installed Slim and Twig with Composer in the Command Line.
This is my index.php
<?php
require __DIR__ . '/vendor/autoload.php';
date_default_timezone_set('Europe/Copenhagen');
$app = new Slim\App( array (
'view' => new Slim\Views\Twig()
));
$view = $app->view();
$view->parserOptions = array(
'debug' => true
);
$view->parserExtensions = array(
new \Slim\Views\Twig(),
);
$app->get('/', function() use($app){
$app->render('about.twig');
});
$app->get('/contact', function() use($app){
$app->render('contact.twig');
});
$app->run();
?>
The error message is:
Fatal error: Class 'Slim\Views' not found in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\projects\simple-php-website\vendor\slim\views\Twig.php on line 46
It works without the Twig framework. So I guess the trouble is on loading the Twig. I've tried different variations of this line:
'view' => new Slim\Views\Twig()
But what confuses me is, that the error message is referring to line 46 in the Twig.php - which is in the core of slim.
I've tried reinstalling Twig and Slim several times.
Any suggestions what is wrong?
Much appreciated!
EDIT
This is from my composer.json
{
"name": "tyf5vl/simple-php-website",
"authors": [
{
"name": "My Name",
"email": "my#mail.com"
}
],
"require": {
"monolog/monolog": "^1.17",
"slim/slim": "^3.1",
"twig/twig": "^1.23",
"slim/views": "^0.1.3"
}
}
http://www.slimframework.com/docs/features/templates.html
states that ONLY view is this -> composer require slim/twig-view
you should have final file as
{
"require": {
"slim/slim": "^3.5",
"slim/twig-view": "^2.1"
}
}

Categories