PHPackages                             murdej/ts-link-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. murdej/ts-link-php

ActiveLibrary[API Development](/categories/api)

murdej/ts-link-php
==================

A simple transparent link for calling php methods from typescript.

v1.6.0(1mo ago)1521[1 issues](https://github.com/murdej/ts-link-php/issues)Apache-2.0PHPPHP &gt;=8.3

Since Dec 13Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/murdej/ts-link-php)[ Packagist](https://packagist.org/packages/murdej/ts-link-php)[ RSS](/packages/murdej-ts-link-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (2)Versions (11)Used By (0)

TS link
=======

[](#ts-link)

What this thing can do. It simply connects PHP and typescript. Just write a class in PHP:

```
public function sayHello(string $name) : string
{
    return "Hello $name from PHP " . date('Y-m-d H:i:s') . ".";
}
```

and call in typescript:

```
const cl = new MyClassCL();
const value = await cl.sayHello("typescript");
```

How to use?
-----------

[](#how-to-use)

Install `murdej/ts-link-php` package with composer.

```
composer require murdej/ts-link-php
```

Create a class that will contain the methods you will use from js/ts. These methods must have the `#[ClientMethod()]` attribute from the namespace `Murdej\TsLinkPhp\`.

```
use Murdej\TsLinkPhp\ClientMethod;

class MyClassCL {
    #[ClientMethod()]
    public function sayHello(string $name) : string
    {
        return "Hello $name from PHP " . date('Y-m-d H:i:s') . ".";
    }
}
```

Create endpoint (in `endpoint.php`):

```
// Create instance of your service
$service = new MyClassCL();
// Create an instance of TsLink and pass your service to the constructor.
$tl = new TsLink($service);
// Get raw post content
$rawPost = file_get_contents('php://input');
// Call processRequest and pass contents,
$response = $tl->processRequest($rawPost);
// Result sent as json
header('Content-type: ' . $response->getContentType());
echo $response;
```

Generate js or ts code

```
$tsg = new TsCodeGenerator();
// Add a PHP class, optionally also the endpoint address. This step can be repeated.
$tsg->add(MyClassCL::class, './endpoint.php');
// Export format, can be ts or js. Default is ts
$tsg->format = "js";
// Enable or disable js modules (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
$tsg->useExport = false;
// Create and save ts/js sources
$source = $tsg->generateCode();
file_put_contents('./tslClasses.js', $source);
```

The generation of js/ts must be started after creating or modifying the header of the method to be accessed from js/ts.

Then you can call PHP methods from js/ts.

```

    const myClass = new MyClassCL();
    (async () => {
        const res = await myClass.sayHello("TypeScript");
        document.getElementById("message").innerText = res;
    })();

```

###  Health Score

44

—

FairBetter than 92% of packages

Maintenance70

Regular maintenance activity

Popularity12

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity71

Established project with proven stability

 Bus Factor1

Top contributor holds 55.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~195 days

Recently: every ~215 days

Total

9

Last Release

52d ago

PHP version history (2 changes)1.0.0PHP &gt;=8.0

v1.5.0PHP &gt;=8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a6ef15652012af4a703ce6c85cdca6b4beb6dbee1a96398d4082160a687fa73?d=identicon)[vit.peprnicek@gmail.com](/maintainers/vit.peprnicek@gmail.com)

---

Top Contributors

[![murdej](https://avatars.githubusercontent.com/u/6561966?v=4)](https://github.com/murdej "murdej (15 commits)")[![jakubboucek](https://avatars.githubusercontent.com/u/1657322?v=4)](https://github.com/jakubboucek "jakubboucek (12 commits)")

---

Tags

ajaxapifetchjavascripttypescript

### Embed Badge

![Health badge](/badges/murdej-ts-link-php/health.svg)

```
[![Health](https://phpackages.com/badges/murdej-ts-link-php/health.svg)](https://phpackages.com/packages/murdej-ts-link-php)
```

###  Alternatives

[worksome/graphlint

A static analysis tool for GraphQL

13189.4k](/packages/worksome-graphlint)[orisai/object-mapper

Raw data mapping to validated objects

1133.5k2](/packages/orisai-object-mapper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
