Exemple #1
0
 /**
  * 
  * Test -- Sets the base directory for the class map.
  * 
  */
 public function testSetBase()
 {
     $dir = Solar_Class::dir('Solar', '..');
     $base = Solar_Dir::fix(realpath($dir));
     $map = Solar::factory('Solar_Class_Map');
     $map->setBase($base);
     $actual = $map->getBase();
     $this->assertSame($actual, $base);
 }
Exemple #2
0
 /**
  * 
  * Writes the Solar_Mail_Message headers and content to a file.
  * 
  * @return bool True on success, false on failure.
  * 
  */
 protected function _send()
 {
     $file = Solar_Dir::fix($this->_config['dir']) . $this->_config['prefix'] . date('Y-m-d_H-i-s') . '.' . substr(microtime(), 2, 6);
     $text = $this->_headersToString($this->_mail->fetchHeaders()) . $this->_mail->getCrlf() . $this->_mail->fetchContent();
     $result = file_put_contents($file, $text);
     if ($result === false) {
         return false;
     } else {
         return true;
     }
 }
Exemple #3
0
 /**
  * _postConstruct
  *
  * @param $model
  */
 protected function _postConstruct()
 {
     parent::_postConstruct();
     $this->_model = $this->_config['model'];
     $this->web_root = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : Solar::$system . DIRECTORY_SEPARATOR . 'docroot' . DIRECTORY_SEPARATOR;
     $this->web_root = Solar_Dir::fix($this->web_root);
     $class_arr = explode('_', get_class($this));
     $this->_module_name = end($class_arr);
     $this->_module_info = $this->_model->modules->fetchModuleInfoByName($this->_module_name);
     $this->_setViewPath();
     $this->_setViewFile();
     $this->_setView();
     $this->_view->addHelperClass('Foresmo_View_Helper');
 }
 /**
  * 
  * 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);
     }
 }
Exemple #5
0
 public function testSet_byArray()
 {
     $expect = array(Solar_Dir::fix('/path/foo/'), Solar_Dir::fix('/path/bar/'), Solar_Dir::fix('/path/baz/'));
     $stack = Solar::factory('Solar_Path_Stack');
     $stack->set($expect);
     $this->assertSame($stack->get(), $expect);
 }
Exemple #6
0
 /**
  * 
  * Post-construction tasks to complete object construction.
  * 
  * @return void
  * 
  */
 protected function _postConstruct()
 {
     parent::_postConstruct();
     // path to storage; include the prefix as part of the path
     $this->_path = Solar_Dir::fix($this->_config['path'] . '/' . $this->_prefix);
     // whether or not to hash
     $this->_hash = $this->_config['hash'];
     // build the context property
     if (is_resource($this->_config['context'])) {
         // assume it's a context resource
         $this->_context = $this->_config['context'];
     } elseif (is_array($this->_config['context'])) {
         // create from scratch
         $this->_context = stream_context_create($this->_config['context']);
     } else {
         // not a resource, not an array, so ignore.
         // have to use a resource of some sort, so create
         // a blank context resource.
         $this->_context = stream_context_create(array());
     }
     // make sure the cache directory is there; create it if
     // necessary.
     if (!is_dir($this->_path)) {
         mkdir($this->_path, $this->_config['mode'], true, $this->_context);
     }
 }
Exemple #7
0
 /**
  * 
  * Writes the model "Locale/en_US.php" file.
  * 
  * @param string $class The model class name.
  * 
  * @return void
  * 
  */
 protected function _writeLocaleFile($class)
 {
     $dir = Solar_Dir::fix($this->_target . str_replace('_', '/', $class) . '/Locale');
     // does the locale file already exist?
     $file = $dir . DIRECTORY_SEPARATOR . 'en_US.php';
     if (file_exists($file)) {
         $this->_outln('Locale file for en_US already exists.');
         return;
     }
     // does it exist?
     if (!$this->_table_cols) {
         $this->_outln('Not creating locale file; no table_cols available.');
         return;
     }
     // create a label value & descr placeholder for each column
     $list = array_keys($this->_table_cols);
     $label = array();
     $descr = array();
     foreach ($list as $col) {
         $key = strtoupper("LABEL_{$col}");
         $label[$key] = ucwords(str_replace('_', ' ', $col));
         $key = strtoupper("DESCR_{$col}");
         $descr[$key] = '';
     }
     // write the en_US file
     $this->_out('Saving locale file for en_US ... ');
     $data = array_merge($label, $descr);
     $text = var_export($data, true);
     file_put_contents($file, "<?php return {$text};");
     $this->_outln('done.');
 }
Exemple #8
0
 /**
  * _setup
  *
  * Set variables used throughout the app here.
  */
 protected function _setup()
 {
     parent::_setup();
     $this->web_root = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : Solar::$system . '/docroot/';
     $this->web_root = Solar_Dir::fix($this->web_root);
     if (!isset($this->session)) {
         $this->session = Solar::factory('Solar_Session', array('class' => 'Foresmo_App'));
     }
     // Set CSRF Token
     $this->_setToken();
     $this->csrf_token = $this->_getToken();
     $this->installed = (bool) Solar_Config::get('Foresmo', 'installed');
     if (!$this->installed && $this->_controller != 'install' && $this->_controller != 'ajax') {
         $this->_redirect('/install');
     } elseif (!$this->installed) {
         return;
     }
     $adapter_type = Solar_Config::get('Solar_Sql', 'adapter');
     $adapter = Solar::factory($adapter_type);
     try {
         $adapter->connect();
     } catch (Exception $e) {
         // Display No DB Connection view and exit.
         $this->connect = false;
         $view = Solar::factory('Solar_View', array('template_path' => dirname(__FILE__) . '/Base/View/'));
         $view->assign('adapter_config', Solar_Config::get($adapter_type));
         echo $view->fetch('nodb');
         exit;
     }
     $this->_adapter = $adapter;
     $this->_model = Solar_Registry::get('model_catalog');
     // Set Cache
     $cache_settings = Solar_Config::get('Foresmo', 'cache');
     if (isset($cache_settings['adapter'])) {
         $this->_model->_config['cache'] = $cache_settings;
         $this->_cache = Solar::factory('Solar_Cache', $cache_settings);
     }
     $this->_setBlogOptions();
     $this->page_title = $this->blog_title;
     $time_info = Foresmo::getTimeInfo();
     Foresmo::$date_format = $time_info['blog_date_format'];
     Foresmo::$timezone = $time_info['blog_timezone'];
     $this->_model->posts->published_posts_count = $this->_model->posts->fetchPublishedPostsCount();
     $this->_setPagesCount($this->_model->posts->posts_per_page, $this->_model->posts->published_posts_count);
     //$this->_layout_default = $this->blog_theme;
     // Load Themes
     $this->_themes = Solar::factory('Foresmo_Themes', array('model' => $this->_model));
     // Load Modules
     $this->_modules = Solar::factory('Foresmo_Modules', array('model' => $this->_model));
     $this->_modules->registerModuleHooks();
     $this->enabled_modules = $this->_modules->getEnabledModulesData();
 }
Exemple #9
0
 public function testFindReal()
 {
     // use the testing directory to look for __construct.phpt files
     $dir = $this->_support_path;
     $path = array("{$dir}/a", "{$dir}/b", "{$dir}/c");
     $stack = Solar::factory('Solar_Path_Stack');
     $stack->add($path[0]);
     $stack->add($path[1]);
     $stack->add($path[2]);
     // should find it at Solar_Base
     $actual = $stack->findReal('target1');
     $expect = Solar_Dir::fix($path[0]) . 'target1';
     $this->assertSame($expect, $actual);
     // should find it at Solar_Debug_Timer
     $actual = $stack->findReal('target2');
     $expect = Solar_Dir::fix($path[1]) . 'target2';
     $this->assertSame($expect, $actual);
     // should find it at Solar_Debug_Var
     $actual = $stack->findReal('target3');
     $expect = Solar_Dir::fix($path[2]) . 'target3';
     $this->assertSame($expect, $actual);
     // should not find it at all
     $actual = $stack->findReal('no_such_file');
     $this->assertFalse($actual);
 }
Exemple #10
0
 /**
  * 
  * Sets the base directory target.
  * 
  * @return void
  * 
  */
 protected function _setTarget()
 {
     $target = Solar::$system . "/include";
     $this->_target = Solar_Dir::fix($target);
 }
 /**
  * 
  * Main action: parse the classes and write documentation.
  * 
  * @param string $class Start parsing with this class and recursively
  * descend.
  * 
  * @return void
  * 
  */
 protected function _exec($class = null)
 {
     $begin = time();
     if (!$class) {
         $class = 'Solar';
     }
     // get the source dir
     $this->_source = $this->_options['source'];
     if (!$this->_source) {
         // get the directory where this class is stored
         $this->_source = Solar_Dir::name(__FILE__, 2);
     }
     // start parsing
     $this->_outln("Parsing source files from '{$this->_source}' ... ");
     $ref = Solar::factory('Solar_Docs_Apiref');
     $ref->addFiles($this->_source, $class);
     // are we only linting the sources?
     if ($this->_options['lint']) {
         $this->_outln('Done.');
         return;
     }
     // get the target API dir
     $class_dir = $this->_options['class_dir'];
     if ($class_dir) {
         $this->_class_dir = Solar_Dir::fix($class_dir);
     }
     // do we have a class dir?
     if (!$this->_class_dir) {
         throw $this->_exception('ERR_NO_CLASS_DIR');
     }
     // get the target package dir (if any)
     $package_dir = $this->_options['package_dir'];
     if ($package_dir) {
         $this->_package_dir = Solar_Dir::fix($package_dir);
     }
     // do we have a package dir?
     if (!$this->_package_dir) {
         throw $this->_exception('ERR_NO_PACKAGE_DIR');
     }
     // get the docbook dir
     $docbook_dir = $this->_options['docbook_dir'];
     if ($docbook_dir) {
         $this->_docbook_dir = Solar_Dir::fix($docbook_dir);
     }
     // import the class data
     $this->api = $ref->api;
     ksort($this->api);
     // import the package data
     $this->packages = $ref->packages;
     ksort($this->packages);
     // write out the package pages
     $this->_outln();
     $this->writePackages();
     // write out the class pages
     $this->_outln();
     $this->writeClasses();
     // time note
     $time = time() - $begin;
     $this->_outln("Wiki docs written in {$time} seconds.");
     // convert to docbook?
     if ($this->_docbook_dir) {
         $this->_outln();
         $cli = Solar::factory('Solar_Cli_MakeDocbook');
         $argv = array("--class-dir={$this->_class_dir}", "--package-dir={$this->_package_dir}", "--docbook-dir={$this->_docbook_dir}", $class);
         $cli->exec($argv);
         $this->_outln();
         $time = time() - $begin;
         $this->_outln("All docs written and converted in {$time} seconds.");
     }
 }
 /**
  * 
  * Main action: parse the classes and write documentation.
  * 
  * @param string $class Start parsing with this class and recursively
  * descend.
  * 
  * @return void
  * 
  */
 protected function _exec($class = null)
 {
     $begin = time();
     if (!$class) {
         $class = 'Solar';
     }
     // get the source dir
     $this->_source = $this->_options['source'];
     if (!$this->_source) {
         // get the directory where this class is stored
         $this->_source = Solar_Dir::name(__FILE__, 2);
     }
     // start parsing
     $this->_outln("Parsing source files from '{$this->_source}' ... ");
     $ref = Solar::factory('Solar_Docs_Apiref');
     $ref->addFiles($this->_source, $class);
     // are we only linting the sources?
     if ($this->_options['lint']) {
         $this->_outln('Done.');
         return;
     }
     // get the target API dir
     $class_dir = $this->_options['class_dir'];
     if ($class_dir) {
         $this->_class_dir = Solar_Dir::fix($class_dir);
     }
     // do we have a class dir?
     if (!$this->_class_dir) {
         throw $this->_exception('ERR_NO_CLASS_DIR');
     }
     // get the target package dir (if any)
     $package_dir = $this->_options['package_dir'];
     if ($package_dir) {
         $this->_package_dir = Solar_Dir::fix($package_dir);
     }
     // do we have a package dir?
     if (!$this->_package_dir) {
         throw $this->_exception('ERR_NO_PACKAGE_DIR');
     }
     // import the class data
     $this->api = $ref->api;
     ksort($this->api);
     // import the package data
     $this->packages = $ref->packages;
     ksort($this->packages);
     // write out the package pages
     $this->_outln();
     $this->writePackages();
     // write out the class pages
     $this->_outln();
     $this->writeClasses();
     // done!
     $this->_outln();
     $time = time() - $begin;
     $this->_outln("Docs completed in {$time} seconds.");
 }
Exemple #13
0
 /**
  * 
  * Sets the base directory for the class map.
  * 
  * @param string $base The base directory.
  * 
  * @return void
  * 
  */
 public function setBase($base)
 {
     $this->_base = Solar_Dir::fix($base);
 }
Exemple #14
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);
     }
 }
Exemple #15
0
 /**
  * 
  * Loads the translation array for a given class.
  * 
  * @param string $class The class name to load translations for.
  * 
  * @return void
  * 
  */
 protected function _load($class)
 {
     // build the file name.  note that we use the fixdir()
     // method, which automatically replaces '/' with the
     // correct directory separator.
     $base = str_replace('_', '/', $class);
     $file = Solar_Dir::fix($base . '/Locale/') . $this->_code . '.php';
     // can we find the file?
     $target = Solar_File::exists($file);
     if ($target) {
         // put the locale values into the shared locale array
         $this->trans[$class] = (array) Solar_File::load($target);
     } else {
         // could not find file.
         // fail silently, as it's often the case that the
         // translation file simply doesn't exist.
         $this->trans[$class] = array();
     }
 }
Exemple #16
0
 /**
  * 
  * Sets directory paths for reading and writing.
  * 
  * @return void
  * 
  */
 protected function _setDirs()
 {
     // get the source class dir
     $class_dir = $this->_options['class_dir'];
     if ($class_dir) {
         $this->_class_dir = Solar_Dir::fix($class_dir);
     }
     // do we have a class dir?
     if (!$this->_class_dir) {
         throw $this->_exception('ERR_NO_CLASS_DIR');
     }
     // get the source package dir (if any)
     $package_dir = $this->_options['package_dir'];
     if ($package_dir) {
         $this->_package_dir = Solar_Dir::fix($package_dir);
     }
     // do we have a package dir?
     if (!$this->_package_dir) {
         throw $this->_exception('ERR_NO_PACKAGE_DIR');
     }
     // get the target docbook dir (if any)
     $docbook_dir = $this->_options['docbook_dir'];
     if ($docbook_dir) {
         $this->_docbook_dir = Solar_Dir::fix($docbook_dir);
     }
     // do we have a docbook dir?
     if (!$this->_docbook_dir) {
         throw $this->_exception('ERR_NO_DOCBOOK_DIR');
     }
 }
 /**
  * 
  * Sets the base directory target.
  * 
  * @return void
  * 
  */
 protected function _setTarget()
 {
     $target = $this->_options['target'];
     if (!$target) {
         // use the solar system "include" directory.
         // that should automatically point to the right vendor for us.
         $target = Solar::$system . "/include";
     }
     $this->_target = Solar_Dir::fix($target);
 }
Exemple #18
0
 /**
  * 
  * Sets the base directory target.
  * 
  * @return void
  * 
  */
 protected function _setTarget()
 {
     // look for a test directory, otherwise assume that the tests are
     // in the same dir
     $this->_target = $this->_options['target'];
     if (!$this->_target) {
         $this->_target = Solar::$system . "/include";
     }
     // make sure it matches the OS.
     $this->_target = Solar_Dir::fix($this->_target);
     // make sure it exists
     if (!is_dir($this->_target)) {
         throw $this->_exception('ERR_TARGET_NOT_EXIST');
     }
 }