Esempio n. 1
0
 /**
  * Will create the contents of the classes Base and delegate your writing
  */
 public function Create()
 {
     foreach ($this->schema as $table => $rows) {
         $classPeerBase = $this->returnClassNameType('PeerBase', $table);
         $classBase = $this->returnClassNameType('Base', $table);
         $classPeer = $this->returnClassNameType('Peer', $table);
         $content = str_replace("[%nameClassPeer%]", $classPeerBase, $this->getContentTemplate($this->fileTemplateBasePeer));
         $content = str_replace("[%nameClassBase%]", $classBase, $content);
         $content = str_replace("[%obj%]", $this->returnClassName($table), $content);
         $content = str_replace("[%searchBy%]", $this->returnSearch($rows, $table), $content);
         $contentPeer = str_replace("[%nameClassPeer%]", $classPeerBase, $this->getContentTemplate($this->fileTemplatePeer));
         $contentPeer = str_replace("[%nameClass%]", $classPeer, $contentPeer);
         foreach ($rows as $index => $infoClass) {
             if ($index == '$doc$') {
                 $content = str_replace("[%doc%]", $infoClass, $content);
                 $content = str_replace("[%date%]", date('d-m-Y'), $content);
                 $contentPeer = str_replace("[%doc%]", $infoClass, $contentPeer);
                 $contentPeer = str_replace("[%date%]", date('d-m-Y'), $contentPeer);
             }
             if (!is_array($infoClass)) {
                 continue;
             }
         }
         $fileName = $classPeerBase . '.php';
         $fileNamePeer = $classPeer . '.php';
         WriteToFile::writeContent($content, CLASS_BASE, $fileName, true, true);
         WriteToFile::writeContent($contentPeer, CLASS_PEER, $fileNamePeer, false, false);
     }
 }
Esempio n. 2
0
 /**
  * Will create the contents of the classes Base and delegate your writing
  */
 public function Create()
 {
     foreach ($this->schema as $table => $rows) {
         $class = $this->returnClassName($table);
         $classPeer = $this->returnClassNameType('Peer', $table);
         $content = str_replace("[%nameClass%]", $class, $this->getContentTemplate($this->fileTemplateClass));
         $content = str_replace("[%nameClassPeer%]", $classPeer, $content);
         foreach ($rows as $index => $infoClass) {
             if ($index == '$doc$') {
                 $content = str_replace("[%doc%]", $infoClass, $content);
                 $content = str_replace("[%date%]", date('d-m-Y'), $content);
             }
             if (!is_array($infoClass)) {
                 continue;
             }
         }
         $fileName = $class . '.php';
         WriteToFile::writeContent($content, CLASS_CLASS, $fileName, false, false);
     }
 }
Esempio n. 3
0
 /**
  * Write the contents of the file
  * @param String $content
  * @param String $path
  * @param String $fileName
  * @param Boolean $overwrite
  * @param Boolean $replace
  * @return Boolean
  */
 public static function writeContent($content, $path, $fileName, $overwrite = true, $replace = true)
 {
     self::$path = $path;
     self::$fileName = $fileName;
     if (!self::checkPathExists()) {
         $log = new Log();
         $log->setLog(__FILE__, 'The directory is not exists: ' . $path);
         throw new Exception('The directory is not exists: ' . $path);
     }
     if (!self::checkPathPermission()) {
         $log = new Log();
         $log->setLog(__FILE__, 'The directory is not writable: ' . $path);
         throw new Exception('The directory is not writable: ' . $path);
     }
     if (!$overwrite && !$replace && self::checkFileExists()) {
         return false;
     }
     $owner = fileowner($path);
     $group = filegroup($path);
     $permission = 0777;
     $type = "w";
     if ($overwrite && !$replace) {
         $type = "a";
         $content = '\\n' . $content;
     }
     if ($overwrite && $replace) {
         @unlink($path . $fileName);
     }
     $open = fopen($path . $fileName, $type);
     fwrite($open, $content);
     fclose($open);
     chmod($path . $fileName, $permission);
     #chown($path.$fileName,$owner);
     #chgrp($path.$fileName,$group);
     return true;
 }
Esempio n. 4
0
 /**
  * Will create the contents of the classes Base and delegate your writing
  */
 public function Create()
 {
     foreach ($this->schema as $table => $rows) {
         $class = $this->returnClassNameType('Base', $table);
         $classPeer = $this->returnClassNameType('Peer', $table);
         $content = str_replace("[%nameClass%]", $class, $this->getContentTemplate($this->fileTemplateBase));
         $content = str_replace("[%nameClassPeer%]", $classPeer, $content);
         $content = str_replace("[%table%]", $table, $content);
         $content = str_replace("[%consts%]", $this->returnConsts($rows), $content);
         $content = str_replace("[%privates%]", $this->returnPrivates($rows), $content);
         $content = str_replace("[%validates%]", $this->returnIsValid($rows), $content);
         $content = str_replace("[%retrive%]", $this->returnRetrive($rows), $content);
         $content = str_replace("[%delete%]", $this->returnDelete($rows), $content);
         $content = str_replace("[%sets%]", $this->returnSets($rows), $content);
         $content = str_replace("[%gets%]", $this->returnGets($rows), $content);
         $content = str_replace("[%ConvertingObject%]", $this->returnConvertingObject($rows, $table), $content);
         $content = str_replace("[%save%]", $this->returnSave($rows, $table), $content);
         foreach ($rows as $index => $infoClass) {
             if ($index == '$doc$') {
                 $content = str_replace("[%doc%]", $infoClass, $content);
                 $content = str_replace("[%date%]", date('d-m-Y'), $content);
             }
             if (!is_array($infoClass)) {
                 continue;
             }
         }
         $fileName = $class . '.php';
         WriteToFile::writeContent($content, CLASS_BASE, $fileName, true, true);
     }
 }
 public function SaveFile($settings = false)
 {
     $dir = !empty($settings['save_dir']) ? $settings['save_dir'] : false;
     $filename = !empty($settings['save_name']) ? $settings['save_name'] : "myjavascript.js";
     $this->content = preg_replace('!<script [.*]{1,}></script>!', "", $this->content);
     include_once __DIR__ . '/class.WriteToFile.php';
     $write = new WriteToFile();
     $write->AddInput(array("content" => $this->content, "save_name" => $filename, "save_dir" => $dir))->SaveDocument();
 }
Esempio n. 6
0
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Extending Exceptions</title>
</head>
<body>
<?php 
# write_to_file.php
// Load the class definition:
require 'FileException.php';
require 'WriteToFile.php';
try {
    // Create the object:
    $fp = new WriteToFile('data.txt', 'w');
    // Write the data:
    $fp->write('This is a line of data.');
    // Close the file:
    $fp->close();
    // Delete the object:
    unset($fp);
    // If we got this far, everything worked!
    echo '<p>The data has been written.</p>';
} catch (FileException $e) {
    echo '<p>The process could not be completed. Debugging information:<br>' . $e->getMessage() . '<br>' . $e->getDetails() . '</p>';
}
echo '<p>This is the end of the script.</p>';
?>
</body>
</html>
Esempio n. 7
0
        if (!($this->fp = @fopen($file, 'w'))) {
            throw new Exception("Error Processing Request:could not open file");
        }
    }
    function write($data)
    {
        if (@(!fwrite($this->fp, $data . "\n"))) {
            throw new Exception("Error Processing Request:could not write to file");
        }
    }
    function close()
    {
        if ($this->fp) {
            fclose($this->fp);
            $this->fp = NULL;
        }
    }
    function __destruct()
    {
        $this->close;
    }
}
try {
    $fp = new WriteToFile('data.txt');
    $fp->write('f**k');
    $fp->close();
    unset($fp);
    echo 'success';
} catch (Exception $e) {
    echo $e->getMessage();
}
Esempio n. 8
0
 public function createSchema()
 {
     $dumper = new sfYamlDumper();
     $yaml = $dumper->dump($this->mountSchema(), 4);
     WriteToFile::writeContent($yaml, PATH_CONFIG, 'schemaTemp.yml');
 }
Esempio n. 9
0
 public function newModule($module)
 {
     $module = ucfirst($module);
     if (is_dir(PATH_LAYOUTS . $module)) {
         $log = new Log();
         $log->setLog(__FILE__, 'The directory of this module already exists: ' . PATH_LAYOUTS . $module);
         throw new Exception('The directory of this module already exists: ' . PATH_LAYOUTS . $module);
     }
     if (is_dir(PATH_MODULES . $module)) {
         $log = new Log();
         $log->setLog(__FILE__, 'The directory of this module already exists: ' . PATH_MODULES . $module);
         throw new Exception('The directory of this module already exists: ' . PATH_MODULES . $module);
     }
     if (is_dir(PATH_TEMPLATES . $module)) {
         $log = new Log();
         $log->setLog(__FILE__, 'The directory of this module already exists: ' . PATH_TEMPLATES . $module);
         throw new Exception('The directory of this module already exists: ' . PATH_TEMPLATES . $module);
     }
     if (is_dir(PATH_WEB . $module)) {
         $log = new Log();
         $log->setLog(__FILE__, 'The directory of this module already exists: ' . PATH_WEB . $module);
         throw new Exception('The directory of this module already exists: ' . PATH_WEB . $module);
     }
     mkdir(PATH_LAYOUTS . $module);
     mkdir(PATH_MODULES . $module);
     mkdir(PATH_MODULES . $module . '/lib/');
     mkdir(PATH_TEMPLATES . $module);
     mkdir(PATH_TEMPLATES . $module . '/Includes/');
     mkdir(PATH_WEB . $module);
     mkdir(PATH_WEB . $module . '/css/');
     mkdir(PATH_WEB . $module . '/images/');
     mkdir(PATH_WEB . $module . '/js/');
     $permission = 0777;
     chmod(PATH_LAYOUTS . $module, $permission);
     chmod(PATH_MODULES . $module, $permission);
     chmod(PATH_MODULES . $module . '/lib/', $permission);
     chmod(PATH_TEMPLATES . $module, $permission);
     chmod(PATH_TEMPLATES . $module . '/Includes/', $permission);
     chmod(PATH_WEB . $module, $permission);
     chmod(PATH_WEB . $module . '/css/', $permission);
     chmod(PATH_WEB . $module . '/images/', $permission);
     chmod(PATH_WEB . $module . '/js/', $permission);
     $templateLayout = $this->getContentTemplate($this->templateLayout);
     $pathLayout = PATH_LAYOUTS . $module . '/';
     WriteToFile::writeContent($templateLayout, $pathLayout, 'index.php', true, true);
     $templateModule = $this->getContentTemplate($this->templateModule);
     $templateModule = str_replace("[%module%]", $module, $templateModule);
     $templateModule = str_replace("[%date%]", date('d/m/Y H:i:s'), $templateModule);
     $pathModules = PATH_MODULES . $module . '/';
     $fileModule = 'Action' . $module . '.php';
     WriteToFile::writeContent($templateModule, $pathModules, $fileModule, true, true);
     $templateTemplate = $this->getContentTemplate($this->templateTemplate);
     $pathTemplate = PATH_TEMPLATES . $module . '/';
     WriteToFile::writeContent($templateTemplate, $pathTemplate, 'index.php', true, true);
     return true;
 }