Exemplo n.º 1
0
 /**
  * 
  * Creates a symlink in "docroot/public" for a given class.
  * 
  * @param string $class The class name.
  * 
  * @return void
  * 
  */
 protected function _link($class)
 {
     // array of class-name parts
     $arr = explode('_', $class);
     // the last part of the class name where to put the symlink
     $tgt = array_pop($arr);
     // make the rest of the array into a subdirectory path
     $sub = implode('/', $arr);
     // where is the source (original) directory located, relatively?
     $k = count($arr);
     $src = "";
     for ($i = 0; $i < $k; $i++) {
         $src .= "../";
     }
     $src .= "../../include/{$sub}/{$tgt}/Public";
     // need the system root
     $system = Solar::$system;
     // make sure we have a place to make the symlink
     $dir = "docroot/public/{$sub}";
     if (!Solar_Dir::exists("{$system}/{$dir}")) {
         $this->_out("    Making public directory {$dir} ... ");
         Solar_Dir::mkdir("{$system}/{$dir}", 0755, true);
         $this->_outln("done.");
     }
     // make the symlink
     $this->_out("    Making public symlink for {$class} ... ");
     try {
         Solar_Symlink::make($src, $tgt, $dir);
         $this->_outln('done.');
     } catch (Exception $e) {
         $this->_out($e->getMessage());
         $this->_outln(' ... failed.');
     }
 }
Exemplo n.º 2
0
 /**
  * 
  * Makes a symbolic link to a file or directory.
  * 
  * @param string $src The source path of the real file or directory.
  * 
  * @param string $tgt The target path for where to put the symlink.
  * 
  * @param string $dir Change to this directory before creating the
  * symlink, typically the target directory; this helps when making
  * relative symlinks.
  * 
  * @return string The last line from the [[php::exec() | ]] call to
  * create the symlink.
  * 
  */
 public static function make($src, $tgt, $dir = null)
 {
     // are we on a windows system prior to NT6?
     $is_win = strtolower(substr(PHP_OS, 0, 3)) == 'win';
     if ($is_win && php_uname('r') < 6) {
         throw Solar_Symlink::_exception('ERR_WINDOWS_VERSION');
     }
     // massage the change-dir a bit
     $dir = trim($dir);
     if ($dir) {
         $dir = Solar_Dir::fix($dir);
     }
     // is the source a directory or a file?
     $path = $dir . $src;
     $is_dir = Solar_Dir::exists($path);
     $is_file = Solar_File::exists($path);
     if (!$is_dir && !$is_file) {
         // no source found
         throw Solar_Symlink::_exception('ERR_SOURCE_NOT_FOUND', array('src' => $src, 'tgt' => $tgt, 'dir' => $dir, 'path' => $path));
     }
     // find any existing path to the target
     if ($is_dir) {
         $path = Solar_Dir::exists($dir . $tgt);
     } else {
         $path = Solar_File::exists($dir . $tgt);
     }
     // does the target exist already?
     if ($path) {
         throw Solar_Symlink::_exception('ERR_TARGET_EXISTS', array('src' => $src, 'tgt' => $tgt, 'dir' => $dir, 'path' => $path));
     }
     // escape arguments for the command
     $src = escapeshellarg($src);
     $tgt = escapeshellarg($tgt);
     $dir = escapeshellarg($dir);
     if ($is_win && $is_dir) {
         // windows directory
         return Solar_Symlink::_makeWinDir($src, $tgt, $dir);
     } elseif ($is_win && $is_file) {
         // windows file
         return Solar_Symlink::_makeWinFile($src, $tgt, $dir);
     } else {
         // non-windows
         return Solar_Symlink::_make($src, $tgt, $dir);
     }
 }
Exemplo n.º 3
0
 /**
  * 
  * Write out a series of dirs and symlinks for a new Vendor source.
  * 
  * @param string $vendor The Vendor name.
  * 
  * @return void
  * 
  */
 protected function _exec($vendor = null)
 {
     // we need a vendor name, at least
     if (!$vendor) {
         throw $this->_exception('ERR_NO_VENDOR');
     }
     $this->_outln("Removing links for vendor '{$vendor}' ...");
     // build "foo-bar" and "FooBar" versions of the vendor name.
     $this->_inflect = Solar_Registry::get('inflect');
     $this->_dashes = $this->_inflect->camelToDashes($vendor);
     $this->_studly = $this->_inflect->dashesToStudly($this->_dashes);
     // the base system dir
     $system = Solar::$system;
     // the links to remove (reverse order from make-vendor)
     $links = array("script/{$this->_dashes}", "include/Fixture/{$this->_studly}", "include/Mock/{$this->_studly}", "include/Test/{$this->_studly}", "include/{$this->_studly}");
     // remove the links
     foreach ($links as $link) {
         $this->_out("    Removing '{$link}' ... ");
         $path = "{$system}/{$link}";
         // fix for windows
         $path = str_replace('/', DIRECTORY_SEPARATOR, $path);
         if (Solar_File::exists($path) || Solar_Dir::exists($path)) {
             Solar_Symlink::remove($path);
             $this->_outln("done.");
         } else {
             $this->_outln("missing.");
         }
     }
     // done!
     $this->_outln("... done.");
     // reminders
     $this->_outln("Remember to remove '{$this->_studly}_App' from the " . "['Solar_Controller_Front']['classes'] element " . "in your config file.");
     $this->_outln("Remember to remove '{$this->_studly}_Model' from the " . "['Solar_Sql_Model_Catalog']['classes'] element " . "in your config file.");
     // need to write a recursive-remove method for Solar_Dir that will
     // delete only the symlinked files (not the real files)
     $this->_outln("You will need to remove the " . "'docroot/public/{$this->_studly}' directory yourself, as it " . "may contain copies of public assets (not links).");
 }
Exemplo n.º 4
0
 /**
  * 
  * Populates the list of recognized commands.
  * 
  * @return void
  * 
  */
 protected function _setCommandList()
 {
     $list = array();
     // loop through class stack and add commands
     $stack = $this->_stack->get();
     foreach ($stack as $class) {
         $dir = Solar_Dir::exists(str_replace('_', DIRECTORY_SEPARATOR, $class));
         if (!$dir) {
             continue;
         }
         // loop through each file in the directory
         $files = scandir($dir);
         foreach ($files as $file) {
             // file must end in .php and start with an upper-case letter
             $char = $file[0];
             $keep = substr($file, -4) == '.php' && ctype_alpha($char) && strtoupper($char) == $char;
             if (!$keep) {
                 // doesn't look like a command class
                 continue;
             }
             // the list-value is the base class name, plus the file name,
             // minus the .php extension, to give us a class name
             $val = $class . substr($file, 0, -4);
             // the list-key is the command name; convert the file name to a
             // command name.  FooBar.php becomes "foo-bar".
             $key = substr($file, 0, -4);
             $key = preg_replace('/([a-z])([A-Z])/', '$1-$2', $key);
             $key = strtolower($key);
             // keep the command name and class name
             $list[$key] = $val;
         }
     }
     // override with explicit routings
     $this->_command_list = array_merge($list, $this->_routing);
     // sort, and done
     ksort($this->_command_list);
 }
Exemplo n.º 5
0
 /**
  * _setLayoutTemplates
  * Override Solar_Controller_Page _setLayoutTemplates
  * to add theme layout path to layout stack
  *
  */
 protected function _setLayoutTemplates()
 {
     // get the parents of the current class, including self
     $stack = array_reverse(Solar_Class::parents($this, true));
     // remove Solar_Base
     array_pop($stack);
     // convert underscores to slashes, and add /Layout
     foreach ($stack as $key => $val) {
         $stack[$key] = str_replace('_', '/', $val) . '/Layout';
     }
     // add theme layout path
     if ($this->_controller == 'admin') {
         $theme_name = $this->blog_admin_theme;
         $theme_layout_path = Solar::$system . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . $theme_name . DIRECTORY_SEPARATOR . 'layouts';
         $default_layout_path = Solar::$system . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'admin' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'layouts';
     } else {
         $theme_name = $this->blog_theme;
         $theme_layout_path = Solar::$system . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . $theme_name . DIRECTORY_SEPARATOR . 'layouts';
         $default_layout_path = Solar::$system . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . 'main' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'layouts';
     }
     if (Solar_Dir::exists($default_layout_path)) {
         array_unshift($stack, $default_layout_path);
     }
     if (Solar_Dir::exists($theme_layout_path) && $theme_layout_path != $default_layout_path) {
         array_unshift($stack, $theme_layout_path);
     }
     // done, add the stack
     $this->_view_object->setTemplatePath($stack);
 }
Exemplo n.º 6
0
 /**
  * 
  * Finds the base directory from the include-path to the requested class.
  * 
  * @param string $class The requested class file.
  * 
  * @return string The base directory.
  * 
  */
 protected function _findBaseByClass($class)
 {
     $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
     $base = Solar_File::exists($file);
     if ($base) {
         $neglen = -1 * strlen($file);
         $base = substr($base, 0, $neglen);
         return $base;
     }
     // no base yet, look for a dir (drop the .php, add a separator)
     $dir = substr($file, 0, -4);
     $base = Solar_Dir::exists($dir);
     if ($base) {
         $neglen = -1 * strlen($dir);
         $base = substr($base, 0, $neglen);
         return $base;
     }
     // still no base, we have a problem
     throw $this->_exception('ERR_NO_BASE_DIR', array('class' => $class));
 }
Exemplo n.º 7
0
 /**
  * 
  * Returns the directory for a specific class, plus an optional
  * subdirectory path.
  * 
  * @param string|object $spec The class or object to find parents
  * for.
  * 
  * @param string $sub Append this subdirectory.
  * 
  * @return string The class directory, with optional subdirectory.
  * 
  */
 public static function dir($spec, $sub = null)
 {
     if (is_object($spec)) {
         $class = get_class($spec);
     } else {
         $class = $spec;
     }
     // convert the class to a base directory to stem from
     $base = str_replace('_', DIRECTORY_SEPARATOR, $class);
     // does the directory exist?
     $dir = Solar_Dir::exists($base);
     if (!$dir) {
         throw Solar::exception('Solar_Class', 'ERR_NO_DIR_FOR_CLASS', 'Directory does not exist', array('class' => $class, 'base' => $base));
     } else {
         return Solar_Dir::fix($dir . DIRECTORY_SEPARATOR . $sub);
     }
 }
Exemplo n.º 8
0
 /**
  * 
  * Removes a file or directory symbolic link.
  * 
  * Actually, this will remove the file or directory even if it's not
  * a symbolic link, so be careful with it.
  * 
  * @param string $path The symbolic link to remove.
  * 
  * @return void
  * 
  */
 public static function remove($path)
 {
     // are we on a windows system prior to NT6?
     $is_win = strtolower(substr(PHP_OS, 0, 3)) == 'win';
     if ($is_win && php_uname('r') < 6) {
         throw Solar_Symlink::_exception('ERR_WINDOWS_VERSION');
     }
     // does the path exist for removal?
     $is_dir = Solar_Dir::exists($path);
     $is_file = Solar_File::exists($path);
     if (!$is_dir && !$is_file) {
         throw Solar_Symlink::_exception('ERR_PATH_NOT_FOUND', array('path' => $path));
     }
     // how to remove?
     if ($is_win) {
         // have to double up on removals because windows reports all
         // symlinks as files, even if they point to dirs.
         @unlink($path);
         Solar_Dir::rmdir($path);
     } else {
         // unix file or dir
         @unlink($path);
     }
 }