How to add a new vendor - prestashop-1.7

I am new to prestashop and trying to add a 3rd party library in vendor folder which i could use in my custom module. I have added composer.json in my module as well but unable to get the 3rd party library installed in prestashop vendor folder.
Any help/guidance would be much appreciated.

I used the fzaninotto/faker library and I got it working like this :
Composer.json at the root of my module :
{
"require": {
"fzaninotto/faker": "^1.6"
}
}
then run
composer install
Now in order to use this package I created a file called faker.php at the root of my module that starts with including the correct files :
<?php
require('vendor/autoload.php');
require('../../config/config.inc.php');
$faker = Faker\Factory::create('fr_FR');
Basicly this is a 3 step process :
1. Create your composer.json
2. Run composer install
3. Include the autoload.php that is in the newly created vendor directory, make sure you use the correct relative path

Related

Modified vendor files, Laravel

I'm currently using Laravel 7.xx, and during working on my project, I change some vendor files, modify it
Because few things doesn't work for me, so without any option left, I have to modify some vendor files.
In case if I ever want / need to update my laravel / packages version, will the modified vendor files revert back to original state and I lost all my modified code?
Thanks in advance
Yes! whenever you do composer install or composer update, your modified vendor files will revert back. So, you never should edit any vendor files.
What you can do is extend those specific classes to new files of your own
Make a new file of the class that you are overriding : (e.g : app/Overrides/MyClass.php)
in your composer.json
"exclude-from-classmap": [
"vendor/pathtotheYourVendorFileThatYouAreOverriding.php"
],
"psr-4": {
"App\\": "app/",
"Illuminate\\": "app/Overrides/"
}

Submit a plugin to Octobercms Market with composer requirements; must the vendor map be included?

As an developer I want to submit a plugin to the OC Market. My plugin has composer requirements defined in composer.json.
On dev machine everything works well, the dependencies are included with composer update executed in the root of the project. So all dependencies are in the main root vendor map.
I already have submitted my plugin to the OC Market, from within the account/plugin/create page. The plugin was uploaded as ZIP file without(!) vendor map. The dependencies were only defined in a composer.json file, but not actually included in the ZIP file.
When I now install my plugin in a fresh OC install, a 'vendor' map is included in the plugin folder. Like this: 'plugins/author/foo/vendor'. The plugin is installed from within the CMS (url: backend/system/updates/install), and also as a second test on cli with $ artisan plugin:install author.foo. Both times the installation went correct.
How is this vendor map got in the folder where the plugin reside?
Is it good practice to add or not add a vendor map in the ZIP file on submitting to OC Market?
The octobercms.com marketplace build process pulls in the plugin’s dependencies into a vendor directory under the plugin’s own directory and then removes composer.lock and composer.json from the package that gets generated. This is to support users that don’t use composer while also supporting users that use both marketplace plugins and composer-based plugins.
If we left the composer.json in the plugin during the build process and then the user were to run composer update from the project root on that marketplace plugin, suddenly they would have duplicated dependencies which was causing a lot of issues.
All of this to say: Don't include your vendor directory when submitting a plugin to the marketplace, the marketplace will take care of that. Do include your composer.json file though.
In regards to RainLab.GoogleAnalytics, the build on the marketplace appears to be broken which means that it needs to be rebuilt on the marketplace. This could be triggered by pushing an update to the Github repository, unfortunately for some reason that repository is massively broken for my Github account and I don't even have the ability to comment on issues. Thus, I'm unable to trigger a rebuild of the plugin. However, if you remind me on Slack or IRC to talk to #spunky (creator of October) about it then I can do that and perhaps he can trigger a rebuild.
October fetchs the composer depencies on plugin install or php artisan october:up
For example in my plugin:
{
"name" : "Tschallacka/dynamic-pages-plugin",
"type" : "october-plugin",
"description" : "DynamicPages plugin for October CMS",
"homepage" : "",
"keywords" : [
"october",
"octobercms",
"pages",
"exit"
],
"authors" : [{
"name" : "Tschallacka",
"email" : "tsch#",
"role" : "Developer"
}
],
"require" : {
"php" : ">=7.0",
"composer/installers" : "~1.0",
"webpatser/laravel-uuid" : "^2.0",
"paragonie/random_compat" : "^2.0"
},
"minimum-stability" : "dev"
}
If I supply it without the vendor folder, then when I do october:up or install it via october backend, the vendor folder (residing here plugins/author/myplugin/vendor) will be populated with the required files, so I end up with the composer, webpatser and paragonie folders in my vendor dir.

Why did composer install oauth2-client with different directory names and files

I am new to composer and I used it to install the oauth2-client. I think I am having some sort of misunderstanding about how this is supposed to work.
From thephpleague github page I installed from the command line using
composer require league/oauth2-client
This added files to /usr/local/bin/vendor/league/oauth2-client.
The file structure looks the same as it does on github, except I don't have all the same files.
And the php in the files is looking for files in \League\OAuth2, so I am getting errors that it can't find included files, because I don't have that directory.
Did I do it wrong, or am I just not getting something?
The backslash is the PHP namespace separator, not the directory separator.
In the composer.json for oauth2 from TheLeague, this is the autoload directive:
"autoload": {
"psr-4": {
"League\\OAuth2\\Client\\": "src/"
}
},
It says that the code inside of src directory is in the League\OAuth2\Client namespace.
Composer follows PSR-4 with regards to namespacing and autoloading, so check that out if you want to know what goes on.
UPDATE:
If you've installed other League extensions, like oauth2-facebook, it will install itself into the same src directory - because of the autoload directive in composer.json.
Why?
Well, because of the namespace, you will find 'Facebook' in the League\OAuth2\Client\Provider namespace.
Because of PSR-4, this means that they need to go into the same directory, even though they are different packages.
That is the reason why you'll see Facebook.php in src/Providers directory. Check the oauth2-facebook repository
You probably have required oauth2-facebook and oauth2-google, or one of your other required packages requires it. It rarely just add themselves. :)

Composer private package issue

I have created a private composer package in packagist.com but when I use
composer require command to fetch it. My package coming under vendor folder which is on root.
But I want it to be in app/code folder. Is there any parameter for composer.json where I can set app/code, so it will come under app/code/.
Yes there is. According to the composer documentation, if your project uses the PSR-4 specification for loading classes, then adding the snippet below to the composer.json file would work.
NB: You will need to change ProjectNameSpace to the base namespace for your project.
...
"autoload": {
"psr-4": {
"ProjectNameSpace\\": "app/code"
}
},
...
Theoretically. You can't composer will always place the code in vendor directory. The code is external and therefore can be updated only by composer. It must not be in app/code as only code you modify for the project should be in app/code.
If you wish to make a Magento project, you should have the fallowing files in the versioning tool.
app/*
composer.json
composer.lock
.htaccess
index.php
The other files will be handled by composer.
But if you really need to do it, but I don't see any reason to do so, then you could use a post-update & post-install script to move the code. But it's a very bad idea.

How to set custom folder path for sub folders in vendor when installing a package?

I want to install a package into my local project.For that I'm creating a composer.json file in my project folder is given below, it gives the total vendor folder of that package into my custom folder in my project. Its working fine.....
{
"config": {
"vendor-dir": "/var/www/html/Test2/Testing/Down"
},
}
It gives the package into 'Down' folder.
But, now I want the sub folders or files in that packages to be installed in my custom folders like js/css folders in my project.
For example i want jquery.js file into my local folder path
/var/www/html/Test2/Testing/assests/js
From the package "frameworks/jquery".
For that, what changes are needed in my composer.json file?
Composer is used to bring in packages to support the PHP code of a project, here is how they describe it on the Composer website:
Composer is a tool for dependency management in PHP. It allows you to
declare the libraries your project depends on and it will manage
(install/update) them for you.
In other words, if you need to do logging in your PHP code and decide to use the publicly available monolog package, you use composer to bring that package into your project, then in your PHP code, you can call monolog functions.
Using config to rename the vendor directory is trying to use Composer in a way that doesn't fit the intent of the tool. The vendor directory is used to hold the packages brought in (such as the monolog code). The vendor-dir value is simply renaming that directory.
Since you have GitHub listed as a tag, you could possibly use cloning to get your files to your website directory.
I've modified my composer.json file, it looks like the below:
{
"config": {
"vendor-dir": "/var/www/html/Test2/Testing/Down"
},
"require": {
},
"scripts": {
"post-package-install": [
"php -r \"exec('cp -r /var/www/html/Test2/Testing/Down/frameworks/jquery/* /var/www/html/Test2/Testing/assets/js');\""
]
}
}
It will gives all selected files in a package to my local folder.
Briefly the files in the folder 'frameworks/jquery' are copied into my local 'assets/js' folder.

Resources