I can't use vendor package in yii2 - Class not found - php

I have a yii project and i would like get groups via mailerlite api.
I cant use package after composer update.
Do you need a conversion within the package?
Thank you for your help.
Sample code:
use MailerLiteApi\MailerLite;
public function actionTeszt() {
$groupsApi = (new MailerLite('XXXXXXX'))->groups();
$allGroups = $groupsApi->get();
print_r($allGroups);
exit;
}
Error
Class 'MailerLiteApi\MailerLite' not found

composer require mailerlite/mailerlite-api-v2-php-sdk && composer update

Related

Implementing asinfotrack\yii2-wiki Module not found

I'm implementing this package following the instructions found here.
In my config, as instructed, I have
'wiki'=>[
'class'=>'asinfotrack\yii2\wiki\Module',
'processContentCallback'=>function($content) {
//example if you want to use markdown in your wiki
return Parsedown::instance()->parse($content);
}
]
I am getting an error on wiki/content/view?id=index: Class 'app\modules\wiki\Module' not found - what have I missed?
It looks like there is wrong class namespace used in the package by the developer i.e app\modules\wiki\Module instead of asinfotrack\yii2\wiki\Module
to fix this issue without changing the code in the vendor you can set the classmap on top of the project config file( common.php or main.php ) like this
Yii::$classMap['app\modules\wiki\Module'] = VENDOR_PATH.'/toasinfotrack/yii2-wiki/Module.php';
More details about classmapping in Yii2 can be found here

Class 'Stripe\Stripe' not found

I've installed the stripe library with composer, and I have a problem that is only on one page (see picture here :
my code in cancelStripeSubscription.php :
Stripe\Stripe::setApiKey("my key here");
$sub = \Stripe\Subscription::retrieve($getSubId);
$sub->cancel();
I really don't understand why it's not working since it works in other files in the same directory.
error showing : "Fatal error: Class 'Stripe\Stripe' not found in D:\wamp64\www\etape4Prestige\"
Thanks in advance for helping!
You could use autoloader to actually include the Stripe classes...
require_once('vendor/autoload.php');
This should do the trick if the library is installed with composer I guess...
I have also installed and got the same error, You need to call stripe library like below by creating an object of Stripe not by scope resolution operator(::)
$stripe_obj = new Stripe();
$stripe = $stripe_obj->setApiKey(env('STRIPE_SECRET'));

Call to undefined method Maatwebsite\Excel\Excel::create() - laravel 5.6

I am using Maatwebsite/Excel in my application and when i get the error
Call to undefined method Maatwebsite\Excel\Excel::create()
from one of my controllers. I am using laravel 5.6 and i have followed the documentation strictly and other very few related discussions online to solve this, but i still get the error.
How do i solve this error please
app.php
'provider' => 'Maatwebsite\Excel\ExcelServiceProvider',
'alias' => 'Excel'=> 'Maatwebsite\Excel\Facades\Excel',
Controller
$cl = ClassModel::Select('name')->where('code',$input->class)->first();
$input->class=$cl->name;
$fileName=$input->class.'-'.$input->section.'-'.$input->session.'-'.$input->exam;
// return $students;
Excel::create($fileName, function($excel) use($input,$subjects,$students) {
$excel->sheet('New sheet', function($sheet) use ($input,$subjects,$students) {
$sheet->loadView('app.excel',compact('subjects','input','students'));
});
})->download('xlsx');
You are using 2.* syntax while using 3.* package. Please refer to the correct documentation over here: https://laravel-excel.maatwebsite.nl/docs/3.0/export/basics
Try to decrease the version using :
composer require "maatwebsite/excel=2.1.0"
There have been many changes in the new version of the package.
In your composer.json file inside the require array replace your package with this:
"maatwebsite/excel": "~2.1.0",
and then run composer update
This should work fine.
Please switch to version 2*
Version 3.0 of that package doesn't handle imports yet. Release date for this feature is unknown. See this post for more details: maatwebsite
I have worked it around but I know it's not a perfect solution. It will really help you if you only have concerns with the uploading not adjusting Crudbooster features.
I removed the extra features from the importing screen of the Crudbooster by applying the following CSS in the crudbooster-controller.
$this->style_css = "ul.nav li:not(:first-child) {
display: none;
}";
I copied the getImportData() method from Crudbooster CBController and overridden it in the crudbooster-controller by the following code.
//PHP
//By the way, you can still create your own method in here... :)
public function getImportData()
{
$this->cbLoader();
$data['page_menu'] = Route::getCurrentRoute()->getActionName();
$data['page_title'] = 'Import Data';
if (request('file') && ! request('import')) {
$file = base64_decode(request('file'));
$file = storage_path('app/'.$file);
$data = Excel::import(new ProductImport, $file);
CRUDBooster::redirect('/admin/products', cbLang("alert_add_data_success"), 'success');
}
return view('crudbooster::import', $data);
}
Importing is working fine now

Laravel 5 add nusoap

I am unable to install nusoap to my existing laravel 5 application. Ive done the following:
Created a new Folder in App/Http/Controllers/ - namend "Soap" - and copied the libary into it.
use
composer dump-autoload
So i am able to use
use nusoap_client;
But i am always getting an error:
Class 'App\Http\Controllers\nusoap_client' not found
I thought that laravel automatically load all classes from the "app" directory, but how can i use it here?
Tried with:
$wsdl = "test.xx/_vti_bin/lists.asmx?wsdl";
$client = new nusoap_client($wsdl, true);
Thanks for any help!
Just add these lines to your controller:
include 'nusoap.php';
use nusoap_client;
As a simple way, you can add a backslash in front of nusoap_client, like this:
$client = new \nusoap_client($wsdl, true);

Stripe Payments in PHP With Namespaces

I built a PHP application that uses namespaces and PSR-0 autoloading. In trying to implement the Stripe library, I've found that it can't seem to load the classes because they aren't namespaced. Is there a way to not autoload if I have manually included the files?
// Get Stripe Library
require_once(App\App::$APP_PATH . "/Extensions/Stripe.php");
// Set Key
Stripe::setApiKey($stripe['secret_key']);
Setting the key in the example fails with a fatal error because it thinks a Stripe class exists in my namespace of the current file.
I found that if I add a use Stripe; line below my namespace declaration, it will work, but then fails on the next class in the Stripe library.
Am I really going to have to add a Use Stripe, Stripe_Customer, Stripe_xyz...; line to let it load the files correctly (which there are over 25 files) or is there a better way?
[EDIT]
Until I hear whether there is a better way, I've done this:
// Import Non-Namespaced Stripe Library
use Stripe, Stripe_Account, Stripe_ApiConnectionError, Stripe_ApiError, Stripe_ApiRequestor, Stripe_ApiResource, Stripe_AuthenticationError;
use Stripe_Card, Stripe_CardError, Stripe_Charge, Stripe_Coupon, Stripe_Customer, Stripe_Error, Stripe_Event, Stripe_InvalidRequestError;
use Stripe_Invoice, Stripe_InvoiceItem, Stripe_List, Stripe_Object, Stripe_Plan, Stripe_Recipient, Stripe_SingletonApiResource;
use Stripe_Stripe, Stripe_Token, Stripe_Transfer, Stripe_Util;
Using composer is the easiest way (I promise!)
Just install composer and then install stripe. Once you have those installed just browse to your project's folder and run composer install. This will install the needed dependencies and will put composer in a folder called vendor.
Then you simple require the autoload.php file which will load up stripe, without bothering to use a namespace. Here's a full example block that I grabbed from here.
<?php
require_once('vendor/autoload.php');
$stripe = array(
"secret_key" => "sk_test_BQokikJOvBiI2HlWgH4olfQ2",
"publishable_key" => "pk_test_6pRNASCoBOKtIshFeQd4XMUh"
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
?>
You can use \ to specify that the class name you're specifying is a fully qualified namespace (FQNS), for example:
<?php
use \Stripe, \Stripe_Account;
$stripe = new Stripe();
$stripe_account = new Stripe_Account();
or without use statements:
<?php
$stripe = new \Stripe();
$stripe_account = new \Stripe_Account();

Categories