Got not found when trying to use zend-soap - php

I am trying to write a SOAP server in PHP using zendframework/zend-soap library. This is my directory structure:
|- app/
|- mySoapService.php
|- composer.json
|- composer.lock
|- vendor/
This is the content of composer.json:
{
"name": "my_soap_service",
"description": "This package is implementing a SOAP service.",
"type": "project",
"require": {
"zendframework/zend-soap": "^2.8"
},
"require-dev": {
}
}
I entered following commands in terminal:
zeinab: ~/my_soap_server$ composer install
PHP Warning: Module 'soap' already loaded in Unknown on line 0
PHP Warning: Module 'soap' already loaded in Unknown on line 0
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 10 installs, 0 updates, 0 removals
- Installing psr/container (1.0.0): Loading from cache
- Installing container-interop/container-interop (1.2.0): Loading from cache
- Installing zendframework/zend-stdlib (3.2.1): Loading from cache
- Installing zendframework/zend-validator (2.12.2): Downloading (100%)
- Installing zendframework/zend-escaper (2.6.1): Downloading (100%)
- Installing zendframework/zend-uri (2.7.1): Downloading (100%)
- Installing zendframework/zend-eventmanager (3.2.1): Loading from cache
- Installing zendframework/zend-code (3.4.1): Downloading (100%)
- Installing zendframework/zend-server (2.8.1): Downloading (100%)
- Installing zendframework/zend-soap (2.8.0): Downloading (100%)
zendframework/zend-validator suggests installing psr/http-message (psr/http-message, required when validating PSR-7 UploadedFileInterface instances via the Upload and UploadFile validators)
zendframework/zend-validator suggests installing zendframework/zend-db (Zend\Db component, required by the (No)RecordExists validator)
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)
zendframework/zend-validator suggests installing zendframework/zend-math (Zend\Math component, required by the Csrf validator)
zendframework/zend-validator suggests installing zendframework/zend-i18n-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, ^2.8; required by the Csrf validator)
zendframework/zend-code suggests installing doctrine/annotations (Doctrine\Common\Annotations >=1.0 for annotation features)
zendframework/zend-soap suggests installing zendframework/zend-http (Zend\Http component)
Package container-interop/container-interop is abandoned, you should avoid using it. Use psr/container instead.
Writing lock file
Generating autoload files
And:
zeinab:~/my_soap_server$ composer require zendframework/zend-soap
PHP Warning: Module 'soap' already loaded in Unknown on line 0
PHP Warning: Module 'soap' already loaded in Unknown on line 0
Using version ^2.8 for zendframework/zend-soap
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Package container-interop/container-interop is abandoned, you should avoid using it. Use psr/container instead.
Writing lock file
Generating autoload files
This is the content of mySoapService.php:
class MyClass {
/**
* #param integer $inputParam
* #return string
*/
public function method1($inputParam) {
return "This is your input: " . $inputParam . ".";
}
/**
* #param integer $inputParam1
* #param string $inputParam2
* #return float
*/
public function method2($inputParam1, $inputParam2) {
return "This is your inputs: " . $inputParam1 . " and " . $inputParam2 . ".";
}
}
$server = new Zend\Soap\Server(null, $options);
// Bind Class to Soap Server
$server->setClass('MyClass');
// Bind already initialized object to Soap Server
$server->setObject(new MyClass());
$server->handle();
But when I try to run it using php mySoapService.php, I get this error:
zeinab:~/my_soap_server$ php app/mySoapServer.php
PHP Warning: Module 'soap' already loaded in Unknown on line 0
PHP Fatal error: Uncaught Error: Class 'Zend\Soap\Server' not found in /home/zeinab/my_soap_server/app/mySoapServer.php:23
Stack trace:
#0 {main}
thrown in /home/zeinab/my_soap_server/app/mySoapServer.php on line 23
I also tried to put "zendframework/zend-soap": "^2.8" inside both require and require-dev sections of composer.json and repeat the process; same results happened.

It seems you forgot to add composer's autoloading. This is necessary to tell PHP where to find the classes you are instantiating. Take a look at Composer's documentation for more informations about it.
Add include __DIR__ . '/PATH/TO/VENDOR/FOLDER/autoload.php'; at the beginning of the file.

Related

Laravel composer TypeError during installation

I have a little problem with my composer.
I'm using laragon on windows so everything is 'made' for me.
I've installed using composer require pragmarx/tracker command, and it was fine.
But because I'm a bit stupid I thought it was causing some problems so I've removed it with composer remove pragmarx/tracker. Now I want to reinstall it, but I got the following problem.
I can't find a solution anywhere, and I don't really understand the problem.
C:\laragon\www\Portfolio (master)
λ composer require pragmarx/tracker
Using version ^4.0 for pragmarx/tracker
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 12 installs, 0 updates, 0 removals
- Installing jaybizzle/crawler-detect (v1.2.96): Loading from cache
- Installing snowplow/referer-parser (0.2.0): Loading from cache
- Installing pragmarx/datatables (v1.4.12): Loading from cache
- Installing composer/ca-bundle (1.2.7): Loading from cache
- Installing ua-parser/uap-php (v3.9.13): Loading from cache
- Installing mobiledetect/mobiledetectlib (2.8.34): Loading from cache
- Installing jenssegers/agent (v2.6.4): Loading from cache
- Installing pragmarx/support (0.9.2): Loading from cache
- Installing doctrine/event-manager (1.1.1): Loading from cache
- Installing doctrine/cache (1.10.2): Loading from cache
- Installing doctrine/dbal (2.10.2): Loading from cache
- Installing pragmarx/tracker (v4.0.0): Loading from cache
snowplow/referer-parser suggests installing symfony/yaml (Support for YAML configuration file)
ua-parser/uap-php suggests installing symfony/yaml (Required for CLI usage - ^3.4 || ^4.3 || ^5.0)
ua-parser/uap-php suggests installing symfony/filesystem (Required for CLI usage - ^3.4 || ^4.3 || ^5.0)
pragmarx/support suggests installing symfony/yaml (The Yaml class needs it)
doctrine/cache suggests installing alcaeus/mongo-php-adapter (Required to use legacy MongoDB driver)
pragmarx/tracker suggests installing geoip/geoip (~1.14)
pragmarx/tracker suggests installing geoip2/geoip2 (~2.0)
Writing lock file
Generating optimized autoload files
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
TypeError
Argument 1 passed to UAParser\Parser::parse() must be of the type string, null given, called in C:\laragon\www\Portfolio\vendor\pragmarx\tracker\src\Support\UserAgentParser.php on line 25
at C:\laragon\www\Portfolio\vendor\ua-parser\uap-php\src\Parser.php:37
33| $this->userAgentParser = new UserAgentParser($this->regexes);
34| }
35|
36| /** Sets up some standard variables as well as starts the user agent parsing process */
> 37| public function parse(string $userAgent, array $jsParseBits = []): Client
38| {
39| $client = new Client($userAgent);
40|
41| $client->ua = $this->userAgentParser->parseUserAgent($userAgent, $jsParseBits);
1 C:\laragon\www\Portfolio\vendor\pragmarx\tracker\src\Support\UserAgentParser.php:25
UAParser\Parser::parse()
2 C:\laragon\www\Portfolio\vendor\pragmarx\tracker\src\Vendor\Laravel\ServiceProvider.php:174
PragmaRX\Tracker\Support\UserAgentParser::__construct("C:\laragon\www\Portfolio")
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
Installation failed, reverting ./composer.json to its original content.
EDIT 1:
The result of composer dump-autoload is:
composer dump-autoload
Generating optimized autoload files> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
TypeError
Argument 1 passed to UAParser\Parser::parse() must be of the type string, null given, called in C:\laragon\www\Portfolio\vendor\pragmarx\tracker\src\Support\UserAgentParser.php on line 25
at C:\laragon\www\Portfolio\vendor\ua-parser\uap-php\src\Parser.php:37
33| $this->userAgentParser = new UserAgentParser($this->regexes);
34| }
35|
36| /** Sets up some standard variables as well as starts the user agent parsing process */
> 37| public function parse(string $userAgent, array $jsParseBits = []): Client
38| {
39| $client = new Client($userAgent);
40|
41| $client->ua = $this->userAgentParser->parseUserAgent($userAgent, $jsParseBits);
1 C:\laragon\www\Portfolio\vendor\pragmarx\tracker\src\Support\UserAgentParser.php:25
UAParser\Parser::parse()
2 C:\laragon\www\Portfolio\vendor\pragmarx\tracker\src\Vendor\Laravel\ServiceProvider.php:174
PragmaRX\Tracker\Support\UserAgentParser::__construct("C:\laragon\www\Portfolio")
Script #php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

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

can not find class of 2amigos

PHP Fatal Error – yii\base\ErrorException Class 'Da\QrCode\QrCode'
not found
code fires the Err in my TaolistController.php
use Da\QrCode\QrCode;
public function actionGenQrcode(){
$qrCode = (new QrCode($kaSTR))//right here
->setSize(250)
->setMargin(5)
->useForegroundColor(51, 153, 255);
}
I've used composer to add 2amigos.
C:\Users\cyh>composer require 2amigos/qrcode-library:~1.1
./composer.json has been created Loading composer repositories with
package information Updating dependencies (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
- Installing khanamiryan/qrcode-detector-decoder (1): Downloading (100%)
- Installing bacon/bacon-qr-code (1.0.3): Downloading (100%)
- Installing 2amigos/qrcode-library (1.1.2): Downloading (100%) Writing lock file Generating autoload files
Actually my phpstorm can find this class. I'm using yiiframework.
run the following command using terminal(CMD)
composer dump-autoload
this command will dumps the autoloaded files
if this not working try to use it like Component
http://qrcode-library.readthedocs.io/en/latest/yii/qrcode-component/
Try install QR Code library using
composer require 2amigos/qrcode-library
It works for me. Good luck.

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.

Categories