Create WSDL File For SoapServer EndPoint PHP File - php

i wanna create wsdl file for my php end point.
this is my php end point class with two function:
class server{
private $UserIdSender;
private $UserIdReciver;
private $Title;
private $Body;
private $BoardId;
private $obj_ticket;
private $obj_ticket_owner;
private $ticket_id;
public function __construct() {
date_default_timezone_set("Asia/Tehran");
require_once "../../diba-modules/conf.php";
require_once "../../diba-modules/functions.php";
require_once "../../diba-include/entities/ticket.php";
require_once "../../diba-include/entities/ticket_owner.php";
$this->obj_ticket = new \entities\ticket(TRUE);
$this->obj_ticket_owner = new \entities\ticket_owner(TRUE);
mb_internal_encoding("UTF-8");
}
/*public board = 17*/
public function SaveTicketFromPortal($Token,$NationalCodeSender , $NationalCodeReciver , $Title , $Body = "" , $BoardId = 17 ){
$this->UserIdSender = get_id_from_national_code($NationalCodeSender);
$this->UserIdReciver = get_id_from_national_code($NationalCodeReciver);
$this->Title = trim(filter_var($Title,FILTER_SANITIZE_STRING));
$this->Body = trim(filter_var($Body,FILTER_SANITIZE_STRING));
$this->BoardId = filter_var($BoardId,FILTER_SANITIZE_NUMBER_INT);
if($this->UserIdSender <= 0 ){
return array("Success" => "-1" , "Message" => "Sender NationalCode Not Found !" );
}elseif($this->UserIdReciver <= 0 ){
return array("Success" => "-1" , "Message" => "Reciver NationalCode Not Found !" );
} elseif(mb_strlen($this->Title)>500){
return array("Success" => "-1" , "Message" => "OverFlow in Ticket Title Variable! Type Of Variable Is String(500) " );
}elseif(mb_strlen($this->Body)>3000){
return array("Success" => "-1" , "Message" => "OverFlow in Ticket Body Variable! Type Of Variable Is String(3000) " );
}elseif(!is_numeric($this->BoardId) ){
return array("Success" => "-1" , "Message" => "BoardId Should Be Number!" );
}else{
$this->ticket_id = $this->obj_ticket->save(NULL, $this->Title, $this->Body, $this->UserIdSender , date("Y-m-d H:i:s"), "" , 3 , 0 , $this->BoardId);
$this->obj_ticket_owner->save(NULL, $this->ticket_id, $this->UserIdReciver, date("Y-m-d H:i:s"), 3, 0, 1);
if($this->obj_ticket->flage && $this->obj_ticket_owner->flage){
$this->obj_ticket->commit(TRUE);
$this->obj_ticket_owner->commit(TRUE);
$boardname = get_board_name($this->BoardId);
$robot_msg = "\xF0\x9F\x93\xA2 Your Ticket Has Been Successfuly Refrenced From Portal. \n\x23\xE2\x83\xA3 $this->ticket_id \n\xF0\x9F\x93\x8B Board $boardname";
send_with_telegram($this->UserIdReciver, $robot_msg,$this->UserIdSender);
return array("Success" => "1" , "Message" => "Your Ticket Has Been Successfuly Refrenced." );
}else{
$this->obj_ticket->commit(FALSE);
$this->obj_ticket_owner->commit(FALSE);
return array("Success" => "-1" , "Message" => "Error In Ticket Referrals!" );
}
}
}
public function SaveTicketFromPortalResponse($Token){
}
}
$params=array("uri"=>"http://127.0.0.1/board/my-webservice/portal/server.php");
$server = new SoapServer(NULL,$params);
$server->setClass("server");
$server->handle();
when i use address "server.php?wsdl" for call my Soap Function from asp.net i recive a error like this :
WSDL generation is no supported yet.!
please help.
its emergency.
thanks a lot.

i found it =>
wsdl.php
<?php
$functions = array();
$serviceName = "My Webservice For Recive Data From Portal";
$functions[] = array("funcName" => "SaveTicketFromPortal",
"doc" => "My Webservice For Recive Data From Portal",
"inputParams" => array(array("name" => "Token", "type" => "string"),
array("name" => "NationalCodeSender", "type" => "string"),
array("name" => "NationalCodeReciver", "type" => "string"),
array("name" => "Title", "type" => "string"),
array("name" => "Body", "type" => "string")
),
"outputParams" => array(array("name" => "Success", "type" => "string"),
array("name" => "Message" ,"type" => "string" )),
"soapAddress" => "http://192.168.10.16/board/my-webservice/portal/server.php"
);
$functions[] = array("funcName" => "SetState",
"doc" => "To Change Ticket State From Todo To Doing And Done",
"inputParams" => array(array("name" => "Token", "type" => "string"),
array("name" => "TicketId", "type" => "string"),
array("name" => "NationalCode", "type" => "string"),
array("name" => "StateId", "type" => "string")),
"outputParams" => array(array("name" => "Success", "type" => "string"),
array("name" => "Message" ,"type" => "string" )),
"soapAddress" => "http://192.168.10.16/board/my-webservice/portal/server.php"
);
if (stristr($_SERVER['QUERY_STRING'], "wsdl")) {
// WSDL request - output raw XML
header("Content-Type: application/soap+xml; charset=utf-8");
echo DisplayXML();
} else {
// Page accessed normally - output documentation
$cp = substr($_SERVER["SCRIPT_NAME"], strrpos($_SERVER["SCRIPT_NAME"], "/") + 1); // Current page
echo '<!-- Attention: To access via a SOAP client use ' . $cp . '?WSDL -->';
echo '<html>';
echo '<head><title>' . $serviceName . '</title></head>';
echo '<body>';
echo '<h1>' . $serviceName . '</h1>';
echo '<p style="margin-left:20px;">To access via a SOAP client use <code>' . $cp . '?WSDL</code></p>';
// Document each function
echo '<h2>Available Functions:</h2>';
echo '<div style="margin-left:20px;">';
for ($i=0;$i<count($functions);$i++) {
echo '<h3>Function: ' . $functions[$i]['funcName'] . '</h3>';
echo '<div style="margin-left:20px;">';
echo '<p>';
echo $functions[$i]['doc'];
echo '<ul>';
if (array_key_exists("inputParams", $functions[$i])) {
echo '<li>Input Parameters:<ul>';
for ($j=0;$j<count($functions[$i]['inputParams']);$j++) {
echo '<li>' . $functions[$i]['inputParams'][$j]['name'];
echo ' (' . $functions[$i]['inputParams'][$j]['type'];
echo ')</li>';
}
echo '</ul></li>';
}
if (array_key_exists("outputParams", $functions[$i])) {
echo '<li>Output Parameters:<ul>';
for ($j=0;$j<count($functions[$i]['outputParams']);$j++) {
echo '<li>' . $functions[$i]['outputParams'][$j]['name'];
echo ' (' . $functions[$i]['outputParams'][$j]['type'];
echo ')</li>';
}
echo '</ul></li>';
}
echo '</ul>';
echo '</p>';
echo '</div>';
}
echo '</div>';
echo '<h2>WSDL output:</h2>';
echo '<pre style="margin-left:20px;width:800px;overflow-x:scroll;border:1px solid black;padding:10px;background-color:#D3D3D3;">';
echo DisplayXML(false);
echo '</pre>';
echo '</body></html>';
}
exit;
/*****************************************************************************
* Create WSDL XML
* #PARAM xmlformat=true - Display output in HTML friendly format if set false
*****************************************************************************/
function DisplayXML($xmlformat=true) {
global $functions; // Functions that this web service supports
global $serviceName; // Web Service ID
$i = 0; // For traversing functions array
$j = 0; // For traversing parameters arrays
$str = ''; // XML String to output
// Tab spacings
$t1 = ' ';
if (!$xmlformat) $t1 = ' ';
$t2 = $t1 . $t1;
$t3 = $t2 . $t1;
$t4 = $t3 . $t1;
$t5 = $t4 . $t1;
$serviceID = str_replace(" ", "", $serviceName);
// Declare XML format
$str .= '<?xml version="1.0" encoding="UTF-8" standalone="no"?>' . "\n\n";
// Declare definitions / namespaces
$str .= '<wsdl:definitions ' . "\n";
$str .= $t1 . 'xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" ' . "\n";
$str .= $t1 . 'xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" ' . "\n";
$str .= $t1 . 'xmlns:s="http://www.w3.org/2001/XMLSchema" ' . "\n";
$str .= $t1 . 'targetNamespace="http://www.darkerwhite.com/" ' . "\n";
$str .= $t1 . 'xmlns:tns="http://www.darkerwhite.com/" ' . "\n";
$str .= $t1 . 'name="' . $serviceID . '" ' . "\n";
$str .= '>' . "\n\n";
// Declare Types / Schema
$str .= '<wsdl:types>' . "\n";
$str .= $t1 . '<s:schema elementFormDefault="qualified" targetNamespace="http://www.darkerwhite.com/">' . "\n";
for ($i=0;$i<count($functions);$i++) {
// Define Request Types
if (array_key_exists("inputParams", $functions[$i])) {
$str .= $t2 . '<s:element name="' . $functions[$i]['funcName'] . 'Request">' . "\n";
$str .= $t3 . '<s:complexType><s:sequence>' . "\n";
for ($j=0;$j<count($functions[$i]['inputParams']);$j++) {
$str .= $t4 . '<s:element minOccurs="1" maxOccurs="1" ';
$str .= 'name="' . $functions[$i]['inputParams'][$j]['name'] . '" ';
$str .= 'type="s:' . $functions[$i]['inputParams'][$j]['type'] . '" />' . "\n";
}
$str .= $t3 . '</s:sequence></s:complexType>' . "\n";
$str .= $t2 . '</s:element>' . "\n";
}
// Define Response Types
if (array_key_exists("outputParams", $functions[$i])) {
$str .= $t2 . '<s:element name="' . $functions[$i]['funcName'] . 'Response">' . "\n";
$str .= $t3 . '<s:complexType><s:sequence>' . "\n";
for ($j=0;$j<count($functions[$i]['outputParams']);$j++) {
$str .= $t4 . '<s:element minOccurs="1" maxOccurs="1" ';
$str .= 'name="' . $functions[$i]['outputParams'][$j]['name'] . '" ';
$str .= 'type="s:' . $functions[$i]['outputParams'][$j]['type'] . '" />' . "\n";
}
$str .= $t3 . '</s:sequence></s:complexType>' . "\n";
$str .= $t2 . '</s:element>' . "\n";
}
}
$str .= $t1 . '</s:schema>' . "\n";
$str .= '</wsdl:types>' . "\n\n";
// Declare Messages
for ($i=0;$i<count($functions);$i++) {
// Define Request Messages
if (array_key_exists("inputParams", $functions[$i])) {
$str .= '<wsdl:message name="' . $functions[$i]['funcName'] . 'Request">' . "\n";
$str .= $t1 . '<wsdl:part name="parameters" element="tns:' . $functions[$i]['funcName'] . 'Request" />' . "\n";
$str .= '</wsdl:message>' . "\n";
}
// Define Response Messages
if (array_key_exists("outputParams", $functions[$i])) {
$str .= '<wsdl:message name="' . $functions[$i]['funcName'] . 'Response">' . "\n";
$str .= $t1 . '<wsdl:part name="parameters" element="tns:' . $functions[$i]['funcName'] . 'Response" />' . "\n";
$str .= '</wsdl:message>' . "\n\n";
}
}
// Declare Port Types
for ($i=0;$i<count($functions);$i++) {
$str .= '<wsdl:portType name="' . $functions[$i]['funcName'] . 'PortType">' . "\n";
$str .= $t1 . '<wsdl:operation name="' . $functions[$i]['funcName'] . '">' . "\n";
if (array_key_exists("inputParams", $functions[$i]))
$str .= $t2 . '<wsdl:input message="tns:' . $functions[$i]['funcName'] . 'Request" />' . "\n";
if (array_key_exists("outputParams", $functions[$i]))
$str .= $t2 . '<wsdl:output message="tns:' . $functions[$i]['funcName'] . 'Response" />' . "\n";
$str .= $t1 . '</wsdl:operation>' . "\n";
$str .= '</wsdl:portType>' . "\n\n";
}
// Declare Bindings
for ($i=0;$i<count($functions);$i++) {
$str .= '<wsdl:binding name="' . $functions[$i]['funcName'] . 'Binding" type="tns:' . $functions[$i]['funcName'] . 'PortType">' . "\n";
$str .= $t1 . '<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />' . "\n";
$str .= $t1 . '<wsdl:operation name="' . $functions[$i]['funcName'] . '">' . "\n";
$str .= $t2 . '<soap:operation soapAction="' . $functions[$i]['soapAddress'] . '#' . $functions[$i]['funcName'] . '" style="document" />' . "\n";
if (array_key_exists("inputParams", $functions[$i]))
$str .= $t2 . '<wsdl:input><soap:body use="literal" /></wsdl:input>' . "\n";
if (array_key_exists("outputParams", $functions[$i]))
$str .= $t2 . '<wsdl:output><soap:body use="literal" /></wsdl:output>' . "\n";
$str .= $t2 . '<wsdl:documentation>' . $functions[$i]['doc'] . '</wsdl:documentation>' . "\n";
$str .= $t1 . '</wsdl:operation>' . "\n";
$str .= '</wsdl:binding>' . "\n\n";
}
// Declare Service
$str .= '<wsdl:service name="' . $serviceID . '">' . "\n";
for ($i=0;$i<count($functions);$i++) {
$str .= $t1 . '<wsdl:port name="' . $functions[$i]['funcName'] . 'Port" binding="tns:' . $functions[$i]['funcName'] . 'Binding">' . "\n";
$str .= $t2 . '<soap:address location="' . $functions[$i]['soapAddress'] . '" />' . "\n";
$str .= $t1 . '</wsdl:port>' . "\n";
}
$str .= '</wsdl:service>' . "\n\n";
// End Document
$str .= '</wsdl:definitions>' . "\n";
if (!$xmlformat) $str = str_replace("<", "<", $str);
if (!$xmlformat) $str = str_replace(">", ">", $str);
if (!$xmlformat) $str = str_replace("\n", "<br />", $str);
return $str;
}
?>

Related

Why isn't my Azure SAS Token Signature matching?

This is the error returned when I try to access a blob in storage:
Code: AuthenticationFailed
Message: Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
AuthenticationErrorDetail: Signature did not match. String to sign used was xxstorageaccount rwdlac b sco 2017-08-17T21:29:24Z 2017-08-17T21:34:24Z https 2017-04-17
Here's my code:
$storageAccount = config('azure.storage.account');
$start = new \DateTime();
$end = (new \DateTime())->modify('+5 minutes');
$start = $start->format('Y-m-d\TH:i:s\Z');
$end = $end->format('Y-m-d\TH:i:s\Z');
$toSign = $storageAccount . "\n";
$toSign .= "rwdlac" . "\n";
$toSign .= "b" . "\n";
$toSign .= "sco" . "\n";
$toSign .= $start . "\n";
$toSign .= $end . "\n";
$toSign .= "\n";
$toSign .= "https" . "\n";
$toSign .= "2017-04-17" . "\n";
$signature = rawurlencode(base64_encode(hash_hmac('sha256', $toSign, $sasKeyValue, TRUE)));
$token = "?sv=2017-04-17&ss=b&srt=sco&sp=rwdlac&se=" . $end . "&st=" . $start . "&spr=https&sig=" . $signature;
return $uri . $token;
You could do 2 things to avoid this error.
Convert start and end time to GMT time via setTimezone() function or consider using the gmdate function instead.
Decode base64 account key through base64_decode() function.
Please change your code like the following:
$storageAccount = config('azure.storage.account');
$start = (new \DateTime())->setTimezone(new DateTimeZone('GMT'));
$end = (new \DateTime())->setTimezone(new DateTimeZone('GMT'))->modify('+5 minutes');
$start = $start->format('Y-m-d\TH:i:s\Z');
$end = $end->format('Y-m-d\TH:i:s\Z');
$toSign = $storageAccount . "\n";
$toSign .= "rwdlac" . "\n";
$toSign .= "b" . "\n";
$toSign .= "sco" . "\n";
$toSign .= $start . "\n";
$toSign .= $end . "\n";
$toSign .= "\n";
$toSign .= "https" . "\n";
$toSign .= "2017-04-17" . "\n";
$signature = rawurlencode(base64_encode(hash_hmac('sha256', $toSign, base64_decode($sasKeyValue), TRUE)));
$token = "?sv=2017-04-17&ss=b&srt=sco&sp=rwdlac&se=" . $end . "&st=" . $start . "&spr=https&sig=" . $signature;
return $uri . $token;

Php Code (Get/Fetch Kongregate Games)

Can you help me there is a problem that is detect by php when execute but I think my code is okay.
The error say "Catchable fatal error: Object of class stdClass could not be converted to string in C:\Program Files\wamp\www\getkongregate.php on line 46"
Website of kongregate xml: here
This is the code I have:
<?php
$xml = simplexml_load_string(file_get_contents('http://www.kongregate.com/games_for_your_site.xml'));
$json = json_encode($xml);
$games = json_decode($json);
$count = 0;
foreach ($games->game as $game) {
echo $game->id . "\n";
echo $game->title . "\n";
echo $game->thumbnail . "\n";
echo $game->launch_date . "\n";
echo $game->category . "\n";
if (array_key_exists('screenshot',$game)) {
for($i=0;$i<=(count($game->screenshot)-1);$i++) {
echo $game->screenshot[$i] . "\n";
}
}
echo $game->flash_file . "\n";
echo $game->width . "\n";
echo $game->height . "\n";
echo $game->description . "\n";
echo $game->instructions . "\n";
echo $game->gameplays . "\n";
echo $game->rating . "\n\n------\n\n";
if ($count == 100) {break;}
$count++;
}
?>
You are retreiving xml.
Why are you parsing it as json?
Use SimpleXmlElement instead and then iterate through xml elements to retreive your data.
$xml = file_get_contents($map_url);
$simpleXmlElement = simplexml_load_string($xml);
var_dump($simpleXmlElement);
Here: :)
$url = 'http://www.kongregate.com/games_for_your_site.xml';
$content = file_get_contents($url)
$xml = simplexml_load_string($content);
$count = 0;
foreach ($xml as $game) {
echo strval($game->id) . PHP_EOL;
echo strval($game->title) . PHP_EOL;
echo strval($game->thumbnail) . PHP_EOL;
echo strval($game->launch_date) . PHP_EOL;
echo strval($game->category) . PHP_EOL;
if (isset($game->screenshot) && is_array($game->screenshot)) {
foreach ($game->screenshot as $screenshot) {
echo strval($screenshot) . "\n";
}
}
echo strval($game->flash_file) . PHP_EOL;
echo strval($game->width) . PHP_EOL;
echo strval($game->height) . PHP_EOL;
echo strval($game->description) . PHP_EOL;
echo strval($game->instructions) . PHP_EOL;
echo strval($game->gameplays) . PHP_EOL;
echo strval($game->rating) . PHP_EOL;
if ($count >= 100) {
break;
}
$count++;
}

Associate attributes with products in opencart to generate xml file

The past couple of hours I am trying to generate an xml file like this
<?xml version="1.0" encoding="UTF-8"?>
<mywebstore>
<created_at>2010-04-08 12:32</created_at>
<products>
<product>
<id>322233</id>
<name><![CDATA[MadBiker 600 Black Polarized]]></name>
<link><![CDATA[http://www.mywebstore.gr/product/322233]]></link>
<image><![CDATA[http://www.mywebstore.gr/product/322233.jpg]]></image>
<category id="23"><![CDATA[Sports > Extreme Sports]]></category>
<price_with_vat>322.33</price_with_vat>
<manufacturer><![CDATA[SuperGlasses]]></manufacturer>
<description><![CDATA[This is the description.....]]></description>
<weight>350</weight>
<mpn>ZHD332</mpn>
<instock>N</instock>
<availability>Pre-order</availability>
</product>
<product>
...
</product>
</products>
</mywebstore>
from opencart.
I have written this piece of code
<?php
class ControllerFeedSkroutzXml extends Controller {
public function index() {
$this->language->load('feed/skroutz_xml');
if ($this->config->get('skroutz_xml_status')) {
$output = '<?xml version="1.0" encoding="UTF-8"?>';
$output .= '<mywebstore>';
$output .= '<created_at>' . date('Y-m-d H:i') . '</created_at>';
$output .= '<products>';
$this->load->model('catalog/product');
$products = $this->model_catalog_product->getProducts();
foreach ($products as $product) {
$attribute_groups = $this->model_catalog_product->getProductAttributes($product['product_id']);
//print_r($attribute_groups);
if (!empty($attribute_groups)) {
foreach ($attribute_groups as $attribute_group) {
if (!empty($attribute_group)) {
foreach ($attribute_group['attribute'] as $attribute) {
$attribute = array_filter($attribute);
if (!empty($attribute)) {
// [attribute_id] => 13, Color
if ($attribute['attribute_id'] == 13 && $attribute['text'] != '') {
$attribute_color = $attribute['text'];
}
// [attribute_id] => 16, Lens Technology
if ($attribute['attribute_id'] == 16 && $attribute['text'] != '') {
$attribute_lens_technology = $attribute['text'];
}
}
}
}
}
}
if ($product['special']) {
$final_price = number_format((float)$product['special'], 2, '.', '');
} else {
$final_price = number_format((float)$product['price'], 2, '.', '');
}
if ($product['quantity'] > 0) {
$instock = $this->language->get('instock_Y');
} else {
$instock = $this->language->get('instock_N');
}
$output .= '<product>';
$output .= '<id>' . $product['product_id'] . '</id>';
$output .= '<name><![CDATA[' . $this->language->get('category_name') . ' ' . $product['name'] . ' ' . $attribute_color . ' ' . $attribute_lens_technology . ']]></name>';
$output .= '<link><![CDATA[' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . ']]></link>';
$output .= '<image><![CDATA['. HTTP_IMAGE . $product['image'] . ']]></image>';
$output .= '<category id="' . $product['manufacturer_id'] . '"><![CDATA[ ' . $this->language->get('category_name') . ' > ' . $product['manufacturer'] . ' ]]></category>';
$output .= '<price_with_vat>' . $final_price . '</price_with_vat>';
$output .= '<manufacturer><![CDATA[' . $product['manufacturer'] . ']]></manufacturer>';
$output .= '<description><![CDATA[' . $product['meta_description'] . ']]></description>';
$output .= '<instock>' . $instock . '</instock>';
$output .= '<availability>' . $product['stock_status'] . '</availability>';
$output .= '</product>';
}
$output .= '</products>';
$output .= '</mywebstore>';
$this->response->addHeader('Content-Type: application/xml');
$this->response->setOutput($output);
}
}
}
?>
But the block of code that generates the attributes it doesn't work as expected.
A lot of my products don't have attributes (at least not yet), so what I want to accomplish is to show attributes right next to the name of the product
Example
Name: MadBiker 600
Attribute - Color: Black
Attribute - Lens Technology : Polarized
All together <name>MadBiker 600 Black Polarized</name>
Only if a product has attributes!
The above php code generates the <name>MadBiker 600 Black Polarized</name> to all empty of attributes products until it finds the next product with an attribute!
Could someone please point out where is the problem?
Thank you!
You aren't resetting the $attribute_lens_technology and $attribute_color with each iteration of the foreach. You need to reset these after the foreach loop definition
New foreach loop:
foreach ($products as $product) {
$attribute_lens_technology = false;
$attribute_color = false;
$attribute_groups = $this->model_catalog_product->getProductAttributes($product['product_id']);
//print_r($attribute_groups);
if (!empty($attribute_groups)) {
foreach ($attribute_groups as $attribute_group) {
if (!empty($attribute_group)) {
foreach ($attribute_group['attribute'] as $attribute) {
$attribute = array_filter($attribute);
if (!empty($attribute)) {
// [attribute_id] => 13, Color
if ($attribute['attribute_id'] == 13 && $attribute['text'] != '') {
$attribute_color = $attribute['text'];
}
// [attribute_id] => 16, Lens Technology
if ($attribute['attribute_id'] == 16 && $attribute['text'] != '') {
$attribute_lens_technology = $attribute['text'];
}
}
}
}
}
}
if ($attribute_lens_technology === false || $attribute_color === false) {
// Code here such as continue; if you want to skip products without both attributes
}
if ($product['special']) {
$final_price = number_format((float)$product['special'], 2, '.', '');
} else {
$final_price = number_format((float)$product['price'], 2, '.', '');
}
if ($product['quantity'] > 0) {
$instock = $this->language->get('instock_Y');
} else {
$instock = $this->language->get('instock_N');
}
$output .= '<product>';
$output .= '<id>' . $product['product_id'] . '</id>';
$output .= '<name><![CDATA[' . $this->language->get('category_name') . ' ' . $product['name'] . ' ' . $attribute_color . ' ' . $attribute_lens_technology . ']]></name>';
$output .= '<link><![CDATA[' . $this->url->link('product/product', 'product_id=' . $product['product_id']) . ']]></link>';
$output .= '<image><![CDATA['. HTTP_IMAGE . $product['image'] . ']]></image>';
$output .= '<category id="' . $product['manufacturer_id'] . '"><![CDATA[ ' . $this->language->get('category_name') . ' > ' . $product['manufacturer'] . ' ]]></category>';
$output .= '<price_with_vat>' . $final_price . '</price_with_vat>';
$output .= '<manufacturer><![CDATA[' . $product['manufacturer'] . ']]></manufacturer>';
$output .= '<description><![CDATA[' . $product['meta_description'] . ']]></description>';
$output .= '<instock>' . $instock . '</instock>';
$output .= '<availability>' . $product['stock_status'] . '</availability>';
$output .= '</product>';
}
It's easier to write an xml file using simplexml than it is to manually try and output your own.
Nevertheless, here's a simple shorthand if statement to fix to your problem though (if attribute color is empty, it will append an empty string instead:
$output .= !empty($attribute_color) ? '<name><![CDATA[' . $this->language->get('category_name') . ' ' . $product['name'] . ' ' . $attribute_color . ' ' . $attribute_lens_technology . ']]></name>' : '';

Could not convert object to string

So I I've tried to make this code log an exception but it gives me the error message object of class domain_model could not be converted to string
The function looks as follows:
function errorLog($log, $error_type, $string, $file, $row, $error_hash, $error_trace)
{
$text = $error_hash . ' (' . date('Y-m-d H:i') . "):\n[Error type]: " . $error_type . "\n[Message]: " . $string . "\n[File]: " . $file . "\n[Row]: " . $row . "\n";
$text .= "[Trace]:\n";
foreach ($error_trace as $t)
{
$text .= ((isset($t['type']) && isset($t['object'])) ? $t['object'] . $t['type'] . $t['function'] : $t['function']) . "\n";
$text .= $t['file'] . "\n";
$text .= $t['line'] . "\n";
$text .= print_r($t['file'], 1) . "\n";
}
file_put_contents(BASE . $log . '.log', $text, FILE_APPEND);
}
After alot of thinking eventually saw that the line in making a mess is infact this one:
$text .= ((isset($t['type']) && isset($t['object'])) ? $t['object'] . $t['type'] . $t['function'] : $t['function']) . "\n";
And as I see it the only one in need of conversion should be $t['object'] however using (string)$t['object'] didn't work and still gives me the same error. Is there any other solution on how to convert it to a string than this?
I've looked at how they suggest it to be done here

PHP operator confusion (a beginner's question)

I'm trying to figure out someone else's code and have come across this piece of code:
$html = '<div class="event">' . "\n";
if (get ( 'Event_Image' ))
{
$html .= '<a href="' . get ( 'Event_Image' ) . '">'
. '<img src="' . pt () . '?src=' . get ( 'Event_Image' ) . '&w=100" alt="' . get_the_title () . '" />'
. '</a><br />' . "\n";
}
$html .= '<a href="' . get_permalink ( $eventId ) . '">' . // title="Permanent Link to ' . get_the_title_attribute() . '"
get_the_title () . '</a><br />' . "\n";
if (get ( 'Event_Time' ))
{
$html .= get ( 'Event_Time' ) . '<br />' . "\n";
}
if (get ( 'Store_Location' ))
{
$html .= get ( 'Store_Location' );
}
$html .= '</div><!-- event -->' . "\n";
$eventsArr [$dateArr] [$eventId] = $html;
}
My question: What does the .= mean? Does it add to the variable (in this case $html)?
Yes. See http://www.php.net/manual/en/language.operators.string.php.
It means concatenate/append the value on the right hand to the value stored in the variable:
$a = 'str';
$a .= 'ing';
echo $a; // string
Yes, you got it right, here is an example:
$str = 'Hello ';
$str .= 'World';
echo $str;
Result:
Hello World
It means concatinate equals. So
$var = 'foo';
$var .= 'bar';
echo $var;
// output is 'foobar'
It is concatenate, then assign.
Same as:
$html = $html . $someString;

Categories