/** * Set a cookie * * {@inheritdoc} * * A value may either be a string or a ResponseCookie instance * String values will be converted into a ResponseCookie with * the "name" of the cookie being set from the "key" * * Obviously, the developer is free to organize this collection * however they like, and can be more explicit by passing a more * suggested "$key" as the cookie's "domain" and passing in an * instance of a ResponseCookie as the "$value" * * @see DataCollection::set() * @param string $key The name of the cookie to set * @param ResponseCookie|string $value The value of the cookie to set * @return ResponseCookieDataCollection */ public function set($key, $value) { if (!$value instanceof ResponseCookie) { $value = new ResponseCookie($key, $value); } return parent::set($key, $value); }
/** * Set a route * * {@inheritdoc} * * A value may either be a callable or a Route instance * Callable values will be converted into a Route with * the "name" of the route being set from the "key" * * A developer may add a named route to the collection * by passing the name of the route as the "$key" and an * instance of a Route as the "$value" * * @see DataCollection::set() * @param string $key The name of the route to set * @param Route|callable $value The value of the route to set * @return RouteCollection */ public function set($key, $value) { if (!$value instanceof Route) { $value = new Route($value); } return parent::set($key, $value); }
public function testSet() { // Test data $data = array('dog' => 'cooper'); // Create our collection with NO data $data_collection = new DataCollection(); // Make sure its first empty $this->assertSame(array(), $data_collection->all()); // Set our data from our test data $return_val = $data_collection->set(key($data), current($data)); // Make sure the set worked $this->assertSame(current($data), $data_collection->get(key($data))); // Make sure it returned the instance during "set" $this->assertEquals($return_val, $data_collection); $this->assertSame($return_val, $data_collection); }
/** * Magic "__set" method * * Allows the ability to arbitrarily set a parameter from this instance * while treating it as an instance property * * NOTE: This currently sets the "named" parameters, since that's the * one collection that we have the most sane control over * * @param string $param The name of the parameter * @param mixed $value The value of the parameter * @return void */ public function __set($param, $value) { $this->params_named->set($param, $value); }