npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

create-php-native

v1.0.3

Published

Your Code, Your Rules.

Readme

PHP-Native

Keep it simple and fast. Build scalable applications with a lightweight PHP framework that’s purely native, with no extra overhead.

Folder Structure

php/
│── app/
│   ├── Controllers/
│   │    ├── Api/
│   │    │    ├── WelcomeController.php
│   │    ├── Error404Controller.php
│   │    ├── ErrorController.php
│   │    ├── HomeController.php
│   │
│   ├── Middleware/
│   │    ├── ApiKeyMiddleware.php
│   │
│   ├── Models/
│   │    ├── ExampleData.php
│   │
│   ├── Routes/
│   │    ├── web.php
│   │    ├── api.php
│   │
│   ├── Views/
│        ├── layouts/
│        │    ├── main.php
│        ├── partials/
│        │    ├── header.php
│        │    ├── footer.php
│        ├── pages/
│             ├── 404.php
│             ├── error.php
│             ├── home.php
│── config/
│   ├── config.php
│
│── core/
│   ├── Controller.php
│   ├── Cors.php
│   ├── Database.php
│   ├── Model.php
│   ├── Router.php
│   ├── Security.php
│
│── public/
│   ├── images/
│   ├── css/
│   ├── js/
│   ├── .htaccess
│   ├── index.php
│
│── vendor/
│
│── .htaccess
│── composer.json
│── gulpfile.js
│── package.json
│── README.md

Example Get Data

// Display data
use Core\Database;

public function Example() {
  $data = Database::fetchAll("SELECT * FROM table_name");
  return $this->view('pages/home', 
  [
    'data' => $data, 
    'title' => 'Example Pages'
  ]);
}

Example Get By ID Data

use Core\Database;

public function example($id) {
  $data = Database::fetch("SELECT * FROM table_name WHERE id = :id", ['id' => $id]);
  if (!$data) {
    header("Location: /error");
    exit;
  }
  return $this->view('pages/home', [
    'data' => $data,
    'title' => 'Example Page'
  ]);
}

Example Adding Data

use Core\Database;

public function Example() {
  if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['form_column_name'])) {
    Database::execute("INSERT INTO table_name (column_name) VALUES (:column_name)", 
    [
    'column_name' => htmlspecialchars(trim($_POST['form_column_name']))
    ]);
  }
  header("Location: /");
  exit;
}

Example Edit Data

use Core\Database;

public function update($id) {
  if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    return;
  }
  Database::execute("UPDATE table_name SET column_name = :column_name WHERE id = :id", 
  [
    'column_name' => htmlspecialchars(trim($_POST['form_column_name'])),
    'id' => $id
  ]);
  header("Location: /");
  exit;
}

Example Delete Data

use Core\Database;

public function delete($id) {
  Database::execute("DELETE FROM table_name WHERE id = :id", ['id' => $id]);
  header("Location: /");
  exit;
}

Generate & Verification CSRF Input (View)

// Generate in Form
<?php use Core\Security; ?>
...
<input type="hidden" name="csrf_token" value="<?= Security::generateCsrfToken() ?>">
...

// Verification in Controller
use Core\Security;
...
if ($_SERVER["REQUEST_METHOD"] !== "POST" || !Security::verifyCsrfToken($_POST['csrf_token'] ?? '')) {
  $_SESSION['error'] = "Invalid CSRF Token!";
  header("Location: /error");
  exit;
}
...

Enable Secure Input (Controller)

use Core\Security;
...
'column_name' => trim(Security::sanitize($_POST['form_column_name'])),
...

Disable display layout, add 'false' to disable layout usage

return $this->view('pages/home', 
  [
    'title' => 'Home'
  ], false);

Set up a database connection in /config/config.php

'db' => [
  'host' => 'localhost',
  'dbname' => 'demo',
  'user' => 'root',
  'pass' => ''
],

Change api key (http://localhost:8000/v1?api-key=) in /config/config.php

'api' => [
  'api_key' => 'example-api-key-here',
]

Manage Additional Security in /config/config.php

'security' => [
  'csrf_protection' => true,
  'session_security' => true,
  'rate_limiting' => true,
  'security_headers' => true,
  'headers' => [
    'X-Frame-Options'            => 'DENY',
    'X-XSS-Protection'           => '1; mode=block',
    'X-Content-Type-Options'     => 'nosniff',
    'Referrer-Policy'            => 'no-referrer-when-downgrade',
    'Strict-Transport-Security'  => 'max-age=31536000; includeSubDomains; preload',
  ],
],