- FEATURES
- Autoload
- Class Reflection
- Magic Methods
- Exceptions
- Late Static Binding
- Type Hinting
- SPL
- PHPUNIT
- PHAR
- COMPOSER
- Carbon
- Guzzle
- Faker
- Math
- Requests
- DESIGN PATTERNS
- Singleton Pattern
- Observer Pattern
- Strategy Pattern
- Dependency Injection
- Middleware
-
Registry
- SYMFONY
- Routes
- Annotations
- Flex
- Controllers
- Doctrine
- Templating
- VERSIONS
- Php7.4
- Php8.0
- SECURITY
- Filter Input
- Remote Code Injection
- Sql Injection
- Session Fixation
- File Uploads
- Cross Site Scripting
- Spoofed Forms
- CSRF
- Session Hijacking
- MODERN PHP
- Composer
- Autoloader
- Package
- Releases
- Generators
- Dependency Injection
- Middleware
- CUSTOM FRAMEWORK
- App
- Http Foundation
- Front Controller
- Routing
- Render Controller
- Resolver
- SoC
- FRAMEWORKS
- Slim
- Symfony V5
- Laravel V8
- Laminas V3
- Codeigniter V4
Registry Pattern
Allows any object to be used as Singleton, without it being written as Singleton.
class MyController extends MyBaseController
{
public function listAction()
{
$articles = $this->articleModel->getArticles();
// __get() called
}
}
class MyBaseController
{
private $register = array();
public function __get($var) // Magic method
{
if (strstr($var, 'Model')) {
$modelKey = substr($var, 0, -5);
if (in_array($modelKey, $this->register)) {
return $this->register[$modelKey]; // Look Here
} else {
eval('$model = new '. ucfirst($modelKey).'Model();');
$this->register[$modelKey] = $model;
return $model;
}
}
}
}
class ArticleModel
{
public function getArticles()
{
echo 'articles displayed';
}
}
$test = new MyController();
$test->listAction(); // articles displayed
Last update: 533 days ago