Core  3.2
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
Class.ActionUsage.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @package FDL
5 */
6 /**
7  * Verify arguments for action function
8  *
9  * @brief Verify arguments for action function
10  * @class ActionUsage
11  * @code
12  $usage = new ActionUsage();
13  $usage->setDescriptionText("Refresh documents ");
14  $usage->addRequiredParameter("famid", "the family filter");
15  $usage->addOptionalParameter("revision", "use all revision - default is no", array(
16  "yes",
17  "no"
18  ));
19  $usage->addOptionalParameter("save", "use modify default is light", array(
20  "complete",
21  "light",
22  "none"
23  ));
24  $usage->verify();
25  * @endcode
26  */
27 class ActionUsage extends ApiUsage
28 {
29  /**
30  * init current action
31  *
32  * @param Action &$action current action
33  */
34  public function __construct(Action & $action)
35  {
36  $this->action = $action;
37  $this->setDefinitionText(_($action->short_name));
38  $this->addRequiredParameter('app', "application name");
39  $this->addOptionalParameter('action', "action name");
40  $this->addHiddenParameter('sole', "display mode (deprecated)");
41  $authType = $this->addHiddenParameter('authtype', "authentication type");
42  $this->addHiddenParameter(\openAuthenticator::openGetId, "authentication token");
43  if("open" === $authType) {
44  $this->addHiddenParameter("privateid", "token");
45  }
46  }
47  /**
48  * @api Get usage for action funtion
49  * @return mixed|string
50  */
51  public function getUsage()
52  {
53  $usage = parent::getUsage();
54  $usage = str_replace('--app=', '--app=' . $this->action->parent->name . ' : ', $usage);
55  $usage = str_replace('--action=', '--action=' . $this->action->name . ' : ', $usage);
56  return $usage;
57  }
58  /**
59  * Return value of argument key
60  * @param string $key the identifier
61  * @param string $defaultValue value to return if value is empty
62  * @return mixed|string
63  */
64  protected function getArgumentValue($key, $defaultValue = '')
65  {
66  $value = parent::getArgumentValue($key, null);
67  if ($value === null) {
68  if (isset($_FILES[$key])) {
69  return $_FILES[$key];
70  }
71  }
72  return ($value === null) ? $defaultValue : $value;
73  }
74 
75  /**
76  * Restriction callback to verify a file array value
77  * @param string $argVal argument value
78  * @param string $argName argument name
79  * @param ApiUsage $apiUsage current apiUsage object
80  * @return string
81  */
82  public static function isFile($argVal, $argName, $apiUsage)
83  {
84  $err = "";
85  if (!is_array($argVal) || !isset($argVal["name"]) || !isset($argVal["tmp_name"])) {
86  $err = sprintf("Value type isn't authorized for argument, must be a file description array");
87  }
88  return $err;
89  }
90 }
91 ?>
__construct(Action &$action)
addOptionalParameter($argName, $argDefinition, $restriction=null, $default=null)
static isFile($argVal, $argName, $apiUsage)
setDefinitionText($text)
Verify arguments for action function.
addHiddenParameter($argName, $argDefinition)
getArgumentValue($key, $defaultValue= '')
if($file) if($subject==""&&$file) if($subject=="") $err
addRequiredParameter($argName, $argDefinition, $restriction=null)
$usage
$value
Verify arguments for wsh programs.
← centre documentaire © anakeen