/**
  * Set the spooled mails directory
  *
  * @param string $dir The directory where to create spooled mails files
  * @return self
  * @throws \Exception if the directory doesn't exist and can't be created
  * @see \Library\Helper\Directory::ensureExists()
  */
 public function setSpoolDirectory($dir)
 {
     if (!DirectoryHelper::ensureExists($dir)) {
         throw new \Exception(sprintf('Can not create emails spooling directory "%s"!', $dir));
     }
     $this->spool_dir = $dir;
     return $this;
 }
 /**
  * Gets the temporary directory
  *
  * @return  string
  * @throws  \InvalidArgumentException if the path doesn't exist and can't be created
  */
 public static function getTemporaryDirectory()
 {
     $exists = DirectoryHelper::ensureExists(self::$tmp_directory);
     if (@file_exists(self::$tmp_directory)) {
         return self::$tmp_directory;
     } else {
         throw new \InvalidArgumentException(sprintf('Directory "%s" can not be found and can not be created!', self::$tmp_directory));
     }
 }
 /**
  * @param   string      $source The source image path
  * @param   string      $source_content The source image content (only used if no path is set)
  * @param   string|array $filter A filter name or a list of filters
  * @param   array       $filter_options An array of filter options (if the $filter arg is an array, the options must be ordered as $filters)
  * @param   string      $target_filename
  */
 public function __construct($source = null, $source_content = null, $filter = null, $filter_options = null, $target_filename = null)
 {
     self::$tmp_directory = DirectoryHelper::slashDirname(MediaProcessor::getTemporaryDirectory());
     $this->target_directory = DirectoryHelper::slashDirname(realpath(self::$tmp_directory));
     DirectoryHelper::ensureExists($this->target_directory);
     $this->resetFilters();
     if (!is_null($source)) {
         $this->setSourceFile($source);
     } elseif (!is_null($source_content)) {
         $this->buildSourceFileFromContent($source_content);
     }
     if (!is_null($target_filename)) {
         $this->setTargetFilename($target_filename);
     }
     if (!is_null($filter)) {
         if (is_string($filter)) {
             $this->addFilter($filter, $filter_options);
         } else {
             $this->setFilters($filter, $filter_options);
         }
     }
 }
 /**
  * @param   \MVCFundamental\Interfaces\FrontControllerInterface $app
  * @return  void
  * @throws  \MVCFundamental\Exception\ErrorException
  */
 public static function boot(FrontControllerInterface $app)
 {
     // stores the FrontController
     self::setFrontController($app);
     // define internal handlers
     set_exception_handler(array(__CLASS__, 'handleException'));
     register_shutdown_function(array(__CLASS__, 'handleShutdown'));
     if (self::getFrontController()->getOption('convert_error_to_exception') == true) {
         set_error_handler(array(__CLASS__, 'handleError'));
     }
     // the required temporary directory
     $tmp_dir = self::getFrontController()->getOption('temp_dir');
     if (empty($tmp_dir) || !file_exists($tmp_dir) && !@DirectoryHelper::create($tmp_dir) || !is_dir($tmp_dir) || !is_writable($tmp_dir)) {
         $tmp_dir = DirectoryHelper::slashDirname(sys_get_temp_dir()) . 'mvc-fundamental';
         if (!@DirectoryHelper::ensureExists($tmp_dir)) {
             throw new ErrorException(sprintf('The "%s" temporary directory can not be created or is not writable (and a default one could not be taken)!', $tmp_dir));
         }
         self::getFrontController()->setOption('temp_dir', $tmp_dir);
     }
     // the application logger
     if (self::getFrontController()->getOption('minimum_log_level') == null) {
         self::getFrontController()->setOption('log_level', self::getFrontController()->isMode('production') ? Logger::WARNING : Logger::DEBUG);
     }
     $logger_options = array('duplicate_errors' => false, 'directory' => self::getFrontController()->getOption('temp_dir'), 'minimum_log_level' => self::getFrontController()->getOption('log_level'));
     $logger_class = self::getFrontController()->getOption('app_logger');
     if (!class_exists($logger_class) || !Helper::classImplements($logger_class, self::getApi('logger'))) {
         throw new ErrorException(sprintf('A logger must exist and implement the "%s" interface (for class "%s")!', self::getApi('logger'), $logger_class));
     }
     self::set('logger', new $logger_class($logger_options));
     // load services
     foreach (self::getFrontController()->getOptions() as $var => $val) {
         if (array_key_exists($var, self::$_api)) {
             self::set($var, self::apiFactory($var, $val));
         }
         if (array_key_exists($var, self::$_constructors)) {
             $cls_index = self::$_constructors[$var];
             self::getInstance()->setProvider($var, function ($app, $name, array $arguments = array()) use($val, $cls_index) {
                 return $app::apiFactory($cls_index, $val, $arguments);
             });
         }
     }
     self::get('event_manager')->setEventClass(self::getFrontController()->getOption('event_item'));
 }
Esempio n. 5
0
<?php 
echo 'echo $str = "My ! special éàè§ text file name";' . "\n";
echo 'echo Library\\Helper\\File::formatFilename($str);' . "\n";
$str = "My ! special éàè§ text file name";
echo '=> ' . var_export(Library\Helper\File::formatFilename($str), 1);
?>
    </pre>

<h4 id="dirhelper">Library\Helper\Directory</h4>
    <pre class="code" data-language="php">
<?php 
$logs = array();
$dir = __DIR__ . '/tmp/tmp_tmp';
echo '$logs = array();' . "\n";
echo '$dir = __DIR__."/tmp/tmp_tmp";' . "\n";
\Library\Helper\Directory::ensureExists($dir);
\Library\Helper\File::touch($dir . '/test1');
\Library\Helper\File::touch($dir . '/test2');
\Library\Helper\File::touch($dir . '/test/test1');
\Library\Helper\File::touch($dir . '/test/test2');
\Library\Helper\Directory::chmod($dir, 777, true, 766, $logs);
\Library\Helper\Directory::remove($dir, $logs);
echo "\n";
echo '\\Library\\Helper\\Directory::ensureExists($dir);' . "\n";
echo '\\Library\\Helper\\File::touch($dir."/test1");' . "\n";
echo '\\Library\\Helper\\File::touch($dir."/test2");' . "\n";
echo '\\Library\\Helper\\File::touch($dir."/test/test1");' . "\n";
echo '\\Library\\Helper\\File::touch($dir."/test/test2");' . "\n";
echo '\\Library\\Helper\\Directory::chmod($dir, 777, true, 766, $logs);' . "\n";
echo '\\Library\\Helper\\Directory::remove($dir, $logs);' . "\n";
echo "\n";
 /**
  * @covers ../../../src/Library/Helper/Directory::ensureExists()
  */
 public function test_ensureExists()
 {
     $this->checkNoArg('ensureExists');
     $this->assertTrue(\Library\Helper\Directory::ensureExists(self::$tmp_dir));
     $this->assertTrue(file_exists(self::$tmp_dir));
 }
Esempio n. 7
0
 /**
  * @covers ../../../src/Library/Helper/File::write()
  */
 public function test_write()
 {
     $this->checkNoArg('remove');
     \Library\Helper\Directory::ensureExists(self::$tmp_dir);
     \Library\Helper\File::touch(self::$tmp_file);
     $logs = array();
     $this->assertTrue(\Library\Helper\File::write(self::$tmp_file, $this->lorem_ipsum));
     $this->assertEmpty($logs);
     $ctt = trim(file_get_contents(self::$tmp_file));
     $this->assertEquals($this->lorem_ipsum, $ctt);
 }
 /**
  * Initializer : this method is called after any instance creation
  *
  * @param object $request \Library\HttpFundamental\Request
  * @param object $response \Library\HttpFundamental\Response
  * @param array $user_options
  */
 protected function init(Request $request = null, Response $response = null, array $user_options = array())
 {
     $this->setUserOptions($this->extendOptions($user_options));
     foreach (array('tmp_directory', 'var_directory', 'log_directory') as $_dir) {
         DirectoryHelper::ensureExists($this->getOption($_dir));
     }
     $this->setLogger(new Logger($this->getLoggerOptions()));
     if (!is_null($request)) {
         $this->setRequest($request);
     }
     if (!is_null($response)) {
         $this->setResponse($response);
     }
     $this->getResponse()->setContentType('json');
     if ($this->getOption('enable_url_rewrite') === true) {
         $this->getRequest()->setFlag(Request::REWRITE_SEGMENTS_QUERY)->setArguments($this->getRequest()->getArguments());
     }
     /*
     echo '<pre>';
     var_export($this->getRequest());
     exit('yo');
     */
 }