PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 22, 2022

[FIXED] laravel include php(sdk) use psr-4 is class not found

 January 22, 2022     composer-php, laravel, psr-4     No comments   

Issue

Excuse me, I want to use this sdk GitHub

I try include file php into laravel controller , but is not work.

then, I'll update composer.json, using PSR-4 .. is class XXX/XXX/ not found..

error message Class 'App\Http\Controllers\ECPay_AllInOne' not found

how can I do? please help me, thanks~

my project sdk file :

image link

composer.json

"autoload": {
    "classmap": [
        "database"
    ],
    "psr-4": {
        "App\\": "app/",
        "ECPaySDK\\": "ECPaySDK/"
    },
    "files": [
        "ECPaySDK/ECPayPaymentIntegration.php"
    ]


},

my controller

<?php

namespace App\Http\Controllers;
use ECPaySDK;
use Illuminate\Http\Request;
use Mail;
use App\Http\Requests;
use App\Travel_user;
use App\Travel_user_place;
use App\Place;
use App\Files;
use App\House;
use DB;
use Illuminate\Support\Facades\File;
class BackendController extends Controller

sdk class

<?php
namespace ECPaySDK;
abstract class ECPay_PaymentMethod {
const ALL = 'ALL';

Solution

After adding it to composer.json, import it to your class with use keyword. Change this

namespace ECPaySDK;

To

use ECPaySDK\ECPay_AllInOne;

In the format NAMESPACE\CLASSNAME;

For this to work, go at the top of your file and define a namespace. It seems there is no namespace for now. You can define like this

namespace ECPaySDK;

So depending on the class you want to use, prefix it with ECPaySDK namespace. Assuming you put your your SDK directory at the root of your application.

Update

You have a single file with multiple class declarations. Go to your composer file in the autoload part, just below "psr-4" create a new entry called files.

"files": [
    "ECPaySDK/ECPaymentIntegration.php"
]

Then run composer dumpautoload



Answered By - EddyTheDove
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing