Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
fdl_method.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Apply document methods
8  *
9  * @author Anakeen
10  * @version $Id: fdl_method.php,v 1.8 2008/12/12 14:38:29 marc Exp $
11  * @package FDL
12  * @subpackage
13  */
14 /**
15  */
16 
17 include_once ("FDL/Class.Doc.php");
19 {
20  $dbaccess = $action->dbaccess;
21  $docid = $action->getArgument("id", 0);
22  $method = $action->getArgument("method");
23  $zone = $action->getArgument("zone");
24  $noredirect = (strtolower(substr($action->getArgument("redirect") , 0, 1)) == "n");
25 
27  $opt = '';
28  $err = '';
29 
30  if ($doc && $doc->isAlive()) {
31 
32  $err = $doc->control("view");
33  if ($err != "") $action->exitError($err);
34  if (!strpos($method, '(')) $method.= '()';
35  if (strpos($method, '::') === false) $method = '::' . $method;
36  $match = commentMethodMatch($doc, $method, '@apiExpose');
37  if ($match) {
38  $err = $doc->ApplyMethod($method);
39  } else {
40  $err = sprintf(_("Method %s cannot be call by client. Must be exposable method") , $method);
41  }
42  }
43 
44  if ($err != "") $action->AddWarningMsg($err);
45  $action->AddLogMsg(sprintf(_("method %s executed for %s ") , $method, $doc->title));
46  if ($err) $doc->addHistoryEntry(sprintf(_("method %s not executed : %s") , $method, $err) , HISTO_ERROR);
47  else $doc->addHistoryEntry(sprintf(_("method %s executed") , $method) , HISTO_NOTICE);
48 
49  if (!$noredirect) {
50  if ($zone) $opt = "&zone=$zone";
51  $referer = isset($_SERVER["HTTP_REFERER"]) ? $_SERVER["HTTP_REFERER"] : null;
52  if ($referer) {
53  Header("Location: $referer");
54  exit;
55  } else {
56  redirect($action, "FDL", sprintf("FDL_CARD%s&id=%d", $opt, $doc->id));
57  }
58  } else {
59  if ($err) $action->lay->template = htmlspecialchars($err, ENT_QUOTES);
60  else $action->lay->template = htmlspecialchars(sprintf(_("method %s applied to document %s #%d") , $method, $doc->title, $doc->id) , ENT_QUOTES);
61  $action->lay->noparse = true;
62  }
63 }
64 /**
65  * Verify if a method of an object contains the $comment
66  * @param $object
67  * @param string $method like "::test()"
68  * @param string $comment
69  * @return bool
70  */
71 function commentMethodMatch(&$object, $method, $comment)
72 {
73  $parseMethod = new parseFamilyMethod();
74  $parseMethod->parse($method);
75  $err = $parseMethod->getError();
76  if ($err) return $err;
77 
78  $staticClass = $parseMethod->className;
79  if (!$staticClass) $staticClass = get_class($object);
80  $methodName = $parseMethod->methodName;
81 
82  try {
83  $refMeth = new ReflectionMethod($staticClass, $methodName);
84  $mComment = $refMeth->getDocComment();
85  if (!preg_match('/' . $comment . '\b/', $mComment)) {
86  global $action;
87  $syserr = ErrorCode::getError("DOC1100", $refMeth->getDeclaringClass()->getName() , $refMeth->getName() , $object);
88  $action->log->error($syserr);
89  return false;
90  }
91  }
92  catch(Exception $e) {
93  $err = $e->getMessage();
94  }
95  return true;
96 }
$comment
Definition: fdl_execute.php:35
global $action
const HISTO_NOTICE
fdl_method(Action &$action)
Definition: fdl_method.php:18
static getError($code, $args=null)
Definition: ErrorCode.php:27
exitError($texterr, $exit=true, $code="")
const HISTO_ERROR
$docid
Definition: cleanFamily.php:13
global $_SERVER
switch($command) exit
Definition: checkVault.php:46
new_Doc($dbaccess, $id= '', $latest=false)
static getArgument($k, $def= '')
$dbaccess
Definition: checkVault.php:17
if($file) if($subject==""&&$file) if($subject=="") $err
commentMethodMatch(&$object, $method, $comment)
Definition: fdl_method.php:71
← centre documentaire © anakeen