示例#1
0
 /**
  * 
  * Model-specific setup.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_belongsTo('node');
 }
 /**
  * 
  * 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_NAME');
     }
     $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/Mock/{$this->_studly}", "include/Test/{$this->_studly}", "include/{$this->_studly}");
     // remove the links
     foreach ($links as $link) {
         $this->_out("    Removing '{$link}' ... ");
         $path = "{$system}/{$link}";
         if (Solar_File::exists($path)) {
             unlink($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).");
 }
示例#3
0
 /**
  *
  * Model-specific setup.
  *
  * @return void
  *
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_hasMany('moduleinfo', array('foreign_class' => 'Foresmo_Model_ModuleInfo', 'foreign_key' => 'module_id'));
 }
示例#4
0
 /**
  *
  * Model-specific setup.
  *
  * @return void
  *
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_belongsTo('comments', array('foreign_class' => 'Foresmo_Model_Comments'));
 }
示例#5
0
文件: File.php 项目: agentile/foresmo
 /**
  * 
  * Fetches the roles for a username.
  * 
  * @param string $handle User handle to get roles for.
  * 
  * @return array An array of discovered roles.
  * 
  */
 public function fetch($handle)
 {
     // force the full, real path to the file
     $file = realpath($this->_config['file']);
     // does the file exist?
     if (!Solar_File::exists($file)) {
         throw $this->_exception('ERR_FILE_NOT_READABLE', array('file' => $file));
     }
     // load the file as an array of lines
     $lines = file($file);
     // the discovered roles
     $roles = array();
     // loop through each line, find the group, then see if the user
     // is on the line anywhere
     foreach ($lines as $line) {
         // eliminate all spaces, which cause mismatches when we get to
         // in_array() later
         $line = preg_replace("/\\s/", '', $line);
         // break apart at first ':'
         $pos = strpos($line, ':');
         // the group name is the part before the ':'
         $group = substr($line, 0, $pos);
         // the list of user handles comes after
         $tmp = substr($line, $pos + 1);
         $list = explode(',', $tmp);
         // is the user part of the group?
         if (in_array($handle, $list)) {
             $roles[] = $group;
         }
     }
     // done!
     return $roles;
 }
示例#6
0
文件: Class.php 项目: btweedy/foresmo
 /**
  * 
  * Loads a class or interface file from the include_path.
  * 
  * Thanks to Robert Gonzalez  for the report leading to this method.
  * 
  * @param string $name A Solar (or other) class or interface name.
  * 
  * @return void
  * 
  * @todo Add localization for errors
  * 
  */
 public static function autoload($name)
 {
     // did we ask for a non-blank name?
     if (trim($name) == '') {
         throw Solar::exception('Solar_Class', 'ERR_AUTOLOAD_EMPTY', 'No class or interface named for loading.', array('name' => $name));
     }
     // pre-empt further searching for the named class or interface.
     // do not use autoload, because this method is registered with
     // spl_autoload already.
     $exists = class_exists($name, false) || interface_exists($name, false);
     if ($exists) {
         return;
     }
     // convert the class name to a file path.
     $file = str_replace('_', DIRECTORY_SEPARATOR, $name) . '.php';
     // include the file and check for failure. we use Solar_File::load()
     // instead of require() so we can see the exception backtrace.
     Solar_File::load($file);
     // if the class or interface was not in the file, we have a problem.
     // do not use autoload, because this method is registered with
     // spl_autoload already.
     $exists = class_exists($name, false) || interface_exists($name, false);
     if (!$exists) {
         throw Solar::exception('Solar_Class', 'ERR_AUTOLOAD_FAILED', 'Class or interface does not exist in loaded file', array('name' => $name, 'file' => $file));
     }
 }
示例#7
0
文件: Nodes.php 项目: btweedy/foresmo
 /**
  * 
  * Model-specific setup.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_index = Solar_File::load($dir . 'index_info.php');
     /**
      * Special columns
      */
     $this->_serialize_cols[] = 'prefs';
     $this->_calculate_cols[] = 'tags_as_string';
     /**
      * Filters
      */
     // make sure the name is unique for its area and model
     $where = array('inherit = :inherit', 'area_id = :area_id');
     $this->_addFilter('name', 'validateUnique', $where);
     // other filters
     $this->_addFilter('email', 'validateEmail');
     $this->_addFilter('uri', 'validateUri');
     $this->_addFilter('editor_ipaddr', 'validateIpv4');
     $this->_addFilter('locale', 'validateLocaleCode');
     $this->_addFilter('mime', 'validateMimeType');
     $this->_addFilter('tags_as_string', 'validateSepWords');
     /**
      * Relationships.
      */
     $this->_belongsTo('area');
     $this->_hasMany('taggings');
     $this->_hasMany('tags', array('through' => 'taggings'));
 }
示例#8
0
 /**
  *
  * Model-specific setup.
  *
  * @return void
  *
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_hasMany('userinfo', array('foreign_class' => 'Foresmo_Model_UserInfo', 'foreign_key' => 'user_id'));
     $this->_hasOne('groups', array('foreign_class' => 'Foresmo_Model_Groups', 'native_col' => 'group_id', 'foreign_col' => 'id'));
 }
示例#9
0
文件: Tags.php 项目: agentile/foresmo
 /**
  *
  * Model-specific setup.
  *
  * @return void
  *
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_hasMany('posts_tags', array('foreign_class' => 'Foresmo_Model_PostsTags', 'foreign_key' => 'tag_id'));
     $this->_hasMany('posts', array('foreign_class' => 'Foresmo_Model_Posts', 'through' => 'posts_tags', 'through_key' => 'post_id', 'through_native_col' => 'tag_id', 'through_foreign_col' => 'post_id', 'conditions' => array('status = ?' => array(1))));
 }
示例#10
0
 public function setup()
 {
     // easier to do this here than as a property, since we use functions.
     $this->_config = array('adapters' => array(array('adapter' => 'Solar_Log_Adapter_File', 'events' => 'debug', 'file' => Solar_File::tmp('test_solar_log_adapter_multi.debug.log'), 'format' => '%e %m'), array('adapter' => 'Solar_Log_Adapter_File', 'events' => 'info, notice', 'file' => Solar_File::tmp('test_solar_log_adapter_multi.other.log'), 'format' => '%e %m')));
     parent::setup();
     @unlink($this->_config['adapters'][0]['file']);
     @unlink($this->_config['adapters'][1]['file']);
 }
示例#11
0
文件: Users.php 项目: btweedy/foresmo
 /**
  * 
  * Model setup.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_model_name = 'users';
     $this->_index = array('created', 'updated', 'handle' => 'unique');
 }
示例#12
0
 /**
  *
  * Model-specific setup.
  *
  * @return void
  *
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_belongsTo('tags', array('foreign_key' => 'id'));
     $this->_belongsTo('posts', array('foreign_key' => 'id'));
 }
示例#13
0
 /**
  *
  * Model-specific setup.
  *
  * @return void
  *
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_hasMany('comments');
     $this->_hasMany('permissions', array('through' => 'groupspermissions'));
 }
示例#14
0
 public function testCallbacks_instanceMethod()
 {
     $file = Solar_Class::dir('Mock_Solar') . 'callbacks-instance-method.php';
     Solar_File::load($file);
     $instance = Solar::factory('Solar_Callbacks_Instance_Method');
     Solar::callbacks(array(array($instance, 'callback')));
     $this->assertTrue($GLOBALS['SOLAR_CALLBACKS_INSTANCE_METHOD']);
 }
示例#15
0
 /**
  * 
  * Model setup.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_addFilter('email', 'validateEmail');
     $this->_addFilter('uri', 'validateUri');
     $this->_index_info = array('created', 'updated', 'email' => 'unique', 'uri');
 }
示例#16
0
 /**
  * 
  * Model setup.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_model_name = 'tags';
     $this->_hasMany('taggings');
     $this->_hasMany('nodes', array('through' => 'taggings'));
     $this->_index = array('name' => 'unique');
 }
示例#17
0
 /**
  * 
  * Model setup.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_model_name = 'areas';
     $this->_hasMany('nodes');
     $this->_belongsTo('user');
     $this->_index = array('created', 'updated', 'user_id');
 }
示例#18
0
 /**
  * 
  * Model setup.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_model_name = 'taggings';
     $this->_belongsTo('node');
     $this->_belongsTo('tag');
     $this->_index = array('node_id', 'tag_id');
 }
示例#19
0
 /**
  * 
  * Model setup.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     // recognize sequence columns
     $this->_sequence_cols = array('seq_foo' => 'test_solar_foo', 'seq_bar' => 'test_solar_bar');
     // recognize serialize columns
     $this->_serialize_cols = 'serialize';
 }
示例#20
0
文件: Posts.php 项目: btweedy/foresmo
 /**
  *
  * Model-specific setup.
  *
  * @return void
  *
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_hasMany('postinfo', array('foreign_class' => 'Foresmo_Model_PostInfo', 'foreign_key' => 'post_id'));
     $this->_hasMany('comments', array('foreign_class' => 'Foresmo_Model_Comments', 'foreign_key' => 'post_id'));
     $this->_hasMany('posts_tags', array('foreign_class' => 'Foresmo_Model_PostsTags', 'foreign_key' => 'post_id'));
     $this->_hasMany('tags', array('foreign_class' => 'Foresmo_Model_Tags', 'through' => 'posts_tags', 'through_key' => 'tag_id'));
     $this->_hasOne('users', array('foreign_class' => 'Foresmo_Model_Users', 'cols' => array('id', 'username', 'email'), 'native_col' => 'user_id', 'foreign_col' => 'id'));
 }
示例#21
0
文件: Nodes.php 项目: btweedy/foresmo
 /**
  * 
  * Model setup.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_model_name = 'nodes';
     $this->_belongsTo('area');
     $this->_belongsTo('user');
     $this->_hasOne('meta');
     $this->_hasMany('comments');
     $this->_hasMany('taggings');
     $this->_hasManyThrough('tags', 'taggings');
     $this->_index = array('created', 'updated', 'area_id', 'user_id', 'node_id', 'inherit');
 }
示例#22
0
文件: Areas.php 项目: btweedy/foresmo
 /**
  * 
  * Model-specific setup.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_index = Solar_File::load($dir . 'index_info.php');
     /**
      * Behaviors (serialize, sequence, filter).
      */
     $this->_serialize_cols[] = 'prefs';
     /**
      * Relationships.
      */
     $this->_hasMany('nodes');
 }
示例#23
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);
     }
 }
示例#24
0
文件: File.php 项目: btweedy/foresmo
 /**
  * 
  * Fetch access privileges for a user handle and roles.
  * 
  * @param string $handle The user handle.
  * 
  * @param array $roles The user roles.
  * 
  * @return array
  * 
  */
 public function fetch($handle, $roles)
 {
     // force the full, real path to the file
     $file = realpath($this->_config['file']);
     // does the file exist?
     if (!Solar_File::exists($file)) {
         throw $this->_exception('ERR_FILE_NOT_READABLE', array('file' => $this->_config['file'], 'realpath' => $file));
     }
     $handle = trim($handle);
     // eventual access list for the handle and roles
     $list = array();
     // get the access source and split into lines
     $src = file_get_contents($this->_config['file']);
     $src = preg_replace('/[ \\t]{2,}/', ' ', trim($src));
     $lines = explode("\n", $src);
     foreach ($lines as $line) {
         $line = trim($line);
         // allow blank lines
         if ($line == '') {
             continue;
         }
         // allow comment lines
         $char = substr($line, 0, 1);
         if ($char == '#') {
             continue;
         }
         // $info keys are ...
         // 0 => "allow" or "deny"
         // 1 => "handle", "role", or "owner"
         // 2 => handle/role name (not used by 'owner' type)
         // 3 => class name
         // 4 => action name
         $info = explode(' ', $line);
         if ($info[1] == 'handle' && $info[2] == $handle || $info[1] == 'handle' && $info[2] == '+' && $handle || $info[1] == 'handle' && $info[2] == '*' || $info[1] == 'role' && in_array($info[2], $roles) || $info[1] == 'role' && $info[2] == '*' || $info[1] == 'owner') {
             // content owner
             // keep the line
             $list[] = array('allow' => $info[0] == 'allow' ? true : false, 'type' => $info[1], 'name' => $info[2], 'class' => $info[3], 'action' => $info[4]);
         }
     }
     return $list;
 }
示例#25
0
 /**
  * 
  * Model setup.
  * 
  * @return void
  * 
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
     $this->_model_name = 'nodes';
     $this->_belongsTo('area');
     $this->_belongsTo('area_false', array('foreign_name' => 'areas', 'where' => '0=1'));
     $this->_belongsTo('user');
     $this->_hasOne('meta');
     $this->_hasOne('meta_false', array('foreign_name' => 'metas', 'where' => '0=1'));
     $this->_hasMany('comments');
     $this->_hasMany('comments_false', array('foreign_name' => 'comments', 'where' => '0=1', 'join_flag' => true));
     $this->_hasMany('taggings');
     $this->_hasManyThrough('tags', 'taggings');
     $this->_index = array('created', 'updated', 'area_id', 'user_id', 'node_id', 'inherit');
     $this->_hasManyThrough('tags_false', 'taggings', array('foreign_name' => 'tags', 'where' => '0=1'));
     $this->_hasMany('taggings_false', array('foreign_name' => 'taggings', 'where' => '0=1'));
     $this->_hasManyThrough('tags_through_false', 'taggings_false', array('foreign_name' => 'tags'));
     $this->_hasManyThrough('tags_false_through_false', 'taggings_false', array('foreign_name' => 'tags', 'where' => '0=1'));
 }
示例#26
0
 /**
  * 
  * Loads a class using the class stack prefixes.
  * 
  * {{code: php
  *     $stack = Solar::factory('Solar_Class_Stack');
  *     $stack->add('Base1');
  *     $stack->add('Base2');
  *     $stack->add('Base3');
  *     
  *     $class = $stack->load('Name');
  *     // $class is now the first instance of '*_Name' found from the         
  *     // class stack, looking first for 'Base3_Name', then            
  *     // 'Base2_Name', then finally 'Base1_Name'.
  * }}
  * 
  * @param string $name The class to load using the class stack.
  * 
  * @param bool $throw Throw an exception if no matching class is found
  * in the stack (default true).  When false, returns boolean false if no
  * matching class is found.
  * 
  * @return string The full name of the loaded class.
  * 
  * @throws Solar_Exception_ClassNotFound
  * 
  */
 public function load($name, $throw = true)
 {
     // some preliminary checks for valid class names
     if (!$name || $name != trim($name) || !ctype_alpha($name[0])) {
         if ($throw) {
             throw $this->_exception('ERR_CLASS_NOT_VALID', array('name' => $name, 'stack' => $this->_stack));
         } else {
             return false;
         }
     }
     // make sure the name is upper-cased, then loop through the stack
     // to find it.
     $name = ucfirst($name);
     foreach ($this->_stack as $prefix) {
         // the full class name
         $class = "{$prefix}{$name}";
         // pre-empt searching.
         // don't use autoload.
         if (class_exists($class, false)) {
             return $class;
         }
         // the related file
         $file = str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
         // does the file exist?
         if (!Solar_File::exists($file)) {
             continue;
         }
         // include it in a limited scope. we don't use Solar_File::load()
         // because we want to avoid exceptions.
         $this->_run($file);
         // did the class exist within the file?
         // don't use autoload.
         if (class_exists($class, false)) {
             // yes, we're done
             return $class;
         }
     }
     // failed to find the class in the stack
     if ($throw) {
         throw $this->_exception('ERR_CLASS_NOT_FOUND', array('class' => $name, 'stack' => $this->_stack));
     } else {
         return false;
     }
 }
示例#27
0
 /**
  *
  * Model-specific setup.
  *
  * @return void
  *
  */
 protected function _setup()
 {
     $dir = str_replace('_', DIRECTORY_SEPARATOR, __CLASS__) . DIRECTORY_SEPARATOR . 'Setup' . DIRECTORY_SEPARATOR;
     $this->_table_name = $this->_config['prefix'] . Solar_File::load($dir . 'table_name.php');
     $this->_table_cols = Solar_File::load($dir . 'table_cols.php');
 }
示例#28
0
 /**
  * 
  * Runs a series of callbacks using call_user_func_array().
  * 
  * The callback array looks like this:
  * 
  * {{code: php
  *     $callbacks = array(
  *         // static method call
  *         array('Class_Name', 'method', $param1, $param2, ...),
  *         
  *         // instance method call on a registry object
  *         array('registry-key', 'method', $param1, $param2, ...),
  *         
  *         // instance method call
  *         array($object, 'method', $param1, $param2, ...),
  *         
  *         // function call
  *         array(null, 'function', $param1, $param2, ...),
  *         
  *         // file include, as in previous versions of Solar
  *         'path/to/file.php',
  *     );
  * }}
  * 
  * @param array $callbacks The array of callbacks.
  * 
  * @return void
  * 
  * @see start()
  * 
  * @see stop()
  * 
  */
 public static function callbacks($callbacks)
 {
     foreach ((array) $callbacks as $params) {
         // include a file as in previous versions of Solar
         if (is_string($params)) {
             Solar_File::load($params);
             continue;
         }
         // $spec is an object instance, class name, or registry key
         $spec = array_shift($params);
         if (!is_object($spec)) {
             // not an object, so treat as a class name ...
             $spec = (string) $spec;
             // ... unless it's a registry key.
             if (Solar_Registry::exists($spec)) {
                 $spec = Solar_Registry::get($spec);
             }
         }
         // the method to call on $spec
         $func = array_shift($params);
         // make the call
         if ($spec) {
             call_user_func_array(array($spec, $func), $params);
         } else {
             call_user_func_array($func, $params);
         }
     }
 }
示例#29
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();
     }
 }
示例#30
0
 /**
  * 
  * Gets the option settings from the class hierarchy.
  * 
  * @return array
  * 
  */
 protected function _fetchGetoptOptions()
 {
     // the options to be set
     $options = array();
     // find the parents of this class, including this class
     $parents = Solar_Class::parents($this, true);
     array_shift($parents);
     // Solar_Base
     // get Info/options.php for each class in the stack
     foreach ($parents as $class) {
         $file = Solar_Class::file($class, 'Info/options.php');
         if ($file) {
             $options = array_merge($options, (array) Solar_File::load($file));
         }
     }
     return $options;
 }