Giter Site home page Giter Site logo

event.fpv.jp-api's Introduction

event.fpv.jp-api

エンティティの作成: まず、Doctrineで扱いたいデータベースのテーブルに対応するエンティティクラスを作成します。

php vendor/bin/doctrine orm:generate-entities ./src

Did you mean one of these?
orm:clear-cache:metadata
orm:clear-cache:query
orm:clear-cache:region:collection
orm:clear-cache:region:entity
orm:clear-cache:region:query
orm:clear-cache:result
orm:convert-d1-schema
orm:convert-mapping
orm:convert:d1-schema
orm:convert:mapping
orm:ensure-production-settings
orm:generate-entities
orm:generate-proxies
orm:generate-repositories
orm:generate:entities
orm:generate:proxies
orm:generate:repositories
orm:info
orm:mapping:describe
orm:run-dql
orm:schema-tool:create
orm:schema-tool:drop
orm:schema-tool:update
orm:validate-schema

.github/workflows/ci.yml

A project to demonstrate how to integrate Doctrine 2.x into Slim. This is the companion code for the Cookbook entry Using Doctrine with Slim in Slim's documentation.

Requirements

  • PHP 8.1+
  • PHP SQLite extension
  • Composer

Overview

The Slim-Doctrine-Demo project is a small REST API that allows its clients to create and retrieve lists of users.

  • GET /api/users -> Retrieves a list of all users created so far.
  • POST /api/users -> Creates a new user (does not accept any parameters, fake data is autogenerated).

At its core, Doctrine's EntityManager is used to persist and retrieve these users from an SQLite database.

Project structure

Slim-Doctrine-Demo
├── public
│   └── index.php           -- HTTP front controller (requires ../bootstrap.php)
├── src
│   ├── Rest              -- Slim request handlers
│   │   ├── CreateUser.php
│   │   └── ListUsers.php
│   ├── DI
│   │   ├── Doctrine.php    -- EntityManager service definition
│   │   └── Slim.php        -- Slim request handlers service definitions
│   └── Domain              -- Annotated entity classes
│       └── User.php
├── tests/                  -- Automated tests
├── var
│   ├── coverage/           -- Test coverage results in HTML
│   ├── doctrine/           -- Doctrine metadata cache
│   └── database.sqlite     -- Development database
├── bootstrap.php           -- DI container setup (requires ./settings.php)
├── cli-config.php          -- Configuration file for the vendor/bin/doctrine development tool
├── composer.json
├── composer.lock
├── LICENSE
├── phpunit.xml.dist
├── README.md               -- You are here.
├── settings.php            -- Settings currently in use (ignored by Git)
└── settings.php.dist       -- Sample settings.php for development (committed to Git)

Running the app

Typing composer serve in a console will install the project dependencies, create the database and open the API at http://localhost:8001. Once it is running you can make requests against it with a browser, curl or similar tools.

$ curl -X POST localhost:8001/api/users

$ curl -X GET localhost:8001/api/users

% curl -X POST \
  -H "Content-Type: application/json" \
  --data '{"query": "query { user(id: \"1\") { id email registered_at } }"}' \
  http://localhost:8001/graphql

% curl -X POST \
    -d '{"query": "query { allUsers { id email registered_at } }" }' \
    -H "Content-Type: application/json" \
    http://localhost:8001/graphql

% curl -X POST \
  -H "Content-Type: application/json" \
  --data '{"query": "mutation { createUser(email: \"[email protected]\", password: \"password\") { id email registered_at } }"}' \
  http://localhost:8001/graphql

% curl -X POST \
  -H "Content-Type: application/json" \
  --data '{"query": "mutation { updateUser(id: \"1\", email: \"[email protected]\") { id email registered_at } }"}' \
  http://localhost:8001/graphql

% curl -X POST \
  -H "Content-Type: application/json" \
  --data '{"query": "mutation { deleteUser(id: \"1\") { id email } }"}' \
  http://localhost:8001/graphql

Using the Doctrine Command Line Interface

Run ./bin/doctrine (this script needs the project dependencies, so run composer install first).

Running the tests

Similarly, typing composer test will take care of loading the testing environment and running PHPUnit. If the XDebug exension is enabled code coverage results will be available at var/coverage/ after running the tests.

event.fpv.jp-api's People

Contributors

fpv-jp avatar hexaforce 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.