Namespacing issue in custom php package, unable to do “use joelwmale/RSSFeedPHP”












0














I have created my own composer package but am having some issues trying to load and use it outside of the package itself (i.e in my laravel application).



My composer file looks like:



{
"name": "joelwmale/rss-feed-php",
"type": "library",
"description": "RSS Feeds for PHP is a very small, lightweight, and easy-to-use library for consuming an RSS feed.",
"keywords": [
"rss",
"feed",
"php"
],
"homepage": "https://github.com/joelwmale/rss-feed-php",
"support": {
"issues": "https://github.com/joelwmale/rss-feed-php/issues",
"source": "https://github.com/joelwmale/rss-feed-php"
},
"license": "MIT",
"authors": [
{
"name": "Joel Male",
"email": "joel@joelmale.com",
"homepage": "https://www.joelmale.com",
"role": "Author"
}
],
"minimum-stability": "dev",
"require": {
"php": "^7.1",
"ext-simplexml": "*",
"nesbot/carbon": "^1.26.3"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"phpstan/phpstan": "^0.11.0@dev"
},
"autoload": {
"psr-4": {
"RSSFeedPHP\": "src/RSSFeedPHP/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"scripts": {
"test": [
"@phpunit",
"@phpcs"
],
"phpunit": "vendor/bin/phpunit",
"phpcs": "php-cs-fixer fix -v --diff --dry-run",
"phpstan": "phpstan analyse --configuration phpstan.neon --level 3 src tests"
},
"extra": {
"laravel": {
"providers": [
"RSSFeedPHP\Laravel\ServiceProvider"
]
}
}
}


And my main class is located in: src/RSSFeedPHP/RSSFeedPHP.php. However, when I try and load it in my laravel application:



use joelwmaleRSSFeedPHP;


I get:



"Class 'joelwmaleRSSFeedPHP' not found"


Even though I have required it in my laravel application. I can see the joelwmale folder inside vendor, and can also see my package and it's composer file.



There has to be something wrong with the composer.json or way I've setup the project - but I can't figure it out.



Any ideas?



Edit: Repo link: https://github.com/joelwmale/rss-feed-php










share|improve this question




















  • 1




    Have you run composer dump-autoload and checked output?
    – Calos Kao
    Dec 28 '18 at 7:56












  • I have, daly it just prints nothing other then "Dumping autoload" :(
    – joelwxd
    Dec 28 '18 at 8:15










  • I suggest you to read carefully about how PSR-4 works: php-fig.org/psr/psr-4.
    – GiamPy
    Dec 28 '18 at 8:22










  • I do understand how it works. Your comment does not really help as I am already following PSR-4. I have even looked at Carbon's composer file (which works like CarbonCarbon but for some reason that is not working for me. Right now I can get it working doing use RSSFeedPHPRSSFeedPHP, but what I want to achieve is doing a vendor/package namespace, e.g: use joelwmaleRSSFeedPHP
    – joelwxd
    Dec 28 '18 at 8:30


















0














I have created my own composer package but am having some issues trying to load and use it outside of the package itself (i.e in my laravel application).



My composer file looks like:



{
"name": "joelwmale/rss-feed-php",
"type": "library",
"description": "RSS Feeds for PHP is a very small, lightweight, and easy-to-use library for consuming an RSS feed.",
"keywords": [
"rss",
"feed",
"php"
],
"homepage": "https://github.com/joelwmale/rss-feed-php",
"support": {
"issues": "https://github.com/joelwmale/rss-feed-php/issues",
"source": "https://github.com/joelwmale/rss-feed-php"
},
"license": "MIT",
"authors": [
{
"name": "Joel Male",
"email": "joel@joelmale.com",
"homepage": "https://www.joelmale.com",
"role": "Author"
}
],
"minimum-stability": "dev",
"require": {
"php": "^7.1",
"ext-simplexml": "*",
"nesbot/carbon": "^1.26.3"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"phpstan/phpstan": "^0.11.0@dev"
},
"autoload": {
"psr-4": {
"RSSFeedPHP\": "src/RSSFeedPHP/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"scripts": {
"test": [
"@phpunit",
"@phpcs"
],
"phpunit": "vendor/bin/phpunit",
"phpcs": "php-cs-fixer fix -v --diff --dry-run",
"phpstan": "phpstan analyse --configuration phpstan.neon --level 3 src tests"
},
"extra": {
"laravel": {
"providers": [
"RSSFeedPHP\Laravel\ServiceProvider"
]
}
}
}


And my main class is located in: src/RSSFeedPHP/RSSFeedPHP.php. However, when I try and load it in my laravel application:



use joelwmaleRSSFeedPHP;


I get:



"Class 'joelwmaleRSSFeedPHP' not found"


Even though I have required it in my laravel application. I can see the joelwmale folder inside vendor, and can also see my package and it's composer file.



There has to be something wrong with the composer.json or way I've setup the project - but I can't figure it out.



Any ideas?



Edit: Repo link: https://github.com/joelwmale/rss-feed-php










share|improve this question




















  • 1




    Have you run composer dump-autoload and checked output?
    – Calos Kao
    Dec 28 '18 at 7:56












  • I have, daly it just prints nothing other then "Dumping autoload" :(
    – joelwxd
    Dec 28 '18 at 8:15










  • I suggest you to read carefully about how PSR-4 works: php-fig.org/psr/psr-4.
    – GiamPy
    Dec 28 '18 at 8:22










  • I do understand how it works. Your comment does not really help as I am already following PSR-4. I have even looked at Carbon's composer file (which works like CarbonCarbon but for some reason that is not working for me. Right now I can get it working doing use RSSFeedPHPRSSFeedPHP, but what I want to achieve is doing a vendor/package namespace, e.g: use joelwmaleRSSFeedPHP
    – joelwxd
    Dec 28 '18 at 8:30
















0












0








0







I have created my own composer package but am having some issues trying to load and use it outside of the package itself (i.e in my laravel application).



My composer file looks like:



{
"name": "joelwmale/rss-feed-php",
"type": "library",
"description": "RSS Feeds for PHP is a very small, lightweight, and easy-to-use library for consuming an RSS feed.",
"keywords": [
"rss",
"feed",
"php"
],
"homepage": "https://github.com/joelwmale/rss-feed-php",
"support": {
"issues": "https://github.com/joelwmale/rss-feed-php/issues",
"source": "https://github.com/joelwmale/rss-feed-php"
},
"license": "MIT",
"authors": [
{
"name": "Joel Male",
"email": "joel@joelmale.com",
"homepage": "https://www.joelmale.com",
"role": "Author"
}
],
"minimum-stability": "dev",
"require": {
"php": "^7.1",
"ext-simplexml": "*",
"nesbot/carbon": "^1.26.3"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"phpstan/phpstan": "^0.11.0@dev"
},
"autoload": {
"psr-4": {
"RSSFeedPHP\": "src/RSSFeedPHP/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"scripts": {
"test": [
"@phpunit",
"@phpcs"
],
"phpunit": "vendor/bin/phpunit",
"phpcs": "php-cs-fixer fix -v --diff --dry-run",
"phpstan": "phpstan analyse --configuration phpstan.neon --level 3 src tests"
},
"extra": {
"laravel": {
"providers": [
"RSSFeedPHP\Laravel\ServiceProvider"
]
}
}
}


And my main class is located in: src/RSSFeedPHP/RSSFeedPHP.php. However, when I try and load it in my laravel application:



use joelwmaleRSSFeedPHP;


I get:



"Class 'joelwmaleRSSFeedPHP' not found"


Even though I have required it in my laravel application. I can see the joelwmale folder inside vendor, and can also see my package and it's composer file.



There has to be something wrong with the composer.json or way I've setup the project - but I can't figure it out.



Any ideas?



Edit: Repo link: https://github.com/joelwmale/rss-feed-php










share|improve this question















I have created my own composer package but am having some issues trying to load and use it outside of the package itself (i.e in my laravel application).



My composer file looks like:



{
"name": "joelwmale/rss-feed-php",
"type": "library",
"description": "RSS Feeds for PHP is a very small, lightweight, and easy-to-use library for consuming an RSS feed.",
"keywords": [
"rss",
"feed",
"php"
],
"homepage": "https://github.com/joelwmale/rss-feed-php",
"support": {
"issues": "https://github.com/joelwmale/rss-feed-php/issues",
"source": "https://github.com/joelwmale/rss-feed-php"
},
"license": "MIT",
"authors": [
{
"name": "Joel Male",
"email": "joel@joelmale.com",
"homepage": "https://www.joelmale.com",
"role": "Author"
}
],
"minimum-stability": "dev",
"require": {
"php": "^7.1",
"ext-simplexml": "*",
"nesbot/carbon": "^1.26.3"
},
"require-dev": {
"phpunit/phpunit": "^7.5",
"phpstan/phpstan": "^0.11.0@dev"
},
"autoload": {
"psr-4": {
"RSSFeedPHP\": "src/RSSFeedPHP/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
}
},
"scripts": {
"test": [
"@phpunit",
"@phpcs"
],
"phpunit": "vendor/bin/phpunit",
"phpcs": "php-cs-fixer fix -v --diff --dry-run",
"phpstan": "phpstan analyse --configuration phpstan.neon --level 3 src tests"
},
"extra": {
"laravel": {
"providers": [
"RSSFeedPHP\Laravel\ServiceProvider"
]
}
}
}


And my main class is located in: src/RSSFeedPHP/RSSFeedPHP.php. However, when I try and load it in my laravel application:



use joelwmaleRSSFeedPHP;


I get:



"Class 'joelwmaleRSSFeedPHP' not found"


Even though I have required it in my laravel application. I can see the joelwmale folder inside vendor, and can also see my package and it's composer file.



There has to be something wrong with the composer.json or way I've setup the project - but I can't figure it out.



Any ideas?



Edit: Repo link: https://github.com/joelwmale/rss-feed-php







php composer-php






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '18 at 8:15







joelwxd

















asked Dec 28 '18 at 7:51









joelwxdjoelwxd

4329




4329








  • 1




    Have you run composer dump-autoload and checked output?
    – Calos Kao
    Dec 28 '18 at 7:56












  • I have, daly it just prints nothing other then "Dumping autoload" :(
    – joelwxd
    Dec 28 '18 at 8:15










  • I suggest you to read carefully about how PSR-4 works: php-fig.org/psr/psr-4.
    – GiamPy
    Dec 28 '18 at 8:22










  • I do understand how it works. Your comment does not really help as I am already following PSR-4. I have even looked at Carbon's composer file (which works like CarbonCarbon but for some reason that is not working for me. Right now I can get it working doing use RSSFeedPHPRSSFeedPHP, but what I want to achieve is doing a vendor/package namespace, e.g: use joelwmaleRSSFeedPHP
    – joelwxd
    Dec 28 '18 at 8:30
















  • 1




    Have you run composer dump-autoload and checked output?
    – Calos Kao
    Dec 28 '18 at 7:56












  • I have, daly it just prints nothing other then "Dumping autoload" :(
    – joelwxd
    Dec 28 '18 at 8:15










  • I suggest you to read carefully about how PSR-4 works: php-fig.org/psr/psr-4.
    – GiamPy
    Dec 28 '18 at 8:22










  • I do understand how it works. Your comment does not really help as I am already following PSR-4. I have even looked at Carbon's composer file (which works like CarbonCarbon but for some reason that is not working for me. Right now I can get it working doing use RSSFeedPHPRSSFeedPHP, but what I want to achieve is doing a vendor/package namespace, e.g: use joelwmaleRSSFeedPHP
    – joelwxd
    Dec 28 '18 at 8:30










1




1




Have you run composer dump-autoload and checked output?
– Calos Kao
Dec 28 '18 at 7:56






Have you run composer dump-autoload and checked output?
– Calos Kao
Dec 28 '18 at 7:56














I have, daly it just prints nothing other then "Dumping autoload" :(
– joelwxd
Dec 28 '18 at 8:15




I have, daly it just prints nothing other then "Dumping autoload" :(
– joelwxd
Dec 28 '18 at 8:15












I suggest you to read carefully about how PSR-4 works: php-fig.org/psr/psr-4.
– GiamPy
Dec 28 '18 at 8:22




I suggest you to read carefully about how PSR-4 works: php-fig.org/psr/psr-4.
– GiamPy
Dec 28 '18 at 8:22












I do understand how it works. Your comment does not really help as I am already following PSR-4. I have even looked at Carbon's composer file (which works like CarbonCarbon but for some reason that is not working for me. Right now I can get it working doing use RSSFeedPHPRSSFeedPHP, but what I want to achieve is doing a vendor/package namespace, e.g: use joelwmaleRSSFeedPHP
– joelwxd
Dec 28 '18 at 8:30






I do understand how it works. Your comment does not really help as I am already following PSR-4. I have even looked at Carbon's composer file (which works like CarbonCarbon but for some reason that is not working for me. Right now I can get it working doing use RSSFeedPHPRSSFeedPHP, but what I want to achieve is doing a vendor/package namespace, e.g: use joelwmaleRSSFeedPHP
– joelwxd
Dec 28 '18 at 8:30














1 Answer
1






active

oldest

votes


















2














"autoload": {
"psr-4": {
"RSSFeedPHP\": "src/RSSFeedPHP/"
}
},


This registers your class under the RSSFeedPHP namespace. Anything in the src/RSSFeedPHP/ directory can now be loaded as if it were in that namespace. Try using



use RSSFeedPHPRSSFeedPHP;



Note that the name of your class must be RSSFeedPHP if your file is called RSSFeedPHP.php, and its namespace must thus be also RSSFeedPHP, i.e.



<?php

namespace RSSFeedPHP;

class RSSFeedPHP {}





share|improve this answer





















  • How would i follow a typical vendor/package namespacing? I did have it joelwmale/RSSFeedPHP before, but then when using the namespace I needed to do: use joelwmale/RSSFeedPHP/RSSFeedPHP I simply want to be able to do: use joelwmale/RSSFeedPHP and it automatically load the class. I have added my github repo to the original post sorry.
    – joelwxd
    Dec 28 '18 at 8:14












  • You can use any namespace you want. The name that ends up in the /vendor directory is the one you specify under the name key in composer.json. E.g. if your package's name is joelwmale/rssfeed then you will see a directory /vendor/joelwmale/rssfeed. You can use any namespace in there, but it's good practice to choose a unique one for your packaging, like Joelwmale. Then you can issue use Joelwmale/RSSFeedPHP;, or use Joelwmale/Feed/RSSFeed; or whatever if you want to "sub"package.
    – minitauros
    Dec 28 '18 at 8:31












  • Yep fully understood. If I wanted my namespacing to be use joelwmale/RSSFeedPHP; how would I achieve that with the composer.json in the file above? The issue ATM is that I can get that to work - but I'd have to do: use joelwmale/RSSFeedPHP/RSSFeedPHP to use the main class. I thought it was possible to somehow tell composer if no class is supplied, to then use that class. So that doing: use joelwmale/RSSFeedPHP would automatically load the RSSFeedPHP.php file? and therefore the static methods accessible.
    – joelwxd
    Dec 28 '18 at 8:51












  • It would. If RSSFeedPHP.php is located in src/RSSFeedPHP, and your composer says - under the psr-4 key - "RSSFeedPHP\": "src/RSSFeedPHP/", then when you call use RSSFeedPHP/RSSFeedPHP;, it will load your class. So in order to change that namespace, change "RSSFeedPHP\": "src/RSSFeedPHP/" to "joelwmale\": "src/RSSFeedPHP/", and you'll be able to call use joelwmaleRSSFeedPHP;.
    – minitauros
    Dec 28 '18 at 9:02












  • Ah that makes total sense. Beautiful. thank you very much for your help!
    – joelwxd
    Dec 28 '18 at 9:10











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53955288%2fnamespacing-issue-in-custom-php-package-unable-to-do-use-joelwmale-rssfeedphp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














"autoload": {
"psr-4": {
"RSSFeedPHP\": "src/RSSFeedPHP/"
}
},


This registers your class under the RSSFeedPHP namespace. Anything in the src/RSSFeedPHP/ directory can now be loaded as if it were in that namespace. Try using



use RSSFeedPHPRSSFeedPHP;



Note that the name of your class must be RSSFeedPHP if your file is called RSSFeedPHP.php, and its namespace must thus be also RSSFeedPHP, i.e.



<?php

namespace RSSFeedPHP;

class RSSFeedPHP {}





share|improve this answer





















  • How would i follow a typical vendor/package namespacing? I did have it joelwmale/RSSFeedPHP before, but then when using the namespace I needed to do: use joelwmale/RSSFeedPHP/RSSFeedPHP I simply want to be able to do: use joelwmale/RSSFeedPHP and it automatically load the class. I have added my github repo to the original post sorry.
    – joelwxd
    Dec 28 '18 at 8:14












  • You can use any namespace you want. The name that ends up in the /vendor directory is the one you specify under the name key in composer.json. E.g. if your package's name is joelwmale/rssfeed then you will see a directory /vendor/joelwmale/rssfeed. You can use any namespace in there, but it's good practice to choose a unique one for your packaging, like Joelwmale. Then you can issue use Joelwmale/RSSFeedPHP;, or use Joelwmale/Feed/RSSFeed; or whatever if you want to "sub"package.
    – minitauros
    Dec 28 '18 at 8:31












  • Yep fully understood. If I wanted my namespacing to be use joelwmale/RSSFeedPHP; how would I achieve that with the composer.json in the file above? The issue ATM is that I can get that to work - but I'd have to do: use joelwmale/RSSFeedPHP/RSSFeedPHP to use the main class. I thought it was possible to somehow tell composer if no class is supplied, to then use that class. So that doing: use joelwmale/RSSFeedPHP would automatically load the RSSFeedPHP.php file? and therefore the static methods accessible.
    – joelwxd
    Dec 28 '18 at 8:51












  • It would. If RSSFeedPHP.php is located in src/RSSFeedPHP, and your composer says - under the psr-4 key - "RSSFeedPHP\": "src/RSSFeedPHP/", then when you call use RSSFeedPHP/RSSFeedPHP;, it will load your class. So in order to change that namespace, change "RSSFeedPHP\": "src/RSSFeedPHP/" to "joelwmale\": "src/RSSFeedPHP/", and you'll be able to call use joelwmaleRSSFeedPHP;.
    – minitauros
    Dec 28 '18 at 9:02












  • Ah that makes total sense. Beautiful. thank you very much for your help!
    – joelwxd
    Dec 28 '18 at 9:10
















2














"autoload": {
"psr-4": {
"RSSFeedPHP\": "src/RSSFeedPHP/"
}
},


This registers your class under the RSSFeedPHP namespace. Anything in the src/RSSFeedPHP/ directory can now be loaded as if it were in that namespace. Try using



use RSSFeedPHPRSSFeedPHP;



Note that the name of your class must be RSSFeedPHP if your file is called RSSFeedPHP.php, and its namespace must thus be also RSSFeedPHP, i.e.



<?php

namespace RSSFeedPHP;

class RSSFeedPHP {}





share|improve this answer





















  • How would i follow a typical vendor/package namespacing? I did have it joelwmale/RSSFeedPHP before, but then when using the namespace I needed to do: use joelwmale/RSSFeedPHP/RSSFeedPHP I simply want to be able to do: use joelwmale/RSSFeedPHP and it automatically load the class. I have added my github repo to the original post sorry.
    – joelwxd
    Dec 28 '18 at 8:14












  • You can use any namespace you want. The name that ends up in the /vendor directory is the one you specify under the name key in composer.json. E.g. if your package's name is joelwmale/rssfeed then you will see a directory /vendor/joelwmale/rssfeed. You can use any namespace in there, but it's good practice to choose a unique one for your packaging, like Joelwmale. Then you can issue use Joelwmale/RSSFeedPHP;, or use Joelwmale/Feed/RSSFeed; or whatever if you want to "sub"package.
    – minitauros
    Dec 28 '18 at 8:31












  • Yep fully understood. If I wanted my namespacing to be use joelwmale/RSSFeedPHP; how would I achieve that with the composer.json in the file above? The issue ATM is that I can get that to work - but I'd have to do: use joelwmale/RSSFeedPHP/RSSFeedPHP to use the main class. I thought it was possible to somehow tell composer if no class is supplied, to then use that class. So that doing: use joelwmale/RSSFeedPHP would automatically load the RSSFeedPHP.php file? and therefore the static methods accessible.
    – joelwxd
    Dec 28 '18 at 8:51












  • It would. If RSSFeedPHP.php is located in src/RSSFeedPHP, and your composer says - under the psr-4 key - "RSSFeedPHP\": "src/RSSFeedPHP/", then when you call use RSSFeedPHP/RSSFeedPHP;, it will load your class. So in order to change that namespace, change "RSSFeedPHP\": "src/RSSFeedPHP/" to "joelwmale\": "src/RSSFeedPHP/", and you'll be able to call use joelwmaleRSSFeedPHP;.
    – minitauros
    Dec 28 '18 at 9:02












  • Ah that makes total sense. Beautiful. thank you very much for your help!
    – joelwxd
    Dec 28 '18 at 9:10














2












2








2






"autoload": {
"psr-4": {
"RSSFeedPHP\": "src/RSSFeedPHP/"
}
},


This registers your class under the RSSFeedPHP namespace. Anything in the src/RSSFeedPHP/ directory can now be loaded as if it were in that namespace. Try using



use RSSFeedPHPRSSFeedPHP;



Note that the name of your class must be RSSFeedPHP if your file is called RSSFeedPHP.php, and its namespace must thus be also RSSFeedPHP, i.e.



<?php

namespace RSSFeedPHP;

class RSSFeedPHP {}





share|improve this answer












"autoload": {
"psr-4": {
"RSSFeedPHP\": "src/RSSFeedPHP/"
}
},


This registers your class under the RSSFeedPHP namespace. Anything in the src/RSSFeedPHP/ directory can now be loaded as if it were in that namespace. Try using



use RSSFeedPHPRSSFeedPHP;



Note that the name of your class must be RSSFeedPHP if your file is called RSSFeedPHP.php, and its namespace must thus be also RSSFeedPHP, i.e.



<?php

namespace RSSFeedPHP;

class RSSFeedPHP {}






share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 28 '18 at 8:03









minitaurosminitauros

839514




839514












  • How would i follow a typical vendor/package namespacing? I did have it joelwmale/RSSFeedPHP before, but then when using the namespace I needed to do: use joelwmale/RSSFeedPHP/RSSFeedPHP I simply want to be able to do: use joelwmale/RSSFeedPHP and it automatically load the class. I have added my github repo to the original post sorry.
    – joelwxd
    Dec 28 '18 at 8:14












  • You can use any namespace you want. The name that ends up in the /vendor directory is the one you specify under the name key in composer.json. E.g. if your package's name is joelwmale/rssfeed then you will see a directory /vendor/joelwmale/rssfeed. You can use any namespace in there, but it's good practice to choose a unique one for your packaging, like Joelwmale. Then you can issue use Joelwmale/RSSFeedPHP;, or use Joelwmale/Feed/RSSFeed; or whatever if you want to "sub"package.
    – minitauros
    Dec 28 '18 at 8:31












  • Yep fully understood. If I wanted my namespacing to be use joelwmale/RSSFeedPHP; how would I achieve that with the composer.json in the file above? The issue ATM is that I can get that to work - but I'd have to do: use joelwmale/RSSFeedPHP/RSSFeedPHP to use the main class. I thought it was possible to somehow tell composer if no class is supplied, to then use that class. So that doing: use joelwmale/RSSFeedPHP would automatically load the RSSFeedPHP.php file? and therefore the static methods accessible.
    – joelwxd
    Dec 28 '18 at 8:51












  • It would. If RSSFeedPHP.php is located in src/RSSFeedPHP, and your composer says - under the psr-4 key - "RSSFeedPHP\": "src/RSSFeedPHP/", then when you call use RSSFeedPHP/RSSFeedPHP;, it will load your class. So in order to change that namespace, change "RSSFeedPHP\": "src/RSSFeedPHP/" to "joelwmale\": "src/RSSFeedPHP/", and you'll be able to call use joelwmaleRSSFeedPHP;.
    – minitauros
    Dec 28 '18 at 9:02












  • Ah that makes total sense. Beautiful. thank you very much for your help!
    – joelwxd
    Dec 28 '18 at 9:10


















  • How would i follow a typical vendor/package namespacing? I did have it joelwmale/RSSFeedPHP before, but then when using the namespace I needed to do: use joelwmale/RSSFeedPHP/RSSFeedPHP I simply want to be able to do: use joelwmale/RSSFeedPHP and it automatically load the class. I have added my github repo to the original post sorry.
    – joelwxd
    Dec 28 '18 at 8:14












  • You can use any namespace you want. The name that ends up in the /vendor directory is the one you specify under the name key in composer.json. E.g. if your package's name is joelwmale/rssfeed then you will see a directory /vendor/joelwmale/rssfeed. You can use any namespace in there, but it's good practice to choose a unique one for your packaging, like Joelwmale. Then you can issue use Joelwmale/RSSFeedPHP;, or use Joelwmale/Feed/RSSFeed; or whatever if you want to "sub"package.
    – minitauros
    Dec 28 '18 at 8:31












  • Yep fully understood. If I wanted my namespacing to be use joelwmale/RSSFeedPHP; how would I achieve that with the composer.json in the file above? The issue ATM is that I can get that to work - but I'd have to do: use joelwmale/RSSFeedPHP/RSSFeedPHP to use the main class. I thought it was possible to somehow tell composer if no class is supplied, to then use that class. So that doing: use joelwmale/RSSFeedPHP would automatically load the RSSFeedPHP.php file? and therefore the static methods accessible.
    – joelwxd
    Dec 28 '18 at 8:51












  • It would. If RSSFeedPHP.php is located in src/RSSFeedPHP, and your composer says - under the psr-4 key - "RSSFeedPHP\": "src/RSSFeedPHP/", then when you call use RSSFeedPHP/RSSFeedPHP;, it will load your class. So in order to change that namespace, change "RSSFeedPHP\": "src/RSSFeedPHP/" to "joelwmale\": "src/RSSFeedPHP/", and you'll be able to call use joelwmaleRSSFeedPHP;.
    – minitauros
    Dec 28 '18 at 9:02












  • Ah that makes total sense. Beautiful. thank you very much for your help!
    – joelwxd
    Dec 28 '18 at 9:10
















How would i follow a typical vendor/package namespacing? I did have it joelwmale/RSSFeedPHP before, but then when using the namespace I needed to do: use joelwmale/RSSFeedPHP/RSSFeedPHP I simply want to be able to do: use joelwmale/RSSFeedPHP and it automatically load the class. I have added my github repo to the original post sorry.
– joelwxd
Dec 28 '18 at 8:14






How would i follow a typical vendor/package namespacing? I did have it joelwmale/RSSFeedPHP before, but then when using the namespace I needed to do: use joelwmale/RSSFeedPHP/RSSFeedPHP I simply want to be able to do: use joelwmale/RSSFeedPHP and it automatically load the class. I have added my github repo to the original post sorry.
– joelwxd
Dec 28 '18 at 8:14














You can use any namespace you want. The name that ends up in the /vendor directory is the one you specify under the name key in composer.json. E.g. if your package's name is joelwmale/rssfeed then you will see a directory /vendor/joelwmale/rssfeed. You can use any namespace in there, but it's good practice to choose a unique one for your packaging, like Joelwmale. Then you can issue use Joelwmale/RSSFeedPHP;, or use Joelwmale/Feed/RSSFeed; or whatever if you want to "sub"package.
– minitauros
Dec 28 '18 at 8:31






You can use any namespace you want. The name that ends up in the /vendor directory is the one you specify under the name key in composer.json. E.g. if your package's name is joelwmale/rssfeed then you will see a directory /vendor/joelwmale/rssfeed. You can use any namespace in there, but it's good practice to choose a unique one for your packaging, like Joelwmale. Then you can issue use Joelwmale/RSSFeedPHP;, or use Joelwmale/Feed/RSSFeed; or whatever if you want to "sub"package.
– minitauros
Dec 28 '18 at 8:31














Yep fully understood. If I wanted my namespacing to be use joelwmale/RSSFeedPHP; how would I achieve that with the composer.json in the file above? The issue ATM is that I can get that to work - but I'd have to do: use joelwmale/RSSFeedPHP/RSSFeedPHP to use the main class. I thought it was possible to somehow tell composer if no class is supplied, to then use that class. So that doing: use joelwmale/RSSFeedPHP would automatically load the RSSFeedPHP.php file? and therefore the static methods accessible.
– joelwxd
Dec 28 '18 at 8:51






Yep fully understood. If I wanted my namespacing to be use joelwmale/RSSFeedPHP; how would I achieve that with the composer.json in the file above? The issue ATM is that I can get that to work - but I'd have to do: use joelwmale/RSSFeedPHP/RSSFeedPHP to use the main class. I thought it was possible to somehow tell composer if no class is supplied, to then use that class. So that doing: use joelwmale/RSSFeedPHP would automatically load the RSSFeedPHP.php file? and therefore the static methods accessible.
– joelwxd
Dec 28 '18 at 8:51














It would. If RSSFeedPHP.php is located in src/RSSFeedPHP, and your composer says - under the psr-4 key - "RSSFeedPHP\": "src/RSSFeedPHP/", then when you call use RSSFeedPHP/RSSFeedPHP;, it will load your class. So in order to change that namespace, change "RSSFeedPHP\": "src/RSSFeedPHP/" to "joelwmale\": "src/RSSFeedPHP/", and you'll be able to call use joelwmaleRSSFeedPHP;.
– minitauros
Dec 28 '18 at 9:02






It would. If RSSFeedPHP.php is located in src/RSSFeedPHP, and your composer says - under the psr-4 key - "RSSFeedPHP\": "src/RSSFeedPHP/", then when you call use RSSFeedPHP/RSSFeedPHP;, it will load your class. So in order to change that namespace, change "RSSFeedPHP\": "src/RSSFeedPHP/" to "joelwmale\": "src/RSSFeedPHP/", and you'll be able to call use joelwmaleRSSFeedPHP;.
– minitauros
Dec 28 '18 at 9:02














Ah that makes total sense. Beautiful. thank you very much for your help!
– joelwxd
Dec 28 '18 at 9:10




Ah that makes total sense. Beautiful. thank you very much for your help!
– joelwxd
Dec 28 '18 at 9:10


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53955288%2fnamespacing-issue-in-custom-php-package-unable-to-do-use-joelwmale-rssfeedphp%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas