2017 © Pedro PelĂĄez
 

library cakephp-hash

XPath-like path syntax for complex arrays using awesome cakePHP’s Hash class

image

zzal/cakephp-hash

XPath-like path syntax for complex arrays using awesome cakePHP’s Hash class

  • Wednesday, May 22, 2013
  • by zzal
  • Repository
  • 1 Watchers
  • 5 Stars
  • 2,555 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

cakephp-hash

Please note that this package is in beta develpment phase., (*1)

This is simply a wrapper package to help you use the awesome cakePHP’s Hash class in your non-cakePHP project (using composer). This helper class let you manipulate complex PHP arrays using Xpath-like syntax., (*2)

See cakePHP documentation., (*3)

Installation

Install this package through Composer. To do so, edit your project's composer.json file to require zzal/cakephp-hash., (*4)

"require": {
    "zzal/cakephp-hash": "*"
}

Then, add this inside the "autoload" section of this file:, (*5)

"autoload": {
    "classmap": [
        

    ],
    "psr-0": {
        "CakePHP\\Utility\\": "vendor/zzal/cakephp-hash/Hash"
    }

Finally, use Composer from the Terminal:, (*6)

composer install

Basic Usage

As Laravel 4 already have a class named Hash, I suggest that you use the cakePHP Hash class with an alias, like in the following example (routes.php):, (*7)

<?php

use CakePHP\Utility\Hash as ArrayXPath;

Route::get('/', function()
{
    $records = array(
        array(
            'pages' => array(
                array('id' => 1, 'title' => 'One'),
                array('id' => 2, 'title' => 'Two'),
                array('id' => 3, 'title' => 'Three'),
            )
        )
    );

    $result = ArrayXPath::extract($records, '{n}.pages.{n}[id=2]');

    var_dump($result);
});

And the result would be:, (*8)

array(1) {
  [0]=>
  array(2) {
    ["id"]=>
    int(2)
    ["title"]=>
    string(3) "Two"
  }
}

The Versions

22/05 2013

dev-master

9999999-dev https://github.com/zzal/cakephp-hash/

XPath-like path syntax for complex arrays using awesome cakePHP’s Hash class

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Alain Duchesneau

laravel 4 array xpath