Adding a class alias at boot time in Laravel
History / Edit / PDF / EPUB / BIB / 2 min read (~281 words)I make extensive use of Laravel Debugbar to track performance of parts of my application. I sprinkle calls to Debugbar::startMeasure
and Debugbar::stopMeasure
to track the duration of certain segments of my code. However, when this code goes into production, this dependency isn't present. This causes the code to break since it cannot find Debugbar
anymore.
To solve this issue, I thought I would create a dummy Debugbar
class and have it added as an alias, so that any code depending on Debugbar
would still work, but end up as a "no operation". I found the article Dynamic class aliases in package which introduced the necessary piece of information to accomplish this.
<?php
use Illuminate\Foundation\AliasLoader;
use My\SuperPackage\FooBar;
class ServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function register()
{
$this->app->booting(function() {
$loader = AliasLoader::getInstance();
$loader->alias('FooBar', FooBar::class);
});
}
}
In my desired use case, I simply implemented the following changes:
In app/Providers/DebugbarServiceProvider.php
(a new file)
<?php
namespace App\Providers;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\ServiceProvider;
class DebugbarServiceProvider extends ServiceProvider
{
public function register()
{
if (!class_exists('Debugbar')) {
$loader = AliasLoader::getInstance();
$loader->alias('Debugbar', NullDebugbar::class);
}
}
}
class NullDebugbar
{
public static function __callStatic(string $name, array $arguments)
{
// Do nothing
}
}
In app/config/app.php
// under the 'providers' key, add
'providers' => [
[...]
// This will take care of loading the service provider defined above
App\Providers\DebugbarServiceProvider::class,
],
With those two changes, it is now possible to make use of Debugbar
in most places and have it work even without the Laravel Debugbar dependency installed.
- Produce content worth sharing
- Get feedback from peers
- Be vocal about your opinion
- Have expertise on what you share your opinion about
- Make yourself seen
- It's important to know what your goals are.
- It's important to understand why they are your goals.
- It's important to determine which goals are more important than others (goals priority).
- It's important to know which goals are dependent on other goals (goals decomposition and dependency).
- To reach a goal, you must first acquire the tools (knowledge, resources) to get to your objective.
-
It's important to know when to drop/abandon goals.
-
Sources of inefficiency
- Repeating the same task without sufficient experience.
-
Always try to figure out the most optimal path toward a goal
- Observe others successful at achieving the goal you want to achieve.
- Determine the differences between your state and theirs (what they know, what resources are available to them, etc.).
- How to determine when it is not possible to reach a goal at a given moment in time?
- Not enough time available
- Too costly
- Dependencies not resolved/ready
- Company name
- Product name
- What problem we are trying to solve
- How we are solving it
- Why should you trust if vs our competitors
- List what it can already do
- List what we expect to be able to do
- Link to our bug tracker
- Subscribe to our mailing list
- Become an alpha tester
- Early access program
-
Email to contact for any question
-
A/B testing of the price
-
Testimonials
-
Full website
- Packages/Pricing/Plans
- Feature list
-
On signing
- Send an email to a small survey
- Establish the price range people would be willing to pay
- Establish the type of model they'd be willing to accept
- Check what feature they're the most interested in
- Check which feature they'd like to see in the future
- Send an email to a small survey
- Events tracking
- Seen sections of the landing page/
- Mouse movement/heatmap/session recording (viewport + mouse position)
- Define the information you want to collect/know more about
- Unique Selling Proposition
- Hero shot
- Benefits of your offering
- Social proof
-
Call-To-Action (single conversion goal)
- The headline should inform the user what the product or service is all about
- http://unbounce.com/landing-pages/7-elements-of-a-winning-landing-page/
- https://blog.kissmetrics.com/beginners-guide-to-landing-pages/
- https://blog.hubspot.com/marketing/landing-page-examples-list
- http://thelandingpagecourse.com/landing-page-101-intro/
- https://blog.crazyegg.com/2014/10/07/landing-page-essentials/
- https://blog.crazyegg.com/2016/03/18/6-laws-of-landing-page-optimization/
- https://www.codeinwp.com/blog/landing-page-basics-you-should-know/
- https://www.weidert.com/whole_brain_marketing_blog/bid/206472/7-basic-landing-page-guidelines-that-make-or-break-conversions
- Want to read but
- Too long -> Transfer to pocket
- Want to watch but
- Too long -> Add to a youtube watchlist (which I'll never watch)
- I need them open to quickly enter data
- I want to watch them again and again
- Download with youtube-dl and watch using VLC
- Would maybe read one day, but definitely not now (very low priority)
- Transfer to pocket
- If a tab is scanned more than 5/10 times, it goes into the backlog bin