Home php教程 php手册 使用PHP开发SCA和SDO

使用PHP开发SCA和SDO

Jun 13, 2016 am 11:01 AM
php use initiate and develop open data Serve Architecture of components For

由开放的面向服务架构联合组织(OSOA)发起的,面向组件的架构(SCA)和服务数据对象(SDO)已经成为了开发面向服务的架构的最新方法。开始时这些开发只是集中在一些通用的开发环境中,如Java和C++,目前SCA和SDO已经开始进入到其他一些平台,在这里我们将讲解如何在PHP上包含一些SOA技术。

首先我们看看SDO能提供给你什么。在一个典型的PHP应用中,数据一半来自关系数据库,但是如果这个应用程序后来不仅仅只是从这儿获取数据,而是从一个普通文本文件或者Web服务中获取数据呢?这个问题很复杂,因为每种数据源都会要求有自己的获取方式。

在这种情况下,PHP中SDO提供了一种处理数据源的透明方式。它不是单独的处理每种数据源,而是提供了一种统一的访问数据对象的方式。这种过程是通过数据访问服务(DAS)来完成的,它是SDO架构上的一种中介方式。让我们看看一个PHP中的SDO请求。

<?php<br>$providers = $company->shippingByGround;<br>foreach ($providers as $name => $value) {<br> echo "$name: $valuen";<br>}<br>?>
Copy after login

注意最后的请求是如何处理未知的数据源的,你不知道这里数据是从哪里提取来的,只是使用了PHP的SDO格式来做一个查找,而细节是由DAS完成的,PHP目前能够支持获取XML和关系数据库的数据源。

SDO关心的是数据,而SCA使用了更加通用的类和组件来完成同样的透明方式。从任何PHP类中访问已有的业务逻辑需要强制开发者来围绕一类特定的假设来做设计吗?逻辑是否已在另外一个本地PHP类中?是否在网络中存在了?是使用PHP编写的吗?

当以上提到的场景在各自的要求中是可满足的话,那么每个都需要使用不同的方法处理。

使用SCA方式,逻辑在哪里存放就无关紧要了,更不要提使用何种语言来实现。那你一定会说:“这不是和一个普通的Web Service差不多吗?没什么不同啊!”那么我们举个例子来看看PHP SCA组件里包含了什么。

<p><?php</p><p>include "SCA/SCA.php";</p><p>/**<br>* Calculate a shipment price for a given customer using a specific provider<br>*<br>* @service<br>*/<br>class ShipmentQuote {</p><p> /**<br> * The customer discount fee service to use.<br> *<br> * @reference<br> * @binding.php ../DiscountFeeRate/DiscountFeeRate.php<br> */<br> public $discountFee;</p><p> /**<br> * The shipping service to use.<br> *<br> * @reference<br> * @binding.wsdl ../Shipper/ShipperQuote.wsdl<br> */<br> public $shipper;</p><p> /**<br> * Get a quote for a given customer using a specific provider<br> *<br> * @param string $shipping The shipping company <br> * @param string $customer The customer requiring shipment, in order to obtain discount rate<br> * @return float The quote for a given customer using a certain shipping provider. <br> */<br> function getQuote($shippingCo, $customer)<br> {<br>$rateShip = $this->shipper->getShippingPrice($shippingCo);<br>$rate = $this->discountFee->getDiscountRate($customer);<br>return $rate * $rateShip;<br> }<br>}<br>?></p>
Copy after login

上文中最关键的就是包含@的语句部分,它们每个都提供了一种特定的SCA行为。最上层的@service标识,表示暴露一个类作为服务。在这个例子里,最后的getQuote函数将会是服务暴露的唯一操作,通过使用@param和@return标识。

这个最后的服务的执行或者部署——将会被委托为一个PHP SCA运行时——将会将我们带入一个创建WSDL合同的访问点,就像你可以在网络服务中看到的那样。除了这种部署服务的方式的简单性以外,SCA模型的真实优势将会在你检查getQuote代码时越发体现的明显。

注意到两个语句$this-<shipper->getShippingPrice($shippingCo)和$this->discountFee->getDiscountRate($customer),它们是基于类中前面的应用。每个应用被其支撑服务锁支持(由@reference和@binding标识来具体操作)在$discountFee用例中,这将是一个PHP类,而在shipper的用例中,这将是一个标准的WSDL基础的服务。

尽管PHP的简单和大量用户群体的支持使得它成为构建web应用的一个好的选择,但是它在企业应用的很多场景中能力有限,现在通过增加SCA和SDO,提供了对PHP和以往技术的强力支持,它也和其他主流语言一样,可以参与到面向服务的潮流中了。

【相关文章】


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

7 PHP Functions I Regret I Didn't Know Before 7 PHP Functions I Regret I Didn't Know Before Nov 13, 2024 am 09:42 AM

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

See all articles