Skip to content

Commit 840be22

Browse files
committed
Move the is_dev_mode method to the core Application class instead of macro
1 parent 5f8e465 commit 840be22

4 files changed

Lines changed: 33 additions & 6 deletions

File tree

‎example/bootstrap/app.php‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
use Themeum\Framework\Application;
44

5-
Application::macro('is_dev_mode', function () {
6-
return defined('WP_DEBUG') && WP_DEBUG;
7-
});
8-
95
return Application::configure(FRAMEWORK_EXAMPLE_PATH)
106
->use_routing(FRAMEWORK_EXAMPLE_PATH . 'routes/api.php')
117
->use_prefix(FRAMEWORK_EXAMPLE_PREFIX)
8+
->app_mode('development')
129
->boot();

‎src/Application.php‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ class Application extends Container
127127
*/
128128
protected string $prefix = '';
129129

130+
/**
131+
* The application is in development mode
132+
* @var string
133+
*/
134+
protected string $mode = 'production';
135+
130136
/**
131137
* Create a new application instance
132138
*
@@ -790,4 +796,28 @@ public function get_namespace_for_path($relative_path)
790796

791797
throw new RuntimeException(sprintf('Unable to detect namespace for path [%s].', $relative_path));
792798
}
799+
800+
/**
801+
* Set the application mode.
802+
*
803+
* @param string $mode
804+
*
805+
* @return static
806+
*/
807+
public function app_mode($mode = 'production')
808+
{
809+
$this->mode = in_array(strtolower($mode), ['dev', 'development'], true) ? 'development' : 'production';
810+
811+
return $this;
812+
}
813+
814+
/**
815+
* Check if the application is in development mode.
816+
*
817+
* @return bool
818+
*/
819+
public function is_dev_mode()
820+
{
821+
return $this->mode === 'development';
822+
}
793823
}

‎src/Discovery/ListenerDiscovery.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public function cache(?string $path = null)
191191
mkdir(dirname($path), 0755, true);
192192
}
193193

194-
file_put_contents($path, "<?php \r\n\r\n/** Auto generated by discovering the listeners. */\r\n\r\nreturn " . var_export($this->listeners(), true) . ';');
194+
file_put_contents($path, "<?php \r\n\r\n/** Auto generated by discovering the listeners. Don't edit this file manually. */\r\n\r\nreturn " . var_export($this->listeners(), true) . ';');
195195

196196
return $this;
197197
}

‎src/Discovery/PolicyDiscovery.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function cache(?string $path = null)
160160
mkdir(dirname($path), 0755, true);
161161
}
162162

163-
file_put_contents($path, "<?php \r\n\r\n/** Auto generated by discovering the policies. */\r\n\r\nreturn " . var_export($this->policies(), true) . ';');
163+
file_put_contents($path, "<?php \r\n\r\n/** Auto generated by discovering the policies. Don't edit this file manually. */\r\n\r\nreturn " . var_export($this->policies(), true) . ';');
164164

165165
return $this;
166166
}

0 commit comments

Comments
 (0)