コード例 #1
0
 protected function getModelEntityByString($postType)
 {
     try {
         $modelEntity = ModelEntity::factoryFromString($postType);
         return $modelEntity->getModel();
     } catch (Exception $e) {
         // don't care, not a strata model.
     }
 }
コード例 #2
0
ファイル: Taxonomy.php プロジェクト: francoisfaubert/strata
 /**
  * Factories a model entity based on the Wordpress key
  * @param  string $str
  * @return mixed An instantiated model
  * @throws Exception
  */
 public static function factoryFromWpQuery()
 {
     global $wp_query;
     if ((bool) $wp_query->is_tax) {
         $term = get_term_by("slug", $wp_query->query_vars['term'], $wp_query->query_vars['taxonomy']);
         return ModelEntity::factoryFromString($term->taxonomy, $term);
     }
     if ($wp_query->queried_object && get_class($wp_query->queried_object) === "WP_Term") {
         $term = $wp_query->queried_object;
         return ModelEntity::factoryFromString($term->taxonomy, $term);
     }
 }
コード例 #3
0
 /**
  * Configures the class writer and makes it generate the
  * test classes required by the accompanying model entity.
  */
 protected function generateEntityTest()
 {
     $classname = ModelEntity::generateClassName($this->keyword);
     $namespace = Strata::getNamespace() . "\\Test\\Model\\Entity";
     $destination = implode(DIRECTORY_SEPARATOR, array("test", "Model", "Entity", $classname . "Test.php"));
     $writer = $this->getWriter();
     $writer->setClassname($classname . "Test");
     $writer->setNamespace($namespace);
     $writer->setDestination($destination);
     $writer->setUses("\nuse Strata\\Test\\Test as StrataTest;\n");
     $writer->setExtends("StrataTest");
     $writer->create(true);
 }
コード例 #4
0
ファイル: Model.php プロジェクト: francoisfaubert/strata
 public static function getEntityFromPost(WP_Post $post)
 {
     return ModelEntity::factoryFromPost($post);
 }
コード例 #5
0
 private function getStrataModel($post)
 {
     if (preg_match('/^cpt_/', $post->post_type)) {
         try {
             $modelEntity = ModelEntity::factoryFromString($post->post_type);
             return $modelEntity->getModel();
         } catch (Exception $e) {
             // we dont care not a Strata model
         }
     }
 }