代码之家  ›  专栏  ›  技术社区  ›  ryeguy

公共领域如何才能打破第二条规则中的“懒加载”?

  •  10
  • ryeguy  · 技术社区  · 14 年前

    doctrine orm:validate-schema ,它会弹出一堆关于我的映射列是公共的并且不使用getter/setter方法包装它们的警告。上面说他们“打破了偷懒加载”。我能理解 关联集合 public可能有问题(我确实将这些设置为私有并包装它们),但是对于对象上的字段来说,这是怎么一个问题呢?据我所知,这些字段已全部加载。

    2 回复  |  直到 14 年前
        1
  •  14
  •   Tim Lytle    14 年前

    尽管我肯定不是医生,但我还是要试一试。

    不加载该对象的数据

    条令是在请求持久化数据时的延迟加载,而不是在请求包含持久化数据的对象时。

    更新: 我看了一下 actual proxy code 看来我最初的理解基本上是正确的。在调用对象的方法之前,代理对象不会加载自身。因此,对公共属性的任何请求都不会加载数据。

        2
  •  9
  •   PowerKiKi webjawns.com    7 年前

    注意,原则2.4现在 supports proxy objects for entites with public properties .

    Marco Pivetta how it works :

    class Customer {
        public $name;
        public $surname;
    }
    
    class CustomerProxy extends Customer {
        public function __construct(Customer $customer) {
            unset($this->name, $this->surname);
            $this->customer = $customer;
        }
        public function __set($name, $value) {
            $this->customer->$name = $value;
        }
    
        public function __get($name) {
            return $this->customer->$name;
        }
        // __isset, __unset, __clone, __sleep, __wakeup (or serialize/unserialize)
    }