0

Recently I added a telegram bot extension in my Yii2 application to use it. but actually it is not a Yii2 extension but its a normal php namespace structured files and classes.

the name of this telegram extension is irazasyed/telegram-bot-sdk actualy its the name that added to my composer.json. I want to know how can I make some classess like this extension?

the irazasyed/telegram-bot-sdk structure is like this:

vandor >>
    irazasyed
        telegram-bot-sdk
            composer.json
            license
            src
                class1.php
                class2.php

and the class files can be accessed from the namespace like \Telegram\Bot\Api from any controller in my application.

i want to know how can I make something like this myself. I want this structure:

vendor >>
    myCustomName
        myCustomPakageName
            composer.json
            license
            src
                Class1.php
                Class2.php

and access the class files from this namespace \something\somethingElse\Class1;

how can I do this?

1 Answers1

0

Just add your files in a folder (or folders) in the project folder and use suggested root namespace. You don't need composer.json since you don't need to install it using composer. And you should not put it in vendor folder.

Example for basic project template: - put everything in myCustomName folder in application root folder, - set namespaces for each class like app\myCustomName (+ whatever subfolder you are using)

Example for advanced project template: - put everything in myCustomName folder in selected application root folder (like frontend or common), - set namespaces for each class like frontend\myCustomName (or common instead of frontend or whatever + whatever subfolder you are using)

Bizley
  • 17,392
  • 5
  • 49
  • 59
  • actually currently I using this approach myself. I want to do it without the `\frontend\ ` part in the name. is it possible? lets say I am in backend controller and myCustom folder is in frontend so I should use `\frontend\myCustom+...` but I want to use something like the namespace I said in my question. – mohammad fallah.rasoulnejad Apr 06 '17 at 10:11
  • In this case you need to register your root namespace for autoloaders. One of the solutions can be [found in my other answer](http://stackoverflow.com/a/42330631/3364821) – Bizley Apr 06 '17 at 10:16