* @version 0.0.0 * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team * @license GNU GPL 3.0 or any newer version * @link http://www.ship-simu.org * @todo Needs to add functionality for handling the object's type * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ class NetworkPackage extends BaseFrameworkSystem implements Deliverable { /** * Package mask for compressing package data */ const PACKAGE_MASK = '%s:%s:%s'; /** * Protected constructor * * @return void */ protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); // We need to initialize a stack here for our packages even those // which have no recipient address and stamp... ;-) $stackerInstance = ObjectFactory::createObjectByConfiguredName('package_stacker_class'); // At last, set it in this class $this->setStackerInstance($stackerInstance); } /** * Creates an instance of this class * * @param $compressorInstance A Compressor instance for compressing the content * @return $packageInstance An instance of a Deliverable class */ public final static function createNetworkPackage (Compressor $compressorInstance) { // Get new instance $packageInstance = new NetworkPackage(); // Now set the compressor instance if set if ($compressorInstance instanceof Compressor) { // Okay, set it $packageInstance->setCompressorInstance($compressorInstance); } // END - if // Return the prepared instance return $packageInstance; } /** * "Queues" raw content into this delivery class by reading the raw content * from given template instance and pushing it on the 'undeclared' stack. * * @param $templateInstance A CompileableTemplate instance * @return void */ public function queueRawDataFromTemplate (CompileableTemplate $templateInstance) { // Get the raw content and compress it $content = $this->getCompressorInstance()->compressStream($templateInstance->getRawTemplateData()); // Add magic in front of it and hash behind it, including BASE64 encoding $content = sprintf(self::PACKAGE_MASK, $this->getCompressorInstance()->getCompressorExtension(), base64_encode($content), crc32($content) // Not so good, but needs to be fast! ); // Now prepare the temporary array and push it on the 'undeclared' stack $this->getStackerInstance()->pushNamed('undeclared', array( 'sender' => null, 'recipient' => null, 'content' => $content )); } } // [EOF] ?>