-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservices.php
More file actions
161 lines (129 loc) · 4.92 KB
/
services.php
File metadata and controls
161 lines (129 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
<?php
/*
* Copyright (c) 2025 Bloxtor (http://bloxtor.com) and Joao Pinto (http://jplpinto.com)
*
* Multi-licensed: BSD 3-Clause | Apache 2.0 | GNU LGPL v3 | HLNC License (http://bloxtor.com/LICENSE_HLNC.md)
* Choose one license that best fits your needs.
*
* Original PHP Spring Lib Repo: https://github.com/a19836/php-spring-lib/
* Original Bloxtor Repo: https://github.com/a19836/bloxtor
*
* YOU ARE NOT AUTHORIZED TO MODIFY OR REMOVE ANY PART OF THIS NOTICE!
*/
include_once __DIR__ . "/../config.php";
include_once __DIR__ . "/config.php";
include get_lib("sqlmap.hibernate.HibernateClient");
include __DIR__ . "/MyHibernateCache.php";
include dirname(__DIR__) . "/MySQLDBBroker.php";
echo $style;
echo '<h1>PHP Spring Lib - Hibernate with services</h1>
<p>Extend Hibernate to allow services.</p>
<div class="note">
<span>
Learn how to use extend the Spring Hibernate library, by creating your own xml nodes.<br/>
In this example we create the \'service\' nodes to work as alias to existing hibernate objects.
</span>
</div>';
if (!$password) {
echo '<div class="error">Please edit config.php file and define your DB credentials first!</div>';
die();
}
echo '
<h3>Some Extended Methods:</h3>
<div class="code short input">
<textarea readonly>
$services = parseServicesFile(__DIR__ . "/assets/services.xml");
$obj_name = $services["Item"];
$obj = $SQLClient->getHbnObj($obj_name);
</textarea>
</div>
<h3>Examples:</h3>';
//Init HibernateClient
$SQLClient = new HibernateClient();
//$MyHibernateCache = new MyHibernateCache( sys_get_temp_dir() . "/cache/spring/hibernate/" );
//$SQLClient->setCacheLayer($MyHibernateCache);
$DBBroker = new MySQLDBBroker($host, $username, $password, $db_name);
$SQLClient->setRDBBroker($DBBroker);
//Prepare table if not exists
createTable($DBBroker);
//Load iBatis queries
$external_vars = array(
"app_path" => $app_path
);
$SQLClient->loadXML( __DIR__ . "/assets/item_subitem.xml", $external_vars);
$code = '$DBBroker = new MySQLDBBroker($host, $username, $password, $db_name);
$SQLClient = new HibernateClient();
$SQLClient->setRDBBroker($DBBroker);
$SQLClient->loadXML( __DIR__ . "/assets/item_subitem.xml");';
echo '<div>
<h4>Start Hibernate Client and load xml file:</h4>
<div class="code short input">
<textarea readonly>' . $code . '</textarea>
</div>
<div class="code xml">
<textarea readonly>' . file_get_contents(__DIR__ . "/assets/item_subitem.xml") . '</textarea>
</div>
</div>';
//Extend beans factory
$services = parseServicesFile(__DIR__ . "/assets/services.xml");
$code = '$services = parseServicesFile(__DIR__ . "/assets/services.xml");';
echo '<div>
<h4>Extend Hibernate with services:</h4>
<div class="code one-line input">
<textarea readonly>' . $code . '</textarea>
</div>
<div class="code short xml">
<textarea readonly>' . file_get_contents(__DIR__ . "/assets/services.xml") . '</textarea>
</div>
</div>
<h4>Get hibernate object \'Item\':</h4>
<div style="margin-left:20px;">';
//Call Hibernate objs
$obj = $SQLClient->getHbnObj($services["Item"]);
if ($obj) {
$code = '$obj = $SQLClient->getHbnObj($services["Item"]);
$class = get_class($obj);';
$output = "class: " . get_class($obj) . "\n\n" . print_r($obj, true);
printTest("Item obj", $code, $output, "one-line", "");
$props_to_attributes = $obj->getPropertiesToAttributes();
$code = '//Then call some hibernate methods
$props_to_attributes = $obj->getPropertiesToAttributes();
//$obj->insert(...);
//$obj->callQuery(...);
//$obj->getData(...);
//$obj->getSQL(...);
//etc...';
$output = print_r($props_to_attributes, true);
printTest("SubItem obj", $code, $output, "short");
}
echo '</div>
<h4>Get hibernate object \'SubItem\':</h4>
<div style="margin-left:20px;">';
$obj = $SQLClient->getHbnObj($services["SubItem"]);
if ($obj) {
$code = '$obj = $SQLClient->getHbnObj($services["SubItem"]);
$class = get_class($obj);';
$output = "class: " . get_class($obj) . "\n\n" . print_r($obj, true);
printTest("SubItem obj", $code, $output, "one-line", "");
}
echo '</div>';
/* EXTENDING SERVICES FUNCTIONS */
function parseServicesFile($services_file_path) {
//get services
$content = file_get_contents($services_file_path);
$nodes = XMLFileParser::parseXMLContentToArray($content);
$first_node_name = is_array($nodes) ? array_keys($nodes) : array();
$first_node_name = isset($first_node_name[0]) ? $first_node_name[0] : null;
$services_node = isset($nodes[$first_node_name][0]["childs"]["services"][0]["childs"]["service"]) && is_array($nodes[$first_node_name][0]["childs"]["services"][0]["childs"]["service"]) ? $nodes[$first_node_name][0]["childs"]["services"][0]["childs"]["service"] : array();
$services = array();
$t = $services_node ? count($services_node) : 0;
for($i = 0; $i < $t; $i++) {
$service_node = $services_node[$i];
$alias = XMLFileParser::getAttribute($service_node, "alias");
$obj = XMLFileParser::getAttribute($service_node, "obj");
$services[$alias] = $obj;
}
//return services
return $services;
}
?>