[Typo3-dev] Validating TypoScript - Schema vs. DTD

Christian Welzel gawain at camlann.de
Thu Dec 1 00:13:52 CET 2005


Elmar Hinz wrote:

> True. Validating extension could only be done, if extensions provide
> calculatable information about their config-options. Otherwise they need
> to be excluded from validation. That is the case for any validation
> technic, not only schema.

That is true, but its many times simple to provide some
object or tables or arrays than to merge extension-dtd or
extension-schema into a global one...

> But building one validation object for every TS object looks like a lot
> of work. To much work only for the purpuse of validation. 

Not necessarily. 
You can write a base-class for validation, thats main purpose
is to provide the validation algorithm. The information about
valid children can then be "outsourced" into a member function.
this way the programmer does not need to reinvent the wheel but
can provide his data in a way he likes best (table, array, xml, foo)
in his own subclass. on the other side you are flexible enough
to implement your own algorithm if you cannot use the standard one
(e.g. for TEXT).
the only thing the dev-guy is responsible for is to provide the information
in a defined way and to register his validation class in typo3.

the validators for internal TS objects are provided by typo3 of cause
(you can validate them with one php object of cause)

scheme:

class BaseValidator {
  function validate() { 
     ... 
     data = getInformation(); 
     error = do_standard_validate_stuff(data); 
     // lookup each property and call the next validator
     // if property has a known validatable type
     ... 
     return error;
  }
  function getInformation () { return the data; }
}

class MyExtentionValidator extends BaseValidator {
  function getInformation() { return my special data from secret file; }
}

TYPO3::registerValidator("tx_myext_pi1", "MyExtentionValidator");

getInformation() could return an Hash (array with keys)

$info["myProp"] = "stdWrap";
$info["myProp2"] = "text";

So can find out easily if an property exists and retrieve the type
of this property at the same time.

To validate TS typo3 has this to do at last:

bv = new BaseValidator(TS-array);
error = bv.validate();
print error;

This would be a very clean, flexible, extendable solution for
TS validation.

-- 
 MfG, Christian Welzel
  (Ex-Admin AG DSN Gerokstrasse)

  GPG-Key:     http://www.camlann.de/key.asc <-> ID: 70A1AD15
  Fingerprint: 4F50 19BF 3346 36A6 CFA9 DBDC C268 6D24 70A1 AD15




More information about the TYPO3-dev mailing list