Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Oct 24, 2024
1 parent e20852b commit cf94ae1
Show file tree
Hide file tree
Showing 29 changed files with 6,032 additions and 0 deletions.
Binary file added .docs/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: http://EditorConfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = tab
indent_size = tab
tab_width = 4

[*.{json,yaml,yml,md}]
indent_style = space
indent_size = 2
10 changes: 10 additions & 0 deletions .github/.kodiak.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version = 1

[merge]
automerge_label = "automerge"
blacklist_title_regex = "^WIP.*"
blacklist_labels = ["WIP"]
method = "rebase"
delete_branch_on_merge = true
notify_on_conflict = true
optimistic_updates = false
9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: daily
labels:
- "dependencies"
- "automerge"
19 changes: 19 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "PHP"

on:
pull_request:

push:
branches: [ "*" ]

schedule:
- cron: "0 8 * * 1"

jobs:
php:
name: "PHP check"
uses: contributte/.github/.github/workflows/php.yml@v1
with:
name: "PHP check"
php: "8.2"
run: "composer validate"
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# IDE
.idea

# Composer
/vendor

# Nette
/config/local.neon

# Docker
/.data
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
![](https://heatbadger.now.sh/github/readme/contributte/demo-typesense/)

<p align=center>
<a href="https://github.com/contributte/demo-typesense/actions"><img src="https://badgen.net/github/checks/contributte/demo-typesense/master"></a>
<a href="https://packagist.org/packages/contributte/demo-typesense"><img src="https://badgen.net/packagist/dm/contributte/demo-typesense"></a>
<a href="https://packagist.org/packages/contributte/demo-typesense"><img src="https://badgen.net/packagist/v/contributte/demo-typesense"></a>
</p>
<p align=center>
<a href="https://packagist.org/packages/contributte/demo-typesense"><img src="https://badgen.net/packagist/php/contributte/demo-typesense"></a>
<a href="https://github.com/contributte/demo-typesense"><img src="https://badgen.net/github/license/contributte/demo-typesense"></a>
<a href="https://bit.ly/ctteg"><img src="https://badgen.net/badge/support/gitter/cyan"></a>
<a href="https://bit.ly/cttfo"><img src="https://badgen.net/badge/support/forum/yellow"></a>
<a href="https://contributte.org/partners.html"><img src="https://badgen.net/badge/sponsor/donations/F96854"></a>
</p>

<p align=center>
Website 🚀 <a href="https://contributte.org">contributte.org</a> | Contact 👨🏻‍💻 <a href="https://f3l1x.io">f3l1x.io</a> | Twitter 🐦 <a href="https://twitter.com/contributte">@contributte</a>
</p>

----

![](.docs/screenshot.png)

-----

## Goal

Demo of [Typesense](https://typesense.org/) Search Engine to Nette ([@nette](https://github.com/nette)) by [@f3l1x](https://github.com/f3l1x).

## Installation

You will need `PHP 8.2+` and [Composer](https://getcomposer.org/).

Create project using composer.

```bash
composer create-project -s dev contributte/demo-typesense acme
```

Now you have application installed. It's time to run it.

## Startup

1. Spin up PostgreSQL database. It will load `init.sql` file, thus you don't have to create schema manually.

```bash
docker compose up
```

2. Prepare search engine structure in Typesense.

```bash
bin/setup
```

3. Prepare fake data in PostgreSQL (optional).

```bash
bin/fake
```

4. Start PHP built-in web server.

```bash
bin/dev
# or
php -S 0.0.0.0:8000 -t www
```

Then visit [http://localhost:8000](http://localhost:8000) in your browser.

## Development

See [how to contribute](https://contributte.org/contributing.html) to this package.

This package is currently maintaining by these authors.

<a href="https://github.com/f3l1x">
<img width="80" height="80" src="https://avatars2.githubusercontent.com/u/538058?v=3&s=80">
</a>

-----

Consider to [support](https://contributte.org/partners.html) **contributte** development team.
Also thank you for using this project.
29 changes: 29 additions & 0 deletions app/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php declare(strict_types = 1);

namespace App;

use Nette\Bootstrap\Configurator;

final class Bootstrap
{

public static function boot(): Configurator
{
$configurator = new Configurator();
$rootDir = dirname(__DIR__);

$configurator->setDebugMode(true);

$configurator->enableTracy($rootDir . '/log');
$configurator->setTempDirectory($rootDir . '/temp');

$configurator->addConfig($rootDir . '/config/config.neon');

if (file_exists($rootDir . '/config/config.local.neon')) {
$configurator->addConfig($rootDir . '/config/config.local.neon');
}

return $configurator;
}

}
17 changes: 17 additions & 0 deletions app/Model/RouterFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php declare(strict_types = 1);

namespace App\Model;

use Nette\Application\Routers\RouteList;

final class RouterFactory
{

public static function createRouter(): RouteList
{
$router = new RouteList;
$router->addRoute('<presenter>/<action>[/<id>]', 'Home:default');
return $router;
}

}
75 changes: 75 additions & 0 deletions app/Model/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php declare(strict_types = 1);

namespace App\Model;

use DateTime;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity(repositoryClass: UserRepository::class)]
#[ORM\Table(name: 'users')]
class User
{

#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
public int $id;

#[ORM\Column(type: 'string')]
public string $username;

#[ORM\Column(type: 'string')]
public string $address;

#[ORM\Column(type: 'string')]
public string $phone;

#[ORM\Column(type: 'string')]
public string $company;

#[ORM\Column(type: 'string')]
public string $bio;

#[ORM\Column(type: 'datetime')]
public DateTime $createdAt;

#[ORM\Column(type: 'datetime', nullable: true)]
public ?DateTime $updatedAt = null;

public function __construct(
string $username,
string $address,
string $phone,
string $company,
string $bio
)
{
$this->username = $username;
$this->address = $address;
$this->phone = $phone;
$this->company = $company;
$this->bio = $bio;
$this->createdAt = new DateTime();
}

#[ORM\PreUpdate]
public function preUpdate(): void
{
$this->updatedAt = new DateTime();
}

public function toSearch(): array
{
return [
'id' => (string) $this->id,
'username' => $this->username,
'address' => $this->address,
'phone' => $this->phone,
'company' => $this->company,
'bio' => $this->bio,
'created_at' => $this->createdAt->format('Y-m-d H:i:s'),
'updated_at' => $this->updatedAt ? $this->updatedAt->format('Y-m-d H:i:s') : null,
];
}

}
18 changes: 18 additions & 0 deletions app/Model/UserRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types = 1);

namespace App\Model;

use Doctrine\ORM\EntityRepository;

/**
* @extends EntityRepository<User>
* @method User|null find($id, ?int $lockMode = null, ?int $lockVersion = null)
* @method User|null findOneBy(array $criteria, array $orderBy = null)
* @method User|null findOneById(int $id)
* @method User[] findAll()
* @method User[] findBy(array $criteria, array $orderBy = null, ?int $limit = null, ?int $offset = null)
*/
final class UserRepository extends EntityRepository
{

}
40 changes: 40 additions & 0 deletions app/UI/@layout.latte
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{block #title|striptags}Typesense Demo{/}</title>

<script src="https://cdn.tailwindcss.com"></script>
</head>
<body>

<div class="antialiased px-6 text-gray-900">
<div class="divide-y max-w-xl md:max-w-4xl mx-auto">
<div class="py-8">
<h1 class="font-bold text-3xl">
Contributte / Typesense Demo
</h1>
</div>

<div n:if="$flashes !== []" n:inner-foreach="$flashes as $flash" class="py-2 flex flex-col gap-2">
<div n:class="$flash->type === 'success' ? 'bg-green-500', $flash->type === 'info' ? 'bg-blue-500', 'rounded-md px-4 py-2 text-white'">
{$flash->message}
</div>
</div>

<div class="py-8">
{include #content}
</div>

<div class="py-8">
&copy; {=date(Y)} by <a href="https://github.com/f3l1x" class="text-blue-600 underline">@f3l1x</a>
</div>
</div>
</div>
</body>
</html>



10 changes: 10 additions & 0 deletions app/UI/BasePresenter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php declare(strict_types = 1);

namespace App\UI;

use Nette\Application\UI\Presenter;

abstract class BasePresenter extends Presenter
{

}
Loading

0 comments on commit cf94ae1

Please sign in to comment.