La clase StdClass de PHP

En PHP existe una clase predefinida en el lenguaje que se llama stdClass. ¿Y que hace tan especial a esta clase? Pues que no tiene ni propiedades, ni métodos, ni padre; es una clase vacía. ¿Y para que queremos esta clase si no tiene nada? Podemos usar esta clase cuando necesitamos un objeto genérico al que luego el podremos añadir propiedades. Veamos un ejemplo:
1<?php
2 
3$objecto new stdClass();
4$objeto->nombre = "Manuel";
5$objeto->apellidos "Carrascosa de la Blanca";
6$objeto->web = "http://mjcarrascosa.com";
7?>
Con este código hemos creado un objeto al que luego le hemos añadido tres atributos. Esto nos puede servir cuando queremos tener un objeto que solo tenga datos y, por la razón que sea, no queremos crear una clase específica.
Hay que tener en cuenta, y esto es muy importante, que esta clase no es la clase de la que heredan todas las clases. En PHP las clases que no heredan de ninguna clase simplemente no tienen padre. En esto PHP se diferencia de muchos lenguajes de programación, donde si una clase no tiene padre hereda automáticamente de una clase base por defecto (como en Java la clase Object).

Implementing a SOAP API with PHP ubuntu

instalar la extension soap para php:

In ubuntu to install php_soap on PHP7 use below commands. Reference
sudo apt-get install php7.0-soap
en mi caso que tengo instalado php7.2:
sudo apt-get install php7.2-soap

Crear una carpeta dentro de htdocs:

mkdir hello

Install the zend-soap library:

Dentro de la carpeta "hello" instalar via composer la libreria zend-soap (se creará los archivos composer.json y composer.lock)
composer require zendframework/zend-soap

Creating a SOAP Endpoint

The endpoint is the URL where your service can be accessed by a client application. To see the WSDL you add ?wsdl to the web service endpoint URL.
Let's create a simple hello world webservice.
Content of server.php:
  <?php

   require_once __DIR__ . '/vendor/autoload.php';

   class Hello
{
    /**
     * Say hello.
     *
     * @param string $firstName
     * @return string $greetings
     */
    public function sayHello($firstName)
    {
        return 'Hello ' . $firstName;
    }

}
 
   $serverUrl = "http://localhost/hello/server.php";
   $options = [
    'uri' => $serverUrl,
    ]; 
   $server = new Zend\Soap\Server(null, $options);

   if (isset($_GET['wsdl'])) {
     $soapAutoDiscover = new \Zend\Soap\AutoDiscover(new \Zend\Soap\Wsdl\ComplexTypeStrategy\ArrayOfTypeSequence());
     $soapAutoDiscover->setBindingStyle(array('style' => 'document'));
     $soapAutoDiscover->setOperationBodyStyle(array('use' => 'literal'));
     $soapAutoDiscover->setClass('Hello');
     $soapAutoDiscover->setUri($serverUrl);

     header("Content-Type: text/xml");
     echo $soapAutoDiscover->generate()->toXml();
}  else {
     $soap = new \Zend\Soap\Server($serverUrl . '?wsdl');
     $soap->setObject(new \Zend\Soap\Server\DocumentLiteralWrapper(new Hello()));
     $soap->handle();
   }


Open the browser to see the WSDL file: http://localhost/hello/server.php?wsdl

Creating a SOAP Client

Create a new file client.php.
File content:
   <?php

    require_once __DIR__ . '/vendor/autoload.php';

    $client = new Zend\Soap\Client('http://localhost/hello/server.php?wsdl');  
    $result = $client->sayHello(['firstName' => 'World']);

    echo $result->sayHelloResult;
The result (response) should look like this:
   Hello World

It is possible that your PHP Static Analysis Tool (e.g. phpstan) has a problem with calling $client->sayHello(...). The reason is that this method does not exist and is called internally via a magic method. To avoid this warning there is a simple trick. Instead, call the web service methods using call(method, params)-methode and simply pass the method name as a string. Note that the parameters must be passed in a double nested array.


$result = $client->call('sayHello', [['firstName' => 'World']]);
echo $result->sayHelloResult;

fuente:

https://dev.to/dopitz/implementing-a-soap-api-with-php-a3n

nota:
si despues de una primera ejecucion se quiere agregar nuevos metodos, o modificar el existente y que lo reconozca el client, se debe agregar tanto en el server como el client
la sgt linea (despues del require...) para que no lea la caché, sino no va a encontrar los nuevos metodos

ini_set('soap.wsdl_cache_enabled', '0');

xampp en ubuntu

previamente...

sudo apt install net-tools
First you should stop your apache server:
sudo /etc/init.d/apache2 stop

Step 1 – download XAMPP


For PHP 7



wget https://www.apachefriends.org/xampp-files/7.2.2/xampp-linux-x64-7.2.2-0-installer.run


Step 2 – Executeable permission

For PHP 7

Do execute the downloaded installer, we need to set executable permissions on it.
chmod +x xampp-linux-x64-7.2.2-0-installer.run

Step 3 – Install XAMPP

For PHP 7

sudo ./xampp-linux-x64-7.2.2-0-installer.run

Step 4 – Start XAMPP

To start all the service (packaged inside XAMPP)

sudo /opt/lampp/xampp start

To stop XAMPP

sudo /opt/lampp/xampp stop
Para poder acceder a las carpetas donde se alojaran las aplicaciones (htdocs)
  1. In the linux terminal navigate to your lampp directory.
    cd /opt/lampp
  2. In the command line type:
    sudo chmod 777 -R htdocs
si todo salió ok, se debería poder acceder desde el navegador a: 

 http://localhost


Step 5 – Change service port (optional)

The location of conf can vary – for our case you can find it at /opt/lampp/etc/httpd.conf. Open the file using editor of your choice, find and update the ‘Listen 80’, replace 80 with port of your choice.

wsdl

The WSDL file is written in plain old XML. The reason that it is in XML is so that the file can be read by any programming language.
<definitions name = "HelloService"
   targetNamespace = "http://www.examples.com/wsdl/HelloService.wsdl"
   xmlns = "http://schemas.xmlsoap.org/wsdl/"
   xmlns:soap = "http://schemas.xmlsoap.org/wsdl/soap/"
   xmlns:tns = "http://www.examples.com/wsdl/HelloService.wsdl"
   xmlns:xsd = "http://www.w3.org/2001/XMLSchema">
 
   <message name = "SayHelloRequest">
      <part name = "firstName" type = "xsd:string"/>
   </message>
 
   <message name = "SayHelloResponse">
      <part name = "greeting" type = "xsd:string"/>
   </message>

   <portType name = "Hello_PortType">
      <operation name = "sayHello">
         <input message = "tns:SayHelloRequest"/>
         <output message = "tns:SayHelloResponse"/>
      </operation>
   </portType>

   <binding name = "Hello_Binding" type = "tns:Hello_PortType">
      <soap:binding style = "rpc"
         transport = "http://schemas.xmlsoap.org/soap/http"/>
      <operation name = "sayHello">
         <soap:operation soapAction = "sayHello"/>
         <input>
            <soap:body
               encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"
               namespace = "urn:examples:helloservice"
               use = "encoded"/>
         </input>
  
         <output>
            <soap:body
               encodingStyle = "http://schemas.xmlsoap.org/soap/encoding/"
               namespace = "urn:examples:helloservice"
               use = "encoded"/>
         </output>
      </operation>
   </binding>

   <service name = "Hello_Service">
      <documentation>WSDL File for HelloService</documentation>
      <port binding = "tns:Hello_Binding" name = "Hello_Port">
         <soap:address
            location = "http://www.examples.com/SayHello/" />
      </port>
   </service>
</definitions>

diagram of the structure of a WSDL file
WSDL – Web services description language

WSDL Elements

The WSDL file contains the following main parts
  1. The <types> tag is used to define all the complex datatypes, which will be used in the message exchanged between the client application and the web service. This is an important aspect of the client application, because if the web service works with a complex data type, then the client application should know how to process the complex data type. Data types such as float, numbers, and strings are all simple data types, but there could be structured data types which may be provided by the web service.
    For example, there could be a data type called EmployeeDataType which could have 2 elements called "EmployeeName" of type string and "EmployeeID" of type number or integer. Together they form a data structure which then becomes a complex data type.
  2. The <messages> tag is used to define the message which is exchanged between the client application and the web server. These messages will explain the input and output operations which can be performed by the web service. An example of a message can be a message which accepts the EmployeeID of an employee, and the output message can be the name of the employee based on the EmpoyeeID provided. For each web method, there are 2 messages, one is for the input, and the other is for the output. Together they form an operation.WSDL – Web services description language
  3. The <portType> tag is used to encapsulate every input and output message into one logical operation. So there could be an operation called "GetEmployee" which combines the input message of accepting the EmployeeID from a client application and then sending the EmployeeName as the output message.
  4. The <binding> tag is used to bind the operation to the particular port type It is used to define how the messages will be transferred. This is so that when the client application calls the relevant port type, it will then be able to access the operations which are bound to this port type. Port types are just like interfaces. So if a client application needs to use a web service they need to use the binding information to ensure that they can connect to the interface provided by that web service.WSDL – Web services description language
  5. The <service> tag is a name given to the web service itself. Initially, when a client application makes a call to the web service, it will do by calling the name of the web service. For example, a web service can be located at an address such as http://localhost/Guru99/Tutorial.asmx . The service tag will actually have the URL defined as http://localhost/Guru99/Tutorial.asmx, which will actually tell the client application that there is a web service available at this location.

linux ubuntu mint actualizar chrome

 desde una terminal: $ sudo apt update $ sudo apt install google-chrome-stable