PHP code example of burobo / ukon

1. Go to this page and download the library: Download burobo/ukon library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

burobo / ukon example snippets


   use Ukon\Unit;

   class Metre extends Unit
   {
       /**
        * @inheritDoc
        */
       protected function languageSpecificFormats(): array
       {
           return [
               'default' => '%s metre',
           ];
       }

       /**
        * @inheritDoc
        */
       protected function globalFormats(): array
       {
           return [
               'abbr' => '%sm',
           ];
       }

       /**
        * @inheritDoc
        */
       protected function domain(): string
       {
           return 'messages';
       }
   }

   

   use Ukon\Type;

   class Length extends Type
   {
       /**
        * @inheritDoc
        */
       public function __construct(int $scale)
       {
           parent::__construct($scale);
           $this->registerUnitRatio(Metre::class, 1000);
           $this->registerUnitRatio(Centimetre::class, 10);
           $this->registerUnitRatio(Millimetre::class, 1);
       }
   }

   


   $height = (new Length(1))
       ->addMetre(1.7)
       ->addMillimetre(1);

   $height->stringify(function (Metre $metre, Centimetre $centimetre, Millimetre $millimetre) {
       return $metre->fmtAbbr() . ' ' . $centimetre->fmtAbbr() . ' ' . $millimetre->fmtAbbr();
   }); // 1m 70cm 1mm