Example #1
0
 public static function parse(Tag $entry)
 {
     $self = new self();
     $author = $entry->f("author");
     if ($author !== null) {
         $self->name($author->f("name.value()"));
         $self->image($author->f("tracks:image.value()"));
         $self->relation($author->f("tracks:relation.value()"));
     } else {
         $self->name($entry->f("title.value()"));
         $self->image($entry->f("icon.value()"));
         $self->relation("friends");
     }
     $self->updated($entry->f("updated.value()"));
     $self->link($entry->f("link.param(href)"));
     return $self;
 }
Example #2
0
 public static function parse(&$src)
 {
     $result = array();
     foreach (Tag::anyhow($src)->in("author") as $in) {
         $src = str_replace($in->plain(), "", $src);
         $o = new self();
         $o->name($in->f("name.value()"));
         $o->url($in->f("url.value()"));
         $o->email($in->f("email.value()"));
         $result[] = $o;
     }
     return $result;
 }
Example #3
0
 /**
  * $objectsに同名のキーがあればマージし無ければ追加する
  * @param self{} $objects 対象の連想配列
  * @param string $doc 値の情報を表す文字列
  * @param string $class 定義されているクラス名
  * @param string $prefix 名称につく接頭辞
  */
 public static function merge(array &$objects, $doc, $class, $prefix = null)
 {
     $self = new self();
     $self->set($doc, $class);
     $name = $prefix . $self->name();
     if ($self->is_name() && isset($objects[$name])) {
         $objects[$name]->type($self->type());
         $objects[$name]->array($self->array());
         $objects[$name]->module($self->module());
         if ($self->is_document()) {
             $objects[$name]->document($self->document());
         }
     }
 }
Example #4
0
 public static function parse(&$src)
 {
     $result = array();
     \org\rhaco\Xml::set($x, '<:>' . $src . '</:>');
     foreach ($x->in('author') as $in) {
         $src = str_replace($in->plain(), '', $src);
         $o = new self();
         $o->name($in->f('name.value()'));
         $o->url($in->f('url.value()'));
         $o->email($in->f('email.value()'));
         if (!$o->is_url()) {
             $o->url($in->f('uri.value()'));
         }
         $result[] = $o;
     }
     return $result;
 }
Example #5
0
 /**
  * ヘルプを表示
  *
  * @param string $class クラス名
  * @param string $method メソッド名
  * @param boolean $flush 出力するか
  * @return string
  */
 public static final function help($class, $method = null, $flush = true)
 {
     $ref = new self($class);
     $doc = "\nHelp in class " . $ref->name() . " ";
     $docs = array();
     $tab = "  ";
     if (empty($method)) {
         $doc .= ":\n";
         $doc .= $tab . str_replace("\n", "\n" . $tab, $ref->document()) . "\n\n";
         if ($ref->is_extends()) {
             $doc .= $tab . "Extends:\n";
             $doc .= $tab . $tab . $ref->extends() . "\n\n";
         }
         if ($ref->is_mixin_object()) {
             $doc .= $tab . "Mixin:\n";
             foreach ($ref->mixin_object() as $o) {
                 $doc .= $tab . $tab . $o . "\n";
             }
             $doc .= "\n";
         }
         $doc .= $tab . "Author:\n";
         $doc .= $tab . $tab . $ref->author() . "\n\n";
         $doc .= $tab . "Valid line: \n";
         $doc .= $tab . $tab . $ref->valid_line() . " lines";
         $doc .= "\n\n";
         $doc .= $tab . "Const: \n";
         foreach ($ref->def() as $d) {
             $doc .= $tab . $tab . "[" . $d->name() . "]" . $tab . $d->document() . "\n";
         }
         $doc .= "\n";
         $public = $static = $protected = $methods = array();
         foreach ($ref->methods() as $name => $m) {
             if (!$m->is_extends()) {
                 if ($m->is_public()) {
                     if ($m->is_static()) {
                         $static[$name] = $m;
                     } else {
                         $public[$name] = $m;
                     }
                 } else {
                     if ($m->is_protected() && !$m->is_final() && !$m->is_static()) {
                         $protected[$name] = $m;
                     } else {
                         if (!$m->is_private() && substr($m->name(), 0, 1) != "_") {
                             $methods[$name] = $m;
                         }
                     }
                 }
             }
         }
         $doc .= $tab . "Static methods defined here:\n";
         $len = Text::length(array_keys($static));
         foreach ($static as $m) {
             $doc .= $tab . $tab . str_pad($m->name(), $len) . ": " . $m->summary() . "\n";
         }
         $doc .= "\n\n";
         $doc .= $tab . "Methods defined here:\n";
         $len = Text::length(array_keys($public));
         foreach ($public as $m) {
             $doc .= $tab . $tab . str_pad($m->name(), $len) . ": " . $m->summary() . "\n";
         }
         $doc .= "\n\n";
         $doc .= $tab . "Methods list you can override:\n";
         $len = Text::length(array_keys($protected));
         foreach ($protected as $m) {
             $doc .= $tab . $tab . str_pad($m->name(), $len) . ": " . $m->summary() . "\n";
         }
         $doc .= "\n\n";
         $doc .= $tab . "Methods list:\n";
         foreach ($methods as $m) {
             $doc .= $tab . $tab . $m->str() . "\n";
         }
     } else {
         if ($ref->is_methods($method)) {
             $m = $ref->in_methods($method);
             $doc .= "in method " . $method . ":\n";
             $doc .= $tab . str_replace("\n", "\n" . $tab, $m->document()) . "\n\n";
             $doc .= "\n";
             if ($m->is_author()) {
                 $doc .= $tab . "Author:\n";
                 $doc .= $tab . $tab . $m->author() . "\n\n";
             }
             $doc .= $tab . "Parameter:\n";
             $len = Text::length(array_keys($m->param()));
             foreach ($m->param() as $name => $o) {
                 $doc .= $tab . $tab . str_pad($name, $len) . " : [" . $o->type() . "] " . ($o->require() ? "" : "(default: " . $o->default() . ") ") . $o->document() . "\n";
             }
             $doc .= "\n";
             $doc .= $tab . "Return:\n";
             $doc .= $tab . $tab . $m->return() . "\n\n";
             if ($m->is_request()) {
                 $doc .= $tab . "Request:\n";
                 $len = Text::length(array_keys($m->request()));
                 foreach ($m->request() as $name => $d) {
                     $doc .= $tab . $tab . str_pad($name, $len) . " : " . $d . "\n";
                 }
                 $doc .= "\n";
             }
             if ($m->is_module()) {
                 $doc .= $tab . "Module Method:\n";
                 $len = Text::length(array_keys($m->module()));
                 foreach ($m->module() as $name => $d) {
                     $doc .= $tab . $tab . str_pad($name, $len) . " : " . $d . "\n";
                 }
                 $doc .= "\n";
             }
         } else {
             throw new InvalidArgumentException($class . " " . $method . " not found");
         }
     }
     if ($flush) {
         print $doc;
     }
     return $doc;
 }
Example #6
0
 /**
  * EXIFを取得する
  * @param string $filename
  * @param string $name
  * @return $this
  */
 public static function get($filename, $name = null)
 {
     if (empty($filename)) {
         throw new \org\rhaco\io\MediaInfo\MediaInfoException('undef filename');
     }
     if (!is_file($filename)) {
         throw new \org\rhaco\io\MediaInfo\MediaInfoException($filename . ' not found');
     }
     $self = new self();
     $self->name($name);
     $self->size(sprintf('%u', @filesize($filename)));
     $info = getimagesize($filename);
     if ($info !== false) {
         try {
             switch ($info[2]) {
                 case IMAGETYPE_JPEG:
                     if (self::cmd() !== '') {
                         $exif = self::exiftool($filename, $self);
                     } else {
                         $exif = exif_read_data($filename);
                         foreach ($exif as $k => $v) {
                             $self->raw($k, $v);
                         }
                         $self->filename(isset($exif['FileName']) ? $exif['FileName'] : basename($filename));
                         $self->width(isset($exif['ExifImageWidth']) ? $exif['ExifImageWidth'] : (isset($info[0]) ? $info[0] : null));
                         $self->height(isset($exif['ExifImageLength']) ? $exif['ExifImageLength'] : (isset($info[1]) ? $info[1] : null));
                         if (isset($exif['DateTimeOriginal']) && !empty($exif['DateTimeOriginal'])) {
                             $self->create_date_value($exif['DateTimeOriginal']);
                             $timestamp = ctype_digit((string) $self->create_date_value()) ? (int) $self->create_date_value() : strtotime($self->create_date_value());
                             if ($timestamp !== false) {
                                 $self->create_date($timestamp);
                             }
                         }
                         if (isset($exif['Make'])) {
                             $self->make($exif['Make']);
                         }
                         if (isset($exif['Model'])) {
                             $self->model($exif['Model']);
                         } else {
                             if (isset($exif['Camera Model Name'])) {
                                 $self->model($exif['Camera Model Name']);
                             }
                         }
                         if (isset($exif['Orientation'])) {
                             switch ($exif['Orientation']) {
                                 case 3:
                                     $self->rotation(180);
                                     break;
                                 case 6:
                                     $self->rotation(90);
                                     break;
                                 case 8:
                                     $self->rotation(270);
                                     break;
                             }
                         }
                         if (isset($exif['GPSLatitudeRef']) && isset($exif['GPSLatitude']) && isset($exif['GPSLongitudeRef']) && isset($exif['GPSLongitude'])) {
                             list($a, $b) = explode('/', $exif['GPSLatitude'][0]);
                             $latitude = $a / $b;
                             list($a, $b) = explode('/', $exif['GPSLatitude'][1]);
                             $latitude = $latitude + $a / $b / 60;
                             list($a, $b) = explode('/', $exif['GPSLatitude'][2]);
                             $latitude = $latitude + $a / $b / 3600;
                             list($a, $b) = explode('/', $exif['GPSLongitude'][0]);
                             $longitude = $a / $b;
                             list($a, $b) = explode('/', $exif['GPSLongitude'][1]);
                             $longitude = $longitude + $a / $b / 60;
                             list($a, $b) = explode('/', $exif['GPSLongitude'][2]);
                             $longitude = $longitude + $a / $b / 3600;
                             $self->latitude($latitude * ($exif['GPSLatitudeRef'] == 'N' ? 1 : -1));
                             $self->longitude($longitude * ($exif['GPSLongitudeRef'] == 'E' ? 1 : -1));
                         }
                     }
                     break;
                 default:
                     $self->type('photo');
                     $self->filename(basename($filename));
                     $self->width(isset($info[0]) ? $info[0] : null);
                     $self->height(isset($info[1]) ? $info[1] : null);
                     break;
             }
         } catch (\ErrorException $e) {
             throw new \org\rhaco\io\MediaInfo\MediaInfoException('Unsupported ' . $e->getMessage());
         }
     } else {
         $exif = self::exiftool($filename, $self);
         if (!isset($exif['MIME Type']) || strpos(strtolower($exif['MIME Type']), 'video') === false) {
             throw new \org\rhaco\io\MediaInfo\MediaInfoException('not supported');
         }
         $self->type('video');
     }
     return $self;
 }
Example #7
0
 public static function createFromToken(FunctionDefine $aFunctionDefine, Aspect $aAspect)
 {
     if (!($aClassDefine = $aFunctionDefine->belongsClass())) {
         throw new Exception("传入的 \$aFunctionDefine 参数无效,必须是一个类方法的定义Token");
     }
     if (!($aDocToken = $aFunctionDefine->docToken())) {
         throw new Exception("传入了无效Advice %s::%s() :没有DocComment申明。", array($aClassDefine->fullName(), $aFunctionDefine->name()));
     }
     $aDocComment = $aDocToken->docComment();
     $sPosition = null;
     if ($aDocComment->hasItem('advice')) {
         $sPosition = $aDocComment->item('advice');
         $sPosition = trim($sPosition);
         $sPosition = strtolower($sPosition);
     }
     if (!$sPosition) {
         $sPosition = self::after;
     }
     $aAdvice = new self($aFunctionDefine->name(), $aFunctionDefine->bodySource(), $sPosition, $aFunctionDefine);
     $aAdvice->aDefineAspect = $aAspect;
     // for pointcut
     foreach ($aDocComment->itemIterator('for') as $sPointcutName) {
         if (!($aPointcut = $aAspect->pointcuts()->getByName($sPointcutName))) {
             throw new Exception("定义Aspect %s 的 Advice %s 时,申明了一个不存在的 Pointcut: %s 。", array($sAspectName, $aAdvice->name(), $sPointcutName));
         }
         $aAdvice->arrForPointcuts[] = $sPointcutName;
     }
     return $aAdvice;
 }
Example #8
0
 public function append($path)
 {
     $pathDO = new self(array('filepath' => $path));
     $newDO = new self(array('filepath' => $this->path() . DIRECTORY_SEPARATOR . $pathDO->name()));
     return $newDO;
 }