PHP code example of khalyomede / fetch

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

    

khalyomede / fetch example snippets


$fetch = new Fetch('config');

$command = $fetch->from('database.option.initial-command');

return [
  'name' => 'My app',
  'charset' => 'utf-8'
];

use Khalyomede\Fetch;

$fetch = new Fetch( __DIR__ . '/config' );

$charset = $fetch->from('app.charset');

print_r($charset);

return [
  'initial-command' => "SET names 'utf-8'"
];

use Khalyomede\Fetch;

$fetch = new Fetch( __DIR__ . '/config' );

$initial_command = $fetch->from('database.option.initial-command');

print_r($initial_command);

return [
  'cache' => [
    'strategy' => 'cache-first'
  ]
];

use Khalyomede\Fetch;

$fetch = new Fetch( __DIR__ . '/config' );

$strategy = $fetch->from('database.option.cache.strategy');

print_r($stategy);

return [
  'cache' => [
    'strategy' => 'cache-first'
  ],
  'timeout' => 12.5
];

use Khalyomede\Fetch;

$fetch = new Fetch( __DIR__ . '/config' );

$data = $fetch->from('database.option');

print_r($data);

Array
(
  [cache] => Array
    (
      [strategy] => cache-first
    )
  [timeout] => 12.5
)

use Khalyomede\Fetch;

$fetch = new Fetch( __DIR__ . '/config' );

$fetch->usingCache( __DIR__ . '/cache' );

$charset = $fetch->from('app.charset');

use Khalyomede\Fetch;

// ...

$fetch = new Fetch( base_path() . '/config' );

if( config('app.debug') !== true ) {
  $fetch->usingCache( base_path() . '/' )
}

$language = $fetch->from('app.locale');

use Khalyomede\Fetch;

$fetch = new Fetch( __DIR__ . '/config' );

$remove_dashes = function ($data) {
  return str_replace('-', '', $data);
};

$charset = $fetch->across($remove_dashes)->from('app.charset');

print_r($charset);

use Khalyomede\Fetch;

$fetch = new Fetch( __DIR__ . '/config' );

$now = (new DateTime())->format('Y-m-d');

$charset = $fetch->across(function($data) use($now) {
  return "$data ($now)";
})->from('app.charset');

print_r($charset);

use Khalyomede\Fetch;

$fetch = new Fetch( __DIR__ . '/config' );

$fetch->across(function($data) {
  return str_replace('-', '', $data);
});

$charset = $fetch->from('app.charset'); 

print_r($charset);

$fetch->uncross(); // or $fetch->uncross()->from('...');

$timeout = $fetch->from('database.option.timeout');

print_r($timeout);

$fetch->prototype('exists', function($path) {
  $exists = false;

  try {
    $this->from($path);

    $exists = true;
  }
  catch(Exception $e) {}

  return $exists;
});

if($fetch->exists('test')) {
  echo $fetch->from('test');
}
else {
  echo 'this configuration does not exists';
}

public function __construct(string $folder_path): Fetch

public function from(string $path): mixed

public function usingCache(string $cache_folder_path): Fetch

public function enableCache(): Fetch

public function disableCache(): Fetch

public function encrypt(string $string): string

public function decrypt(string $string): string

public function across(callable $function): Fetch

public function uncross(): Fetch

/config
  /database
    database.php
    option.php
  app.php

/config
  /database
    database.php
    option.php
  app.php
index.php

/config
  /database
    option.php
  app.php
/cache
index.php

utf-8 (2018-03-03)