Exemple #1
0
 function let(TwigConfig $config)
 {
     $config->getPaths()->willReturn([__DIR__ . '/path1', __DIR__ . '/path2']);
     $config->getNamespaces()->willReturn(['namespace1' => __DIR__ . '/path1', 'namespace2' => __DIR__ . '/path2']);
     $config->getDebug()->willReturn(true);
     $config->getCharset()->willReturn('utf-8');
     $config->getCache()->willReturn(false);
     $config->getBaseTemplateClass()->willReturn('class');
     $config->getAutoReload()->willReturn(true);
     $config->getAutoEscape()->willReturn(true);
     $config->getOptimizations()->willReturn(-1);
     $config->getStrictVariables()->willReturn(true);
     directory_create(__DIR__ . '/path1');
     directory_create(__DIR__ . '/path2');
 }
Exemple #2
0
 /**
  * Copy a file from one location to another
  * and create all necessary subdirectories.
  *
  * @param $oldPath
  * @param $newPath
  *
  * @return bool
  */
 function file_copy($oldPath, $newPath)
 {
     $dir = file_get_directory($newPath);
     if (!directory_exists($dir)) {
         directory_create($dir);
     }
     return copy($oldPath, $newPath);
 }
Exemple #3
0
/**
 * Take the call and properly dispatch it to the methods below.  This method
 * assumes valid input.
 */
function dispatch($arguments)
{
    if (array_key_exists('file', $arguments)) {
        if (array_key_exists('rename', $arguments)) {
            if (!file_directory_rename($arguments['filename'], $arguments['newname'], working_directory())) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            return true;
        }
        if (array_key_exists('copy', $arguments)) {
            if (!($newentry = file_copy($arguments['filename'], working_directory()))) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            echo json_encode($newentry);
            return true;
        }
        if (array_key_exists('delete', $arguments)) {
            if (!file_delete($arguments['filename'], working_directory())) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            return true;
        }
    }
    if (array_key_exists('directory', $arguments)) {
        if (array_key_exists('listing', $arguments)) {
            echo json_encode(directory_listing());
            return true;
        }
        if (array_key_exists('create', $arguments)) {
            if (!directory_create($arguments['dirname'], working_directory())) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            return true;
        }
        if (array_key_exists('delete', $arguments)) {
            if (!directory_delete($arguments['dirname'], working_directory())) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            return true;
        }
        if (array_key_exists('rename', $arguments)) {
            if (!file_directory_rename($arguments['dirname'], $arguments['newname'], working_directory())) {
                http_error_exit('HTTP_CLIENT_FORBIDDEN');
            }
            return true;
        }
    }
    if (array_key_exists('image', $arguments)) {
    }
    if (array_key_exists('upload', $arguments)) {
        store_uploaded_file($arguments['filename'], $arguments['filedata'], working_directory());
        return true;
    }
    return false;
}
 /**
  * Copy a directory and all of its contents to the specified path
  * and create all necessary subdirectories.
  *
  * @param $oldPath
  * @param $newPath
  *
  * @return bool
  */
 function directory_copy($oldPath, $newPath)
 {
     if (directory_exists($oldPath)) {
         if (!directory_exists($newPath)) {
             directory_create($newPath);
         }
         $files = directory_list($oldPath);
         foreach ($files as $file) {
             $oldFilePath = path($oldPath, $file);
             $newFilePath = path($newPath, $file);
             if (directory_exists($oldFilePath)) {
                 directory_copy($oldFilePath, $newFilePath);
             } else {
                 file_copy($oldFilePath, $newFilePath);
             }
         }
     } else {
         return file_copy($oldPath, $newPath);
     }
 }
 public function test_directory_create_checks_if_directory_already_exists()
 {
     $this->assertTrue(directory_create('/tmp'));
 }