JsonTrait.php in Automatic Updates 8.2        
                          
                  
                        
  
  
  
  
  
File
  tests/src/Traits/JsonTrait.php
  
    View source  
  <?php
namespace Drupal\Tests\automatic_updates\Traits;
use Drupal\Component\Serialization\Json;
use PHPUnit\Framework\Assert;
trait JsonTrait {
  
  protected function readJson(string $path) : array {
    Assert::assertIsReadable($path);
    $data = file_get_contents($path);
    return Json::decode($data);
  }
  
  protected function writeJson(string $path, array $data) : void {
    Assert::assertIsWritable(file_exists($path) ? $path : dirname($path));
    file_put_contents($path, Json::encode($data));
  }
}
 
Traits
        
  
  
      
      
         
      
                  
            Name            | 
                  
            Description           | 
              
    
    
          
                  | 
            JsonTrait           | 
                  
            Provides assertive methods to read and write JSON data in files.           |