Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

PSR-0

  • Loading branch information...
commit 6d617e14991c3f375990d4eed52ecbf41c83f523 0 parents
Pranjal Prabhash authored
34 osrf/README.md
@@ -0,0 +1,34 @@
+**openSRF**
+==================================
+openSRF is a message passing architecture. We have many message passing systems today. While browsing a bit over the internet I came across some, a few listed here *http://en.wikipedia.org/wiki/Message_passing#Message_passing_systems*. So why do we have this new message passing thing? It is basically to interact with **Evergreen, an open source Integrated Library System (ILS)**.
+
+While a complete guide to openSRF can be found at *http://journal.code4lib.org/articles/3284*, here is a quick intro to openSRF.
+>The Open Service Request Framework (or OpenSRF, pronounced “open surf”) is an inter-application message passing architecture built on XMPP (aka “jabber”). The Evergreen open source library system is built on an OpenSRF architecture to support loosely coupled individual components communicating over an OpenSRF messaging bus. This article introduces OpenSRF, demonstrates how to build OpenSRF services through simple code examples, explains the technical foundations on which OpenSRF is built, and evaluates OpenSRF’s value in the context of Evergreen. Part 1 of a 2 part article in this issue.
+
+ By Dan Scott
+
+
+Imagine an application architecture in which 10 lines of Perl or Python, using the data types native to each language, are enough to implement a method that can then be deployed and invoked seamlessly across hundreds of servers. You have just imagined developing with OpenSRF – it is truly that simple. Under the covers, of course, the OpenSRF language bindings do an incredible amount of work on behalf of the developer. An OpenSRF application consists of one or more OpenSRF services that expose methods: for example, the opensrf.simple-text demonstration service exposes the opensrf.simple-text.split() and opensrf.simple-text.reverse() methods. Each method accepts zero or more arguments and returns zero or one results. The data types supported by OpenSRF arguments and results are typical core language data types: strings, numbers, booleans, arrays, and hashes.
+
+*(source : http://docs.evergreen-ils.org/1.6/draft/html/writing_an_opensrf_service.html)*
+
+
+Introduction
+-------------
+*(extracted from **http://journal.code4lib.org/articles/3284**)*
+
+OpenSRF is a message routing network that offers scalability and failover support for individual services and entire servers with minimal development and deployment overhead. You can use OpenSRF to build loosely-coupled applications that can be deployed on a single server or on clusters of geographically distributed servers using the same code and minimal configuration changes. Although copyright statements on some of the OpenSRF code date back to Mike Rylander’s original explorations in 2000, Evergreen was the first major application to be developed with, and to take full advantage of, the OpenSRF architecture starting in 2004. The first official release of OpenSRF was 0.1 in February 2005 (http://evergreen-ils.org/blog/?p=21), but OpenSRF’s development continues a steady pace of enhancement and refinement, with the release of 1.0.0 in October 2008 and the most recent release of 1.2.2 in February 2010.
+
+OpenSRF is a distinct break from the architectural approach used by previous library systems and has more in common with modern Web applications. The traditional “scale-up” approach to serve more transactions is to purchase a server with more CPUs and more RAM, possibly splitting the load between a Web server, a database server, and a business logic server. Evergreen, however, is built on the Open Service Request Framework (OpenSRF) architecture, which firmly embraces the “scale-out” approach of spreading transaction load over cheap commodity servers. The initial GPLS PINES hardware cluster, while certainly impressive, may have offered the misleading impression that Evergreen requires a lot of hardware to run. However, Evergreen and OpenSRF easily scale down to a single server; many Evergreen libraries run their entire library system on a single server, and most OpenSRF and Evergreen development occurs on a virtual machine running on a single laptop or desktop image.
+
+Library
+-------
+
+The working of this library is explained in the *docs/* directory
+
+Testing
+--------
+
+There are test servers freely available, which can be used to test the code. Test servers can be found at *http://open-ils.org/dokuwiki/doku.php?id=community_servers*
+
+If you still have any questions or doubts, you are free to talk to **Evergreen, an open source Integrated Library System (ILS)** ( *IRC: #evergreen channel on the Freenode server* HomePage: *http://evergreen-ils.org/* )
145 osrf/pranjal710/osrf/docs/doc.md
@@ -0,0 +1,145 @@
+**OpenSRF PHP**
+===============
+
+The PHP Binding for openSRF takes services, methods and data(also as parameter) to return a simple parsed output. The examples/ directory shows how to use the API.
+
+*In Lebbeous Fogle-Weekley's words:*
+>These PHP bindings for the OpenSRF library allow you to make requests and receive responses from OpenSRF services, such as those that comprise the Evegreen Integrated Library System (ILS).
+>
+>Examples of how to use the bindings to contact typical services for Evergreen are under the examples/ directory.
+>
+>Setting up an OpenSRF session will retrieve the fm_IDL.xml file from the targeted server, which provides that server's Interface Description Language. This essentially means class definitions that allow certain data structures to be interpreted as objects in the Object-oriented sense.
+
+
+**Requirements:** *PHP version > 5 and HTTP_Request2*
+
+
+
+**Files**
+
+**config.php**
+
+This is the main configuration page. It holds the Golbal Variable which define the full path to classfieldmapper file.
+
+
+
+**decodejson2obj.php**
+
+*function decodeFromOpenSRF($data)*
+
+Recursively turns an already decoded json object *i.e.* The parameter $data to fieldmapper object
+
+
+
+**fieldmapper.php**
+
+*abstract class Fieldmapper_Class*
+
+Create/overwrites a dynamic file *i.e.* Classfieldmapper.php from parsed data obtained from fm_IDL (http://hostname/reports/fm_IDL.xml). Its member functions are getter, setter and encodeforopensrf().
+
+*Fieldmapper_Class::function encodeForOpenSRF()*
+
+It recursively encodes an object to be send to opensrf.
+
+
+
+**fieldmapper_class_abstract.php**
+
+It is an abstract class which holds the methods that is used by the numerous class of classfieldmapper.php
+
+
+
+**guid.php**
+
+*function guid()*
+
+It returns a guid. A guid can be used to keep a record in a stateless session.
+
+
+
+**is_open_ils_event.php**
+
+
+
+**open_ils_login.php**
+
+*function Open_Ils_login($username, $password, $server)*
+
+It takes three parameters (username, password , server) and returns an authtoken on successfully login. It calls open_ils_simple_request to get a response.
+
+
+
+**open_ils_simple_request.php**
+
+*function Open_Ils_Simple_request($arr, $m, $s, $server)*
+
+This is one of the most important function. It takes three parameters (method, service, and an array) as parameters. The array contains data to form the HTTP header. It returns a parsed response.
+
+
+
+**osrfMessage.php**
+
+This class is used in sending and retrieving messages to openSRF service. Its member functions are:
+constructor, getguid(), setguid(), toarray(),header(), send(),
+
+
+
+**osrfResponse.php**
+
+This class helps to parse the HTTP response. Each instance of this class holda a HTTP respomse in its 'data' property.
+
+
+
+**osrfSession.php**
+
+This is that class, whose instance is used by the examples file, and it calls other functions.
+
+
+
+**parse.php**
+
+*function Parse_HTTP_response($string)*
+
+$string is a string which holds the HTTP response. The function returns an array, which is the parsed HTTP response.
+
+
+
+**parse_xml_2_array.php**
+
+*function objectsIntoArray($arrObjData, $arrSkipIndices = array())*
+
+It takes two parameters, one as an array object and the other parameter tells which index to miss. It is a generic function to parse an xml into an array
+
+
+
+**stdclass_to_array.php**
+
+*function Stdclass_To_array($ar)*
+
+This takes one parameter *i.e.* $ar. $ar can be an array or an object. It returns an array by converting the object to an associative array.
+
+
+
+**url1.php**
+
+*function urldata($method, $ar)*
+
+One parameter tell about the method to use and the other array $ar holds the data which is used to form the encoded url
+
+
+
+
+**A brief overview of the functioning of openSRF-PHP API**
+============================================================
+
+*Open_Ils_Simple_request()* present in *open_ils_simple_request.php* mainly manages the process. it creates an instance of *osrfMessage Class* and then parses it through another instance of *osrfResponse Class* and its member functions.
+
+An instance of *Class osrfMessage* is used to interact with openSRF service. method, service, endpoint and param are set by the *constructor*. *setGuid()* sets the guid so that an HTTP header can be formed, and it can also help in creating a stateful session when required. With the information gathered a HTTP header is created by *function header()*. *Function toArray()* creates $data which will be used by the curl handle. *function send()* uses libcurlto interact with openSRF. If successfull, it returns a HTTP response.
+
+HTTP response has to be parsed to get the desired result. The result is a json encoded string. For this purpose *Class osrfResponse* is present. *Function send()* initializes $data property of an instance of *Class osrfMessage*. The *function parse()* is then used to parse the generic HTTP response to get the desired output and returns it.
+
+*Open_Ils_Simple_request()* thus gets the parsed result. This functions takes four parameters which are an array, service, method and a server. The array contains the data to form the HTTP header. Depending upon the service, method and the array it gets the response. Other functions use *Open_Ils_Simple_request()* to get result *eg. function Open_Ils_login()* uses it to get an authtoken on successfull login, else it throws an exception.
+
+When multiple user use it, in other words, in case of multiple session, each of these classes and functions should have multiple instances running. To make that happen we have a topmost class: *Class osrfSession*. The example scripts diectly use *Class osrfSession* instances. The constructor sets the server and fm_IDL. Its member functions do as they are named. *function login()* checks username/password for their authenticity. *function loadFieldmapper()* returns the path to *Class classfieldmapper*, which is defined in config.php. *function checkhost()* checks whether hostname entered is true or not and *function request()* deals with *Class osrfMessage*.
+
+The user can use all these files by just including *osrfSession.php*, as it has all other files included. He first creates an instance of *Class osrfSession* and sets hostname, which also sets fm_IDL for different servers. Now he needs to load *Class classfieldmapper* so that he can use numerous the classes present in it. Depending upon whether to used a cached file or to create a new one he sets true or false resp. . Now he has all the required files and functions to go on. He can use an instance of any class(es) from classfieldmapper.php and use *Class osrfSession* member functions to interact with openSRF services.
46 osrf/pranjal710/osrf/examples/open-ils_actor/retrieve.php
@@ -0,0 +1,46 @@
+<?php
+include ("./../../lib/OsrfSession.php");
+
+/* print_names()
+ *
+ * A simple function to print only the name field in a tree of objects
+ * where child nodes are stored in an array in the "children" field.
+ */
+function print_names($node, $depth = 0) {
+ echo str_repeat(" ", $depth) . $node->name . "\n";
+ foreach ($node->children as $child) {
+ print_names($child, $depth + 1);
+ }
+}
+
+$ses = new osrfSession("hostname"); // e.g.: localhost remembers server & loads fieldmapper.
+if ($ses->checkhost() == 200) {
+
+ try {
+ $ses->loadFieldmapper(false); //FALSE to parse fieldmapper anew and create classes no matter what. TRUE to rely on cached fieldmapper classes if found.
+ } catch (Exception $e_load_idl) {
+ echo 'Error: ', $e_load_idl->getMessage() , "\n";
+ }
+ $result = $ses->request("open-ils.actor", "open-ils.actor.org_tree.retrieve", 1)->parse();
+ if ($result) {
+ if (Is_Open_Ils_event($result)) {
+ echo "Could not place hold because of error: " . $result["desc"];
+ }
+ else {
+ echo "<pre>";
+
+ /* This would print a tree of aou objects. */
+ //print_r($result);
+
+ /* This will print only the name field of each aou object */
+ print_names($result);
+
+ echo "</pre>";
+ }
+ }
+ else echo "Errors were encountered.";
+}
+else echo "Could not locate fieldmapper. Invalid hostname!";
+?>
+
+
46 osrf/pranjal710/osrf/examples/open-ils_actor/retrieve.php~
@@ -0,0 +1,46 @@
+<?php
+include ("./../../lib/OsrfSession.php");
+
+/* print_names()
+ *
+ * A simple function to print only the name field in a tree of objects
+ * where child nodes are stored in an array in the "children" field.
+ */
+function print_names($node, $depth = 0) {
+ echo str_repeat(" ", $depth) . $node->name . "\n";
+ foreach ($node->children as $child) {
+ print_names($child, $depth + 1);
+ }
+}
+
+$ses = new osrfSession("evergreen.owwl.org"); // e.g.: localhost remembers server & loads fieldmapper.
+if ($ses->checkhost() == 200) {
+
+ try {
+ $ses->loadFieldmapper(false); //FALSE to parse fieldmapper anew and create classes no matter what. TRUE to rely on cached fieldmapper classes if found.
+ } catch (Exception $e_load_idl) {
+ echo 'Error: ', $e_load_idl->getMessage() , "\n";
+ }
+ $result = $ses->request("open-ils.actor", "open-ils.actor.org_tree.retrieve", 1)->parse();
+ if ($result) {
+ if (Is_Open_Ils_event($result)) {
+ echo "Could not place hold because of error: " . $result["desc"];
+ }
+ else {
+ echo "<pre>";
+
+ /* This would print a tree of aou objects. */
+ //print_r($result);
+
+ /* This will print only the name field of each aou object */
+ print_names($result);
+
+ echo "</pre>";
+ }
+ }
+ else echo "Errors were encountered.";
+}
+else echo "Could not locate fieldmapper. Invalid hostname!";
+?>
+
+
42 osrf/pranjal710/osrf/examples/title_level_hold/index.php
@@ -0,0 +1,42 @@
+<?php
+include ("./../../lib/OsrfSession.php");
+
+$ses = new osrfSession("localhost"); // e.g.: localhost remembers server & loads fieldmapper.
+if ($ses->checkhost() == 200) {
+
+ try {
+ $ses->loadFieldmapper(false); //FALSE to parse fieldmapper and create new fieldmapper class, TRUE for all other cases.
+ } catch (Exception $e_load_idl) {
+ echo 'Error: ', $e_load_idl->getMessage() , "\n";
+ }
+
+ $authtoken = $ses->login('username', 'password'); //// Authentication token
+
+ $hold = new ahr();
+ $hold->target = 3;
+ $hold->hold_type = "T";
+ $hold->pickup_lib = 4;
+ $hold->request_lib = 4;
+ $hold->requestor = 1;
+ $hold->usr = 1;
+
+ $result = $ses->request("open-ils.circ", "open-ils.circ.holds.create", $authtoken, $hold)->parse();
+ if ($result) {
+ /* Upon failure, result can be one OpenILS::Event object (represented
+ * an an associative array here) *or* an array of them. */
+ if (is_array($result)) {
+ if ($result[0]) {
+ foreach ($result as $r) {
+ echo "Could not place hold because of error: " . $r["desc"];
+ }
+ } else {
+ echo "Could not place hold because of error: " . $result["desc"];
+ }
+ }
+ /* Upon success, the result is a simple integer. */
+ else echo "Placed hold successfully. ID is $result.";
+ }
+ else echo "Errors were encountered.";
+}
+else echo "Could not locate fieldmapper. Invalid hostname!";
+?>
42 osrf/pranjal710/osrf/examples/title_level_hold/index.php~
@@ -0,0 +1,42 @@
+<?php
+include ("./../../lib/osrfSession.php");
+
+$ses = new osrfSession("localhost"); // e.g.: localhost remembers server & loads fieldmapper.
+if ($ses->checkhost() == 200) {
+
+ try {
+ $ses->loadFieldmapper(false); //FALSE to parse fieldmapper and create new fieldmapper class, TRUE for all other cases.
+ } catch (Exception $e_load_idl) {
+ echo 'Error: ', $e_load_idl->getMessage() , "\n";
+ }
+
+ $authtoken = $ses->login('username', 'password'); //// Authentication token
+
+ $hold = new ahr();
+ $hold->target = 3;
+ $hold->hold_type = "T";
+ $hold->pickup_lib = 4;
+ $hold->request_lib = 4;
+ $hold->requestor = 1;
+ $hold->usr = 1;
+
+ $result = $ses->request("open-ils.circ", "open-ils.circ.holds.create", $authtoken, $hold)->parse();
+ if ($result) {
+ /* Upon failure, result can be one OpenILS::Event object (represented
+ * an an associative array here) *or* an array of them. */
+ if (is_array($result)) {
+ if ($result[0]) {
+ foreach ($result as $r) {
+ echo "Could not place hold because of error: " . $r["desc"];
+ }
+ } else {
+ echo "Could not place hold because of error: " . $result["desc"];
+ }
+ }
+ /* Upon success, the result is a simple integer. */
+ else echo "Placed hold successfully. ID is $result.";
+ }
+ else echo "Errors were encountered.";
+}
+else echo "Could not locate fieldmapper. Invalid hostname!";
+?>
1  osrf/pranjal710/osrf/lib
@@ -0,0 +1 @@
+Subproject commit c2ed36a696dced07b6d2ef00701ff5cf081ba2c0
Please sign in to comment.
Something went wrong with that request. Please try again.