承接 linq/php-linq 相关项目开发

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

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

linq/php-linq

Composer 安装命令:

composer require linq/php-linq

包简介

the fast and modern library for easy data manipulation

README 文档

README

Linq technology in php language.

Install

composer require linq/php-linq ~1.0

class Linq

Base class that performs queries over the collections of objects and over the array.

List of methods

  • from() - set primary source
  • first() - return first item from collection
  • last() - return last item from collection
  • select($key = null, $key2 = null) - return result. You can use callable as first param
  • count() - return length of collection
  • take($offset, $length = null) - return first x items || return interval
  • skip($offset) - skip x items a and return other data
  • where($condition) - returns only elements that match a given condition
  • reverse() - reverse collection
  • orderBy($column, $desc = false) - sort. desc = descending. defalt asc = ascending
  • distinct() - return unique items
  • takeWhile($requirement) - combination = where(condition) + select()
  • union($array) - union in sql
  • groupBy($key) - Group data
  • innerJoin($array) - return only elements that combine both fields
  • leftJoin($array) - the first collection will list all entries, even those which do not connect with other collections
  • on($condition) - Condition for join two collections
  • in($filter) - Accepts an array of values which elements must acquire
  • notIn($filter) - negation of "in" method
  • onlyKeys($keys) - filtering data by key
  • row_to_column($main_node) - split by a specific key. This key becomes a major hub

testing data

protected $students = array(
    array("name" => "Milan", "surname" => "Gallas", "age" => 20, "Job" => "php Programátor"),
    array("name" => "Amdrea", "surname" => "Novotná", "age" => 17, "Job" => "java Programátor"),
    array("name" => "Honza", "surname" => "Pulkert", "age" => 27, "Job" => "c# Programátor"),
    array("name" => "Nikola", "surname" => "Světnická", "age" => 23, "Job" => "php Programátor"),
    array("name" => "Nikola", "surname" => "Světnická", "age" => 23, "Job" => "php Programátor"),
    array("name" => "Petr", "surname" => "Grůdl", "age" => 31, "Job" => "java Programátor"),
);

protected $sports = array(
    array("userName" => "Milan", "sport" => "šachy", "active" => true),
    array("userName" => "Milan", "sport" => "karate", "active" => false),
    array("userName" => "Honza", "sport" => "box", "active" => true),
    array("userName" => "Honza", "sport" => "fotbal", "active" => false),
    array("userName" => "Milan", "sport" => "hokej", "active" => true),
    array("userName" => "Petr", "sport" => "tenis", "active" => true)
);

example of use

require 'vendor/autoload.php';

//init base linq class
$linq = \Linq\LinqFactory::createLinq();

//filtering data - select only users who are older than 23
$linq
	->from($userData)
	->where(function($item){
		if($item["age"] > 23) return $item;
	})

//clasic select
var_dump($linq->select());
//select data with function
var_dump(
		$linq->select(function($person){
			$person["age"]*=2;
			return $person;
		})
	);
//or
var_dump(
		$linq->select(function($user){
			//return $user["name"]  //you can try = return string
			return array("userName" => $user["name"]); //return array
		})
	);

//short select = less typing :D
var_dump( $linq->select("age") );  echo '<br>';
var_dump( $linq->select("name", "age") ); echo '<br>';
//$linq->select("name", "age") =>
var_dump(
	$linq->select(function($user){
		return array($user["name"] => $user["age"]);
	})
);



//full use with join method and groupBy
$linq
	->from($userData)
	//->innerJoin($sportData)
	->leftJoin($sportData)
	->on(function($user, $sport){
		return ($user["name"] == $sport["userName"]);
	})
	->groupBy("Job")
	->select()

class JsonLinq

The class takes data source in JSON format. Returns array.

testing data

$userJsonData = json_encode($userData);
$sportJsonData = json_encode($sportData);

example of use

$linq = \Linq\LinqFactory::createJsonLinq();

	echo '<pre>'; var_dump(
		$linq
			->from($userJsonData)
			->takeWhile(function($user){
				return ($user["Job"] === "php Programátor" && $user["age"] > 20);
			})
	);

class XmlLinq

The class takes data source in JSON format. Returns array.

The "from" method accept string or SimpleXmlElement. If out choose xml in string, so you will work with array. If you choose xml in SimlpeXmlElement object, so you will work with collection of std objects.

testing data

$sportXml =
'<sports>
     <sport>
         <userName>Milan</userName>
         <sport>šachy</sport>
         <active>true</active>
     </sport>
     <sport>
         <userName>Milan</userName>
         <sport>karate</sport>
         <active>false</active>
     </sport>
         <sport>
         <userName>Milan</userName>
         <sport>hokej</sport>
         <active>true</active>
         </sport>
     <sport>
         <userName>Honza</userName>
         <sport>box</sport>
         <active>true</active>
     </sport>
     <sport>
         <userName>Honza</userName>
         <sport>fotbal</sport>
         <active>false</active>
     </sport>
     <sport>
         <userName>Petr</userName>
         <sport>tenis</sport>
         <active>true</active>
     </sport>
</sports>';

//users
$userXml = '
<students>
     <student>
         <name>Milan</name>
         <surname>Gallas</surname>
         <age>20</age>
         <Job>php Programátor</Job>
     </student>
     <student>
         <name>Amdrea</name>
         <surname>Novotná</surname>
         <age>17</age>
         <Job>Java Programátor</Job>
     </student>
     <student>
         <name>Honza</name>
         <surname>Pulkert</surname>
         <age>27</age>
         <Job>c# Programátor</Job>
     </student>
     <student>
         <name>Nikola</name>
         <surname>Světnická</surname>
         <age>23</age>
         <Job>php Programátor</Job>
     </student>
     <student>
         <name>Nikola</name>
         <surname>Světnická</surname>
         <age>23</age>
         <Job>php Programátor</Job>
     </student>
     <student>
         <name>Petr</name>
         <surname>Grůdl</surname>
         <age>31</age>
         <Job>Java Programátor</Job>
     </student>
</students>
	';

example of use

    //first example. Source is string
	echo '<pre>';
	var_dump(
		\Linq\LinqFactory::createXmlLinq()
			->from($userXml)
			->leftJoin($sportXml)
			->on(function($user, $sport){
				return ($user["name"] == $sport["userName"]);
			})
			->select()
	);


	//second example group by and reverse - source is string
	echo "<pre>";
	var_dump(
		\Linq\LinqFactory::createXmlLinq()->from($userXml)->groupBy("Job", "name")->reverse()->select();
	);
	echo "</pre>";



	//third examlple - source is simpleXmlElement. use condition on collection of objects and sort by orderBy function descending
	$xmlElemetn = new SimpleXMLElement($userXml);
	echo '<pre>';
	var_dump(
		\Linq\LinqFactory::createXmlLinq()
			->from($xmlElemetn)
			->where(function($user){
				return (strlen($user->name) > 5);
			})
			->orderBy("age", true)
			->select()
	);

统计信息

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

GitHub 信息

  • Stars: 7
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2016-10-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固