Exemple #1
0
 public function testCorrectUsage()
 {
     newType(FilePath::class, 'string');
     $path = new FilePath('foobar');
     $this->assertEquals('foobar', $path->unbox());
     newType(Age::class, 'int');
     $age = new Age(16);
     $this->assertEquals(16, $age->unbox());
     newType(Opacity::class, 'float');
     $opacity = new Opacity(0.75);
     $this->assertEquals(0.75, $opacity->unbox());
     newType(UltraBoolean::class, 'bool');
     $ultraBool = new UltraBoolean(EXTREMELY_TRUE);
     $this->assertEquals(EXTREMELY_TRUE, $ultraBool->unbox());
     newType(MegaObject::class, \StdClass::class);
     $inferiorObj = (object) [];
     $megaObj = new MegaObject($inferiorObj);
     $this->assertEquals($inferiorObj, $megaObj->unbox());
     // note explicit leading slash
     newType(SuperMegaObject::class, '\\StdClass');
     $superMegaObj = new SuperMegaObject($inferiorObj);
     $this->assertEquals($inferiorObj, $superMegaObj->unbox());
     newType('\\UltraMegaObject', \StdClass::class);
     $ultraMegaObj = new \UltraMegaObject($inferiorObj);
     $this->assertEquals($inferiorObj, $ultraMegaObj->unbox());
 }
Exemple #2
0
 function __construct($path)
 {
     $realPath = \PMVC\realPath($path);
     if (!$realPath) {
         return !trigger_error('File not exists. [' . $path . ']');
     } else {
         parent::__construct($realPath);
     }
 }
Exemple #3
0
 public function &setPath($passedArgument, $outputErrorOnMissingFile = TRUE)
 {
     parent::setPath($passedArgument, $outputErrorOnMissingFile);
     $this->checkPathExists();
     if ($this->pathExists->toBoolean() == TRUE) {
         # Set the variableContainer to the file content;
         $this->varContainer = file_get_contents($this->varContainer);
         $this->pathContentsAs = 1;
     }
     // Return to chain;
     return $this->returnToChain();
 }
Exemple #4
0
 /**
  * Will read-out the whole module configuration file. This method will get and parse the configuration file of our module by using
  * the PHP specific parse_ini_file function defined by PHP;
  *
  * @param S $moduleDirectoryOrName Path to the file to be processed
  * @return A The file processed as an array
  * @author Catalin Z. Alexandru <*****@*****.**>
  * @copyright Under the terms of the GNU General Public License v3
  * @version $Id: 14_CNF.php 314 2009-10-09 14:24:35Z catalin.zamfir $
  * @since Version 1.0
  * @access protected
  * @final
  */
 protected final function getModuleConfiguration(FilePath $moduleDirectoryOrName)
 {
     if (isset($this->objConfigArray[$moduleDirectoryOrName])) {
         // Do return ...
         return $this->objConfigArray[$moduleDirectoryOrName];
     } else {
         // Do return ...
         return $this->objConfigArray[$moduleDirectoryOrName] = new A(parse_ini_file($moduleDirectoryOrName->toAbsolutePath() . _S . CFG_DIR . _S . $this->objConfigurationFile, TRUE));
     }
 }
Exemple #5
0
 /**
  * Will load the module requested includes. This will invoke the module CONTROLLER, after first processing the MODEL (schema) and
  * proper initial configuration options;
  *
  * @param S $modNameOrDir The name of the registered module
  * @return void Doesn't need to return anything
  * @author Catalin Z. Alexandru <*****@*****.**>
  * @copyright Under the terms of the GNU General Public License v3
  * @version $Id: 15_MOD.php 314 2009-10-09 14:24:35Z catalin.zamfir $
  * @since Version 1.0
  * @access private
  * @static
  */
 private static function requireIncludes(FilePath $modNameOrDir)
 {
     $scannedModuleDirectory = new FileDirectory(self::$objRegisteredModules[$modNameOrDir]['dir'] . _S . INCLUDE_DIR);
     if (!isset($_SESSION[PROJECT_NAME]['RA_mod_inc'][$modNameOrDir->toString()])) {
         // Include ALL files in INCLUDE_DIR, so we can have some features working;
         $_SESSION[PROJECT_NAME]['RA_mod_inc'][$modNameOrDir->toString()]['scandir'] = $includeFiles = $scannedModuleDirectory->scanDirectory($_SESSION[PROJECT_NAME]['RA_mod_inc'][$modNameOrDir->toString()]['f_count']);
     }
     // Do the FOR;
     for ($i = 0; $i < $_SESSION[PROJECT_NAME]['RA_mod_inc'][$modNameOrDir->toString()]['f_count']; ++$i) {
         require_once $scannedModuleDirectory . _S . $_SESSION[PROJECT_NAME]['RA_mod_inc'][$modNameOrDir->toString()]['scandir'][$i];
     }
 }
Exemple #6
0
 /**
  * Will return a boolean, to indicate if the cache file exists, and was read OK. Core developers use this method to return
  * the stored file output directly in the output buffer, passing any other intermediary functions between;
  *
  * @param S $cacheFile The path to the cache file
  * @return B Will return true or false, if it could read the cached file
  * @author Catalin Z. Alexandru <*****@*****.**>
  * @copyright Under the terms of the GNU General Public License v3
  * @version $Id: 10_TPL.php 315 2009-10-11 07:11:31Z catalin.zamfir $
  * @since Version 1.0
  * @access private
  * @static
  */
 private static function tpCache(FilePath $cacheFile)
 {
     #######################################################################
     # The logic is inversed here, we return new B (TRUE) upon error;
     #######################################################################
     # Cause of the fact that we want the static HTML, we issue a readfile ()
     # instead of an 'include', which would've been much slower;
     return new B(!($cacheFile->checkPathExists() && $cacheFile->readFilePath()));
     # This should make the content in the if-else block, not execute;
 }
Exemple #7
0
 /**
  * Will resize the images given from the path. Given a FileDirectory of images we want to resize, this method will provide a way
  * to automatically resize images to the specified width/height. It takes both arguments, including the height/width of the images
  * to be resized as the new array of dimensions to which to resize the file to;
  *
  * @param S $directoryFrom In what directory to save the files
  * @param A $resizeFileArray The array of files to be resized
  * @param A $resizeDimArray The resize array, containing key/var pairs of width and height, to process the images
  * @return void Will not return a thing, but process the images
  * @author Catalin Z. Alexandru <*****@*****.**>
  * @copyright Under the terms of the GNU General Public License v3
  * @version $Id: 12_GPH.php 314 2009-10-09 14:24:35Z catalin.zamfir $
  * @since Version 1.0
  * @access protected
  * @static
  * @final
  */
 protected static final function resizeImageFromUploadPATH(FileDirectory $directoryFrom, A $resizeFileArray, A $resizeDimArray)
 {
     foreach ($resizeFileArray as $kF => $vF) {
         if (($imagePath = new FilePath($directoryFrom . $vF['name'], FALSE)) && $imagePath->checkPathExists()) {
             // Process the LIST;
             list($imgWidth, $imgHeight) = getimagesize($imagePath = new FilePath($imagePath->doToken(DOCUMENT_ROOT, _NONE)));
             // Get the image object, as a resource;
             if (($curIMG = self::getImageObjectFromType(new A($vF), $imagePath)) != NULL) {
                 $currentImageProcessing = new R($curIMG);
             } else {
                 continue;
             }
             // Go further,
             if ($currentImageProcessing->checkIs('res')->toBoolean()) {
                 foreach ($resizeDimArray as $k => $v) {
                     $ratioOriginalImage = $imgWidth / $imgHeight;
                     if ($k / $v > $ratioOriginalImage) {
                         // Set width;
                         $thumbWidth = ceil($v * $ratioOriginalImage);
                         $thumbHeight = $v;
                     } else {
                         // Set height;
                         $thumbHeight = ceil($k / $ratioOriginalImage);
                         $thumbWidth = $k;
                     }
                     // Create the temporary;
                     $temporaryImage = new R(imagecreatetruecolor($thumbWidth, $thumbHeight));
                     if (imagecopyresampled($temporaryImage->toResource(), $currentImageProcessing->toResource(), 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight)) {
                         $uDir = $directoryFrom;
                         switch ($vF['type']) {
                             case 'image/gif':
                                 imagegif($temporaryImage->toResource(), $uDir . $k . '_' . $v . '_' . $vF['name']);
                                 break;
                             case 'image/png':
                                 imagepng($temporaryImage->toResource(), $uDir . $k . '_' . $v . '_' . $vF['name']);
                                 break;
                             case 'image/bmp':
                                 imagewbmp($temporaryImage->toResource(), $uDir . $k . '_' . $v . '_' . $vF['name']);
                                 break;
                             case 'image/jpeg':
                                 imagejpeg($temporaryImage->toResource(), $uDir . $k . '_' . $v . '_' . $vF['name']);
                                 break;
                         }
                     }
                     // Destroy the temporary;
                     imagedestroy($temporaryImage->toResource());
                     unset($temporaryImage);
                 }
                 // Destroy the image!
                 imagedestroy($currentImageProcessing->toResource());
                 unset($currentImageProcessing);
             }
         }
     }
 }
Exemple #8
0
 /**
  * Used to write the generated output stream to a file. It only does so much as dumping the contents of the output buffer to an user
  * specified file. We made this method so we could have a quick method in our TPL object to dump the cached content to a file,
  * without needing to have buggy code inserted in the TPL::tpExe method for writing a file, thus trying to relly on much of the
  * functionality on the specific FilePath/FileContent DataType, more than on developer created code;
  *
  * @param FilePath $whereToSaveOutputStream The path to the file where to save the output stream
  * @return B Will return true if the content was dumped to the file
  * @author Catalin Z. Alexandru <*****@*****.**>
  * @copyright Under the terms of the GNU General Public License
  * @version $Id: 04_OBS.php 313 2009-10-09 13:27:52Z catalin.zamfir $
  * @since Version 1.0
  * @access protected
  * @static
  * @final
  */
 protected static final function writeOutputStreamToFile(FilePath $whereToSaveOutputStream)
 {
     // Do return ...
     return $whereToSaveOutputStream->putToFile(self::getContentFromOutputStream());
 }