Giter Club home page Giter Club logo

yorn's Introduction

Yorn Preview

Build Status Total Downloads Latest Version License

Modules in PHP with the `import` and `export` syntax.

Yorn was carefully crafted to introduce the support for modules in PHP with the import and export syntax. It was created by Nuno Maduro.

Before the quick start, keep in mind that a module usually contains a collection of functions, and those functions are small units of independent, reusable code that is desired to be used as the building blocks in creating a PHP application.

As example, this is how a typical Yorn application would look like:

# src/math/sum.php:
<?php export(function ($one, $two) {
    return $one + $two;
});

# src/index.php:
<?php

$sum = import('math/sum');

echo $sum(1, 2);

🚀 Quick start

Remember, this is just an experiment. Don't use this in production.

# First, install:
composer require nunomaduro/yorn

✨ Exporting a function

Any function can be exported by using the export function:

# src/validators/zipCodeValidator.php:
<?php export(function (string $value) {
    return strlen($value) === 5;
});

✨ Importing a function

Importing is just about as easy as exporting from a module. Importing an exported declaration is done through using one of the import forms below:

# src/index.php
<?php

$zipCodeValidator = import('validators/zipCodeValidator');

echo $zipCodeValidator(8000);

✨ Default exports

Of course, you may want to import all functions in a module:

# src/index.php
<?php

$validators = import('validators'); // zipCodeValidator is imported also here

$zipCodeValidator = $validators->zipCodeValidator;

echo $zipCodeValidator(8000);

💖 Support the development

Do you like this project? Support it by donating

Yorn is open-sourced software licensed under the MIT license.

yorn's People

Contributors

nunomaduro avatar roccohoward avatar

Watchers

James Cloos 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.