• 15-08-2014, 19:10:48
    #1
    İyi akşamlar arkadaşlar,
    PHP de aşağıdaki örnekteki gibi bir kullanımı nasıl sağlayabilirim acaba ?
    (new isyeri(new isci( $isciID )))->mesaiEkle([tarih'=> '201-08-15', 'saat'=>2]);
  • 16-08-2014, 09:02:05
    #2
    $isci = new Isci( $isyeriID, $isciID );
    $isci->mesaiEkle([tarih'=> '201-08-15', 'saat'=>2]);

    bu tarz kod işini görmez mi?
  • 16-08-2014, 12:16:02
    #4
    Kimlik doğrulama veya yönetimden onay bekliyor.
    uysal_rockci adlı üyeden alıntı: mesajı görüntüle
    İyi akşamlar arkadaşlar,
    PHP de aşağıdaki örnekteki gibi bir kullanımı nasıl sağlayabilirim acaba ?
    (new isyeri(new isci( $isciID )))->mesaiEkle([tarih'=> '201-08-15', 'saat'=>2]);
    bu programda kaç tane iş yeri var ki?
  • 16-08-2014, 13:31:08
    #5
    uysal_rockci adlı üyeden alıntı: mesajı görüntüle
    İyi akşamlar arkadaşlar,
    PHP de aşağıdaki örnekteki gibi bir kullanımı nasıl sağlayabilirim acaba ?
    (new isyeri(new isci( $isciID )))->mesaiEkle([tarih'=> '201-08-15', 'saat'=>2]);
    senin dediğin durumda mesai işyerine ekleniyor. ama mantıken işçiye eklenmesi gerekir. yanlış anladıysam düzeltin


    $isci = new isci($isciID);
    $isYeri = new isyeri($isci->isYeriID, $isciID);
    $isYeri->mesaiEkle([tarih'=> '201-08-15', 'saat'=>2]);
    bu şekilde işini görürmü ?
  • 16-08-2014, 14:40:17
    #6
    tüm yorum yapan arkadaşlara teşekkürler. buradaki amacın iç içe kullanmayı başarabilmekti.
    Yukarıda sehzadem 'in örneğindeki gibi bir kullanımda da sınıflar ve fonksiyonlar normal bir şekilde çalışmaktadır.

    saintx 'in gönderdeği kod bloğu ve diğer örnek ile istediğimi yapmayı başardım. ihtiyacı olan arayan varsa yardımcı olması dileğiyle.
    herkese çok teşekkürler.


    saintx :
    <?php 
    
        function with($class) 
        { 
            return $class; 
        } 
    
        class Company 
        { 
            private $_employees; 
    
            public function __construct($employee = null) 
            { 
                if ($employee instanceof Employee) 
                { 
                    $this->setEmployee($employee); 
                } 
            } 
    
            public function getEmployee($id) 
            { 
                return $this->_employees[$id]; 
            } 
    
            public function getEmployees() 
            { 
                return $this->_employees; 
            } 
    
            public function setEmployee(Employee $employee) 
            { 
                if ( ! is_array($this->_employees)) 
                { 
                    $this->_employees = []; 
                } 
    
                $this->_employees[$employee->getId()] = $employee; 
    
                return $employee; 
            } 
        } 
    
        class Employee 
        { 
            private $_id; 
            private $_name; 
            private $_surname; 
    
            public function __construct($id) 
            { 
                return $this->setId($id); 
            } 
    
            public function getId() 
            { 
                return $this->_id; 
            } 
    
            public function setId($id) 
            { 
                $this->_id = $id; 
    
                return $this; 
            } 
    
            public function getName() 
            { 
                return $this->_name; 
            } 
    
            public function setName($name) 
            { 
                $this->_name = $name; 
    
                return $this; 
            } 
    
            public function getSurname() 
            { 
                return $this->_surname; 
            } 
    
            public function setSurname($surname) 
            { 
                $this->_surname = $surname; 
    
                return $this; 
            } 
        } 
    
        $company = new Company(); 
    
        $company->setEmployee(new Employee(1))->setName('Metin'); 
        $company->setEmployee(new Employee(2))->setName('Ali'); 
        $company->setEmployee(new Employee(3))->setName('Feyyaz'); 
    
        print_r($company->getEmployee(2)->getName()); // Ali





    http://www.ozzu.com/programming-forum/php-create-new-class-instance-inside-another-class-t99319.html
    <?php
     
    /*
        Utility class #1
    */
    class hammer
    {
        public function bang(){
            echo 'Bang! ';
            return;
        }
        public function pry(){
            echo 'Pry! ';
            return;
        }
    }
     
    /*
        Utility class #2
    */
    class screwdriver
    {
        public function loosen(){
            echo 'Loosen! ';
            return;
        }
        public function tighten(){
            echo 'Tighten! ';
            return;
        }
    }
     
    /*
        Implementer of utility classes
    */
    class handyman
    {
        /*
            A place to keep our utilities
        */
        public $toolbelt = array();
     
        public function __construct($tools = array())
        {
            foreach($tools as $tool)
            {
                /*
                    http://www.php.net/get_class
                    Make sure we only have one of any given tool, does not _have_ to be this way
                */
                $this->toolbelt[get_class($tool)] = $tool;
            }
            return $this;
        }
     
        /*
            http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods
        */
        public function __call($method_name, $args)
        {
            foreach($this->toolbelt as $tool)
            {
                /*
                    http://www.php.net/is_callable
                    See if the utility object has a callable method matching the one asked for
                */
                if(is_callable(array($tool, $method_name)))
                {
                    /*
                        http://www.php.net/call_user_func_array
                        Forward the method call to the utility object along with the arguments
                    */
                    return call_user_func_array(array($tool, $method_name), $args);
                }
            }
            /*
                http://www.php.net/trigger_error
            */
            trigger_error("Do not have a tool that can $method_name!", E_USER_ERROR);
        }
    }
     
    $me = new handyman(array(new hammer(), new screwdriver()));
     
    $me->bang();
    $me->pry();
    $me->tighten();
    $me->loosen();
    $me->gitrdone();
     
    ?>
  • 16-08-2014, 17:53:25
    #7
    ylv
    Üyeliği durduruldu
    (new isyeri(new isci( $isciID )))->mesaiEkle([tarih'=> '201-08-15', 'saat'=>2]);

    bu tür kullanımlar bana kontrolsüz geliyor, dikkat etmenizde fayda var..

    classı biraz değiştirdim, bu tür kullanımda yapabilirsiniz..

    /*
        Utility class #1
    */
    class hammer
    {
        public function bang(){
            echo 'Bang! ';
            return;
        }
        public function pry(){
            echo 'Pry! ';
            return;
        }
    }
      
    /*
        Utility class #2
    */
    class screwdriver
    {
        public function loosen(){
            echo 'Loosen! ';
            return;
        }
        public function tighten(){
            echo 'Tighten! ';
            return;
        }
    }
      
    
    class handyman
    {
        public function __construct()
        {
            foreach(func_get_args() as $v)
            {
                is_object($v) && $this->{get_class($v)} = $v;
            }
            return $this;
        }
    	
    	public function __set($k,$v) {
    	
    		if (!property_exists($this,$k)) {
    			$this->{$k} = $v;
    		}
    		
    	}
    	
    	public function __get($k) {
    		if (property_exists($this,$k)) {
    			return $k;
    		}
    		throw new Exception(null);
    	}
      
    }
      
    $me = new handyman(new hammer(), new screwdriver(),....);
    
    $me->screwdriver->loosen();
    $me->hammer->bang();
    $me->baska; // hata

    uysal_rockci adlı üyeden alıntı: mesajı görüntüle
    tüm yorum yapan arkadaşlara teşekkürler. buradaki amacın iç içe kullanmayı başarabilmekti.
    Yukarıda sehzadem 'in örneğindeki gibi bir kullanımda da sınıflar ve fonksiyonlar normal bir şekilde çalışmaktadır.

    saintx 'in gönderdeği kod bloğu ve diğer örnek ile istediğimi yapmayı başardım. ihtiyacı olan arayan varsa yardımcı olması dileğiyle.
    herkese çok teşekkürler.


    saintx :
    <?php 
    
        function with($class) 
        { 
            return $class; 
        } 
    
        class Company 
        { 
            private $_employees; 
    
            public function __construct($employee = null) 
            { 
                if ($employee instanceof Employee) 
                { 
                    $this->setEmployee($employee); 
                } 
            } 
    
            public function getEmployee($id) 
            { 
                return $this->_employees[$id]; 
            } 
    
            public function getEmployees() 
            { 
                return $this->_employees; 
            } 
    
            public function setEmployee(Employee $employee) 
            { 
                if ( ! is_array($this->_employees)) 
                { 
                    $this->_employees = []; 
                } 
    
                $this->_employees[$employee->getId()] = $employee; 
    
                return $employee; 
            } 
        } 
    
        class Employee 
        { 
            private $_id; 
            private $_name; 
            private $_surname; 
    
            public function __construct($id) 
            { 
                return $this->setId($id); 
            } 
    
            public function getId() 
            { 
                return $this->_id; 
            } 
    
            public function setId($id) 
            { 
                $this->_id = $id; 
    
                return $this; 
            } 
    
            public function getName() 
            { 
                return $this->_name; 
            } 
    
            public function setName($name) 
            { 
                $this->_name = $name; 
    
                return $this; 
            } 
    
            public function getSurname() 
            { 
                return $this->_surname; 
            } 
    
            public function setSurname($surname) 
            { 
                $this->_surname = $surname; 
    
                return $this; 
            } 
        } 
    
        $company = new Company(); 
    
        $company->setEmployee(new Employee(1))->setName('Metin'); 
        $company->setEmployee(new Employee(2))->setName('Ali'); 
        $company->setEmployee(new Employee(3))->setName('Feyyaz'); 
    
        print_r($company->getEmployee(2)->getName()); // Ali





    http://www.ozzu.com/programming-forum/php-create-new-class-instance-inside-another-class-t99319.html
    <?php
     
    /*
        Utility class #1
    */
    class hammer
    {
        public function bang(){
            echo 'Bang! ';
            return;
        }
        public function pry(){
            echo 'Pry! ';
            return;
        }
    }
     
    /*
        Utility class #2
    */
    class screwdriver
    {
        public function loosen(){
            echo 'Loosen! ';
            return;
        }
        public function tighten(){
            echo 'Tighten! ';
            return;
        }
    }
     
    /*
        Implementer of utility classes
    */
    class handyman
    {
        /*
            A place to keep our utilities
        */
        public $toolbelt = array();
     
        public function __construct($tools = array())
        {
            foreach($tools as $tool)
            {
                /*
                    http://www.php.net/get_class
                    Make sure we only have one of any given tool, does not _have_ to be this way
                */
                $this->toolbelt[get_class($tool)] = $tool;
            }
            return $this;
        }
     
        /*
            http://www.php.net/manual/en/language.oop5.overloading.php#language.oop5.overloading.methods
        */
        public function __call($method_name, $args)
        {
            foreach($this->toolbelt as $tool)
            {
                /*
                    http://www.php.net/is_callable
                    See if the utility object has a callable method matching the one asked for
                */
                if(is_callable(array($tool, $method_name)))
                {
                    /*
                        http://www.php.net/call_user_func_array
                        Forward the method call to the utility object along with the arguments
                    */
                    return call_user_func_array(array($tool, $method_name), $args);
                }
            }
            /*
                http://www.php.net/trigger_error
            */
            trigger_error("Do not have a tool that can $method_name!", E_USER_ERROR);
        }
    }
     
    $me = new handyman(array(new hammer(), new screwdriver()));
     
    $me->bang();
    $me->pry();
    $me->tighten();
    $me->loosen();
    $me->gitrdone();
     
    ?>