Created
July 9, 2017 18:12
-
-
Save mustafat0k/f1e3067b92df4e2d7a52fcc771c73611 to your computer and use it in GitHub Desktop.
Laravel de Trait olarak view'lerde modül sistemi için kullanmayı düşündüğüm bir hook sınıfı
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Kancalama { | |
private $kanca; | |
public function fonksiyon_ekle($nereye, $fonksiyon, $oncelik = 1){ | |
if(!isset($this->kanca[$nereye])) | |
$this->kanca[$nereye] = array(); | |
$this->kanca[$nereye][$fonksiyon] = $oncelik; | |
} | |
public function fonksiyon_sil($nereye, $fonksiyon){ | |
if(isset($this->kanca[$nereye][$fonksiyon])){ | |
unset($this->kanca[$nereye][$fonksiyon]); | |
} | |
} | |
public function calistir($nereye, $args = array()){ | |
if(isset($this->kanca[$nereye])){ | |
$dizi = $this->kanca[$nereye]; | |
arsort($dizi); | |
foreach($dizi as $fonksiyon=>$oncelik) { | |
call_user_func_array($fonksiyon, $args); | |
} | |
} | |
} | |
} | |
$kanca = new Kancalama; | |
$kanca->fonksiyon_ekle("head_sonrasi", "css",10); | |
$kanca->fonksiyon_ekle("slider_sonrasi", "reklam",5); | |
// $kanca->fonksiyon_sil("slider_oncesi", "reklam"); | |
//fonksiyonlar | |
function fonkburaya(){ | |
echo '...'; | |
} | |
function reklam(){ | |
echo 'Burası Reklam Alanı!'; | |
} | |
//Örnek | |
// <?php $kanca->calistir('slider_oncesi'); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment