Browse Source

better comments style, missing @thorws

tags/2.0.0-beta
Alexander Makarov 13 years ago
parent
commit
9c7a06b122
  1. 22
      framework/base/Component.php
  2. 10
      framework/base/Object.php

22
framework/base/Component.php

@ -47,9 +47,11 @@ class Component extends \yii\base\Object
public function __get($name) public function __get($name)
{ {
$getter = 'get' . $name; $getter = 'get' . $name;
if (method_exists($this, $getter)) { // read property, e.g. getName() if (method_exists($this, $getter)) {
// read property, e.g. getName()
return $this->$getter(); return $this->$getter();
} else { // behavior property } else {
// behavior property
$this->ensureBehaviors(); $this->ensureBehaviors();
foreach ($this->_b as $behavior) { foreach ($this->_b as $behavior) {
if ($behavior->canGetProperty($name)) { if ($behavior->canGetProperty($name)) {
@ -91,7 +93,8 @@ class Component extends \yii\base\Object
// as behavior: attach behavior // as behavior: attach behavior
$name = trim(substr($name, 3)); $name = trim(substr($name, 3));
$this->attachBehavior($name, \Yii::createObject($value)); $this->attachBehavior($name, \Yii::createObject($value));
} else { // behavior property } else {
// behavior property
$this->ensureBehaviors(); $this->ensureBehaviors();
foreach ($this->_b as $behavior) { foreach ($this->_b as $behavior) {
if ($behavior->canSetProperty($name)) { if ($behavior->canSetProperty($name)) {
@ -122,9 +125,11 @@ class Component extends \yii\base\Object
public function __isset($name) public function __isset($name)
{ {
$getter = 'get' . $name; $getter = 'get' . $name;
if (method_exists($this, $getter)) { // property is not null if (method_exists($this, $getter)) {
// property is not null
return $this->$getter() !== null; return $this->$getter() !== null;
} else { // behavior property } else {
// behavior property
$this->ensureBehaviors(); $this->ensureBehaviors();
foreach ($this->_b as $behavior) { foreach ($this->_b as $behavior) {
if ($behavior->canGetProperty($name)) { if ($behavior->canGetProperty($name)) {
@ -150,10 +155,12 @@ class Component extends \yii\base\Object
public function __unset($name) public function __unset($name)
{ {
$setter = 'set' . $name; $setter = 'set' . $name;
if (method_exists($this, $setter)) { // write property if (method_exists($this, $setter)) {
// write property
$this->$setter(null); $this->$setter(null);
return; return;
} else { // behavior property } else {
// behavior property
$this->ensureBehaviors(); $this->ensureBehaviors();
foreach ($this->_b as $behavior) { foreach ($this->_b as $behavior) {
if ($behavior->canSetProperty($name)) { if ($behavior->canSetProperty($name)) {
@ -178,6 +185,7 @@ class Component extends \yii\base\Object
* will be implicitly called when an unknown method is being invoked. * will be implicitly called when an unknown method is being invoked.
* @param string $name the method name * @param string $name the method name
* @param array $params method parameters * @param array $params method parameters
* @throws Exception when calling unknown method
* @return mixed the method return value * @return mixed the method return value
*/ */
public function __call($name, $params) public function __call($name, $params)

10
framework/base/Object.php

@ -82,7 +82,8 @@ class Object
public function __isset($name) public function __isset($name)
{ {
$getter = 'get' . $name; $getter = 'get' . $name;
if (method_exists($this, $getter)) { // property is not null if (method_exists($this, $getter)) {
// property is not null
return $this->$getter() !== null; return $this->$getter() !== null;
} else { } else {
return false; return false;
@ -103,7 +104,8 @@ class Object
public function __unset($name) public function __unset($name)
{ {
$setter = 'set' . $name; $setter = 'set' . $name;
if (method_exists($this, $setter)) { // write property if (method_exists($this, $setter)) {
// write property
$this->$setter(null); $this->$setter(null);
} elseif (method_exists($this, 'get' . $name)) { } elseif (method_exists($this, 'get' . $name)) {
throw new Exception('Unsetting read-only property: ' . get_class($this) . '.' . $name); throw new Exception('Unsetting read-only property: ' . get_class($this) . '.' . $name);
@ -119,6 +121,7 @@ class Object
* will be implicitly called when an unknown method is being invoked. * will be implicitly called when an unknown method is being invoked.
* @param string $name the method name * @param string $name the method name
* @param array $params method parameters * @param array $params method parameters
* @throws Exception when calling unknown method
* @return mixed the method return value * @return mixed the method return value
*/ */
public function __call($name, $params) public function __call($name, $params)
@ -267,7 +270,8 @@ class Object
} elseif ($n === 4) { } elseif ($n === 4) {
$object = new $class($args[1], $args[2], $args[3]); $object = new $class($args[1], $args[2], $args[3]);
} else { } else {
array_shift($args); // remove $config // remove $config
array_shift($args);
$r = new \ReflectionClass($class); $r = new \ReflectionClass($class);
$object = $r->newInstanceArgs($args); $object = $r->newInstanceArgs($args);
} }

Loading…
Cancel
Save