diff --git a/src/Base/BaseObject.php b/src/Base/BaseObject.php new file mode 100644 index 00000000..5b9f50e6 --- /dev/null +++ b/src/Base/BaseObject.php @@ -0,0 +1,85 @@ + + */ +class BaseObject +{ + use \Jyotish\Base\Traits\GetTrait; + use \Jyotish\Base\Traits\OptionTrait; + + /** + * Type of object. + * + * @var string + */ + protected $objectType = null; + + /** + * Abbreviation of the object. + * + * @var string|int + */ + protected $objectKey = null; + + /** + * Main name of the object. + * + * @var string + */ + protected $objectName = null; + + /** + * Alternative names of the object. + * + * @var array + */ + protected $objectNames = []; + + /** + * Constructor + * + * @param null|array $options Options to set + */ + public function __construct($options) + { + $this->setOptions($options); + + $this->setObjectName(); + $this->setObjectNames(); + } + + /** + * Set main name of the object. + * + * @return void + */ + protected function setObjectName() + { + $objectType = $this->objectType; + $objectName = ucfirst($objectType); + $className = 'Jyotish\\' . $objectName . '\\' . $objectName; + + $list = $className::$$objectType; + + $this->objectName = $list[$this->objectKey]; + } + + /** + * Set names of the object. + * + * @return void + */ + protected function setObjectNames() + { + $this->objectNames = array_merge([$this->objectName], $this->objectNames); + } +} diff --git a/src/Base/Traits/EnvironmentTrait.php b/src/Base/Traits/EnvironmentTrait.php index f2093e9d..66a42723 100644 --- a/src/Base/Traits/EnvironmentTrait.php +++ b/src/Base/Traits/EnvironmentTrait.php @@ -35,7 +35,7 @@ trait EnvironmentTrait * Set environment. * * @param \Jyotish\Base\Data $Data - * @return \Jyotish\Base\Object + * @return \Jyotish\Base\BaseObject */ public function setEnvironment(\Jyotish\Base\Data $Data) { diff --git a/src/Bhava/Object/BhavaObject.php b/src/Bhava/Object/BhavaObject.php index 6808dc4a..401fb2a7 100644 --- a/src/Bhava/Object/BhavaObject.php +++ b/src/Bhava/Object/BhavaObject.php @@ -6,14 +6,14 @@ namespace Jyotish\Bhava\Object; -use Jyotish\Base\Object; +use Jyotish\Base\BaseObject; /** * Parent class for bhava objects. * * @author Kunjara Lila das */ -class BhavaObject extends Object { +class BhavaObject extends BaseObject { use BhavaEnvironment; diff --git a/src/Graha/Object/GrahaObject.php b/src/Graha/Object/GrahaObject.php index 74d22097..e3bd5866 100644 --- a/src/Graha/Object/GrahaObject.php +++ b/src/Graha/Object/GrahaObject.php @@ -7,7 +7,7 @@ namespace Jyotish\Graha\Object; use Jyotish\Base\Biblio; -use Jyotish\Base\Object; +use Jyotish\Base\BaseObject; use Jyotish\Graha\Graha; use Jyotish\Rashi\Rashi; use Jyotish\Ganita\Math; @@ -18,7 +18,7 @@ * * @author Kunjara Lila das */ -class GrahaObject extends Object +class GrahaObject extends BaseObject { use GrahaEnvironment; diff --git a/src/Rashi/Object/RashiObject.php b/src/Rashi/Object/RashiObject.php index 0ad80c89..0cb0268b 100644 --- a/src/Rashi/Object/RashiObject.php +++ b/src/Rashi/Object/RashiObject.php @@ -16,7 +16,7 @@ * * @author Kunjara Lila das */ -class RashiObject extends \Jyotish\Base\Object +class RashiObject extends \Jyotish\Base\BaseObject { use RashiEnvironment;