/** * Transfer the file to its new location by copying it. * @param \System\IO\File The sourcefile. * @return bool True on success, false otherwise */ public final function transferFile(\System\IO\File $file) { $target = \System\IO\Directory::getPath($this->targetFolder . $file->getFilename()); return \System\IO\File::writeContents($target, $file->getContents()) instanceof \System\IO\File; }
/** * This function only needs the be called once every run to load and to parse the XML file * This call is made automatically. Successive calls will instantly return. */ public static final function prepareObject() { //initialize the xmltree map for the first time in the system //all the objects in the system use the same map as it is static //we do this inline so we can check for the existance of the entry itself instead of using validateMap() if (self::$xmlTree == null) { self::$xmlTree = new \System\Collection\Map(); } $key = get_called_class(); if (!isset(self::$xmlTree[$key])) { //we get the xml file using late static binding $xmlFile = \System\IO\Directory::getPath(static::getXMLSourceFile()); //parse the xml file and create an xml tree $xml = self::parseXML($xmlFile); //create the fields self::createFields($xml); //create the virtuals self::createVirtuals($xml); //create the queries and the conditions self::createQueries($xml); //store the xml and mark the class as completed by doing so self::$xmlTree[$key] = $xml; } }
/** * Process the file upload and publish the posted data to the given targets. * Do note: this function returns True if all placements in the targets are succesfull. * @return bool True on success, false otherwise. */ public final function process() { if (isset($_FILES[$this->formFieldname])) { if (is_uploaded_file($_FILES[$this->formFieldname]['tmp_name'])) { //the file is uploaded succesfully //check for filesize if ($_FILES[$this->formFieldname]['size'] <= $this->maxFileSize) { //check for fileextension if (in_array(strtolower(pathinfo($_FILES[$this->formFieldname]['name'], PATHINFO_EXTENSION)), $this->allowedExtensions)) { //no uploaderrors if ($_FILES[$this->formFieldname]['error'] == UPLOAD_ERR_OK) { $fullPath = \System\IO\Directory::getPath(PATH_TEMP . $this->targetFilename); if (@move_uploaded_file($_FILES[$this->formFieldname]['tmp_name'], $fullPath)) { $file = new \System\IO\File($fullPath); //cycle through all the targets and place them where desired $success = true; foreach ($this->targets as $target) { if (!$target->transferFile($file)) { $success = false; } } //remove the temporary file again $file->delete(); return $success; } } } } } } return false; }
/** * Combines the given blocks, and produces a Renderer to be added to a RenderSurface. * The Render is ready to be added to the surface. * @return \System\Output\Renderer The renderer to use. */ public final function getRenderer() { $xml = $this->generateXML(); switch ($this->getOutputRenderer()) { case self::OUTPUT_RENDERER_XML: $renderer = new \System\Output\Renderer\XMLRenderer(); $renderer->render($xml); break; case self::OUTPUT_RENDERER_XSL: //we raise the event so the system can perform any checks on the page before actually rendering $event = new Event\OnBeforeRenderEvent(); $event->setPage($this); $event->setXmlTree($xml); $event->raise($this); $renderer = new \System\Output\Renderer\XSLTRenderer(); $renderer->render($xml, \System\IO\Directory::getPath($this->getXSL()), $this->getPageOptions()); break; default: throw new \InvalidArgumentException('The given output renderer is invalid: ' . $this->getOutputRenderer()); } return $renderer; }
/** * This function is identical to the getFullPath() function, except that it strips the given * $base variable from the beginning of the file. If the given base is not found, it returns the regular getFullPath() result. * The base variable gets normalised before checking. * @param string The base to remove from the beginning * @return string The remaining fullpath string */ public final function stripBase($base) { $path = $this->getFullPath(); $base = \System\IO\Directory::normalize($base) ?: \System\IO\Directory::getPath($base); $startPos = stripos($path, $base); if ($startPos !== false && $startPos == 0) { return substr($path, strlen($base)); } return $path; }
/** * Stores the given codeblock to its appropriate file. It appends the block to the end of the file. * @param \System\IO\Directory The target base folder * @param \ReflectionClass The class whoms definition to store * @param string The code to place in the sourcefile. */ private static final function storeToFile(\System\IO\Directory $targetFolder, \ReflectionClass $class, $code) { //store the contents to a file $targetFolderStr = \System\IO\Directory::getPath($targetFolder->getCurrentPath(true) . strtolower($class->getNamespaceName()) . \System\IO\Directory::getSeparator()); if (!file_exists($targetFolderStr)) { mkdir($targetFolderStr, 0777, true); } $targetFileName = $targetFolderStr . basename($class->getFileName()); file_put_contents($targetFileName, $code, LOCK_EX | FILE_APPEND); }
/** * Listens to the EVENT_FILE_FINGERPRINT event and returns the fingerprint of the given folders * @param OnInteractionEvent The event to listen to */ public static final function fileFingerprint(\System\System\Interaction\Event\OnInteractionEvent $event) { $msg = $event->getMessage(); if ($msg->getType() == \System\System\Interaction\MessageType::TYPE_SYSTEM && $msg->getMessage() == SystemInteractionEventEvent::EVENT_FILE_FINGERPRINT) { $params = $msg->getParams(); if (isset($params['folders'])) { $folders = $params['folders']; $map = new \System\Collection\Map(); foreach ($folders as $folder) { $directory = new \System\IO\Directory($folder, false); if ($directory) { $content = \System\System\Introspection\IO::getFileFingerprint($directory); $subFolders = new \System\Collection\Vector(); foreach ($directory->getDirectories() as $subFolder) { /** @var \System\IO\Directory */ $subFolder = $subFolder; $subFolders[] = \System\IO\Directory::getPath($subFolder->getCurrentPath(true), '/'); } $content->set('folders', $subFolders); $map->set($folder, $content); } } $response = new \System\System\Interaction\Response($msg, $map); $event->addResponse($response); } } }