public static final function validate($data, $password = true) { Validate::prime($data); if ($password) { Validate::go('password')->not('blank')->min(6)->max(20)->type('password'); } Validate::go('email')->not('blank')->type('email'); Validate::paint(); }
public static function process($xp, $crypt = null) { Validate::prime($xp->get()); Validate::go('action')->not('blank')->is('al'); Validate::paint(); $stream = Stream::receive($xp->getRequestData(), $crypt); $fileio = static::_get(); switch ($xp->get('action')) { case static::FILE_IO_READ: //validate request Validate::prime($xp->get()); Validate::go('path')->not('blank'); Validate::go('offset')->is('num'); Validate::go('length')->is('num'); Validate::paint(); //setup and read $fileio->setPath($xp->get('path')); $fileio->setOffset($xp->get('offset')); $data = $fileio->read($xp->get('length')); $sha1 = sha1($data); $md5 = md5($data); //tune data $stream->setPayload($sha1 . $md5 . $data); //pass data back return $xp->addResponseData($stream->encode()); break; case static::FILE_IO_WRITE: //validate request Validate::prime($xp->get()); Validate::go('path')->not('blank'); Validate::go('offset')->is('num'); Validate::paint(); //validate payload $data = $stream->decode(); $sha1 = substr($data, 0, 40); $md5 = substr($data, 40, 32); $data = substr($data, 72); if (sha1($data) !== $sha1) { throw new Exception('Payload hash mismatch (sha1) block could not be written'); } if (md5($data) !== $md5) { throw new Exception('Payload hash mismatch (md5) block could not be written'); } //Setup and write $fileio->setPath($xp->get('path')); $fileio->setOffset($xp->get('offset')); if (($bytes_written = $fileio->write($data)) === false) { throw new Exception('Failed to write block'); } //pass success return $xp->add('bytes_written', $bytes_written); break; case static::FILE_IO_RCOPY: //validate request Validate::prime($xp->get()); Validate::go('path')->not('blank'); Validate::go('offset')->is('num'); Validate::go('remote_path')->not('blank'); Validate::go('remote_offset')->is('num'); Validate::go('remote_length')->is('num'); Validate::paint(); //setup and copy $fileio->setPath($xp->get('path')); $fileio->setOffset($xp->get('offset')); if (!($bytes_written = $fileio->rcopy($xp->get('remote_path'), $xp->get('remote_offset'), $xp->get('remote_length')))) { throw new Exception('Failed to copy from remote file'); } //pass success return $xp->add('bytes_written', $bytes_written); break; case static::FILE_IO_STORE: //validate request Validate::prime($xp->get()); Validate::go('path')->not('blank'); Validate::paint(); //store new file $fileio->setPath($xp->get('path')); //send back file info return $xp->add('file', $fileio->store()); break; default: throw new Exception('Invalid File IO action'); break; } }