예제 #1
0
 /**
  * Finds the path to the file where the class is defined.
  *
  * @param string $class The name of the class
  *
  * @return bool|null|string The path, if found
  */
 public function find($class)
 {
     $classpath = get_object_vars($this->container->getParameter($this->classpath_key));
     krsort($classpath);
     $current_md5 = md5(RokCommon_Utils_ArrayHelper::toString($classpath));
     if ($this->last_md5 != $current_md5) {
         $this->last_md5 = $current_md5;
         $found_maps = array();
         foreach ($classpath as $priority => $priority_paths) {
             foreach ($priority_paths as $path) {
                 if (!in_array($path, $this->checked_paths)) {
                     $this->checked_paths[] = $path;
                     if (is_dir($path)) {
                         $path = $path . DIRECTORY_SEPARATOR . self::MAP_FILE_DEFAULT_NAME;
                     }
                     if (!in_array($path, $this->checked_paths) && is_file($path)) {
                         if (($path_map = @(include $path)) && is_array($path_map)) {
                             $found_maps[] = $path_map;
                         } else {
                             if (defined('ROKCOMMON_CORE_DEBUG') && ROKCOMMON_CORE_DEBUG) {
                                 error_log(sprintf('%s: Unable to load map file %s as a valid class map', get_class($this), $path));
                             }
                         }
                     }
                 }
             }
             if (isset($this->maps[$priority]) && !empty($found_maps)) {
                 $this->maps[$priority] = array_merge($this->maps[$priority], (array) $found_maps);
             } elseif (!empty($found_maps)) {
                 $this->maps[$priority] = (array) $found_maps;
             }
         }
         krsort($this->maps);
     }
     if ('\\' === $class[0]) {
         $class = substr($class, 1);
     }
     foreach ($this->maps as $priority_maps) {
         foreach ($priority_maps as $map) {
             if (isset($map[$class])) {
                 return $map[$class];
             }
         }
     }
     return false;
 }
예제 #2
0
 static function toString($array = null, $inner_glue = '=', $outer_glue = ' ', $keepOuterKey = false)
 {
     $output = array();
     if (is_array($array)) {
         foreach ($array as $key => $item) {
             if (is_array($item)) {
                 if ($keepOuterKey) {
                     $output[] = $key;
                 }
                 // This is value is an array, go and do it again!
                 $output[] = RokCommon_Utils_ArrayHelper::toString($item, $inner_glue, $outer_glue, $keepOuterKey);
             } else {
                 $output[] = $key . $inner_glue . '"' . $item . '"';
             }
         }
     }
     return implode($outer_glue, $output);
 }
예제 #3
0
 /**
  * Generates an HTML radio list.
  *
  * @param array An array of objects
  * @param string The value of the HTML name attribute
  * @param string Additional HTML attributes for the <select> tag
  * @param mixed The key that is selected
  * @param string The name of the object variable for the option value
  * @param string The name of the object variable for the option text
  * @return string HTML for the select list
  */
 public static function radiolist($data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false, $translate = false)
 {
     reset($data);
     $html = '';
     if (is_array($attribs)) {
         $attribs = RokCommon_Utils_ArrayHelper::toString($attribs);
     }
     $id_text = $idtag ? $idtag : $name;
     foreach ($data as $ind => $obj) {
         $k = $obj->{$optKey};
         $t = $translate ? rc__($obj->{$optText}) : $obj->{$optText};
         $id = isset($obj->id) ? $obj->id : null;
         $extra = '';
         $extra .= $id ? ' id="' . $obj->id . '"' : '';
         if (is_array($selected)) {
             foreach ($selected as $val) {
                 $k2 = is_object($val) ? $val->{$optKey} : $val;
                 if ($k == $k2) {
                     $extra .= ' selected="selected"';
                     break;
                 }
             }
         } else {
             $extra .= (string) $k == (string) $selected ? ' checked="checked"' : '';
         }
         $html .= "\n\t" . '<input type="radio" name="' . $name . '"' . ' id="' . $id_text . $k . '" value="' . $k . '"' . ' ' . $extra . ' ' . $attribs . '/>' . "\n\t" . '<label for="' . $id_text . $k . '" id="' . $id_text . $k . '-lbl" class="radiobtn_' . strtolower($obj->{$optText}) . '">' . $t . '</label>';
     }
     $html .= "\n";
     return $html;
 }