Announcement

Collapse
No announcement yet.

Adding libraries using composer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding libraries using composer

    Is there a way to add libraries to the vendor directory using composer? I need to use Stash in a custom service to prevent making a very slow call to a remote server. However, using composer to install a custom library doesn't seem to work. The autoloader breaks and I have to undo a number of changes.

  • #2
    look here .. emillod have make many video howto ..
    and how add library

    https://forum.espocrm.com/forum/deve...-do-you-think-

    Comment


    • #3
      For Espo modules

      1. Create a `composer.json` file with your dependencies. in your module root (`<application_or_custom>/Espo/Modules/{ModuleName}`).
      2. Create a 'Resources/autoload.json' file in your module.

      autoload.json:

      Code:
      {
          "psr-4": {
              "LibraryNamespace\\": "<application_or_custom>/Espo/Modules/{ModuleName}/vendor/<vendor-name>/<library-name>/path/to/src"
          }
      }
      The problem of such approach is when the library and Espo have mutual dependencies. You will need to make them ignored in the composer.json, so they won't installed.


      For those who build from the Espo repository (who don't make an installable extension, who don't use official Espo upgrades)

      Just use "composer require". This will add dependencies to the main `vendor` directory.
      Last edited by yuri; 06-19-2022, 08:07 AM.
      If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

      Comment


      • #4
        yuri How do you namespace this file? custom/Espo/Modules/TestModule/Test.php

        Is it 'namespace Espo\Custom\Modules\TestModule'?
        Last edited by bandtank; 07-10-2022, 07:46 PM.

        Comment


        • #5
          In case anyone else needs to know, the answer to my question in the previous post is:

          PHP Code:
          namespace Espo\Modules\<ModuleName>;
          ​ 


          For example, a new class called Stuff in the Classes folder in a module called CalendarExt would be coded as follows:

          PHP Code:
          <?php

          namespace Espo\Modules\CalendarExt\Classes;

          class 
          Stuff
          {
              ...
          }

          Comment

          Working...
          X