/** * Place a new order. * * @param CartType $cart urn::cartNS The ticker symbol. * @param CustomerType $customer urn::customerNS The customer data. * @return integer The order id. */ public function placeNewOrder($cart, $customer) { $order = SCA::createDataObject('urn::orderNS', 'OrderType'); $order->orderId = time(); $order->status = 'NONE'; foreach ($cart->item as $item_in_cart) { // TODO is a all-in-one copy from one NS to another in the wishlist? $item_in_order = $order->createDataObject('item'); $item_in_order->itemId = $item_in_cart->itemId; $item_in_order->description = $item_in_cart->description; $item_in_order->price = $item_in_cart->price; $item_in_order->quantity = $item_in_cart->quantity; $item_in_order->warehouseId = $item_in_cart->warehouseId; } $order->customer = $customer; $payment = $order->customer->payment; unset($order->customer->payment); // don't send the payment details to the warehouse $payment->paymentId = $order->orderId; // Send the order to the warehouse for processing $this->warehouse->fulfillOrder($order); // Log an event to say it's been sent to the warehouse $order->status = 'RECEIVED'; $this->event_log->logEvent($order, "Order awaiting dispatch from warehouse."); // Send a payment request to the payment provider $this->payment->directPayment($payment); // Log an event to say the payment has been requested $order->status = 'INVOICED'; $this->event_log->logEvent($order, "Payment taken."); return $order->orderId; }
/** * Create and return a person SDO * * @return personType personNamespace */ public function reply() { $person = SCA::createDataObject('PersonNamespace', 'personType'); $person->name = 'William Shakespeare'; $person->dob = 'April 1564, most likely 23rd'; $person->pob = 'Stratford-upon-Avon, Warwickshire'; return $person; }
/** * @param string $name * @return HelloType http://www.example.org/Hello */ public function hello($name) { $response = SCA::createDataObject('http://www.example.org/Hello', 'HelloType'); $response->name = $name; $response->greeting = "Hello Fred"; $response->reversed = "derF olleH"; return $response; }
/** * A method that sends an email message * * @param EmailType $email http://www.example.org/email * @return EmailResponseType http://www.example.org/email */ function sendComplexMessage(SDO_DataObject $email) { //echo "Sending message $message to address $address"; $emailresponse = SCA::createDataObject("http://www.example.org/email", "EmailResponseType"); $emailresponse->address = $email->address; $emailresponse->message = $email->message; $emailresponse->reply = "local email reply"; return $emailresponse; }
/** * generats a greeting for a batch of names. * * @param string $text custom text * @param people $names http://example.org/names * @return people http://example.org/names */ function greetEveryone($text, $names) { $replies = SCA::createDataObject('http://example.org/names', 'people'); // Iterate through each names to build up the replies foreach ($names->name as $name) { $replies->name[] = $text . " {$name}"; } return $replies; }
/** * @param string $name * @return HelloType http://www.example.org/Hello */ public function hello($name) { $greeting = $this->greeting_service->greet($name); $reversed_greeting = $this->reversing_service->reverse($greeting->greeting); $response = SCA::createDataObject('http://www.example.org/Hello', 'HelloType'); $response->name = $name; $response->greeting = $greeting->greeting; $response->reversed = $reversed_greeting; return $response; }
/** * Converts an Atom Entry SDO to a Contact SDO. */ private function entryToContact($entry) { $contact = SCA::createDataObject('http://example.org/contacts', 'contact'); // Set the title (this is assumed to be the first piece of unstructured text) // We are considering ways to make this simpler in SDO. // Something like $seq->values[0], maybe. // Also, note how title and author, etc are many-valued. This is due // to limitations in xml schema's ability to model the Atom XML. // We are working on ways to improve the SDO APIs in these // circumstances. One way would be a shortcut to the first entry, so // $entry->title[0]->getSequence() and $entry->title->getSequence() // would be equivalent. $seq = $entry->title[0]->getSequence(); for ($i = 0; $i < count($seq); $i++) { if ($seq->getProperty($i) == null) { $contact->title = $seq[$i]; } } // The last part of the entry id (in uri form) is the contact id $segments = explode('/', $entry->id[0]->value); $contact->id = $segments[count($segments) - 1]; // Set the author and updated properties $contact->author = $entry->author[0]->name[0]; $contact->updated = $entry->updated[0]->value; /*****************************************************/ /* Should be able to use XPath but encountered a bug */ /* which mean xpath only searches down 1 level on */ /* open types (e.g. $div['ul/li[title="email"]'];) */ /*****************************************************/ // Get the div and then loop through the <li/>s inside the <ul/>. The // contents of each is the first peice of unstructured text. This code // assumes the span title attribute matches the contact property name. $div = $entry->content[0]->div; /**************** The xhtml should be of this form *************************/ /* <ul class="xoxo contact" title="contact" > */ /* <li class="shortname" title="shortname">shifty</li> */ /* <li class="fullname" title="fullname">Rt. Hon. Elias Shifty Esq.</li> */ /* <li class="email" title="email">shifty@uk.ibm.com</li> */ /* </ul> */ /***************************************************************************/ $ul = $div[0]->ul; $lis = $ul[0]['li']; foreach ($lis as $li) { $seq = $li->getSequence(); for ($i = 0; $i < count($seq); $i++) { if ($seq->getProperty($i) == null) { $contact->{$li->class} = $seq[$i]; } } } return $contact; }
public function retrieveOrdersByStatus($status) { $files = $this->_order_files(); $xmldas = SDO_DAS_XML::create(dirname(__FILE__) . '/../Schema/Order.xsd'); $orders = SCA::createDataObject('urn::orderNS', 'OrdersType'); foreach ($files as $file) { $xdoc = $xmldas->loadFile(dirname(__FILE__) . '/Orders/' . $file); $order = $xdoc->getRootDataObject(); if ($order->status == $status) { $orders->order[] = $order; } } return $orders; }
/** * Say "Hello" to a batch of names. * Note: this demonstrates how to declare data structures in * the @param and @return annotations. * * @param people $names http://example.org/names * @return people http://example.org/names */ function sayHello($names) { /*********************************************************************/ /* Creating an SDO for the replies. This is not strictly necessary */ /* but is done to demonstate how a service gets an SDO for a type it */ /* declares in the @types annotation. */ /*********************************************************************/ $replies = SCA::createDataObject('http://example.org/names', 'people'); // Iterate through each names to build up the replies foreach ($names->name as $name) { $replies->name[] = "Hello {$name}"; } return $replies; }
/** * A method that provides a complex interface and uses a complex interface * * @param EmailType $email http://www.example.org/email * @return EmailResponseListType http://www.example.org/email */ function test(SDO_DataObject $email) { $json_response = $this->email_service->sendComplexMessage($email); $email_response_list = SCA::createDataObject("http://www.example.org/email", "EmailResponseListType"); $email_response = SCA::createDataObject("http://www.example.org/email", "EmailResponseType"); $email_response->address = "Address 1"; $email_response->message = "Message 1"; $email_response->reply = "Reply 1"; $email_response_list->jsonemail[] = $email_response; $email_response = SCA::createDataObject("http://www.example.org/email", "EmailResponseType"); $email_response->address = "Address 2"; $email_response->message = "Message 2"; $email_response->reply = "Reply 2"; $email_response_list->jsonemail[] = $email_response; return $email_response_list; }
/** * Retrieve contact details * * @param string $shortname The short name of the contact * @return contact http://example.org/contacts The full contact details */ public function retrieve($shortname) { try { SCA::$logger->log("Retrieve details for shortname {$shortname}"); $dbh = new PDO(PDO_DSN, DATABASE_USER, DATABASE_PASSWORD); $stmt = $dbh->prepare('SELECT * FROM contact WHERE shortname = ?'); $stmt->execute(array($shortname)); $row = $stmt->fetch(); $contact = SCA::createDataObject('http://example.org/contacts', 'contact'); $contact->shortname = $shortname; if ($row) { SCA::$logger->log("Contact found {$shortname} = " . $row['FULLNAME'] . " " . $row['EMAIL']); //trigger_error("Contact found: " . $shortname); $contact->fullname = $row['FULLNAME']; $contact->email = $row['EMAIL']; } $dbh = 0; return $contact; } catch (Exception $ex) { SCA::$logger->log("Exception on database read = " . $ex); } }
/** * List all the items in the collection */ function enumerate() { try { $dbh = new PDO(PDO_DSN, DATABASE_USER, DATABASE_PASSWORD, array(PDO::ERRMODE_EXCEPTION => true)); // TODO: paging $stmt = $dbh->prepare('SELECT * FROM contact ORDER BY updated DESC'); $stmt->execute(); $contacts = null; while ($row = $stmt->fetch()) { if ($contacts == null) { $contacts = SCA::createDataObject('http://example.org/contacts', 'contacts'); } $contact = $contacts->createDataObject('contact'); $contact->id = $row['id']; $contact->title = $row['title']; $contact->author = $row['author']; $contact->updated = $row['updated']; $contact->shortname = $row['shortname']; $contact->fullname = $row['fullname']; $contact->email = $row['email']; } $dbh = 0; return $contacts; } catch (PDOException $e) { // TODO: logging // We should just log the info in the PDOException. To flow // database info back to the client would break encapsulation. throw new SCA_NotFoundException(); } }
private static function ToSDO($p_resultSet, $p_setTypeName, $p_elementTypeName, $p_mapping) { return Util::ToSDO($p_resultSet, SCA::createDataObject('http://pety.homelinux.org/CloudBank/LedgerAccountService', is_null($p_setTypeName) ? $p_elementTypeName : $p_setTypeName), is_null($p_setTypeName) ? NULL : $p_elementTypeName, $p_mapping); }
/** * A method that sends an email message * * @param EmailType $email http://www.example.org/email * @return EmailResponseListType http://www.example.org/email */ function sendComplexMessageResponseList(SDO_DataObject $email) { $email_response_list = SCA::createDataObject("http://www.example.org/email", "EmailResponseListType"); $json_response = $this->email_service->sendComplexMessage($email); $email_response_list->jsonemail[] = clone $json_response; // the response types don't match here because we have not // specified @types in the another_maile_service reference $json_response = $this->another_email_service->sendComplexMessage($email); $email_response = SCA::createDataObject("http://www.example.org/email", "EmailResponseType"); $email_response->address = $json_response->address; $email_response->message = $json_response->message; $email_response->reply = $json_response->reply . " SMD with no @types"; $email_response_list->jsonemail[] = $email_response; $json_response = $this->hello_service->sayHello("Fred"); $email_response = SCA::createDataObject("http://www.example.org/email", "EmailResponseType"); $email_response->address = "some address"; $email_response->message = $json_response; $email_response->reply = " SMD with no types and with no @types"; $email_response_list->jsonemail[] = $email_response; $webservice_response = $this->web_service->sendComplexMessage($email); $email_response_list->wsemail = clone $webservice_response; $local_response = $this->local_service->sendComplexMessage($email); $email_response_list->localemail = $local_response; return $email_response_list; }
/** * @param string $name * @return GreetingType http://www.example.org/Greeting */ public function greet($name) { $response = SCA::createDataObject('http://www.example.org/Greeting', 'GreetingType'); $response->greeting = 'hello ' . $name; return $response; }
private static function ToSDO($p_resultSet, $p_setTypeName, $p_elementTypeName, $p_mapping) { return Util::ToSDO($p_resultSet, SCA::createDataObject('http://pety.dynu.net/CloudBank/StatementService', is_null($p_setTypeName) ? $p_elementTypeName : $p_setTypeName), is_null($p_setTypeName) ? NULL : $p_elementTypeName, $p_mapping); }