Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
marcus-lodspeakr
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
uib-ub
Spesialsamlingene
marcus-lodspeakr
Commits
e3089512
Commit
e3089512
authored
13 years ago
by
Alvaro Graves
Browse files
Options
Downloads
Patches
Plain Diff
Adding query conversion to services
parent
7eb5b6dd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
classes/Utils.php
+13
-4
13 additions, 4 deletions
classes/Utils.php
classes/modules/serviceModule.php
+118
-28
118 additions, 28 deletions
classes/modules/serviceModule.php
with
131 additions
and
32 deletions
classes/Utils.php
+
13
−
4
View file @
e3089512
...
@@ -355,7 +355,7 @@ class Utils{
...
@@ -355,7 +355,7 @@ class Utils{
$resultVars
[
$v
[
'value'
]]
=
1
;
$resultVars
[
$v
[
'value'
]]
=
1
;
}
}
};
};
$x
=
Utils
::
extract
Triples
(
$q_infos
[
'query'
][
'pattern'
]);
$x
=
Utils
::
extract
Obj
(
$q_infos
[
'query'
][
'pattern'
]);
foreach
(
$x
as
$v
){
foreach
(
$x
as
$v
){
if
((
$resultVars
[
$v
[
's'
]]
&&
$v
[
's_type'
]
==
'var'
)
if
((
$resultVars
[
$v
[
's'
]]
&&
$v
[
's_type'
]
==
'var'
)
||
(
$resultVars
[
$v
[
'p'
]]
&&
$v
[
'p_type'
]
==
'var'
)
||
(
$resultVars
[
$v
[
'p'
]]
&&
$v
[
'p_type'
]
==
'var'
)
...
@@ -393,7 +393,16 @@ class Utils{
...
@@ -393,7 +393,16 @@ class Utils{
$construct
.
=
".
\n
"
;
$construct
.
=
".
\n
"
;
}
}
$query
=
preg_replace
(
'/select.*where/i'
,
'CONSTRUCT {'
.
$construct
.
'} WHERE'
,
$query
);
if
(
$construct
==
""
){
if
(
sizeof
(
$q_infos
[
'query'
][
'result_vars'
])
>
0
){
//For now, assuming variables are in the GRAPH ?g
$query
=
"CONSTRUCT {?g ?x ?y} WHERE{GRAPH ?g{?g ?x ?y}}"
;
}
else
{
Utils
::
send500
();
}
}
else
{
$query
=
preg_replace
(
'/select.*where/i'
,
'CONSTRUCT {'
.
$construct
.
'} WHERE'
,
$query
);
}
}
else
{
}
else
{
Utils
::
send500
(
"invalid query: "
.
$parser
->
getErrors
());
Utils
::
send500
(
"invalid query: "
.
$parser
->
getErrors
());
}
}
...
@@ -519,12 +528,12 @@ class Utils{
...
@@ -519,12 +528,12 @@ class Utils{
}
}
private
static
function
extract
Triples
(
$obj
){
private
static
function
extract
Obj
(
$obj
,
$term
=
'triple'
){
$triples
=
array
();
$triples
=
array
();
if
(
is_array
(
$obj
)){
if
(
is_array
(
$obj
)){
foreach
(
$obj
as
$k
=>
$v
){
foreach
(
$obj
as
$k
=>
$v
){
if
(
$v
[
'type'
]
!=
'triple'
){
if
(
$v
[
'type'
]
!=
'triple'
){
$aux
=
Utils
::
extract
Triples
(
$v
);
$aux
=
Utils
::
extract
Obj
(
$v
);
if
(
$aux
[
'type'
]
!=
'triple'
){
if
(
$aux
[
'type'
]
!=
'triple'
){
$triples
=
array_merge
(
$triples
,
$aux
);
$triples
=
array_merge
(
$triples
,
$aux
);
}
else
{
}
else
{
...
...
This diff is collapsed.
Click to expand it.
classes/modules/serviceModule.php
+
118
−
28
View file @
e3089512
...
@@ -13,38 +13,128 @@ class ServiceModule extends abstractModule{
...
@@ -13,38 +13,128 @@ class ServiceModule extends abstractModule{
return
FALSE
;
return
FALSE
;
}
}
$extension
=
Utils
::
getExtension
(
$acceptContentType
);
$extension
=
Utils
::
getExtension
(
$acceptContentType
);
$auxViewFile
=
$conf
[
'home'
]
.
$conf
[
'view'
][
'directory'
]
.
$conf
[
'service'
][
'prefix'
]
.
$qArr
[
0
]
.
"/"
.
$extension
.
".template"
;
$viewFile
=
$conf
[
'service'
][
'prefix'
]
.
$qArr
[
0
]
.
"/"
.
$extension
.
".template"
;
$auxModelFile
=
$conf
[
'home'
]
.
$conf
[
'model'
][
'directory'
]
.
$conf
[
'service'
][
'prefix'
]
.
$qArr
[
0
]
.
"/"
.
$extension
.
".queries"
;
$modelFile
=
$conf
[
'service'
][
'prefix'
]
.
$qArr
[
0
]
.
"/"
.
$extension
.
".queries"
;
if
(
is_dir
(
$auxModelFile
)
&&
is_file
(
$auxViewFile
)){
if
(
file_exists
(
$conf
[
'home'
]
.
$conf
[
'model'
][
'directory'
]
.
$modelFile
)
&&
file_exists
(
$conf
[
'home'
]
.
$conf
[
'view'
][
'directory'
]
.
$viewFile
)
&&
$qArr
[
0
]
!=
null
){
return
$uri
;
// $qArr[0];
return
array
(
$modelFile
,
$viewFile
);
}
elseif
(
$extension
!=
'html'
&&
file_exists
(
$conf
[
'model'
][
'directory'
]
.
$conf
[
'service'
][
'prefix'
]
.
$qArr
[
0
]
.
'/html.queries'
)){
$modelFile
=
$conf
[
'service'
][
'prefix'
]
.
$qArr
[
0
]
.
'/html.queries'
;
$viewFile
=
null
;
return
array
(
$modelFile
,
$viewFile
);
}
}
$auxViewFile
=
$conf
[
'home'
]
.
$conf
[
'view'
][
'directory'
]
.
$conf
[
'service'
][
'prefix'
]
.
$qArr
[
0
];
$auxModelFile
=
$conf
[
'home'
]
.
$conf
[
'model'
][
'directory'
]
.
$conf
[
'service'
][
'prefix'
]
.
$qArr
[
0
];
return
FALSE
;
if
(
is_dir
(
$auxModelFile
)
&&
is_dir
(
$auxViewFile
)){
}
Utils
::
send406
(
$uri
);
// $qArr[0];
public
function
execute
(
$service
){
global
$conf
;
global
$localUri
;
global
$uri
;
global
$acceptContentType
;
global
$endpoints
;
global
$lodspk
;
$context
=
array
();
$context
[
'contentType'
]
=
$acceptContentType
;
$context
[
'endpoints'
]
=
$endpoints
;
//$sp = new SpecialFunction();
//$sp->execute($localUri, $context);
$f
=
$this
->
getFunction
(
$uri
);
$params
=
array
();
$params
=
$this
->
getParams
(
$uri
);
//$params[] = $context;
$acceptContentType
=
Utils
::
getBestContentType
(
$_SERVER
[
'HTTP_ACCEPT'
]);
$extension
=
Utils
::
getExtension
(
$acceptContentType
);
$args
=
array
();
list
(
$modelFile
,
$viewFile
)
=
$service
;
try
{
$prefixHeader
=
array
();
for
(
$i
=
0
;
$i
<
sizeof
(
$params
);
$i
++
){
if
(
$conf
[
'mirror_external_uris'
]){
$altUri
=
Utils
::
curie2uri
(
$params
[
$i
]);
$altUri
=
preg_replace
(
"|^"
.
$conf
[
'basedir'
]
.
"|"
,
$conf
[
'ns'
][
'local'
],
$altUri
);
$params
[
$i
]
=
Utils
::
uri2curie
(
$altUri
);
}
}
}
if
(
is_dir
(
$auxModelFile
)
&&
is_file
(
$auxViewFile
)){
return
$localUri
;
// $qArr[0];
for
(
$i
=
0
;
$i
<
sizeof
(
$params
);
$i
++
){
$auxPrefix
=
Utils
::
getPrefix
(
$params
[
$i
]);
if
(
$auxPrefix
[
'ns'
]
!=
NULL
){
$prefixHeader
[]
=
$auxPrefix
;
}
$args
[
"arg"
.
$i
]
=
$params
[
$i
];
}
}
$results
[
'params'
]
=
$params
;
return
FALSE
;
$lodspk
=
$conf
[
'view'
][
'standard'
];
$lodspk
[
'type'
]
=
$modelFile
;
$lodspk
[
'root'
]
=
$conf
[
'root'
];
$lodspk
[
'home'
]
=
$conf
[
'basedir'
];
$lodspk
[
'this'
][
'value'
]
=
$uri
;
$lodspk
[
'this'
][
'curie'
]
=
Utils
::
uri2curie
(
$uri
);
$lodspk
[
'this'
][
'contentType'
]
=
$acceptContentType
;
$lodspk
[
'model'
][
'directory'
]
=
$conf
[
'model'
][
'directory'
];
$lodspk
[
'view'
][
'directory'
]
=
$conf
[
'view'
][
'directory'
];
$lodspk
[
'ns'
]
=
$conf
[
'ns'
];
$lodspk
[
'endpoint'
]
=
$conf
[
'endpoint'
];
$lodspk
[
'type'
]
=
$modelFile
;
$lodspk
[
'header'
]
=
$prefixHeader
;
$lodspk
[
'args'
]
=
$args
;
$lodspk
[
'module'
]
=
'service'
;
$lodspk
[
'add_mirrored_uris'
]
=
false
;
$lodspk
[
'baseUrl'
]
=
$conf
[
'basedir'
];
$lodspk
[
'this'
][
'value'
]
=
$uri
;
$lodspk
[
'this'
][
'contentType'
]
=
$acceptContentType
;
$lodspk
[
'view'
][
'directory'
]
=
$conf
[
'home'
]
.
$conf
[
'view'
][
'directory'
]
.
$conf
[
'service'
][
'prefix'
]
.
$f
.
'/'
;
$lodspk
[
'model'
][
'directory'
]
=
$conf
[
'home'
]
.
$conf
[
'model'
][
'directory'
];
if
(
$viewFile
==
null
){
$lodspk
[
'transform_select_query'
]
=
true
;
}
chdir
(
$conf
[
'model'
][
'directory'
]);
$first
=
array
();
Utils
::
queryFile
(
$modelFile
,
$endpoints
[
'local'
],
$results
,
$first
);
chdir
(
$conf
[
'home'
]);
$results
=
Utils
::
internalize
(
$results
);
if
(
is_array
(
$results
)){
$results
=
Convert
::
array_to_object
(
$results
);
}
//Need to redefine viewFile as 'local' i.e., inside service.foo/ so I can load files with the relative path correctly
$viewFile
=
$extension
.
".template"
;
Utils
::
processDocument
(
$viewFile
,
$lodspk
,
$results
);
}
catch
(
Exception
$ex
){
echo
$ex
->
getMessage
();
trigger_error
(
$ex
->
getMessage
(),
E_ERROR
);
Utils
::
send500
(
$uri
);
}
}
exit
(
0
);
public
function
execute
(
$service
){
}
global
$conf
;
global
$localUri
;
global
$uri
;
protected
function
getFunction
(
$uri
){
global
$acceptContentType
;
global
$conf
;
global
$endpoints
;
$count
=
1
;
global
$lodspk
;
$prefixUri
=
$conf
[
'basedir'
];
require_once
(
$conf
[
'home'
]
.
$conf
[
'service'
][
'class'
]);
$aux
=
str_replace
(
$prefixUri
,
''
,
$uri
,
$count
);
$context
=
array
();
$functionAndParams
=
explode
(
'/'
,
$aux
);
$context
[
'contentType'
]
=
$acceptContentType
;
return
$functionAndParams
[
0
];
$context
[
'endpoints'
]
=
$endpoints
;
}
$sp
=
new
SpecialFunction
();
$sp
->
execute
(
$localUri
,
$context
);
protected
function
getParams
(
$uri
){
exit
(
0
);
global
$conf
;
$count
=
1
;
$prefixUri
=
$conf
[
'basedir'
];
$functionAndParams
=
explode
(
'/'
,
str_replace
(
$prefixUri
,
''
,
$uri
,
$count
));
if
(
sizeof
(
$functionAndParams
)
>
1
){
array_shift
(
$functionAndParams
);
return
$functionAndParams
;
}
else
{
return
array
(
null
);
}
}
}
}
}
?>
?>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment