承接 kanoulis/nodes 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kanoulis/nodes

Composer 安装命令:

composer require kanoulis/nodes

包简介

Closure Table Hierarchy data model implementation for PHP Data Objects

README 文档

README

Implementation of closure table for hierarchy data model operations in RDBMS

Features

  • Creates paths when you insert a new node
  • Updates paths when you move a node
  • Updates paths when you rename a node
  • Can search for nodes by node id or node path
  • Can get node tree by node path

Install

To install with composer:

composer require kanoulis/nodes

Usage

Basic usage example:

You need to have permissions to create the sqlite database file.

<?php
    require '/path/to/vendor/autoload.php';

    try {
        /* Open SQLite database */
        
        $pdo = new \PDO('sqlite:nodes.db');
        $pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        $pdo->exec('PRAGMA foreign_keys = ON');
        
        
        /* Create node tables if they do not exist */
        
        $pdo->exec('create table if not exists nodes(
            id integer primary key, 
            parent_id integer, 
            name text unique,
            foreign key (parent_id) references nodes (id) on update cascade on delete cascade
        )');
        
        $pdo->exec('create table if not exists nodes_closure(
            ancestor integer not null, 
            descendant integer not null, 
            depth integer not null, 
            path text not null,
            foreign key (ancestor) references nodes (id) on update cascade on delete cascade,
            foreign key (descendant) references nodes (id) on update cascade on delete cascade
        )');
        
        
        /* Select SQLite repository and initialize operations */
        
        $repo 	= new Nodes\NodeRepository\NodeRepositorySQLite($pdo);
        $nodes 	= new Nodes\Nodes($repo);
        
        
        /* Create some nodes */
        
        $space 		= $nodes->create((new Nodes\Node()));
        $earth 		= $nodes->create((new Nodes\Node())->setParent($space->_id)->setName('earth'));
        $continents 	= $nodes->create((new Nodes\Node())->setParent($earth->_id)->setName('continents'));
        $europe 	= $nodes->create((new Nodes\Node())->setParent($continents->_id)->setName('europe'));
        $asia	 	= $nodes->create((new Nodes\Node())->setParent($continents->_id)->setName('asia'));
        $oceans 	= $nodes->create((new Nodes\Node())->setParent($earth->_id)->setName('oceans'));
        $pacific 	= $nodes->create((new Nodes\Node())->setParent($oceans->_id)->setName('pacific'));
        $atlantic 	= $nodes->create((new Nodes\Node())->setParent($oceans->_id)->setName('atlantik'));
        $africa 	= $nodes->create((new Nodes\Node())->setParent($oceans->_id)->setName('africa'));
        
        /* Try some operations */
        print '<pre>';
        
        print "Show info about the African continent\n";
        print_r($africa);
        
        print "Africa is not an ocean, lets move it under continents!\n";
        $africa->setParent($continents->_id);
        print_r($nodes->update($africa));
        
        print "Show info about the Atlantic ocean\n";
        print_r($atlantic);
        
        print "Atlantic is spelled wrong, lets rename it!\n";
        $atlantic->setName('atlantic');
        print_r($nodes->update($atlantic));
        
        print "Breadcrumps to Asia!\n";
        print_r($nodes->parents($asia->_id));
        
        print "What can we find on earth?\n";
        print_r($nodes->siblings($earth->_id));
        
        print "Show everything on earth\n";
        print_r($nodes->tree($earth->_path));
        
        print "What is above earth?\n";
        print_r($nodes->parent($earth->_id));
        
        print "Get information by path\n";
        print_r($nodes->read('/earth/continents/'));
        
        print "Get information by id\n";
        print_r($nodes->read(false, 9));
        
        print "Get all continents by path\n";
        print_r($nodes->tree('/earth/continents/'));
        
        /* Destroy all */
        
        $nodes->delete($space->_id);
    }
    catch (\Exception $e) {

        echo $e->getMessage();
    }        

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-07-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固