Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ClassTypeDescription.inc.php
1 <?php
17 import('lib.pkp.classes.filter.TypeDescription');
18 import('lib.pkp.classes.filter.TypeDescriptionFactory');
19 
22  var $_className;
23 
26 
32  function ClassTypeDescription($typeName) {
33  parent::TypeDescription($typeName);
34  }
35 
36  //
37  // Setters and Getters
38  //
42  function getNamespace() {
43  return TYPE_DESCRIPTION_NAMESPACE_CLASS;
44  }
45 
46 
47  //
48  // Implement abstract template methods from TypeDescription
49  //
53  function parseTypeName($typeName) {
54  $splitName = $this->splitClassName($typeName);
55  if ($splitName === false) return false;
56  list($this->_packageName, $this->_className) = $splitName;
57 
58  // FIXME: Validate package and class to reduce the risk of
59  // code injection, e.g. check that the package is within given limits/folders,
60  // don't allow empty package parts, etc.
61 
62  return true;
63  }
64 
68  function checkType(&$object) {
69  // We expect an object
70  if (!is_object($object)) return false;
71 
72  // Check the object's class
73  if (!is_a($object, $this->_className)) return false;
74 
75  return true;
76  }
77 
78 
79  //
80  // Protected helper methods
81  //
90  function splitClassName($typeName) {
91  // This should be a class - identify package and class name
92  $typeNameParts = explode('.', $typeName);
93  if (count($typeNameParts) == 1) {
94  // No package given - invalid type description
95  return false;
96  }
97 
98  $className = array_pop($typeNameParts);
99  $packageName = implode('.', $typeNameParts);
100  return array($packageName, $className);
101  }
102 }
103 ?>
A type description that validates objects by class type.
Abstract base class for filter input/output type descriptions.