Git Product home page Git Product logo

Comments (13)

longlivelance avatar longlivelance commented on August 16, 2024 1

If it is helpful for anyone, what I did to fix this in our implementations, was to apply a patch to the library using composer-patches. The patch simply removes the autoload line.

However, this did not completely resolve the issues for me. I also had to use a condition to selectively change the autoload path in spl_autoload_register & then finally include the ET_Client.php file.

...

spl_autoload_register( function($class_name) {
  if (strpos($class_name, 'ET_') === 0) {
    include_once __DIR__ . '../vendor/salesforce-mc/fuel-sdk-php/src/'.$class_name.'.php';
  }
});
require '../vendor/salesforce-mc/fuel-sdk-php/src/ET_Client.php';

Hope this helps some people in the meantime.

from fuelsdk-php.

jlillyreed avatar jlillyreed commented on August 16, 2024

If you follow the demo provided, it starts with this autoload function

  spl_autoload_register(function($class_name) {
    include_once __DIR__ . '/path/to/src/' . $class_name . '.php';
  });

that will automatically load the necessary classes for the library when you call them

from fuelsdk-php.

embolden avatar embolden commented on August 16, 2024

@jlillyreed What demo are you referring to? Please provide a link.

from fuelsdk-php.

jlillyreed avatar jlillyreed commented on August 16, 2024

@embolden https://github.com/salesforce-marketingcloud/FuelSDK-PHP/blob/master/objsamples/sample-list.php

from fuelsdk-php.

longlivelance avatar longlivelance commented on August 16, 2024

@embolden Any luck solving this? Up against exact same issue. Autoload didn't work, so I added it into my composer.json. Now it loads, but cannot find autoload.php at the location it is hardcoded to get it from in ET_Client.php on line 2.

Doing the method mentioned by jillyreed ends in the same issue with

from fuelsdk-php.

DrewSpace avatar DrewSpace commented on August 16, 2024

I am also having issues with the autoloader. On the previous version (0.9) I could access the classes from the global namespace like this \ET_Client().

I upgraded from 0.9 to 1.0 and now those classes cannot be found. I have added

spl_autoload_register(function($class_name) {
    include_once __DIR__ . '/../../vendor/salesforce-mc/fuel-sdk-php/src/' . $class_name . '.php';
}); 

like @jlillyreed suggested, but that results in an error opening fuel-sdk-php/src/../vendor/autoload.php which does not exist. It exists in the root of the vendor directory, not within the sdk's non-existent vendor directory. Changing the require statement to require __DIR__ . '/../../../autoload.php'; fixes the issue without needing a classmap in the project's composer.json.

It seems like the path that it is using for the autoloader is incorrect. Removing the require statement in ET_Client fixes the issue for me if I add a classmap in my composer.json. I'm not sure I understand how that require statement is expected to work since there should not be a vendor directory inside of the sdk when you install it using composer.

from fuelsdk-php.

skylord123 avatar skylord123 commented on August 16, 2024

I'm having issues as well when I did not have issues on the older version. Using Symfony 2.8 w/ composer.

from fuelsdk-php.

skylord123 avatar skylord123 commented on August 16, 2024

Yeah something is really messed up with autoloading on the latest release. @smunuswami or @sharif26 do you maintain this project? If so: please fix.

from fuelsdk-php.

sharif26 avatar sharif26 commented on August 16, 2024

There seems to be an issue with autoload and we are working on it, should be fixed on next release.
So the work around is to comment to autoload line on ET_Client.php file:
//require __DIR__ . '/../vendor/autoload.php';
If you use composer, just make sure you include vendor/autoload.php properly from wherever you are calling from our(or any) dependency. That will ensure all dependencies to load correctly including ours (change the below path according to your vendor location):
require __DIR__ . '/../vendor/autoload.php';
Now if you are testing/using our unit test cases, the line to add on UnitBootstrap.php is:
require __DIR__ . '/../../../autoload.php';
And to run our test cases:
phpunit --bootstrap tests/UnitBootstrap.php tests/CampaignTest.php
Hope it clarifies & resolves the issue for now.

from fuelsdk-php.

skylord123 avatar skylord123 commented on August 16, 2024

@sharif26 Thanks for the quick response. Does this change need to be done to every single class file in this library? Even after using your fix for ET_Client I am still getting issues:

image

Is there an ETA on when the next release will be? I can not and will not use this in a production env. Modifying vendor files is terrible practice. I need this library for a time sensitive project, that is why I ask.

from fuelsdk-php.

skylord123 avatar skylord123 commented on August 16, 2024

You can also just set the version to 0.9.1 until the latest release is fixed. I did this and it is much easier then modifying vendor files (which should be avoided completely on production servers anyways).

Still no ETA on the fix?

from fuelsdk-php.

sharif26 avatar sharif26 commented on August 16, 2024

Please check our new release, autoload issue should be fixed by that. Thanks to all for your helpful code snippet and information.

from fuelsdk-php.

tkhuynh avatar tkhuynh commented on August 16, 2024

Guys,

I came up with a solution.You should go to your vendor folder and delete autoload.php file and rerun php composer.phar update, it will regenerate new autoload.php file and you can use FuelSdk normally, and only need to add require __DIR__ . '/vendor/autoload.php';, nothing else

from fuelsdk-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.