Example #1
0
 public static function instantiate(User $admin, array $data)
 {
     $instance = new self();
     $instance->author()->associate($admin);
     $instance->fill($data)->save();
     return $instance;
 }
Example #2
0
 public static function parse(Tag $entry)
 {
     $self = new self();
     $self->term($entry->f("category.param(term)"));
     $self->link($entry->f("link.param(href)"));
     $self->content($entry->f("content.value()"));
     $self->updated($entry->f("updated.value()"));
     $user = new MixiUser();
     $user->name($entry->f("author.name.value()"));
     $user->link($entry->f("author.uri.value()"));
     $self->author($user);
     return $self;
 }
Example #3
0
 public static function parse_list($response)
 {
     $result = array();
     $res = Text::parse_json($response);
     if (!isset($res["responseData"]["results"])) {
         throw new Exception("Invalid data");
     }
     foreach ($res["responseData"]["results"] as $re) {
         $obj = new self();
         $obj->url($re["blogUrl"]);
         $obj->title($re["titleNoFormatting"]);
         $obj->content($re["content"]);
         $obj->author($re["author"]);
         $obj->published($re["publishedDate"]);
         $result[] = $obj;
     }
     return $result;
 }
Example #4
0
 public static function parse_list($response, $paginator)
 {
     $result = array();
     $res = Text::parse_json($response);
     if (isset($res["error"])) {
         throw new Exception($res["error"]);
     }
     if (!empty($res["pager"])) {
         $paginator = new Paginator($res["pager"]["clips_in_page"], $res["pager"]["current_page"], $res["pager"]["total_entries"]);
     }
     if (!empty($res["entries"])) {
         foreach ($res["entries"] as $re) {
             $obj = new self();
             $obj->id($re["id"]);
             $obj->title($re["title"]);
             $obj->url($re["permalink"]);
             $obj->author(new FlipClipAuthor($re["author"]["id"], $re["author"]["name"], $re["author"]["uri"]));
             $obj->summary($re["summary"]);
             $obj->updated($re["updated"]);
             if (isset($re["category"])) {
                 $obj->category(new FlipClipCategory($re["category"]["term"], $re["category"]["scheme"], $re["category"]["label"]));
             }
             if (isset($re["subcategory"])) {
                 $obj->category(new FlipClipCategory($re["subcategory"]["term"], $re["subcategory"]["scheme"], $re["subcategory"]["label"]));
             }
             if (isset($re["tags"])) {
                 foreach ($re["tags"] as $tag) {
                     $obj->tags(new FlipClipTag($tag["term"], $tag["scheme"], $tag["label"]));
                 }
             }
             $obj->embed_script($re["embed_script"]);
             $obj->latitude($re["latitude"]);
             $obj->longitude($re["longitude"]);
             $obj->privacy($re["privacy"]);
             $obj->duration($re["duration"]);
             $obj->image($re["image"]);
             $obj->image_medium($re["imageMedium"]);
             $obj->image_small($re["imageSmall"]);
             $obj->thumbnail($re["thumbnail"]);
             $result[] = $obj;
         }
     }
     return $result;
 }
Example #5
0
 public static function parse($src)
 {
     $result = array();
     foreach (Tag::anyhow($src)->in("item") as $in) {
         $o = new self();
         $o->title($in->f("title.value()"));
         $o->link($in->f("link.value()"));
         $o->description($in->f("description.value()"));
         $o->author($in->f("author.value()"));
         $o->category($in->f("category.value()"));
         $o->comments($in->f("comments.value()"));
         $o->pubDate($in->f("pubDate.value()"));
         $o->guid($in->f("guid.value()"));
         $value = $in->value();
         $o->enclosure = RssEnclosure::parse($value);
         $o->source = RssSource::parse($src);
         $result[] = $o;
     }
     return $result;
 }
Example #6
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 #7
0
 public static function instantiate(User $user, array $data, array $tags = [])
 {
     $instance = new self();
     $instance->author()->associate($user);
     $instance->fill($data)->save();
     if ($tags) {
         $instance->tags()->attach($tags);
     }
     return $instance;
 }
Example #8
0
 public static function instantiate(User $user, $parent, $data)
 {
     $instance = new self();
     $instance->author()->associate($user);
     if ($parent instanceof Post) {
         $instance->post()->associate($parent);
     } elseif ($parent instanceof Comment) {
         $instance->post_id = $parent->post_id;
     }
     $instance->fill($data)->save();
     if ($parent instanceof Comment) {
         $instance->makeChildOf($parent);
     }
     return $instance;
 }