Codeigniter - how to integrate third-party library installed via composer - php

I try integrate external php inpost library:
https://github.com/imper86/php-inpost-api
I run composer install:
- Installing symfony/polyfill-php73 (v1.27.0): Extracting archive
- Installing symfony/options-resolver (v5.4.11): Extracting archive
- Installing psr/cache (1.0.1): Extracting archive
- Installing php-http/client-common (2.6.0): Extracting archive
- Installing imper86/php-http-cache-plugin (2.0.0): Extracting archive
- Installing imper86/http-client-builder (v2.0.0): Extracting archive
- Installing imper86/php-inpost-api (v1.1.9): Extracting archive
Now all this files I have in public_html/vendor folder.
structure image
I fallow to this example guide:
https://www.wdb24.com/how-to-integrate-faker-as-a-third-party-into-codeigniter/
But for me looks like I have dirrfrent this files structure. Example when I rename folder src and call:
include APPPATH.'/third_party/imper86/autoload.php';
but in imper86 I have 3 extra folders with containst src folder like http-client-builder php-http-cache-plugin and php-inpost-api
Also as is shown in log from composer installation, this library require also symfony psr and php-http
and now im not sure how to now copy this folders to correct structure to working together everything.

Related

JmsSerializerBundle installation ends with error: Unrecognized option "xml" under "jms_serializer.visitors"

When I install a Symfony 4 skeleton project and add the JmsSerializerBundle, I get an error.
To reproduce:
composer create-project symfony/website-skeleton myproject
cd myproject
composer require jms/serializer-bundle
The installation ends with an error:
Using version ^3.0 for jms/serializer-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.1.*"
Package operations: 16 installs, 0 updates, 0 removals
- Installing hoa/exception (1.17.01.16): Loading from cache
- Installing hoa/event (1.17.01.13): Loading from cache
- Installing hoa/consistency (1.17.05.02): Loading from cache
- Installing hoa/visitor (2.17.01.16): Loading from cache
- Installing hoa/ustring (4.17.01.16): Loading from cache
- Installing hoa/protocol (1.17.01.14): Loading from cache
- Installing hoa/zformat (1.17.01.10): Loading from cache
- Installing hoa/iterator (2.17.01.10): Loading from cache
- Installing hoa/compiler (3.17.08.08): Loading from cache
- Installing hoa/regex (1.17.01.13): Loading from cache
- Installing hoa/math (1.17.05.16): Loading from cache
- Installing hoa/stream (1.17.02.21): Loading from cache
- Installing hoa/file (1.17.07.11): Loading from cache
- Installing jms/metadata (2.0.0): Loading from cache
- Installing jms/serializer (2.0.0): Loading from cache
- Installing jms/serializer-bundle (3.0.0): Loading from cache
Writing lock file
Generating autoload files
ocramius/package-versions: Generating version class...
ocramius/package-versions: ...done generating version class
Symfony operations: 1 recipe (f702450e5b1b913f83ea887faacbdb83)
- WARNING jms/serializer-bundle (>=2.0): From github.com/symfony/recipes-contrib:master
The recipe for this package comes from the "contrib" repository, which is open to community contributions.
Review the recipe at https://github.com/symfony/recipes-contrib/tree/master/jms/serializer-bundle/2.0
Do you want to execute this recipe?
[y] Yes
[n] No
[a] Yes for all packages, only for the current installation session
[p] Yes permanently, never ask again for this project
(defaults to n): y
- Configuring jms/serializer-bundle (>=2.0): From github.com/symfony/recipes-contrib:master
Executing script cache:clear [KO]
[KO]
Script cache:clear returned with error code 1
!!
!! In ArrayNode.php line 304:
!!
!! Unrecognized option "xml" under "jms_serializer.visitors"
Running composer etc on Windows 10 Powershell. I'm guessing the skeleton is too bare and it needs a dependency, but shouldn't that be solved automatically?
What could be the cause? How can I fix it? Thanks in advance for your help.
The current recipe is not compatible with JMSSerializerBundle 3 (there is a pending pull request, see https://github.com/symfony/recipes-contrib/pull/559). So for now, you need to adapt the configuration manually.

How do I install a PHP library globally?

I'm running PHP 7 on Mac High Sierra with Apache . How do I install a library so that it is universally available for all my PHP scripts? I have this line in my test.php file
$loop = React\EventLoop\Factory::create();
$tcp = new \React\SocketClient\TcpConnector($loop);
The source code (from ReactPHP -- https://github.com/Bit-Wasp/stratum-php) in question is in a separate project in the directory
./vendor/react/event-loop/src/Factory.php
I copied the "Factory.php" file to the same directory as my "test.php" file but I still get the error
Fatal error: Uncaught Error: Class 'React\EventLoop\Factory' not found in /Library/WebServer/Documents/stratum/test.php on lineĀ 9
Where can I install the missing file to so that it can be universally picked up by all scripts?
Edit: I had tried installing the library using composer. Below is the output. I don't know where it is installing things but it's not getting picked up by my code ...
localhost:react-master davea$ composer global require react/event-loop react/http
Changed current directory to /Users/davea/.composer
Using version ^0.4.3 for react/event-loop
Using version ^0.8.1 for react/http
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 12 installs, 0 updates, 0 removals
- Installing react/promise (v2.5.1): Loading from cache
- Installing evenement/evenement (v3.0.1): Downloading (100%)
- Installing react/event-loop (v0.4.3): Loading from cache
- Installing react/stream (v0.7.7): Loading from cache
- Installing react/promise-stream (v1.1.1): Loading from cache
- Installing react/promise-timer (v1.2.1): Loading from cache
- Installing react/socket (v0.8.9): Loading from cache
- Installing react/dns (v0.4.12): Loading from cache
- Installing react/cache (v0.4.2): Loading from cache
- Installing psr/http-message (1.0.1): Loading from cache
- Installing ringcentral/psr7 (1.2.2): Loading from cache
- Installing react/http (v0.8.1): Loading from cache
react/event-loop suggests installing ext-libevent (>=0.1.0)
react/event-loop suggests installing ext-event (~1.0)
react/event-loop suggests installing ext-libev (*)
Writing lock file
Generating autoload files

Symfony 2.8 to 3.0 migration

I want to upgrade symfony 2.8 project to 3.0, i changed the version in composer.json to 3.0.* but after composer update is done, i have these error in console:
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
PHP Fatal error: Class 'Symfony\Component\HttpKernel\Kernel' not found in
/var/www/html/t/EcoPro/app/AppKernel.php on line 6
It sounds like your code can't find the Kernel class from Symfony. Since it should still be there, as you can see in the Symfony repository in the 3.0-branch I assume something went wrong during your update.
I suggest first running composer diagnose to see if composer itself is up to date and your composer.json is syntactically valid. As a next step you should verify the current version of your dependencies by running composer show. The output should look something like this:
$ composer show
doctrine/annotations v1.2.7 Docblock Annotations Parser
doctrine/cache v1.5.1 Caching library offering an object-oriented API for many cache backends
doctrine/collections v1.3.0 Collections Abstraction library
doctrine/common v2.5.1 Common Library for Doctrine projects
doctrine/dbal v2.5.2 Database Abstraction Layer
doctrine/doctrine-bundle 1.6.0 Symfony DoctrineBundle
doctrine/doctrine-cache-bundle 1.2.2 Symfony Bundle for Doctrine Cache
doctrine/inflector v1.1.0 Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
doctrine/lexer v1.0.1 Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.
doctrine/orm v2.5.2 Object-Relational-Mapper for PHP
incenteev/composer-parameter-handler v2.1.2 Composer script handling your ignored parameter file
jdorn/sql-formatter v1.2.17 a PHP SQL highlighting library
monolog/monolog 1.17.2 Sends your logs to files, sockets, inboxes, databases and various web services
paragonie/random_compat 1.1.0 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
psr/log 1.0.0 Common interface for logging libraries
sensio/distribution-bundle v5.0.2 Base bundle for Symfony Distributions
sensio/framework-extra-bundle v3.0.11 This bundle provides a way to configure your controllers with annotations
sensio/generator-bundle v3.0.0 This bundle generates code for you
sensiolabs/security-checker v3.0.2 A security checker for your composer.lock
swiftmailer/swiftmailer v5.4.1 Swiftmailer, free feature-rich PHP mailer
symfony/monolog-bundle v2.8.2 Symfony MonologBundle
symfony/phpunit-bridge v2.8.0 Symfony PHPUnit Bridge
symfony/polyfill-intl-icu v1.0.0 Symfony polyfill for intl's ICU-related data and classes
symfony/polyfill-mbstring v1.0.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php56 v1.0.0 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-php70 v1.0.0 Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions
symfony/polyfill-util v1.0.0 Symfony utilities for portability of PHP codes
symfony/swiftmailer-bundle v2.3.9 Symfony SwiftmailerBundle
symfony/symfony v3.0.0 The Symfony PHP framework
twig/twig v1.23.1 Twig, the flexible, fast, and secure template language for PHP
This should help you see whether the update actually worked. If all looks fine, I would go the safe route and revert your code back to 2.8 and then do the update like explained below, instead of changing the composer.json!
First make sure you fixed all deprecations in your existing application. You can use the UPGRADE-document as reference, but also run your tests and check the logs for deprecated calls. This will become easier with 3.3+ as these versions have a separate deprecation-log that you can find in var/log alongside the other log files.
Once you are reasonably sure you code will run with a new major version, just use the following composer command:
composer require symfony/lts:"^3.0"
This is only to make sure that we don't accidentally install any Symfony component that is 4.0 during the process. Once you want to upgrade to Symfony 4 you can just remove this dependency using composer remove symfony/lts and then run update.
After the lts meta package is in place you can update Symfony itself:
composer require symfony/symfony:^3.0
to update to the newest 3.x that your dependencies support or use a stricter constraint if you really want to go step by step:
composer require symfony/symfony:3.0.*
You can also do both things in one step if you like:
$ composer require symfony/lts:^3.0 symfony/symfony:^3.0
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 5 installs, 2 updates, 0 removals
- Updating symfony/symfony (v2.8.32 => v3.4.2): Downloading (100%)
- Installing psr/simple-cache (1.0.0): Loading from cache
- Installing psr/link (1.0.0): Loading from cache
- Installing psr/container (1.0.0): Loading from cache
- Installing psr/cache (1.0.1): Loading from cache
- Installing fig/link-util (1.0.0): Loading from cache
Writing lock file
Generating autoload files
> Incenteev\ParameterHandler\ScriptHandler::buildParameters
Updating the "app/config/parameters.yml" file
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::buildBootstrap
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache
// Clearing the cache for the dev environment with debug
// true
[OK] Cache for the "dev" environment (debug=true) was successfully cleared.
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installAssets
Trying to install assets as relative symbolic links.
[OK] No assets were provided by any bundle.
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::installRequirementsFile
> Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::prepareDeploymentTarget
This should already be enough to have Symfony on the newer version. You will likely have other dependencies such as Doctrine or some bundles that you have installed as well. There are a few useful commands for updating them.
First you can update only a single dependency at a time:
composer update doctrine/orm
When you add the option --with-dependencies it will also update doctrine/orm's dependencies.
You can always ask composer why or composer why-not with a dependency and optionally a version to check why a dependency is there and why it won't update. Just type composer help why-not to see how to use it. This is particularly helpful when you want to update a dependency like doctrine/orm, but composer throws an error that it can't do it.

PHPWord through composer on wamp

I know there are many subject about composer but I won't be able to install phpword through composer.
Basically I need to install PHPWord to create word on my network server.
I install wamp on my computer, install composer and create a new folder on www.
Let's say the main directory is : www/test/
I write a composer.json file :
{
"require": {
"phpoffice/phpword": "v0.13.*"
}
}
And with command line, I tried composer install :
Failed loading c:/wamp/bin/php/php5.6.19/ext/php_xdebug-2.4.0-5.6-vc11-nts.dll
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 6 installs, 0 updates, 0 removals
- Installing pclzip/pclzip (2.8.2): Loading from cache
- Installing phpoffice/common (v0.2.6): Loading from cache
- Installing zendframework/zend-stdlib (2.4.13): Loading from cache
- Installing zendframework/zend-validator (2.4.13): Loading from cache
- Installing zendframework/zend-escaper (2.4.13): Loading from cache
- Installing phpoffice/phpword (v0.13.0): Loading from cache
zendframework/zend-stdlib suggests installing zendframework/zend-eventmanager (To support aggregate hydrator usage)
zendframework/zend-stdlib suggests installing zendframework/zend-serializer (Zend\Serializer component)
zendframework/zend-stdlib suggests installing zendframework/zend-servicemanager (To support hydrator plugin manager usage)
zendframework/zend-stdlib suggests installing zendframework/zend-filter (To support naming strategy hydrator usage)
zendframework/zend-validator suggests installing zendframework/zend-db (Zend\Db component)
zendframework/zend-validator suggests installing zendframework/zend-filter (Zend\Filter component, required by the Digits validator)
zendframework/zend-validator suggests installing zendframework/zend-i18n (Zend\I18n component to allow translation of validation error messages as well as to use the various Date validators)
zendframework/zend-validator suggests installing zendframework/zend-math (Zend\Math component)
zendframework/zend-validator suggests installing zendframework/zend-resources (Translations of validator messages)
zendframework/zend-validator suggests installing zendframework/zend-servicemanager (Zend\ServiceManager component to allow using the ValidatorPluginManager and validator chains)
zendframework/zend-validator suggests installing zendframework/zend-session (Zend\Session component)
zendframework/zend-validator suggests installing zendframework/zend-uri (Zend\Uri component, required by the Uri and Sitemap\Loc validators)
phpoffice/phpword suggests installing ext-gd2 (Allows adding images)
phpoffice/phpword suggests installing dompdf/dompdf (Allows writing PDF)
Writing lock file
Generating autoload files
So now I've got a new folder call vendor with autoload.php and many folder inside (zendframework, phpoffice...)
When I try to go to a phpword example, I've got this error :
Fatal error: Uncaught exception 'Exception' with message 'Could not find file '/autoload.php'. It is generated by Composer. Use 'install --prefer-source' or 'update --prefer-source' Composer commands to move forward.' in C:\wamp\www\Nouveau dossier (2)\vendor\phpoffice\phpword\bootstrap.php on line 22
( ! ) Exception: Could not find file '/autoload.php'. It is generated by Composer. Use 'install --prefer-source' or 'update --prefer-source' Composer commands to move forward. in C:\wamp\www\Nouveau dossier (2)\vendor\phpoffice\phpword\bootstrap.php on line 22
The path to autoload.php seems ok.
Anyone know why there is this problem ?
After I juste need to copy vendor folder to my network server ? (windows server with wamp)
Thank for your help.

Accidental removal of some laravel files with composer install/update, how to retrieve?

I was trying to move the packages from my require-dev to require in composer.json, and accidentally created a second require object when there was already one above the autoload object and called composer update. It then began deleting my laravel install and I quickly pressed ctrl+c.
But now I'm getting an error saying Fatal error: Interface 'Symfony\Component\HttpKernel\HttpKernelInterface' not found when I visit my website, or try running composer install/update again.
Is there any way to recover from this?
These are teh files that were deleted:
C:\xampp\htdocs\project>composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Removing laravel/framework (v4.1.18)
- Removing classpreloader/classpreloader (1.0.1)
- Removing d11wtq/boris (v1.0.8)
- Removing ircmaxell/password-compat (1.0.3)
- Removing filp/whoops (1.0.10)
- Removing jeremeamia/superclosure (1.0.1)
- Removing nikic/php-parser (v0.9.4)
- Removing monolog/monolog (1.7.0)
- Removing nesbot/carbon (1.8.0)
- Removing patchwork/utf8 (v1.1.17)
- Removing phpseclib/phpseclib (0.3.5)
- Removing predis/predis (v0.8.5)
- Removing stack/builder (v1.0.1)
- Removing swiftmailer/swiftmailer (v5.0.3)
- Removing symfony/browser-kit (v2.4.1)
- Removing symfony/css-selector (v2.4.1)
- Removing symfony/dom-crawler (v2.4.1)
- Removing symfony/http-kernel (v2.4.1)
^CTerminate batch job (Y/N)? y
Don't worry, you shouldn't loose anything of your application. It was basically removing things in the vendor folder, which are pretty much removable at any time without prejudice for your application source files, but yes, without them your application will not work, so:
Just get your composer.json back in its feets:
"require": {
"laravel/framework": "4.1.*",
},
Completely remove your vendor folder:
del C:\xampp\htdocs\project\vendor\*.* /s
And then:
composer update
Again

Categories