{"id":33966493,"url":"https://github.com/cuculcan/core","last_synced_at":"2025-12-30T17:15:31.881Z","repository":{"id":56960115,"uuid":"82498697","full_name":"Cuculcan/core","owner":"Cuculcan","description":"Our php projects core","archived":false,"fork":false,"pushed_at":"2019-12-09T06:28:12.000Z","size":713,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-23T06:54:40.653Z","etag":null,"topics":["easy","framework","php","restapi"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Cuculcan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-20T00:00:10.000Z","updated_at":"2019-12-09T06:28:15.000Z","dependencies_parsed_at":"2022-08-21T05:10:17.355Z","dependency_job_id":null,"html_url":"https://github.com/Cuculcan/core","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/Cuculcan/core","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cuculcan%2Fcore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cuculcan%2Fcore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cuculcan%2Fcore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cuculcan%2Fcore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Cuculcan","download_url":"https://codeload.github.com/Cuculcan/core/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Cuculcan%2Fcore/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27694707,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-12T02:00:06.775Z","response_time":129,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["easy","framework","php","restapi"],"created_at":"2025-12-12T23:17:08.938Z","updated_at":"2025-12-12T23:17:10.763Z","avatar_url":"https://github.com/Cuculcan.png","language":"PHP","readme":"# CORE\n\nSmall simple PHP MVC RESTlike framework for training purposes\n\n## installation\n\n```sh\ncomposer create-project cuculcan/core\n```\n\n## Navigation\n\n[Model](#Model)\n\n[Controller](#controllers)\n\n[View](#views)\n\n### Model\n\nModels are objects inherited from the Entity class.\nThe entity corresponds to the row in the database table\n\neach entry has at least an \"id\" field\n\nUser class example:\n\n```php\nclass User extends Entity {\n\n    public $name;\n    public $email;\n    public $cityId;\n    public $login;\n    public $password;\n    \n    /**\n     * @type = json\n     */\n    public $subscription;\n    \n    /**\n     * @extra\n     */\n    public $city_name;\n\n    /**\n     * @extra\n     */\n    public $region_name;\n\n    public function __construct(array $data = []) {\n        parent::__construct($data);\n    }\n\n}\n```\n\nEntity fields can be annotated.\n\n***extra*** means that this property has no relation to the table column\n\n***type = json***  used to pack arrays in json when saving to db\n\n***default_value =***  used to set the default value in case the value is undefined\n\nthe constructor should be described as in the example and have at least the data parameter used to build the object after selecting from the database\n\n### Storages\n\nFor entities, storage objects are created that implement the functionality for working with the Database\nRepositories inherit from the MysqlStorage base class\n\nСRUD methods for the Entity object are implemented in the base class MysqlStorage\n\n```php\nclass UsersMysqlStorage extends MysqlStorage {\n\n    /**\n     *\n     * @param \\Pdo $connection\n     */\n    public function __construct($connection) {\n        parent::__construct($connection, 'users'); //Sets the name of the table with which the storage works\n    }\n\n    /**\n     * uses the parent class method getById\n     * @param int $id\n     * @return User\n     */\n    public function getById($id) {\n        $data = parent::getById($id);\n\n        if (!$data || $data === null) {\n            return null;\n        }\n\n        return new User($data);\n    }\n\n     /**\n     * direct query can be implemented using \\PDO\n     * @return int\n     */\n    public function countUsers() {\n        $sql = \" SELECT count(id) AS cnt FROM users \";\n\n        $stm = $this-\u003econnection-\u003eprepare($sql);\n        $stm-\u003eexecute();\n        $cnt = 0;\n        while ($row = $stm-\u003efetch(\\PDO::FETCH_ASSOC)) {\n            $cnt = $row['cnt'];\n        }\n        return $cnt;\n    }\n}\n```\n\n## Controllers\n\nControllers are designed to handle incoming requests\n\nAny request to the site is converted using .htaccess RewriteRule\n\n```htaccess\nRewriteRule ^(.*)$ index.php?handler=$1 [QSA,L]\n```\n\nor nginx rewrite\n\n```nginx\nlocation @rewrite {\n    rewrite ^/(.*)$ /index.php?handler=/$1;\n}\n```\n\nand sent to index.php\n\nThe sequence of request processing is as follows:\n\n```o\n.htaccess-\u003eindex.php-\u003eRequest-\u003eRouter-\u003eController\n```\n\nController Inheritance Chain\n\n```o\nAController\n    ^\n    |\nBaseController\n    ^\n    |\nMainController and other controllers\n```\n\n**AController** is abstract. Invokes methods for handling addresses described in specific controllers. Should not depend on a specific project\n\n**BaseController** inherits from AController and contains common methods for all user controllers. For example, initialization of a session user.\n Preparing data for menus and others.\n\n***MainController and other user controllers*** are inherited from BaseController and contain methods for processing specific url addresses.\nThe project must have at least one controller named **MainController**, it is responsible for processing calls to the root of the site.\n\n```o\nhttp://mysite.com\n```\n\nTo process other requests to the site, request handlers must be described in the appropriate controllers. For example, addresses starting with:\n\n```o\nhttp://mysite.com/user\n```\n\nMust be described in UserController\n\n### Routing\n\nEach controller class must have a method implementation\n\n```php\nprotected function setActions()\n```\n\nHandlers of URL templates are registered inside. There are handlers for ***GET, POST, PUT, DELETE*** requests. Implemented as Methods with appropriate names\n\n```php\nget()\npost()\ndel()\nput()\n```\n\nThe URL template handler has the format\n\n```php\n$this-\u003eget | post | del | put ('[url pattern]', callback function with parameter ($urlParams));\n```\n\nThe implementation of the response to the request is described in the callback of this method.\nIn the URL template, there may be a variable parameter which is written in curly brackets and may be available inside the callback\n\n```php\n$this-\u003eget('/user/{userId}/get_name', function ($urlParams)  {\n    echo $urlParams['userId'];\n});\n```\n\nIn this example, a request of the form ***http: //myexample.com/user/12345/get_name*** will be processed and ***12345*** will be displayed\n\n**Request parameters** can be accessed through the request object and it methods\n\ngetQueryParameters() - will return an array of parameters\n\ngetQueryParameter($name, $default = null) - will return the value of the parameter or the value passed to default, if the parameter is missing\n\n```php\n //process GET request http://myexample.com/user/set_name?name=VasiliyPupkin\n$this-\u003eget('/user/set_name', function ($urlParams)  {\n\n   $name =$this-\u003erequest-\u003egetQueryParameter(\"name\", \"\");\n   echo $name\n});\n```\n\nAll methods described in setActions() are executed in turn and the one that matches the template is selected,\nif more than one method matches the pattern, an exception is thrown\n\nIn all objects of the controller, the variable ***model*** is present.\nIt is used to transfer data to objects of the View class for later display.\n\nThe View object is called by the method $ this-\u003eshowView(\"UserView\"). The parameter is the name of the class to display.\n\n```php\n//process GET request http://myexample.com/user\n$this-\u003eget('/user', function ($urlParams)  {\n\n   $this-\u003emodel['some_parameter'] = 'param from user controller';\n   $this-\u003eshowView(\"UserView\");\n});\n```\n\nView will be displayed with the class UserView\n\n## View\n\nView classes inherit from the abstract class AView, used to display templates. PHP itself is used as a template engine.\n\nMainView class example:\n\n```php\nclass MainView extends AView\n{\n    public function __construct($model) {\n        parent::__construct();\n        $this-\u003emodel = $model;\n    }\n\n    protected function setTemplateName()\n    {\n        /*\n        * the template name is set relative to the path specified in config/config.php\n        */\n        $this-\u003etemplateName = '/main.php';\n    }\n\n    //--------------------------------- SEO --------------------------------\n    protected function setTitle(){\n        $this-\u003etitle = \"\";\n    }\n\n    protected function setKeywords()    {\n        $this-\u003ekeywords=\"\";\n    }\n\n    protected function setDescription(){\n        $this-\u003edescription=\"\";\n    }\n    //---------------------------------------------------------------------------\n    protected function setAdditionalCSS(){\n        array_push($this-\u003eadditionalCSS, '/css/main.css');\n\n    }\n\n    protected function setAdditionalJS(){\n        array_push($this-\u003eadditionalJS, '/js/main.js');\n    }\n\n    protected function setCustomHeaders(){\n        array_push($this-\u003ecustomHeaders, \"MY-PEW-HEADER: pew-pew-pew\");\n    }\n\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuculcan%2Fcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcuculcan%2Fcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcuculcan%2Fcore/lists"}