0

Based on Why do I have conflicts in namespacing? I adjusted my complete system.

As long as I do namespacing in /src, it is goes all very well.
I included my project from Github. Those class files are located in modules/custom/tb/vendor/ccxt/ccxt/php.

When not working with namespaces I included them with include "vendor\ccxt\ccxt\ccxt.php";.

How should I include those classes to module? Because of the Composer structure, those files are in the vendor sub-directory.

Because of namespacing in Drupal, use \Drupal\tb\<classfile> doesn't work.

The content of the composer.json file is the following.

    "name": "org/tb",
    "description": "This extension provides new commands for Drush.",
    "type": "drupal-drush",
    "authors": [
        {
            "name": "Author name",
            "email": "[email protected]"
        }
    ],
    "require": {
        "php": ">=5.6.0",
        "arcturial/clickatell": "^3.0",
        "ccxt/ccxt": "^1.14"
    },
    "extra": {
        "drush": {
            "services": {
                "drush.services.yml": "^9"
            }
        }
    }
}
6
  • 1
    You should move the dependency to your project's composer.json rather than having it in your module. Then the autoloading will just work
    – Clive
    Commented Jun 23, 2018 at 19:19
  • Do you have a link with more information about what you are actually saying?
    – Justme
    Commented Jun 23, 2018 at 20:27
  • Just the general Composer/Drupal Composer docs really. All you need to do is remove the vendor folder in your module, go to your project root and run composer require ccxt/ccxt, then ccxt's namespaces will be available to your code
    – Clive
    Commented Jun 23, 2018 at 20:32
  • But my project root is ... modules\custom\tb so it is already there .
    – Justme
    Commented Jun 23, 2018 at 20:34
  • I meant your Drupal project's root
    – Clive
    Commented Jun 23, 2018 at 20:37

1 Answer 1

1

From your post, it looks like you added the above composer.json file, then ran composer from the module root. This is not the way to do it. This will create a vendor folder inside your module folder, which is not what you want. What you need to do is add the composer.json file to your module, then push that to the remote repository. Then use Composer to install and manage the module. Doing this will add the library to the vendor folder for your project, and the library will be available when calling \ccxt\ccxt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.