CropFactory.php 1.32 KB
<?php

namespace backend\components\croppers;

use Yii;

class CropFactory
{
    private static $instance;
    private $crops = [];

    private function __construct() {
        $this->init();
    }

    private function init() {
        $this->crops[] = new EconomixCrop();
        $this->crops[] = new GoldenGardenFlowersCrop();
        $this->crops[] = new GoldenGardenVegiesCrop();
        $this->crops[] = new GoldenGardenGiantCrop();
        $this->crops[] = new UkrSeedsNovikGiantCrop();
        $this->crops[] = new UkrSeedsNovikMiniCrop();
        $this->crops[] = new UkrSeedsNovikVegiesCrop();
        $this->crops[] = new UkrSeedsNovikFlowersCrop();
        $this->crops[] = new UkrSeedsTekVegiesCrop();
        $this->crops[] = new UkrSeedsFloraMiniCrop();
        $this->crops[] = new UkrSeedsFloraVegiesCrop();
    }

    public function getCrop($crop_id) {
        return $this->crops[$crop_id];
    }

    public function findMinHeight() {
        $min = PHP_INT_MAX;
        foreach ($this->crops as $crop) {
            $height = $crop->getConstants()['HEIGHT'];
            $min = $min > $height ? $height : $min;
        }
        return $min;
    }



    public static function getInstance() {
        if (null === self::$instance) {
            self::$instance = new self();
        }
        return self::$instance;
    }
}