예제 #1
0
 public function copy($path)
 {
     if (!$this->exists()) {
         throw new AeFileException('Cannot copy: file does not exist', 412);
     }
     if ($path instanceof AeInterface_File) {
         $path = $path->getPath();
     }
     if (file_exists($path)) {
         if (!is_dir($path)) {
             throw new AeFileException('Cannot copy: target already exists', 400);
         }
         $path = $path . SLASH . $this->name;
     }
     if ($path == $this->path) {
         throw new AeFileException('Cannot copy: target path matches original path', 400);
     }
     if ($this->fireEvent('copy', array($path))) {
         if (!@copy($this->path, $path)) {
             $e = error_get_last();
             throw new AeFileException('Cannot copy: ' . $e['message'], 500);
         }
     }
     return AeFile::getInstance($path);
 }
예제 #2
0
 /**
  * Get image file
  *
  * Returns an image file object, wrapped in the {@link AeFile} class
  * instance (or one of its subdrivers). This is useful when working with
  * uploaded images:
  * <code> $image = new AeImage($_FILES['foo']);
  * $image->getFile()->move('images');</code>
  *
  * @see AeFile
  *
  * @return AeFile
  */
 public function getFile()
 {
     if ($this->_file === null) {
         throw new AeImageException('No path value passed', 400);
     }
     if (is_string($this->_file)) {
         $this->setFile(AeFile::getInstance($this->_file));
     }
     return $this->_file;
 }
예제 #3
0
 /**
  * Save settings
  *
  * Save settings using file path provided. A file path can be an absolute
  * path, relative path to AnEngine root directory (the one with index.php in
  * it) or relative path to include path. File path must contain the target
  * file name including extension.
  *
  * If the file path is not passed, current {@linkAeSettings_Driver_Ini::_filename}
  * property value will be used. If the latter is not set either, the file
  * will be created in the AnEngine root dir, with {@link
  * AeSettings_Driver_Ini::_section} plus .ini extension as its filename.
  *
  * Any multi-dimensional arrays, set via advanced <var>$name</var> usage of
  * the {@link AeSettings_Driver_Ini::set()} method, will be written using
  * the dot as the array key separator:
  * <code> $params->set('section.foo.bar', 'baz');
  * $params->save('section.ini');</code>
  *
  * The above code will produce something like this in the ini file:
  * <pre> [section]
  * ; foo array
  * foo.bar = baz</pre>
  *
  * Each file also contains generator information, which includes:
  * - absolute file path
  * - generation date
  * - generator class (in case used driver is a child of this class)
  *
  * @param string $data setting file path
  *
  * @return bool true on success, false otherwise
  */
 public function save($data = null)
 {
     if ($data === null) {
         $data = $this->_filename === null ? $this->_section : $this->_filename;
     }
     // *** Check extension and add if required
     if (strpos($data, '.') === false) {
         $data .= '.' . self::EXTENSION;
     }
     if ($data === null || file_exists($data) && !is_writable($data)) {
         return false;
     }
     $file = AeFile::getInstance($data);
     $file->clear();
     $file->append('; File generated automatically' . "\n");
     $file->append('; Path: ' . $file->getPath() . "\n");
     $file->append('; Date: ' . date('r') . "\n");
     $file->append('; Generator: ' . $this->getClass() . "\n");
     if (count($this->_properties) > 0) {
         foreach ($this->_properties as $section => $values) {
             if (count($values) > 0) {
                 $file->append("\n" . '[' . $section . ']' . "\n");
                 $file->append($this->_valueToString($values));
             }
         }
     }
     return true;
 }
예제 #4
0
 /**
  * Save settings
  *
  * Save settings using file path provided. A file path can be an absolute
  * path, relative path to AnEngine root directory (the one with index.php in
  * it) or relative path to include path. File path must contain the target
  * file name including extension.
  *
  * If the file path is not passed, current {@link AeSettings_Driver_Php::_filename}
  * property value will be used. If the latter is not set either, the file
  * will be created in the AnEngine root dir, with {@link
  * AeSettings_Driver_Php::_section} plus .php extension as its filename.
  *
  * Any multi-dimensional arrays, set via advanced <var>$name</var> usage of
  * the {@link AeSettings_Driver_Php::set()} method, will be written as a
  * multi-dimensional array:
  * <code> $params->set('section.foo.bar', 'baz');
  * $params->save('section.php');</code>
  *
  * The above code will produce something like this in the php file:
  * <code> if (!defined('SLASH')) die;
  *
  * $s = array();
  *
  * // *** Section section
  * $s['section'] = array();
  *
  * $s['section']['foo'] = array (
  *   'bar' => 'bar',
  * );</code>
  *
  * Each file also contains generator information, which includes:
  * - absolute file path
  * - generation date
  * - generator class (in case used driver is a child of this class)
  * - package AnEngine (for use with phpDocumentor) and subpackage Runtime,
  *   to distinct internal files with auto-generated config files
  *
  * @param string $data setting file path
  *
  * @return bool true on success, false otherwise
  */
 public function save($data = null)
 {
     if ($data === null) {
         $data = $this->_filename === null ? $this->_section : $this->_filename;
     }
     // *** Check extension and add if required
     if (strpos($data, '.') === false) {
         $data .= '.' . self::EXTENSION;
     }
     if ($data === null || file_exists($data) && !is_writable($data)) {
         return false;
     }
     $file = AeFile::getInstance($data);
     $file->clear();
     $file->append('<' . '?php' . "\n");
     $file->append('/**' . "\n");
     $file->append(' * File generated automatically' . "\n");
     $file->append(' *' . "\n");
     $file->append(' * Path: ' . $file->getPath() . "\n");
     $file->append(' * Date: ' . date('r') . "\n");
     $file->append(' * Generator: {@link ' . $this->getClass() . "}\n");
     $file->append(' *' . "\n");
     $file->append(' * @package AnEngine' . "\n");
     $file->append(' * @todo add subpackage once custom documentor is done //Runtime' . "\n");
     $file->append(' */' . "\n");
     $file->append('if (!defined(\'SLASH\')) die;' . "\n");
     $file->append("\n" . '$s = array();' . "\n");
     if (count($this->_properties) > 0) {
         foreach ($this->_properties as $section => $values) {
             if (count($values) > 0) {
                 $_section = var_export($section, true);
                 $file->append("\n" . '// *** Section ' . $section . "\n");
                 $file->append('$s[' . $_section . '] = array();' . "\n\n");
                 foreach ($values as $key => $value) {
                     $_key = var_export($key, true);
                     $file->append('$s[' . $_section . '][' . $_key . '] = ' . var_export($this->_valueToString($value), true) . ';' . "\n");
                 }
             }
         }
     }
     $file->append("\n" . '?' . '>');
     return true;
 }
예제 #5
0
 /**
  * Write method
  *
  * Saves session data, takes session id and data to be save as its
  * parameters. The "write" handler is not executed until after the output
  * stream is closed. Thus, output from debugging statements in the "write"
  * handler will never be seen in the browser. If debugging output is
  * necessary, it is suggested that the debug output be written to a file
  * instead
  *
  * @param string $id
  * @param string $data
  *
  * @return bool
  */
 public function write($id, $data)
 {
     $session = AeFile::getInstance($this->_storagePath . SLASH . $id . '.' . $this->_extension);
     $session->clear()->write($data);
     return true;
 }
예제 #6
0
 /**
  * Write XML to file
  *
  * Writes XML to the specified file, using current element as a root
  * element. If you do not specify any file extension, xml is assumed
  *
  * @param string $file
  *
  * @return AeXml_Entity_Element self
  */
 public function save($file)
 {
     $file = (string) $file;
     if (strpos($file, '.') === false) {
         $file .= '.xml';
     }
     $file = AeFile::getInstance($file);
     if (!$file->exists()) {
         $file->create();
     }
     $file->write((string) $this);
     return $this;
 }