protected function getModelEntityByString($postType) { try { $modelEntity = ModelEntity::factoryFromString($postType); return $modelEntity->getModel(); } catch (Exception $e) { // don't care, not a strata model. } }
/** * 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); } }
/** * 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); }
public static function getEntityFromPost(WP_Post $post) { return ModelEntity::factoryFromPost($post); }
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 } } }