Giter VIP home page Giter VIP logo

php5-helpers's Introduction

PHP5-Helpers - классы хелперы, которые часто бывают полезны в разработке

composer require darkfriend/php5-helpers

Структура:

  • CurlHelper - очень упрощает работу с CURL
  • DebugHelper - удобный дебаггинг и трассировка данных
  • ArrayHelper - полезные методы при работе с массивами
  • StringHelper - полезные методы при работе со строками
  • TypeHelper - полезные методы для строгой тепизации
  • Xml - полезные методы для работы с XML
  • Json - полезные методы для работы с JSON
  • Request - полезные методы для работы с request
  • Response - полезные методы для работы с response
  • DateTimeHelper - полезные хелперы для работы с датой
  • FileHelper - полезные хелперы для работы с файлами

Json - полезные методы для работы с JSON

$json = [
    'param1' => 'value1',
    'param2' => 'value2',
    'param3' => 'value3',
];
\darkfriend\helpers\Json::encode($json); // string

$jsonString = '{"param1":"value1","param2":"value2","param3":"value3"}';
\darkfriend\helpers\Json::decode($jsonString); // array

Request - полезные методы для работы с request

// request body string
$body = \darkfriend\helpers\Request::getBody(); 

// get request body json
$body = \darkfriend\helpers\Request::getBodyJson();
var_dump($body); // all keys from body json

Response - полезные методы для работы с response

$jsonResponse = [
    'param1' => 'value1',
    'param2' => 'value2',
    'param3' => 'value3',
];
// json response
$body = \darkfriend\helpers\Response::json($jsonResponse); 
die($body);
// or response json string
\darkfriend\helpers\Response::json($jsonResponse,[
    'show' => true,
    'die' => true,
]);

// xml response
$body = \darkfriend\helpers\Response::xml($jsonResponse);
die($body);
// or response xml string
\darkfriend\helpers\Response::xml($jsonResponse,[
    'show' => true,
    'die' => true,
]);

// add header
\darkfriend\helpers\Response::setHeader([
    'Content-Type' => 'application/json',
    'Custom-Header' => 'custom header value',
]);

DateTimeHelper - полезные хелперы для работы с датой

Узнать возраст (кол-во годов)

$age = \darkfriend\helpers\DateTimeHelper::getAge('1992-05-16'); // 28 (by from 3 october 2020)
// or
$age = \darkfriend\helpers\DateTimeHelper::getAge('1992-05-16', '2020-10-03'); // 28 (by from 3 october 2020)

Узнать кол-во секунд до конца дня

$seconds = \darkfriend\helpers\DateTimeHelper::getAmountEndDay();

Узнать кол-во секунд между сейчас и определенной датой

$endTime = strtotime("tomorrow") - 1;
$seconds = \darkfriend\helpers\DateTimeHelper::getAmountSeconds($endTime);

php5-helpers's People

Contributors

darkfriend avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.