public final function __construct() { $class_name = get_called_class(); $reflection = new \ReflectionClass($class_name); $slug = strtolower($reflection->getShortName()); if (isset(self::$_instances[$slug])) { // Don't create a new one return; } $this->slug = $slug; $this->faker = \Faker\Factory::create(); self::$flag = apply_filters('fakerpress.modules_flag', self::$flag); $this->provider = (string) apply_filters("fakerpress.module.{$this->slug}.provider", $this->provider); $this->dependencies = (array) apply_filters("fakerpress.module.{$this->slug}.dependencies", $this->dependencies); // We need to merge the Provider to the Dependecies, so everything is loaded if (!empty($this->provider)) { $providers = array_merge($this->dependencies, (array) $this->provider); } else { $providers = $this->dependencies; } foreach ($providers as $provider_class) { $provider = new $provider_class($this->faker); $this->faker->addProvider($provider); } // Execute a method that can be overwritten by the called class $this->init(); if ($this->page) { add_action('admin_menu', array($this, '_action_setup_admin_page')); add_action('fakerpress.view.request.' . $this->page->view, array(&$this, '_action_parse_request')); } }
public final function __construct() { $class_name = get_called_class(); $reflection = new \ReflectionClass($class_name); $slug = strtolower($reflection->getShortName()); if (isset(self::$_instances[$slug])) { // Don't create a new one return; } $this->slug = $slug; $this->faker = \Faker\Factory::create(); self::$flag = apply_filters('fakerpress.modules_flag', self::$flag); $this->provider = (string) apply_filters("fakerpress.module.{$this->slug}.provider", $this->provider); $this->dependencies = (array) apply_filters("fakerpress.module.{$this->slug}.dependencies", $this->dependencies); // We need to merge the Provider to the Dependecies, so everything is loaded if (!empty($this->provider)) { $providers = array_merge($this->dependencies, (array) $this->provider); } else { $providers = $this->dependencies; } foreach ($providers as $provider_class) { $provider = new $provider_class($this->faker); $this->faker->addProvider($provider); } if (!empty($this->provider)) { // Create a Reflection of the Provider class to discover all the methods that will fake an Argument $provider_reflection = new \ReflectionClass($this->provider); $provider_methods = $provider_reflection->getMethods(); // Loop and verify which methods are will be faked on `generate` foreach ($provider_methods as $method) { if ($provider_reflection->getName() !== $method->class) { continue; } $this->faked[] = $method->name; } } // Execute a method that can be overwritten by the called class $this->init(); // Create a meta with the FakerPress flag, always $this->meta(self::$flag, null, 1); if ($this->page) { add_action('admin_menu', array($this, '_action_setup_admin_page')); add_action('fakerpress.view.request.' . $this->page->view, array(&$this, '_action_parse_request')); } }