Re: Properly handling multiple constructors.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Richard Quadling wrote:
The following code (which cannot currently work as PHP does not allow
for method overloading) would be perfect for me.

<?php
class DataConnector {
	/**
	 * Rules
	 *
	 * What rules does this data connector use.
	 *
	 * @param Zend_Config
	 */
	private $Rules = Null;

	/**
	 * Constructor : Keyed
	 *
	 * This constructor will access the main registry to determine which
pre-saved rules to use.
	 *
	 * @param string $Key The registry key.
	 *
	 * @return DataConnector
	 */
	public function __construct($Key) {
	 // Use the key to retrieve the rules for this connector.
	 $this->__construct(registry::RetrieveViaKey(__CLASS__, $Key));
	}

	/**
	 * Constructor : Partial
	 *
	 * This constructor will construct the rules from the default
template and populate the 3 critical ones.
	 *
	 * @param string $Part1
	 * @param string $Part2
	 * @param string $Part3
	 *
	 * @return DataConnector
	 */
	public function __construct($Part1, $Part2, $Part3) {
	 // Use the Parts to construct the rules for this connector.
	 $Rules = registry::RetrieveDefault(__CLASS__);
	 $Rules->setPart1 = $Part1;
	 $Rules->setPart2 = $Part2;
	 $Rules->setPart3 = $Part3;
	 $this->__construct($Rules);
	}

	/**
	 * Constructor : Complete
	 *
	 * This constructor will take the supplied config and apply it to the rules.
	 *
	 * @param Zend_Config $Rules
	 *
	 * @return DataConnector
	 */
	public function __construct(Zend_Config $Rules) {
	 // Use the supplied rules
	 $this->Rules = $Rules;
	 $this->Init();
	}

	/**
	 * Post construction processing
	 */
	protected function Init() {
	}

	/**
	 * Store configuration in the registry.
	 *
	 * @param string $Key Allow for a new key to be used.
	 *
	 * @return DataConnector
	 */
	public function Store($Key = Null) {
		$this->Rules['Key'] = $Key ?: $this->Rules['Key'];
		registry::Store(__CLASS__, $this->Rules);
		return $this;
	}
}
?>

Are you asking a question? I'm not sure what you want here :) Does the technique I sent provide you with a solution to this problem or not?

:)

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux