public function setColor($color) {

        // if null is passed in, then just leave everything null
        if (!is_null($color)) {

            // if it an instance of another color
            if ($color instanceof ColorInterface) {

                // save the name
                $this->name = $color->getName();

                // save the xterm code
                $this->XTermCode = $color->getXTermCode();

                // save the RGB
                $this->RGB = $color->getRGB();

                // save the ansi code
                $this->ANSICode = $color->getANSICode();

                // if it is string, then it is a color name (maybe)
            } else if (is_string($color)) {

                if (Colors::isValidColorName($color)) {

                    $this->name = Colors::stripName($color);

                    // get the code for that name
                    $this->XTermCode = Colors::getXTermCode($this->name);

                    // save the RGB
                    $this->RGB = Colors::getRGB($this->name);

                    // get the ANSI code
                    $this->ANSICode = Colors::getANSICode($this->name);

                }

                // if it is an integer, then it is likely a xterm code
            } else if (is_int($color)) {

                // if it is between 0 and 255
                if ($color >= 0 && $color <= 255) {

                    // save this code
                    $this->XTermCode = $color;

                    // get the RGB for it
                    $this->name = Colors::getColorIndexForXTermCode($this->XTermCode);

                    // get the RGB
                    $this->RGB = Colors::getRGB($this->name);

                    // get the ANSI Code
                    $this->ANSICode = Colors::getANSICode($this->name);
                }

                // if it is an RGB array
            } else if (is_array($color)) {

                // there must be three items in the array
                if (count($color) === 3) {

                    // save the RGB
                    $this->RGB = $color;

                    // match this RGB to some code
                    $this->name = Colors::matchRGB($this->RGB);

                    // get the nearest ANSI Code
                    $this->ANSICode = Colors::getANSICode($this->name);

                    // get the nearest XTerm code
                    $this->XTermCode = Colors::getXTermCode($this->name);

                }
            }

        // null was passed in
        } else {

            // set the color to be empty
            $this->setEmpty();
        }
    }
public function setColor($color) {

        // if null is passed in, then just leave everything null
        if (!is_null($color)) {

            // if it an instance of another color
            if ($color instanceof ColorInterface) {

                // save the name
                $this->name = $color->getName();

                // save the xterm code
                $this->XTermCode = $color->getXTermCode();

                // save the RGB
                $this->RGB = $color->getRGB();

                // save the ansi code
                $this->ANSICode = $color->getANSICode();

                // if it is string, then it is a color name (maybe)
            } else if (is_string($color)) {

                if (Colors::isValidColorName($color)) {

                    $this->name = Colors::stripName($color);

                    // get the code for that name
                    $this->XTermCode = Colors::getXTermCode($this->name);

                    // save the RGB
                    $this->RGB = Colors::getRGB($this->name);

                    // get the ANSI code
                    $this->ANSICode = Colors::getANSICode($this->name);

                }

                // if it is an integer, then it is likely a xterm code
            } else if (is_int($color)) {

                // if it is between 0 and 255
                if ($color >= 0 && $color <= 255) {

                    // save this code
                    $this->XTermCode = $color;

                    // get the RGB for it
                    $this->name = Colors::getColorIndexForXTermCode($this->XTermCode);

                    // get the RGB
                    $this->RGB = Colors::getRGB($this->name);

                    // get the ANSI Code
                    $this->ANSICode = Colors::getANSICode($this->name);
                }

                // if it is an RGB array
            } else if (is_array($color)) {

                // there must be three items in the array
                if (count($color) === 3) {

                    // save the RGB
                    $this->RGB = $color;

                    // match this RGB to some code
                    $this->name = Colors::matchRGB($this->RGB);

                    // get the nearest ANSI Code
                    $this->ANSICode = Colors::getANSICode($this->name);

                    // get the nearest XTerm code
                    $this->XTermCode = Colors::getXTermCode($this->name);

                }
            }

        // null was passed in
        } else {

            // set the color to be empty
            $this->setEmpty();
        }
    }
public function setColor ( $ color ) { // if null is passed in, then just leave everything null if ( ! is_null ( $ color ) ) { // if it an instance of another color if ( $ color instanceof ColorInterface ) { // save the name $ this -> name = $ color -> getName ( ) ; // save the xterm code $ this -> XTermCode = $ color -> getXTermCode ( ) ; // save the RGB $ this -> RGB = $ color -> getRGB ( ) ; // save the ansi code $ this -> ANSICode = $ color -> getANSICode ( ) ; // if it is string, then it is a color name (maybe) } else if ( is_string ( $ color ) ) { if ( Colors :: isValidColorName ( $ color ) ) { $ this -> name = Colors :: stripName ( $ color ) ; // get the code for that name $ this -> XTermCode = Colors :: getXTermCode ( $ this -> name ) ; // save the RGB $ this -> RGB = Colors :: getRGB ( $ this -> name ) ; // get the ANSI code $ this -> ANSICode = Colors :: getANSICode ( $ this -> name ) ; } // if it is an integer, then it is likely a xterm code } else if ( is_int ( $ color ) ) { // if it is between 0 and 255 if ( $ color >= 0 && $ color <= 255 ) { // save this code $ this -> XTermCode = $ color ; // get the RGB for it $ this -> name = Colors :: getColorIndexForXTermCode ( $ this -> XTermCode ) ; // get the RGB $ this -> RGB = Colors :: getRGB ( $ this -> name ) ; // get the ANSI Code $ this -> ANSICode = Colors :: getANSICode ( $ this -> name ) ; } // if it is an RGB array } else if ( is_array ( $ color ) ) { // there must be three items in the array if ( count ( $ color ) === 3 ) { // save the RGB $ this -> RGB = $ color ; // match this RGB to some code $ this -> name = Colors :: matchRGB ( $ this -> RGB ) ; // get the nearest ANSI Code $ this -> ANSICode = Colors :: getANSICode ( $ this -> name ) ; // get the nearest XTerm code $ this -> XTermCode = Colors :: getXTermCode ( $ this -> name ) ; } } // null was passed in } else { // set the color to be empty $ this -> setEmpty ( ) ; } }
The variety of ways to set a color
@param ColorInterface | string | integer | int[] $color - Many options for initializing a color object - SEE CONSTRUCTOR
The variety of ways to set a color