PHP code example of alternatex / widespread

1. Go to this page and download the library: Download alternatex/widespread 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/ */

    

alternatex / widespread example snippets



// ...
Widespread\Widespread as Widespread;


 

// ...
$data = Widespread::FetchMetadata(

  // path to entity
  'test/examples/members/', 

  // properties to extract
  array('UUID', 'Name', 'Repository', 'Version', 'Sort', 'Status'),

  // sort by field
  'Sort', 

  // sort ascending
  false,

  // filters to apply
  array(

    // published only
    'Status' => array(
      array('NOT', 'Published')
    ),

    // restrict by name
    'Name' => array(
      array('IN', array('Include_1', 'Include_2')),
      array('EX', array('Exclude_1'))
    ),  

    // restrict by age
    'Sort'  => array(
      array('LT', 1000), 
      array('GT', 200)
    )
  )
);


 

// ...
foreach(array('buckets', 'options', 'widgets') as $context) $$context = array(); // $buckets = $options = $widgets = array();

// fetch partials
Widespread::FetchPartials(
  $buckets, 
  $options, 
  $widgets, 
  'index.html', 
  '{{>/templates/body}}'
);

// create mustache rendering engine helper
$m = new \Mustache_Engine(array('partials' => $buckets));

// process
print $m->render($buckets['index.html'], $data);

 

// ...
$data = array(
  '...',
  '...',
  '...'
);

// default access
$segment_a = &Widespread::AccessSegment($data, 'path.to.prop.where.ever');

// custom delimiter
$segment_b = &Widespread::AccessSegment($data, 'path/to/prop/where/ever', null, null, null, '/');

// ...
$segment_a = 'test';

// ...
echo $data['path']->to['prop']['where']->ever;

// ...
$segment_b = 'test2';

// ...
echo $data['path']->to['prop']['where']->ever;